From a68ae2e1b15892b8e822f5a99f2b9d1e59b56e4c Mon Sep 17 00:00:00 2001 From: Marek Polacek Date: Tue, 23 Jun 2015 17:10:10 +0000 Subject: [PATCH] c-common.c (warn_logical_operator): Use tree_int_cst_equal when comparing INTEGER_CSTs. * 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 | 5 +++++ gcc/c-family/c-common.c | 3 ++- gcc/testsuite/ChangeLog | 4 ++++ gcc/testsuite/c-c++-common/Wlogical-op-3.c | 22 ++++++++++++++++++++++ 4 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/c-c++-common/Wlogical-op-3.c diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index a721ab58183..e2bd7e972c8 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,8 @@ +2015-06-23 Marek Polacek + + * c-common.c (warn_logical_operator): Use tree_int_cst_equal + when comparing INTEGER_CSTs. + 2015-06-22 Pierre-Marie de Rodat * c-ada-spec.h (cpp_operation): Add HAS_DEPENDENT_TEMPLATE_ARGS. diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index c39a36deb30..9fcd9d69b74 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -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, diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index cfb7af77346..eeb839f5f41 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2015-06-23 Marek Polacek + + * c-c++-common/Wlogical-op-3.c: New test. + 2015-06-23 Paolo Carlini 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 index 00000000000..83b5df43ba5 --- /dev/null +++ b/gcc/testsuite/c-c++-common/Wlogical-op-3.c @@ -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" } */ +} -- 2.30.2