From 173864e8f143d138c2805c03699d8d58b2c970c8 Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Thu, 30 Jul 2015 08:31:59 +0000 Subject: [PATCH] c-common.c (warn_tautological_cmp): Bail for float types. * 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 | 4 ++++ gcc/c-family/c-common.c | 6 ++++++ gcc/testsuite/ChangeLog | 4 ++++ .../c-c++-common/Wtautological-compare-3.c | 20 +++++++++++++++++++ 4 files changed, 34 insertions(+) create mode 100644 gcc/testsuite/c-c++-common/Wtautological-compare-3.c diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 06853ea86e9..d8953942a0a 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,7 @@ +2015-07-30 Marek Polacek + + * c-common.c (warn_tautological_cmp): Bail for float types. + 2015-07-27 Marek Polacek PR bootstrap/67030 diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index caa801e2adb..a8e5353749c 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -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; diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 3d72f47a3a8..08ea0c8dccc 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2015-07-30 Marek Polacek + + * c-c++-common/Wtautological-compare-3.c: New test. + 2015-07-29 Alan Lawrence * 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 index 00000000000..64807b01d59 --- /dev/null +++ b/gcc/testsuite/c-c++-common/Wtautological-compare-3.c @@ -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); +} -- 2.30.2