LLVM miscompile with -Copt-level=2 and -Ctarget-cpu=znver2
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 119k
- Forks
- 16.1k
- PR merge metrics
- PR metrics pending
Description
#![allow(internal_features)]
#![feature(custom_mir, core_intrinsics)]
extern crate core;
use core::intrinsics::mir::*;
#[custom_mir(dialect = "runtime", phase = "initial")]
fn fn2() -> u8 {
mir!{
let _1: (u16, u8, [u32; 3]);
let _2: *mut [u32; 3];
let _3: (u16, u8, [u32; 3]);
let _4: u16;
{
_1.0 = 0;
_1.1 = 0;
_1.2 = [0, 0, 0];
_2 = core::ptr::addr_of_mut!(_1.2);
_3 = _1;
_4 = _3.0;
_1 = (0, 0, _3.2);
_1 = _3;
*_2 = _3.2;
_1 = (0, _3.1, _3.2);
Call(RET = dump_var(_4, Move(_3), Move(_1)), ReturnTo(bb52), UnwindUnreachable())
}
bb52 = {
Return()
}
}
}
#[inline(never)]
fn dump_var(val0: u16, val1: (u16, u8, [u32; 3]), val2: (u16, u8, [u32; 3])) -> u8 {
let _val0 = std::hint::black_box(val0);
let _val1 = std::hint::black_box(val1);
val2.1
}
fn main() {
println!("{}", fn2());
}
Compile with
-Zmir-opt-level=0 -Copt-level=2 -Ctarget-cpu=znver2
And you'll get different output run-to-run. Miri reports no UB with Tree Borrows.
I'm sure this is incompletely reduced, but I am tired so I am filing this here for someone to reduce away the Rust layer around the bad LLVM IR pattern.
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 compiling the supplied Rust reproducer with -Zmir-opt-level=0, -Copt-level=2, and -Ctarget-cpu=znver2, then compare its run-to-run output and Miri result. Reduce the custom MIR and Rust layer while preserving the nondeterministic behavior, and inspect the resulting LLVM IR for the miscompile pattern. Done means a smaller reproducer or a clearly isolated bad LLVM IR pattern.
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
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 38/100