x86_64 opt-level=0: load through a pointer made from f64 bits uses the XMM register as the address base
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 22/100
Línea de trabajo
The fix belongs in X86FastISel::X86SelectAddress in llvm/lib/Target/X86/X86FastISel.cpp, where the BitCast case recurses without checking the operand type, unlike the IntToPtr case just below it. Reproduce first with the given rustc --emit=asm command plus -Cllvm-args=-verify-machineinstrs to confirm the FR64 base register, then rebuild LLVM and recheck the assembly. Done looks like movq %xmm0, %rax followed by movl (%rax), %eax, a clean verifier run, and a codegen test under LLVM's X86 tests.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
On x86_64 at opt-level = 0, a pointer built from the bits of an f64 is loaded through the wrong register. LLVM's FastISel folds the bitcast double to i64 and the inttoptr into the load address and uses the XMM register as the base register. In the object file that register number is the general purpose register with the same number (xmm0 becomes rax), so the load reads through whatever rax holds.
Code
#[no_mangle]
#[allow(unnecessary_transmutes)]
pub unsafe fn read_through_f64(x: f64) -> u32 {
let p = std::mem::transmute::<f64, usize>(x) as *const u32;
*p
}
rustc --crate-type=lib --target x86_64-unknown-linux-gnu -Copt-level=0 -Cdebug-assertions=off --emit=asm m.rs
I expected movq %xmm0, %rax followed by movl (%rax), %eax. Instead:
read_through_f64:
movl (%xmm0), %eax
retq
The machine verifier agrees (-Cllvm-args=-verify-machineinstrs):
*** Bad machine code: Illegal virtual register for instruction ***
- instruction: %3:gr32 = MOV32rm %1:fr64, 1, $noreg, 0, $noreg :: (load (s32) from %ir.3)
Expected a GR64 register, but got a FR64 register
The IR is fine:
define i32 @read_through_f64(double %x) unnamed_addr #0 {
start:
%_3 = bitcast double %x to i64
%p = inttoptr i64 %_3 to ptr
%_0 = load i32, ptr %p, align 4
ret i32 %_0
}
Same output for x86_64-pc-windows-msvc and x86_64-apple-darwin. -Cllvm-args=-fast-isel=false gives correct code. With debug assertions on, the alignment check splits the block and hides it; that is why the repro turns them off.
Where it bites
This crashes real code: wasmi 2.0.0 keeps an instance pointer in an f64 on x86_64, and a generic #[inline] path that gets instantiated in an opt-level = 0 crate (optimized dependency, unoptimized embedder) faults on Windows with rax holding a string length. See https://github.com/wasmi-labs/wasmi/issues/2061.
Cause
X86FastISel::X86SelectAddress in llvm/lib/Target/X86/X86FastISel.cpp looks past every BitCast, without checking that the operand is an integer or pointer:
case Instruction::BitCast:
// Look past bitcasts.
return X86SelectAddress(U->getOperand(0), AM);
So it reaches the double argument and uses its FR64 register as the base. The IntToPtr case right below already checks the operand type. This is still the code on LLVM main today.
Version
rustc 1.94.0 (4a4ef493e 2026-03-02), LLVM 21.1.8
Also reported on 1.95.0 and 1.100.0 (via the wasmi issue).
- Lenguaje dominante
- Rust
- Estrellas
- 122k
- Forks
- 16.7k
- Merge medio
- 2 d 16 h
- PR fusionados (30 d)
- 515
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de rust-lang/rust
-
Remove unnecessary parentheses when suggesting to remove '&' from a patternPosiblemente ocupada @BartSimpson001 la tomó hace 1 día. AbiertoA-diagnostics D-invalid-suggestion T-compiler
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
Windows `File::set_permissions` silently does nothing when clearing `readonly` leaves `FileAttributes == 0`Posiblemente ocupada @ChrisDenton la tomó hace 11 días. AbiertoA-filesystem C-bug O-windows T-libs
Dificultad 2/5 1-3 horas Aptitud para principiantes 62/100
Los mantenedores suelen responder en 1 día
-
A-run-make relnotes relnotes-needs-review relnotes-tracking-issue T-lang T-libs
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
-
A-LLVM O-Arm O-UEFI O-x86_64 relnotes relnotes-needs-review relnotes-tracking-issue T-compiler
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
rust-lang/rust#165504 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
relnotes relnotes-tracking-issue T-libs
Dificultad 1/5 Menos de una hora Aptitud para principiantes 72/100
Los mantenedores suelen responder en 1 día
Todos los issues de rust-lang/rust
Issues similares
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
bytecodealliance/wrpc#1785 ·
Los mantenedores suelen responder en 1 día
-
2 advisory ignore entries no longer match anything (`quick-xml` already patched in `Cargo.lock`)Abierto
Dificultad 1/5 Menos de una hora Aptitud para principiantes 85/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
longbridge/nsh#2758 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
antithesishq/bombadil#473 ·
Los mantenedores suelen responder en 2 días
-
bench/api.sh exec test fails with curl exit 52, and --ignore-failure still records the timingsAbiertobug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
libracoder/kiri#669 ·
Los mantenedores suelen responder en 1 día