c-common.c (shorten_compare): Don't -Wtype-limits if the non-constant operand comes...
authorJason Merrill <jason@redhat.com>
Thu, 19 Nov 2015 04:26:48 +0000 (23:26 -0500)
committerJason Merrill <jason@gcc.gnu.org>
Thu, 19 Nov 2015 04:26:48 +0000 (23:26 -0500)
* c-common.c (shorten_compare): Don't -Wtype-limits if the
non-constant operand comes from a macro.

From-SVN: r230589

gcc/c-family/ChangeLog
gcc/c-family/c-common.c
gcc/testsuite/g++.dg/warn/Wtype-limits2.C [new file with mode: 0644]

index 9ba2ea0ed4f2b85456654ed86fadc5df84ee799e..5ca75b4dbf00cededd675350a9bbca03d34425c2 100644 (file)
@@ -1,3 +1,8 @@
+2015-11-18  Jason Merrill  <jason@redhat.com>
+
+       * c-common.c (shorten_compare): Don't -Wtype-limits if the
+       non-constant operand comes from a macro.
+
 2015-11-17  Jason Merrill  <jason@redhat.com>
 
        PR bootstrap/68346
index f50ca48f4f2cd4bb047cb9c7152d947e37ad9956..068a0bcd2ec02c107fb45df631879a9dbf12b538 100644 (file)
@@ -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 (file)
index 0000000..a46baad
--- /dev/null
@@ -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();
+}