rust-lang / rust-lang/rustc_codegen_gcc

Operation resulting in a NaN gets optimized away, changing the result to infinity.

Open
#704 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

arm bug
Dominant language
Rust
Stars
1.2k
Forks
105
Avg merge
8h 20m
Merged PRs (30d)
14

Description

This is, once again, an ARM-specific bug.

When this code is compiled with LLVM(or release GCC on x86_64, or debug GCC on ARM), it prints NaN.

When the same code is compiled with release GCC on ARM, it produces an infinity value instead.

#[no_mangle]
#[inline(never)]
fn dump_var(val3: f32) {
    println!("{val3:?}")
}
fn fn2(param: f32) {
    let inf = param * 170141170000000000000000000000000000000.0;
    let should_be_nan = inf + 0.0 - inf;
    dump_var(should_be_nan);
}
fn main() {
    fn2(3.0);
}

Subtracting infinity from ininifty ought to result in an NaN value.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided Rust reproducer, especially fn2 and the inf + 0.0 - inf expression, and compare release GCC output on ARM with LLVM and x86_64 or debug GCC. Trace the generated operation and verify that the compiled program preserves the expected NaN result rather than producing infinity.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.