From patchwork Wed Sep 21 19:25:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Edlinger X-Patchwork-Id: 673023 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3sfV393TbFz9sQw for ; Thu, 22 Sep 2016 05:25:56 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=nPCweEok; dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:references:in-reply-to :content-type:content-id:content-transfer-encoding:mime-version; q=dns; s=default; b=qZwTU78GUI3ycsgb3ZO/Weabco+Jps4Llf+OQdoXLhJ /V3sqAiV16kISdDyMdCDTWVpOJG+yrMTggJ5qE0EcSYrMtzIOz7CgsC/Byb7uD35 HSVizTms6w634px5wuXdTAEolcGzw2Sp5DJ15AsbbcyHWbx6T89EPyz3NPxFagHU = DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:from :to:cc:subject:date:message-id:references:in-reply-to :content-type:content-id:content-transfer-encoding:mime-version; s=default; bh=W3ACe3rTw7GqVVg3q3VdICnivaI=; b=nPCweEokcO2zz3rT9 CJi2TnYwCZWeUIMPq0dmTTPGFFnDsAaFCJsvidULcc8QtgwY/9nwFXrYkacR/K8v LM64yxawOLOcV7qEUevI1d3hpcRzACXs4bZ0a5UlydA+/uZlODjf5f+sv+S1jSUt aDCl0cfvC4xaQe0eP5XJ/1/Bdk= Received: (qmail 57637 invoked by alias); 21 Sep 2016 19:25:45 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 56806 invoked by uid 89); 21 Sep 2016 19:25:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.5 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_LOW, SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:1632, xxx X-HELO: BLU004-OMC2S24.hotmail.com Received: from blu004-omc2s24.hotmail.com (HELO BLU004-OMC2S24.hotmail.com) (65.55.111.99) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 21 Sep 2016 19:25:34 +0000 Received: from EUR03-AM5-obe.outbound.protection.outlook.com ([65.55.111.72]) by BLU004-OMC2S24.hotmail.com over TLS secured channel with Microsoft SMTPSVC(7.5.7601.23008); Wed, 21 Sep 2016 12:25:32 -0700 Received: from VE1EUR03FT045.eop-EUR03.prod.protection.outlook.com (10.152.18.55) by VE1EUR03HT061.eop-EUR03.prod.protection.outlook.com (10.152.19.162) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.629.5; Wed, 21 Sep 2016 19:25:31 +0000 Received: from AM4PR0701MB2162.eurprd07.prod.outlook.com (10.152.18.56) by VE1EUR03FT045.mail.protection.outlook.com (10.152.19.51) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.629.5 via Frontend Transport; Wed, 21 Sep 2016 19:25:30 +0000 Received: from AM4PR0701MB2162.eurprd07.prod.outlook.com ([10.167.132.147]) by AM4PR0701MB2162.eurprd07.prod.outlook.com ([10.167.132.147]) with mapi id 15.01.0629.006; Wed, 21 Sep 2016 19:25:30 +0000 From: Bernd Edlinger To: Jason Merrill CC: Kyrill Tkachov , Jeff Law , GCC Patches , Joseph Myers Subject: Re: [PATCHv3, resent] Add a warning for suspicious use of conditional expressions in boolean context Date: Wed, 21 Sep 2016 19:25:30 +0000 Message-ID: References: <8ef95068-7826-ab09-6c22-12dd381aa808@redhat.com> <57E11D80.9080409@foss.arm.com> In-Reply-To: authentication-results: spf=softfail (sender IP is 10.152.18.56) smtp.mailfrom=hotmail.de; redhat.com; dkim=none (message not signed) header.d=none; redhat.com; dmarc=none action=none header.from=hotmail.de; received-spf: SoftFail (protection.outlook.com: domain of transitioning hotmail.de discourages use of 10.152.18.56 as permitted sender) x-ms-exchange-messagesentrepresentingtype: 1 x-eopattributedmessage: 0 x-microsoft-exchange-diagnostics: 1; VE1EUR03HT061; 6:UQBro8myUj+OCsPnjb5XDrmVmBqZnK/sgmGCw/nQ6zqECiaaU/neC4J8m47OxP6oEXPC7dJ0Cc3OlV0Ig+nP5nMTDxosJIl/QJQpCLH/wsPVc9z1jMtmXp7ajBRiUUBS5/zFlvg851dSjbk/wE2o2FcUnRncoP3DKTsgke/s3jCh/CXAuFIjxF6/TF8pyndPSr7gQg0ngWUh9ZSFZ3UtGkYwkN057EgxN5LcxDP934p55AFPtIuitJZaw6n+DUiUnZB8cFYNoAEvc/mHZe9SBEVKwVUrjm2TG51BuuHNJPQ=; 5:K7lOVR8np/lhMgAI2APyZvQwsG3e19Mr7i/G29oOFwY/7La/U8mAEDsueFNfyl4sKPiKs0rqDvWNg4jjfWJPnHn2b3fJYnyBSS0bzoqaXnVYMVfb3lYB/kDts1mG3LTfncupRNudn7ahz/31GopFeg==; 24:gnHe15MNzulI9ohXag6z1JL7aHS86PVs/iBU99LatgksYetYMrOo+atXHj3r6KHla8DybmmS6tZPuR57NtuzybU4Z5WfZ1RPsjwQJgS9xp8=; 7:1eOupvrAu7G0rRA/WzOK6AKbBZvcJyKQNEGOCm8KFSw5wS5LgaUh3UnRj1fr5GNWIwtrwGA1SZFpv0DQnaHPGx6q5h0YA8JCKI49+7gJLvj6b99v87QpTYlpQvy5sS2G+VsCd9+l1VNyNyBGlU540oCiSmaXKexPxnCBf+r4ncySPSPMWYUhddRQNyBgXi5Sakwy00pRzotnQHCAeS7/l61rYK6NGhpE4gr+gokABrccXIWkNVfep09Umq11jgjaw4wr55Ob6zM6JSgvGv/RLU8p+9x3icLu9AWdWSOXI1pR07we4+GqdTcvKa/aT1zj x-forefront-antispam-report: EFV:NLI; SFV:NSPM; SFS:(10019020)(98900003); DIR:OUT; SFP:1102; SCL:1; SRVR:VE1EUR03HT061; H:AM4PR0701MB2162.eurprd07.prod.outlook.com; FPR:; SPF:None; LANG:en; x-ms-office365-filtering-correlation-id: b3759567-4e1e-4000-6623-08d3e2550c2c x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(1601124038)(1603103081)(1601125047); SRVR:VE1EUR03HT061; x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(432015012)(82015046); SRVR:VE1EUR03HT061; BCL:0; PCL:0; RULEID:; SRVR:VE1EUR03HT061; x-forefront-prvs: 007271867D spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-ID: MIME-Version: 1.0 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Sep 2016 19:25:30.8077 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1EUR03HT061 On 09/21/16 21:03, Jason Merrill wrote: > On Wed, Sep 21, 2016 at 11:43 AM, Bernd Edlinger > wrote: >> Yes. I think that goes in the right direction, >> but it does not work yet. >> >> #define XXX (a ? 2 : 3) >> >> if (XXX) // prints a warning, but it should not. > > Indeed, that was too simplistic. This patch adds a > from_macro_definition_at test that ought to do what you want: > I tried something similar, which seems to work: I will try your patch now, and see if it works for me. Thanks Bernd. --- input.h (Revision 240313) +++ input.h (Arbeitskopie) @@ -73,10 +73,19 @@ 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))) +/* Return TRUE if LOCATION is the locus of a token that + comes from a macro expansion, FALSE otherwise. */ +static inline bool +from_macro_expansion_at (location_t loc) +{ + /* Resolve to the spelling location so we return false for arguments to a + macro. */ + return linemap_location_from_macro_expansion_p (line_table, loc) + && linemap_resolve_location (line_table, loc, + LRK_MACRO_DEFINITION_LOCATION, NULL) + == linemap_resolve_location (line_table, loc, + LRK_SPELLING_LOCATION, NULL); +} static inline location_t get_pure_location (location_t loc)