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...@@ -6504,8 +6504,7 @@ fn ret(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Inst.Ref
6504 },6504 },
6505 .always => {6505 .always => {
6506 // Value is always an error. Emit both error defers and regular defers.6506 // 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;6507 const err_code = if (rl == .ptr) try gz.addUnNode(.load, rl.ptr, node) else operand;
6508 const err_code = try gz.addUnNode(.err_union_code, result, node);
6509 try genDefers(gz, defer_outer, scope, .{ .both = err_code });6508 try genDefers(gz, defer_outer, scope, .{ .both = err_code });
6510 try gz.addRet(rl, operand, node);6509 try gz.addRet(rl, operand, node);
6511 return Zir.Inst.Ref.unreachable_value;6510 return Zir.Inst.Ref.unreachable_value;
test/cases/safety/@errSetCast error not present in destination.zig +6-4
...@@ -1,9 +1,11 @@...@@ -1,9 +1,11 @@
1const std = @import("std");1const std = @import("std");
22
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
4 _ = message;
5 _ = stack_trace;4 _ = 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);
7}9}
8const Set1 = error{A, B};10const Set1 = error{A, B};
9const Set2 = error{A, C};11const Set2 = error{A, C};
...@@ -15,5 +17,5 @@ fn foo(set1: Set1) Set2 {...@@ -15,5 +17,5 @@ fn foo(set1: Set1) Set2 {
15 return @errSetCast(Set2, set1);17 return @errSetCast(Set2, set1);
16}18}
17// run19// 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 @@...@@ -1,9 +1,11 @@
1const std = @import("std");1const std = @import("std");
22
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
4 _ = message;
5 _ = stack_trace;4 _ = 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);
7}9}
810
9pub fn main() !void {11pub fn main() !void {
...@@ -16,5 +18,5 @@ fn bar(one: u1, not_zero: i32) void {...@@ -16,5 +18,5 @@ fn bar(one: u1, not_zero: i32) void {
16 _ = x;18 _ = x;
17}19}
18// run20// 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 @@...@@ -1,9 +1,11 @@
1const std = @import("std");1const std = @import("std");
22
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
4 _ = message;
5 _ = stack_trace;4 _ = 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);
7}9}
8pub fn main() !void {10pub fn main() !void {
9 var zero: usize = 0;11 var zero: usize = 0;
...@@ -12,5 +14,5 @@ pub fn main() !void {...@@ -12,5 +14,5 @@ pub fn main() !void {
12 return error.TestFailed;14 return error.TestFailed;
13}15}
14// run16// run
15// backend=stage117// backend=llvm
16// target=native18// target=native
test/cases/safety/@intToPtr address zero to non-optional pointer.zig +5-3
...@@ -1,9 +1,11 @@...@@ -1,9 +1,11 @@
1const std = @import("std");1const std = @import("std");
22
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
4 _ = message;
5 _ = stack_trace;4 _ = 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);
7}9}
8pub fn main() !void {10pub fn main() !void {
9 var zero: usize = 0;11 var zero: usize = 0;
...@@ -12,5 +14,5 @@ pub fn main() !void {...@@ -12,5 +14,5 @@ pub fn main() !void {
12 return error.TestFailed;14 return error.TestFailed;
13}15}
14// run16// run
15// backend=stage117// backend=llvm
16// target=native18// target=native
test/cases/safety/calling panic.zig +2-2
...@@ -12,5 +12,5 @@ pub fn main() !void {...@@ -12,5 +12,5 @@ pub fn main() !void {
12 return error.TestFailed;12 return error.TestFailed;
13}13}
14// run14// 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 @@...@@ -1,9 +1,11 @@
1const std = @import("std");1const std = @import("std");
22
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
4 _ = message;
5 _ = stack_trace;4 _ = 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);
7}9}
8pub fn main() !void {10pub fn main() !void {
9 bar(9999) catch {};11 bar(9999) catch {};
...@@ -13,5 +15,5 @@ fn bar(x: u16) anyerror {...@@ -13,5 +15,5 @@ fn bar(x: u16) anyerror {
13 return @intToError(x);15 return @intToError(x);
14}16}
15// run17// 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 {...@@ -14,5 +14,5 @@ pub fn main() !void {
14 return error.TestFailed;14 return error.TestFailed;
15}15}
16// run16// run
17// backend=stage117// backend=llvm
18// target=native18// target=native
test/cases/safety/integer addition overflow.zig +1-1
...@@ -19,5 +19,5 @@ fn add(a: u16, b: u16) u16 {...@@ -19,5 +19,5 @@ fn add(a: u16, b: u16) u16 {
19}19}
2020
21// run21// run
22// backend=stage122// backend=llvm
23// target=native23// target=native
test/cases/safety/integer multiplication overflow.zig +6-4
...@@ -1,9 +1,11 @@...@@ -1,9 +1,11 @@
1const std = @import("std");1const std = @import("std");
22
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
4 _ = message;
5 _ = stack_trace;4 _ = 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);
7}9}
810
9pub fn main() !void {11pub fn main() !void {
...@@ -15,5 +17,5 @@ fn mul(a: u16, b: u16) u16 {...@@ -15,5 +17,5 @@ fn mul(a: u16, b: u16) u16 {
15 return a * b;17 return a * b;
16}18}
17// run19// 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 @@...@@ -1,9 +1,11 @@
1const std = @import("std");1const std = @import("std");
22
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
4 _ = message;
5 _ = stack_trace;4 _ = 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);
7}9}
810
9pub fn main() !void {11pub fn main() !void {
...@@ -15,5 +17,5 @@ fn neg(a: i16) i16 {...@@ -15,5 +17,5 @@ fn neg(a: i16) i16 {
15 return -a;17 return -a;
16}18}
17// run19// 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 @@...@@ -1,9 +1,11 @@
1const std = @import("std");1const std = @import("std");
22
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
4 _ = message;
5 _ = stack_trace;4 _ = 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);
7}9}
810
9pub fn main() !void {11pub fn main() !void {
...@@ -15,5 +17,5 @@ fn sub(a: u16, b: u16) u16 {...@@ -15,5 +17,5 @@ fn sub(a: u16, b: u16) u16 {
15 return a - b;17 return a - b;
16}18}
17// run19// 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 @@...@@ -1,9 +1,11 @@
1const std = @import("std");1const std = @import("std");
22
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
4 _ = message;
5 _ = stack_trace;4 _ = 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);
7}9}
8pub fn main() !void {10pub fn main() !void {
9 var ptr: [*c]i32 = null;11 var ptr: [*c]i32 = null;
...@@ -12,5 +14,5 @@ pub fn main() !void {...@@ -12,5 +14,5 @@ pub fn main() !void {
12 return error.TestFailed;14 return error.TestFailed;
13}15}
14// run16// run
15// backend=stage117// backend=llvm
16// target=native18// target=native
test/cases/safety/optional unwrap operator on null pointer.zig +5-3
...@@ -1,9 +1,11 @@...@@ -1,9 +1,11 @@
1const std = @import("std");1const std = @import("std");
22
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
4 _ = message;
5 _ = stack_trace;4 _ = 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);
7}9}
8pub fn main() !void {10pub fn main() !void {
9 var ptr: ?*i32 = null;11 var ptr: ?*i32 = null;
...@@ -12,5 +14,5 @@ pub fn main() !void {...@@ -12,5 +14,5 @@ pub fn main() !void {
12 return error.TestFailed;14 return error.TestFailed;
13}15}
14// run16// run
15// backend=stage117// backend=llvm
16// target=native18// target=native
test/cases/safety/out of bounds slice access.zig +6-4
...@@ -1,9 +1,11 @@...@@ -1,9 +1,11 @@
1const std = @import("std");1const std = @import("std");
22
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
4 _ = message;
5 _ = stack_trace;4 _ = 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);
7}9}
8pub fn main() !void {10pub fn main() !void {
9 const a = [_]i32{1, 2, 3, 4};11 const a = [_]i32{1, 2, 3, 4};
...@@ -15,5 +17,5 @@ fn bar(a: []const i32) i32 {...@@ -15,5 +17,5 @@ fn bar(a: []const i32) i32 {
15}17}
16fn baz(_: i32) void { }18fn baz(_: i32) void { }
17// run19// 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 @@...@@ -1,9 +1,11 @@
1const std = @import("std");1const std = @import("std");
22
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
4 _ = message;
5 _ = stack_trace;4 _ = 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);
7}9}
810
9pub fn main() !void {11pub fn main() !void {
...@@ -15,5 +17,5 @@ fn shl(a: i16, b: u4) i16 {...@@ -15,5 +17,5 @@ fn shl(a: i16, b: u4) i16 {
15 return @shlExact(a, b);17 return @shlExact(a, b);
16}18}
17// run19// 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 {...@@ -16,5 +16,5 @@ pub fn main() !void {
16}16}
1717
18// run18// run
19// backend=stage119// backend=llvm
20// target=native20// 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 @@...@@ -1,9 +1,11 @@
1const std = @import("std");1const std = @import("std");
22
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
4 _ = message;
5 _ = stack_trace;4 _ = 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);
7}9}
8pub fn main() !void {10pub fn main() !void {
9 var value: u8 = 245;11 var value: u8 = 245;
...@@ -12,5 +14,5 @@ pub fn main() !void {...@@ -12,5 +14,5 @@ pub fn main() !void {
12 return error.TestFailed;14 return error.TestFailed;
13}15}
14// run16// 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 @@...@@ -1,9 +1,11 @@
1const std = @import("std");1const std = @import("std");
22
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
4 _ = message;
5 _ = stack_trace;4 _ = 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);
7}9}
810
9pub fn main() !void {11pub fn main() !void {
...@@ -15,5 +17,5 @@ fn shl(a: u16, b: u4) u16 {...@@ -15,5 +17,5 @@ fn shl(a: u16, b: u4) u16 {
15 return @shlExact(a, b);17 return @shlExact(a, b);
16}18}
17// run19// 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 {...@@ -16,5 +16,5 @@ pub fn main() !void {
16}16}
1717
18// run18// run
19// backend=stage119// backend=llvm
20// target=native20// target=native
test/cases/safety/unwrap error.zig +2-2
...@@ -15,5 +15,5 @@ fn bar() !void {...@@ -15,5 +15,5 @@ fn bar() !void {
15 return error.Whatever;15 return error.Whatever;
16}16}
17// run17// 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 @@...@@ -1,9 +1,11 @@
1const std = @import("std");1const std = @import("std");
22
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
4 _ = message;
5 _ = stack_trace;4 _ = 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);
7}9}
810
9pub fn main() !void {11pub fn main() !void {
...@@ -15,5 +17,5 @@ fn shorten_cast(x: u8) u0 {...@@ -15,5 +17,5 @@ fn shorten_cast(x: u8) u0 {
15 return @intCast(u0, x);17 return @intCast(u0, x);
16}18}
17// run19// 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 @@...@@ -1,9 +1,11 @@
1const std = @import("std");1const std = @import("std");
22
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
4 _ = message;
5 _ = stack_trace;4 _ = 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);
7}9}
810
9pub fn main() !void {11pub fn main() !void {
...@@ -15,5 +17,5 @@ fn shorten_cast(x: i32) i8 {...@@ -15,5 +17,5 @@ fn shorten_cast(x: i32) i8 {
15 return @intCast(i8, x);17 return @intCast(i8, x);
16}18}
17// run19// 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 @@...@@ -1,9 +1,11 @@
1const std = @import("std");1const std = @import("std");
22
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
4 _ = message;
5 _ = stack_trace;4 _ = 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);
7}9}
8pub fn main() !void {10pub fn main() !void {
9 var a: @Vector(4, i32) = [_]i32{ 1, 2, 2147483643, 4 };11 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) {...@@ -16,5 +18,5 @@ fn add(a: @Vector(4, i32), b: @Vector(4, i32)) @Vector(4, i32) {
16 return a + b;18 return a + b;
17}19}
18// run20// 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 @@...@@ -1,9 +1,11 @@
1const std = @import("std");1const std = @import("std");
22
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
4 _ = message;
5 _ = stack_trace;4 _ = 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);
7}9}
8pub fn main() !void {10pub fn main() !void {
9 var a: @Vector(4, u8) = [_]u8{ 1, 2, 200, 4 };11 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) {...@@ -16,5 +18,5 @@ fn mul(a: @Vector(4, u8), b: @Vector(4, u8)) @Vector(4, u8) {
16 return a * b;18 return a * b;
17}19}
18// run20// 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 @@...@@ -1,9 +1,11 @@
1const std = @import("std");1const std = @import("std");
22
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
4 _ = message;
5 _ = stack_trace;4 _ = 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);
7}9}
8pub fn main() !void {10pub fn main() !void {
9 var a: @Vector(4, i16) = [_]i16{ 1, -32768, 200, 4 };11 var a: @Vector(4, i16) = [_]i16{ 1, -32768, 200, 4 };
...@@ -15,5 +17,5 @@ fn neg(a: @Vector(4, i16)) @Vector(4, i16) {...@@ -15,5 +17,5 @@ fn neg(a: @Vector(4, i16)) @Vector(4, i16) {
15 return -a;17 return -a;
16}18}
17// run19// 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 @@...@@ -1,9 +1,11 @@
1const std = @import("std");1const std = @import("std");
22
3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {3pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
4 _ = message;
5 _ = stack_trace;4 _ = 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);
7}9}
8pub fn main() !void {10pub fn main() !void {
9 var a: @Vector(4, u32) = [_]u32{ 1, 2, 8, 4 };11 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) {...@@ -16,5 +18,5 @@ fn sub(a: @Vector(4, u32), b: @Vector(4, u32)) @Vector(4, u32) {
16 return a - b;18 return a - b;
17}19}
18// run20// run
19// backend=stage1
20// target=native
\ No newline at end of file
21// backend=llvm
22// target=native