Skip to content

Commit fa8f6b6

Browse files
authored
Rollup merge of rust-lang#98980 - RalfJung:const-prop-ice, r=oli-obk
fix ICE in ConstProp Fixes rust-lang#96169
2 parents 62f13cd + cf9186e commit fa8f6b6

File tree

6 files changed

+39
-12
lines changed

6 files changed

+39
-12
lines changed

compiler/rustc_const_eval/src/const_eval/machine.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use rustc_middle::mir::AssertMessage;
1414
use rustc_session::Limit;
1515
use rustc_span::symbol::{sym, Symbol};
1616
use rustc_target::abi::{Align, Size};
17-
use rustc_target::spec::abi::Abi;
17+
use rustc_target::spec::abi::Abi as CallAbi;
1818

1919
use crate::interpret::{
2020
self, compile_time_machine, AllocId, ConstAllocation, Frame, ImmTy, InterpCx, InterpResult,
@@ -263,7 +263,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
263263
fn find_mir_or_eval_fn(
264264
ecx: &mut InterpCx<'mir, 'tcx, Self>,
265265
instance: ty::Instance<'tcx>,
266-
_abi: Abi,
266+
_abi: CallAbi,
267267
args: &[OpTy<'tcx>],
268268
_dest: &PlaceTy<'tcx>,
269269
_ret: Option<mir::BasicBlock>,

compiler/rustc_const_eval/src/interpret/machine.rs

+5-5
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 CallAbi;
1414

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

141-
/// Whether function calls should be [ABI](Abi)-checked.
141+
/// Whether function calls should be [ABI](CallAbi)-checked.
142142
fn enforce_abi(_ecx: &InterpCx<'mir, 'tcx, Self>) -> bool {
143143
true
144144
}
@@ -169,7 +169,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
169169
fn find_mir_or_eval_fn(
170170
ecx: &mut InterpCx<'mir, 'tcx, Self>,
171171
instance: ty::Instance<'tcx>,
172-
abi: Abi,
172+
abi: CallAbi,
173173
args: &[OpTy<'tcx, Self::PointerTag>],
174174
destination: &PlaceTy<'tcx, Self::PointerTag>,
175175
target: Option<mir::BasicBlock>,
@@ -181,7 +181,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
181181
fn call_extra_fn(
182182
ecx: &mut InterpCx<'mir, 'tcx, Self>,
183183
fn_val: Self::ExtraFnVal,
184-
abi: Abi,
184+
abi: CallAbi,
185185
args: &[OpTy<'tcx, Self::PointerTag>],
186186
destination: &PlaceTy<'tcx, Self::PointerTag>,
187187
target: Option<mir::BasicBlock>,
@@ -483,7 +483,7 @@ pub macro compile_time_machine(<$mir: lifetime, $tcx: lifetime>) {
483483
fn call_extra_fn(
484484
_ecx: &mut InterpCx<$mir, $tcx, Self>,
485485
fn_val: !,
486-
_abi: Abi,
486+
_abi: CallAbi,
487487
_args: &[OpTy<$tcx>],
488488
_destination: &PlaceTy<$tcx, Self::PointerTag>,
489489
_target: Option<mir::BasicBlock>,

compiler/rustc_const_eval/src/interpret/operand.rs

+4
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ impl<'tcx, Tag: Provenance> Immediate<Tag> {
7878
}
7979

8080
#[inline]
81+
#[cfg_attr(debug_assertions, track_caller)] // only in debug builds due to perf (see #98980)
8182
pub fn to_scalar_or_uninit(self) -> ScalarMaybeUninit<Tag> {
8283
match self {
8384
Immediate::Scalar(val) => val,
@@ -87,11 +88,13 @@ impl<'tcx, Tag: Provenance> Immediate<Tag> {
8788
}
8889

8990
#[inline]
91+
#[cfg_attr(debug_assertions, track_caller)] // only in debug builds due to perf (see #98980)
9092
pub fn to_scalar(self) -> InterpResult<'tcx, Scalar<Tag>> {
9193
self.to_scalar_or_uninit().check_init()
9294
}
9395

9496
#[inline]
97+
#[cfg_attr(debug_assertions, track_caller)] // only in debug builds due to perf (see #98980)
9598
pub fn to_scalar_or_uninit_pair(self) -> (ScalarMaybeUninit<Tag>, ScalarMaybeUninit<Tag>) {
9699
match self {
97100
Immediate::ScalarPair(val1, val2) => (val1, val2),
@@ -101,6 +104,7 @@ impl<'tcx, Tag: Provenance> Immediate<Tag> {
101104
}
102105

103106
#[inline]
107+
#[cfg_attr(debug_assertions, track_caller)] // only in debug builds due to perf (see #98980)
104108
pub fn to_scalar_pair(self) -> InterpResult<'tcx, (Scalar<Tag>, Scalar<Tag>)> {
105109
let (val1, val2) = self.to_scalar_or_uninit_pair();
106110
Ok((val1.check_init()?, val2.check_init()?))

compiler/rustc_mir_transform/src/const_prop.rs

+8-3
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 CallAbi;
2727
use rustc_trait_selection::traits;
2828

2929
use crate::MirPass;
@@ -195,7 +195,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine<'mir, 'tcx>
195195
fn find_mir_or_eval_fn(
196196
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
197197
_instance: ty::Instance<'tcx>,
198-
_abi: Abi,
198+
_abi: CallAbi,
199199
_args: &[OpTy<'tcx>],
200200
_destination: &PlaceTy<'tcx>,
201201
_target: Option<BasicBlock>,
@@ -659,6 +659,11 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> {
659659
(Ok(_), Ok(_)) => return this.ecx.eval_rvalue_into_place(rvalue, place),
660660
};
661661

662+
if !matches!(const_arg.layout.abi, abi::Abi::Scalar(..)) {
663+
// We cannot handle Scalar Pair stuff.
664+
return this.ecx.eval_rvalue_into_place(rvalue, place);
665+
}
666+
662667
let arg_value = const_arg.to_scalar()?.to_bits(const_arg.layout.size)?;
663668
let dest = this.ecx.eval_place(place)?;
664669

compiler/rustc_mir_transform/src/const_prop_lint.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use rustc_middle::ty::{
2424
use rustc_session::lint;
2525
use rustc_span::{def_id::DefId, Span};
2626
use rustc_target::abi::{HasDataLayout, Size, TargetDataLayout};
27-
use rustc_target::spec::abi::Abi;
27+
use rustc_target::spec::abi::Abi as CallAbi;
2828
use rustc_trait_selection::traits;
2929

3030
use crate::MirLint;
@@ -191,7 +191,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine<'mir, 'tcx>
191191
fn find_mir_or_eval_fn(
192192
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
193193
_instance: ty::Instance<'tcx>,
194-
_abi: Abi,
194+
_abi: CallAbi,
195195
_args: &[OpTy<'tcx>],
196196
_destination: &PlaceTy<'tcx>,
197197
_target: Option<BasicBlock>,

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

+18
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)