aboutsummaryrefslogtreecommitdiff
path: root/gcc/c
diff options
context:
space:
mode:
authorJakub Jelinek <jakub@redhat.com>2015-03-09 19:26:52 +0100
committerJakub Jelinek <jakub@gcc.gnu.org>2015-03-09 19:26:52 +0100
commit01177669b2eabfb1ddb3290c35bc110980b44d62 (patch)
tree2111b63d7da0a0531f8135d1ab1f64662e3887af /gcc/c
parentee876e59156337667c4945c3346c0c7876f3a98c (diff)
downloadgcc-01177669b2eabfb1ddb3290c35bc110980b44d62.zip
gcc-01177669b2eabfb1ddb3290c35bc110980b44d62.tar.gz
gcc-01177669b2eabfb1ddb3290c35bc110980b44d62.tar.bz2
re PR c/65120 (Wlogical-not-parentheses should not warn about double exclamation !!)
PR c/65120 * c-typeck.c (parser_build_binary_op): Don't warn for !!x == y or !b == y where b is _Bool. * parser.c (cp_parser_binary_expression): Don't warn for !!x == y or !b == y where b is bool. * c-c++-common/pr49706.c: Adjust tests for not warning about !!x == y or !b == y where b is boolean, and add some further tests. * c-c++-common/pr62199-2.c: Likewise. From-SVN: r221284
Diffstat (limited to 'gcc/c')
-rw-r--r--gcc/c/ChangeLog6
-rw-r--r--gcc/c/c-typeck.c30
2 files changed, 34 insertions, 2 deletions
diff --git a/gcc/c/ChangeLog b/gcc/c/ChangeLog
index a5fcb35..7b81080 100644
--- a/gcc/c/ChangeLog
+++ b/gcc/c/ChangeLog
@@ -1,3 +1,9 @@
+2015-03-09 Jakub Jelinek <jakub@redhat.com>
+
+ PR c/65120
+ * c-typeck.c (parser_build_binary_op): Don't warn for
+ !!x == y or !b == y where b is _Bool.
+
2015-03-09 Marek Polacek <polacek@redhat.com>
* c-convert.c (convert): Make use of do_ubsan_in_current_function.
diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index 7c6d974..98bff32 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -3460,8 +3460,34 @@ parser_build_binary_op (location_t location, enum tree_code code,
if (warn_logical_not_paren
&& code1 == TRUTH_NOT_EXPR
- && code2 != TRUTH_NOT_EXPR)
- warn_logical_not_parentheses (location, code, arg2.value);
+ && code2 != TRUTH_NOT_EXPR
+ /* Avoid warning for !!x == y. */
+ && (TREE_CODE (arg1.value) != NE_EXPR
+ || !integer_zerop (TREE_OPERAND (arg1.value, 1))))
+ {
+ /* Avoid warning for !b == y where b has _Bool type. */
+ tree t = integer_zero_node;
+ if (TREE_CODE (arg1.value) == EQ_EXPR
+ && integer_zerop (TREE_OPERAND (arg1.value, 1))
+ && TREE_TYPE (TREE_OPERAND (arg1.value, 0)) == integer_type_node)
+ {
+ t = TREE_OPERAND (arg1.value, 0);
+ do
+ {
+ if (TREE_TYPE (t) != integer_type_node)
+ break;
+ if (TREE_CODE (t) == C_MAYBE_CONST_EXPR)
+ t = C_MAYBE_CONST_EXPR_EXPR (t);
+ else if (CONVERT_EXPR_P (t))
+ t = TREE_OPERAND (t, 0);
+ else
+ break;
+ }
+ while (1);
+ }
+ if (TREE_CODE (TREE_TYPE (t)) != BOOLEAN_TYPE)
+ warn_logical_not_parentheses (location, code, arg2.value);
+ }
/* Warn about comparisons against string literals, with the exception
of testing for equality or inequality of a string literal with NULL. */