]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c-common.c (warn_logical_operator): Use tree_int_cst_equal when comparing INTEGER_CSTs.
authorMarek Polacek <polacek@redhat.com>
Tue, 23 Jun 2015 17:10:10 +0000 (17:10 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Tue, 23 Jun 2015 17:10:10 +0000 (17:10 +0000)
* c-common.c (warn_logical_operator): Use tree_int_cst_equal
when comparing INTEGER_CSTs.

* c-c++-common/Wlogical-op-3.c: New test.

From-SVN: r224853

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

index a721ab58183c2f6f01463f42aabb1065c22eb889..e2bd7e972c8df6bf0a11bff3717d63bb10443b37 100644 (file)
@@ -1,3 +1,8 @@
+2015-06-23  Marek Polacek  <polacek@redhat.com>
+
+       * c-common.c (warn_logical_operator): Use tree_int_cst_equal
+       when comparing INTEGER_CSTs.
+
 2015-06-22  Pierre-Marie de Rodat  <derodat@adacore.com>
 
        * c-ada-spec.h (cpp_operation): Add HAS_DEPENDENT_TEMPLATE_ARGS.
index c39a36deb30dc0c5cb6c92dea147ae9dfdcabbf7..9fcd9d69b74cf60e31f482a07a0fabb9423a3336 100644 (file)
@@ -1838,7 +1838,8 @@ warn_logical_operator (location_t location, enum tree_code code, tree type,
        }
       /* Or warn if the operands have exactly the same range, e.g.
         A > 0 && A > 0.  */
-      else if (low0 == low1 && high0 == high1)
+      else if (tree_int_cst_equal (low0, low1)
+              && tree_int_cst_equal (high0, high1))
        {
          if (or_op)
            warning_at (location, OPT_Wlogical_op,
index cfb7af77346c1cedbd3b2e1cd882b43d27f41a5c..eeb839f5f410f180b765b0c12a934558aa3c50d4 100644 (file)
@@ -1,3 +1,7 @@
+2015-06-23  Marek Polacek  <polacek@redhat.com>
+
+       * c-c++-common/Wlogical-op-3.c: New test.
+
 2015-06-23  Paolo Carlini  <paolo.carlini@oracle.com>
 
        PR c++/66254
diff --git a/gcc/testsuite/c-c++-common/Wlogical-op-3.c b/gcc/testsuite/c-c++-common/Wlogical-op-3.c
new file mode 100644 (file)
index 0000000..83b5df4
--- /dev/null
@@ -0,0 +1,22 @@
+/* { dg-do compile } */
+/* { dg-options "-Wlogical-op" } */
+
+void
+fn1 (int a)
+{
+  const int x = a;
+  if (x && x) {} /* { dg-warning "logical .and. of equal expressions" } */
+  if (x && (int) x) {} /* { dg-warning "logical .and. of equal expressions" } */
+  if ((int) x && x) {} /* { dg-warning "logical .and. of equal expressions" } */
+  if ((int) x && (int) x) {} /* { dg-warning "logical .and. of equal expressions" } */
+}
+
+void
+fn2 (int a)
+{
+  const int x = a;
+  if (x || x) {} /* { dg-warning "logical .or. of equal expressions" } */
+  if (x || (int) x) {} /* { dg-warning "logical .or. of equal expressions" } */
+  if ((int) x || x) {} /* { dg-warning "logical .or. of equal expressions" } */
+  if ((int) x || (int) x) {} /* { dg-warning "logical .or. of equal expressions" } */
+}