-
Notifications
You must be signed in to change notification settings - Fork 12.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Miscompilation: comparing a pointer against all possible addresses returns false
#130388
Comments
This also gets optimized to simply returning #![feature(strict_provenance)]
use std::ptr;
#[no_mangle]
pub fn test(p: *mut u8) -> bool {
let a = 0u8;
p.addr() == ptr::from_ref(&a).addr()
} I'm not sure if #[no_mangle]
pub fn test(x: *const u8) -> bool {
let a = 0u8;
(&a as *const u8 as usize) == x as usize
} |
@orlp yes but that can be justified. You are basically comparing an arbitrary non-deterministic value with And this has nothing to do with strict provenance indeed, I just used |
Simply put the non-inlined |
@orlp that doesn't work since You'd have to construct an example where one can actually tell, inside the Rust program (i.e., not via a debugger or by inspecting the assembly), that |
Alright, I tried a bit to make a contradiction under those conditions and couldn't make one. |
WG-prioritization assigning priority (Zulip discussion). @rustbot label -I-prioritize +P-low |
I think this is another manifest of #107975 (adapted from Essentially LLVM performs pointer comparision with provenance. |
No, this is a completely unrelated issue. The issue description already links the corresponding LLVM issue. |
Consider this code:
This compares
x.addr()
with every possible address there is. And yet, the optimized LLVM IR for this is:That's clearly nonsense.
This is the Rust version of llvm/llvm-project#34450.
Cc @nikic @rust-lang/opsem
The text was updated successfully, but these errors were encountered: