#[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.
```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
```
I tried this code:
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
: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 ```