Rust LLVMIR causes errors after LTO on x86-32
Open
Nobody has claimed this yet.
A-ABI
A-LLVM
A-LTO
C-bug
O-x86_32
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
#[repr(C)]
pub struct UrlpPattern(pub *mut c_void);
#[unsafe(no_mangle)]
pub unsafe extern "C" fn square(num: UrlpPattern) -> *mut c_void {
num.0
}
generates
define noundef ptr @square(ptr noalias nocapture noundef readonly byval([4 x i8]) align 4 dereferenceable(4) %num) unnamed_addr {
start:
%_0 = load ptr, ptr %num, align 4
ret ptr %_0
}
but
struct wrapper {
void *p;
};
void *square(wrapper p) {
return p.p;
}
generates
define dso_local i8* @square(wrapper)(i8* readnone returned %p.0) local_unnamed_addr {
entry:
ret i8* %p.0
}
It seems like this mostly works because it compiles to the same thing x86-32 code:
square(wrapper): # @square(wrapper)
mov eax, dword ptr [esp + 4]
ret
However, if the rust code is inlined into C++ with LTO we end up with an extra dereference.
We ran into this in Firefox here: https://bugzilla.mozilla.org/show_bug.cgi?id=1973805
rustc --version --verbose:
rustc 1.88.0 (6b00bc388 2025-06-23)
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the Rust and C/C++ examples with rustc 1.88.0 and compare their LLVM IR, including an LTO build. Use the Firefox Bugzilla report as context, then verify that x86-32 LTO no longer introduces an extra dereference while preserving the expected ABI behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100