Skip to content

Commit

Permalink
Pass FnAbi to find_mir_or_eval_fn
Browse files Browse the repository at this point in the history
  • Loading branch information
tiif committed Dec 19, 2024
1 parent a4079b2 commit fd8b983
Show file tree
Hide file tree
Showing 31 changed files with 484 additions and 455 deletions.
4 changes: 3 additions & 1 deletion compiler/rustc_const_eval/src/const_eval/dummy_machine.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
use rustc_middle::mir::interpret::{AllocId, ConstAllocation, InterpResult};
use rustc_middle::mir::*;
use rustc_middle::query::TyCtxtAt;
use rustc_middle::ty::Ty;
use rustc_middle::ty::layout::TyAndLayout;
use rustc_middle::{bug, span_bug, ty};
use rustc_span::def_id::DefId;
use rustc_target::callconv::FnAbi;

use crate::interpret::{
self, HasStaticRootDefId, ImmTy, Immediate, InterpCx, PointerArithmetic, interp_ok,
Expand Down Expand Up @@ -86,7 +88,7 @@ impl<'tcx> interpret::Machine<'tcx> for DummyMachine {
fn find_mir_or_eval_fn(
_ecx: &mut InterpCx<'tcx, Self>,
_instance: ty::Instance<'tcx>,
_abi: rustc_abi::ExternAbi,
_abi: &FnAbi<'tcx, Ty<'tcx>>,
_args: &[interpret::FnArg<'tcx, Self::Provenance>],
_destination: &interpret::MPlaceTy<'tcx, Self::Provenance>,
_target: Option<BasicBlock>,
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_const_eval/src/const_eval/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::borrow::{Borrow, Cow};
use std::fmt;
use std::hash::Hash;

use rustc_abi::{Align, ExternAbi, Size};
use rustc_abi::{Align, Size};
use rustc_ast::Mutability;
use rustc_data_structures::fx::{FxHashMap, FxIndexMap, IndexEntry};
use rustc_hir::def_id::{DefId, LocalDefId};
Expand All @@ -14,6 +14,7 @@ use rustc_middle::ty::layout::{HasTypingEnv, TyAndLayout};
use rustc_middle::ty::{self, Ty, TyCtxt};
use rustc_middle::{bug, mir};
use rustc_span::{Span, Symbol, sym};
use rustc_target::callconv::FnAbi;
use tracing::debug;

use super::error::*;
Expand Down Expand Up @@ -339,7 +340,7 @@ impl<'tcx> interpret::Machine<'tcx> for CompileTimeMachine<'tcx> {
fn find_mir_or_eval_fn(
ecx: &mut InterpCx<'tcx, Self>,
orig_instance: ty::Instance<'tcx>,
_abi: ExternAbi,
_abi: &FnAbi<'tcx, Ty<'tcx>>,
args: &[FnArg<'tcx>],
dest: &MPlaceTy<'tcx>,
ret: Option<mir::BasicBlock>,
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_const_eval/src/interpret/call.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
return M::call_extra_fn(
self,
extra,
caller_abi,
caller_fn_abi,
args,
destination,
target,
Expand Down Expand Up @@ -570,7 +570,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
let Some((body, instance)) = M::find_mir_or_eval_fn(
self,
instance,
caller_abi,
caller_fn_abi,
args,
destination,
target,
Expand Down
9 changes: 5 additions & 4 deletions compiler/rustc_const_eval/src/interpret/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::borrow::{Borrow, Cow};
use std::fmt::Debug;
use std::hash::Hash;

use rustc_abi::{Align, ExternAbi, Size};
use rustc_abi::{Align, Size};
use rustc_apfloat::{Float, FloatConvert};
use rustc_ast::{InlineAsmOptions, InlineAsmTemplatePiece};
use rustc_middle::query::TyCtxtAt;
Expand All @@ -15,6 +15,7 @@ use rustc_middle::ty::layout::TyAndLayout;
use rustc_middle::{mir, ty};
use rustc_span::Span;
use rustc_span::def_id::DefId;
use rustc_target::callconv::FnAbi;

use super::{
AllocBytes, AllocId, AllocKind, AllocRange, Allocation, CTFE_ALLOC_SALT, ConstAllocation,
Expand Down Expand Up @@ -201,7 +202,7 @@ pub trait Machine<'tcx>: Sized {
fn find_mir_or_eval_fn(
ecx: &mut InterpCx<'tcx, Self>,
instance: ty::Instance<'tcx>,
abi: ExternAbi,
abi: &FnAbi<'tcx, Ty<'tcx>>,
args: &[FnArg<'tcx, Self::Provenance>],
destination: &MPlaceTy<'tcx, Self::Provenance>,
target: Option<mir::BasicBlock>,
Expand All @@ -213,7 +214,7 @@ pub trait Machine<'tcx>: Sized {
fn call_extra_fn(
ecx: &mut InterpCx<'tcx, Self>,
fn_val: Self::ExtraFnVal,
abi: ExternAbi,
abi: &FnAbi<'tcx, Ty<'tcx>>,
args: &[FnArg<'tcx, Self::Provenance>],
destination: &MPlaceTy<'tcx, Self::Provenance>,
target: Option<mir::BasicBlock>,
Expand Down Expand Up @@ -656,7 +657,7 @@ pub macro compile_time_machine(<$tcx: lifetime>) {
fn call_extra_fn(
_ecx: &mut InterpCx<$tcx, Self>,
fn_val: !,
_abi: ExternAbi,
_abi: &FnAbi<$tcx, Ty<$tcx>>,
_args: &[FnArg<$tcx>],
_destination: &MPlaceTy<$tcx, Self::Provenance>,
_target: Option<mir::BasicBlock>,
Expand Down
19 changes: 9 additions & 10 deletions src/tools/miri/src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use rustc_middle::ty::layout::{FnAbiOf, LayoutOf, MaybeResult, TyAndLayout};
use rustc_middle::ty::{self, FloatTy, IntTy, Ty, TyCtxt, UintTy};
use rustc_session::config::CrateType;
use rustc_span::{Span, Symbol};
use rustc_target::callconv::{Conv, FnAbi};

use crate::*;

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

/// Check that the ABI is what we expect.
fn check_abi<'a>(&self, abi: ExternAbi, exp_abi: ExternAbi) -> InterpResult<'a, ()> {
if abi != exp_abi {
fn check_abi<'a>(&self, fn_abi: &FnAbi<'tcx, Ty<'tcx>>, exp_abi: Conv) -> InterpResult<'a, ()> {
if fn_abi.conv != exp_abi {
throw_ub_format!(
"calling a function with ABI {} using caller ABI {}",
exp_abi.name(),
abi.name()
)
"calling a function with ABI {:?} using caller ABI {:?}",
exp_abi, fn_abi.conv);
}
interp_ok(())
}
Expand Down Expand Up @@ -950,8 +949,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {

fn check_abi_and_shim_symbol_clash(
&mut self,
abi: ExternAbi,
exp_abi: ExternAbi,
abi: &FnAbi<'tcx, Ty<'tcx>>,
exp_abi: Conv,
link_name: Symbol,
) -> InterpResult<'tcx, ()> {
self.check_abi(abi, exp_abi)?;
Expand All @@ -975,8 +974,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {

fn check_shim<'a, const N: usize>(
&mut self,
abi: ExternAbi,
exp_abi: ExternAbi,
abi: &FnAbi<'tcx, Ty<'tcx>>,
exp_abi: Conv,
link_name: Symbol,
args: &'a [OpTy<'tcx>],
) -> InterpResult<'tcx, &'a [OpTy<'tcx>; N]>
Expand Down
5 changes: 3 additions & 2 deletions src/tools/miri/src/machine.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use rand::{Rng, SeedableRng};
use rustc_abi::{Align, ExternAbi, Size};
use rustc_attr_parsing::InlineAttr;
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use rustc_target::callconv::FnAbi;
#[allow(unused)]
use rustc_data_structures::static_assert_size;
use rustc_middle::mir;
Expand Down Expand Up @@ -1010,7 +1011,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
fn find_mir_or_eval_fn(
ecx: &mut MiriInterpCx<'tcx>,
instance: ty::Instance<'tcx>,
abi: ExternAbi,
abi: &FnAbi<'tcx, Ty<'tcx>>,
args: &[FnArg<'tcx, Provenance>],
dest: &MPlaceTy<'tcx>,
ret: Option<mir::BasicBlock>,
Expand All @@ -1037,7 +1038,7 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
fn call_extra_fn(
ecx: &mut MiriInterpCx<'tcx>,
fn_val: DynSym,
abi: ExternAbi,
abi: &FnAbi<'tcx, Ty<'tcx>>,
args: &[FnArg<'tcx, Provenance>],
dest: &MPlaceTy<'tcx>,
ret: Option<mir::BasicBlock>,
Expand Down
21 changes: 11 additions & 10 deletions src/tools/miri/src/shims/backtrace.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
use rustc_abi::{ExternAbi, Size};
use rustc_abi::Size;
use rustc_middle::ty::layout::LayoutOf as _;
use rustc_middle::ty::{self, Instance, Ty};
use rustc_span::{BytePos, Loc, Symbol, hygiene};
use rustc_target::callconv::{Conv, FnAbi};

use crate::helpers::check_min_arg_count;
use crate::*;
Expand All @@ -10,13 +11,13 @@ impl<'tcx> EvalContextExt<'tcx> for crate::MiriInterpCx<'tcx> {}
pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
fn handle_miri_backtrace_size(
&mut self,
abi: ExternAbi,
abi: &FnAbi<'tcx, Ty<'tcx>>,
link_name: Symbol,
args: &[OpTy<'tcx>],
dest: &MPlaceTy<'tcx>,
) -> InterpResult<'tcx> {
let this = self.eval_context_mut();
let [flags] = this.check_shim(abi, ExternAbi::Rust, link_name, args)?;
let [flags] = this.check_shim(abi, Conv::Rust, link_name, args)?;

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

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

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

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

let buf_place = this.deref_pointer(buf)?;

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

fn handle_miri_resolve_frame(
&mut self,
abi: ExternAbi,
abi: &FnAbi<'tcx, Ty<'tcx>>,
link_name: Symbol,
args: &[OpTy<'tcx>],
dest: &MPlaceTy<'tcx>,
) -> InterpResult<'tcx> {
let this = self.eval_context_mut();
let [ptr, flags] = this.check_shim(abi, ExternAbi::Rust, link_name, args)?;
let [ptr, flags] = this.check_shim(abi, Conv::Rust, link_name, args)?;

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

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

fn handle_miri_resolve_frame_names(
&mut self,
abi: ExternAbi,
abi: &FnAbi<'tcx, Ty<'tcx>>,
link_name: Symbol,
args: &[OpTy<'tcx>],
) -> InterpResult<'tcx> {
let this = self.eval_context_mut();

let [ptr, flags, name_ptr, filename_ptr] =
this.check_shim(abi, ExternAbi::Rust, link_name, args)?;
this.check_shim(abi, Conv::Rust, link_name, args)?;

let flags = this.read_scalar(flags)?.to_u64()?;
if flags != 0 {
Expand Down
Loading

0 comments on commit fd8b983

Please sign in to comment.