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

"Illegal instruction" when running release build #82278

Closed
SlaynAndKorpil opened this issue Feb 18, 2021 · 1 comment
Closed

"Illegal instruction" when running release build #82278

SlaynAndKorpil opened this issue Feb 18, 2021 · 1 comment
Labels
C-bug Category: This is a bug.

Comments

@SlaynAndKorpil
Copy link

SlaynAndKorpil commented Feb 18, 2021

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

@SlaynAndKorpil SlaynAndKorpil added the C-bug Category: This is a bug. label Feb 18, 2021
@ehuss
Copy link
Contributor

ehuss commented Feb 18, 2021

Thanks for the report! Infinite loops are undefined behavior in LLVM, which can result in anything happening. This is a known issue, closing as a duplicate of #28728.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug.
Projects
None yet
Development

No branches or pull requests

2 participants