update langref, compile-error tests, safety tests

for the std.builtin re-arranging
This commit is contained in:
Andrew Kelley 2021-05-17 15:25:27 -07:00
parent f41892f736
commit 8cfa231104
3 changed files with 225 additions and 178 deletions

View File

@ -1099,7 +1099,6 @@ const nan = std.math.nan(f128);
{#code_release_fast#}
{#code_disable_cache#}
const std = @import("std");
const builtin = std.builtin;
const big = @as(f64, 1 << 40);
export fn foo_strict(x: f64) f64 {
@ -2603,7 +2602,7 @@ test "default struct initialization fields" {
</p>
{#code_begin|test#}
const std = @import("std");
const builtin = std.builtin;
const native_endian = @import("builtin").target.cpu.arch.endian();
const expect = std.testing.expect;
const Full = packed struct {
@ -2625,7 +2624,7 @@ fn doTheTest() !void {
try expect(@sizeOf(Divided) == 2);
var full = Full{ .number = 0x1234 };
var divided = @bitCast(Divided, full);
switch (builtin.endian) {
switch (native_endian) {
.Big => {
try expect(divided.half1 == 0x12);
try expect(divided.quarter3 == 0x3);
@ -4236,7 +4235,7 @@ test "noreturn" {
<p>Another use case for {#syntax#}noreturn{#endsyntax#} is the {#syntax#}exit{#endsyntax#} function:</p>
{#code_begin|test#}
{#target_windows#}
pub extern "kernel32" fn ExitProcess(exit_code: c_uint) callconv(if (@import("builtin").arch == .i386) .Stdcall else .C) noreturn;
pub extern "kernel32" fn ExitProcess(exit_code: c_uint) callconv(if (@import("builtin").target.cpu.arch == .i386) .Stdcall else .C) noreturn;
test "foo" {
const value = bar() catch ExitProcess(1);
@ -4271,7 +4270,7 @@ export fn sub(a: i8, b: i8) i8 { return a - b; }
// at link time, when linking statically, or at runtime, when linking
// dynamically.
// The callconv specifier changes the calling convention of the function.
extern "kernel32" fn ExitProcess(exit_code: u32) callconv(if (@import("builtin").arch == .i386) .Stdcall else .C) noreturn;
extern "kernel32" fn ExitProcess(exit_code: u32) callconv(if (@import("builtin").target.cpu.arch == .i386) .Stdcall else .C) noreturn;
extern "c" fn atan2(a: f64, b: f64) f64;
// 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 {}
The {#syntax#}fence{#endsyntax#} function is used to introduce happens-before edges between operations.
</p>
<p>
{#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("builtin").AtomicOrder{#endsyntax#}.
{#syntax#}AtomicOrder{#endsyntax#} can be found with {#syntax#}@import("std").builtin.AtomicOrder{#endsyntax#}.
</p>
{#see_also|Compile Variables#}
{#header_close#}
@ -7780,8 +7779,8 @@ test "@hasDecl" {
</p>
<ul>
<li>{#syntax#}@import("std"){#endsyntax#} - Zig Standard Library</li>
<li>{#syntax#}@import("builtin"){#endsyntax#} - Compiler-provided types and variables.
The command <code>zig builtin</code> outputs the source to stdout for reference.
<li>{#syntax#}@import("builtin"){#endsyntax#} - Target-specific information
The command <code>zig build-exe --show-builtin</code> outputs the source to stdout for reference.
</li>
</ul>
{#see_also|Compile Variables|@embedFile#}
@ -7912,11 +7911,11 @@ mem.set(u8, dest, c);{#endsyntax#}</pre>
</p>
{#code_begin|test#}
const std = @import("std");
const builtin = @import("builtin");
const native_arch = @import("builtin").target.cpu.arch;
const expect = std.testing.expect;
test "@wasmMemoryGrow" {
if (builtin.arch != .wasm32) return error.SkipZigTest;
if (native_arch != .wasm32) return error.SkipZigTest;
var prev = @wasmMemorySize(0);
try expect(prev == @wasmMemoryGrow(0, 1));
@ -8084,7 +8083,7 @@ test "foo" {
{#header_close#}
{#header_open|@setFloatMode#}
<pre>{#syntax#}@setFloatMode(mode: @import("builtin").FloatMode){#endsyntax#}</pre>
<pre>{#syntax#}@setFloatMode(mode: @import("std").builtin.FloatMode){#endsyntax#}</pre>
<p>
Sets the floating point mode of the current scope. Possible values are:
</p>
@ -8273,7 +8272,7 @@ test "vector @splat" {
{#header_close#}
{#header_open|@reduce#}
<pre>{#syntax#}@reduce(comptime op: builtin.ReduceOp, value: anytype) std.meta.Child(value){#endsyntax#}</pre>
<pre>{#syntax#}@reduce(comptime op: std.builtin.ReduceOp, value: anytype) std.meta.Child(value){#endsyntax#}</pre>
<p>
Transforms a {#link|vector|Vectors#} into a scalar value by performing a
sequential horizontal reduction of its elements using the specified operator {#syntax#}op{#endsyntax#}.
@ -8565,7 +8564,7 @@ test "integer truncation" {
{#header_close#}
{#header_open|@Type#}
<pre>{#syntax#}@Type(comptime info: @import("builtin").TypeInfo) type{#endsyntax#}</pre>
<pre>{#syntax#}@Type(comptime info: std.builtin.TypeInfo) type{#endsyntax#}</pre>
<p>
This function is the inverse of {#link|@typeInfo#}. It reifies type information
into a {#syntax#}type{#endsyntax#}.
@ -8607,7 +8606,7 @@ test "integer truncation" {
</ul>
{#header_close#}
{#header_open|@typeInfo#}
<pre>{#syntax#}@typeInfo(comptime T: type) @import("std").builtin.TypeInfo{#endsyntax#}</pre>
<pre>{#syntax#}@typeInfo(comptime T: type) std.builtin.TypeInfo{#endsyntax#}</pre>
<p>
Provides type reflection.
</p>
@ -9628,7 +9627,7 @@ test "string literal to constant slice" {
</p>
{#code_begin|syntax#}
const builtin = @import("builtin");
const separator = if (builtin.os == builtin.Os.windows) '\\' else '/';
const separator = if (builtin.os.tag == builtin.Os.windows) '\\' else '/';
{#code_end#}
<p>
Example of what is imported with {#syntax#}@import("builtin"){#endsyntax#}:
@ -9653,7 +9652,7 @@ const separator = if (builtin.os == builtin.Os.windows) '\\' else '/';
</p>
{#code_begin|test|detect_test#}
const std = @import("std");
const builtin = std.builtin;
const builtin = @import("builtin");
const expect = std.testing.expect;
test "builtin.is_test" {

View File

@ -208,7 +208,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
});
cases.add("@Type with TypeInfo.Int",
\\const builtin = @import("builtin");
\\const builtin = @import("std").builtin;
\\export fn entry() void {
\\ _ = @Type(builtin.TypeInfo.Int {
\\ .signedness = .signed,
@ -242,7 +242,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
});
cases.add("@Type for exhaustive enum with undefined tag type",
\\const TypeInfo = @import("builtin").TypeInfo;
\\const TypeInfo = @import("std").builtin.TypeInfo;
\\const Tag = @Type(.{
\\ .Enum = .{
\\ .layout = .Auto,
@ -272,7 +272,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
});
cases.add("@Type for exhaustive enum with non-integer tag type",
\\const TypeInfo = @import("builtin").TypeInfo;
\\const TypeInfo = @import("std").builtin.TypeInfo;
\\const Tag = @Type(.{
\\ .Enum = .{
\\ .layout = .Auto,
@ -331,7 +331,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
});
cases.add("@Type for tagged union with extra enum field",
\\const TypeInfo = @import("builtin").TypeInfo;
\\const TypeInfo = @import("std").builtin.TypeInfo;
\\const Tag = @Type(.{
\\ .Enum = .{
\\ .layout = .Auto,
@ -397,7 +397,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ .is_generic = true,
\\ .is_var_args = false,
\\ .return_type = u0,
\\ .args = &[_]@import("builtin").TypeInfo.FnArg{},
\\ .args = &[_]@import("std").builtin.TypeInfo.FnArg{},
\\ },
\\});
\\comptime { _ = Foo; }
@ -413,7 +413,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ .is_generic = false,
\\ .is_var_args = true,
\\ .return_type = u0,
\\ .args = &[_]@import("builtin").TypeInfo.FnArg{},
\\ .args = &[_]@import("std").builtin.TypeInfo.FnArg{},
\\ },
\\});
\\comptime { _ = Foo; }
@ -429,7 +429,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
\\ .is_generic = false,
\\ .is_var_args = false,
\\ .return_type = null,
\\ .args = &[_]@import("builtin").TypeInfo.FnArg{},
\\ .args = &[_]@import("std").builtin.TypeInfo.FnArg{},
\\ },
\\});
\\comptime { _ = Foo; }
@ -438,7 +438,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
});
cases.add("@Type for union with opaque field",
\\const TypeInfo = @import("builtin").TypeInfo;
\\const TypeInfo = @import("std").builtin.TypeInfo;
\\const Untagged = @Type(.{
\\ .Union = .{
\\ .layout = .Auto,
@ -474,7 +474,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
});
cases.add("@Type for union with zero fields",
\\const TypeInfo = @import("builtin").TypeInfo;
\\const TypeInfo = @import("std").builtin.TypeInfo;
\\const Untagged = @Type(.{
\\ .Union = .{
\\ .layout = .Auto,
@ -492,7 +492,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
});
cases.add("@Type for exhaustive enum with zero fields",
\\const TypeInfo = @import("builtin").TypeInfo;
\\const TypeInfo = @import("std").builtin.TypeInfo;
\\const Tag = @Type(.{
\\ .Enum = .{
\\ .layout = .Auto,
@ -511,7 +511,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
});
cases.add("@Type for tagged union with extra union field",
\\const TypeInfo = @import("builtin").TypeInfo;
\\const TypeInfo = @import("std").builtin.TypeInfo;
\\const Tag = @Type(.{
\\ .Enum = .{
\\ .layout = .Auto,
@ -1946,7 +1946,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
});
cases.add("attempt to create 17 bit float type",
\\const builtin = @import("builtin");
\\const builtin = @import("std").builtin;
\\comptime {
\\ _ = @Type(builtin.TypeInfo { .Float = builtin.TypeInfo.Float { .bits = 17 } });
\\}
@ -1963,7 +1963,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
});
cases.add("@Type with non-constant expression",
\\const builtin = @import("builtin");
\\const builtin = @import("std").builtin;
\\var globalTypeInfo : builtin.TypeInfo = undefined;
\\export fn entry() void {
\\ _ = @Type(globalTypeInfo);
@ -5963,7 +5963,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
});
cases.add("atomic orderings of cmpxchg - failure stricter than success",
\\const AtomicOrder = @import("builtin").AtomicOrder;
\\const AtomicOrder = @import("std").builtin.AtomicOrder;
\\export fn f() void {
\\ var x: i32 = 1234;
\\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.Monotonic, AtomicOrder.SeqCst)) {}
@ -5973,7 +5973,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
});
cases.add("atomic orderings of cmpxchg - success Monotonic or stricter",
\\const AtomicOrder = @import("builtin").AtomicOrder;
\\const AtomicOrder = @import("std").builtin.AtomicOrder;
\\export fn f() void {
\\ var x: i32 = 1234;
\\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.Unordered, AtomicOrder.Unordered)) {}
@ -6579,12 +6579,12 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
});
cases.add("invalid member of builtin enum",
\\const builtin = @import("builtin",);
\\const builtin = @import("std").builtin;
\\export fn entry() void {
\\ const foo = builtin.Arch.x86;
\\ const foo = builtin.Mode.x86;
\\}
, &[_][]const u8{
"tmp.zig:3:29: error: container 'std.target.Arch' has no member called 'x86'",
"tmp.zig:3:29: error: container 'std.builtin.Mode' has no member called 'x86'",
});
cases.add("int to ptr of 0 bits",
@ -6853,8 +6853,8 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.add("@setFloatMode twice for same scope",
\\export fn foo() void {
\\ @setFloatMode(@import("builtin").FloatMode.Optimized);
\\ @setFloatMode(@import("builtin").FloatMode.Optimized);
\\ @setFloatMode(@import("std").builtin.FloatMode.Optimized);
\\ @setFloatMode(@import("std").builtin.FloatMode.Optimized);
\\}
, &[_][]const u8{
"tmp.zig:3:5: error: float mode set twice for same scope",
@ -7066,7 +7066,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
});
cases.add("passing a not-aligned-enough pointer to cmpxchg",
\\const AtomicOrder = @import("builtin").AtomicOrder;
\\const AtomicOrder = @import("std").builtin.AtomicOrder;
\\export fn entry() bool {
\\ var x: i32 align(1) = 1234;
\\ while (!@cmpxchgWeak(i32, &x, 1234, 5678, AtomicOrder.SeqCst, AtomicOrder.SeqCst)) {}
@ -7233,7 +7233,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
});
cases.add("storing runtime value in compile time variable then using it",
\\const Mode = @import("builtin").Mode;
\\const Mode = @import("std").builtin.Mode;
\\
\\fn Free(comptime filename: []const u8) TestCase {
\\ return TestCase {
@ -7776,11 +7776,11 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
cases.addTest("nested vectors",
\\export fn entry() void {
\\ const V1 = @import("std").meta.Vector(4, u8);
\\ const V2 = @Type(@import("builtin").TypeInfo{ .Vector = .{ .len = 4, .child = V1 } });
\\ const V2 = @Type(@import("std").builtin.TypeInfo{ .Vector = .{ .len = 4, .child = V1 } });
\\ var v: V2 = undefined;
\\}
, &[_][]const u8{
"tmp.zig:3:49: error: vector element type must be integer, float, bool, or pointer; '@Vector(4, u8)' is invalid",
"tmp.zig:3:53: error: vector element type must be integer, float, bool, or pointer; '@Vector(4, u8)' is invalid",
"tmp.zig:3:16: note: referenced here",
});

View File

@ -3,7 +3,7 @@ const tests = @import("tests.zig");
pub fn addCases(cases: *tests.CompareOutputContext) void {
{
const check_panic_msg =
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ if (std.mem.eql(u8, message, "reached unreachable code")) {
\\ std.process.exit(126); // good
\\ }
@ -44,7 +44,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
{
const check_panic_msg =
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ if (std.mem.eql(u8, message, "invalid enum value")) {
\\ std.process.exit(126); // good
\\ }
@ -82,7 +82,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
{
const check_panic_msg =
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ if (std.mem.eql(u8, message, "index out of bounds")) {
\\ std.process.exit(126); // good
\\ }
@ -152,7 +152,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
cases.addRuntimeSafety("truncating vector cast",
\\const std = @import("std");
\\const V = @import("std").meta.Vector;
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ if (std.mem.eql(u8, message, "integer cast truncated bits")) {
\\ std.process.exit(126); // good
\\ }
@ -167,7 +167,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
cases.addRuntimeSafety("unsigned-signed vector cast",
\\const std = @import("std");
\\const V = @import("std").meta.Vector;
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ if (std.mem.eql(u8, message, "integer cast truncated bits")) {
\\ std.process.exit(126); // good
\\ }
@ -182,7 +182,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
cases.addRuntimeSafety("signed-unsigned vector cast",
\\const std = @import("std");
\\const V = @import("std").meta.Vector;
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ if (std.mem.eql(u8, message, "attempt to cast negative value to unsigned integer")) {
\\ std.process.exit(126); // good
\\ }
@ -196,7 +196,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
cases.addRuntimeSafety("shift left by huge amount",
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ if (std.mem.eql(u8, message, "shift amount is greater than the type size")) {
\\ std.process.exit(126); // good
\\ }
@ -211,7 +211,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
cases.addRuntimeSafety("shift right by huge amount",
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ if (std.mem.eql(u8, message, "shift amount is greater than the type size")) {
\\ std.process.exit(126); // good
\\ }
@ -226,7 +226,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
cases.addRuntimeSafety("slice sentinel mismatch - optional pointers",
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ if (std.mem.eql(u8, message, "sentinel mismatch")) {
\\ std.process.exit(126); // good
\\ }
@ -240,7 +240,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
cases.addRuntimeSafety("slice sentinel mismatch - floats",
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ if (std.mem.eql(u8, message, "sentinel mismatch")) {
\\ std.process.exit(126); // good
\\ }
@ -254,7 +254,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
cases.addRuntimeSafety("pointer slice sentinel mismatch",
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ if (std.mem.eql(u8, message, "sentinel mismatch")) {
\\ std.process.exit(126); // good
\\ }
@ -269,7 +269,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
cases.addRuntimeSafety("slice slice sentinel mismatch",
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ if (std.mem.eql(u8, message, "sentinel mismatch")) {
\\ std.process.exit(126); // good
\\ }
@ -284,7 +284,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
cases.addRuntimeSafety("array slice sentinel mismatch",
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ if (std.mem.eql(u8, message, "sentinel mismatch")) {
\\ std.process.exit(126); // good
\\ }
@ -298,7 +298,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
cases.addRuntimeSafety("intToPtr with misaligned address",
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ if (std.mem.eql(u8, message, "incorrect alignment")) {
\\ std.os.exit(126); // good
\\ }
@ -311,19 +311,20 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
);
cases.addRuntimeSafety("resuming a non-suspended function which never been suspended",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\fn foo() void {
\\ var f = async bar(@frame());
\\ @import("std").os.exit(0);
\\ std.os.exit(0);
\\}
\\
\\fn bar(frame: anyframe) void {
\\ suspend {
\\ resume frame;
\\ }
\\ @import("std").os.exit(0);
\\ std.os.exit(0);
\\}
\\
\\pub fn main() void {
@ -332,35 +333,37 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
);
cases.addRuntimeSafety("resuming a non-suspended function which has been suspended and resumed",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\fn foo() void {
\\ suspend {
\\ global_frame = @frame();
\\ }
\\ var f = async bar(@frame());
\\ @import("std").os.exit(0);
\\ std.os.exit(0);
\\}
\\
\\fn bar(frame: anyframe) void {
\\ suspend {
\\ resume frame;
\\ }
\\ @import("std").os.exit(0);
\\ std.os.exit(0);
\\}
\\
\\var global_frame: anyframe = undefined;
\\pub fn main() void {
\\ _ = async foo();
\\ resume global_frame;
\\ @import("std").os.exit(0);
\\ std.os.exit(0);
\\}
);
cases.addRuntimeSafety("nosuspend function call, callee suspends",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\pub fn main() void {
\\ _ = nosuspend add(101, 100);
@ -374,8 +377,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
);
cases.addRuntimeSafety("awaiting twice",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\var frame: anyframe = undefined;
\\
@ -398,8 +402,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
);
cases.addRuntimeSafety("@asyncCall with too small a frame",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\pub fn main() void {
\\ var bytes: [1]u8 align(16) = undefined;
@ -412,8 +417,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
);
cases.addRuntimeSafety("resuming a function which is awaiting a frame",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\pub fn main() void {
\\ var frame = async first();
@ -429,8 +435,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
);
cases.addRuntimeSafety("resuming a function which is awaiting a call",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\pub fn main() void {
\\ var frame = async first();
@ -445,8 +452,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
);
cases.addRuntimeSafety("invalid resume of async function",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\pub fn main() void {
\\ var p = async suspendOnce();
@ -459,8 +467,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
);
cases.addRuntimeSafety(".? operator on null pointer",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\pub fn main() void {
\\ var ptr: ?*i32 = null;
@ -469,8 +478,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
);
cases.addRuntimeSafety(".? operator on C pointer",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\pub fn main() void {
\\ var ptr: [*c]i32 = null;
@ -479,8 +489,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
);
cases.addRuntimeSafety("@intToPtr address zero to non-optional pointer",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\pub fn main() void {
\\ var zero: usize = 0;
@ -489,8 +500,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
);
cases.addRuntimeSafety("@intToPtr address zero to non-optional byte-aligned pointer",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\pub fn main() void {
\\ var zero: usize = 0;
@ -499,8 +511,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
);
cases.addRuntimeSafety("pointer casting null to non-optional pointer",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\pub fn main() void {
\\ var c_ptr: [*c]u8 = 0;
@ -509,8 +522,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
);
cases.addRuntimeSafety("@intToEnum - no matching tag value",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\const Foo = enum {
\\ A,
@ -527,8 +541,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
);
cases.addRuntimeSafety("@floatToInt cannot fit - negative to unsigned",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\pub fn main() void {
\\ baz(bar(-1.1));
@ -540,8 +555,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
);
cases.addRuntimeSafety("@floatToInt cannot fit - negative out of range",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\pub fn main() void {
\\ baz(bar(-129.1));
@ -553,8 +569,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
);
cases.addRuntimeSafety("@floatToInt cannot fit - positive out of range",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\pub fn main() void {
\\ baz(bar(256.2));
@ -566,8 +583,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
);
cases.addRuntimeSafety("calling panic",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\pub fn main() void {
\\ @panic("oh no");
@ -575,8 +593,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
);
cases.addRuntimeSafety("out of bounds slice access",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\pub fn main() void {
\\ const a = [_]i32{1, 2, 3, 4};
@ -589,8 +608,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
);
cases.addRuntimeSafety("integer addition overflow",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\pub fn main() !void {
\\ const x = add(65530, 10);
@ -602,63 +622,68 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
);
cases.addRuntimeSafety("vector integer addition overflow",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\pub fn main() void {
\\ var a: @import("std").meta.Vector(4, i32) = [_]i32{ 1, 2, 2147483643, 4 };
\\ var b: @import("std").meta.Vector(4, i32) = [_]i32{ 5, 6, 7, 8 };
\\ var a: std.meta.Vector(4, i32) = [_]i32{ 1, 2, 2147483643, 4 };
\\ var b: std.meta.Vector(4, i32) = [_]i32{ 5, 6, 7, 8 };
\\ const x = add(a, b);
\\}
\\fn add(a: @import("std").meta.Vector(4, i32), b: @import("std").meta.Vector(4, i32)) @import("std").meta.Vector(4, i32) {
\\fn add(a: std.meta.Vector(4, i32), b: std.meta.Vector(4, i32)) std.meta.Vector(4, i32) {
\\ return a + b;
\\}
);
cases.addRuntimeSafety("vector integer subtraction overflow",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\pub fn main() void {
\\ var a: @import("std").meta.Vector(4, u32) = [_]u32{ 1, 2, 8, 4 };
\\ var b: @import("std").meta.Vector(4, u32) = [_]u32{ 5, 6, 7, 8 };
\\ var a: std.meta.Vector(4, u32) = [_]u32{ 1, 2, 8, 4 };
\\ var b: std.meta.Vector(4, u32) = [_]u32{ 5, 6, 7, 8 };
\\ const x = sub(b, a);
\\}
\\fn sub(a: @import("std").meta.Vector(4, u32), b: @import("std").meta.Vector(4, u32)) @import("std").meta.Vector(4, u32) {
\\fn sub(a: std.meta.Vector(4, u32), b: std.meta.Vector(4, u32)) std.meta.Vector(4, u32) {
\\ return a - b;
\\}
);
cases.addRuntimeSafety("vector integer multiplication overflow",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\pub fn main() void {
\\ var a: @import("std").meta.Vector(4, u8) = [_]u8{ 1, 2, 200, 4 };
\\ var b: @import("std").meta.Vector(4, u8) = [_]u8{ 5, 6, 2, 8 };
\\ var a: std.meta.Vector(4, u8) = [_]u8{ 1, 2, 200, 4 };
\\ var b: std.meta.Vector(4, u8) = [_]u8{ 5, 6, 2, 8 };
\\ const x = mul(b, a);
\\}
\\fn mul(a: @import("std").meta.Vector(4, u8), b: @import("std").meta.Vector(4, u8)) @import("std").meta.Vector(4, u8) {
\\fn mul(a: std.meta.Vector(4, u8), b: std.meta.Vector(4, u8)) std.meta.Vector(4, u8) {
\\ return a * b;
\\}
);
cases.addRuntimeSafety("vector integer negation overflow",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\pub fn main() void {
\\ var a: @import("std").meta.Vector(4, i16) = [_]i16{ 1, -32768, 200, 4 };
\\ var a: std.meta.Vector(4, i16) = [_]i16{ 1, -32768, 200, 4 };
\\ const x = neg(a);
\\}
\\fn neg(a: @import("std").meta.Vector(4, i16)) @import("std").meta.Vector(4, i16) {
\\fn neg(a: std.meta.Vector(4, i16)) std.meta.Vector(4, i16) {
\\ return -a;
\\}
);
cases.addRuntimeSafety("integer subtraction overflow",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\pub fn main() !void {
\\ const x = sub(10, 20);
@ -670,8 +695,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
);
cases.addRuntimeSafety("integer multiplication overflow",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\pub fn main() !void {
\\ const x = mul(300, 6000);
@ -683,8 +709,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
);
cases.addRuntimeSafety("integer negation overflow",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\pub fn main() !void {
\\ const x = neg(-32768);
@ -696,8 +723,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
);
cases.addRuntimeSafety("signed integer division overflow",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\pub fn main() !void {
\\ const x = div(-32768, -1);
@ -709,23 +737,25 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
);
cases.addRuntimeSafety("signed integer division overflow - vectors",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\pub fn main() !void {
\\ var a: @import("std").meta.Vector(4, i16) = [_]i16{ 1, 2, -32768, 4 };
\\ var b: @import("std").meta.Vector(4, i16) = [_]i16{ 1, 2, -1, 4 };
\\ var a: std.meta.Vector(4, i16) = [_]i16{ 1, 2, -32768, 4 };
\\ var b: std.meta.Vector(4, i16) = [_]i16{ 1, 2, -1, 4 };
\\ const x = div(a, b);
\\ if (x[2] == 32767) return error.Whatever;
\\}
\\fn div(a: @import("std").meta.Vector(4, i16), b: @import("std").meta.Vector(4, i16)) @import("std").meta.Vector(4, i16) {
\\fn div(a: std.meta.Vector(4, i16), b: std.meta.Vector(4, i16)) std.meta.Vector(4, i16) {
\\ return @divTrunc(a, b);
\\}
);
cases.addRuntimeSafety("signed shift left overflow",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\pub fn main() !void {
\\ const x = shl(-16385, 1);
@ -737,8 +767,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
);
cases.addRuntimeSafety("unsigned shift left overflow",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\pub fn main() !void {
\\ const x = shl(0b0010111111111111, 3);
@ -750,8 +781,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
);
cases.addRuntimeSafety("signed shift right overflow",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\pub fn main() !void {
\\ const x = shr(-16385, 1);
@ -763,8 +795,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
);
cases.addRuntimeSafety("unsigned shift right overflow",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\pub fn main() !void {
\\ const x = shr(0b0010111111111111, 3);
@ -776,8 +809,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
);
cases.addRuntimeSafety("integer division by zero",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\pub fn main() void {
\\ const x = div0(999, 0);
@ -788,22 +822,24 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
);
cases.addRuntimeSafety("integer division by zero - vectors",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\pub fn main() void {
\\ var a: @import("std").meta.Vector(4, i32) = [4]i32{111, 222, 333, 444};
\\ var b: @import("std").meta.Vector(4, i32) = [4]i32{111, 0, 333, 444};
\\ var a: std.meta.Vector(4, i32) = [4]i32{111, 222, 333, 444};
\\ var b: std.meta.Vector(4, i32) = [4]i32{111, 0, 333, 444};
\\ const x = div0(a, b);
\\}
\\fn div0(a: @import("std").meta.Vector(4, i32), b: @import("std").meta.Vector(4, i32)) @import("std").meta.Vector(4, i32) {
\\fn div0(a: std.meta.Vector(4, i32), b: std.meta.Vector(4, i32)) std.meta.Vector(4, i32) {
\\ return @divTrunc(a, b);
\\}
);
cases.addRuntimeSafety("exact division failure",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\pub fn main() !void {
\\ const x = divExact(10, 3);
@ -815,15 +851,16 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
);
cases.addRuntimeSafety("exact division failure - vectors",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\pub fn main() !void {
\\ var a: @import("std").meta.Vector(4, i32) = [4]i32{111, 222, 333, 444};
\\ var b: @import("std").meta.Vector(4, i32) = [4]i32{111, 222, 333, 441};
\\ var a: std.meta.Vector(4, i32) = [4]i32{111, 222, 333, 444};
\\ var b: std.meta.Vector(4, i32) = [4]i32{111, 222, 333, 441};
\\ const x = divExact(a, b);
\\}
\\fn divExact(a: @import("std").meta.Vector(4, i32), b: @import("std").meta.Vector(4, i32)) @import("std").meta.Vector(4, i32) {
\\fn divExact(a: std.meta.Vector(4, i32), b: std.meta.Vector(4, i32)) std.meta.Vector(4, i32) {
\\ return @divExact(a, b);
\\}
);
@ -843,8 +880,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
);
cases.addRuntimeSafety("value does not fit in shortening cast",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\pub fn main() !void {
\\ const x = shorten_cast(200);
@ -856,8 +894,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
);
cases.addRuntimeSafety("value does not fit in shortening cast - u0",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\pub fn main() !void {
\\ const x = shorten_cast(1);
@ -869,8 +908,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
);
cases.addRuntimeSafety("signed integer not fitting in cast to unsigned integer",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\pub fn main() !void {
\\ const x = unsigned_cast(-10);
@ -882,8 +922,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
);
cases.addRuntimeSafety("signed integer not fitting in cast to unsigned integer - widening",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\pub fn main() void {
\\ var value: c_short = -1;
@ -892,8 +933,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
);
cases.addRuntimeSafety("unsigned integer not fitting in cast to signed integer - same bit count",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\pub fn main() void {
\\ var value: u8 = 245;
@ -902,11 +944,12 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
);
cases.addRuntimeSafety("unwrap error",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ if (@import("std").mem.eql(u8, message, "attempt to unwrap error: Whatever")) {
\\ @import("std").os.exit(126); // good
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ if (std.mem.eql(u8, message, "attempt to unwrap error: Whatever")) {
\\ std.os.exit(126); // good
\\ }
\\ @import("std").os.exit(0); // test failed
\\ std.os.exit(0); // test failed
\\}
\\pub fn main() void {
\\ bar() catch unreachable;
@ -917,8 +960,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
);
cases.addRuntimeSafety("cast integer to global error and no code matches",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\pub fn main() void {
\\ bar(9999) catch {};
@ -929,8 +973,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
);
cases.addRuntimeSafety("@errSetCast error not present in destination",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\const Set1 = error{A, B};
\\const Set2 = error{A, C};
@ -960,8 +1005,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
);
cases.addRuntimeSafety("bad union field access",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\
\\const Foo = union {
@ -983,8 +1029,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
// but we still emit a safety check to ensure the integer was 0 and thus
// did not truncate information.
cases.addRuntimeSafety("@intCast to u0",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\
\\pub fn main() void {
@ -1001,7 +1048,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
cases.addRuntimeSafety("error return trace across suspend points",
\\const std = @import("std");
\\
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\
@ -1035,8 +1082,9 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
// Slicing a C pointer returns a non-allowzero slice, thus we need to emit
// a safety check to ensure the pointer is not null.
cases.addRuntimeSafety("slicing null C pointer",
\\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
\\ @import("std").os.exit(126);
\\const std = @import("std");
\\pub fn panic(message: []const u8, stack_trace: ?*std.builtin.StackTrace) noreturn {
\\ std.os.exit(126);
\\}
\\
\\pub fn main() void {