Skip to content

Commit

Permalink
Add test for fn pointer duplication.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Apr 9, 2024
1 parent fc1a4c5 commit 9206a9f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
10 changes: 10 additions & 0 deletions tests/ui/mir/auxiliary/static_fnptr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
//@ compile-flags:-O

fn foo() {}

pub static ADDR: fn() = foo;

#[inline(always)]
pub fn bar(x: fn()) -> bool {
x == ADDR
}
14 changes: 14 additions & 0 deletions tests/ui/mir/static_fnptr.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
//@ 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 9206a9f

Please sign in to comment.