Miscompilation with `-C opt-level=2 -C codegen-units=1`(but not with opt-level=3) due `loop-vectorize` llvm pass
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 8/100
Línea de trabajo
The miscompilation shows up only at opt-level=2 with codegen-units=1, and bisection points at the LLVM loop-vectorize pass on the generic reduced::e::<i128> instance. Start by reproducing with the reduced program and the -C llvm-args=-opt-bisect-limit flag, then inspect the LLVM IR before and after vectorization. Done means identifying the root cause, whether in the Rust codegen of the i128 wrapping ops or in LLVM, and adding a regression test.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
I tried this code:
use std::hint::black_box;
trait Num: Copy + PartialOrd {
fn wadd(self, o: Self) -> Self;
fn wsub(self, o: Self) -> Self;
fn from_u64(v: u64) -> Self;
fn hi(self) -> u64;
}
impl Num for i128 {
fn wadd(self, o: Self) -> Self {
self.wrapping_add(o)
}
fn wsub(self, o: Self) -> Self {
self.wrapping_sub(o)
}
fn from_u64(v: u64) -> Self {
v as i128
}
fn hi(self) -> u64 {
self as u64
}
}
fn e<T: Num>(a: T, b: T, n: u32) -> T {
let mut d = T::from_u64(0);
for i in 0..n {
let a = a.wadd(T::from_u64(i as u64));
d = if T::from_u64(i as u64) >= T::from_u64(if T::from_u64(19937u64) >= a { a } else { T::from_u64(6u64) }.hi()) {
T::from_u64(if T::from_u64(19937u64) >= a { T::from_u64(19937u64).wsub(a) } else { a }.hi())
} else {
T::from_u64(if T::from_u64(19937u64) >= a { T::from_u64(19937u64).wsub(a) } else { a }.hi()).wsub(T::from_u64(1))
}
}
match 0 {
_ => d,
}
}
fn main() {
let c: fn(i128, i128, u32) -> i128 = black_box(e);
println!("{}", c(Num::from_u64(2961832378146261130u64), 0, 2))
}
Rust compiled with
rustc +nightly reduced.rs; ./reduced
rustc +nightly reduced.rs -C opt-level=3 -C codegen-units=1; ./reduced # Same with opt-level=0/1/s/z
prints
2961832378146261130
but compiled with
rustc +nightly reduced.rs -C opt-level=2 -C codegen-units=1; ./reduced
rustc +nightly reduced.rs -C opt-level=2 -C codegen-units=1 -Zmir-opt-level=0; ./reduced # Same with mir-opt-level=1/2/3
prints
15484911695563310421
Bisecting the optimization passes with -C llvm-args=-opt-bisect-limit: the first LLVM pass that changes the result is pass 744 of 1301, loop-vectorize on reduced::e::<i128>.
Meta
rustc --version --verbose:
rustc 1.99.1 (58cf8f9c3 2026-10-13)
binary: rustc
commit-hash: 58cf8f9c35b355199727627d07ae34a4e2846d67
commit-date: 2026-10-13
host: x86_64-unknown-linux-gnu
release: 1.99.1
LLVM version: 23.1.1
| channel | reproducible |
|---|---|
| stable (rustc 1.99.1 (58cf8f9c3 2026-10-13)) | yes |
| beta (rustc 1.100.0-beta.7 (fd8e211ae 2026-10-17)) | yes |
| nightly (rustc 1.101.0-nightly (16d1ffac1 2026-10-26)) | yes |
| stable 1.98.0 (rustc 1.98.0 (88d9e12ae 2026-08-18)) | no |
| stable 1.99.0 (rustc 1.99.0 (b940084d7 2026-09-28)) | yes |
| nightly-2026-08-05 (rustc 1.99.0-nightly (1ed2df61a 2026-08-04)) | no |
| nightly-2026-08-06 (rustc 1.99.0-nightly (7608eb7b0 2026-08-05)) | yes |
Bisected with cargo bisect-rustc:
- searched commit range: https://github.com/rust-lang/rust/compare/1ed2df61a19042f231709eb05d032ae9e2cb2084...7608eb7b07eaf93f16d7cf5bcb2098eca87503df
- regressed commit: https://github.com/rust-lang/rust/commit/1b29cfdbee8ee37333f4b24afb936350eb57e705
Problem was found by and minimized by rust fuzzer(created by llm) - https://github.com/qarmin/rs-compiler-fuzzer (the latest findings of the fuzzer can be checked by hand in https://github.com/qarmin/rs-compiler-fuzzer/releases/download/Nightly/findings.zip)
- Lenguaje dominante
- Rust
- Estrellas
- 121k
- Forks
- 17.3k
- Merge medio
- 2 d 21 h
- PR fusionados (30 d)
- 531
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
-
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
-
relnotes relnotes-needs-review relnotes-tracking-issue T-compiler T-libs
Dificultad 1/5 Menos de una hora Aptitud para principiantes 78/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
-
unclear wording in vec macroPosiblemente ocupada @Suhird la tomó hace 5 días. AbiertoA-docs A-slice-vec T-libs
Dificultad 1/5 1-3 horas Aptitud para principiantes 70/100
rust-lang/rust#165360 · 6 comentarios · 1 asignado ·
Los mantenedores suelen responder en 1 día
Todos los issues de rust-lang/rust
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 69/100
bytecodealliance/rustix#1736 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
longbridge/gpui-kit#3871 ·
Los mantenedores suelen responder en 1 día
-
area:models enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
Los mantenedores suelen responder en 1 día
-
fix v1 repository metadataAbiertogood first issue help wanted
Dificultad 1/5 Menos de una hora Aptitud para principiantes 84/100
servo/rust-smallvec#864 ·