-
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
Miri interning: replace ICEs by proper errors #71665
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
c400f75
Miri interning: replace ICEs by proper errors, make intern_shallow ty…
RalfJung 8e48a30
remove some dead code, and assert we do not swallow allocating errors
RalfJung ff39457
avoid raising interpreter errors from interning
RalfJung d3b2e1f
fmt
RalfJung a06740c
Typo
RalfJung e73ee41
rebase fallout
RalfJung 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
Large diffs are not rendered by default.
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
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 |
---|---|---|
@@ -1,13 +1,25 @@ | ||
error: any use of this value will cause an error | ||
--> $DIR/dangling-alloc-id-ice.rs:8:1 | ||
error: encountered dangling pointer in final constant | ||
--> $DIR/dangling-alloc-id-ice.rs:9:1 | ||
| | ||
LL | / const FOO: &() = { | ||
LL | | | ||
LL | | let y = (); | ||
LL | | unsafe { Foo { y: &y }.long_live_the_unit } | ||
LL | | }; | ||
| |__^ encountered dangling pointer in final constant | ||
| |__^ | ||
|
||
error[E0080]: it is undefined behavior to use this value | ||
--> $DIR/dangling-alloc-id-ice.rs:9:1 | ||
| | ||
LL | / const FOO: &() = { | ||
LL | | | ||
LL | | let y = (); | ||
LL | | unsafe { Foo { y: &y }.long_live_the_unit } | ||
LL | | }; | ||
| |__^ type validation failed: encountered a dangling reference (use-after-free) | ||
| | ||
= note: `#[deny(const_err)]` on by default | ||
= note: The rules on what exactly is undefined behavior aren't clear, so this check might be overzealous. Please open an issue on the rustc repository if you believe it should not be considered undefined behavior. | ||
|
||
error: aborting due to previous error | ||
error: aborting due to 2 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0080`. |
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 |
---|---|---|
@@ -1,13 +1,11 @@ | ||
error: any use of this value will cause an error | ||
error: encountered dangling pointer in final constant | ||
--> $DIR/dangling_raw_ptr.rs:1:1 | ||
| | ||
LL | / const FOO: *const u32 = { | ||
LL | | let x = 42; | ||
LL | | &x | ||
LL | | }; | ||
| |__^ encountered dangling pointer in final constant | ||
| | ||
= note: `#[deny(const_err)]` on by default | ||
| |__^ | ||
|
||
error: aborting due to previous error | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
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
37 changes: 37 additions & 0 deletions
37
src/test/ui/consts/miri_unleashed/mutable_references_err.rs
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,37 @@ | ||
// compile-flags: -Zunleash-the-miri-inside-of-you | ||
|
||
#![allow(const_err)] | ||
|
||
use std::cell::UnsafeCell; | ||
|
||
// this test ensures that our mutability story is sound | ||
|
||
struct Meh { | ||
x: &'static UnsafeCell<i32>, | ||
} | ||
unsafe impl Sync for Meh {} | ||
|
||
// the following will never be ok! no interior mut behind consts, because | ||
// all allocs interned here will be marked immutable. | ||
const MUH: Meh = Meh { //~ ERROR: mutable memory (`UnsafeCell`) is not allowed in constant | ||
x: &UnsafeCell::new(42), | ||
}; | ||
|
||
struct Synced { | ||
x: UnsafeCell<i32>, | ||
} | ||
unsafe impl Sync for Synced {} | ||
|
||
// Make sure we also catch this behind a type-erased `dyn Trait` reference. | ||
const SNEAKY: &dyn Sync = &Synced { x: UnsafeCell::new(42) }; | ||
//~^ ERROR: mutable memory (`UnsafeCell`) is not allowed in constant | ||
|
||
// Make sure we also catch mutable references. | ||
const BLUNT: &mut i32 = &mut 42; | ||
//~^ ERROR: mutable memory (`&mut`) is not allowed in constant | ||
|
||
fn main() { | ||
unsafe { | ||
*MUH.x.get() = 99; | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
src/test/ui/consts/miri_unleashed/mutable_references_err.stderr
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,40 @@ | ||
error: mutable memory (`UnsafeCell`) is not allowed in constant | ||
--> $DIR/mutable_references_err.rs:16:1 | ||
| | ||
LL | / const MUH: Meh = Meh { | ||
LL | | x: &UnsafeCell::new(42), | ||
LL | | }; | ||
| |__^ | ||
|
||
error: mutable memory (`UnsafeCell`) is not allowed in constant | ||
--> $DIR/mutable_references_err.rs:26:1 | ||
| | ||
LL | const SNEAKY: &dyn Sync = &Synced { x: UnsafeCell::new(42) }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
error: mutable memory (`&mut`) is not allowed in constant | ||
--> $DIR/mutable_references_err.rs:30:1 | ||
| | ||
LL | const BLUNT: &mut i32 = &mut 42; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
||
warning: skipping const checks | ||
| | ||
help: skipping check that does not even have a feature gate | ||
--> $DIR/mutable_references_err.rs:17:8 | ||
| | ||
LL | x: &UnsafeCell::new(42), | ||
| ^^^^^^^^^^^^^^^^^^^^ | ||
help: skipping check that does not even have a feature gate | ||
--> $DIR/mutable_references_err.rs:26:27 | ||
| | ||
LL | const SNEAKY: &dyn Sync = &Synced { x: UnsafeCell::new(42) }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
help: skipping check for `const_mut_refs` feature | ||
--> $DIR/mutable_references_err.rs:30:25 | ||
| | ||
LL | const BLUNT: &mut i32 = &mut 42; | ||
| ^^^^^^^ | ||
|
||
error: aborting due to 3 previous errors; 1 warning emitted | ||
|
29 changes: 0 additions & 29 deletions
29
src/test/ui/consts/miri_unleashed/mutable_references_ice.rs
This file was deleted.
Oops, something went wrong.
25 changes: 0 additions & 25 deletions
25
src/test/ui/consts/miri_unleashed/mutable_references_ice.stderr
This file was deleted.
Oops, something went wrong.
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.
I still need to try and actually case the ICE here -- but my worry is that the
delay_span_bug
in interning all assume that validation will be run after interning is done, and this code here violates that assumption.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.
Turns out we can get that to ICE even without Miri:
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.
Do you want to add a test for this in this PR or fix it in this PR?
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.
The PR does contain a test for the ICE outside Miri -- mostly accidentally, when I added
allow(const_err)
I did not realize I was testing an ICE. ;)For whether this can ICE with Miri, I haven't done another attempt at triggering it (this one specifically is what I am worried about).