-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Eliminate UbCheck
for non-standard libraries
#122282
Closed
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
//@ unit-test: InstSimplify | ||
//@ compile-flags: -Cdebug-assertions=no -Zinline-mir | ||
|
||
// EMIT_MIR ub_check.unwrap_unchecked.InstSimplify.diff | ||
pub fn unwrap_unchecked(x: Option<i32>) -> i32 { | ||
// CHECK-LABEL: fn unwrap_unchecked( | ||
// CHECK-NOT: UbCheck(LanguageUb) | ||
// CHECK: [[assume:_.*]] = const false; | ||
// CHECK-NEXT: assume([[assume]]); | ||
// CHECK-NEXT: unreachable_unchecked::precondition_check | ||
unsafe { x.unwrap_unchecked() } | ||
} | ||
|
||
fn main() { | ||
unwrap_unchecked(None); | ||
} |
55 changes: 55 additions & 0 deletions
55
tests/mir-opt/instsimplify/ub_check.unwrap_unchecked.InstSimplify.diff
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,55 @@ | ||
- // MIR for `unwrap_unchecked` before InstSimplify | ||
+ // MIR for `unwrap_unchecked` after InstSimplify | ||
|
||
fn unwrap_unchecked(_1: Option<i32>) -> i32 { | ||
debug x => _1; | ||
let mut _0: i32; | ||
let mut _2: std::option::Option<i32>; | ||
scope 1 { | ||
scope 2 (inlined #[track_caller] Option::<i32>::unwrap_unchecked) { | ||
debug self => _2; | ||
let mut _3: isize; | ||
scope 3 { | ||
debug val => _0; | ||
} | ||
scope 4 { | ||
scope 5 (inlined unreachable_unchecked) { | ||
let mut _4: bool; | ||
let _5: (); | ||
scope 6 { | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
bb0: { | ||
StorageLive(_2); | ||
_2 = _1; | ||
StorageLive(_3); | ||
StorageLive(_5); | ||
_3 = discriminant(_2); | ||
switchInt(move _3) -> [0: bb2, 1: bb3, otherwise: bb1]; | ||
} | ||
|
||
bb1: { | ||
unreachable; | ||
} | ||
|
||
bb2: { | ||
StorageLive(_4); | ||
- _4 = UbCheck(LanguageUb); | ||
+ _4 = const false; | ||
assume(_4); | ||
_5 = unreachable_unchecked::precondition_check() -> [return: bb1, unwind unreachable]; | ||
} | ||
|
||
bb3: { | ||
_0 = move ((_2 as Some).0: i32); | ||
StorageDead(_5); | ||
StorageDead(_3); | ||
StorageDead(_2); | ||
return; | ||
} | ||
} | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This transform breaks the documented semantics of these intrinsics in the interpreter: that UB checks are always disabled there.