forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of rust-lang#123576 - matthiaskrgr:rollup-9wiqkfa, r=matth…
…iaskrgr Rollup of 6 pull requests Successful merges: - rust-lang#119224 (Drop panic hook after running tests) - rust-lang#123411 (Put checks that detect UB under their own flag below debug_assertions) - rust-lang#123516 (Do not ICE on field access check on expr with `ty::Error`) - rust-lang#123522 (Stabilize const Atomic*::into_inner) - rust-lang#123559 (Add a debug asserts call to match_projection_projections to ensure invariant) - rust-lang#123563 (Rewrite `version` test run-make as an UI test) Failed merges: - rust-lang#123569 (Move some tests) r? `@ghost` `@rustbot` modify labels: rollup
- Loading branch information
Showing
53 changed files
with
298 additions
and
80 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# `ub-checks` | ||
|
||
The tracking issue for this feature is: [#123499](https://github.com/rust-lang/rust/issues/123499). | ||
|
||
-------------------- | ||
|
||
The `-Zub-checks` compiler flag enables additional runtime checks that detect some causes of Undefined Behavior at runtime. | ||
By default, `-Zub-checks` flag inherits the value of `-Cdebug-assertions`. | ||
|
||
All checks are generated on a best-effort basis; even if we have a check implemented for some cause of Undefined Behavior, it may be possible for the check to not fire. | ||
If a dependency is compiled with `-Zub-checks=no` but the final binary or library is compiled with `-Zub-checks=yes`, UB checks reached by the dependency are likely to be optimized out. | ||
|
||
When `-Zub-checks` detects UB, a non-unwinding panic is produced. | ||
That means that we will not unwind the stack and will not call any `Drop` impls, but we will execute the configured panic hook. | ||
We expect that unsafe code has been written which relies on code not unwinding which may have UB checks inserted. | ||
Ergo, an unwinding panic could easily turn works-as-intended UB into a much bigger problem. | ||
Calling the panic hook theoretically has the same implications, but we expect that the standard library panic hook will be stateless enough to be always called, and that if a user has configured a panic hook that the hook may be very helpful to debugging the detected UB. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
// With -Zub-checks=yes (enabled by default by -Cdebug-assertions=yes) we will produce a runtime | ||
// check that the index to slice::get_unchecked is in-bounds of the slice. That is tested for by | ||
// tests/ui/precondition-checks/out-of-bounds-get-unchecked.rs | ||
// | ||
// This test ensures that such a runtime check is *not* emitted when debug-assertions are enabled, | ||
// but ub-checks are explicitly disabled. | ||
|
||
//@ revisions: DEBUG NOCHECKS | ||
//@ [DEBUG] compile-flags: | ||
//@ [NOCHECKS] compile-flags: -Zub-checks=no | ||
//@ compile-flags: -O -Cdebug-assertions=yes | ||
|
||
#![crate_type = "lib"] | ||
|
||
use std::ops::Range; | ||
|
||
// CHECK-LABEL: @slice_get_unchecked( | ||
#[no_mangle] | ||
pub unsafe fn slice_get_unchecked(x: &[i32], i: usize) -> &i32 { | ||
// CHECK: icmp ult | ||
// NOCHECKS: tail call void @llvm.assume | ||
// DEBUG: br i1 | ||
// DEBUG: call core::panicking::panic_nounwind | ||
// DEBUG: unreachable | ||
// CHECK: getelementptr inbounds | ||
// CHECK: ret ptr | ||
x.get_unchecked(i) | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.