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

Out of range float casts miscompilation #635

Open
bjorn3 opened this issue Aug 16, 2021 · 3 comments
Open

Out of range float casts miscompilation #635

bjorn3 opened this issue Aug 16, 2021 · 3 comments
Labels

Comments

@bjorn3
Copy link

bjorn3 commented Aug 16, 2021

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.
@bjorn3 bjorn3 added the bug label Aug 16, 2021
mathstuf added a commit to mathstuf/gccrs that referenced this issue Nov 1, 2021
The set of inline modules is required to find the expected location of a
module file. Track this information with an RAII object
(`InlineModuleStackScope`) and pass it down to any out-of-line modules
so that, when requested, the set of inline modules can be added to the
search path.

Fixes: Rust-GCC#635

Signed-off-by: Ben Boeckel <mathstuf@gmail.com>
@philberty
Copy link
Member

I think the code to check for this is in the GCC TREE_OVERFLOW flags

@philberty philberty added this to To do in Control Flow 3 Macros via automation Jan 5, 2022
@philberty philberty added this to the Macro Expansion milestone Jan 5, 2022
@philberty
Copy link
Member

@bjorn3 I have a branch of code to fix this but the part about Saturating to f32::INFINITY I might leave out for the first PR, I have code to catch this case but I wonder is there documentation that I can reference on this saturating to infinity?

philberty added a commit that referenced this issue Jan 5, 2022
This checks that the literal value is within the bounds of their respective
types. I have ommited code fixing the other issue in the bug report that
overflow/max_val integers should be saturated to infinity when cast to
REAL_TYPE's this seems like something we really should have documentation
to reference in the code as to why this is the correct Rust behaviour.

Addresses #635
@bjorn3
Copy link
Author

bjorn3 commented Jan 5, 2022

This is the PR which originallt changed it from UB to saturating: rust-lang/rust#71269

philberty added a commit that referenced this issue Jan 5, 2022
This checks that the literal value is within the bounds of their respective
types. I have ommited code fixing the other issue in the bug report that
overflow/max_val integers should be saturated to infinity when cast to
REAL_TYPE's this seems like something we really should have documentation
to reference in the code as to why this is the correct Rust behaviour.

Addresses #635
philberty added a commit that referenced this issue Jan 6, 2022
This checks that the literal value is within the bounds of their respective
types. I have ommited code fixing the other issue in the bug report that
overflow/max_val integers should be saturated to infinity when cast to
REAL_TYPE's this seems like something we really should have documentation
to reference in the code as to why this is the correct Rust behaviour.

Addresses #635
bors bot added a commit that referenced this issue Jan 7, 2022
860: Add overflow checking on LiteralExpression r=philberty a=philberty

This checks that the literal value is within the bounds of their respective
types. I have omitted code fixing the other issue in the bug report that
overflow/max_val integers should be saturated to infinity when cast to
REAL_TYPE's this seems like something we really should have documentation
to reference in the code as to why this is the correct Rust behaviour.

Addresses #635


Co-authored-by: Philip Herron <philip.herron@embecosm.com>
@philberty philberty removed this from To do in Control Flow 3 Macros Mar 14, 2022
@philberty philberty removed this from the Macro Expansion milestone Mar 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants