re PR c/61534 (Wlogical-op should not warn when either operand comes from macro expan...
authorMarek Polacek <polacek@redhat.com>
Fri, 24 Apr 2015 11:49:52 +0000 (11:49 +0000)
committerMarek Polacek <mpolacek@gcc.gnu.org>
Fri, 24 Apr 2015 11:49:52 +0000 (11:49 +0000)
PR c/61534
* input.h (from_macro_expansion_at): Define.

* c-common.c (warn_logical_operator): Bail if either operand comes
from a macro expansion.

* c-c++-common/pr61534-1.c: New test.

From-SVN: r222406

gcc/ChangeLog
gcc/c-family/ChangeLog
gcc/c-family/c-common.c
gcc/input.h
gcc/testsuite/ChangeLog
gcc/testsuite/c-c++-common/pr61534-1.c [new file with mode: 0644]

index b302e363279e9bdc1f8c27f8ae96af166cd54e1a..4bb36799a17935f329174cc9c0e71092cd3b24be 100644 (file)
@@ -1,3 +1,8 @@
+2015-04-24  Marek Polacek  <polacek@redhat.com>
+
+       PR c/61534
+       * input.h (from_macro_expansion_at): Define.
+
 2015-04-24  Thomas Preud'homme  <thomas.preudhomme@arm.com>
 
        * config/arm/unknown-elf.h (ASM_OUTPUT_ALIGNED_DECL_LOCAL): fix
index 337354949ee716e4518161cd334318ffdaf46328..270ef70e84839328d376b664e47c23e2e1f440ad 100644 (file)
@@ -1,3 +1,9 @@
+2015-04-24  Marek Polacek  <polacek@redhat.com>
+
+       PR c/61534
+       * c-common.c (warn_logical_operator): Bail if either operand comes
+       from a macro expansion.
+
 2015-04-10  Bernhard Reutner-Fischer  <aldot@gcc.gnu.org>
 
        PR target/55143
index 7fe7fa6007c03ceb0905a86c270e44060b74f4e2..b09bbb86f6f62ce0158c23b88ad67a3086a57c63 100644 (file)
@@ -1697,6 +1697,13 @@ warn_logical_operator (location_t location, enum tree_code code, tree type,
       && code != TRUTH_OR_EXPR)
     return;
 
+  /* We don't want to warn if either operand comes from a macro
+     expansion.  ??? This doesn't work with e.g. NEGATE_EXPR yet;
+     see PR61534.  */
+  if (from_macro_expansion_at (EXPR_LOCATION (op_left))
+      || from_macro_expansion_at (EXPR_LOCATION (op_right)))
+    return;
+
   /* Warn if &&/|| are being used in a context where it is
      likely that the bitwise equivalent was intended by the
      programmer. That is, an expression such as op && MASK
index 7a0483f730c19ce0da5ccbaf863d6cc67c54bb7c..93eb6ed4c32036c2127eaac04f9a6cf6b4b6a246 100644 (file)
@@ -70,6 +70,10 @@ extern location_t input_location;
    header, but expanded in a non-system file.  */
 #define in_system_header_at(LOC) \
   (linemap_location_in_system_header_p (line_table, LOC))
+/* Return a positive value if LOCATION is the locus of a token that
+   comes from a macro expansion, O otherwise.  */
+#define from_macro_expansion_at(LOC) \
+  ((linemap_location_from_macro_expansion_p (line_table, LOC)))
 
 void dump_line_table_statistics (void);
 
index bbc0b24ef5edbd28d208996b00f4d4291e0e9df3..c493bd83109dc235e19a6da302736e28992ad445 100644 (file)
@@ -1,3 +1,8 @@
+2015-04-24  Marek Polacek  <polacek@redhat.com>
+
+       PR c/61534
+       * c-c++-common/pr61534-1.c: New test.
+
 2015-04-24  Thomas Preud'homme  <thomas.preudhomme@arm.com>
            Steven Bosscher <steven@gcc.gnu.org>
 
diff --git a/gcc/testsuite/c-c++-common/pr61534-1.c b/gcc/testsuite/c-c++-common/pr61534-1.c
new file mode 100644 (file)
index 0000000..1e304f0
--- /dev/null
@@ -0,0 +1,13 @@
+/* PR c/61534 */
+/* { dg-options "-Wlogical-op" } */
+
+extern int xxx;
+#define XXX !xxx
+int
+test (void)
+{
+  if (XXX && xxx) /* { dg-bogus "logical" } */
+    return 4;
+  else
+    return 0;
+}