Rust-GCC / Rust-GCC/gccrs

Out of range float casts miscompilation

Open
#635 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
C++
Stars
2.9k
Forks
230
Avg merge
19h 55m
Merged PRs (30d)
67

Description

I tried this code:

pub fn foo() -> f32 {
    0xffff_ffff_ffff_ffff_ffff_ffff_ffff_ffffu128 as f32
}

I expected to see this happen: Saturating to f32::INFINITY

Instead, this happened: 9223372000000000000.0 is returned

Another case is

pub fn foo() -> f32 {
    1<an absolutely huge amount of zeros>u128 as f32
}

which should give an out of range error, but returns 0.0.

Meta
  • What version of Rust GCC were you using, git sha if possible: The current version at godbolt.

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 by reproducing both Rust snippets with the current gccrs version or the Godbolt setup referenced in the issue, and compare their results with the expected saturating conversion behavior. Trace the compiler handling of out-of-range u128-to-f32 casts; done means both examples produce the specified results and regression coverage is added where the relevant tests are found.

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
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.