]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
ubsan: Don't test for NaNs if those do not exist (PR97926)
authorSegher Boessenkool <segher@kernel.crashing.org>
Fri, 19 Mar 2021 15:02:00 +0000 (15:02 +0000)
committerSegher Boessenkool <segher@kernel.crashing.org>
Mon, 22 Mar 2021 16:32:42 +0000 (16:32 +0000)
2021-03-22  Segher Boessenkool  <segher@kernel.crashing.org>

PR target/97926
* ubsan.c (ubsan_instrument_float_cast): Don't test for unordered if
there are no NaNs.

gcc/ubsan.c

index d752b897d642a9a51ab7dbd8e28ae27bea1d655b..1089aef639ffd2bae247cf54eda4e871bb4ca555 100644 (file)
@@ -1890,8 +1890,16 @@ ubsan_instrument_float_cast (location_t loc, tree type, tree expr)
   else
     return NULL_TREE;
 
-  t = fold_build2 (UNLE_EXPR, boolean_type_node, expr, min);
-  tt = fold_build2 (UNGE_EXPR, boolean_type_node, expr, max);
+  if (HONOR_NANS (mode))
+    {
+      t = fold_build2 (UNLE_EXPR, boolean_type_node, expr, min);
+      tt = fold_build2 (UNGE_EXPR, boolean_type_node, expr, max);
+    }
+  else
+    {
+      t = fold_build2 (LE_EXPR, boolean_type_node, expr, min);
+      tt = fold_build2 (GE_EXPR, boolean_type_node, expr, max);
+    }
   t = fold_build2 (TRUTH_OR_EXPR, boolean_type_node, t, tt);
   if (integer_zerop (t))
     return NULL_TREE;