forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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``````
- Loading branch information
Showing
2 changed files
with
32 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} |