Check the ABI of body.source
This commit is contained in:
parent
d6d028369b
commit
c6ae57cb83
1 changed files with 15 additions and 11 deletions
|
@ -3,7 +3,10 @@ use std::convert::TryFrom;
|
||||||
|
|
||||||
use rustc_middle::ty::layout::TyAndLayout;
|
use rustc_middle::ty::layout::TyAndLayout;
|
||||||
use rustc_middle::ty::Instance;
|
use rustc_middle::ty::Instance;
|
||||||
use rustc_middle::{mir, ty};
|
use rustc_middle::{
|
||||||
|
mir,
|
||||||
|
ty::{self, Ty},
|
||||||
|
};
|
||||||
use rustc_target::abi::{self, LayoutOf as _};
|
use rustc_target::abi::{self, LayoutOf as _};
|
||||||
use rustc_target::spec::abi::Abi;
|
use rustc_target::spec::abi::Abi;
|
||||||
|
|
||||||
|
@ -228,15 +231,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||||
};
|
};
|
||||||
|
|
||||||
// ABI check
|
// ABI check
|
||||||
{
|
let check_abi = |this: &Self, instance_ty: Ty<'tcx>| -> InterpResult<'tcx> {
|
||||||
let callee_abi = {
|
let callee_abi = match instance_ty.kind() {
|
||||||
let instance_ty = instance.ty(*self.tcx, self.param_env);
|
ty::FnDef(..) => instance_ty.fn_sig(*this.tcx).abi(),
|
||||||
match instance_ty.kind() {
|
|
||||||
ty::FnDef(..) => instance_ty.fn_sig(*self.tcx).abi(),
|
|
||||||
ty::Closure(..) => Abi::RustCall,
|
ty::Closure(..) => Abi::RustCall,
|
||||||
ty::Generator(..) => Abi::Rust,
|
ty::Generator(..) => Abi::Rust,
|
||||||
_ => span_bug!(self.cur_span(), "unexpected callee ty: {:?}", instance_ty),
|
_ => span_bug!(this.cur_span(), "unexpected callee ty: {:?}", instance_ty),
|
||||||
}
|
|
||||||
};
|
};
|
||||||
let normalize_abi = |abi| match abi {
|
let normalize_abi = |abi| match abi {
|
||||||
Abi::Rust | Abi::RustCall | Abi::RustIntrinsic | Abi::PlatformIntrinsic =>
|
Abi::Rust | Abi::RustCall | Abi::RustIntrinsic | Abi::PlatformIntrinsic =>
|
||||||
|
@ -253,10 +253,12 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||||
caller_abi.name()
|
caller_abi.name()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
Ok(())
|
||||||
|
};
|
||||||
|
|
||||||
match instance.def {
|
match instance.def {
|
||||||
ty::InstanceDef::Intrinsic(..) => {
|
ty::InstanceDef::Intrinsic(..) => {
|
||||||
|
check_abi(self, instance.ty(*self.tcx, self.param_env))?;
|
||||||
assert!(caller_abi == Abi::RustIntrinsic || caller_abi == Abi::PlatformIntrinsic);
|
assert!(caller_abi == Abi::RustIntrinsic || caller_abi == Abi::PlatformIntrinsic);
|
||||||
M::call_intrinsic(self, instance, args, ret, unwind)
|
M::call_intrinsic(self, instance, args, ret, unwind)
|
||||||
}
|
}
|
||||||
|
@ -274,6 +276,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||||
None => return Ok(()),
|
None => return Ok(()),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
check_abi(self, self.tcx.type_of(body.source.def_id()))?;
|
||||||
|
|
||||||
self.push_stack_frame(
|
self.push_stack_frame(
|
||||||
instance,
|
instance,
|
||||||
body,
|
body,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue