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: 683825 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 3sz3Bk1pnVz9s3s for ; Wed, 19 Oct 2016 05:14:54 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=xbzhAvTP; 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:mime-version; q=dns; s=default; b=C//RsXoiw65/efw5 VeGxvVKXSRSZ6cq5zujWqtuS8+I32TXRlj1TVz2rMUI+1ZRu5TtclQ/U/RST5b7o pJJIBw6QQwhhIKgQZ1M6/cVY8Bl2c+ONOQL84sGVJwBpz4Cj6grfXgmEw3daNdFq TXM3ED8efGa1q8Ny2MRdUX51Vkg= 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=xbzhAvTP9ksZGZiK2dBUWFsq2zCplQhJEFzSScPiDijodq8U062CDn +uebOuTaY1hhWHFohnjloqjVpz5+m8ogndltSK9cJsGlg0dftW8rYTbRTwJ1AFzP 7vbGLECRQo+sAEU2E0QnioSTgNPLjkIzM1UHhCR+Q2ATUJeo9Fy04= 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; +}