-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Description
When running this code with cargo run --release
, it prints Illegal instruction
and immedialy exits with error code 132. This only happens when running the release build, the debug build created by cargo build
just runs endlessly as expected.
use std::thread;
fn main() {
let thread = thread::spawn(move || {
let x = 0isize;
loop {
x % 1;
}
});
thread.join().unwrap();
}
This happens when x is of any signed integer type. When I replace the content of the loop with 0isize % 1;
, the error does not occur. Using something like while true
instead of loop
leads to the same error.
I did not modify the Cargo.toml
generated by cargo new
:
[package]
name = "bug"
version = "0.1.0"
authors = ["felix <[email protected]>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
Meta
I have tested this problem on two Linux machines (uname -a
):
Linux wheatly 4.19.0-14-amd64 #1 SMP Debian 4.19.171-2 (2021-01-30) x86_64 GNU/Linux
and Linux raspberrypi 5.4.79-v7l+ #1373 SMP Mon Nov 23 13:27:40 GMT 2020 armv7l GNU/Linux
both running the same rust version:
rustc --version --verbose
:
rustc 1.50.0 (cb75ad5db 2021-02-10)
binary: rustc
commit-hash: cb75ad5db02783e8b0222fee363c5f63f7e2cf5b
commit-date: 2021-02-10
host: x86_64-unknown-linux-gnu
release: 1.50.0