Open
Description
Consider this code:
#![feature(strict_provenance)]
use std::ptr;
#[no_mangle]
pub fn test(x: *mut u8) -> bool {
let local = 0u8;
for i in 0..=usize::MAX {
if x.addr() == ptr::from_ref(&local).wrapping_add(i).addr() {
return true;
}
}
false
}
This compares x.addr()
with every possible address there is. And yet, the optimized LLVM IR for this is:
; Function Attrs: mustprogress nofree norecurse nosync nounwind nonlazybind willreturn memory(none) uwtable
define noundef zeroext i1 @test(ptr nocapture noundef readnone %x) unnamed_addr #0 {
start:
ret i1 false
}
That's clearly nonsense.
This is the Rust version of llvm/llvm-project#34450.
Cc @nikic @rust-lang/opsem
Metadata
Metadata
Assignees
Labels
Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Issue: Correct Rust code lowers to incorrect machine codeIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessLow priorityRelevant to the compiler team, which will review and decide on the PR/issue.