Skip to content

Commit a58ce58

Browse files
committed
Auto merge of #123781 - RalfJung:miri-fn-identity, r=oli-obk
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.
2 parents 3b435ba + 94b832f commit a58ce58

File tree

3 files changed

+4
-2
lines changed

3 files changed

+4
-2
lines changed

src/shims/backtrace.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
119119
let (alloc_id, offset, _prov) = this.ptr_get_alloc_id(ptr)?;
120120

121121
// This has to be an actual global fn ptr, not a dlsym function.
122-
let fn_instance = if let Some(GlobalAlloc::Function(instance)) =
122+
let fn_instance = if let Some(GlobalAlloc::Function { instance, .. }) =
123123
this.tcx.try_get_global_alloc(alloc_id)
124124
{
125125
instance

tests/pass/function_pointers.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ fn h(i: i32, j: i32) -> i32 {
2323
j * i * 7
2424
}
2525

26+
#[inline(never)]
2627
fn i() -> i32 {
2728
73
2829
}
@@ -77,7 +78,7 @@ fn main() {
7778
assert_eq!(indirect_mut3(h), 210);
7879
assert_eq!(indirect_once3(h), 210);
7980
// Check that `i` always has the same address. This is not guaranteed
80-
// but Miri currently uses a fixed address for monomorphic functions.
81+
// but Miri currently uses a fixed address for non-inlineable monomorphic functions.
8182
assert!(return_fn_ptr(i) == i);
8283
assert!(return_fn_ptr(i) as unsafe fn() -> i32 == i as fn() -> i32 as unsafe fn() -> i32);
8384
// Miri gives different addresses to different reifications of a generic function.

tests/pass/issues/issue-91636.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ impl Function {
1010
}
1111
}
1212

13+
#[inline(never)]
1314
fn dummy(_: &str) {}
1415

1516
fn main() {

0 commit comments

Comments
 (0)