Closed
Description
Code:
fn main() {
fn x() {}
fn y() {}
let a = x as usize;
let b = y as usize;
assert_eq!(a, b);
}
Output in release mode:
thread 'main' panicked at 'assertion failed: `(left == right)`
left: `94740677858160`,
right: `94740677858160`', src/main.rs:8:5
There is a similar issue about comparing function pointers, but incorrect comparison of usize
may be more dangerous. For example, if unsafe code checks the equality between usize
to uphold its invariant, passing values obtained this way may break the invariant, even though the unsafe code itself didn't work with function pointers.
Metadata
Metadata
Assignees
Labels
Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Category: This is a bug.Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessMedium priorityRelevant to the compiler team, which will review and decide on the PR/issue.