From a32f59b256df8c0ca85ff3a958be6dad3f1c1b61 Mon Sep 17 00:00:00 2001 From: Wolfgang Bumiller Date: Tue, 26 Feb 2013 16:39:28 +0100 Subject: [PATCH] hopefully fix an off-by-1 vararg copy issue --- ir.c | 6 +++--- tests/varargs2.qc | 12 ++++++++++++ tests/varargs2.tmpl | 5 +++++ 3 files changed, 20 insertions(+), 3 deletions(-) create mode 100644 tests/varargs2.qc create mode 100644 tests/varargs2.tmpl diff --git a/ir.c b/ir.c index e794860..a28b07e 100644 --- a/ir.c +++ b/ir.c @@ -3151,14 +3151,14 @@ static bool gen_function_varargs_copy(ir_function *self) stmt.o3.s1 = 0; maxparams = numparams + self->max_varargs; for (i = numparams; i < maxparams; ++i) { - if (i <= 8) { + if (i < 8) { stmt.o1.u1 = OFS_PARM0 + 3*i; stmt.o2.u1 = ir_value_code_addr(self->locals[i]); code_push_statement(&stmt, self->context.line); continue; } - ext = i - 9; - if (ext >= vec_size(ir->extparams)) + ext = i - 8; + while (ext >= vec_size(ir->extparams)) ir_gen_extparam(ir); ep = ir->extparams[ext]; diff --git a/tests/varargs2.qc b/tests/varargs2.qc new file mode 100644 index 0000000..7fb807a --- /dev/null +++ b/tests/varargs2.qc @@ -0,0 +1,12 @@ +void past8(float a, float b, float c, float d, ...count) +{ + float i; + print("out:"); + for (i = 0; i < count; ++i) + print(" ", ftos(...(i, float)), ""); + print("\n"); +} + +void main() { + past8(1, 2, 3, 4, 10, 20, 30, 40, 50, 60, 70, 80); +} diff --git a/tests/varargs2.tmpl b/tests/varargs2.tmpl new file mode 100644 index 0000000..61f721e --- /dev/null +++ b/tests/varargs2.tmpl @@ -0,0 +1,5 @@ +I: varargs2.qc +D: non-builtin vararg support test 2 +T: -execute +C: -std=fteqcc -fvariadic-args +M: out: 10 20 30 40 50 60 70 80 -- 2.39.2