Commit c7775a9f62

Jakub Konka <kubkon@jakubkonka.com>
2022-02-11 15:04:59
x64: impl genBinMathOpMir for ptr_stack_off and PIE memory
1 parent 5283a52
Changed files (2)
src
arch
test
behavior
src/arch/x86_64/CodeGen.zig
@@ -2244,7 +2244,9 @@ fn genBinMathOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MC
                 .none => unreachable,
                 .undef => try self.genSetReg(dst_ty, dst_reg, .undef),
                 .dead, .unreach => unreachable,
-                .ptr_stack_offset => unreachable,
+                .ptr_stack_offset => |off| {
+                    return self.genBinMathOpMir(mir_tag, dst_ty, dst_mcv, .{ .immediate = @bitCast(u32, off) });
+                },
                 .ptr_embedded_in_code => unreachable,
                 .register => |src_reg| {
                     _ = try self.addInst(.{
@@ -2265,16 +2267,17 @@ fn genBinMathOpMir(self: *Self, mir_tag: Mir.Inst.Tag, dst_ty: Type, dst_mcv: MC
                         .data = .{ .imm = @truncate(u32, imm) },
                     });
                 },
-                .embedded_in_code, .memory => {
+                .embedded_in_code,
+                .memory,
+                .got_load,
+                .direct_load,
+                => {
                     assert(abi_size <= 8);
                     self.register_manager.freezeRegs(&.{dst_reg});
                     defer self.register_manager.unfreezeRegs(&.{dst_reg});
                     const reg = try self.copyToTmpRegister(dst_ty, src_mcv);
                     return self.genBinMathOpMir(mir_tag, dst_ty, dst_mcv, .{ .register = reg });
                 },
-                .got_load, .direct_load => {
-                    return self.fail("TODO implement x86 ADD/SUB/CMP source symbol at index in linker", .{});
-                },
                 .stack_offset => |off| {
                     if (off > math.maxInt(i32)) {
                         return self.fail("stack offset too large", .{});
@@ -4620,6 +4623,9 @@ fn genTypedValue(self: *Self, typed_value: TypedValue) InnerError!MCValue {
     }
 
     switch (typed_value.ty.zigTypeTag()) {
+        .Array => {
+            return self.lowerUnnamedConst(typed_value);
+        },
         .Pointer => switch (typed_value.ty.ptrSize()) {
             .Slice => {
                 return self.lowerUnnamedConst(typed_value);
test/behavior/slice.zig
@@ -29,7 +29,6 @@ comptime {
 test "slicing" {
     if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
     if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
-    if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
     if (builtin.zig_backend == .stage2_c) return error.SkipZigTest; // TODO
 
     var array: [20]i32 = undefined;
@@ -223,7 +222,6 @@ test "compile time slice of pointer to hard coded address" {
 test "slice string literal has correct type" {
     if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
     if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
-    if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
 
     comptime {
         try expect(@TypeOf("aoeu"[0..]) == *const [4:0]u8);
@@ -365,7 +363,6 @@ test "empty array to slice" {
 test "@ptrCast slice to pointer" {
     if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
     if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
-    if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
 
     const S = struct {
         fn doTheTest() !void {