-
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
Fix ICEs on invalid vtable size/alignment const UB errors #86245
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
52 changes: 52 additions & 0 deletions
52
src/test/ui/consts/const-eval/ub-incorrect-vtable.32bit.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,52 @@ | ||
error: any use of this value will cause an error | ||
--> $DIR/ub-incorrect-vtable.rs:19:14 | ||
| | ||
LL | / const INVALID_VTABLE_ALIGNMENT: &dyn Trait = | ||
LL | | unsafe { std::mem::transmute((&92u8, &[0usize, 1usize, 1000usize])) }; | ||
| |______________^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^__- | ||
| | | ||
| invalid vtable: alignment `1000` is not a power of 2 | ||
| | ||
= note: `#[deny(const_err)]` on by default | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800> | ||
|
||
error: any use of this value will cause an error | ||
--> $DIR/ub-incorrect-vtable.rs:25:14 | ||
| | ||
LL | / const INVALID_VTABLE_SIZE: &dyn Trait = | ||
LL | | unsafe { std::mem::transmute((&92u8, &[1usize, usize::MAX, 1usize])) }; | ||
| |______________^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^__- | ||
| | | ||
| invalid vtable: size is bigger than largest supported object | ||
| | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800> | ||
|
||
error[E0080]: it is undefined behavior to use this value | ||
--> $DIR/ub-incorrect-vtable.rs:36:1 | ||
| | ||
LL | / const INVALID_VTABLE_ALIGNMENT_UB: W<&dyn Trait> = | ||
LL | | unsafe { std::mem::transmute((&92u8, &(drop_me as fn(*mut usize), 1usize, 1000usize))) }; | ||
| |_____________________________________________________________________________________________^ type validation failed: encountered invalid vtable: alignment `1000` is not a power of 2 at .0 | ||
| | ||
= 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. | ||
= note: the raw bytes of the constant (size: 8, align: 4) { | ||
╾─allocN─╼ ╾─allocN─╼ │ ╾──╼╾──╼ | ||
} | ||
|
||
error[E0080]: it is undefined behavior to use this value | ||
--> $DIR/ub-incorrect-vtable.rs:41:1 | ||
| | ||
LL | / const INVALID_VTABLE_SIZE_UB: W<&dyn Trait> = | ||
LL | | unsafe { std::mem::transmute((&92u8, &(drop_me as fn(*mut usize), usize::MAX, 1usize))) }; | ||
| |______________________________________________________________________________________________^ type validation failed: encountered invalid vtable: size is bigger than largest supported object at .0 | ||
| | ||
= 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. | ||
= note: the raw bytes of the constant (size: 8, align: 4) { | ||
╾─allocN─╼ ╾─allocN─╼ │ ╾──╼╾──╼ | ||
} | ||
|
||
error: aborting due to 4 previous errors | ||
|
||
For more information about this error, try `rustc --explain E0080`. |
52 changes: 52 additions & 0 deletions
52
src/test/ui/consts/const-eval/ub-incorrect-vtable.64bit.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,52 @@ | ||
error: any use of this value will cause an error | ||
--> $DIR/ub-incorrect-vtable.rs:19:14 | ||
| | ||
LL | / const INVALID_VTABLE_ALIGNMENT: &dyn Trait = | ||
LL | | unsafe { std::mem::transmute((&92u8, &[0usize, 1usize, 1000usize])) }; | ||
| |______________^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^__- | ||
| | | ||
| invalid vtable: alignment `1000` is not a power of 2 | ||
| | ||
= note: `#[deny(const_err)]` on by default | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800> | ||
|
||
error: any use of this value will cause an error | ||
--> $DIR/ub-incorrect-vtable.rs:25:14 | ||
| | ||
LL | / const INVALID_VTABLE_SIZE: &dyn Trait = | ||
LL | | unsafe { std::mem::transmute((&92u8, &[1usize, usize::MAX, 1usize])) }; | ||
| |______________^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^__- | ||
| | | ||
| invalid vtable: size is bigger than largest supported object | ||
| | ||
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release! | ||
= note: for more information, see issue #71800 <https://github.com/rust-lang/rust/issues/71800> | ||
|
||
error[E0080]: it is undefined behavior to use this value | ||
--> $DIR/ub-incorrect-vtable.rs:36:1 | ||
| | ||
LL | / const INVALID_VTABLE_ALIGNMENT_UB: W<&dyn Trait> = | ||
LL | | unsafe { std::mem::transmute((&92u8, &(drop_me as fn(*mut usize), 1usize, 1000usize))) }; | ||
| |_____________________________________________________________________________________________^ type validation failed: encountered invalid vtable: alignment `1000` is not a power of 2 at .0 | ||
| | ||
= 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. | ||
= note: the raw bytes of the constant (size: 16, align: 8) { | ||
╾───────allocN───────╼ ╾───────allocN───────╼ │ ╾──────╼╾──────╼ | ||
} | ||
|
||
error[E0080]: it is undefined behavior to use this value | ||
--> $DIR/ub-incorrect-vtable.rs:41:1 | ||
| | ||
LL | / const INVALID_VTABLE_SIZE_UB: W<&dyn Trait> = | ||
LL | | unsafe { std::mem::transmute((&92u8, &(drop_me as fn(*mut usize), usize::MAX, 1usize))) }; | ||
| |______________________________________________________________________________________________^ type validation failed: encountered invalid vtable: size is bigger than largest supported object at .0 | ||
| | ||
= 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. | ||
= note: the raw bytes of the constant (size: 16, align: 8) { | ||
╾───────allocN───────╼ ╾───────allocN───────╼ │ ╾──────╼╾──────╼ | ||
} | ||
|
||
error: aborting due to 4 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 was deleted.
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.
@oli-obk reading this, I feel like we should reorder these error messages a bit, and make them more like
What do you think? (@lqd certainly not for this PR though)
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.
if you and oli want this, I can certainly do that 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.
This will affect many tests, so it should be a separate PR. Reviewing is also much easier if we keep PRs small. But sure, if you want to help with this that'd be great. :)
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.
Agreed, I'll do that in another PR.
Would something like this work for you ? Changing
ValidationFailure
's content from a String message to apath: Option<String>, mesg: String
so thatrust/compiler/rustc_mir/src/interpret/validity.rs
Lines 27 to 47 in 3e827cc
rust/compiler/rustc_middle/src/mir/interpret/error.rs
Line 326 in 2779fc1
(I don't know when I'll get to this though: I'm currently having trouble executing some 32bits tests of the master branch, which fail with syntax errors when executed in the test runner but not by themselves, making blessing tests rather ... difficult. Thankfully it did not happen on the test 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.
Let's discuss the implementation details elsewhere (possibly on Zulip), if/when @oli-obk agrees that we even want to do this. :)
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 agree that the proposed ordering is better than the current one