Commit a7da90071e

joachimschmidt557 <joachim.schmidt557@outlook.com>
2021-01-08 22:11:49
stage2: fix bug in genArg
When an argument is unused in the function body, still increment arg_index so we still select the correct arguments in the args slice.
1 parent 29928af
Changed files (1)
src/codegen.zig
@@ -1480,6 +1480,9 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
         }
 
         fn genArg(self: *Self, inst: *ir.Inst.Arg) !MCValue {
+            const arg_index = self.arg_index;
+            self.arg_index += 1;
+
             if (FreeRegInt == u0) {
                 return self.fail(inst.base.src, "TODO implement Register enum for {}", .{self.target.cpu.arch});
             }
@@ -1488,8 +1491,7 @@ fn Function(comptime arch: std.Target.Cpu.Arch) type {
 
             try self.registers.ensureCapacity(self.gpa, self.registers.count() + 1);
 
-            const result = self.args[self.arg_index];
-            self.arg_index += 1;
+            const result = self.args[arg_index];
 
             const name_with_null = inst.name[0 .. mem.lenZ(inst.name) + 1];
             switch (result) {