From 9907ad6ed9fde5ccdb58a7d59d652a4c8a98a346 Mon Sep 17 00:00:00 2001 From: Mark Rousskov Date: Fri, 17 Apr 2020 21:42:22 -0400 Subject: Define UB in float-to-int casts to saturate - Round to zero, and representable values cast directly. - `NaN` goes to 0 - Values beyond the limits of the type are saturated to the "nearest value" (essentially rounding to zero, in some sense) in the integral type, so e.g. `f32::INFINITY` would go to `{u,i}N::MAX.` --- src/librustc_codegen_ssa/mir/rvalue.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/librustc_codegen_ssa') diff --git a/src/librustc_codegen_ssa/mir/rvalue.rs b/src/librustc_codegen_ssa/mir/rvalue.rs index 19a0138d9cb..bb532abd84b 100644 --- a/src/librustc_codegen_ssa/mir/rvalue.rs +++ b/src/librustc_codegen_ssa/mir/rvalue.rs @@ -768,7 +768,7 @@ fn cast_float_to_int<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>( ) -> Bx::Value { let fptosui_result = if signed { bx.fptosi(x, int_ty) } else { bx.fptoui(x, int_ty) }; - if !bx.cx().sess().opts.debugging_opts.saturating_float_casts { + if let Some(false) = bx.cx().sess().opts.debugging_opts.saturating_float_casts { return fptosui_result; } -- cgit 1.4.1-3-g733a5