public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] Quiet down -Wlogical-op a bit (PR c/61534)
@ 2015-04-22 13:56 Marek Polacek
  2015-04-23 14:30 ` Dodji Seketeli
  2015-04-23 22:00 ` Jeff Law
  0 siblings, 2 replies; 3+ messages in thread
From: Marek Polacek @ 2015-04-22 13:56 UTC (permalink / raw)
  To: GCC Patches
  Cc: Dodji Seketeli, Joseph Myers, Manuel López-Ibáñez

This patch stifles -Wlogical-op a bit: don't warn if either operand comes from
a macro expansion.  As the comment says, it doesn't fix the bug completely, but
it's a simple improvement.  I did this by introducing a new macro.

Bootstrapped/regtested on x86_64-linux, ok for trunk?
(Bootstrap with -Wlogical-op enabled does not pass yet.)

2015-04-22  Marek Polacek  <polacek@redhat.com>

	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.

diff --git gcc/c-family/c-common.c gcc/c-family/c-common.c
index 7fe7fa6..b09bbb8 100644
--- gcc/c-family/c-common.c
+++ gcc/c-family/c-common.c
@@ -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
diff --git gcc/input.h gcc/input.h
index 7a0483f..93eb6ed 100644
--- gcc/input.h
+++ gcc/input.h
@@ -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);
 
diff --git gcc/testsuite/c-c++-common/pr61534-1.c gcc/testsuite/c-c++-common/pr61534-1.c
index e69de29..1e304f0 100644
--- gcc/testsuite/c-c++-common/pr61534-1.c
+++ gcc/testsuite/c-c++-common/pr61534-1.c
@@ -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;
+}

	Marek

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Quiet down -Wlogical-op a bit (PR c/61534)
  2015-04-22 13:56 [PATCH] Quiet down -Wlogical-op a bit (PR c/61534) Marek Polacek
@ 2015-04-23 14:30 ` Dodji Seketeli
  2015-04-23 22:00 ` Jeff Law
  1 sibling, 0 replies; 3+ messages in thread
From: Dodji Seketeli @ 2015-04-23 14:30 UTC (permalink / raw)
  To: Marek Polacek
  Cc: GCC Patches, Joseph Myers, Manuel López-Ibáñez

Hi!

Marek Polacek <polacek@redhat.com> writes:

> This patch stifles -Wlogical-op a bit: don't warn if either operand
> comes from a macro expansion.  As the comment says, it doesn't fix the
> bug completely, but it's a simple improvement.

I cannot approve this patch, but for what it's worth, I like it and
would vote for it to go in.

> I did this by introducing a new macro.

Fair enough.

[...]

> Bootstrapped/regtested on x86_64-linux, ok for trunk?

[+1] from me.

Thanks!

-- 
		Dodji

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Quiet down -Wlogical-op a bit (PR c/61534)
  2015-04-22 13:56 [PATCH] Quiet down -Wlogical-op a bit (PR c/61534) Marek Polacek
  2015-04-23 14:30 ` Dodji Seketeli
@ 2015-04-23 22:00 ` Jeff Law
  1 sibling, 0 replies; 3+ messages in thread
From: Jeff Law @ 2015-04-23 22:00 UTC (permalink / raw)
  To: Marek Polacek, GCC Patches
  Cc: Dodji Seketeli, Joseph Myers, Manuel López-Ibáñez

On 04/22/2015 07:56 AM, Marek Polacek wrote:
> This patch stifles -Wlogical-op a bit: don't warn if either operand comes from
> a macro expansion.  As the comment says, it doesn't fix the bug completely, but
> it's a simple improvement.  I did this by introducing a new macro.
>
> Bootstrapped/regtested on x86_64-linux, ok for trunk?
> (Bootstrap with -Wlogical-op enabled does not pass yet.)
>
> 2015-04-22  Marek Polacek  <polacek@redhat.com>
>
> 	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.
OK.
jeff

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-04-23 22:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-22 13:56 [PATCH] Quiet down -Wlogical-op a bit (PR c/61534) Marek Polacek
2015-04-23 14:30 ` Dodji Seketeli
2015-04-23 22:00 ` Jeff Law

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).