You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The following program (with perhaps undefined behaviour) causes an ICE:
fnice(){println!("{:?}",Some(257.0f32asu8));}
Interestingly, if not wrapping the result in a Some, then there's no ICE.
fnno_ice(){println!("{:?}",257.0f32asu8);}
Here's the result from running it on the playground:
Compiling playground v0.0.1(file:///playground)
error: internal compiler error: unexpected panic
note: the compiler unexpectedly panicked.this is a bug.
note: we would appreciate a bug report: https://github.com/rust-lang/rust/blob/master/CONTRIBUTING.md#bug-reports
note: rustc 1.20.0(f3d6973f4 2017-08-27) running on x86_64-unknown-linux-gnu
thread 'rustc' panicked at 'assertion failed:!is_undef(val)', /checkout/src/librustc_trans/mir/constant.rs:1083:8
note:Run with `RUST_BACKTRACE=1` for a backtrace.
error:Could not compile `playground`.To learn more, run the command again with --verbose.
The text was updated successfully, but these errors were encountered:
Same underlying issue, but a different code path than the one that's been exclusively (as far as I can tell) discussed over there. So this report was very valuable for my in-progress patch addressing #10184, thank you @samnardoni!
Saturating casts between integers and floats
Introduces a new flag, `-Z saturating-float-casts`, which makes code generation for int->float and float->int casts safe (`undef`-free), implementing [the saturating semantics laid out by](#10184 (comment)) @jorendorff for float->int casts and overflowing to infinity for `u128::MAX` -> `f32`.
Constant evaluation in trans was changed to behave like HIR const eval already did, i.e., saturate for u128->f32 and report an error for problematic float->int casts.
Many thanks to @eddyb, whose APFloat port simplified many parts of this patch, and made HIR constant evaluation recognize dangerous float casts as mentioned above.
Also thanks to @ActuallyaDeviloper whose branchless implementation served as inspiration for this implementation.
cc #10184#41799fixes#45134
The following program (with perhaps undefined behaviour) causes an ICE:
Interestingly, if not wrapping the result in a
Some
, then there's no ICE.Here's the result from running it on the playground:
The text was updated successfully, but these errors were encountered: