-
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
Conversation
Some changes occured to the CTFE / Miri engine cc @rust-lang/miri Some changes occured to the CTFE / Miri engine cc @rust-lang/miri |
This comment has been minimized.
This comment has been minimized.
c29f599
to
b38e376
Compare
/// Invalid size in a vtable: too large. | ||
InvalidSize, | ||
/// Invalid alignment in a vtable: too large, or not a power of 2. | ||
InvalidAlignment(String), |
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 feel like InvalidVtable{Size,Alignment,DropFn}
would be clearer names for these variants. What do you think?
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.
sure, I'll do that ! I initially did name those specifically for vtables but then InvalidDropFn
"convinced me" not to do so ^^
// ICEs as tracked by #86193. So we also use the transparent wrapper to verify actual const UB hard | ||
// errors are emitted now instead of ICEs. |
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.
// ICEs as tracked by #86193. So we also use the transparent wrapper to verify actual const UB hard | |
// errors are emitted now instead of ICEs. | |
// ICEs as tracked by #86193. So we also use the transparent wrapper to verify proper validation | |
// errors are emitted instead of ICEs. |
| | ||
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 |
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.
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 a path: Option<String>, mesg: String
so that
rust/compiler/rustc_mir/src/interpret/validity.rs
Lines 27 to 47 in 3e827cc
macro_rules! throw_validation_failure { | |
($where:expr, { $( $what_fmt:expr ),+ } $( expected { $( $expected_fmt:expr ),+ } )?) => {{ | |
let msg = rustc_middle::ty::print::with_no_trimmed_paths(|| { | |
let mut msg = String::new(); | |
msg.push_str("encountered "); | |
write!(&mut msg, $($what_fmt),+).unwrap(); | |
let where_ = &$where; | |
if !where_.is_empty() { | |
msg.push_str(" at "); | |
write_path(&mut msg, where_); | |
} | |
$( | |
msg.push_str(", but expected "); | |
write!(&mut msg, $($expected_fmt),+).unwrap(); | |
)? | |
msg | |
}); | |
throw_ub!(ValidationFailure(msg)) | |
}}; | |
} |
ValidationFailure(ref err) => write!(f, "type validation failed: {}", err), |
(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
This looks great, thanks a lot. :-) |
📌 Commit 9c7133c95bdfaf3b14798f61d40edeb1564b2ed3 has been approved by |
This comment has been minimized.
This comment has been minimized.
@bors r- |
They were "freeform const UB" error message, but could reach validation and trigger ICEs there. We now catch them during validation to avoid that.
CI is green after actually calling rustfmt... @bors r=RalfJung |
📌 Commit e29f3e8 has been approved by |
☀️ Test successful - checks-actions |
Improve CTFE UB validation error messages As mentioned in rust-lang#86245 (comment) this PR slightly improves the formatting of validation errors, to move the path to the error prefix. From: `type validation failed: encountered invalid vtable: size is bigger than largest supported object at .0` To: `type validation failed at .0: encountered invalid vtable: size is bigger than largest supported object`.
Improve CTFE UB validation error messages As mentioned in rust-lang#86245 (comment) this PR slightly improves the formatting of validation errors, to move the path to the error prefix. From: `type validation failed: encountered invalid vtable: size is bigger than largest supported object at .0` To: `type validation failed at .0: encountered invalid vtable: size is bigger than largest supported object`.
The invalid vtable size/alignment errors from
InterpCx::read_size_and_align_from_vtable
were "freeform const UB errors", causing ICEs when reaching validation. This PR turns them into const UB hard errors to catch them during validation and avoid that.Fixes #86193
r? @RalfJung
(It seemed cleaner to have 2 variants but they can be merged into one variant with a message payload if you prefer that ?)