authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-05-17 15:25:27-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-05-17 15:25:27-07:00
log8cfa231104cc99c3a6c85a2ff691d89e6c856e89
treeee006a72e0ff06ef21f0fcb2b202fd24c203a1a0
parentf41892f73696edfddad5597ee927e7371a0891ad

update langref, compile-error tests, safety tests

for the std.builtin re-arranging

3 files changed, 225 insertions(+), 178 deletions(-)

doc/langref.html.in+15-16
......@@ -1099,7 +1099,6 @@ const nan = std.math.nan(f128);
10991099 {#code_release_fast#}
11001100 {#code_disable_cache#}
11011101const std = @import("std");
1102const builtin = std.builtin;
11031102const big = @as(f64, 1 << 40);
11041103
11051104export fn foo_strict(x: f64) f64 {
......@@ -2603,7 +2602,7 @@ test "default struct initialization fields" {
26032602 </p>
26042603 {#code_begin|test#}
26052604const std = @import("std");
2606const builtin = std.builtin;
2605const native_endian = @import("builtin").target.cpu.arch.endian();
26072606const expect = std.testing.expect;
26082607
26092608const Full = packed struct {
......@@ -2625,7 +2624,7 @@ fn doTheTest() !void {
26252624 try expect(@sizeOf(Divided) == 2);
26262625 var full = Full{ .number = 0x1234 };
26272626 var divided = @bitCast(Divided, full);
2628 switch (builtin.endian) {
2627 switch (native_endian) {
26292628 .Big => {
26302629 try expect(divided.half1 == 0x12);
26312630 try expect(divided.quarter3 == 0x3);
......@@ -4236,7 +4235,7 @@ test "noreturn" {
42364235 <p>Another use case for {#syntax#}noreturn{#endsyntax#} is the {#syntax#}exit{#endsyntax#} function:</p>
42374236 {#code_begin|test#}
42384237 {#target_windows#}
4239pub extern "kernel32" fn ExitProcess(exit_code: c_uint) callconv(if (@import("builtin").arch == .i386) .Stdcall else .C) noreturn;
4238pub extern "kernel32" fn ExitProcess(exit_code: c_uint) callconv(if (@import("builtin").target.cpu.arch == .i386) .Stdcall else .C) noreturn;
42404239
42414240test "foo" {
42424241 const value = bar() catch ExitProcess(1);
......@@ -4271,7 +4270,7 @@ export fn sub(a: i8, b: i8) i8 { return a - b; }
42714270// at link time, when linking statically, or at runtime, when linking
42724271// dynamically.
42734272// The callconv specifier changes the calling convention of the function.
4274extern "kernel32" fn ExitProcess(exit_code: u32) callconv(if (@import("builtin").arch == .i386) .Stdcall else .C) noreturn;
4273extern "kernel32" fn ExitProcess(exit_code: u32) callconv(if (@import("builtin").target.cpu.arch == .i386) .Stdcall else .C) noreturn;
42754274extern "c" fn atan2(a: f64, b: f64) f64;
42764275
42774276// The @setCold builtin tells the optimizer that a function is rarely called.
......@@ -7577,7 +7576,7 @@ export fn @"A function name that is a complete sentence."() void {}
75777576 The {#syntax#}fence{#endsyntax#} function is used to introduce happens-before edges between operations.
75787577 </p>
75797578 <p>
7580 {#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("builtin").AtomicOrder{#endsyntax#}.
7579 {#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("std").builtin.AtomicOrder{#endsyntax#}.
75817580 </p>
75827581 {#see_also|Compile Variables#}
75837582 {#header_close#}
......@@ -7780,8 +7779,8 @@ test "@hasDecl" {
77807779 </p>
77817780 <ul>
77827781 <li>{#syntax#}@import("std"){#endsyntax#} - Zig Standard Library</li>
7783 <li>{#syntax#}@import("builtin"){#endsyntax#} - Compiler-provided types and variables.
7784 The command <code>zig builtin</code> outputs the source to stdout for reference.
7782 <li>{#syntax#}@import("builtin"){#endsyntax#} - Target-specific information
7783 The command <code>zig build-exe --show-builtin</code> outputs the source to stdout for reference.
77857784 </li>
77867785 </ul>
77877786 {#see_also|Compile Variables|@embedFile#}
......@@ -7912,11 +7911,11 @@ mem.set(u8, dest, c);{#endsyntax#}</pre>
79127911 </p>
79137912 {#code_begin|test#}
79147913const std = @import("std");
7915const builtin = @import("builtin");
7914const native_arch = @import("builtin").target.cpu.arch;
79167915const expect = std.testing.expect;
79177916
79187917test "@wasmMemoryGrow" {
7919 if (builtin.arch != .wasm32) return error.SkipZigTest;
7918 if (native_arch != .wasm32) return error.SkipZigTest;
79207919
79217920 var prev = @wasmMemorySize(0);
79227921 try expect(prev == @wasmMemoryGrow(0, 1));
......@@ -8084,7 +8083,7 @@ test "foo" {
80848083 {#header_close#}
80858084
80868085 {#header_open|@setFloatMode#}
8087 <pre>{#syntax#}@setFloatMode(mode: @import("builtin").FloatMode){#endsyntax#}</pre>
8086 <pre>{#syntax#}@setFloatMode(mode: @import("std").builtin.FloatMode){#endsyntax#}</pre>
80888087 <p>
80898088 Sets the floating point mode of the current scope. Possible values are:
80908089 </p>
......@@ -8273,7 +8272,7 @@ test "vector @splat" {
82738272 {#header_close#}
82748273
82758274 {#header_open|@reduce#}
8276 <pre>{#syntax#}@reduce(comptime op: builtin.ReduceOp, value: anytype) std.meta.Child(value){#endsyntax#}</pre>
8275 <pre>{#syntax#}@reduce(comptime op: std.builtin.ReduceOp, value: anytype) std.meta.Child(value){#endsyntax#}</pre>
82778276 <p>
82788277 Transforms a {#link|vector|Vectors#} into a scalar value by performing a
82798278 sequential horizontal reduction of its elements using the specified operator {#syntax#}op{#endsyntax#}.
......@@ -8565,7 +8564,7 @@ test "integer truncation" {
85658564 {#header_close#}
85668565
85678566 {#header_open|@Type#}
8568 <pre>{#syntax#}@Type(comptime info: @import("builtin").TypeInfo) type{#endsyntax#}</pre>
8567 <pre>{#syntax#}@Type(comptime info: std.builtin.TypeInfo) type{#endsyntax#}</pre>
85698568 <p>
85708569 This function is the inverse of {#link|@typeInfo#}. It reifies type information
85718570 into a {#syntax#}type{#endsyntax#}.
......@@ -8607,7 +8606,7 @@ test "integer truncation" {
86078606 </ul>
86088607 {#header_close#}
86098608 {#header_open|@typeInfo#}
8610 <pre>{#syntax#}@typeInfo(comptime T: type) @import("std").builtin.TypeInfo{#endsyntax#}</pre>
8609 <pre>{#syntax#}@typeInfo(comptime T: type) std.builtin.TypeInfo{#endsyntax#}</pre>
86118610 <p>
86128611 Provides type reflection.
86138612 </p>
......@@ -9628,7 +9627,7 @@ test "string literal to constant slice" {
96289627 </p>
96299628 {#code_begin|syntax#}
96309629const builtin = @import("builtin");
9631const separator = if (builtin.os == builtin.Os.windows) '\\' else '/';
9630const separator = if (builtin.os.tag == builtin.Os.windows) '\\' else '/';
96329631 {#code_end#}
96339632 <p>
96349633 Example of what is imported with {#syntax#}@import("builtin"){#endsyntax#}:
......@@ -9653,7 +9652,7 @@ const separator = if (builtin.os == builtin.Os.windows) '\\' else '/';
96539652 </p>
96549653 {#code_begin|test|detect_test#}
96559654const std = @import("std");
9656const builtin = std.builtin;
9655const builtin = @import("builtin");
96579656const expect = std.testing.expect;
96589657
96599658test "builtin.is_test" {
test/compile_errors.zig+24-24
......@@ -208,7 +208,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
208208 });
209209
210210 cases.add("@Type with TypeInfo.Int",
211 \\const builtin = @import("builtin");
211 \\const builtin = @import("std").builtin;
212212 \\export fn entry() void {
213213 \\ _ = @Type(builtin.TypeInfo.Int {
214214 \\ .signedness = .signed,
......@@ -242,7 +242,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
242242 });
243243
244244 cases.add("@Type for exhaustive enum with undefined tag type",
245 \\const TypeInfo = @import("builtin").TypeInfo;
245 \\const TypeInfo = @import("std").builtin.TypeInfo;
246246 \\const Tag = @Type(.{
247247 \\ .Enum = .{
248248 \\ .layout = .Auto,
......@@ -272,7 +272,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
272272 });
273273
274274 cases.add("@Type for exhaustive enum with non-integer tag type",
275 \\const TypeInfo = @import("builtin").TypeInfo;
275 \\const TypeInfo = @import("std").builtin.TypeInfo;
276276 \\const Tag = @Type(.{
277277 \\ .Enum = .{
278278 \\ .layout = .Auto,
......@@ -331,7 +331,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
331331 });
332332
333333 cases.add("@Type for tagged union with extra enum field",
334 \\const TypeInfo = @import("builtin").TypeInfo;
334 \\const TypeInfo = @import("std").builtin.TypeInfo;
335335 \\const Tag = @Type(.{
336336 \\ .Enum = .{
337337 \\ .layout = .Auto,
......@@ -397,7 +397,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
397397 \\ .is_generic = true,
398398 \\ .is_var_args = false,
399399 \\ .return_type = u0,
400 \\ .args = &[_]@import("builtin").TypeInfo.FnArg{},
400 \\ .args = &[_]@import("std").builtin.TypeInfo.FnArg{},
401401 \\ },
402402 \\});
403403 \\comptime { _ = Foo; }
......@@ -413,7 +413,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
413413 \\ .is_generic = false,
414414 \\ .is_var_args = true,
415415 \\ .return_type = u0,
416 \\ .args = &[_]@import("builtin").TypeInfo.FnArg{},
416 \\ .args = &[_]@import("std").builtin.TypeInfo.FnArg{},
417417 \\ },
418418 \\});
419419 \\comptime { _ = Foo; }
......@@ -429,7 +429,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
429429 \\ .is_generic = false,
430430 \\ .is_var_args = false,
431431 \\ .return_type = null,
432 \\ .args = &[_]@import("builtin").TypeInfo.FnArg{},
432 \\ .args = &[_]@import("std").builtin.TypeInfo.FnArg{},
433433 \\ },
434434 \\});
435435 \\comptime { _ = Foo; }
......@@ -438,7 +438,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
438438 });
439439
440440 cases.add("@Type for union with opaque field",
441 \\const TypeInfo = @import("builtin").TypeInfo;
441 \\const TypeInfo = @import("std").builtin.TypeInfo;
442442 \\const Untagged = @Type(.{
443443 \\ .Union = .{
444444 \\ .layout = .Auto,
......@@ -474,7 +474,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
474474 });
475475
476476 cases.add("@Type for union with zero fields",
477 \\const TypeInfo = @import("builtin").TypeInfo;
477 \\const TypeInfo = @import("std").builtin.TypeInfo;
478478 \\const Untagged = @Type(.{
479479 \\ .Union = .{
480480 \\ .layout = .Auto,
......@@ -492,7 +492,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
492492 });
493493
494494 cases.add("@Type for exhaustive enum with zero fields",
495 \\const TypeInfo = @import("builtin").TypeInfo;
495 \\const TypeInfo = @import("std").builtin.TypeInfo;
496496 \\const Tag = @Type(.{
497497 \\ .Enum = .{
498498 \\ .layout = .Auto,
......@@ -511,7 +511,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
511511 });
512512
513513 cases.add("@Type for tagged union with extra union field",
514 \\const TypeInfo = @import("builtin").TypeInfo;
514 \\const TypeInfo = @import("std").builtin.TypeInfo;
515515 \\const Tag = @Type(.{
516516 \\ .Enum = .{
517517 \\ .layout = .Auto,
......@@ -1946,7 +1946,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
19461946 });
19471947
19481948 cases.add("attempt to create 17 bit float type",
1949 \\const builtin = @import("builtin");
1949 \\const builtin = @import("std").builtin;
19501950 \\comptime {
19511951 \\ _ = @Type(builtin.TypeInfo { .Float = builtin.TypeInfo.Float { .bits = 17 } });
19521952 \\}
......@@ -1963,7 +1963,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
19631963 });
19641964
19651965 cases.add("@Type with non-constant expression",
1966 \\const builtin = @import("builtin");
1966 \\const builtin = @import("std").builtin;
19671967 \\var globalTypeInfo : builtin.TypeInfo = undefined;
19681968 \\export fn entry() void {
19691969 \\ _ = @Type(globalTypeInfo);
......@@ -5963,7 +5963,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
59635963 });
59645964
59655965 cases.add("atomic orderings of cmpxchg - failure stricter than success",
5966 \\const AtomicOrder = @import("builtin").AtomicOrder;
5966 \\const AtomicOrder = @import("std").builtin.AtomicOrder;
59675967 \\export fn f() void {
59685968 \\ var x: i32 = 1234;
59695969 \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.Monotonic, AtomicOrder.SeqCst)) {}
......@@ -5973,7 +5973,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
59735973 });
59745974
59755975 cases.add("atomic orderings of cmpxchg - success Monotonic or stricter",
5976 \\const AtomicOrder = @import("builtin").AtomicOrder;
5976 \\const AtomicOrder = @import("std").builtin.AtomicOrder;
59775977 \\export fn f() void {
59785978 \\ var x: i32 = 1234;
59795979 \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.Unordered, AtomicOrder.Unordered)) {}
......@@ -6579,12 +6579,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
65796579 });
65806580
65816581 cases.add("invalid member of builtin enum",
6582 \\const builtin = @import("builtin",);
6582 \\const builtin = @import("std").builtin;
65836583 \\export fn entry() void {
6584 \\ const foo = builtin.Arch.x86;
6584 \\ const foo = builtin.Mode.x86;
65856585 \\}
65866586 , &[_][]const u8{
6587 "tmp.zig:3:29: error: container 'std.target.Arch' has no member called 'x86'",
6587 "tmp.zig:3:29: error: container 'std.builtin.Mode' has no member called 'x86'",
65886588 });
65896589
65906590 cases.add("int to ptr of 0 bits",
......@@ -6853,8 +6853,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
68536853
68546854 cases.add("@setFloatMode twice for same scope",
68556855 \\export fn foo() void {
6856 \\ @setFloatMode(@import("builtin").FloatMode.Optimized);
6857 \\ @setFloatMode(@import("builtin").FloatMode.Optimized);
6856 \\ @setFloatMode(@import("std").builtin.FloatMode.Optimized);
6857 \\ @setFloatMode(@import("std").builtin.FloatMode.Optimized);
68586858 \\}
68596859 , &[_][]const u8{
68606860 "tmp.zig:3:5: error: float mode set twice for same scope",
......@@ -7066,7 +7066,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
70667066 });
70677067
70687068 cases.add("passing a not-aligned-enough pointer to cmpxchg",
7069 \\const AtomicOrder = @import("builtin").AtomicOrder;
7069 \\const AtomicOrder = @import("std").builtin.AtomicOrder;
70707070 \\export fn entry() bool {
70717071 \\ var x: i32 align(1) = 1234;
70727072 \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) {}
......@@ -7233,7 +7233,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
72337233 });
72347234
72357235 cases.add("storing runtime value in compile time variable then using it",
7236 \\const Mode = @import("builtin").Mode;
7236 \\const Mode = @import("std").builtin.Mode;
72377237 \\
72387238 \\fn Free(comptime filename: []const u8) TestCase {
72397239 \\ return TestCase {
......@@ -7776,11 +7776,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
77767776 cases.addTest("nested vectors",
77777777 \\export fn entry() void {
77787778 \\ const V1 = @import("std").meta.Vector(4, u8);
7779 \\ const V2 = @Type(@import("builtin").TypeInfo{ .Vector = .{ .len = 4, .child = V1 } });
7779 \\ const V2 = @Type(@import("std").builtin.TypeInfo{ .Vector = .{ .len = 4, .child = V1 } });
77807780 \\ var v: V2 = undefined;
77817781 \\}
77827782 , &[_][]const u8{
7783 "tmp.zig:3:49: error: vector element type must be integer, float, bool, or pointer; '@Vector(4, u8)' is invalid",
7783 "tmp.zig:3:53: error: vector element type must be integer, float, bool, or pointer; '@Vector(4, u8)' is invalid",
77847784 "tmp.zig:3:16: note: referenced here",
77857785 });
77867786
test/runtime_safety.zig+186-138
......@@ -3,7 +3,7 @@ const tests = @import("tests.zig");
33pub fn addCases(cases: *tests.CompareOutputContext) void {
44 {
55 const check_panic_msg =
6 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
6 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
77 \\ if (std.mem.eql(u8, message, "reached unreachable code")) {
88 \\ std.process.exit(126); // good
99 \\ }
......@@ -44,7 +44,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
4444
4545 {
4646 const check_panic_msg =
47 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
47 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
4848 \\ if (std.mem.eql(u8, message, "invalid enum value")) {
4949 \\ std.process.exit(126); // good
5050 \\ }
......@@ -82,7 +82,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
8282
8383 {
8484 const check_panic_msg =
85 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
85 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
8686 \\ if (std.mem.eql(u8, message, "index out of bounds")) {
8787 \\ std.process.exit(126); // good
8888 \\ }
......@@ -152,7 +152,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
152152 cases.addRuntimeSafety("truncating vector cast",
153153 \\const std = @import("std");
154154 \\const V = @import("std").meta.Vector;
155 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
155 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
156156 \\ if (std.mem.eql(u8, message, "integer cast truncated bits")) {
157157 \\ std.process.exit(126); // good
158158 \\ }
......@@ -167,7 +167,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
167167 cases.addRuntimeSafety("unsigned-signed vector cast",
168168 \\const std = @import("std");
169169 \\const V = @import("std").meta.Vector;
170 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
170 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
171171 \\ if (std.mem.eql(u8, message, "integer cast truncated bits")) {
172172 \\ std.process.exit(126); // good
173173 \\ }
......@@ -182,7 +182,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
182182 cases.addRuntimeSafety("signed-unsigned vector cast",
183183 \\const std = @import("std");
184184 \\const V = @import("std").meta.Vector;
185 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
185 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
186186 \\ if (std.mem.eql(u8, message, "attempt to cast negative value to unsigned integer")) {
187187 \\ std.process.exit(126); // good
188188 \\ }
......@@ -196,7 +196,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
196196
197197 cases.addRuntimeSafety("shift left by huge amount",
198198 \\const std = @import("std");
199 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
199 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
200200 \\ if (std.mem.eql(u8, message, "shift amount is greater than the type size")) {
201201 \\ std.process.exit(126); // good
202202 \\ }
......@@ -211,7 +211,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
211211
212212 cases.addRuntimeSafety("shift right by huge amount",
213213 \\const std = @import("std");
214 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
214 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
215215 \\ if (std.mem.eql(u8, message, "shift amount is greater than the type size")) {
216216 \\ std.process.exit(126); // good
217217 \\ }
......@@ -226,7 +226,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
226226
227227 cases.addRuntimeSafety("slice sentinel mismatch - optional pointers",
228228 \\const std = @import("std");
229 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
229 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
230230 \\ if (std.mem.eql(u8, message, "sentinel mismatch")) {
231231 \\ std.process.exit(126); // good
232232 \\ }
......@@ -240,7 +240,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
240240
241241 cases.addRuntimeSafety("slice sentinel mismatch - floats",
242242 \\const std = @import("std");
243 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
243 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
244244 \\ if (std.mem.eql(u8, message, "sentinel mismatch")) {
245245 \\ std.process.exit(126); // good
246246 \\ }
......@@ -254,7 +254,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
254254
255255 cases.addRuntimeSafety("pointer slice sentinel mismatch",
256256 \\const std = @import("std");
257 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
257 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
258258 \\ if (std.mem.eql(u8, message, "sentinel mismatch")) {
259259 \\ std.process.exit(126); // good
260260 \\ }
......@@ -269,7 +269,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
269269
270270 cases.addRuntimeSafety("slice slice sentinel mismatch",
271271 \\const std = @import("std");
272 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
272 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
273273 \\ if (std.mem.eql(u8, message, "sentinel mismatch")) {
274274 \\ std.process.exit(126); // good
275275 \\ }
......@@ -284,7 +284,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
284284
285285 cases.addRuntimeSafety("array slice sentinel mismatch",
286286 \\const std = @import("std");
287 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
287 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
288288 \\ if (std.mem.eql(u8, message, "sentinel mismatch")) {
289289 \\ std.process.exit(126); // good
290290 \\ }
......@@ -298,7 +298,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
298298
299299 cases.addRuntimeSafety("intToPtr with misaligned address",
300300 \\const std = @import("std");
301 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
301 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
302302 \\ if (std.mem.eql(u8, message, "incorrect alignment")) {
303303 \\ std.os.exit(126); // good
304304 \\ }
......@@ -311,19 +311,20 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
311311 );
312312
313313 cases.addRuntimeSafety("resuming a non-suspended function which never been suspended",
314 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
315 \\ @import("std").os.exit(126);
314 \\const std = @import("std");
315 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
316 \\ std.os.exit(126);
316317 \\}
317318 \\fn foo() void {
318319 \\ var f = async bar(@frame());
319 \\ @import("std").os.exit(0);
320 \\ std.os.exit(0);
320321 \\}
321322 \\
322323 \\fn bar(frame: anyframe) void {
323324 \\ suspend {
324325 \\ resume frame;
325326 \\ }
326 \\ @import("std").os.exit(0);
327 \\ std.os.exit(0);
327328 \\}
328329 \\
329330 \\pub fn main() void {
......@@ -332,35 +333,37 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
332333 );
333334
334335 cases.addRuntimeSafety("resuming a non-suspended function which has been suspended and resumed",
335 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
336 \\ @import("std").os.exit(126);
336 \\const std = @import("std");
337 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
338 \\ std.os.exit(126);
337339 \\}
338340 \\fn foo() void {
339341 \\ suspend {
340342 \\ global_frame = @frame();
341343 \\ }
342344 \\ var f = async bar(@frame());
343 \\ @import("std").os.exit(0);
345 \\ std.os.exit(0);
344346 \\}
345347 \\
346348 \\fn bar(frame: anyframe) void {
347349 \\ suspend {
348350 \\ resume frame;
349351 \\ }
350 \\ @import("std").os.exit(0);
352 \\ std.os.exit(0);
351353 \\}
352354 \\
353355 \\var global_frame: anyframe = undefined;
354356 \\pub fn main() void {
355357 \\ _ = async foo();
356358 \\ resume global_frame;
357 \\ @import("std").os.exit(0);
359 \\ std.os.exit(0);
358360 \\}
359361 );
360362
361363 cases.addRuntimeSafety("nosuspend function call, callee suspends",
362 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
363 \\ @import("std").os.exit(126);
364 \\const std = @import("std");
365 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
366 \\ std.os.exit(126);
364367 \\}
365368 \\pub fn main() void {
366369 \\ _ = nosuspend add(101, 100);
......@@ -374,8 +377,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
374377 );
375378
376379 cases.addRuntimeSafety("awaiting twice",
377 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
378 \\ @import("std").os.exit(126);
380 \\const std = @import("std");
381 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
382 \\ std.os.exit(126);
379383 \\}
380384 \\var frame: anyframe = undefined;
381385 \\
......@@ -398,8 +402,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
398402 );
399403
400404 cases.addRuntimeSafety("@asyncCall with too small a frame",
401 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
402 \\ @import("std").os.exit(126);
405 \\const std = @import("std");
406 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
407 \\ std.os.exit(126);
403408 \\}
404409 \\pub fn main() void {
405410 \\ var bytes: [1]u8 align(16) = undefined;
......@@ -412,8 +417,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
412417 );
413418
414419 cases.addRuntimeSafety("resuming a function which is awaiting a frame",
415 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
416 \\ @import("std").os.exit(126);
420 \\const std = @import("std");
421 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
422 \\ std.os.exit(126);
417423 \\}
418424 \\pub fn main() void {
419425 \\ var frame = async first();
......@@ -429,8 +435,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
429435 );
430436
431437 cases.addRuntimeSafety("resuming a function which is awaiting a call",
432 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
433 \\ @import("std").os.exit(126);
438 \\const std = @import("std");
439 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
440 \\ std.os.exit(126);
434441 \\}
435442 \\pub fn main() void {
436443 \\ var frame = async first();
......@@ -445,8 +452,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
445452 );
446453
447454 cases.addRuntimeSafety("invalid resume of async function",
448 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
449 \\ @import("std").os.exit(126);
455 \\const std = @import("std");
456 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
457 \\ std.os.exit(126);
450458 \\}
451459 \\pub fn main() void {
452460 \\ var p = async suspendOnce();
......@@ -459,8 +467,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
459467 );
460468
461469 cases.addRuntimeSafety(".? operator on null pointer",
462 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
463 \\ @import("std").os.exit(126);
470 \\const std = @import("std");
471 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
472 \\ std.os.exit(126);
464473 \\}
465474 \\pub fn main() void {
466475 \\ var ptr: ?*i32 = null;
......@@ -469,8 +478,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
469478 );
470479
471480 cases.addRuntimeSafety(".? operator on C pointer",
472 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
473 \\ @import("std").os.exit(126);
481 \\const std = @import("std");
482 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
483 \\ std.os.exit(126);
474484 \\}
475485 \\pub fn main() void {
476486 \\ var ptr: [*c]i32 = null;
......@@ -479,8 +489,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
479489 );
480490
481491 cases.addRuntimeSafety("@intToPtr address zero to non-optional pointer",
482 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
483 \\ @import("std").os.exit(126);
492 \\const std = @import("std");
493 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
494 \\ std.os.exit(126);
484495 \\}
485496 \\pub fn main() void {
486497 \\ var zero: usize = 0;
......@@ -489,8 +500,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
489500 );
490501
491502 cases.addRuntimeSafety("@intToPtr address zero to non-optional byte-aligned pointer",
492 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
493 \\ @import("std").os.exit(126);
503 \\const std = @import("std");
504 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
505 \\ std.os.exit(126);
494506 \\}
495507 \\pub fn main() void {
496508 \\ var zero: usize = 0;
......@@ -499,8 +511,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
499511 );
500512
501513 cases.addRuntimeSafety("pointer casting null to non-optional pointer",
502 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
503 \\ @import("std").os.exit(126);
514 \\const std = @import("std");
515 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
516 \\ std.os.exit(126);
504517 \\}
505518 \\pub fn main() void {
506519 \\ var c_ptr: [*c]u8 = 0;
......@@ -509,8 +522,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
509522 );
510523
511524 cases.addRuntimeSafety("@intToEnum - no matching tag value",
512 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
513 \\ @import("std").os.exit(126);
525 \\const std = @import("std");
526 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
527 \\ std.os.exit(126);
514528 \\}
515529 \\const Foo = enum {
516530 \\ A,
......@@ -527,8 +541,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
527541 );
528542
529543 cases.addRuntimeSafety("@floatToInt cannot fit - negative to unsigned",
530 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
531 \\ @import("std").os.exit(126);
544 \\const std = @import("std");
545 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
546 \\ std.os.exit(126);
532547 \\}
533548 \\pub fn main() void {
534549 \\ baz(bar(-1.1));
......@@ -540,8 +555,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
540555 );
541556
542557 cases.addRuntimeSafety("@floatToInt cannot fit - negative out of range",
543 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
544 \\ @import("std").os.exit(126);
558 \\const std = @import("std");
559 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
560 \\ std.os.exit(126);
545561 \\}
546562 \\pub fn main() void {
547563 \\ baz(bar(-129.1));
......@@ -553,8 +569,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
553569 );
554570
555571 cases.addRuntimeSafety("@floatToInt cannot fit - positive out of range",
556 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
557 \\ @import("std").os.exit(126);
572 \\const std = @import("std");
573 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
574 \\ std.os.exit(126);
558575 \\}
559576 \\pub fn main() void {
560577 \\ baz(bar(256.2));
......@@ -566,8 +583,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
566583 );
567584
568585 cases.addRuntimeSafety("calling panic",
569 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
570 \\ @import("std").os.exit(126);
586 \\const std = @import("std");
587 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
588 \\ std.os.exit(126);
571589 \\}
572590 \\pub fn main() void {
573591 \\ @panic("oh no");
......@@ -575,8 +593,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
575593 );
576594
577595 cases.addRuntimeSafety("out of bounds slice access",
578 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
579 \\ @import("std").os.exit(126);
596 \\const std = @import("std");
597 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
598 \\ std.os.exit(126);
580599 \\}
581600 \\pub fn main() void {
582601 \\ const a = [_]i32{1, 2, 3, 4};
......@@ -589,8 +608,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
589608 );
590609
591610 cases.addRuntimeSafety("integer addition overflow",
592 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
593 \\ @import("std").os.exit(126);
611 \\const std = @import("std");
612 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
613 \\ std.os.exit(126);
594614 \\}
595615 \\pub fn main() !void {
596616 \\ const x = add(65530, 10);
......@@ -602,63 +622,68 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
602622 );
603623
604624 cases.addRuntimeSafety("vector integer addition overflow",
605 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
606 \\ @import("std").os.exit(126);
625 \\const std = @import("std");
626 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
627 \\ std.os.exit(126);
607628 \\}
608629 \\pub fn main() void {
609 \\ var a: @import("std").meta.Vector(4, i32) = [_]i32{ 1, 2, 2147483643, 4 };
610 \\ var b: @import("std").meta.Vector(4, i32) = [_]i32{ 5, 6, 7, 8 };
630 \\ var a: std.meta.Vector(4, i32) = [_]i32{ 1, 2, 2147483643, 4 };
631 \\ var b: std.meta.Vector(4, i32) = [_]i32{ 5, 6, 7, 8 };
611632 \\ const x = add(a, b);
612633 \\}
613 \\fn add(a: @import("std").meta.Vector(4, i32), b: @import("std").meta.Vector(4, i32)) @import("std").meta.Vector(4, i32) {
634 \\fn add(a: std.meta.Vector(4, i32), b: std.meta.Vector(4, i32)) std.meta.Vector(4, i32) {
614635 \\ return a + b;
615636 \\}
616637 );
617638
618639 cases.addRuntimeSafety("vector integer subtraction overflow",
619 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
620 \\ @import("std").os.exit(126);
640 \\const std = @import("std");
641 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
642 \\ std.os.exit(126);
621643 \\}
622644 \\pub fn main() void {
623 \\ var a: @import("std").meta.Vector(4, u32) = [_]u32{ 1, 2, 8, 4 };
624 \\ var b: @import("std").meta.Vector(4, u32) = [_]u32{ 5, 6, 7, 8 };
645 \\ var a: std.meta.Vector(4, u32) = [_]u32{ 1, 2, 8, 4 };
646 \\ var b: std.meta.Vector(4, u32) = [_]u32{ 5, 6, 7, 8 };
625647 \\ const x = sub(b, a);
626648 \\}
627 \\fn sub(a: @import("std").meta.Vector(4, u32), b: @import("std").meta.Vector(4, u32)) @import("std").meta.Vector(4, u32) {
649 \\fn sub(a: std.meta.Vector(4, u32), b: std.meta.Vector(4, u32)) std.meta.Vector(4, u32) {
628650 \\ return a - b;
629651 \\}
630652 );
631653
632654 cases.addRuntimeSafety("vector integer multiplication overflow",
633 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
634 \\ @import("std").os.exit(126);
655 \\const std = @import("std");
656 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
657 \\ std.os.exit(126);
635658 \\}
636659 \\pub fn main() void {
637 \\ var a: @import("std").meta.Vector(4, u8) = [_]u8{ 1, 2, 200, 4 };
638 \\ var b: @import("std").meta.Vector(4, u8) = [_]u8{ 5, 6, 2, 8 };
660 \\ var a: std.meta.Vector(4, u8) = [_]u8{ 1, 2, 200, 4 };
661 \\ var b: std.meta.Vector(4, u8) = [_]u8{ 5, 6, 2, 8 };
639662 \\ const x = mul(b, a);
640663 \\}
641 \\fn mul(a: @import("std").meta.Vector(4, u8), b: @import("std").meta.Vector(4, u8)) @import("std").meta.Vector(4, u8) {
664 \\fn mul(a: std.meta.Vector(4, u8), b: std.meta.Vector(4, u8)) std.meta.Vector(4, u8) {
642665 \\ return a * b;
643666 \\}
644667 );
645668
646669 cases.addRuntimeSafety("vector integer negation overflow",
647 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
648 \\ @import("std").os.exit(126);
670 \\const std = @import("std");
671 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
672 \\ std.os.exit(126);
649673 \\}
650674 \\pub fn main() void {
651 \\ var a: @import("std").meta.Vector(4, i16) = [_]i16{ 1, -32768, 200, 4 };
675 \\ var a: std.meta.Vector(4, i16) = [_]i16{ 1, -32768, 200, 4 };
652676 \\ const x = neg(a);
653677 \\}
654 \\fn neg(a: @import("std").meta.Vector(4, i16)) @import("std").meta.Vector(4, i16) {
678 \\fn neg(a: std.meta.Vector(4, i16)) std.meta.Vector(4, i16) {
655679 \\ return -a;
656680 \\}
657681 );
658682
659683 cases.addRuntimeSafety("integer subtraction overflow",
660 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
661 \\ @import("std").os.exit(126);
684 \\const std = @import("std");
685 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
686 \\ std.os.exit(126);
662687 \\}
663688 \\pub fn main() !void {
664689 \\ const x = sub(10, 20);
......@@ -670,8 +695,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
670695 );
671696
672697 cases.addRuntimeSafety("integer multiplication overflow",
673 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
674 \\ @import("std").os.exit(126);
698 \\const std = @import("std");
699 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
700 \\ std.os.exit(126);
675701 \\}
676702 \\pub fn main() !void {
677703 \\ const x = mul(300, 6000);
......@@ -683,8 +709,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
683709 );
684710
685711 cases.addRuntimeSafety("integer negation overflow",
686 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
687 \\ @import("std").os.exit(126);
712 \\const std = @import("std");
713 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
714 \\ std.os.exit(126);
688715 \\}
689716 \\pub fn main() !void {
690717 \\ const x = neg(-32768);
......@@ -696,8 +723,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
696723 );
697724
698725 cases.addRuntimeSafety("signed integer division overflow",
699 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
700 \\ @import("std").os.exit(126);
726 \\const std = @import("std");
727 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
728 \\ std.os.exit(126);
701729 \\}
702730 \\pub fn main() !void {
703731 \\ const x = div(-32768, -1);
......@@ -709,23 +737,25 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
709737 );
710738
711739 cases.addRuntimeSafety("signed integer division overflow - vectors",
712 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
713 \\ @import("std").os.exit(126);
740 \\const std = @import("std");
741 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
742 \\ std.os.exit(126);
714743 \\}
715744 \\pub fn main() !void {
716 \\ var a: @import("std").meta.Vector(4, i16) = [_]i16{ 1, 2, -32768, 4 };
717 \\ var b: @import("std").meta.Vector(4, i16) = [_]i16{ 1, 2, -1, 4 };
745 \\ var a: std.meta.Vector(4, i16) = [_]i16{ 1, 2, -32768, 4 };
746 \\ var b: std.meta.Vector(4, i16) = [_]i16{ 1, 2, -1, 4 };
718747 \\ const x = div(a, b);
719748 \\ if (x[2] == 32767) return error.Whatever;
720749 \\}
721 \\fn div(a: @import("std").meta.Vector(4, i16), b: @import("std").meta.Vector(4, i16)) @import("std").meta.Vector(4, i16) {
750 \\fn div(a: std.meta.Vector(4, i16), b: std.meta.Vector(4, i16)) std.meta.Vector(4, i16) {
722751 \\ return @divTrunc(a, b);
723752 \\}
724753 );
725754
726755 cases.addRuntimeSafety("signed shift left overflow",
727 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
728 \\ @import("std").os.exit(126);
756 \\const std = @import("std");
757 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
758 \\ std.os.exit(126);
729759 \\}
730760 \\pub fn main() !void {
731761 \\ const x = shl(-16385, 1);
......@@ -737,8 +767,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
737767 );
738768
739769 cases.addRuntimeSafety("unsigned shift left overflow",
740 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
741 \\ @import("std").os.exit(126);
770 \\const std = @import("std");
771 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
772 \\ std.os.exit(126);
742773 \\}
743774 \\pub fn main() !void {
744775 \\ const x = shl(0b0010111111111111, 3);
......@@ -750,8 +781,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
750781 );
751782
752783 cases.addRuntimeSafety("signed shift right overflow",
753 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
754 \\ @import("std").os.exit(126);
784 \\const std = @import("std");
785 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
786 \\ std.os.exit(126);
755787 \\}
756788 \\pub fn main() !void {
757789 \\ const x = shr(-16385, 1);
......@@ -763,8 +795,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
763795 );
764796
765797 cases.addRuntimeSafety("unsigned shift right overflow",
766 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
767 \\ @import("std").os.exit(126);
798 \\const std = @import("std");
799 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
800 \\ std.os.exit(126);
768801 \\}
769802 \\pub fn main() !void {
770803 \\ const x = shr(0b0010111111111111, 3);
......@@ -776,8 +809,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
776809 );
777810
778811 cases.addRuntimeSafety("integer division by zero",
779 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
780 \\ @import("std").os.exit(126);
812 \\const std = @import("std");
813 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
814 \\ std.os.exit(126);
781815 \\}
782816 \\pub fn main() void {
783817 \\ const x = div0(999, 0);
......@@ -788,22 +822,24 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
788822 );
789823
790824 cases.addRuntimeSafety("integer division by zero - vectors",
791 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
792 \\ @import("std").os.exit(126);
825 \\const std = @import("std");
826 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
827 \\ std.os.exit(126);
793828 \\}
794829 \\pub fn main() void {
795 \\ var a: @import("std").meta.Vector(4, i32) = [4]i32{111, 222, 333, 444};
796 \\ var b: @import("std").meta.Vector(4, i32) = [4]i32{111, 0, 333, 444};
830 \\ var a: std.meta.Vector(4, i32) = [4]i32{111, 222, 333, 444};
831 \\ var b: std.meta.Vector(4, i32) = [4]i32{111, 0, 333, 444};
797832 \\ const x = div0(a, b);
798833 \\}
799 \\fn div0(a: @import("std").meta.Vector(4, i32), b: @import("std").meta.Vector(4, i32)) @import("std").meta.Vector(4, i32) {
834 \\fn div0(a: std.meta.Vector(4, i32), b: std.meta.Vector(4, i32)) std.meta.Vector(4, i32) {
800835 \\ return @divTrunc(a, b);
801836 \\}
802837 );
803838
804839 cases.addRuntimeSafety("exact division failure",
805 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
806 \\ @import("std").os.exit(126);
840 \\const std = @import("std");
841 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
842 \\ std.os.exit(126);
807843 \\}
808844 \\pub fn main() !void {
809845 \\ const x = divExact(10, 3);
......@@ -815,15 +851,16 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
815851 );
816852
817853 cases.addRuntimeSafety("exact division failure - vectors",
818 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
819 \\ @import("std").os.exit(126);
854 \\const std = @import("std");
855 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
856 \\ std.os.exit(126);
820857 \\}
821858 \\pub fn main() !void {
822 \\ var a: @import("std").meta.Vector(4, i32) = [4]i32{111, 222, 333, 444};
823 \\ var b: @import("std").meta.Vector(4, i32) = [4]i32{111, 222, 333, 441};
859 \\ var a: std.meta.Vector(4, i32) = [4]i32{111, 222, 333, 444};
860 \\ var b: std.meta.Vector(4, i32) = [4]i32{111, 222, 333, 441};
824861 \\ const x = divExact(a, b);
825862 \\}
826 \\fn divExact(a: @import("std").meta.Vector(4, i32), b: @import("std").meta.Vector(4, i32)) @import("std").meta.Vector(4, i32) {
863 \\fn divExact(a: std.meta.Vector(4, i32), b: std.meta.Vector(4, i32)) std.meta.Vector(4, i32) {
827864 \\ return @divExact(a, b);
828865 \\}
829866 );
......@@ -843,8 +880,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
843880 );
844881
845882 cases.addRuntimeSafety("value does not fit in shortening cast",
846 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
847 \\ @import("std").os.exit(126);
883 \\const std = @import("std");
884 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
885 \\ std.os.exit(126);
848886 \\}
849887 \\pub fn main() !void {
850888 \\ const x = shorten_cast(200);
......@@ -856,8 +894,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
856894 );
857895
858896 cases.addRuntimeSafety("value does not fit in shortening cast - u0",
859 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
860 \\ @import("std").os.exit(126);
897 \\const std = @import("std");
898 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
899 \\ std.os.exit(126);
861900 \\}
862901 \\pub fn main() !void {
863902 \\ const x = shorten_cast(1);
......@@ -869,8 +908,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
869908 );
870909
871910 cases.addRuntimeSafety("signed integer not fitting in cast to unsigned integer",
872 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
873 \\ @import("std").os.exit(126);
911 \\const std = @import("std");
912 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
913 \\ std.os.exit(126);
874914 \\}
875915 \\pub fn main() !void {
876916 \\ const x = unsigned_cast(-10);
......@@ -882,8 +922,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
882922 );
883923
884924 cases.addRuntimeSafety("signed integer not fitting in cast to unsigned integer - widening",
885 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
886 \\ @import("std").os.exit(126);
925 \\const std = @import("std");
926 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
927 \\ std.os.exit(126);
887928 \\}
888929 \\pub fn main() void {
889930 \\ var value: c_short = -1;
......@@ -892,8 +933,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
892933 );
893934
894935 cases.addRuntimeSafety("unsigned integer not fitting in cast to signed integer - same bit count",
895 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
896 \\ @import("std").os.exit(126);
936 \\const std = @import("std");
937 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
938 \\ std.os.exit(126);
897939 \\}
898940 \\pub fn main() void {
899941 \\ var value: u8 = 245;
......@@ -902,11 +944,12 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
902944 );
903945
904946 cases.addRuntimeSafety("unwrap error",
905 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
906 \\ if (@import("std").mem.eql(u8, message, "attempt to unwrap error: Whatever")) {
907 \\ @import("std").os.exit(126); // good
947 \\const std = @import("std");
948 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
949 \\ if (std.mem.eql(u8, message, "attempt to unwrap error: Whatever")) {
950 \\ std.os.exit(126); // good
908951 \\ }
909 \\ @import("std").os.exit(0); // test failed
952 \\ std.os.exit(0); // test failed
910953 \\}
911954 \\pub fn main() void {
912955 \\ bar() catch unreachable;
......@@ -917,8 +960,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
917960 );
918961
919962 cases.addRuntimeSafety("cast integer to global error and no code matches",
920 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
921 \\ @import("std").os.exit(126);
963 \\const std = @import("std");
964 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
965 \\ std.os.exit(126);
922966 \\}
923967 \\pub fn main() void {
924968 \\ bar(9999) catch {};
......@@ -929,8 +973,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
929973 );
930974
931975 cases.addRuntimeSafety("@errSetCast error not present in destination",
932 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
933 \\ @import("std").os.exit(126);
976 \\const std = @import("std");
977 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
978 \\ std.os.exit(126);
934979 \\}
935980 \\const Set1 = error{A, B};
936981 \\const Set2 = error{A, C};
......@@ -960,8 +1005,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
9601005 );
9611006
9621007 cases.addRuntimeSafety("bad union field access",
963 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
964 \\ @import("std").os.exit(126);
1008 \\const std = @import("std");
1009 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
1010 \\ std.os.exit(126);
9651011 \\}
9661012 \\
9671013 \\const Foo = union {
......@@ -983,8 +1029,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
9831029 // but we still emit a safety check to ensure the integer was 0 and thus
9841030 // did not truncate information.
9851031 cases.addRuntimeSafety("@intCast to u0",
986 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
987 \\ @import("std").os.exit(126);
1032 \\const std = @import("std");
1033 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
1034 \\ std.os.exit(126);
9881035 \\}
9891036 \\
9901037 \\pub fn main() void {
......@@ -1001,7 +1048,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
10011048 cases.addRuntimeSafety("error return trace across suspend points",
10021049 \\const std = @import("std");
10031050 \\
1004 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
1051 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
10051052 \\ std.os.exit(126);
10061053 \\}
10071054 \\
......@@ -1035,8 +1082,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
10351082 // Slicing a C pointer returns a non-allowzero slice, thus we need to emit
10361083 // a safety check to ensure the pointer is not null.
10371084 cases.addRuntimeSafety("slicing null C pointer",
1038 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
1039 \\ @import("std").os.exit(126);
1085 \\const std = @import("std");
1086 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
1087 \\ std.os.exit(126);
10401088 \\}
10411089 \\
10421090 \\pub fn main() void {