Skip to content

Commit 419d3fc

Browse files
committed
move ABI check out to cover all calls
1 parent 5900b32 commit 419d3fc

File tree

1 file changed

+24
-24
lines changed

1 file changed

+24
-24
lines changed

src/librustc_mir/interpret/terminator.rs

+24-24
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,30 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
251251
}
252252
};
253253

254+
// ABI check
255+
{
256+
let callee_abi = {
257+
let instance_ty = instance.ty(*self.tcx);
258+
match instance_ty.kind {
259+
ty::FnDef(..) =>
260+
instance_ty.fn_sig(*self.tcx).abi(),
261+
ty::Closure(..) => Abi::RustCall,
262+
ty::Generator(..) => Abi::Rust,
263+
_ => bug!("unexpected callee ty: {:?}", instance_ty),
264+
}
265+
};
266+
let normalize_abi = |abi| match abi {
267+
Abi::Rust | Abi::RustCall | Abi::RustIntrinsic | Abi::PlatformIntrinsic =>
268+
// These are all the same ABI, really.
269+
Abi::Rust,
270+
abi =>
271+
abi,
272+
};
273+
if normalize_abi(caller_abi) != normalize_abi(callee_abi) {
274+
throw_unsup!(FunctionAbiMismatch(caller_abi, callee_abi))
275+
}
276+
}
277+
254278
match instance.def {
255279
ty::InstanceDef::Intrinsic(..) => {
256280
assert!(caller_abi == Abi::RustIntrinsic || caller_abi == Abi::PlatformIntrinsic);
@@ -263,30 +287,6 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
263287
ty::InstanceDef::DropGlue(..) |
264288
ty::InstanceDef::CloneShim(..) |
265289
ty::InstanceDef::Item(_) => {
266-
// ABI check
267-
{
268-
let callee_abi = {
269-
let instance_ty = instance.ty(*self.tcx);
270-
match instance_ty.kind {
271-
ty::FnDef(..) =>
272-
instance_ty.fn_sig(*self.tcx).abi(),
273-
ty::Closure(..) => Abi::RustCall,
274-
ty::Generator(..) => Abi::Rust,
275-
_ => bug!("unexpected callee ty: {:?}", instance_ty),
276-
}
277-
};
278-
let normalize_abi = |abi| match abi {
279-
Abi::Rust | Abi::RustCall | Abi::RustIntrinsic | Abi::PlatformIntrinsic =>
280-
// These are all the same ABI, really.
281-
Abi::Rust,
282-
abi =>
283-
abi,
284-
};
285-
if normalize_abi(caller_abi) != normalize_abi(callee_abi) {
286-
throw_unsup!(FunctionAbiMismatch(caller_abi, callee_abi))
287-
}
288-
}
289-
290290
// We need MIR for this fn
291291
let body = match M::find_fn(self, instance, args, dest, ret, unwind)? {
292292
Some(body) => body,

0 commit comments

Comments
 (0)