Not planned
Description
I tried this code:
pub fn a() -> i32 {
return 0;
}
pub fn b() -> i32 {
return 0;
}
pub fn main() {
if Some(b as fn() -> i32) != Some(a as fn() -> i32) {
println!("OK\n");
}
}
I expected to see this happen: -Copt-level=0/1/2/3 should give the same result
Instead, this happened:
% rustc test.rs -Copt-level=1 &&./test
OK
% rustc test.rs -Copt-level=2 &&./test
%
Meta
rustc --version --verbose
:
rustc 1.84.0-nightly (9322d183f 2024-10-14)
binary: rustc
commit-hash: 9322d183f45e0fd5a509820874cc5ff27744a479
commit-date: 2024-10-14
host: x86_64-unknown-linux-gnu
release: 1.84.0-nightly
LLVM version: 19.1.1
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
saethlin commentedon Oct 15, 2024
This is not a bug, you're tripping over rust-lang/unsafe-code-guidelines#522.
In short:
The program above has different behavior because the functions are merged at some opt levels. Note that function addresses truly are unstable, not only can you get merges like this, a single function can have multiple addresses in a single program.