]> git.xonotic.org Git - xonotic/gmqcc.git/commitdiff
hopefully fix an off-by-1 vararg copy issue
authorWolfgang Bumiller <blub@speed.at>
Tue, 26 Feb 2013 15:39:28 +0000 (16:39 +0100)
committerWolfgang Bumiller <blub@speed.at>
Tue, 26 Feb 2013 15:39:28 +0000 (16:39 +0100)
ir.c
tests/varargs2.qc [new file with mode: 0644]
tests/varargs2.tmpl [new file with mode: 0644]

diff --git a/ir.c b/ir.c
index e794860f078a998cbe1694799574cc55fec99d7a..a28b07e95f3452d5b68999a1005799fbd41480c9 100644 (file)
--- 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) {
     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;
         }
             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];
             ir_gen_extparam(ir);
 
         ep = ir->extparams[ext];
diff --git a/tests/varargs2.qc b/tests/varargs2.qc
new file mode 100644 (file)
index 0000000..7fb807a
--- /dev/null
@@ -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 (file)
index 0000000..61f721e
--- /dev/null
@@ -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