From patchwork Tue Oct 18 18:14:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bernd Edlinger X-Patchwork-Id: 78116 Delivered-To: patch@linaro.org Received: by 10.140.97.247 with SMTP id m110csp1014007qge; Tue, 18 Oct 2016 11:14:59 -0700 (PDT) X-Received: by 10.98.82.75 with SMTP id g72mr2920682pfb.119.1476814499167; Tue, 18 Oct 2016 11:14:59 -0700 (PDT) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id xy9si8603591pab.170.2016.10.18.11.14.58 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 18 Oct 2016 11:14:59 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-return-438949-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-438949-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-438949-patch=linaro.org@gcc.gnu.org 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:mime-version; q=dns; s=default; b=sdDgkUrW3li7GDa7 C7HK1AGn2YDw7LyaYvb8vruVgLGo7MguBYqPci40JUFB+i4XHMHPawXUtWgNcl6Z /+McYFOMg6sFcquKqab3qoh7+L0hZAj+5fED6Qg1c65bWg40PnQPDidNFZU6MsiR MRKNY+V470rfpOgVog0RmcHLitI= 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:mime-version; s=default; bh=t+G6aYv5GhcfhYcLhKmZie lOq10=; b=aTk584Lq+lBIPrCOuPfZlydA5487pbe1CsLbL0I+qqsArj1eH26+fB EAUNt2N3Ay1y84wekMXl2tBSDpE/Xg5SxL+Xnxt8ALLT2TizqkbURftthosVlzWi 8FbIM1k5OWAEndcoxTzdSq2TfrW30jPukNHFP84WAoH5J59Pqx9Q4= Received: (qmail 46336 invoked by alias); 18 Oct 2016 18:14: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 46274 invoked by uid 89); 18 Oct 2016 18:14:41 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.2 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=no version=3.3.2 spammy=dg-warning, dgwarning, reg-tested, H*c:HHH X-HELO: BAY004-OMC1S17.hotmail.com Received: from bay004-omc1s17.hotmail.com (HELO BAY004-OMC1S17.hotmail.com) (65.54.190.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 18 Oct 2016 18:14:31 +0000 Received: from EUR01-VE1-obe.outbound.protection.outlook.com ([65.54.190.59]) by BAY004-OMC1S17.hotmail.com over TLS secured channel with Microsoft SMTPSVC(7.5.7601.23008); Tue, 18 Oct 2016 11:14:25 -0700 Received: from HE1EUR01FT015.eop-EUR01.prod.protection.outlook.com (10.152.0.59) by HE1EUR01HT116.eop-EUR01.prod.protection.outlook.com (10.152.1.69) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.7; Tue, 18 Oct 2016 18:14:23 +0000 Received: from AM4PR0701MB2162.eurprd07.prod.outlook.com (10.152.0.56) by HE1EUR01FT015.mail.protection.outlook.com (10.152.0.154) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.669.7 via Frontend Transport; Tue, 18 Oct 2016 18:14:23 +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.0679.006; Tue, 18 Oct 2016 18:14:23 +0000 From: Bernd Edlinger To: Joseph Myers CC: Markus Trippelsdorf , Jason Merrill , Florian Weimer , "gcc-patches@gcc.gnu.org" , Jeff Law Subject: Re: [PATCH] Make -Wint-in-bool-context warn on suspicious shift ops Date: Tue, 18 Oct 2016 18:14:22 +0000 Message-ID: References: <87fuol77ri.fsf@mid.deneb.enyo.de> <20161017152304.GA303@x4> <20161017171124.GB303@x4> In-Reply-To: authentication-results: codesourcery.com; dkim=none (message not signed) header.d=none; codesourcery.com; dmarc=none action=none header.from=hotmail.de; x-ms-exchange-messagesentrepresentingtype: 1 x-eopattributedmessage: 0 x-microsoft-exchange-diagnostics: 1; HE1EUR01HT116; 6:xTklpuzP/aOUKKToxf+RmEXb8hFSzMdyGqCpGX/inBIeh6IqhLO2wZjKqkz5WbAuTgNVWN4rzqc3qN9hQrWSGu+6JMPYDam/hQCvJ0HPxmD13qiQnSYdwlFkmWAUw5mfmtYtFv7hBZ67rEapE9gkkrqUtPOM/M98/56UJrqwb5ur2mCU5eQA7NzO6mmzatbfA3NfQHWYo73w2G4yyc1fsFa/fwdPR72oq8kq2T/CGZlNRJXnzCzldN228g66D7TErsnGJRLrbMRiAXNIfpzBYBqESvL1Sk5LCekORWmeeRfxTTco6qlepmyeAhCCnUsW; 5:bVGPD3W6VRxYXQ8ztvOKA47nrAZ3kuMFuSoZoEYVvLbQg/5ycM+g8l4ke3rT9Jag+qBDP5ckiY2Ok/lT1Ug/CgWLllcTTl46/SG3pzkVnJQarUvHKr0oVM7e4qRNKKbtVOBdVvBJu6DPEQWzcSj1yw==; 24:DP75doLeKBLAr9taQ2iwyKEtjjyzhmWgmyBNn4eN/a5lukG8fLA8I/A8D1K+942cvSn26fphz4l3Y+S4vE9i7k4VvCA1pMRFXuFl8jgiDOU=; 7:FAJ8PTZsFm/mnIx0rqtpdZd1JJHusQZbdcUKAq4fHXzi6k2zMYiMshqEVQA6bzS5Zg9r7lzjx/ADfkjWjsj+EGjfxc+Z3RbUsK1TcQ/El4iiNGFBc5RdyjaMGqd7zr1/eXTUqqXU+P1tu5jCzWsyGVYWwsvQomgb3x7C+BK/lmVo/yU6D6AKqFJIoS+Q3J/XEwypHXR3q+zovJwoMZnPo/EAAS2fkVQtkk0tGM9pYcktbMdWG95Ov45Zo+ToLObbJ0ba4HFOpYDFbMPq7kfGh+tUnr4LOj4kP96CE+trmmlzXtsNs5knMv0FPN4SNrg5xmP/oH790r53eu04efbqt7Xoh40mUMF8ANBKlR3qFNg= x-forefront-antispam-report: EFV:NLI; SFV:NSPM; SFS:(10019020)(98900003); DIR:OUT; SFP:1102; SCL:1; SRVR:HE1EUR01HT116; H:AM4PR0701MB2162.eurprd07.prod.outlook.com; FPR:; SPF:None; LANG:en; x-ms-office365-filtering-correlation-id: e8538608-4ae9-499f-f8dc-08d3f7829597 x-microsoft-antispam: UriScan:; BCL:0; PCL:0; RULEID:(1601124038)(1603103081)(1601125047); SRVR:HE1EUR01HT116; x-exchange-antispam-report-cfa-test: BCL:0; PCL:0; RULEID:(432015012)(102415321)(82015046); SRVR:HE1EUR01HT116; BCL:0; PCL:0; RULEID:; SRVR:HE1EUR01HT116; x-forefront-prvs: 00997889E7 spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM MIME-Version: 1.0 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Oct 2016 18:14:22.9096 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: HE1EUR01HT116 On 10/18/16 19:05, Joseph Myers wrote: > On Tue, 18 Oct 2016, Bernd Edlinger wrote: > >> Hi, >> >> this restricts the -Wint-in-bool-context warning to signed shifts, >> to reduce the number of false positives Markus reported yesterday. > > This patch seems to be missing testcases (that warned before the patch > and don't warn after it). > Yes of course. New patch, this time with a test case, compiled from the linux sample. Bootstrapped and reg-tested as usual. Is it OK for trunk? Bernd. c-family: 2016-10-17 Bernd Edlinger * c-common.c (c_common_truthvalue_conversion): Warn only for signed integer shift ops in boolean context. testsuite: 2016-10-17 Bernd Edlinger * c-c++-common/Wint-in-bool-context-2.c: New test. Index: gcc/c-family/c-common.c =================================================================== --- gcc/c-family/c-common.c (revision 241270) +++ gcc/c-family/c-common.c (working copy) @@ -3328,8 +3328,10 @@ TREE_OPERAND (expr, 0)); case LSHIFT_EXPR: - warning_at (EXPR_LOCATION (expr), OPT_Wint_in_bool_context, - "<< in boolean context, did you mean '<' ?"); + if (TREE_CODE (TREE_TYPE (expr)) == INTEGER_TYPE + && !TYPE_UNSIGNED (TREE_TYPE (expr))) + warning_at (EXPR_LOCATION (expr), OPT_Wint_in_bool_context, + "<< in boolean context, did you mean '<' ?"); break; case COND_EXPR: Index: gcc/testsuite/c-c++-common/Wint-in-bool-context-2.c =================================================================== --- gcc/testsuite/c-c++-common/Wint-in-bool-context-2.c (revision 0) +++ gcc/testsuite/c-c++-common/Wint-in-bool-context-2.c (working copy) @@ -0,0 +1,17 @@ +/* { dg-options "-Wint-in-bool-context" } */ +/* { dg-do compile } */ + +typedef unsigned u32; +typedef unsigned char u8; +#define KEYLENGTH 8 + +int foo (u8 plen, u32 key) +{ + if ((plen < KEYLENGTH) && (key << plen)) /* { dg-bogus "boolean context" } */ + return -1; + + if ((plen << KEYLENGTH) && (key < plen)) /* { dg-warning "boolean context" } */ + return -2; + + return 0; +}