-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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 transmute intrinsic mir validation ICE #109959
Conversation
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.
Thanks for catching this! Looks entirely reasonable to me, but I don't think I have enough context in exactly why it's needed to sign off.
aa6aaac
to
dd92a6a
Compare
I don't think we should just skip this check for opaques. We should probably instead normalize to reveal the opaque types, since we're always in a diff --git a/compiler/rustc_const_eval/src/transform/validate.rs b/compiler/rustc_const_eval/src/transform/validate.rs
index 0f56fda18f5..d4bed97380b 100644
--- a/compiler/rustc_const_eval/src/transform/validate.rs
+++ b/compiler/rustc_const_eval/src/transform/validate.rs
@@ -679,13 +679,21 @@ macro_rules! check_kinds {
// Unlike `mem::transmute`, a MIR `Transmute` is well-formed
// for any two `Sized` types, just potentially UB to run.
- if !op_ty.is_sized(self.tcx, self.param_env) {
+ if !self
+ .tcx
+ .normalize_erasing_regions(self.param_env, op_ty)
+ .is_sized(self.tcx, self.param_env)
+ {
self.fail(
location,
format!("Cannot transmute from non-`Sized` type {op_ty:?}"),
);
}
- if !target_type.is_sized(self.tcx, self.param_env) {
+ if !self
+ .tcx
+ .normalize_erasing_regions(self.param_env, *target_type)
+ .is_sized(self.tcx, self.param_env)
+ {
self.fail(
location,
format!("Cannot transmute to non-`Sized` type {target_type:?}"), |
For the more type system savvy, checking some "trivial" opaque self type obligation
... which means that we then try to equate the obligation
... which will fail because That's why normalizing here is the right thing to do -- we can only verify fully revealed predicates in fully revealed environments. |
dd92a6a
to
d8ed2fb
Compare
@bors r+ |
…ompiler-errors Fix transmute intrinsic mir validation ICE I stumbled across this at work, the minimal reproducer is included as a test which ICEs before this change. I'm not 100% sure this is the right fix, but it matches what we do in `mir_assign_valid_types` so seems reasonable at least. fixes rust-lang#110151 r? `@lcnr` since they've been keeping the relevant logic correct, cc `@scottmcm`
⌛ Testing commit d8ed2fb with merge 8c9883e63fd369fd83fd5be467dc14f8476bc2cb... |
💔 Test failed - checks-actions |
The job Click to see the possible cause of the failure (guessed by this bot)
|
Segfault so... maybe spurious? |
@bors retry |
…iaskrgr Rollup of 8 pull requests Successful merges: - rust-lang#109959 (Fix transmute intrinsic mir validation ICE) - rust-lang#110176 (Renumbering cleanups) - rust-lang#110182 (Use `itertools::Either` instead of own impl) - rust-lang#110188 (Remove orphaned remove_dir_all implementation from rust-installer) - rust-lang#110190 (Custom MIR: Support `BinOp::Offset`) - rust-lang#110209 (Add regression test for rust-lang#59003) - rust-lang#110210 (`DescriptionCtx` cleanups) - rust-lang#110217 (doc: loongarch: Fix typos) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
I stumbled across this at work, the minimal reproducer is included as a test which ICEs before this change.
I'm not 100% sure this is the right fix, but it matches what we do in
mir_assign_valid_types
so seems reasonable at least.fixes #110151
r? @lcnr since they've been keeping the relevant logic correct, cc @scottmcm