Skip to content

Commit

Permalink
Rollup merge of rust-lang#123714 - cjgillot:static-fnptr, r=wesleywiser
Browse files Browse the repository at this point in the history
Add test for fn pointer duplication.

I managed to make it fail when removing provenance checks in GVN.

cc rust-lang#123670

r? ``@oli-obk``
  • Loading branch information
matthiaskrgr committed Jun 27, 2024
2 parents ab690fe + 4c779d7 commit 72f2d11
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
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.
//! `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())
}

0 comments on commit 72f2d11

Please sign in to comment.