about summary refs log tree commit diff
path: root/compiler/rustc_apfloat/src/ieee.rs
diff options
context:
space:
mode:
authorJonas Schievink <jonasschievink@gmail.com>2020-10-04 15:45:39 +0200
committerGitHub <noreply@github.com>2020-10-04 15:45:39 +0200
commit9ea462fd70cf80b9371c7da875add271ad17f415 (patch)
tree2b857bf81d6abd66a5a9d8f6530000ab2e548b87 /compiler/rustc_apfloat/src/ieee.rs
parent4ae7710e1df02a1c38f2d2908fbbe5543c2e9d51 (diff)
parentd010809c8c0062a4c7a3249254a5193dd1ca15c7 (diff)
Rollup merge of #77368 - est31:apfloat_fix, r=varkor
Backport LLVM apfloat commit to rustc_apfloat

Backports LLVM commit: https://github.com/llvm/llvm-project/commit/e34bd1e0b03d20a506ada156d87e1b3a96d82fa2

Fixes #69532
Diffstat (limited to 'compiler/rustc_apfloat/src/ieee.rs')
-rw-r--r--compiler/rustc_apfloat/src/ieee.rs15
1 files changed, 10 insertions, 5 deletions
diff --git a/compiler/rustc_apfloat/src/ieee.rs b/compiler/rustc_apfloat/src/ieee.rs
index e3d941cad7a..71bcb8f090d 100644
--- a/compiler/rustc_apfloat/src/ieee.rs
+++ b/compiler/rustc_apfloat/src/ieee.rs
@@ -1511,11 +1511,16 @@ impl<S: Semantics, T: Semantics> FloatConvert<IeeeFloat<T>> for IeeeFloat<S> {
                 sig::set_bit(&mut r.sig, T::PRECISION - 1);
             }
 
-            // gcc forces the Quiet bit on, which means (float)(double)(float_sNan)
-            // does not give you back the same bits. This is dubious, and we
-            // don't currently do it. You're really supposed to get
-            // an invalid operation signal at runtime, but nobody does that.
-            status = Status::OK;
+            // Convert of sNaN creates qNaN and raises an exception (invalid op).
+            // This also guarantees that a sNaN does not become Inf on a truncation
+            // that loses all payload bits.
+            if self.is_signaling() {
+                // Quiet signaling NaN.
+                sig::set_bit(&mut r.sig, T::QNAN_BIT);
+                status = Status::INVALID_OP;
+            } else {
+                status = Status::OK;
+            }
         } else {
             *loses_info = false;
             status = Status::OK;