authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-02-20 03:53:42+00:00
committergravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-02-20 12:10:29+00:00
log65a87ff299a364e7d8bab6256e0b05022f1a2620
treeabcf162300432c9b8f8c1c8ffe692f7877ce71fa
parent97290e0bfc38e75fb0e19f382a2187801bf4a458

Liveness: do not elide safety-checked instructions

Resolves: #19012

2 files changed, 24 insertions(+), 3 deletions(-)

src/Air.zig+3-3
......@@ -1646,20 +1646,20 @@ pub fn mustLower(air: Air, inst: Air.Inst.Index, ip: *const InternPool) bool {
16461646 .c_va_copy,
16471647 .c_va_end,
16481648 .c_va_start,
1649 .add_safe,
1650 .sub_safe,
1651 .mul_safe,
16491652 => true,
16501653
16511654 .add,
1652 .add_safe,
16531655 .add_optimized,
16541656 .add_wrap,
16551657 .add_sat,
16561658 .sub,
1657 .sub_safe,
16581659 .sub_optimized,
16591660 .sub_wrap,
16601661 .sub_sat,
16611662 .mul,
1662 .mul_safe,
16631663 .mul_optimized,
16641664 .mul_wrap,
16651665 .mul_sat,
test/cases/safety/ignored expression integer overflow.zig created+21
......@@ -0,0 +1,21 @@
1const std = @import("std");
2
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {
4 _ = stack_trace;
5 if (std.mem.eql(u8, message, "integer overflow")) {
6 std.process.exit(0);
7 }
8 std.process.exit(1);
9}
10
11pub fn main() !void {
12 var x: usize = undefined;
13 x = 0;
14 // We ignore this result but it should still trigger a safety panic!
15 _ = x - 1;
16 return error.TestFailed;
17}
18
19// run
20// backend=llvm
21// target=native