]> de.git.xonotic.org Git - xonotic/gmqcc.git/blobdiff - ir.c
Fixes, updates, and added uninstall target for makefile
[xonotic/gmqcc.git] / ir.c
diff --git a/ir.c b/ir.c
index 46e74894a14e8e1d7c613343b73a88e0d912e0b8..ad86914e5feb6144876c31be9062f663e00d998b 100644 (file)
--- a/ir.c
+++ b/ir.c
@@ -2257,18 +2257,22 @@ bool ir_function_allocate_locals(ir_function *self)
                     irerror(call->context, "internal error: unlocked parameter %s not found", v->name);
                     goto error;
                 }
-
                 ++opts_optimizationcount[OPTIM_CALL_STORES];
                 v->callparam = true;
                 if (param < 8)
                     ir_value_code_setaddr(v, OFS_PARM0 + 3*param);
                 else {
+                    size_t nprotos = vec_size(self->owner->extparam_protos);
                     ir_value *ep;
                     param -= 8;
-                    if (vec_size(self->owner->extparam_protos) <= param)
-                        ep = ir_gen_extparam_proto(self->owner);
-                    else
+                    if (nprotos > param)
                         ep = self->owner->extparam_protos[param];
+                    else
+                    {
+                        ep = ir_gen_extparam_proto(self->owner);
+                        while (++nprotos <= param)
+                            ep = ir_gen_extparam_proto(self->owner);
+                    }
                     ir_instr_op(v->writes[0], 0, ep, true);
                     call->params[param+8] = ep;
                 }
@@ -3113,7 +3117,7 @@ static ir_value* ir_gen_extparam_proto(ir_builder *ir)
     ir_value *global;
     char      name[128];
 
-    snprintf(name, sizeof(name), "EXTPARM#%i", (int)(vec_size(ir->extparam_protos)+8));
+    snprintf(name, sizeof(name), "EXTPARM#%i", (int)(vec_size(ir->extparam_protos)));
     global = ir_value_var(name, store_global, TYPE_VECTOR);
 
     vec_push(ir->extparam_protos, global);
@@ -3200,7 +3204,7 @@ static bool gen_function_varargs_copy(ir_function *self)
             code_push_statement(&stmt, self->context.line);
             continue;
         }
-        ext = i - 8;
+        ext = i - 9;
         if (ext >= vec_size(ir->extparams))
             ir_gen_extparam(ir);