Skip to content

Commit

Permalink
Auto merge of rust-lang#123781 - RalfJung:miri-fn-identity, r=oli-obk
Browse files Browse the repository at this point in the history
Miri function identity hack: account for possible inlining

Having a non-lifetime generic is not the only reason a function can be duplicated. Another possibility is that the function may be eligible for cross-crate inlining. So also take into account the inlining attribute in this Miri hack for function pointer identity.

That said, `cross_crate_inlinable` will still sometimes return true even for `inline(never)` functions:
- when they are `DefKind::Ctor(..) | DefKind::Closure` -- I assume those cannot be `InlineAttr::Never` anyway?
- when `cross_crate_inline_threshold == InliningThreshold::Always`

so maybe this is still not quite the right criterion to use for function pointer identity.
  • Loading branch information
bors committed Jul 4, 2024
2 parents c6b883b + a6056bc commit 8620e85
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ pub(crate) fn codegen_const_value<'tcx>(
fx.bcx.ins().global_value(fx.pointer_type, local_data_id)
}
}
GlobalAlloc::Function(instance) => {
GlobalAlloc::Function { instance, .. } => {
let func_id = crate::abi::import_function(fx.tcx, fx.module, instance);
let local_func_id =
fx.module.declare_func_in_func(func_id, &mut fx.bcx.func);
Expand Down Expand Up @@ -351,7 +351,9 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
TodoItem::Alloc(alloc_id) => {
let alloc = match tcx.global_alloc(alloc_id) {
GlobalAlloc::Memory(alloc) => alloc,
GlobalAlloc::Function(_) | GlobalAlloc::Static(_) | GlobalAlloc::VTable(..) => {
GlobalAlloc::Function { .. }
| GlobalAlloc::Static(_)
| GlobalAlloc::VTable(..) => {
unreachable!()
}
};
Expand Down Expand Up @@ -415,7 +417,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant

let reloc_target_alloc = tcx.global_alloc(alloc_id);
let data_id = match reloc_target_alloc {
GlobalAlloc::Function(instance) => {
GlobalAlloc::Function { instance, .. } => {
assert_eq!(addend, 0);
let func_id =
crate::abi::import_function(tcx, module, instance.polymorphize(tcx));
Expand Down

0 comments on commit 8620e85

Please sign in to comment.