authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-09-18 21:24:50-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-09-19 00:43:21-07:00
log3e79315d19c7dfe5f9b90185d8030209ef8dd829
tree28be901fb7fa95af1e73bd4c6b8297421b916570
parentf91ff9a746ff97945dacc8114c073bd279f68f17

x86 backend: don't read bogus safety flag

Safety is not a global flag that should be enabled or disabled for all stores - it's lowered by the frontend directly into AIR instruction semantics. The flag for this is communicated via the `store` vs `store_safe` AIR instructions, and whether to write 0xaa bytes or not should be decided in `airStore` and passed down via function parameters. This commit is a step backwards since it removes functionality but it aims our feet towards a better mountain to climb.

3 files changed, 6 insertions(+), 16 deletions(-)

src/arch/x86_64/CodeGen.zig+3-15
......@@ -1934,7 +1934,7 @@ fn genBody(self: *Self, body: []const Air.Inst.Index) InnerError!void {
19341934 .ptr_elem_ptr => try self.airPtrElemPtr(inst),
19351935
19361936 .inferred_alloc, .inferred_alloc_comptime => unreachable,
1937 .unreach => if (self.wantSafety()) try self.airTrap() else self.finishAirBookkeeping(),
1937 .unreach => self.finishAirBookkeeping(),
19381938
19391939 .optional_payload => try self.airOptionalPayload(inst),
19401940 .optional_payload_ptr => try self.airOptionalPayloadPtr(inst),
......@@ -9813,8 +9813,7 @@ fn genSetReg(self: *Self, dst_reg: Register, ty: Type, src_mcv: MCValue) InnerEr
98139813 .register_overflow,
98149814 .reserved_frame,
98159815 => unreachable,
9816 .undef => if (self.wantSafety())
9817 try self.genSetReg(dst_reg.to64(), Type.usize, .{ .immediate = 0xaaaaaaaaaaaaaaaa }),
9816 .undef => {},
98189817 .eflags => |cc| try self.asmSetccRegister(dst_reg.to8(), cc),
98199818 .immediate => |imm| {
98209819 if (imm == 0) {
......@@ -10098,8 +10097,7 @@ fn genSetMem(self: *Self, base: Memory.Base, disp: i32, ty: Type, src_mcv: MCVal
1009810097 };
1009910098 switch (src_mcv) {
1010010099 .none, .unreach, .dead, .reserved_frame => unreachable,
10101 .undef => if (self.wantSafety())
10102 try self.genInlineMemset(dst_ptr_mcv, .{ .immediate = 0xaa }, .{ .immediate = abi_size }),
10100 .undef => {},
1010310101 .immediate => |imm| switch (abi_size) {
1010410102 1, 2, 4 => {
1010510103 const immediate = if (ty.isSignedInt(mod))
......@@ -12016,16 +12014,6 @@ fn resolveCallingConventionValues(
1201612014 return result;
1201712015}
1201812016
12019/// TODO support scope overrides. Also note this logic is duplicated with `Module.wantSafety`.
12020fn wantSafety(self: *Self) bool {
12021 return switch (self.bin_file.options.optimize_mode) {
12022 .Debug => true,
12023 .ReleaseSafe => true,
12024 .ReleaseFast => false,
12025 .ReleaseSmall => false,
12026 };
12027}
12028
1202912017fn fail(self: *Self, comptime format: []const u8, args: anytype) InnerError {
1203012018 @setCold(true);
1203112019 assert(self.err_msg == null);
test/behavior/cast.zig+2-1
......@@ -334,10 +334,11 @@ test "*const ?[*]const T to [*c]const [*c]const T" {
334334 try expect(b[0][1] == 'k');
335335}
336336
337test "array coersion to undefined at runtime" {
337test "array coercion to undefined at runtime" {
338338 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
339339 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
340340 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
341 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
341342
342343 @setRuntimeSafety(true);
343344
test/behavior/int128.zig+1
......@@ -28,6 +28,7 @@ test "undefined 128 bit int" {
2828 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
2929 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
3030 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
31 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest;
3132
3233 @setRuntimeSafety(true);
3334