Skip to content

Commit 529b94e

Browse files
committed
[const-prop] Fix ICE when casting function pointers
This fixes an ICE when building libcore with `-Z mir-opt-level=3`.
1 parent daf1ed0 commit 529b94e

File tree

2 files changed

+29
-6
lines changed

2 files changed

+29
-6
lines changed

src/librustc_mir/transform/const_prop.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -525,12 +525,10 @@ impl<'a, 'mir, 'tcx> ConstPropagator<'a, 'mir, 'tcx> {
525525
source_info: SourceInfo,
526526
) {
527527
trace!("attepting to replace {:?} with {:?}", rval, value);
528-
self.ecx.validate_operand(
529-
value,
530-
vec![],
531-
None,
532-
true,
533-
).expect("value should already be a valid const");
528+
if let Err(e) = self.ecx.validate_operand(value, vec![], None, true) {
529+
trace!("validation error, attempt failed: {:?}", e);
530+
return;
531+
}
534532

535533
// FIXME> figure out what tho do when try_read_immediate fails
536534
let imm = self.use_ecx(source_info, |this| {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
fn main() {
2+
let _ = main as usize as *const fn();
3+
}
4+
5+
// END RUST SOURCE
6+
// START rustc.main.ConstProp.before.mir
7+
// bb0: {
8+
// ...
9+
// _3 = const main as fn() (Pointer(ReifyFnPointer));
10+
// _2 = move _3 as usize (Misc);
11+
// ...
12+
// _1 = move _2 as *const fn() (Misc);
13+
// ...
14+
// }
15+
// END rustc.main.ConstProp.before.mir
16+
// START rustc.main.ConstProp.after.mir
17+
// bb0: {
18+
// ...
19+
// _3 = const Scalar(AllocId(1).0x0) : fn();
20+
// _2 = move _3 as usize (Misc);
21+
// ...
22+
// _1 = const Scalar(AllocId(1).0x0) : *const fn();
23+
// ...
24+
// }
25+
// END rustc.main.ConstProp.after.mir

0 commit comments

Comments
 (0)