Skip to content

Commit a73e255

Browse files
committed
fix ICE in ConstProp
1 parent dfd243e commit a73e255

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

compiler/rustc_const_eval/src/interpret/machine.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use rustc_middle::mir;
1010
use rustc_middle::ty::{self, Ty, TyCtxt};
1111
use rustc_span::def_id::DefId;
1212
use rustc_target::abi::Size;
13-
use rustc_target::spec::abi::Abi;
13+
use rustc_target::spec::abi::Abi as FnAbi;
1414

1515
use super::{
1616
AllocId, AllocRange, Allocation, ConstAllocation, Frame, ImmTy, InterpCx, InterpResult,
@@ -139,7 +139,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
139139
/// Whether to enforce integers and floats not having provenance.
140140
fn enforce_number_no_provenance(ecx: &InterpCx<'mir, 'tcx, Self>) -> bool;
141141

142-
/// Whether function calls should be [ABI](Abi)-checked.
142+
/// Whether function calls should be [ABI](FnAbi)-checked.
143143
fn enforce_abi(_ecx: &InterpCx<'mir, 'tcx, Self>) -> bool {
144144
true
145145
}
@@ -170,7 +170,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
170170
fn find_mir_or_eval_fn(
171171
ecx: &mut InterpCx<'mir, 'tcx, Self>,
172172
instance: ty::Instance<'tcx>,
173-
abi: Abi,
173+
abi: FnAbi,
174174
args: &[OpTy<'tcx, Self::PointerTag>],
175175
destination: &PlaceTy<'tcx, Self::PointerTag>,
176176
target: Option<mir::BasicBlock>,
@@ -182,7 +182,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
182182
fn call_extra_fn(
183183
ecx: &mut InterpCx<'mir, 'tcx, Self>,
184184
fn_val: Self::ExtraFnVal,
185-
abi: Abi,
185+
abi: FnAbi,
186186
args: &[OpTy<'tcx, Self::PointerTag>],
187187
destination: &PlaceTy<'tcx, Self::PointerTag>,
188188
target: Option<mir::BasicBlock>,
@@ -480,7 +480,7 @@ pub macro compile_time_machine(<$mir: lifetime, $tcx: lifetime>) {
480480
fn call_extra_fn(
481481
_ecx: &mut InterpCx<$mir, $tcx, Self>,
482482
fn_val: !,
483-
_abi: Abi,
483+
_abi: FnAbi,
484484
_args: &[OpTy<$tcx>],
485485
_destination: &PlaceTy<$tcx, Self::PointerTag>,
486486
_target: Option<mir::BasicBlock>,

compiler/rustc_mir_transform/src/const_prop.rs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ use rustc_middle::ty::{
2222
self, ConstKind, EarlyBinder, Instance, ParamEnv, Ty, TyCtxt, TypeVisitable,
2323
};
2424
use rustc_span::{def_id::DefId, Span};
25-
use rustc_target::abi::{HasDataLayout, Size, TargetDataLayout};
26-
use rustc_target::spec::abi::Abi;
25+
use rustc_target::abi::{self, HasDataLayout, Size, TargetDataLayout};
26+
use rustc_target::spec::abi::Abi as FnAbi;
2727
use rustc_trait_selection::traits;
2828

2929
use crate::MirPass;
@@ -199,7 +199,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine<'mir, 'tcx>
199199
fn find_mir_or_eval_fn(
200200
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
201201
_instance: ty::Instance<'tcx>,
202-
_abi: Abi,
202+
_abi: FnAbi,
203203
_args: &[OpTy<'tcx>],
204204
_destination: &PlaceTy<'tcx>,
205205
_target: Option<BasicBlock>,
@@ -654,6 +654,11 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
654654
(Ok(_), Ok(_)) => return this.ecx.eval_rvalue_into_place(rvalue, place),
655655
};
656656

657+
if !matches!(const_arg.layout.abi, abi::Abi::Scalar(..)) {
658+
// We cannot handle Scalar Pair stuff.
659+
return this.ecx.eval_rvalue_into_place(rvalue, place);
660+
}
661+
657662
let arg_value = const_arg.to_scalar()?.to_bits(const_arg.layout.size)?;
658663
let dest = this.ecx.eval_place(place)?;
659664

src/test/ui/consts/issue-96169.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// check-pass
2+
// compile-flags: -Zmir-opt-level=4 --emit=mir
3+
#![allow(unused)]
4+
fn a() -> usize { 0 }
5+
6+
fn bar(_: u32) {}
7+
8+
fn baz() -> *const dyn Fn(u32) { unimplemented!() }
9+
10+
fn foo() {
11+
match () {
12+
_ if baz() == &bar as &dyn Fn(u32) => (),
13+
() => (),
14+
}
15+
}
16+
17+
fn main() {
18+
}

0 commit comments

Comments
 (0)