Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Runtime safety (panic interface, slices) #19764

Open
wants to merge 154 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
154 commits
Select commit Hold shift + click to select a range
94cc651
std.builtin: Removed `format` from `StackTrace`.
amp-59 Mar 10, 2024
8a2df9d
c: Added placeholder `panicNew` function to replace `panic`.
amp-59 Mar 10, 2024
f9e0050
compiler_rt: Added placeholder `panicNew` function to replace `panic`.
amp-59 Mar 10, 2024
886fd57
std.builtin: Added the standard library implementation for `panicNew`.
amp-59 Mar 10, 2024
51b75df
std.multi_array_list: Rewrote `MultiArrayList.Slice.items` to not
amp-59 Mar 10, 2024
ff948d0
Builtin: Added field and module value `runtime_safety`.
amp-59 Mar 10, 2024
15c882c
type: Added function `allowSentinel` for determining whether an aggre…
amp-59 Mar 10, 2024
f488c1f
Module: Added cache of panic-related types and function references.
amp-59 Mar 10, 2024
9024015
Compilation: Added `runtime_safety` to cache. Currently using the
amp-59 Mar 10, 2024
e1050b8
Package.Module:
amp-59 Mar 10, 2024
65ce79e
main:
amp-59 Mar 10, 2024
6e29a90
Sema: Each of the following additions are to a sub-namespace `Runtime…
amp-59 Mar 10, 2024
a65c226
Sema: Added compile errors for non-scalar sentinels in functions:
amp-59 Mar 10, 2024
b0e6394
Sema: Added optional usage of `analyzeSlice2` by functions:
amp-59 Mar 10, 2024
d178d20
Sema: Added optional usage of `panicReachedUnreachable` by
amp-59 Mar 10, 2024
11691df
Sema: Added optional usage of `checkMismatchedForLoopCaptureLengths`
amp-59 Mar 10, 2024
04d7b0e
Sema: Added optional usage of `panicWithMsg` by `zirPanic`.
amp-59 Mar 10, 2024
436caf6
Sema: Added optional usage of `panicReachedUnreachable` by `analyzeCa…
amp-59 Mar 10, 2024
64c2137
Sema: Added optional usage of `checkCastToErrorFromInvalid`
amp-59 Mar 10, 2024
c51b932
Sema: Added optional usage of `checkCastToEnumFromInvalid` by
amp-59 Mar 10, 2024
0844b72
Sema: Added optional usage of `checkAccessNullValue` by
amp-59 Mar 10, 2024
901b465
Sema: Added optional usage of `checkAccessNullValue` by
amp-59 Mar 10, 2024
00d73f8
Sema: Added optional usage of `checkUnwrappedError` by
amp-59 Mar 10, 2024
7b733e7
Sema: Added optional usage of `checkUnwrappedError` by
amp-59 Mar 10, 2024
bc638a2
Sema: Added optional usage of `checkCastTruncatedData` and
amp-59 Mar 10, 2024
4563dc6
Sema: Added optional usage of `checkCastToEnumFromInvalid` by
amp-59 Mar 10, 2024
c6d9548
Sema: Added optional usage of `checkCastToEnumFromInvalid` and
amp-59 Mar 10, 2024
1bf37e6
Sema: Added optional usage of `panicUnwrappedError` to `maybeErrorUnw…
amp-59 Mar 10, 2024
9242dac
Sema: Added usage of `checkShiftAmountOverflow` and
amp-59 Mar 10, 2024
b9041bf
Sema: Added optional usage of `checkShiftAmountOverflow` and
amp-59 Mar 10, 2024
442a35f
Sema: Added optional usage of `checkArithmeticOverflow` by
amp-59 Mar 10, 2024
8febf86
Sema: Added optional usage of `checkArithmeticOverflow` by
amp-59 Mar 10, 2024
39ddcd2
Sema: Added optional usage of `checkDivisionByZero` by
amp-59 Mar 10, 2024
3f2a60f
Sema: Added optional usage of `checkArithmeticOverflow` by
amp-59 Mar 10, 2024
2cd6aa5
Sema: Added optional usage of `checkCastToEnumFromInvalid` by
amp-59 Mar 10, 2024
67da75a
Sema: Added optional usage of `checkCastToIntFromInvalid` by
amp-59 Mar 10, 2024
2ba80f4
Sema: Added optional usage of `checkCastToPointerFromInvalid` by
amp-59 Mar 10, 2024
218209e
Sema: Added optional usage of `checkCastToErrorFromInvalid` by
amp-59 Mar 10, 2024
1fc3ed0
Sema: Added optional usage of `checkCastToPointerFromInvalid` by
amp-59 Mar 10, 2024
b77bc3f
Sema: Added optional usage of `checkAliasingMemcpyArguments`,
amp-59 Mar 10, 2024
da5d75b
Sema: Added optional usage of `checkAccessInactiveUnionField` by
amp-59 Mar 10, 2024
fdeb462
Sema: Added optional usage of `checkAccessInactiveUnionField` by
amp-59 Mar 10, 2024
a706bf6
Sema: Added optional usage of `checkAccessOutOfBounds` by
amp-59 Mar 10, 2024
8d52709
Sema: Added optional usage of `checkAccessOutOfBounds` by
amp-59 Mar 10, 2024
5748840
Sema: Added optional usage of `checkAccessOutOfBounds` by
amp-59 Mar 10, 2024
a6b7cb7
Sema: Added optional usage of `checkAccessOutOfBounds` by
amp-59 Mar 10, 2024
99dd22a
Sema: Added optional usage of `checkCastToPointerFromInvalid` by
amp-59 Mar 10, 2024
05730b4
Sema:
amp-59 Mar 10, 2024
e67ac50
std.builtin: Repurposed definition of `default_panic`.
amp-59 Mar 11, 2024
fe3bd05
std.debug:
amp-59 Mar 11, 2024
d9a4cf1
std.builtin:
amp-59 Mar 11, 2024
a5e4c95
test.tests: Added definition for `panicNew` to godbolt test code.
amp-59 Mar 11, 2024
f029550
Sema: Destructured `SliceAnalysis`, as values and checks should be ob…
amp-59 Mar 12, 2024
53586d2
test: Removed `panic`-related test cases using the old interface.
amp-59 Mar 12, 2024
8c04e3a
crash_report: Added tentative definition for `compilerPanicNew`.
amp-59 Mar 12, 2024
1166e34
Sema: Attempted to reduce the number and frequency of use of potentially
amp-59 Mar 12, 2024
2ab3c36
Merge remote-tracking branch 'refs/remotes/origin/master' into runtim…
amp-59 Mar 12, 2024
f190dc1
Merge branch 'master' of https://github.com/ziglang/zig into runtime_…
amp-59 Apr 18, 2024
3293103
Sema: Updated for changes to compile-time pointers, `Alignment`, and …
amp-59 Apr 19, 2024
e704d9a
builtin: Removed `packed` from panic data type for
amp-59 Apr 19, 2024
d995178
Merge branch 'master' of https://github.com/ziglang/zig into runtime_…
amp-59 Apr 19, 2024
0152d9d
builtin: Changed error message to be adequate for a larger number of
amp-59 Apr 20, 2024
48697fc
Merge branch 'master' of https://github.com/ziglang/zig into runtime_…
amp-59 Apr 21, 2024
5ba88af
Merge branch 'master' of https://github.com/ziglang/zig into runtime_…
amp-59 Apr 22, 2024
17346b8
Sema: Updated `RuntimeSafety.abiSizeOfContainingDecl`.
amp-59 Apr 23, 2024
3734c11
Merge branch 'master' of https://github.com/ziglang/zig into runtime_…
amp-59 Apr 24, 2024
00d7c23
Sema:
amp-59 Apr 27, 2024
8178ed6
Sema: Updated `abiSizeOfContainingDecl` to exclude `usizeCast`.
amp-59 Apr 27, 2024
d107743
Sema:
amp-59 Apr 27, 2024
4426504
test: Updated return types.
amp-59 Apr 27, 2024
5dd4f39
test: Updated compile error test for slice of pointer-to-one.
amp-59 Apr 27, 2024
1fb30d9
Merge branch 'master' of https://github.com/ziglang/zig into runtime_…
amp-59 Apr 27, 2024
411dba1
Sema: Corrected `toUnsignedInt` to `getUnsignedIntAdvanced`. This unwrap
amp-59 Apr 28, 2024
c7d4e58
builtin:
amp-59 Apr 28, 2024
e3cdf74
test: Fixup precise error message source locations.
amp-59 Apr 28, 2024
bac3b9f
Sema: Reduced ambiguity of slice bounds compile error messages.
amp-59 Apr 28, 2024
d989c59
Merge branch 'master' of https://github.com/ziglang/zig into runtime_…
amp-59 Apr 28, 2024
ce79ca8
debug: Substituted usage of `std.os.abort` with `std.process.abort`.
amp-59 May 2, 2024
ee49dc2
builtin:
amp-59 May 2, 2024
d214cfc
meta: Relocated (added) `BestNum` and related.
amp-59 May 2, 2024
8059085
test:
amp-59 May 2, 2024
fe2e299
test: Restored many runtime safety tests. This includes some slice
amp-59 May 2, 2024
1519f84
test: Included `slice2.zig` in `behavior.zig`. A recent release
amp-59 May 2, 2024
72c854e
test: Updated test "type pun signed and unsigned as array pointer",
amp-59 May 2, 2024
cb99c8e
test: Updated test "comptime slice-sentinel in bounds (on target sent…
amp-59 May 2, 2024
45fa681
test: Removed test using illegal combination of slice inputs. That is,
amp-59 May 2, 2024
f24a0fa
test:
amp-59 May 2, 2024
812ff6c
Sema: Removed various work-in-progress elements, which will not be used.
amp-59 May 2, 2024
8de4351
test: Added compile error variants of `Sema.analyzeSlice2` testsuite.
amp-59 May 2, 2024
5f3555a
Merge branch 'master' of https://github.com/ziglang/zig into runtime_…
amp-59 May 2, 2024
fdfb156
test:
amp-59 May 10, 2024
d0d66f9
test: Updated `panic_has_source_location` to define `panicNew`.
amp-59 May 10, 2024
c459905
Sema: Removed all optional usage of the old panic interface.
amp-59 May 10, 2024
e9cc266
Sema: Relocated `Sema.analyzeSlice2` to the file scope namespace.
amp-59 May 10, 2024
5f92f62
Sema: Removed `air_tag_safe` from primary `analyzeArithmetic` switch, as
amp-59 May 10, 2024
e43d6be
Sema: Added check for backend support for error return trace. It is
amp-59 May 10, 2024
0eaa15c
Sema: Removed `analyzeSlice`.
amp-59 May 10, 2024
95122fb
Sema:
amp-59 May 11, 2024
9f147ed
main: Removed command line parsing for test options.
amp-59 May 11, 2024
83d9fa6
Builtin: Removed `runtime_safety` field and module value.
amp-59 May 11, 2024
094d970
Sema: Added attempt to optimise arithmetic overflow check. This has
amp-59 May 11, 2024
4c1a227
Sema: Updated `prepareRuntimeSafety` to be less lenient regarding `pa…
amp-59 May 11, 2024
3486a21
lib: Removed old panic interface definitions from compiler_rt and c.
amp-59 May 12, 2024
ea8f407
builtin:
amp-59 May 12, 2024
1c19a5c
builtin: Updated `PanicData` to match the compiler implementation
amp-59 May 12, 2024
3e82d47
builtin: Removed `RuntimeSafety` type definition.
amp-59 May 12, 2024
942806f
builtin: Updated `panicImpl` to avoid `never_inline`.
amp-59 May 12, 2024
f72f49b
debug: Minor restructure to provide for rendering operands in
amp-59 May 12, 2024
a90c4f9
debug: Improved presentability of vector arithmetic overflow messages.
amp-59 May 12, 2024
c23e812
meta: Added another useful function `Scalar`.
amp-59 May 12, 2024
eb367f4
Compilation: Removed `runtime_safety` from cache.
amp-59 May 12, 2024
f13051d
Module:
amp-59 May 12, 2024
6e2e9f0
Sema: Made `casted_rhs_val` a parameter of `checkSimpleArithmeticOver…
amp-59 May 12, 2024
d7ea11c
Merge branch 'master' of https://github.com/ziglang/zig into runtime_…
amp-59 May 12, 2024
1072c2a
builtin: Renamed arithmetic overflow formatter structs.
amp-59 May 14, 2024
2d3846d
Sema: Removed unused functions: `panicWithMsg`, `panicUnwrapError`,
amp-59 May 14, 2024
9c6b1f4
test:
amp-59 May 14, 2024
c8296a5
langref: Updated panic error messages.
amp-59 May 16, 2024
d7aa820
builtin: Removed panic causes without panic data from primary switch, as
amp-59 May 16, 2024
e817541
debug: Combined error message writers for `(add|sub|div|mul)_overflow…
amp-59 May 16, 2024
7e617d2
Sema: Removed experimental optimisation. It caused problems with
amp-59 May 16, 2024
e5dffaa
Sema:
amp-59 May 16, 2024
0fa47ce
Sema:
amp-59 May 16, 2024
29f35cc
Merge branch 'master' of https://github.com/ziglang/zig into runtime_…
amp-59 May 16, 2024
7fed217
nextafter: Added workaround to avoid introduction of `zig_make_big`,
amp-59 May 17, 2024
d4e9d57
Module: Removed unused `safety` cache elements.
amp-59 May 20, 2024
3b300fb
Sema: Added simple panic interface mode.
amp-59 May 20, 2024
2945639
builtin: Added panic function types to guide user declarations.
amp-59 May 20, 2024
d1a246c
test: Added runtime panic variants for slices of various pointers to
amp-59 May 20, 2024
ecc1860
Merge branch 'master' of https://github.com/ziglang/zig into runtime_…
amp-59 May 20, 2024
c51a44e
test: Updated runtime panic test cases definitions of `panic2`.
amp-59 May 24, 2024
2c4bca6
c: Updated definitions related to `panic2`.
amp-59 May 24, 2024
7df0078
builtin:
amp-59 May 24, 2024
d796bc5
Module: Removed unused fields related to simple panics.
amp-59 May 24, 2024
80b95f7
Sema:
amp-59 May 24, 2024
b2aec81
Sema: Changed method used to determine bits shifted-out by `@shrExact`.
amp-59 May 24, 2024
8b3bd60
Sema: Restored usage of safe arithmetic instructions when the panic
amp-59 May 24, 2024
c378d7f
Sema: Removed `inc_overflowed` and `dec_overflowed` from `RuntimeSafe…
amp-59 May 24, 2024
7c28d24
Sema: Many minor changes intended to enable reuse of generic
amp-59 May 24, 2024
cbbb9d3
llvm:
amp-59 May 24, 2024
2f06f82
Sema:
amp-59 May 24, 2024
458cafc
test:
amp-59 May 24, 2024
278ffff
Merge branch 'master' of https://github.com/ziglang/zig into runtime_…
amp-59 May 24, 2024
a7f8cf7
Sema: Implemented slice casts, closes #20057.
amp-59 May 26, 2024
3e848ae
Merge branch 'master' of https://github.com/ziglang/zig into runtime_…
amp-59 May 26, 2024
e5af5aa
crash_report: Restored old `panic`. This settles the question of whether
amp-59 May 26, 2024
53b5879
main: Removed `RuntimeSafety` namespace.
amp-59 May 26, 2024
83d6c7e
builtin: Made `panicImpl` and `panicImplData` public, allowing the user
amp-59 May 26, 2024
2b568a4
builtin: Disabled runtime safety for `addErrRetTraceAddr`.
amp-59 May 26, 2024
6949b3a
Compilation: Handle error from `deleteFile` so that the desired
amp-59 May 26, 2024
61e4bf8
fixup!
amp-59 May 26, 2024
1ae4a73
builtin: Added to logic to determine the default panic interface mode.
amp-59 May 27, 2024
f3451dd
Merge branch 'master' of https://github.com/ziglang/zig into runtime_…
amp-59 May 27, 2024
d57f82c
Merge branch 'master' into runtime_safety
amp-59 May 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/langref/test_basic_slices.zig
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ test "basic slices" {
// asserts that the slice has len > 0.
}

// test_safety=index out of bounds
// test_safety=index 10 out of bounds of length 4
2 changes: 1 addition & 1 deletion doc/langref/test_intCast_builtin.zig
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ test "integer cast panic" {
_ = b;
}

// test_error=cast truncated bits
// test_error=cast to 'u8' from 'u16' truncated bits: 43981 above 'u8' maximum (255)
2 changes: 1 addition & 1 deletion doc/langref/test_setRuntimeSafety_builtin.zig
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ test "@setRuntimeSafety" {
}
}

// test_safety=integer overflow
// test_safety=add overflowed
// optimize=ReleaseFast
11 changes: 11 additions & 0 deletions lib/c.zig
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,17 @@ pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, _: ?
else => std.os.abort(),
}
}
/// TODO: Rename to `panic` when old interface is removed.
pub fn panic2(comptime _: std.builtin.PanicCause, data: anytype) noreturn {
@setCold(true);
if (builtin.is_test) {
std.debug.panic("{any}", .{data});
}
switch (native_os) {
.freestanding, .other, .amdhsa, .amdpal => while (true) {},
else => std.os.abort(),
}
}

extern fn main(argc: c_int, argv: [*:null]?[*:0]u8) c_int;
fn wasm_start() callconv(.C) void {
Expand Down
2 changes: 1 addition & 1 deletion lib/compiler_rt.zig
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const builtin = @import("builtin");

pub const panic = @import("compiler_rt/common.zig").panic;
pub const panic2 = @import("compiler_rt/common.zig").panic2;

comptime {
// Integer routines
Expand Down
14 changes: 4 additions & 10 deletions lib/compiler_rt/common.zig
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,10 @@ pub const gnu_f16_abi = switch (builtin.cpu.arch) {

pub const want_sparc_abi = builtin.cpu.arch.isSPARC();

// Avoid dragging in the runtime safety mechanisms into this .o file,
// unless we're trying to test compiler-rt.
pub fn panic(msg: []const u8, error_return_trace: ?*std.builtin.StackTrace, _: ?usize) noreturn {
_ = error_return_trace;
if (builtin.is_test) {
@setCold(true);
std.debug.panic("{s}", .{msg});
} else {
unreachable;
}
/// TODO: Rename to `panic` when old interface is removed.
pub fn panic2(_: std.builtin.PanicCause, _: anytype) noreturn {
@setRuntimeSafety(false);
unreachable;
}

/// AArch64 is the only ABI (at the moment) to support f16 arguments without the
Expand Down