Skip to content

SIGSEGV: rustc crashed on valid code #131419

Open
@shao-hua-li

Description

@shao-hua-li

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

% 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-LLVMArea: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues.C-bugCategory: This is a bug.I-crashIssue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions