-
Notifications
You must be signed in to change notification settings - Fork 12.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #120367 - RalfJung:project_downcast_uninhabited, r=oli-obk
interpret: project_downcast: do not ICE for uninhabited variants Fixes #120337 This assertion was already under discussion for a bit; I think the [example](#120337 (comment)) `@tmiasko` found is the final nail in the coffin. One could argue maybe MIR building should read the discriminant before projecting, but even then MIR optimizations should be allowed to remove that read, so the downcast should still not ICE. Maybe the downcast should be UB, but in this example UB already arises earlier when a value of type `E` is constructed. r? `@oli-obk`
- Loading branch information
Showing
9 changed files
with
128 additions
and
26 deletions.
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
16 changes: 16 additions & 0 deletions
16
src/tools/miri/tests/pass/issues/issue-120337-irrefutable-let-ice.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,16 @@ | ||
// Validation stops the test before the ICE we used to hit | ||
//@compile-flags: -Zmiri-disable-validation | ||
|
||
#![feature(never_type)] | ||
#[derive(Copy, Clone)] | ||
pub enum E { | ||
A(!), | ||
} | ||
pub union U { | ||
u: (), | ||
e: E, | ||
} | ||
|
||
fn main() { | ||
let E::A(ref _a) = unsafe { &(&U { u: () }).e }; | ||
} |
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,34 @@ | ||
- // MIR for `f` before GVN | ||
+ // MIR for `f` after GVN | ||
|
||
fn f() -> u32 { | ||
let mut _0: u32; | ||
let _1: u32; | ||
let mut _2: E; | ||
let mut _3: &U; | ||
let _4: U; | ||
scope 1 { | ||
debug i => _1; | ||
} | ||
scope 2 { | ||
let mut _5: &U; | ||
} | ||
|
||
bb0: { | ||
StorageLive(_2); | ||
StorageLive(_3); | ||
_5 = const _; | ||
_3 = &(*_5); | ||
_2 = ((*_3).1: E); | ||
StorageLive(_1); | ||
- _1 = ((_2 as A).1: u32); | ||
+ _1 = const 0_u32; | ||
StorageDead(_3); | ||
StorageDead(_2); | ||
- _0 = _1; | ||
+ _0 = const 0_u32; | ||
StorageDead(_1); | ||
return; | ||
} | ||
} | ||
|
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,34 @@ | ||
- // MIR for `f` before GVN | ||
+ // MIR for `f` after GVN | ||
|
||
fn f() -> u32 { | ||
let mut _0: u32; | ||
let _1: u32; | ||
let mut _2: E; | ||
let mut _3: &U; | ||
let _4: U; | ||
scope 1 { | ||
debug i => _1; | ||
} | ||
scope 2 { | ||
let mut _5: &U; | ||
} | ||
|
||
bb0: { | ||
StorageLive(_2); | ||
StorageLive(_3); | ||
_5 = const _; | ||
_3 = &(*_5); | ||
_2 = ((*_3).1: E); | ||
StorageLive(_1); | ||
- _1 = ((_2 as A).1: u32); | ||
+ _1 = const 0_u32; | ||
StorageDead(_3); | ||
StorageDead(_2); | ||
- _0 = _1; | ||
+ _0 = const 0_u32; | ||
StorageDead(_1); | ||
return; | ||
} | ||
} | ||
|
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,24 @@ | ||
// unit-test: GVN | ||
// compile-flags: -O | ||
// EMIT_MIR_FOR_EACH_PANIC_STRATEGY | ||
// skip-filecheck | ||
|
||
#![feature(never_type)] | ||
|
||
#[derive(Copy, Clone)] | ||
pub enum E { | ||
A(!, u32), | ||
} | ||
|
||
pub union U { | ||
i: u32, | ||
e: E, | ||
} | ||
|
||
// EMIT_MIR gvn_uninhabited.f.GVN.diff | ||
pub const fn f() -> u32 { | ||
let E::A(_, i) = unsafe { (&U { i: 0 }).e }; | ||
i | ||
} | ||
|
||
fn main() {} |
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,10 @@ | ||
// check-pass | ||
#![feature(never_type)] | ||
#[derive(Copy, Clone)] | ||
pub enum E { A(!), } | ||
pub union U { u: (), e: E, } | ||
pub const C: () = { | ||
let E::A(ref a) = unsafe { &(&U { u: () }).e}; | ||
}; | ||
|
||
fn main() {} |