Miscompile at -Copt-level=1
Open
@dianqk is already working on this.
Since Nov 25, 2025.
A-LLVM
A-rustlantis
C-bug
I-miscompile
P-medium
T-compiler
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
I think this is an LLVM SROA bug, it reproduces with -Cno-prepopulate-passes -Cpasses=sroa.
I'm running out of ideas for how to minimize this. Maybe it's minimal?
#![feature(custom_mir, core_intrinsics)]
extern crate core;
use core::intrinsics::mir::*;
#[inline(never)]
fn opaque<T>(t: T) {std::hint::black_box(t);}
#[inline(never)]
#[custom_mir(dialect = "runtime", phase = "initial")]
pub fn fn0() -> ([u8; 1], u32) {
mir! {
let _1: (([u8; 1], u32), [u8; 5]);
let _2: ();
{
_1.0.0 = [0];
_1.0.1 = 2;
_1.1 = [0, 0, 0, 0, 0];
Call(RET = fn1(_1.0, _1.0, _1), ReturnTo(bb2), UnwindUnreachable())
}
bb2 = {
Call(_2 = opaque(Move(_1)), ReturnTo(bb3), UnwindUnreachable())
}
bb3 = {
Return()
}
}
}
#[inline(never)]
#[custom_mir(dialect = "runtime", phase = "initial")]
fn fn1(
mut _1: ([u8; 1], u32),
mut _2: ([u8; 1], u32),
mut _3: (([u8; 1], u32), [u8; 5]),
) -> ([u8; 1], u32) {
mir! {
let _4: ();
{
_1 = (_3.0.0, 0);
_3.0 = _1;
RET = _1;
Call(_4 = opaque(_2.1), ReturnTo(bb6), UnwindUnreachable())
}
bb6 = {
Call(_4 = opaque(Move(_3)), ReturnTo(bb7), UnwindUnreachable())
}
bb7 = {
Return()
}
}
}
fn main() {
println!("{:?}", fn0());
}
Miri prints:
([0], 0)
rustc -Copt-level=1 -Zmir-opt-level=0 prints:
([0], 2)
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.
Assessment
This issue has not been assessed yet.