-
Notifications
You must be signed in to change notification settings - Fork 13.8k
Open
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.Category: This is a bug.I-miscompileIssue: Correct Rust code lowers to incorrect machine codeIssue: Correct Rust code lowers to incorrect machine codeI-prioritizeIssue: Indicates that prioritization has been requested for this issue.Issue: Indicates that prioritization has been requested for this issue.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.
Description
Making a separate tracking issue for the core problem @nikic identified in #147265 (comment) since it's been in stable since at least May 2024.
The following rust code: https://rust.godbolt.org/z/eT9fbKvbq
#[no_mangle]
unsafe fn f(a: usize) -> u8 {
let b = g(a) as usize;
unsafe { *(b as *const u8) }
}
#[cold]
fn g(a: usize) -> *const u8 {
unsafe { std::mem::transmute(a) }
}
in 1.77 compiled to
f:
movzx eax, byte ptr [rdi]
ret
but starting in 1.78 becomes
f:
ud2
The change on the rust side is #121282 (cc @saethlin), but that's just exposing the problem in this example -- the root problem could probably be repro'd on older stable too, just in less-obvious ways.
It happens because LLVM removes the ptrtoint
+inttoptr
that's needed to recover exposed provenance from an otherwise-without_provenance
pointer.
Metadata
Metadata
Assignees
Labels
A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.Category: This is a bug.I-miscompileIssue: Correct Rust code lowers to incorrect machine codeIssue: Correct Rust code lowers to incorrect machine codeI-prioritizeIssue: Indicates that prioritization has been requested for this issue.Issue: Indicates that prioritization has been requested for this issue.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.