public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* PATCH to shorten_compare -Wtype-limits handling
@ 2015-11-19  4:26 Jason Merrill
  2015-11-19  4:33 ` David Edelsohn
  2015-11-19 19:44 ` Martin Sebor
  0 siblings, 2 replies; 15+ messages in thread
From: Jason Merrill @ 2015-11-19  4:26 UTC (permalink / raw)
  To: gcc-patches List; +Cc: David Edelsohn, Manuel López-Ibáñez

[-- Attachment #1: Type: text/plain, Size: 423 bytes --]

The rs6000 target was hitting a bootstrap failure due to 
-Werror=type-limits.  Since warn_tautological_cmp and other warnings 
avoid warning if one of the operands comes from a macro, I thought it 
would make sense to do that here as well.

Tested that this allows rs6000 bootstrap to proceed, regression tested 
on x86_64-pc-linux-gnu, applying to trunk.  David, do you want to revert 
the #pragma GCC diagnostic change?

[-- Attachment #2: type-lim.patch --]
[-- Type: text/x-patch, Size: 1206 bytes --]

commit 3d382500ccb766eb1c6dea69a32348d62c86b950
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Nov 18 16:30:06 2015 -0500

    	* c-common.c (shorten_compare): Don't -Wtype-limits if the
    	non-constant operand comes from a macro.

diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index f50ca48..068a0bc 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -4650,7 +4650,9 @@ shorten_compare (location_t loc, tree *op0_ptr, tree *op1_ptr,
 	  type = c_common_unsigned_type (type);
 	}
 
-      if (TREE_CODE (primop0) != INTEGER_CST)
+      if (TREE_CODE (primop0) != INTEGER_CST
+	  /* Don't warn if it's from a macro.  */
+	  && !from_macro_expansion_at (EXPR_LOCATION (primop0)))
 	{
 	  if (val == truthvalue_false_node)
 	    warning_at (loc, OPT_Wtype_limits,
diff --git a/gcc/testsuite/g++.dg/warn/Wtype-limits2.C b/gcc/testsuite/g++.dg/warn/Wtype-limits2.C
new file mode 100644
index 0000000..a46baad
--- /dev/null
+++ b/gcc/testsuite/g++.dg/warn/Wtype-limits2.C
@@ -0,0 +1,11 @@
+// { dg-options -Wtype-limits }
+
+unsigned char array[4];
+bool b;
+#define VAL (b ? array[0] : (unsigned char)0)
+
+int main()
+{
+  if (VAL > 1000)
+    __builtin_abort();
+}

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

end of thread, other threads:[~2015-12-09 18:45 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-11-19  4:26 PATCH to shorten_compare -Wtype-limits handling Jason Merrill
2015-11-19  4:33 ` David Edelsohn
2015-11-19 17:09   ` Jeff Law
2015-11-19 17:49     ` Manuel López-Ibáñez
2015-11-19 17:54       ` Jeff Law
2015-11-19 19:02         ` Manuel López-Ibáñez
2015-11-20 17:42           ` Jeff Law
2015-11-20 18:05             ` Manuel López-Ibáñez
2015-11-20 22:49               ` Jeff Law
2015-12-09 18:45                 ` Manuel López-Ibáñez
2015-11-19 19:44 ` Martin Sebor
2015-11-19 22:16   ` Jason Merrill
2015-11-20 15:51     ` Jason Merrill
2015-11-20 16:10       ` Martin Sebor
2015-11-20 17:20         ` Manuel López-Ibáñez

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).