authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-07-16 01:50:32+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-07-23 15:40:11+03:00
log4d20d6874c418f596c576cea48985de6ef3a3dd2
treedbae7fa6ce09114fe95bb7148b54bca9ac9ec2fb
parent72c60acd5dd9172c648cb3c5a4b51224ebea33f2

move passing safety tests to stage2


28 files changed, 140 insertions(+), 86 deletions(-)

src/AstGen.zig+1-2
......@@ -6504,8 +6504,7 @@ fn ret(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Inst.Ref
65046504 },
65056505 .always => {
65066506 // Value is always an error. Emit both error defers and regular defers.
6507 const result = if (rl == .ptr) try gz.addUnNode(.load, rl.ptr, node) else operand;
6508 const err_code = try gz.addUnNode(.err_union_code, result, node);
6507 const err_code = if (rl == .ptr) try gz.addUnNode(.load, rl.ptr, node) else operand;
65096508 try genDefers(gz, defer_outer, scope, .{ .both = err_code });
65106509 try gz.addRet(rl, operand, node);
65116510 return Zir.Inst.Ref.unreachable_value;
test/cases/safety/@errSetCast error not present in destination.zig +6-4
......@@ -1,9 +1,11 @@
11const std = @import("std");
22
33pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
4 _ = message;
54 _ = stack_trace;
6 std.process.exit(0);
5 if (std.mem.eql(u8, message, "invalid error code")) {
6 std.process.exit(0);
7 }
8 std.process.exit(1);
79}
810const Set1 = error{A, B};
911const Set2 = error{A, C};
......@@ -15,5 +17,5 @@ fn foo(set1: Set1) Set2 {
1517 return @errSetCast(Set2, set1);
1618}
1719// run
18// backend=stage1
19// target=native
\ No newline at end of file
20// backend=llvm
21// target=native
test/cases/safety/@intCast to u0.zig +6-4
......@@ -1,9 +1,11 @@
11const std = @import("std");
22
33pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
4 _ = message;
54 _ = stack_trace;
6 std.process.exit(0);
5 if (std.mem.eql(u8, message, "integer cast truncated bits")) {
6 std.process.exit(0);
7 }
8 std.process.exit(1);
79}
810
911pub fn main() !void {
......@@ -16,5 +18,5 @@ fn bar(one: u1, not_zero: i32) void {
1618 _ = x;
1719}
1820// run
19// backend=stage1
20// target=native
\ No newline at end of file
21// backend=llvm
22// target=native
test/cases/safety/@intToPtr address zero to non-optional byte-aligned pointer.zig +5-3
......@@ -1,9 +1,11 @@
11const std = @import("std");
22
33pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
4 _ = message;
54 _ = stack_trace;
6 std.process.exit(0);
5 if (std.mem.eql(u8, message, "cast causes pointer to be null")) {
6 std.process.exit(0);
7 }
8 std.process.exit(1);
79}
810pub fn main() !void {
911 var zero: usize = 0;
......@@ -12,5 +14,5 @@ pub fn main() !void {
1214 return error.TestFailed;
1315}
1416// run
15// backend=stage1
17// backend=llvm
1618// target=native
test/cases/safety/@intToPtr address zero to non-optional pointer.zig +5-3
......@@ -1,9 +1,11 @@
11const std = @import("std");
22
33pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
4 _ = message;
54 _ = stack_trace;
6 std.process.exit(0);
5 if (std.mem.eql(u8, message, "cast causes pointer to be null")) {
6 std.process.exit(0);
7 }
8 std.process.exit(1);
79}
810pub fn main() !void {
911 var zero: usize = 0;
......@@ -12,5 +14,5 @@ pub fn main() !void {
1214 return error.TestFailed;
1315}
1416// run
15// backend=stage1
17// backend=llvm
1618// target=native
test/cases/safety/calling panic.zig +2-2
......@@ -12,5 +12,5 @@ pub fn main() !void {
1212 return error.TestFailed;
1313}
1414// run
15// backend=stage1
16// target=native
\ No newline at end of file
15// backend=llvm
16// target=native
test/cases/safety/cast integer to global error and no code matches.zig +6-4
......@@ -1,9 +1,11 @@
11const std = @import("std");
22
33pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
4 _ = message;
54 _ = stack_trace;
6 std.process.exit(0);
5 if (std.mem.eql(u8, message, "invalid error code")) {
6 std.process.exit(0);
7 }
8 std.process.exit(1);
79}
810pub fn main() !void {
911 bar(9999) catch {};
......@@ -13,5 +15,5 @@ fn bar(x: u16) anyerror {
1315 return @intToError(x);
1416}
1517// run
16// backend=stage1
17// target=native
\ No newline at end of file
18// backend=llvm
19// target=native
test/cases/safety/intToPtr with misaligned address.zig +1-1
......@@ -14,5 +14,5 @@ pub fn main() !void {
1414 return error.TestFailed;
1515}
1616// run
17// backend=stage1
17// backend=llvm
1818// target=native
test/cases/safety/integer addition overflow.zig +1-1
......@@ -19,5 +19,5 @@ fn add(a: u16, b: u16) u16 {
1919}
2020
2121// run
22// backend=stage1
22// backend=llvm
2323// target=native
test/cases/safety/integer multiplication overflow.zig +6-4
......@@ -1,9 +1,11 @@
11const std = @import("std");
22
33pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
4 _ = message;
54 _ = stack_trace;
6 std.process.exit(0);
5 if (std.mem.eql(u8, message, "integer overflow")) {
6 std.process.exit(0);
7 }
8 std.process.exit(1);
79}
810
911pub fn main() !void {
......@@ -15,5 +17,5 @@ fn mul(a: u16, b: u16) u16 {
1517 return a * b;
1618}
1719// run
18// backend=stage1
19// target=native
\ No newline at end of file
20// backend=llvm
21// target=native
test/cases/safety/integer negation overflow.zig +6-4
......@@ -1,9 +1,11 @@
11const std = @import("std");
22
33pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
4 _ = message;
54 _ = stack_trace;
6 std.process.exit(0);
5 if (std.mem.eql(u8, message, "integer overflow")) {
6 std.process.exit(0);
7 }
8 std.process.exit(1);
79}
810
911pub fn main() !void {
......@@ -15,5 +17,5 @@ fn neg(a: i16) i16 {
1517 return -a;
1618}
1719// run
18// backend=stage1
19// target=native
\ No newline at end of file
20// backend=llvm
21// target=native
test/cases/safety/integer subtraction overflow.zig +6-4
......@@ -1,9 +1,11 @@
11const std = @import("std");
22
33pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
4 _ = message;
54 _ = stack_trace;
6 std.process.exit(0);
5 if (std.mem.eql(u8, message, "integer overflow")) {
6 std.process.exit(0);
7 }
8 std.process.exit(1);
79}
810
911pub fn main() !void {
......@@ -15,5 +17,5 @@ fn sub(a: u16, b: u16) u16 {
1517 return a - b;
1618}
1719// run
18// backend=stage1
19// target=native
\ No newline at end of file
20// backend=llvm
21// target=native
test/cases/safety/optional unwrap operator on C pointer.zig +5-3
......@@ -1,9 +1,11 @@
11const std = @import("std");
22
33pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
4 _ = message;
54 _ = stack_trace;
6 std.process.exit(0);
5 if (std.mem.eql(u8, message, "attempt to use null value")) {
6 std.process.exit(0);
7 }
8 std.process.exit(1);
79}
810pub fn main() !void {
911 var ptr: [*c]i32 = null;
......@@ -12,5 +14,5 @@ pub fn main() !void {
1214 return error.TestFailed;
1315}
1416// run
15// backend=stage1
17// backend=llvm
1618// target=native
test/cases/safety/optional unwrap operator on null pointer.zig +5-3
......@@ -1,9 +1,11 @@
11const std = @import("std");
22
33pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
4 _ = message;
54 _ = stack_trace;
6 std.process.exit(0);
5 if (std.mem.eql(u8, message, "attempt to use null value")) {
6 std.process.exit(0);
7 }
8 std.process.exit(1);
79}
810pub fn main() !void {
911 var ptr: ?*i32 = null;
......@@ -12,5 +14,5 @@ pub fn main() !void {
1214 return error.TestFailed;
1315}
1416// run
15// backend=stage1
17// backend=llvm
1618// target=native
test/cases/safety/out of bounds slice access.zig +6-4
......@@ -1,9 +1,11 @@
11const std = @import("std");
22
33pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
4 _ = message;
54 _ = stack_trace;
6 std.process.exit(0);
5 if (std.mem.eql(u8, message, "attempt to index out of bound: index 4, len 4")) {
6 std.process.exit(0);
7 }
8 std.process.exit(1);
79}
810pub fn main() !void {
911 const a = [_]i32{1, 2, 3, 4};
......@@ -15,5 +17,5 @@ fn bar(a: []const i32) i32 {
1517}
1618fn baz(_: i32) void { }
1719// run
18// backend=stage1
19// target=native
\ No newline at end of file
20// backend=llvm
21// target=native
test/cases/safety/signed shift left overflow.zig +6-4
......@@ -1,9 +1,11 @@
11const std = @import("std");
22
33pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
4 _ = message;
54 _ = stack_trace;
6 std.process.exit(0);
5 if (std.mem.eql(u8, message, "left shift overflowed bits")) {
6 std.process.exit(0);
7 }
8 std.process.exit(1);
79}
810
911pub fn main() !void {
......@@ -15,5 +17,5 @@ fn shl(a: i16, b: u4) i16 {
1517 return @shlExact(a, b);
1618}
1719// run
18// backend=stage1
19// target=native
\ No newline at end of file
20// backend=llvm
21// target=native
test/cases/safety/truncating vector cast.zig +1-1
......@@ -16,5 +16,5 @@ pub fn main() !void {
1616}
1717
1818// run
19// backend=stage1
19// backend=llvm
2020// target=native
test/cases/safety/unreachable.zig created+15
......@@ -0,0 +1,15 @@
1const std = @import("std");
2
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
4 _ = stack_trace;
5 if (std.mem.eql(u8, message, "reached unreachable code")) {
6 std.process.exit(0);
7 }
8 std.process.exit(1);
9}
10pub fn main() !void {
11 unreachable;
12}
13// run
14// backend=llvm
15// target=native
test/cases/safety/unsigned integer not fitting in cast to signed integer - same bit count.zig +6-4
......@@ -1,9 +1,11 @@
11const std = @import("std");
22
33pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
4 _ = message;
54 _ = stack_trace;
6 std.process.exit(0);
5 if (std.mem.eql(u8, message, "integer cast truncated bits")) {
6 std.process.exit(0);
7 }
8 std.process.exit(1);
79}
810pub fn main() !void {
911 var value: u8 = 245;
......@@ -12,5 +14,5 @@ pub fn main() !void {
1214 return error.TestFailed;
1315}
1416// run
15// backend=stage1
16// target=native
\ No newline at end of file
17// backend=llvm
18// target=native
test/cases/safety/unsigned shift left overflow.zig +6-4
......@@ -1,9 +1,11 @@
11const std = @import("std");
22
33pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
4 _ = message;
54 _ = stack_trace;
6 std.process.exit(0);
5 if (std.mem.eql(u8, message, "left shift overflowed bits")) {
6 std.process.exit(0);
7 }
8 std.process.exit(1);
79}
810
911pub fn main() !void {
......@@ -15,5 +17,5 @@ fn shl(a: u16, b: u4) u16 {
1517 return @shlExact(a, b);
1618}
1719// run
18// backend=stage1
19// target=native
\ No newline at end of file
20// backend=llvm
21// target=native
test/cases/safety/unsigned-signed vector cast.zig +1-1
......@@ -16,5 +16,5 @@ pub fn main() !void {
1616}
1717
1818// run
19// backend=stage1
19// backend=llvm
2020// target=native
test/cases/safety/unwrap error.zig +2-2
......@@ -15,5 +15,5 @@ fn bar() !void {
1515 return error.Whatever;
1616}
1717// run
18// backend=stage1
19// target=native
\ No newline at end of file
18// backend=llvm
19// target=native
test/cases/safety/value does not fit in shortening cast - u0.zig +6-4
......@@ -1,9 +1,11 @@
11const std = @import("std");
22
33pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
4 _ = message;
54 _ = stack_trace;
6 std.process.exit(0);
5 if (std.mem.eql(u8, message, "integer cast truncated bits")) {
6 std.process.exit(0);
7 }
8 std.process.exit(1);
79}
810
911pub fn main() !void {
......@@ -15,5 +17,5 @@ fn shorten_cast(x: u8) u0 {
1517 return @intCast(u0, x);
1618}
1719// run
18// backend=stage1
19// target=native
\ No newline at end of file
20// backend=llvm
21// target=native
test/cases/safety/value does not fit in shortening cast.zig +6-4
......@@ -1,9 +1,11 @@
11const std = @import("std");
22
33pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
4 _ = message;
54 _ = stack_trace;
6 std.process.exit(0);
5 if (std.mem.eql(u8, message, "integer cast truncated bits")) {
6 std.process.exit(0);
7 }
8 std.process.exit(1);
79}
810
911pub fn main() !void {
......@@ -15,5 +17,5 @@ fn shorten_cast(x: i32) i8 {
1517 return @intCast(i8, x);
1618}
1719// run
18// backend=stage1
19// target=native
\ No newline at end of file
20// backend=llvm
21// target=native
test/cases/safety/vector integer addition overflow.zig +6-4
......@@ -1,9 +1,11 @@
11const std = @import("std");
22
33pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
4 _ = message;
54 _ = stack_trace;
6 std.process.exit(0);
5 if (std.mem.eql(u8, message, "integer overflow")) {
6 std.process.exit(0);
7 }
8 std.process.exit(1);
79}
810pub fn main() !void {
911 var a: @Vector(4, i32) = [_]i32{ 1, 2, 2147483643, 4 };
......@@ -16,5 +18,5 @@ fn add(a: @Vector(4, i32), b: @Vector(4, i32)) @Vector(4, i32) {
1618 return a + b;
1719}
1820// run
19// backend=stage1
20// target=native
\ No newline at end of file
21// backend=llvm
22// target=native
test/cases/safety/vector integer multiplication overflow.zig +6-4
......@@ -1,9 +1,11 @@
11const std = @import("std");
22
33pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
4 _ = message;
54 _ = stack_trace;
6 std.process.exit(0);
5 if (std.mem.eql(u8, message, "integer overflow")) {
6 std.process.exit(0);
7 }
8 std.process.exit(1);
79}
810pub fn main() !void {
911 var a: @Vector(4, u8) = [_]u8{ 1, 2, 200, 4 };
......@@ -16,5 +18,5 @@ fn mul(a: @Vector(4, u8), b: @Vector(4, u8)) @Vector(4, u8) {
1618 return a * b;
1719}
1820// run
19// backend=stage1
20// target=native
\ No newline at end of file
21// backend=llvm
22// target=native
test/cases/safety/vector integer negation overflow.zig +6-4
......@@ -1,9 +1,11 @@
11const std = @import("std");
22
33pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
4 _ = message;
54 _ = stack_trace;
6 std.process.exit(0);
5 if (std.mem.eql(u8, message, "integer overflow")) {
6 std.process.exit(0);
7 }
8 std.process.exit(1);
79}
810pub fn main() !void {
911 var a: @Vector(4, i16) = [_]i16{ 1, -32768, 200, 4 };
......@@ -15,5 +17,5 @@ fn neg(a: @Vector(4, i16)) @Vector(4, i16) {
1517 return -a;
1618}
1719// run
18// backend=stage1
19// target=native
\ No newline at end of file
20// backend=llvm
21// target=native
test/cases/safety/vector integer subtraction overflow.zig +6-4
......@@ -1,9 +1,11 @@
11const std = @import("std");
22
33pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
4 _ = message;
54 _ = stack_trace;
6 std.process.exit(0);
5 if (std.mem.eql(u8, message, "integer overflow")) {
6 std.process.exit(0);
7 }
8 std.process.exit(1);
79}
810pub fn main() !void {
911 var a: @Vector(4, u32) = [_]u32{ 1, 2, 8, 4 };
......@@ -16,5 +18,5 @@ fn sub(a: @Vector(4, u32), b: @Vector(4, u32)) @Vector(4, u32) {
1618 return a - b;
1719}
1820// run
19// backend=stage1
20// target=native
\ No newline at end of file
21// backend=llvm
22// target=native