Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SIGSEGV: rustc crashed on valid code #131419

Open
shao-hua-li opened this issue Oct 8, 2024 · 2 comments
Open

SIGSEGV: rustc crashed on valid code #131419

shao-hua-li opened this issue Oct 8, 2024 · 2 comments
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@shao-hua-li
Copy link

shao-hua-li commented Oct 8, 2024

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

@shao-hua-li shao-hua-li added the C-bug Category: This is a bug. label Oct 8, 2024
@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Oct 8, 2024
@tmiasko tmiasko added I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Oct 8, 2024
@DianQK
Copy link
Member

DianQK commented Oct 9, 2024

Increasing RUST_MIN_STACK may help this.

@workingjubilee
Copy link
Member

I guess this is a followup to #131195 huh.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-LLVM Area: Code generation parts specific to LLVM. Both correctness bugs and optimization-related issues. C-bug Category: This is a bug. I-crash Issue: The compiler crashes (SIGSEGV, SIGABRT, etc). Use I-ICE instead when the compiler panics. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

5 participants