c-common.c (warn_tautological_cmp): Bail for float types.
authorMarek Polacek <polacek@redhat.com>
Thu, 30 Jul 2015 08:31:59 +0000 (08:31 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Thu, 30 Jul 2015 08:31:59 +0000 (08:31 +0000)
* c-common.c (warn_tautological_cmp): Bail for float types.

* c-c++-common/Wtautological-compare-3.c: New test.

From-SVN: r226388

gcc/c-family/ChangeLog
gcc/c-family/c-common.c
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/Wtautological-compare-3.c [new file with mode: 0644]

index 06853ea86e96dd33ec10476de268e5a0c9a59cf9..d8953942a0a9b83d319e2d0ba41021c069c7287a 100644 (file)
@@ -1,3 +1,7 @@
+2015-07-30  Marek Polacek  <polacek@redhat.com>
+
+       * c-common.c (warn_tautological_cmp): Bail for float types.
+
 2015-07-27  Marek Polacek  <polacek@redhat.com>
 
        PR bootstrap/67030
index caa801e2adbcb10e7a4f4cded8e076f208a636bd..a8e5353749c2bd58dcc60541c6326f4daf6fff0f 100644 (file)
@@ -1910,6 +1910,12 @@ warn_tautological_cmp (location_t loc, enum tree_code code, tree lhs, tree rhs)
       || (CONVERT_EXPR_P (rhs) || TREE_CODE (rhs) == NON_LVALUE_EXPR))
     return;
 
+  /* Don't warn if either LHS or RHS has an IEEE floating-point type.
+     It could be a NaN, and NaN never compares equal to anything, even
+     itself.  */
+  if (FLOAT_TYPE_P (TREE_TYPE (lhs)) || FLOAT_TYPE_P (TREE_TYPE (rhs)))
+    return;
+
   if (operand_equal_p (lhs, rhs, 0))
     {
       /* Don't warn about array references with constant indices;
index 3d72f47a3a8dfd860b023450ed4b3f3066c94f23..08ea0c8dccc5f2ec09f101e750df57073eba5655 100644 (file)
@@ -1,3 +1,7 @@
+2015-07-30  Marek Polacek  <polacek@redhat.com>
+
+       * c-c++-common/Wtautological-compare-3.c: New test.
+
 2015-07-29  Alan Lawrence  <alan.lawrence@arm.com>
 
        * gcc.target/aarch64/vld1_lane.c (main): Remove unused test data.
diff --git a/gcc/testsuite/c-c++-common/Wtautological-compare-3.c b/gcc/testsuite/c-c++-common/Wtautological-compare-3.c
new file mode 100644 (file)
index 0000000..64807b0
--- /dev/null
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-options "-Wtautological-compare" } */
+/* Test we don't warn for floats.  */
+
+struct S { double d; float f; };
+
+void
+fn1 (int i, float f, double d, struct S *s, float *fp)
+{
+  if (f == f);
+  if (f != f);
+  if (d == d);
+  if (d != d);
+  if (fp[i] == fp[i]);
+  if (fp[i] != fp[i]);
+  if (s->f == s->f);
+  if (s->f != s->f);
+  if (s->d == s->d);
+  if (s->d != s->d);
+}