Skip to content

Commit b93753e

Browse files
authored
Rollup merge of #85087 - hyd-dev:lots-of-abis, r=RalfJung
`eval_fn_call`: check the ABI of `body.source` And stop checking `instance_ty.fn_sig(*self.tcx).abi()`, if the function is not an intrinsic. Addresses rust-lang/miri#1776 (comment). No idea how to test this without Miri...
2 parents 9964284 + 97bc0ee commit b93753e

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

compiler/rustc_mir/src/interpret/terminator.rs

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@ use std::convert::TryFrom;
33

44
use rustc_middle::ty::layout::TyAndLayout;
55
use rustc_middle::ty::Instance;
6-
use rustc_middle::{mir, ty};
6+
use rustc_middle::{
7+
mir,
8+
ty::{self, Ty},
9+
};
710
use rustc_target::abi::{self, LayoutOf as _};
811
use rustc_target::spec::abi::Abi;
912

@@ -228,15 +231,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
228231
};
229232

230233
// ABI check
231-
{
232-
let callee_abi = {
233-
let instance_ty = instance.ty(*self.tcx, self.param_env);
234-
match instance_ty.kind() {
235-
ty::FnDef(..) => instance_ty.fn_sig(*self.tcx).abi(),
236-
ty::Closure(..) => Abi::RustCall,
237-
ty::Generator(..) => Abi::Rust,
238-
_ => span_bug!(self.cur_span(), "unexpected callee ty: {:?}", instance_ty),
239-
}
234+
let check_abi = |this: &Self, instance_ty: Ty<'tcx>| -> InterpResult<'tcx> {
235+
let callee_abi = match instance_ty.kind() {
236+
ty::FnDef(..) => instance_ty.fn_sig(*this.tcx).abi(),
237+
ty::Closure(..) => Abi::RustCall,
238+
ty::Generator(..) => Abi::Rust,
239+
_ => span_bug!(this.cur_span(), "unexpected callee ty: {:?}", instance_ty),
240240
};
241241
let normalize_abi = |abi| match abi {
242242
Abi::Rust | Abi::RustCall | Abi::RustIntrinsic | Abi::PlatformIntrinsic =>
@@ -253,10 +253,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
253253
caller_abi.name()
254254
)
255255
}
256-
}
256+
Ok(())
257+
};
257258

258259
match instance.def {
259260
ty::InstanceDef::Intrinsic(..) => {
261+
check_abi(self, instance.ty(*self.tcx, self.param_env))?;
260262
assert!(caller_abi == Abi::RustIntrinsic || caller_abi == Abi::PlatformIntrinsic);
261263
M::call_intrinsic(self, instance, args, ret, unwind)
262264
}
@@ -274,6 +276,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
274276
None => return Ok(()),
275277
};
276278

279+
// Check against the ABI of the MIR body we are calling (not the ABI of `instance`;
280+
// these can differ when `find_mir_or_eval_fn` does something clever like resolve
281+
// exported symbol names).
282+
check_abi(self, self.tcx.type_of(body.source.def_id()))?;
283+
277284
self.push_stack_frame(
278285
instance,
279286
body,

0 commit comments

Comments
 (0)