rust-lang / rust

Empowering everyone to build reliable and efficient software.
https://www.rust-lang.org
Other
99.18k stars 12.8k forks source link

SIGSEGV: rustc crashed on valid code #131419

Open shao-hua-li opened 1 month ago

shao-hua-li commented 1 month ago

I tried this code:

#[no_mangle]
pub static mut a: i32 = 0;
pub static mut g: [i32; 1] = [0; 1];
fn myfunc() {
    unsafe {
        while a != 0 {
            let mut c = &mut a;
            let mut b = 7;
            while b != 0 {
                let mut f = 1;
                while f <= 9 {
                    let mut d = 0;
                    while d <= 9 {
                        if !(*g.as_mut_ptr() != 0) {
                            *c = 0;
                        }
                        d += 1;
                    }
                    *g.as_mut_ptr() = 2;
                    f += 1;
                }
                b -= 1;
            }
            *g.as_mut_ptr() = b;
        }
    }
}

pub fn main() {
    myfunc();
}

I expected to see this happen: rustc compiles it

Instead, this happened: When compiling with rustc -Copt-level=1, rustc crashes with a segmentation fault.

Meta

rustc --version --verbose:

rustc 1.83.0-nightly (3ae715c8c 2024-10-07)
binary: rustc
commit-hash: 3ae715c8c63f9aeac47cbf7d8d9dadb3fa32c638
commit-date: 2024-10-07
host: x86_64-unknown-linux-gnu
release: 1.83.0-nightly
LLVM version: 19.1.1
Backtrace

```console % rustc -Awarnings test.rs -Zmir-opt-level=0 -Copt-level=1 error: rustc interrupted by SIGSEGV, printing backtrace /home/shaohua/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/librustc_driver-57fe6e1841a504ec.so(+0x3609be3)[0x7f0887209be3] /lib/x86_64-linux-gnu/libc.so.6(+0x42520)[0x7f0883842520] /home/shaohua/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM.so.19.1-rust-1.83.0-nightly(_ZN4llvm19simplifyInstructionEPNS_11InstructionERKNS_13SimplifyQueryE+0x42)[0x7f0881ac6102] /home/shaohua/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM.so.19.1-rust-1.83.0-nightly(_ZN4llvm15ScalarEvolution10createSCEVEPNS_5ValueE+0x364)[0x7f0881ca7464] ### cycle encountered after 4 frames with period 6 /home/shaohua/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM.so.19.1-rust-1.83.0-nightly(_ZN4llvm15ScalarEvolution14createSCEVIterEPNS_5ValueE+0x41e)[0x7f0881ca5b74] /home/shaohua/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM.so.19.1-rust-1.83.0-nightly(_ZN4llvm15ScalarEvolution27createNodeFromSelectLikePHIEPNS_7PHINodeE+0x2c5)[0x7f0881c9a88d] /home/shaohua/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM.so.19.1-rust-1.83.0-nightly(_ZN4llvm15ScalarEvolution10createSCEVEPNS_5ValueE+0x378)[0x7f0881ca7478] /home/shaohua/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM.so.19.1-rust-1.83.0-nightly(_ZN4llvm15ScalarEvolution14createSCEVIterEPNS_5ValueE+0x41e)[0x7f0881ca5b74] /home/shaohua/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM.so.19.1-rust-1.83.0-nightly(_ZN4llvm15ScalarEvolution27createNodeFromSelectLikePHIEPNS_7PHINodeE+0x2c5)[0x7f0881c9a88d] /home/shaohua/.rustup/toolchains/nightly-x86_64-unknown-linux-gnu/lib/libLLVM.so.19.1-rust-1.83.0-nightly(_ZN4llvm15ScalarEvolution10createSCEVEPNS_5ValueE+0x378)[0x7f0881ca7478] ### recursed 42 times note: rustc unexpectedly overflowed its stack! this is a bug note: maximum backtrace depth reached, frames may have been lost note: we would appreciate a report at https://github.com/rust-lang/rust help: you can increase rustc's stack size by setting RUST_MIN_STACK=16777216 [1] 1426002 segmentation fault rustc -Awarnings test.rs -Copt-level=1 ```

DianQK commented 1 month ago

Increasing RUST_MIN_STACK may help this.

workingjubilee commented 1 month ago

I guess this is a followup to https://github.com/rust-lang/rust/issues/131195 huh.