Skip to content

Commit c6ae57c

Browse files
author
hyd-dev
committed
Check the ABI of body.source
1 parent d6d0283 commit c6ae57c

File tree

1 file changed

+15
-11
lines changed

1 file changed

+15
-11
lines changed

compiler/rustc_mir/src/interpret/terminator.rs

Lines changed: 15 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,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
274276
None => return Ok(()),
275277
};
276278

279+
check_abi(self, self.tcx.type_of(body.source.def_id()))?;
280+
277281
self.push_stack_frame(
278282
instance,
279283
body,

0 commit comments

Comments
 (0)