From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 16425 invoked by alias); 19 Nov 2015 04:26:45 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 16328 invoked by uid 89); 19 Nov 2015 04:26:36 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-3.7 required=5.0 tests=AWL,BAYES_00,RP_MATCHES_RCVD,SPF_HELO_PASS autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Thu, 19 Nov 2015 04:26:35 +0000 Received: from int-mx13.intmail.prod.int.phx2.redhat.com (int-mx13.intmail.prod.int.phx2.redhat.com [10.5.11.26]) by mx1.redhat.com (Postfix) with ESMTPS id F05E796E3; Thu, 19 Nov 2015 04:26:32 +0000 (UTC) Received: from [10.10.116.26] (ovpn-116-26.rdu2.redhat.com [10.10.116.26]) by int-mx13.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id tAJ4QWW0029241; Wed, 18 Nov 2015 23:26:32 -0500 X-Mozilla-News-Host: news://news.gmane.org:119 To: gcc-patches List Cc: David Edelsohn , =?UTF-8?B?TWFudWVsIEzDs3Blei1JYsOh?= =?UTF-8?Q?=c3=b1ez?= From: Jason Merrill Subject: PATCH to shorten_compare -Wtype-limits handling Message-ID: <564D4F77.3010005@redhat.com> Date: Thu, 19 Nov 2015 04:26:00 -0000 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="------------060103030303020803030703" X-SW-Source: 2015-11/txt/msg02305.txt.bz2 This is a multi-part message in MIME format. --------------060103030303020803030703 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-length: 423 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? --------------060103030303020803030703 Content-Type: text/x-patch; name="type-lim.patch" Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename="type-lim.patch" Content-length: 1206 commit 3d382500ccb766eb1c6dea69a32348d62c86b950 Author: Jason Merrill 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(); +} --------------060103030303020803030703--