From: Jason Merrill Date: Thu, 19 Nov 2015 04:26:48 +0000 (-0500) Subject: c-common.c (shorten_compare): Don't -Wtype-limits if the non-constant operand comes... X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=d0eccfcdc30257a23ce82041a035626350fa421f;p=gcc.git c-common.c (shorten_compare): Don't -Wtype-limits if the non-constant operand comes from a macro. * c-common.c (shorten_compare): Don't -Wtype-limits if the non-constant operand comes from a macro. From-SVN: r230589 --- diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index 9ba2ea0ed4f..5ca75b4dbf0 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,8 @@ +2015-11-18 Jason Merrill + + * c-common.c (shorten_compare): Don't -Wtype-limits if the + non-constant operand comes from a macro. + 2015-11-17 Jason Merrill PR bootstrap/68346 diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index f50ca48f4f2..068a0bcd2ec 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 00000000000..a46baad8397 --- /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(); +}