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);...@@ -1099,7 +1099,6 @@ const nan = std.math.nan(f128);
1099 {#code_release_fast#}1099 {#code_release_fast#}
1100 {#code_disable_cache#}1100 {#code_disable_cache#}
1101const std = @import("std");1101const std = @import("std");
1102const builtin = std.builtin;
1103const big = @as(f64, 1 << 40);1102const big = @as(f64, 1 << 40);
11041103
1105export fn foo_strict(x: f64) f64 {1104export fn foo_strict(x: f64) f64 {
...@@ -2603,7 +2602,7 @@ test "default struct initialization fields" {...@@ -2603,7 +2602,7 @@ test "default struct initialization fields" {
2603 </p>2602 </p>
2604 {#code_begin|test#}2603 {#code_begin|test#}
2605const std = @import("std");2604const std = @import("std");
2606const builtin = std.builtin;2605const native_endian = @import("builtin").target.cpu.arch.endian();
2607const expect = std.testing.expect;2606const expect = std.testing.expect;
26082607
2609const Full = packed struct {2608const Full = packed struct {
...@@ -2625,7 +2624,7 @@ fn doTheTest() !void {...@@ -2625,7 +2624,7 @@ fn doTheTest() !void {
2625 try expect(@sizeOf(Divided) == 2);2624 try expect(@sizeOf(Divided) == 2);
2626 var full = Full{ .number = 0x1234 };2625 var full = Full{ .number = 0x1234 };
2627 var divided = @bitCast(Divided, full);2626 var divided = @bitCast(Divided, full);
2628 switch (builtin.endian) {2627 switch (native_endian) {
2629 .Big => {2628 .Big => {
2630 try expect(divided.half1 == 0x12);2629 try expect(divided.half1 == 0x12);
2631 try expect(divided.quarter3 == 0x3);2630 try expect(divided.quarter3 == 0x3);
...@@ -4236,7 +4235,7 @@ test "noreturn" {...@@ -4236,7 +4235,7 @@ test "noreturn" {
4236 <p>Another use case for {#syntax#}noreturn{#endsyntax#} is the {#syntax#}exit{#endsyntax#} function:</p>4235 <p>Another use case for {#syntax#}noreturn{#endsyntax#} is the {#syntax#}exit{#endsyntax#} function:</p>
4237 {#code_begin|test#}4236 {#code_begin|test#}
4238 {#target_windows#}4237 {#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
4241test "foo" {4240test "foo" {
4242 const value = bar() catch ExitProcess(1);4241 const value = bar() catch ExitProcess(1);
...@@ -4271,7 +4270,7 @@ export fn sub(a: i8, b: i8) i8 { return a - b; }...@@ -4271,7 +4270,7 @@ export fn sub(a: i8, b: i8) i8 { return a - b; }
4271// at link time, when linking statically, or at runtime, when linking4270// at link time, when linking statically, or at runtime, when linking
4272// dynamically.4271// dynamically.
4273// The callconv specifier changes the calling convention of the function.4272// 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;
4275extern "c" fn atan2(a: f64, b: f64) f64;4274extern "c" fn atan2(a: f64, b: f64) f64;
42764275
4277// The @setCold builtin tells the optimizer that a function is rarely called.4276// 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 {}...@@ -7577,7 +7576,7 @@ export fn @"A function name that is a complete sentence."() void {}
7577 The {#syntax#}fence{#endsyntax#} function is used to introduce happens-before edges between operations.7576 The {#syntax#}fence{#endsyntax#} function is used to introduce happens-before edges between operations.
7578 </p>7577 </p>
7579 <p>7578 <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#}.
7581 </p>7580 </p>
7582 {#see_also|Compile Variables#}7581 {#see_also|Compile Variables#}
7583 {#header_close#}7582 {#header_close#}
...@@ -7780,8 +7779,8 @@ test "@hasDecl" {...@@ -7780,8 +7779,8 @@ test "@hasDecl" {
7780 </p>7779 </p>
7781 <ul>7780 <ul>
7782 <li>{#syntax#}@import("std"){#endsyntax#} - Zig Standard Library</li>7781 <li>{#syntax#}@import("std"){#endsyntax#} - Zig Standard Library</li>
7783 <li>{#syntax#}@import("builtin"){#endsyntax#} - Compiler-provided types and variables.7782 <li>{#syntax#}@import("builtin"){#endsyntax#} - Target-specific information
7784 The command <code>zig builtin</code> outputs the source to stdout for reference.7783 The command <code>zig build-exe --show-builtin</code> outputs the source to stdout for reference.
7785 </li>7784 </li>
7786 </ul>7785 </ul>
7787 {#see_also|Compile Variables|@embedFile#}7786 {#see_also|Compile Variables|@embedFile#}
...@@ -7912,11 +7911,11 @@ mem.set(u8, dest, c);{#endsyntax#}</pre>...@@ -7912,11 +7911,11 @@ mem.set(u8, dest, c);{#endsyntax#}</pre>
7912 </p>7911 </p>
7913 {#code_begin|test#}7912 {#code_begin|test#}
7914const std = @import("std");7913const std = @import("std");
7915const builtin = @import("builtin");7914const native_arch = @import("builtin").target.cpu.arch;
7916const expect = std.testing.expect;7915const expect = std.testing.expect;
79177916
7918test "@wasmMemoryGrow" {7917test "@wasmMemoryGrow" {
7919 if (builtin.arch != .wasm32) return error.SkipZigTest;7918 if (native_arch != .wasm32) return error.SkipZigTest;
79207919
7921 var prev = @wasmMemorySize(0);7920 var prev = @wasmMemorySize(0);
7922 try expect(prev == @wasmMemoryGrow(0, 1));7921 try expect(prev == @wasmMemoryGrow(0, 1));
...@@ -8084,7 +8083,7 @@ test "foo" {...@@ -8084,7 +8083,7 @@ test "foo" {
8084 {#header_close#}8083 {#header_close#}
80858084
8086 {#header_open|@setFloatMode#}8085 {#header_open|@setFloatMode#}
8087 <pre>{#syntax#}@setFloatMode(mode: @import("builtin").FloatMode){#endsyntax#}</pre>8086 <pre>{#syntax#}@setFloatMode(mode: @import("std").builtin.FloatMode){#endsyntax#}</pre>
8088 <p>8087 <p>
8089 Sets the floating point mode of the current scope. Possible values are:8088 Sets the floating point mode of the current scope. Possible values are:
8090 </p>8089 </p>
...@@ -8273,7 +8272,7 @@ test "vector @splat" {...@@ -8273,7 +8272,7 @@ test "vector @splat" {
8273 {#header_close#}8272 {#header_close#}
82748273
8275 {#header_open|@reduce#}8274 {#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>
8277 <p>8276 <p>
8278 Transforms a {#link|vector|Vectors#} into a scalar value by performing a8277 Transforms a {#link|vector|Vectors#} into a scalar value by performing a
8279 sequential horizontal reduction of its elements using the specified operator {#syntax#}op{#endsyntax#}.8278 sequential horizontal reduction of its elements using the specified operator {#syntax#}op{#endsyntax#}.
...@@ -8565,7 +8564,7 @@ test "integer truncation" {...@@ -8565,7 +8564,7 @@ test "integer truncation" {
8565 {#header_close#}8564 {#header_close#}
85668565
8567 {#header_open|@Type#}8566 {#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>
8569 <p>8568 <p>
8570 This function is the inverse of {#link|@typeInfo#}. It reifies type information8569 This function is the inverse of {#link|@typeInfo#}. It reifies type information
8571 into a {#syntax#}type{#endsyntax#}.8570 into a {#syntax#}type{#endsyntax#}.
...@@ -8607,7 +8606,7 @@ test "integer truncation" {...@@ -8607,7 +8606,7 @@ test "integer truncation" {
8607 </ul>8606 </ul>
8608 {#header_close#}8607 {#header_close#}
8609 {#header_open|@typeInfo#}8608 {#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>
8611 <p>8610 <p>
8612 Provides type reflection.8611 Provides type reflection.
8613 </p>8612 </p>
...@@ -9628,7 +9627,7 @@ test "string literal to constant slice" {...@@ -9628,7 +9627,7 @@ test "string literal to constant slice" {
9628 </p>9627 </p>
9629 {#code_begin|syntax#}9628 {#code_begin|syntax#}
9630const builtin = @import("builtin");9629const builtin = @import("builtin");
9631const separator = if (builtin.os == builtin.Os.windows) '\\' else '/';9630const separator = if (builtin.os.tag == builtin.Os.windows) '\\' else '/';
9632 {#code_end#}9631 {#code_end#}
9633 <p>9632 <p>
9634 Example of what is imported with {#syntax#}@import("builtin"){#endsyntax#}:9633 Example of what is imported with {#syntax#}@import("builtin"){#endsyntax#}:
...@@ -9653,7 +9652,7 @@ const separator = if (builtin.os == builtin.Os.windows) '\\' else '/';...@@ -9653,7 +9652,7 @@ const separator = if (builtin.os == builtin.Os.windows) '\\' else '/';
9653 </p>9652 </p>
9654 {#code_begin|test|detect_test#}9653 {#code_begin|test|detect_test#}
9655const std = @import("std");9654const std = @import("std");
9656const builtin = std.builtin;9655const builtin = @import("builtin");
9657const expect = std.testing.expect;9656const expect = std.testing.expect;
96589657
9659test "builtin.is_test" {9658test "builtin.is_test" {
test/compile_errors.zig+24-24
...@@ -208,7 +208,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -208,7 +208,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
208 });208 });
209209
210 cases.add("@Type with TypeInfo.Int",210 cases.add("@Type with TypeInfo.Int",
211 \\const builtin = @import("builtin");211 \\const builtin = @import("std").builtin;
212 \\export fn entry() void {212 \\export fn entry() void {
213 \\ _ = @Type(builtin.TypeInfo.Int {213 \\ _ = @Type(builtin.TypeInfo.Int {
214 \\ .signedness = .signed,214 \\ .signedness = .signed,
...@@ -242,7 +242,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -242,7 +242,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
242 });242 });
243243
244 cases.add("@Type for exhaustive enum with undefined tag type",244 cases.add("@Type for exhaustive enum with undefined tag type",
245 \\const TypeInfo = @import("builtin").TypeInfo;245 \\const TypeInfo = @import("std").builtin.TypeInfo;
246 \\const Tag = @Type(.{246 \\const Tag = @Type(.{
247 \\ .Enum = .{247 \\ .Enum = .{
248 \\ .layout = .Auto,248 \\ .layout = .Auto,
...@@ -272,7 +272,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -272,7 +272,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
272 });272 });
273273
274 cases.add("@Type for exhaustive enum with non-integer tag type",274 cases.add("@Type for exhaustive enum with non-integer tag type",
275 \\const TypeInfo = @import("builtin").TypeInfo;275 \\const TypeInfo = @import("std").builtin.TypeInfo;
276 \\const Tag = @Type(.{276 \\const Tag = @Type(.{
277 \\ .Enum = .{277 \\ .Enum = .{
278 \\ .layout = .Auto,278 \\ .layout = .Auto,
...@@ -331,7 +331,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -331,7 +331,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
331 });331 });
332332
333 cases.add("@Type for tagged union with extra enum field",333 cases.add("@Type for tagged union with extra enum field",
334 \\const TypeInfo = @import("builtin").TypeInfo;334 \\const TypeInfo = @import("std").builtin.TypeInfo;
335 \\const Tag = @Type(.{335 \\const Tag = @Type(.{
336 \\ .Enum = .{336 \\ .Enum = .{
337 \\ .layout = .Auto,337 \\ .layout = .Auto,
...@@ -397,7 +397,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -397,7 +397,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
397 \\ .is_generic = true,397 \\ .is_generic = true,
398 \\ .is_var_args = false,398 \\ .is_var_args = false,
399 \\ .return_type = u0,399 \\ .return_type = u0,
400 \\ .args = &[_]@import("builtin").TypeInfo.FnArg{},400 \\ .args = &[_]@import("std").builtin.TypeInfo.FnArg{},
401 \\ },401 \\ },
402 \\});402 \\});
403 \\comptime { _ = Foo; }403 \\comptime { _ = Foo; }
...@@ -413,7 +413,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -413,7 +413,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
413 \\ .is_generic = false,413 \\ .is_generic = false,
414 \\ .is_var_args = true,414 \\ .is_var_args = true,
415 \\ .return_type = u0,415 \\ .return_type = u0,
416 \\ .args = &[_]@import("builtin").TypeInfo.FnArg{},416 \\ .args = &[_]@import("std").builtin.TypeInfo.FnArg{},
417 \\ },417 \\ },
418 \\});418 \\});
419 \\comptime { _ = Foo; }419 \\comptime { _ = Foo; }
...@@ -429,7 +429,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -429,7 +429,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
429 \\ .is_generic = false,429 \\ .is_generic = false,
430 \\ .is_var_args = false,430 \\ .is_var_args = false,
431 \\ .return_type = null,431 \\ .return_type = null,
432 \\ .args = &[_]@import("builtin").TypeInfo.FnArg{},432 \\ .args = &[_]@import("std").builtin.TypeInfo.FnArg{},
433 \\ },433 \\ },
434 \\});434 \\});
435 \\comptime { _ = Foo; }435 \\comptime { _ = Foo; }
...@@ -438,7 +438,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -438,7 +438,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
438 });438 });
439439
440 cases.add("@Type for union with opaque field",440 cases.add("@Type for union with opaque field",
441 \\const TypeInfo = @import("builtin").TypeInfo;441 \\const TypeInfo = @import("std").builtin.TypeInfo;
442 \\const Untagged = @Type(.{442 \\const Untagged = @Type(.{
443 \\ .Union = .{443 \\ .Union = .{
444 \\ .layout = .Auto,444 \\ .layout = .Auto,
...@@ -474,7 +474,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -474,7 +474,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
474 });474 });
475475
476 cases.add("@Type for union with zero fields",476 cases.add("@Type for union with zero fields",
477 \\const TypeInfo = @import("builtin").TypeInfo;477 \\const TypeInfo = @import("std").builtin.TypeInfo;
478 \\const Untagged = @Type(.{478 \\const Untagged = @Type(.{
479 \\ .Union = .{479 \\ .Union = .{
480 \\ .layout = .Auto,480 \\ .layout = .Auto,
...@@ -492,7 +492,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -492,7 +492,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
492 });492 });
493493
494 cases.add("@Type for exhaustive enum with zero fields",494 cases.add("@Type for exhaustive enum with zero fields",
495 \\const TypeInfo = @import("builtin").TypeInfo;495 \\const TypeInfo = @import("std").builtin.TypeInfo;
496 \\const Tag = @Type(.{496 \\const Tag = @Type(.{
497 \\ .Enum = .{497 \\ .Enum = .{
498 \\ .layout = .Auto,498 \\ .layout = .Auto,
...@@ -511,7 +511,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -511,7 +511,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
511 });511 });
512512
513 cases.add("@Type for tagged union with extra union field",513 cases.add("@Type for tagged union with extra union field",
514 \\const TypeInfo = @import("builtin").TypeInfo;514 \\const TypeInfo = @import("std").builtin.TypeInfo;
515 \\const Tag = @Type(.{515 \\const Tag = @Type(.{
516 \\ .Enum = .{516 \\ .Enum = .{
517 \\ .layout = .Auto,517 \\ .layout = .Auto,
...@@ -1946,7 +1946,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -1946,7 +1946,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
1946 });1946 });
19471947
1948 cases.add("attempt to create 17 bit float type",1948 cases.add("attempt to create 17 bit float type",
1949 \\const builtin = @import("builtin");1949 \\const builtin = @import("std").builtin;
1950 \\comptime {1950 \\comptime {
1951 \\ _ = @Type(builtin.TypeInfo { .Float = builtin.TypeInfo.Float { .bits = 17 } });1951 \\ _ = @Type(builtin.TypeInfo { .Float = builtin.TypeInfo.Float { .bits = 17 } });
1952 \\}1952 \\}
...@@ -1963,7 +1963,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -1963,7 +1963,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
1963 });1963 });
19641964
1965 cases.add("@Type with non-constant expression",1965 cases.add("@Type with non-constant expression",
1966 \\const builtin = @import("builtin");1966 \\const builtin = @import("std").builtin;
1967 \\var globalTypeInfo : builtin.TypeInfo = undefined;1967 \\var globalTypeInfo : builtin.TypeInfo = undefined;
1968 \\export fn entry() void {1968 \\export fn entry() void {
1969 \\ _ = @Type(globalTypeInfo);1969 \\ _ = @Type(globalTypeInfo);
...@@ -5963,7 +5963,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -5963,7 +5963,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
5963 });5963 });
59645964
5965 cases.add("atomic orderings of cmpxchg - failure stricter than success",5965 cases.add("atomic orderings of cmpxchg - failure stricter than success",
5966 \\const AtomicOrder = @import("builtin").AtomicOrder;5966 \\const AtomicOrder = @import("std").builtin.AtomicOrder;
5967 \\export fn f() void {5967 \\export fn f() void {
5968 \\ var x: i32 = 1234;5968 \\ var x: i32 = 1234;
5969 \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.Monotonic, AtomicOrder.SeqCst)) {}5969 \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.Monotonic, AtomicOrder.SeqCst)) {}
...@@ -5973,7 +5973,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -5973,7 +5973,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
5973 });5973 });
59745974
5975 cases.add("atomic orderings of cmpxchg - success Monotonic or stricter",5975 cases.add("atomic orderings of cmpxchg - success Monotonic or stricter",
5976 \\const AtomicOrder = @import("builtin").AtomicOrder;5976 \\const AtomicOrder = @import("std").builtin.AtomicOrder;
5977 \\export fn f() void {5977 \\export fn f() void {
5978 \\ var x: i32 = 1234;5978 \\ var x: i32 = 1234;
5979 \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.Unordered, AtomicOrder.Unordered)) {}5979 \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.Unordered, AtomicOrder.Unordered)) {}
...@@ -6579,12 +6579,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -6579,12 +6579,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
6579 });6579 });
65806580
6581 cases.add("invalid member of builtin enum",6581 cases.add("invalid member of builtin enum",
6582 \\const builtin = @import("builtin",);6582 \\const builtin = @import("std").builtin;
6583 \\export fn entry() void {6583 \\export fn entry() void {
6584 \\ const foo = builtin.Arch.x86;6584 \\ const foo = builtin.Mode.x86;
6585 \\}6585 \\}
6586 , &[_][]const u8{6586 , &[_][]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'",
6588 });6588 });
65896589
6590 cases.add("int to ptr of 0 bits",6590 cases.add("int to ptr of 0 bits",
...@@ -6853,8 +6853,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -6853,8 +6853,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
68536853
6854 cases.add("@setFloatMode twice for same scope",6854 cases.add("@setFloatMode twice for same scope",
6855 \\export fn foo() void {6855 \\export fn foo() void {
6856 \\ @setFloatMode(@import("builtin").FloatMode.Optimized);6856 \\ @setFloatMode(@import("std").builtin.FloatMode.Optimized);
6857 \\ @setFloatMode(@import("builtin").FloatMode.Optimized);6857 \\ @setFloatMode(@import("std").builtin.FloatMode.Optimized);
6858 \\}6858 \\}
6859 , &[_][]const u8{6859 , &[_][]const u8{
6860 "tmp.zig:3:5: error: float mode set twice for same scope",6860 "tmp.zig:3:5: error: float mode set twice for same scope",
...@@ -7066,7 +7066,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -7066,7 +7066,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
7066 });7066 });
70677067
7068 cases.add("passing a not-aligned-enough pointer to cmpxchg",7068 cases.add("passing a not-aligned-enough pointer to cmpxchg",
7069 \\const AtomicOrder = @import("builtin").AtomicOrder;7069 \\const AtomicOrder = @import("std").builtin.AtomicOrder;
7070 \\export fn entry() bool {7070 \\export fn entry() bool {
7071 \\ var x: i32 align(1) = 1234;7071 \\ var x: i32 align(1) = 1234;
7072 \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) {}7072 \\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) {}
...@@ -7233,7 +7233,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -7233,7 +7233,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
7233 });7233 });
72347234
7235 cases.add("storing runtime value in compile time variable then using it",7235 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;
7237 \\7237 \\
7238 \\fn Free(comptime filename: []const u8) TestCase {7238 \\fn Free(comptime filename: []const u8) TestCase {
7239 \\ return TestCase {7239 \\ return TestCase {
...@@ -7776,11 +7776,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -7776,11 +7776,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
7776 cases.addTest("nested vectors",7776 cases.addTest("nested vectors",
7777 \\export fn entry() void {7777 \\export fn entry() void {
7778 \\ const V1 = @import("std").meta.Vector(4, u8);7778 \\ 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 } });
7780 \\ var v: V2 = undefined;7780 \\ var v: V2 = undefined;
7781 \\}7781 \\}
7782 , &[_][]const u8{7782 , &[_][]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",
7784 "tmp.zig:3:16: note: referenced here",7784 "tmp.zig:3:16: note: referenced here",
7785 });7785 });
77867786
test/runtime_safety.zig+186-138
...@@ -3,7 +3,7 @@ const tests = @import("tests.zig");...@@ -3,7 +3,7 @@ const tests = @import("tests.zig");
3pub fn addCases(cases: *tests.CompareOutputContext) void {3pub fn addCases(cases: *tests.CompareOutputContext) void {
4 {4 {
5 const check_panic_msg =5 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 {
7 \\ if (std.mem.eql(u8, message, "reached unreachable code")) {7 \\ if (std.mem.eql(u8, message, "reached unreachable code")) {
8 \\ std.process.exit(126); // good8 \\ std.process.exit(126); // good
9 \\ }9 \\ }
...@@ -44,7 +44,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -44,7 +44,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
4444
45 {45 {
46 const check_panic_msg =46 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 {
48 \\ if (std.mem.eql(u8, message, "invalid enum value")) {48 \\ if (std.mem.eql(u8, message, "invalid enum value")) {
49 \\ std.process.exit(126); // good49 \\ std.process.exit(126); // good
50 \\ }50 \\ }
...@@ -82,7 +82,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -82,7 +82,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
8282
83 {83 {
84 const check_panic_msg =84 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 {
86 \\ if (std.mem.eql(u8, message, "index out of bounds")) {86 \\ if (std.mem.eql(u8, message, "index out of bounds")) {
87 \\ std.process.exit(126); // good87 \\ std.process.exit(126); // good
88 \\ }88 \\ }
...@@ -152,7 +152,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -152,7 +152,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
152 cases.addRuntimeSafety("truncating vector cast",152 cases.addRuntimeSafety("truncating vector cast",
153 \\const std = @import("std");153 \\const std = @import("std");
154 \\const V = @import("std").meta.Vector;154 \\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 {
156 \\ if (std.mem.eql(u8, message, "integer cast truncated bits")) {156 \\ if (std.mem.eql(u8, message, "integer cast truncated bits")) {
157 \\ std.process.exit(126); // good157 \\ std.process.exit(126); // good
158 \\ }158 \\ }
...@@ -167,7 +167,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -167,7 +167,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
167 cases.addRuntimeSafety("unsigned-signed vector cast",167 cases.addRuntimeSafety("unsigned-signed vector cast",
168 \\const std = @import("std");168 \\const std = @import("std");
169 \\const V = @import("std").meta.Vector;169 \\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 {
171 \\ if (std.mem.eql(u8, message, "integer cast truncated bits")) {171 \\ if (std.mem.eql(u8, message, "integer cast truncated bits")) {
172 \\ std.process.exit(126); // good172 \\ std.process.exit(126); // good
173 \\ }173 \\ }
...@@ -182,7 +182,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -182,7 +182,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
182 cases.addRuntimeSafety("signed-unsigned vector cast",182 cases.addRuntimeSafety("signed-unsigned vector cast",
183 \\const std = @import("std");183 \\const std = @import("std");
184 \\const V = @import("std").meta.Vector;184 \\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 {
186 \\ if (std.mem.eql(u8, message, "attempt to cast negative value to unsigned integer")) {186 \\ if (std.mem.eql(u8, message, "attempt to cast negative value to unsigned integer")) {
187 \\ std.process.exit(126); // good187 \\ std.process.exit(126); // good
188 \\ }188 \\ }
...@@ -196,7 +196,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -196,7 +196,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
196196
197 cases.addRuntimeSafety("shift left by huge amount",197 cases.addRuntimeSafety("shift left by huge amount",
198 \\const std = @import("std");198 \\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 {
200 \\ if (std.mem.eql(u8, message, "shift amount is greater than the type size")) {200 \\ if (std.mem.eql(u8, message, "shift amount is greater than the type size")) {
201 \\ std.process.exit(126); // good201 \\ std.process.exit(126); // good
202 \\ }202 \\ }
...@@ -211,7 +211,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -211,7 +211,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
211211
212 cases.addRuntimeSafety("shift right by huge amount",212 cases.addRuntimeSafety("shift right by huge amount",
213 \\const std = @import("std");213 \\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 {
215 \\ if (std.mem.eql(u8, message, "shift amount is greater than the type size")) {215 \\ if (std.mem.eql(u8, message, "shift amount is greater than the type size")) {
216 \\ std.process.exit(126); // good216 \\ std.process.exit(126); // good
217 \\ }217 \\ }
...@@ -226,7 +226,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -226,7 +226,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
226226
227 cases.addRuntimeSafety("slice sentinel mismatch - optional pointers",227 cases.addRuntimeSafety("slice sentinel mismatch - optional pointers",
228 \\const std = @import("std");228 \\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 {
230 \\ if (std.mem.eql(u8, message, "sentinel mismatch")) {230 \\ if (std.mem.eql(u8, message, "sentinel mismatch")) {
231 \\ std.process.exit(126); // good231 \\ std.process.exit(126); // good
232 \\ }232 \\ }
...@@ -240,7 +240,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -240,7 +240,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
240240
241 cases.addRuntimeSafety("slice sentinel mismatch - floats",241 cases.addRuntimeSafety("slice sentinel mismatch - floats",
242 \\const std = @import("std");242 \\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 {
244 \\ if (std.mem.eql(u8, message, "sentinel mismatch")) {244 \\ if (std.mem.eql(u8, message, "sentinel mismatch")) {
245 \\ std.process.exit(126); // good245 \\ std.process.exit(126); // good
246 \\ }246 \\ }
...@@ -254,7 +254,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -254,7 +254,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
254254
255 cases.addRuntimeSafety("pointer slice sentinel mismatch",255 cases.addRuntimeSafety("pointer slice sentinel mismatch",
256 \\const std = @import("std");256 \\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 {
258 \\ if (std.mem.eql(u8, message, "sentinel mismatch")) {258 \\ if (std.mem.eql(u8, message, "sentinel mismatch")) {
259 \\ std.process.exit(126); // good259 \\ std.process.exit(126); // good
260 \\ }260 \\ }
...@@ -269,7 +269,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -269,7 +269,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
269269
270 cases.addRuntimeSafety("slice slice sentinel mismatch",270 cases.addRuntimeSafety("slice slice sentinel mismatch",
271 \\const std = @import("std");271 \\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 {
273 \\ if (std.mem.eql(u8, message, "sentinel mismatch")) {273 \\ if (std.mem.eql(u8, message, "sentinel mismatch")) {
274 \\ std.process.exit(126); // good274 \\ std.process.exit(126); // good
275 \\ }275 \\ }
...@@ -284,7 +284,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -284,7 +284,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
284284
285 cases.addRuntimeSafety("array slice sentinel mismatch",285 cases.addRuntimeSafety("array slice sentinel mismatch",
286 \\const std = @import("std");286 \\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 {
288 \\ if (std.mem.eql(u8, message, "sentinel mismatch")) {288 \\ if (std.mem.eql(u8, message, "sentinel mismatch")) {
289 \\ std.process.exit(126); // good289 \\ std.process.exit(126); // good
290 \\ }290 \\ }
...@@ -298,7 +298,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -298,7 +298,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
298298
299 cases.addRuntimeSafety("intToPtr with misaligned address",299 cases.addRuntimeSafety("intToPtr with misaligned address",
300 \\const std = @import("std");300 \\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 {
302 \\ if (std.mem.eql(u8, message, "incorrect alignment")) {302 \\ if (std.mem.eql(u8, message, "incorrect alignment")) {
303 \\ std.os.exit(126); // good303 \\ std.os.exit(126); // good
304 \\ }304 \\ }
...@@ -311,19 +311,20 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -311,19 +311,20 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
311 );311 );
312312
313 cases.addRuntimeSafety("resuming a non-suspended function which never been suspended",313 cases.addRuntimeSafety("resuming a non-suspended function which never been suspended",
314 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {314 \\const std = @import("std");
315 \\ @import("std").os.exit(126);315 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
316 \\ std.os.exit(126);
316 \\}317 \\}
317 \\fn foo() void {318 \\fn foo() void {
318 \\ var f = async bar(@frame());319 \\ var f = async bar(@frame());
319 \\ @import("std").os.exit(0);320 \\ std.os.exit(0);
320 \\}321 \\}
321 \\322 \\
322 \\fn bar(frame: anyframe) void {323 \\fn bar(frame: anyframe) void {
323 \\ suspend {324 \\ suspend {
324 \\ resume frame;325 \\ resume frame;
325 \\ }326 \\ }
326 \\ @import("std").os.exit(0);327 \\ std.os.exit(0);
327 \\}328 \\}
328 \\329 \\
329 \\pub fn main() void {330 \\pub fn main() void {
...@@ -332,35 +333,37 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -332,35 +333,37 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
332 );333 );
333334
334 cases.addRuntimeSafety("resuming a non-suspended function which has been suspended and resumed",335 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 \\const std = @import("std");
336 \\ @import("std").os.exit(126);337 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
338 \\ std.os.exit(126);
337 \\}339 \\}
338 \\fn foo() void {340 \\fn foo() void {
339 \\ suspend {341 \\ suspend {
340 \\ global_frame = @frame();342 \\ global_frame = @frame();
341 \\ }343 \\ }
342 \\ var f = async bar(@frame());344 \\ var f = async bar(@frame());
343 \\ @import("std").os.exit(0);345 \\ std.os.exit(0);
344 \\}346 \\}
345 \\347 \\
346 \\fn bar(frame: anyframe) void {348 \\fn bar(frame: anyframe) void {
347 \\ suspend {349 \\ suspend {
348 \\ resume frame;350 \\ resume frame;
349 \\ }351 \\ }
350 \\ @import("std").os.exit(0);352 \\ std.os.exit(0);
351 \\}353 \\}
352 \\354 \\
353 \\var global_frame: anyframe = undefined;355 \\var global_frame: anyframe = undefined;
354 \\pub fn main() void {356 \\pub fn main() void {
355 \\ _ = async foo();357 \\ _ = async foo();
356 \\ resume global_frame;358 \\ resume global_frame;
357 \\ @import("std").os.exit(0);359 \\ std.os.exit(0);
358 \\}360 \\}
359 );361 );
360362
361 cases.addRuntimeSafety("nosuspend function call, callee suspends",363 cases.addRuntimeSafety("nosuspend function call, callee suspends",
362 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {364 \\const std = @import("std");
363 \\ @import("std").os.exit(126);365 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
366 \\ std.os.exit(126);
364 \\}367 \\}
365 \\pub fn main() void {368 \\pub fn main() void {
366 \\ _ = nosuspend add(101, 100);369 \\ _ = nosuspend add(101, 100);
...@@ -374,8 +377,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -374,8 +377,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
374 );377 );
375378
376 cases.addRuntimeSafety("awaiting twice",379 cases.addRuntimeSafety("awaiting twice",
377 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {380 \\const std = @import("std");
378 \\ @import("std").os.exit(126);381 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
382 \\ std.os.exit(126);
379 \\}383 \\}
380 \\var frame: anyframe = undefined;384 \\var frame: anyframe = undefined;
381 \\385 \\
...@@ -398,8 +402,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -398,8 +402,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
398 );402 );
399403
400 cases.addRuntimeSafety("@asyncCall with too small a frame",404 cases.addRuntimeSafety("@asyncCall with too small a frame",
401 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {405 \\const std = @import("std");
402 \\ @import("std").os.exit(126);406 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
407 \\ std.os.exit(126);
403 \\}408 \\}
404 \\pub fn main() void {409 \\pub fn main() void {
405 \\ var bytes: [1]u8 align(16) = undefined;410 \\ var bytes: [1]u8 align(16) = undefined;
...@@ -412,8 +417,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -412,8 +417,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
412 );417 );
413418
414 cases.addRuntimeSafety("resuming a function which is awaiting a frame",419 cases.addRuntimeSafety("resuming a function which is awaiting a frame",
415 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {420 \\const std = @import("std");
416 \\ @import("std").os.exit(126);421 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
422 \\ std.os.exit(126);
417 \\}423 \\}
418 \\pub fn main() void {424 \\pub fn main() void {
419 \\ var frame = async first();425 \\ var frame = async first();
...@@ -429,8 +435,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -429,8 +435,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
429 );435 );
430436
431 cases.addRuntimeSafety("resuming a function which is awaiting a call",437 cases.addRuntimeSafety("resuming a function which is awaiting a call",
432 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {438 \\const std = @import("std");
433 \\ @import("std").os.exit(126);439 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
440 \\ std.os.exit(126);
434 \\}441 \\}
435 \\pub fn main() void {442 \\pub fn main() void {
436 \\ var frame = async first();443 \\ var frame = async first();
...@@ -445,8 +452,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -445,8 +452,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
445 );452 );
446453
447 cases.addRuntimeSafety("invalid resume of async function",454 cases.addRuntimeSafety("invalid resume of async function",
448 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {455 \\const std = @import("std");
449 \\ @import("std").os.exit(126);456 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
457 \\ std.os.exit(126);
450 \\}458 \\}
451 \\pub fn main() void {459 \\pub fn main() void {
452 \\ var p = async suspendOnce();460 \\ var p = async suspendOnce();
...@@ -459,8 +467,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -459,8 +467,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
459 );467 );
460468
461 cases.addRuntimeSafety(".? operator on null pointer",469 cases.addRuntimeSafety(".? operator on null pointer",
462 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {470 \\const std = @import("std");
463 \\ @import("std").os.exit(126);471 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
472 \\ std.os.exit(126);
464 \\}473 \\}
465 \\pub fn main() void {474 \\pub fn main() void {
466 \\ var ptr: ?*i32 = null;475 \\ var ptr: ?*i32 = null;
...@@ -469,8 +478,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -469,8 +478,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
469 );478 );
470479
471 cases.addRuntimeSafety(".? operator on C pointer",480 cases.addRuntimeSafety(".? operator on C pointer",
472 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {481 \\const std = @import("std");
473 \\ @import("std").os.exit(126);482 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
483 \\ std.os.exit(126);
474 \\}484 \\}
475 \\pub fn main() void {485 \\pub fn main() void {
476 \\ var ptr: [*c]i32 = null;486 \\ var ptr: [*c]i32 = null;
...@@ -479,8 +489,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -479,8 +489,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
479 );489 );
480490
481 cases.addRuntimeSafety("@intToPtr address zero to non-optional pointer",491 cases.addRuntimeSafety("@intToPtr address zero to non-optional pointer",
482 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {492 \\const std = @import("std");
483 \\ @import("std").os.exit(126);493 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
494 \\ std.os.exit(126);
484 \\}495 \\}
485 \\pub fn main() void {496 \\pub fn main() void {
486 \\ var zero: usize = 0;497 \\ var zero: usize = 0;
...@@ -489,8 +500,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -489,8 +500,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
489 );500 );
490501
491 cases.addRuntimeSafety("@intToPtr address zero to non-optional byte-aligned pointer",502 cases.addRuntimeSafety("@intToPtr address zero to non-optional byte-aligned pointer",
492 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {503 \\const std = @import("std");
493 \\ @import("std").os.exit(126);504 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
505 \\ std.os.exit(126);
494 \\}506 \\}
495 \\pub fn main() void {507 \\pub fn main() void {
496 \\ var zero: usize = 0;508 \\ var zero: usize = 0;
...@@ -499,8 +511,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -499,8 +511,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
499 );511 );
500512
501 cases.addRuntimeSafety("pointer casting null to non-optional pointer",513 cases.addRuntimeSafety("pointer casting null to non-optional pointer",
502 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {514 \\const std = @import("std");
503 \\ @import("std").os.exit(126);515 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
516 \\ std.os.exit(126);
504 \\}517 \\}
505 \\pub fn main() void {518 \\pub fn main() void {
506 \\ var c_ptr: [*c]u8 = 0;519 \\ var c_ptr: [*c]u8 = 0;
...@@ -509,8 +522,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -509,8 +522,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
509 );522 );
510523
511 cases.addRuntimeSafety("@intToEnum - no matching tag value",524 cases.addRuntimeSafety("@intToEnum - no matching tag value",
512 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {525 \\const std = @import("std");
513 \\ @import("std").os.exit(126);526 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
527 \\ std.os.exit(126);
514 \\}528 \\}
515 \\const Foo = enum {529 \\const Foo = enum {
516 \\ A,530 \\ A,
...@@ -527,8 +541,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -527,8 +541,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
527 );541 );
528542
529 cases.addRuntimeSafety("@floatToInt cannot fit - negative to unsigned",543 cases.addRuntimeSafety("@floatToInt cannot fit - negative to unsigned",
530 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {544 \\const std = @import("std");
531 \\ @import("std").os.exit(126);545 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
546 \\ std.os.exit(126);
532 \\}547 \\}
533 \\pub fn main() void {548 \\pub fn main() void {
534 \\ baz(bar(-1.1));549 \\ baz(bar(-1.1));
...@@ -540,8 +555,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -540,8 +555,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
540 );555 );
541556
542 cases.addRuntimeSafety("@floatToInt cannot fit - negative out of range",557 cases.addRuntimeSafety("@floatToInt cannot fit - negative out of range",
543 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {558 \\const std = @import("std");
544 \\ @import("std").os.exit(126);559 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
560 \\ std.os.exit(126);
545 \\}561 \\}
546 \\pub fn main() void {562 \\pub fn main() void {
547 \\ baz(bar(-129.1));563 \\ baz(bar(-129.1));
...@@ -553,8 +569,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -553,8 +569,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
553 );569 );
554570
555 cases.addRuntimeSafety("@floatToInt cannot fit - positive out of range",571 cases.addRuntimeSafety("@floatToInt cannot fit - positive out of range",
556 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {572 \\const std = @import("std");
557 \\ @import("std").os.exit(126);573 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
574 \\ std.os.exit(126);
558 \\}575 \\}
559 \\pub fn main() void {576 \\pub fn main() void {
560 \\ baz(bar(256.2));577 \\ baz(bar(256.2));
...@@ -566,8 +583,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -566,8 +583,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
566 );583 );
567584
568 cases.addRuntimeSafety("calling panic",585 cases.addRuntimeSafety("calling panic",
569 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {586 \\const std = @import("std");
570 \\ @import("std").os.exit(126);587 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
588 \\ std.os.exit(126);
571 \\}589 \\}
572 \\pub fn main() void {590 \\pub fn main() void {
573 \\ @panic("oh no");591 \\ @panic("oh no");
...@@ -575,8 +593,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -575,8 +593,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
575 );593 );
576594
577 cases.addRuntimeSafety("out of bounds slice access",595 cases.addRuntimeSafety("out of bounds slice access",
578 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {596 \\const std = @import("std");
579 \\ @import("std").os.exit(126);597 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
598 \\ std.os.exit(126);
580 \\}599 \\}
581 \\pub fn main() void {600 \\pub fn main() void {
582 \\ const a = [_]i32{1, 2, 3, 4};601 \\ const a = [_]i32{1, 2, 3, 4};
...@@ -589,8 +608,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -589,8 +608,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
589 );608 );
590609
591 cases.addRuntimeSafety("integer addition overflow",610 cases.addRuntimeSafety("integer addition overflow",
592 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {611 \\const std = @import("std");
593 \\ @import("std").os.exit(126);612 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
613 \\ std.os.exit(126);
594 \\}614 \\}
595 \\pub fn main() !void {615 \\pub fn main() !void {
596 \\ const x = add(65530, 10);616 \\ const x = add(65530, 10);
...@@ -602,63 +622,68 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -602,63 +622,68 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
602 );622 );
603623
604 cases.addRuntimeSafety("vector integer addition overflow",624 cases.addRuntimeSafety("vector integer addition overflow",
605 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {625 \\const std = @import("std");
606 \\ @import("std").os.exit(126);626 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
627 \\ std.os.exit(126);
607 \\}628 \\}
608 \\pub fn main() void {629 \\pub fn main() void {
609 \\ var a: @import("std").meta.Vector(4, i32) = [_]i32{ 1, 2, 2147483643, 4 };630 \\ var a: std.meta.Vector(4, i32) = [_]i32{ 1, 2, 2147483643, 4 };
610 \\ var b: @import("std").meta.Vector(4, i32) = [_]i32{ 5, 6, 7, 8 };631 \\ var b: std.meta.Vector(4, i32) = [_]i32{ 5, 6, 7, 8 };
611 \\ const x = add(a, b);632 \\ const x = add(a, b);
612 \\}633 \\}
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) {
614 \\ return a + b;635 \\ return a + b;
615 \\}636 \\}
616 );637 );
617638
618 cases.addRuntimeSafety("vector integer subtraction overflow",639 cases.addRuntimeSafety("vector integer subtraction overflow",
619 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {640 \\const std = @import("std");
620 \\ @import("std").os.exit(126);641 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
642 \\ std.os.exit(126);
621 \\}643 \\}
622 \\pub fn main() void {644 \\pub fn main() void {
623 \\ var a: @import("std").meta.Vector(4, u32) = [_]u32{ 1, 2, 8, 4 };645 \\ var a: std.meta.Vector(4, u32) = [_]u32{ 1, 2, 8, 4 };
624 \\ var b: @import("std").meta.Vector(4, u32) = [_]u32{ 5, 6, 7, 8 };646 \\ var b: std.meta.Vector(4, u32) = [_]u32{ 5, 6, 7, 8 };
625 \\ const x = sub(b, a);647 \\ const x = sub(b, a);
626 \\}648 \\}
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) {
628 \\ return a - b;650 \\ return a - b;
629 \\}651 \\}
630 );652 );
631653
632 cases.addRuntimeSafety("vector integer multiplication overflow",654 cases.addRuntimeSafety("vector integer multiplication overflow",
633 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {655 \\const std = @import("std");
634 \\ @import("std").os.exit(126);656 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
657 \\ std.os.exit(126);
635 \\}658 \\}
636 \\pub fn main() void {659 \\pub fn main() void {
637 \\ var a: @import("std").meta.Vector(4, u8) = [_]u8{ 1, 2, 200, 4 };660 \\ var a: std.meta.Vector(4, u8) = [_]u8{ 1, 2, 200, 4 };
638 \\ var b: @import("std").meta.Vector(4, u8) = [_]u8{ 5, 6, 2, 8 };661 \\ var b: std.meta.Vector(4, u8) = [_]u8{ 5, 6, 2, 8 };
639 \\ const x = mul(b, a);662 \\ const x = mul(b, a);
640 \\}663 \\}
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) {
642 \\ return a * b;665 \\ return a * b;
643 \\}666 \\}
644 );667 );
645668
646 cases.addRuntimeSafety("vector integer negation overflow",669 cases.addRuntimeSafety("vector integer negation overflow",
647 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {670 \\const std = @import("std");
648 \\ @import("std").os.exit(126);671 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
672 \\ std.os.exit(126);
649 \\}673 \\}
650 \\pub fn main() void {674 \\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 };
652 \\ const x = neg(a);676 \\ const x = neg(a);
653 \\}677 \\}
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) {
655 \\ return -a;679 \\ return -a;
656 \\}680 \\}
657 );681 );
658682
659 cases.addRuntimeSafety("integer subtraction overflow",683 cases.addRuntimeSafety("integer subtraction overflow",
660 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {684 \\const std = @import("std");
661 \\ @import("std").os.exit(126);685 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
686 \\ std.os.exit(126);
662 \\}687 \\}
663 \\pub fn main() !void {688 \\pub fn main() !void {
664 \\ const x = sub(10, 20);689 \\ const x = sub(10, 20);
...@@ -670,8 +695,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -670,8 +695,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
670 );695 );
671696
672 cases.addRuntimeSafety("integer multiplication overflow",697 cases.addRuntimeSafety("integer multiplication overflow",
673 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {698 \\const std = @import("std");
674 \\ @import("std").os.exit(126);699 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
700 \\ std.os.exit(126);
675 \\}701 \\}
676 \\pub fn main() !void {702 \\pub fn main() !void {
677 \\ const x = mul(300, 6000);703 \\ const x = mul(300, 6000);
...@@ -683,8 +709,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -683,8 +709,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
683 );709 );
684710
685 cases.addRuntimeSafety("integer negation overflow",711 cases.addRuntimeSafety("integer negation overflow",
686 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {712 \\const std = @import("std");
687 \\ @import("std").os.exit(126);713 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
714 \\ std.os.exit(126);
688 \\}715 \\}
689 \\pub fn main() !void {716 \\pub fn main() !void {
690 \\ const x = neg(-32768);717 \\ const x = neg(-32768);
...@@ -696,8 +723,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -696,8 +723,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
696 );723 );
697724
698 cases.addRuntimeSafety("signed integer division overflow",725 cases.addRuntimeSafety("signed integer division overflow",
699 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {726 \\const std = @import("std");
700 \\ @import("std").os.exit(126);727 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
728 \\ std.os.exit(126);
701 \\}729 \\}
702 \\pub fn main() !void {730 \\pub fn main() !void {
703 \\ const x = div(-32768, -1);731 \\ const x = div(-32768, -1);
...@@ -709,23 +737,25 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -709,23 +737,25 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
709 );737 );
710738
711 cases.addRuntimeSafety("signed integer division overflow - vectors",739 cases.addRuntimeSafety("signed integer division overflow - vectors",
712 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {740 \\const std = @import("std");
713 \\ @import("std").os.exit(126);741 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
742 \\ std.os.exit(126);
714 \\}743 \\}
715 \\pub fn main() !void {744 \\pub fn main() !void {
716 \\ var a: @import("std").meta.Vector(4, i16) = [_]i16{ 1, 2, -32768, 4 };745 \\ var a: std.meta.Vector(4, i16) = [_]i16{ 1, 2, -32768, 4 };
717 \\ var b: @import("std").meta.Vector(4, i16) = [_]i16{ 1, 2, -1, 4 };746 \\ var b: std.meta.Vector(4, i16) = [_]i16{ 1, 2, -1, 4 };
718 \\ const x = div(a, b);747 \\ const x = div(a, b);
719 \\ if (x[2] == 32767) return error.Whatever;748 \\ if (x[2] == 32767) return error.Whatever;
720 \\}749 \\}
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) {
722 \\ return @divTrunc(a, b);751 \\ return @divTrunc(a, b);
723 \\}752 \\}
724 );753 );
725754
726 cases.addRuntimeSafety("signed shift left overflow",755 cases.addRuntimeSafety("signed shift left overflow",
727 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {756 \\const std = @import("std");
728 \\ @import("std").os.exit(126);757 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
758 \\ std.os.exit(126);
729 \\}759 \\}
730 \\pub fn main() !void {760 \\pub fn main() !void {
731 \\ const x = shl(-16385, 1);761 \\ const x = shl(-16385, 1);
...@@ -737,8 +767,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -737,8 +767,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
737 );767 );
738768
739 cases.addRuntimeSafety("unsigned shift left overflow",769 cases.addRuntimeSafety("unsigned shift left overflow",
740 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {770 \\const std = @import("std");
741 \\ @import("std").os.exit(126);771 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
772 \\ std.os.exit(126);
742 \\}773 \\}
743 \\pub fn main() !void {774 \\pub fn main() !void {
744 \\ const x = shl(0b0010111111111111, 3);775 \\ const x = shl(0b0010111111111111, 3);
...@@ -750,8 +781,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -750,8 +781,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
750 );781 );
751782
752 cases.addRuntimeSafety("signed shift right overflow",783 cases.addRuntimeSafety("signed shift right overflow",
753 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {784 \\const std = @import("std");
754 \\ @import("std").os.exit(126);785 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
786 \\ std.os.exit(126);
755 \\}787 \\}
756 \\pub fn main() !void {788 \\pub fn main() !void {
757 \\ const x = shr(-16385, 1);789 \\ const x = shr(-16385, 1);
...@@ -763,8 +795,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -763,8 +795,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
763 );795 );
764796
765 cases.addRuntimeSafety("unsigned shift right overflow",797 cases.addRuntimeSafety("unsigned shift right overflow",
766 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {798 \\const std = @import("std");
767 \\ @import("std").os.exit(126);799 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
800 \\ std.os.exit(126);
768 \\}801 \\}
769 \\pub fn main() !void {802 \\pub fn main() !void {
770 \\ const x = shr(0b0010111111111111, 3);803 \\ const x = shr(0b0010111111111111, 3);
...@@ -776,8 +809,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -776,8 +809,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
776 );809 );
777810
778 cases.addRuntimeSafety("integer division by zero",811 cases.addRuntimeSafety("integer division by zero",
779 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {812 \\const std = @import("std");
780 \\ @import("std").os.exit(126);813 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
814 \\ std.os.exit(126);
781 \\}815 \\}
782 \\pub fn main() void {816 \\pub fn main() void {
783 \\ const x = div0(999, 0);817 \\ const x = div0(999, 0);
...@@ -788,22 +822,24 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -788,22 +822,24 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
788 );822 );
789823
790 cases.addRuntimeSafety("integer division by zero - vectors",824 cases.addRuntimeSafety("integer division by zero - vectors",
791 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {825 \\const std = @import("std");
792 \\ @import("std").os.exit(126);826 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
827 \\ std.os.exit(126);
793 \\}828 \\}
794 \\pub fn main() void {829 \\pub fn main() void {
795 \\ var a: @import("std").meta.Vector(4, i32) = [4]i32{111, 222, 333, 444};830 \\ var a: 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};831 \\ var b: std.meta.Vector(4, i32) = [4]i32{111, 0, 333, 444};
797 \\ const x = div0(a, b);832 \\ const x = div0(a, b);
798 \\}833 \\}
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) {
800 \\ return @divTrunc(a, b);835 \\ return @divTrunc(a, b);
801 \\}836 \\}
802 );837 );
803838
804 cases.addRuntimeSafety("exact division failure",839 cases.addRuntimeSafety("exact division failure",
805 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {840 \\const std = @import("std");
806 \\ @import("std").os.exit(126);841 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
842 \\ std.os.exit(126);
807 \\}843 \\}
808 \\pub fn main() !void {844 \\pub fn main() !void {
809 \\ const x = divExact(10, 3);845 \\ const x = divExact(10, 3);
...@@ -815,15 +851,16 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -815,15 +851,16 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
815 );851 );
816852
817 cases.addRuntimeSafety("exact division failure - vectors",853 cases.addRuntimeSafety("exact division failure - vectors",
818 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {854 \\const std = @import("std");
819 \\ @import("std").os.exit(126);855 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
856 \\ std.os.exit(126);
820 \\}857 \\}
821 \\pub fn main() !void {858 \\pub fn main() !void {
822 \\ var a: @import("std").meta.Vector(4, i32) = [4]i32{111, 222, 333, 444};859 \\ var a: 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};860 \\ var b: std.meta.Vector(4, i32) = [4]i32{111, 222, 333, 441};
824 \\ const x = divExact(a, b);861 \\ const x = divExact(a, b);
825 \\}862 \\}
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) {
827 \\ return @divExact(a, b);864 \\ return @divExact(a, b);
828 \\}865 \\}
829 );866 );
...@@ -843,8 +880,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -843,8 +880,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
843 );880 );
844881
845 cases.addRuntimeSafety("value does not fit in shortening cast",882 cases.addRuntimeSafety("value does not fit in shortening cast",
846 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {883 \\const std = @import("std");
847 \\ @import("std").os.exit(126);884 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
885 \\ std.os.exit(126);
848 \\}886 \\}
849 \\pub fn main() !void {887 \\pub fn main() !void {
850 \\ const x = shorten_cast(200);888 \\ const x = shorten_cast(200);
...@@ -856,8 +894,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -856,8 +894,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
856 );894 );
857895
858 cases.addRuntimeSafety("value does not fit in shortening cast - u0",896 cases.addRuntimeSafety("value does not fit in shortening cast - u0",
859 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {897 \\const std = @import("std");
860 \\ @import("std").os.exit(126);898 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
899 \\ std.os.exit(126);
861 \\}900 \\}
862 \\pub fn main() !void {901 \\pub fn main() !void {
863 \\ const x = shorten_cast(1);902 \\ const x = shorten_cast(1);
...@@ -869,8 +908,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -869,8 +908,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
869 );908 );
870909
871 cases.addRuntimeSafety("signed integer not fitting in cast to unsigned integer",910 cases.addRuntimeSafety("signed integer not fitting in cast to unsigned integer",
872 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {911 \\const std = @import("std");
873 \\ @import("std").os.exit(126);912 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
913 \\ std.os.exit(126);
874 \\}914 \\}
875 \\pub fn main() !void {915 \\pub fn main() !void {
876 \\ const x = unsigned_cast(-10);916 \\ const x = unsigned_cast(-10);
...@@ -882,8 +922,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -882,8 +922,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
882 );922 );
883923
884 cases.addRuntimeSafety("signed integer not fitting in cast to unsigned integer - widening",924 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 {925 \\const std = @import("std");
886 \\ @import("std").os.exit(126);926 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
927 \\ std.os.exit(126);
887 \\}928 \\}
888 \\pub fn main() void {929 \\pub fn main() void {
889 \\ var value: c_short = -1;930 \\ var value: c_short = -1;
...@@ -892,8 +933,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -892,8 +933,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
892 );933 );
893934
894 cases.addRuntimeSafety("unsigned integer not fitting in cast to signed integer - same bit count",935 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 {936 \\const std = @import("std");
896 \\ @import("std").os.exit(126);937 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
938 \\ std.os.exit(126);
897 \\}939 \\}
898 \\pub fn main() void {940 \\pub fn main() void {
899 \\ var value: u8 = 245;941 \\ var value: u8 = 245;
...@@ -902,11 +944,12 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -902,11 +944,12 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
902 );944 );
903945
904 cases.addRuntimeSafety("unwrap error",946 cases.addRuntimeSafety("unwrap error",
905 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {947 \\const std = @import("std");
906 \\ if (@import("std").mem.eql(u8, message, "attempt to unwrap error: Whatever")) {948 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
907 \\ @import("std").os.exit(126); // good949 \\ if (std.mem.eql(u8, message, "attempt to unwrap error: Whatever")) {
950 \\ std.os.exit(126); // good
908 \\ }951 \\ }
909 \\ @import("std").os.exit(0); // test failed952 \\ std.os.exit(0); // test failed
910 \\}953 \\}
911 \\pub fn main() void {954 \\pub fn main() void {
912 \\ bar() catch unreachable;955 \\ bar() catch unreachable;
...@@ -917,8 +960,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -917,8 +960,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
917 );960 );
918961
919 cases.addRuntimeSafety("cast integer to global error and no code matches",962 cases.addRuntimeSafety("cast integer to global error and no code matches",
920 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {963 \\const std = @import("std");
921 \\ @import("std").os.exit(126);964 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
965 \\ std.os.exit(126);
922 \\}966 \\}
923 \\pub fn main() void {967 \\pub fn main() void {
924 \\ bar(9999) catch {};968 \\ bar(9999) catch {};
...@@ -929,8 +973,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -929,8 +973,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
929 );973 );
930974
931 cases.addRuntimeSafety("@errSetCast error not present in destination",975 cases.addRuntimeSafety("@errSetCast error not present in destination",
932 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {976 \\const std = @import("std");
933 \\ @import("std").os.exit(126);977 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
978 \\ std.os.exit(126);
934 \\}979 \\}
935 \\const Set1 = error{A, B};980 \\const Set1 = error{A, B};
936 \\const Set2 = error{A, C};981 \\const Set2 = error{A, C};
...@@ -960,8 +1005,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -960,8 +1005,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
960 );1005 );
9611006
962 cases.addRuntimeSafety("bad union field access",1007 cases.addRuntimeSafety("bad union field access",
963 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {1008 \\const std = @import("std");
964 \\ @import("std").os.exit(126);1009 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
1010 \\ std.os.exit(126);
965 \\}1011 \\}
966 \\1012 \\
967 \\const Foo = union {1013 \\const Foo = union {
...@@ -983,8 +1029,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -983,8 +1029,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
983 // but we still emit a safety check to ensure the integer was 0 and thus1029 // but we still emit a safety check to ensure the integer was 0 and thus
984 // did not truncate information.1030 // did not truncate information.
985 cases.addRuntimeSafety("@intCast to u0",1031 cases.addRuntimeSafety("@intCast to u0",
986 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {1032 \\const std = @import("std");
987 \\ @import("std").os.exit(126);1033 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
1034 \\ std.os.exit(126);
988 \\}1035 \\}
989 \\1036 \\
990 \\pub fn main() void {1037 \\pub fn main() void {
...@@ -1001,7 +1048,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -1001,7 +1048,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
1001 cases.addRuntimeSafety("error return trace across suspend points",1048 cases.addRuntimeSafety("error return trace across suspend points",
1002 \\const std = @import("std");1049 \\const std = @import("std");
1003 \\1050 \\
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 {
1005 \\ std.os.exit(126);1052 \\ std.os.exit(126);
1006 \\}1053 \\}
1007 \\1054 \\
...@@ -1035,8 +1082,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -1035,8 +1082,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
1035 // Slicing a C pointer returns a non-allowzero slice, thus we need to emit1082 // Slicing a C pointer returns a non-allowzero slice, thus we need to emit
1036 // a safety check to ensure the pointer is not null.1083 // a safety check to ensure the pointer is not null.
1037 cases.addRuntimeSafety("slicing null C pointer",1084 cases.addRuntimeSafety("slicing null C pointer",
1038 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {1085 \\const std = @import("std");
1039 \\ @import("std").os.exit(126);1086 \\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
1087 \\ std.os.exit(126);
1040 \\}1088 \\}
1041 \\1089 \\
1042 \\pub fn main() void {1090 \\pub fn main() void {