rust-lang / rust-lang/rust

LLVM miscompilation in instcombine

Open
#149,429 6 comments 0 reactions 1 assignee View on GitHub

@dianqk is already working on this.

Since Dec 3, 2025.

A-LLVM A-rustlantis E-needs-test I-miscompile T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

#![feature(custom_mir, core_intrinsics)]
extern crate core;
use core::intrinsics::mir::*;
fn main() {
    println!("{}", oof());
}
#[custom_mir(dialect = "runtime", phase = "initial")]
fn oof() -> isize {
    mir! {
        let _2: isize;
        let _3: f64;
        let _4: isize;
        let _6: isize;
        let _7: isize;
        let _9: isize;
        let _10: isize;
        let _8: isize;
        let _13: char;
        let _14: i8;
        let _16: &'static mut char;
        let _21: u64;
        let _25: *const i8;
        let _32: &'static mut char;
        let _35: isize;
        let _68: isize;
        {
            _7 = isize::MIN;
            _9 = isize::MIN;
            _10 = isize::MIN;
            _8 = 0;
            _2 = isize::MAX;
            Goto(bb2)
        }
        bb2 = {
            _4 = _7 & _8;
            _6 = !_4;
            _8 = _2 >> _6;
            _4 = _9 & _7;
            _7 = !_8;
            _16 = &mut _13;
            Goto(bb4)
        }
        bb4 = {
            _6 = _7 | _10;
            _8 = _6 << _7;
            _3 = _8 as f64;
            _25 = core::ptr::addr_of!(_14);
            _9 = 0;
            _10 = !_4;
            _35 = _3 as isize;
            _32 = _16;
            _21 = 1;
            match _21 {
                0_u64 => bb4,
                _ => bb29,
            }
        }
        bb29 = {
            _7 = _10 & _6;
            _2 = _6;
            *_25 = 1;
            match *_25 {
                1 => bb39,
                _ => bb2
            }
        }
        bb39 = {
            _68 = _7 & _35;
            Call(*_32 = fn17(_25), ReturnTo(bb56), UnwindUnreachable())
        }
        bb56 = {
            RET = _68;
            Return()
        }
    }
}
fn fn17(_: *const i8) -> char {
    'a'
}

Compile with

rustc +nightly -Zmir-opt-level=0 -Copt-level=1 -o $OUT -Cno-prepopulate-passes -Cpasses=sroa,instcombine

And the executable will print

-9223372036854775808

But if run with Miri:

MIRIFLAGS="-Zmiri-tree-borrows -Zmiri-no-short-fd-operations" cargo +nightly miri run

It will print 0.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.