Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit a53204f

Browse files
authoredDec 20, 2024
Rollup merge of #133103 - tiif:fnabi, r=RalfJung
Pass FnAbi to find_mir_or_eval_fn rust-lang/miri#4013 needs information from ``FnAbi``, hence it is passed to ``find_mir_or_eval_fn``. r? `@RalfJung`
2 parents 1ec6d09 + fd8b983 commit a53204f

31 files changed

+484
-455
lines changed
 

‎compiler/rustc_const_eval/src/const_eval/dummy_machine.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
use rustc_middle::mir::interpret::{AllocId, ConstAllocation, InterpResult};
22
use rustc_middle::mir::*;
33
use rustc_middle::query::TyCtxtAt;
4+
use rustc_middle::ty::Ty;
45
use rustc_middle::ty::layout::TyAndLayout;
56
use rustc_middle::{bug, span_bug, ty};
67
use rustc_span::def_id::DefId;
8+
use rustc_target::callconv::FnAbi;
79

810
use crate::interpret::{
911
self, HasStaticRootDefId, ImmTy, Immediate, InterpCx, PointerArithmetic, interp_ok,
@@ -86,7 +88,7 @@ impl<'tcx> interpret::Machine<'tcx> for DummyMachine {
8688
fn find_mir_or_eval_fn(
8789
_ecx: &mut InterpCx<'tcx, Self>,
8890
_instance: ty::Instance<'tcx>,
89-
_abi: rustc_abi::ExternAbi,
91+
_abi: &FnAbi<'tcx, Ty<'tcx>>,
9092
_args: &[interpret::FnArg<'tcx, Self::Provenance>],
9193
_destination: &interpret::MPlaceTy<'tcx, Self::Provenance>,
9294
_target: Option<BasicBlock>,

‎compiler/rustc_const_eval/src/const_eval/machine.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::borrow::{Borrow, Cow};
22
use std::fmt;
33
use std::hash::Hash;
44

5-
use rustc_abi::{Align, ExternAbi, Size};
5+
use rustc_abi::{Align, Size};
66
use rustc_ast::Mutability;
77
use rustc_data_structures::fx::{FxHashMap, FxIndexMap, IndexEntry};
88
use rustc_hir::def_id::{DefId, LocalDefId};
@@ -14,6 +14,7 @@ use rustc_middle::ty::layout::{HasTypingEnv, TyAndLayout};
1414
use rustc_middle::ty::{self, Ty, TyCtxt};
1515
use rustc_middle::{bug, mir};
1616
use rustc_span::{Span, Symbol, sym};
17+
use rustc_target::callconv::FnAbi;
1718
use tracing::debug;
1819

1920
use super::error::*;
@@ -339,7 +340,7 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> {
339340
fn find_mir_or_eval_fn(
340341
ecx: &mut InterpCx<'tcx, Self>,
341342
orig_instance: ty::Instance<'tcx>,
342-
_abi: ExternAbi,
343+
_abi: &FnAbi<'tcx, Ty<'tcx>>,
343344
args: &[FnArg<'tcx>],
344345
dest: &MPlaceTy<'tcx>,
345346
ret: Option<mir::BasicBlock>,

‎compiler/rustc_const_eval/src/interpret/call.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
519519
return M::call_extra_fn(
520520
self,
521521
extra,
522-
caller_abi,
522+
caller_fn_abi,
523523
args,
524524
destination,
525525
target,
@@ -570,7 +570,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
570570
let Some((body, instance)) = M::find_mir_or_eval_fn(
571571
self,
572572
instance,
573-
caller_abi,
573+
caller_fn_abi,
574574
args,
575575
destination,
576576
target,

‎compiler/rustc_const_eval/src/interpret/machine.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use std::borrow::{Borrow, Cow};
66
use std::fmt::Debug;
77
use std::hash::Hash;
88

9-
use rustc_abi::{Align, ExternAbi, Size};
9+
use rustc_abi::{Align, Size};
1010
use rustc_apfloat::{Float, FloatConvert};
1111
use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
1212
use rustc_middle::query::TyCtxtAt;
@@ -15,6 +15,7 @@ use rustc_middle::ty::layout::TyAndLayout;
1515
use rustc_middle::{mir, ty};
1616
use rustc_span::Span;
1717
use rustc_span::def_id::DefId;
18+
use rustc_target::callconv::FnAbi;
1819

1920
use super::{
2021
AllocBytes, AllocId, AllocKind, AllocRange, Allocation, CTFE_ALLOC_SALT, ConstAllocation,
@@ -201,7 +202,7 @@ pub trait Machine<'tcx>: Sized {
201202
fn find_mir_or_eval_fn(
202203
ecx: &mut InterpCx<'tcx, Self>,
203204
instance: ty::Instance<'tcx>,
204-
abi: ExternAbi,
205+
abi: &FnAbi<'tcx, Ty<'tcx>>,
205206
args: &[FnArg<'tcx, Self::Provenance>],
206207
destination: &MPlaceTy<'tcx, Self::Provenance>,
207208
target: Option<mir::BasicBlock>,
@@ -213,7 +214,7 @@ pub trait Machine<'tcx>: Sized {
213214
fn call_extra_fn(
214215
ecx: &mut InterpCx<'tcx, Self>,
215216
fn_val: Self::ExtraFnVal,
216-
abi: ExternAbi,
217+
abi: &FnAbi<'tcx, Ty<'tcx>>,
217218
args: &[FnArg<'tcx, Self::Provenance>],
218219
destination: &MPlaceTy<'tcx, Self::Provenance>,
219220
target: Option<mir::BasicBlock>,
@@ -656,7 +657,7 @@ pub macro compile_time_machine(<$tcx: lifetime>) {
656657
fn call_extra_fn(
657658
_ecx: &mut InterpCx<$tcx, Self>,
658659
fn_val: !,
659-
_abi: ExternAbi,
660+
_abi: &FnAbi<$tcx, Ty<$tcx>>,
660661
_args: &[FnArg<$tcx>],
661662
_destination: &MPlaceTy<$tcx, Self::Provenance>,
662663
_target: Option<mir::BasicBlock>,

‎src/tools/miri/src/helpers.rs

+9-10
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ 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::{Conv, FnAbi};
2223

2324
use crate::*;
2425

@@ -914,13 +915,11 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
914915
}
915916

916917
/// Check that the ABI is what we expect.
917-
fn check_abi<'a>(&self, abi: ExternAbi, exp_abi: ExternAbi) -> InterpResult<'a, ()> {
918-
if abi != exp_abi {
918+
fn check_abi<'a>(&self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, exp_abi: Conv) -> InterpResult<'a, ()> {
919+
if fn_abi.conv != exp_abi {
919920
throw_ub_format!(
920-
"calling a function with ABI {} using caller ABI {}",
921-
exp_abi.name(),
922-
abi.name()
923-
)
921+
"calling a function with ABI {:?} using caller ABI {:?}",
922+
exp_abi, fn_abi.conv);
924923
}
925924
interp_ok(())
926925
}
@@ -950,8 +949,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
950949

951950
fn check_abi_and_shim_symbol_clash(
952951
&mut self,
953-
abi: ExternAbi,
954-
exp_abi: ExternAbi,
952+
abi: &FnAbi<'tcx, Ty<'tcx>>,
953+
exp_abi: Conv,
955954
link_name: Symbol,
956955
) -> InterpResult<'tcx, ()> {
957956
self.check_abi(abi, exp_abi)?;
@@ -975,8 +974,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
975974

976975
fn check_shim<'a, const N: usize>(
977976
&mut self,
978-
abi: ExternAbi,
979-
exp_abi: ExternAbi,
977+
abi: &FnAbi<'tcx, Ty<'tcx>>,
978+
exp_abi: Conv,
980979
link_name: Symbol,
981980
args: &'a [OpTy<'tcx>],
982981
) -> InterpResult<'tcx, &'a [OpTy<'tcx>; N]>

‎src/tools/miri/src/machine.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use rand::{Rng, SeedableRng};
1313
use rustc_abi::{Align, ExternAbi, Size};
1414
use rustc_attr_parsing::InlineAttr;
1515
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
16+
use rustc_target::callconv::FnAbi;
1617
#[allow(unused)]
1718
use rustc_data_structures::static_assert_size;
1819
use rustc_middle::mir;
@@ -1010,7 +1011,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
10101011
fn find_mir_or_eval_fn(
10111012
ecx: &mut MiriInterpCx<'tcx>,
10121013
instance: ty::Instance<'tcx>,
1013-
abi: ExternAbi,
1014+
abi: &FnAbi<'tcx, Ty<'tcx>>,
10141015
args: &[FnArg<'tcx, Provenance>],
10151016
dest: &MPlaceTy<'tcx>,
10161017
ret: Option<mir::BasicBlock>,
@@ -1037,7 +1038,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
10371038
fn call_extra_fn(
10381039
ecx: &mut MiriInterpCx<'tcx>,
10391040
fn_val: DynSym,
1040-
abi: ExternAbi,
1041+
abi: &FnAbi<'tcx, Ty<'tcx>>,
10411042
args: &[FnArg<'tcx, Provenance>],
10421043
dest: &MPlaceTy<'tcx>,
10431044
ret: Option<mir::BasicBlock>,

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

+11-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
use rustc_abi::{ExternAbi, Size};
1+
use rustc_abi::Size;
22
use rustc_middle::ty::layout::LayoutOf as _;
33
use rustc_middle::ty::{self, Instance, Ty};
44
use rustc_span::{BytePos, Loc, Symbol, hygiene};
5+
use rustc_target::callconv::{Conv, FnAbi};
56

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

2122
let flags = this.read_scalar(flags)?.to_u64()?;
2223
if flags != 0 {
@@ -30,7 +31,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
3031

3132
fn handle_miri_get_backtrace(
3233
&mut self,
33-
abi: ExternAbi,
34+
abi: &FnAbi<'tcx, Ty<'tcx>>,
3435
link_name: Symbol,
3536
args: &[OpTy<'tcx>],
3637
dest: &MPlaceTy<'tcx>,
@@ -71,7 +72,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
7172
// storage for pointers is allocated by miri
7273
// deallocating the slice is undefined behavior with a custom global allocator
7374
0 => {
74-
let [_flags] = this.check_shim(abi, ExternAbi::Rust, link_name, args)?;
75+
let [_flags] = this.check_shim(abi, Conv::Rust, link_name, args)?;
7576

7677
let alloc = this.allocate(array_layout, MiriMemoryKind::Rust.into())?;
7778

@@ -86,7 +87,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
8687
}
8788
// storage for pointers is allocated by the caller
8889
1 => {
89-
let [_flags, buf] = this.check_shim(abi, ExternAbi::Rust, link_name, args)?;
90+
let [_flags, buf] = this.check_shim(abi, Conv::Rust, link_name, args)?;
9091

9192
let buf_place = this.deref_pointer(buf)?;
9293

@@ -136,13 +137,13 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
136137

137138
fn handle_miri_resolve_frame(
138139
&mut self,
139-
abi: ExternAbi,
140+
abi: &FnAbi<'tcx, Ty<'tcx>>,
140141
link_name: Symbol,
141142
args: &[OpTy<'tcx>],
142143
dest: &MPlaceTy<'tcx>,
143144
) -> InterpResult<'tcx> {
144145
let this = self.eval_context_mut();
145-
let [ptr, flags] = this.check_shim(abi, ExternAbi::Rust, link_name, args)?;
146+
let [ptr, flags] = this.check_shim(abi, Conv::Rust, link_name, args)?;
146147

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

@@ -207,14 +208,14 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
207208

208209
fn handle_miri_resolve_frame_names(
209210
&mut self,
210-
abi: ExternAbi,
211+
abi: &FnAbi<'tcx, Ty<'tcx>>,
211212
link_name: Symbol,
212213
args: &[OpTy<'tcx>],
213214
) -> InterpResult<'tcx> {
214215
let this = self.eval_context_mut();
215216

216217
let [ptr, flags, name_ptr, filename_ptr] =
217-
this.check_shim(abi, ExternAbi::Rust, link_name, args)?;
218+
this.check_shim(abi, Conv::Rust, link_name, args)?;
218219

219220
let flags = this.read_scalar(flags)?.to_u64()?;
220221
if flags != 0 {
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.