Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions tests/ui/mir/auxiliary/static_fnptr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//@ compile-flags:-O

#[inline]
fn foo() {}

pub static ADDR: fn() = foo;

#[inline(always)]
pub fn bar(x: fn()) -> bool {
x == ADDR
}
21 changes: 21 additions & 0 deletions tests/ui/mir/static_fnptr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//! Verify that we correctly handle fn pointer provenance in MIR optimizations.
//! By asking to inline `static_fnptr::bar`, we have two copies of `static_fnptr::foo`, one in the
//! auxiliary crate and one in the local crate CGU.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to rely on foo being automatically marked as inline? Does inline(never) on foo make the issue go away?

If yes it'd be better to mark it as inline explicitly to avoid rely on the auto-inline heuristic.

//! `baz` must only consider the versions from upstream crate, and not try to compare with the
//! address of the CGU-local copy.
//! Related issue: #123670

//@ run-pass
//@ compile-flags:-Cno-prepopulate-passes -Copt-level=0
//@ aux-build:static_fnptr.rs

extern crate static_fnptr;
use static_fnptr::{ADDR, bar};

fn baz() -> bool {
bar(ADDR)
}

fn main() {
assert!(baz())
}