Skip to content

Commit 46dd656

Browse files
committed
Let all checkshim use FnAbi instead
1 parent 2c03bef commit 46dd656

File tree

4 files changed

+85
-64
lines changed

4 files changed

+85
-64
lines changed

src/tools/miri/src/helpers.rs

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ use rustc_middle::ty::layout::{FnAbiOf, LayoutOf, MaybeResult, TyAndLayout};
1919
use rustc_middle::ty::{self, FloatTy, IntTy, Ty, TyCtxt, UintTy};
2020
use rustc_session::config::CrateType;
2121
use rustc_span::{Span, Symbol};
22+
use rustc_target::callconv::FnAbi;
23+
use rustc_target::callconv::Conv;
24+
25+
2226

2327
use crate::*;
2428

@@ -916,13 +920,27 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
916920
}
917921

918922
/// Check that the ABI is what we expect.
919-
fn check_abi<'a>(&self, abi: ExternAbi, exp_abi: ExternAbi) -> InterpResult<'a, ()> {
920-
if abi != exp_abi {
921-
throw_ub_format!(
922-
"calling a function with ABI {} using caller ABI {}",
923-
exp_abi.name(),
924-
abi.name()
925-
)
923+
fn check_abi<'a>(&self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, exp_abi: ExternAbi) -> InterpResult<'a, ()> {
924+
let call_conv;
925+
match fn_abi.conv {
926+
Conv::C => {
927+
// TODO: unwind what?
928+
call_conv = ExternAbi::C { unwind: false};
929+
},
930+
Conv::Rust => {
931+
call_conv = ExternAbi::Rust;
932+
},
933+
_=> {
934+
// TODO: What is a better way of doing this?
935+
panic!("Unsupported calling convention");
936+
}
937+
};
938+
if call_conv != exp_abi {
939+
throw_ub_format!(
940+
"calling a function with ABI {} using caller ABI {}",
941+
exp_abi.name(),
942+
call_conv.name()
943+
)
926944
}
927945
interp_ok(())
928946
}
@@ -952,11 +970,11 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
952970

953971
fn check_abi_and_shim_symbol_clash(
954972
&mut self,
955-
abi: ExternAbi,
973+
fnabi: &FnAbi<'tcx, Ty<'tcx>>,
956974
exp_abi: ExternAbi,
957975
link_name: Symbol,
958976
) -> InterpResult<'tcx, ()> {
959-
self.check_abi(abi, exp_abi)?;
977+
self.check_abi(fnabi, exp_abi)?;
960978
if let Some((body, instance)) = self.eval_context_mut().lookup_exported_symbol(link_name)? {
961979
// If compiler-builtins is providing the symbol, then don't treat it as a clash.
962980
// We'll use our built-in implementation in `emulate_foreign_item_inner` for increased
@@ -978,14 +996,15 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
978996
fn check_shim<'a, const N: usize>(
979997
&mut self,
980998
abi: ExternAbi,
999+
_fnabi: &FnAbi<'tcx, Ty<'tcx>>,
9811000
exp_abi: ExternAbi,
9821001
link_name: Symbol,
9831002
args: &'a [OpTy<'tcx>],
9841003
) -> InterpResult<'tcx, &'a [OpTy<'tcx>; N]>
9851004
where
9861005
&'a [OpTy<'tcx>; N]: TryFrom<&'a [OpTy<'tcx>]>,
9871006
{
988-
self.check_abi_and_shim_symbol_clash(abi, exp_abi, link_name)?;
1007+
self.check_abi_and_shim_symbol_clash(_fnabi, exp_abi, link_name)?;
9891008
check_arg_count(args)
9901009
}
9911010

src/tools/miri/src/machine.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1023,7 +1023,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
10231023
// Any needed call to `goto_block` will be performed by `emulate_foreign_item`.
10241024
let args = ecx.copy_fn_args(args); // FIXME: Should `InPlace` arguments be reset to uninit?
10251025
let link_name = Symbol::intern(ecx.tcx.symbol_name(instance).name);
1026-
return ecx.emulate_foreign_item(link_name, abi, &args, dest, ret, unwind);
1026+
return ecx.emulate_foreign_item(link_name, abi, _fnabi, &args, dest, ret, unwind);
10271027
}
10281028

10291029
// Otherwise, load the MIR.

src/tools/miri/src/shims/backtrace.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use rustc_ast::ast::Mutability;
33
use rustc_middle::ty::layout::LayoutOf as _;
44
use rustc_middle::ty::{self, Instance, Ty};
55
use rustc_span::{BytePos, Loc, Symbol, hygiene};
6+
use rustc_target::callconv::FnAbi;
67

78
use crate::helpers::check_min_arg_count;
89
use crate::*;
@@ -11,13 +12,13 @@ impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {}
1112
pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
1213
fn handle_miri_backtrace_size(
1314
&mut self,
14-
abi: ExternAbi,
15+
fnabi: &FnAbi<'tcx, Ty<'tcx>>,
1516
link_name: Symbol,
1617
args: &[OpTy<'tcx>],
1718
dest: &MPlaceTy<'tcx>,
1819
) -> InterpResult<'tcx> {
1920
let this = self.eval_context_mut();
20-
let [flags] = this.check_shim(abi, ExternAbi::Rust, link_name, args)?;
21+
let [flags] = this.check_shim(fnabi, ExternAbi::Rust, link_name, args)?;
2122

2223
let flags = this.read_scalar(flags)?.to_u64()?;
2324
if flags != 0 {
@@ -137,13 +138,13 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
137138

138139
fn handle_miri_resolve_frame(
139140
&mut self,
140-
abi: ExternAbi,
141+
fnabi: &FnAbi<'tcx, Ty<'tcx>>,
141142
link_name: Symbol,
142143
args: &[OpTy<'tcx>],
143144
dest: &MPlaceTy<'tcx>,
144145
) -> InterpResult<'tcx> {
145146
let this = self.eval_context_mut();
146-
let [ptr, flags] = this.check_shim(abi, ExternAbi::Rust, link_name, args)?;
147+
let [ptr, flags] = this.check_shim(fnabi, ExternAbi::Rust, link_name, args)?;
147148

148149
let flags = this.read_scalar(flags)?.to_u64()?;
149150

@@ -215,14 +216,14 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
215216

216217
fn handle_miri_resolve_frame_names(
217218
&mut self,
218-
abi: ExternAbi,
219+
fnabi: &FnAbi<'tcx, Ty<'tcx>>,
219220
link_name: Symbol,
220221
args: &[OpTy<'tcx>],
221222
) -> InterpResult<'tcx> {
222223
let this = self.eval_context_mut();
223224

224225
let [ptr, flags, name_ptr, filename_ptr] =
225-
this.check_shim(abi, ExternAbi::Rust, link_name, args)?;
226+
this.check_shim(fnabi, ExternAbi::Rust, link_name, args)?;
226227

227228
let flags = this.read_scalar(flags)?.to_u64()?;
228229
if flags != 0 {

0 commit comments

Comments
 (0)