Skip to content

Commit 95a6279

Browse files
authored
Rollup merge of #80878 - unseddd:abi, r=RalfJung
Add ABI argument to `find_mir_or_eval_fn` Add ABI argument for called function in `find_mir_or_eval_fn` and `call_extra_fn`. Useful for comparing with expected ABI in interpreters. Related to [miri/1631](rust-lang/miri#1631) r? `@RalfJung`
2 parents e728fcb + 06fd212 commit 95a6279

File tree

4 files changed

+14
-5
lines changed

4 files changed

+14
-5
lines changed

compiler/rustc_mir/src/const_eval/machine.rs

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use rustc_middle::mir::AssertMessage;
1313
use rustc_session::Limit;
1414
use rustc_span::symbol::{sym, Symbol};
1515
use rustc_target::abi::{Align, Size};
16+
use rustc_target::spec::abi::Abi;
1617

1718
use crate::interpret::{
1819
self, compile_time_machine, AllocId, Allocation, Frame, ImmTy, InterpCx, InterpResult, Memory,
@@ -203,6 +204,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for CompileTimeInterpreter<'mir,
203204
fn find_mir_or_eval_fn(
204205
ecx: &mut InterpCx<'mir, 'tcx, Self>,
205206
instance: ty::Instance<'tcx>,
207+
_abi: Abi,
206208
args: &[OpTy<'tcx>],
207209
_ret: Option<(PlaceTy<'tcx>, mir::BasicBlock)>,
208210
_unwind: Option<mir::BasicBlock>, // unwinding is not supported in consts

compiler/rustc_mir/src/interpret/machine.rs

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use rustc_middle::mir;
1010
use rustc_middle::ty::{self, Ty};
1111
use rustc_span::def_id::DefId;
1212
use rustc_target::abi::Size;
13+
use rustc_target::spec::abi::Abi;
1314

1415
use super::{
1516
AllocId, Allocation, AllocationExtra, CheckInAllocMsg, Frame, ImmTy, InterpCx, InterpResult,
@@ -144,6 +145,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
144145
fn find_mir_or_eval_fn(
145146
ecx: &mut InterpCx<'mir, 'tcx, Self>,
146147
instance: ty::Instance<'tcx>,
148+
abi: Abi,
147149
args: &[OpTy<'tcx, Self::PointerTag>],
148150
ret: Option<(PlaceTy<'tcx, Self::PointerTag>, mir::BasicBlock)>,
149151
unwind: Option<mir::BasicBlock>,
@@ -154,6 +156,7 @@ pub trait Machine<'mir, 'tcx>: Sized {
154156
fn call_extra_fn(
155157
ecx: &mut InterpCx<'mir, 'tcx, Self>,
156158
fn_val: Self::ExtraFnVal,
159+
abi: Abi,
157160
args: &[OpTy<'tcx, Self::PointerTag>],
158161
ret: Option<(PlaceTy<'tcx, Self::PointerTag>, mir::BasicBlock)>,
159162
unwind: Option<mir::BasicBlock>,
@@ -405,6 +408,7 @@ pub macro compile_time_machine(<$mir: lifetime, $tcx: lifetime>) {
405408
fn call_extra_fn(
406409
_ecx: &mut InterpCx<$mir, $tcx, Self>,
407410
fn_val: !,
411+
_abi: Abi,
408412
_args: &[OpTy<$tcx>],
409413
_ret: Option<(PlaceTy<$tcx>, mir::BasicBlock)>,
410414
_unwind: Option<mir::BasicBlock>,

compiler/rustc_mir/src/interpret/terminator.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
219219
let instance = match fn_val {
220220
FnVal::Instance(instance) => instance,
221221
FnVal::Other(extra) => {
222-
return M::call_extra_fn(self, extra, args, ret, unwind);
222+
return M::call_extra_fn(self, extra, caller_abi, args, ret, unwind);
223223
}
224224
};
225225

@@ -264,10 +264,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
264264
| ty::InstanceDef::CloneShim(..)
265265
| ty::InstanceDef::Item(_) => {
266266
// We need MIR for this fn
267-
let body = match M::find_mir_or_eval_fn(self, instance, args, ret, unwind)? {
268-
Some(body) => body,
269-
None => return Ok(()),
270-
};
267+
let body =
268+
match M::find_mir_or_eval_fn(self, instance, caller_abi, args, ret, unwind)? {
269+
Some(body) => body,
270+
None => return Ok(()),
271+
};
271272

272273
self.push_stack_frame(
273274
instance,

compiler/rustc_mir/src/transform/const_prop.rs

+2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use rustc_middle::ty::{
2525
use rustc_session::lint;
2626
use rustc_span::{def_id::DefId, Span};
2727
use rustc_target::abi::{HasDataLayout, LayoutOf, Size, TargetDataLayout};
28+
use rustc_target::spec::abi::Abi;
2829
use rustc_trait_selection::traits;
2930

3031
use crate::const_eval::ConstEvalErr;
@@ -187,6 +188,7 @@ impl<'mir, 'tcx> interpret::Machine<'mir, 'tcx> for ConstPropMachine<'mir, 'tcx>
187188
fn find_mir_or_eval_fn(
188189
_ecx: &mut InterpCx<'mir, 'tcx, Self>,
189190
_instance: ty::Instance<'tcx>,
191+
_abi: Abi,
190192
_args: &[OpTy<'tcx>],
191193
_ret: Option<(PlaceTy<'tcx>, BasicBlock)>,
192194
_unwind: Option<BasicBlock>,

0 commit comments

Comments
 (0)