Skip to content

Commit e9cfac3

Browse files
authored
Unrolled build for rust-lang#123714
Rollup merge of rust-lang#123714 - cjgillot:static-fnptr, r=wesleywiser 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``````
2 parents 9ed2ab3 + 4c779d7 commit e9cfac3

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed
+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
//@ compile-flags:-O
2+
3+
#[inline]
4+
fn foo() {}
5+
6+
pub static ADDR: fn() = foo;
7+
8+
#[inline(always)]
9+
pub fn bar(x: fn()) -> bool {
10+
x == ADDR
11+
}

tests/ui/mir/static_fnptr.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//! Verify that we correctly handle fn pointer provenance in MIR optimizations.
2+
//! By asking to inline `static_fnptr::bar`, we have two copies of `static_fnptr::foo`, one in the
3+
//! auxiliary crate and one in the local crate CGU.
4+
//! `baz` must only consider the versions from upstream crate, and not try to compare with the
5+
//! address of the CGU-local copy.
6+
//! Related issue: #123670
7+
8+
//@ run-pass
9+
//@ compile-flags:-Cno-prepopulate-passes -Copt-level=0
10+
//@ aux-build:static_fnptr.rs
11+
12+
extern crate static_fnptr;
13+
use static_fnptr::{ADDR, bar};
14+
15+
fn baz() -> bool {
16+
bar(ADDR)
17+
}
18+
19+
fn main() {
20+
assert!(baz())
21+
}

0 commit comments

Comments
 (0)