From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 129371 invoked by alias); 5 Sep 2016 14:39:53 -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 129357 invoked by uid 89); 5 Sep 2016 14:39:52 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.9 required=5.0 tests=AWL,BAYES_00,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=ham version=3.3.2 spammy=H*c:Windows-1252, Hx-spam-relays-external:sk:snt004-, H*RU:sk:snt004-, Hx-spam-relays-external:sk:SNT004- X-HELO: SNT004-OMC2S46.hotmail.com Received: from snt004-omc2s46.hotmail.com (HELO SNT004-OMC2S46.hotmail.com) (65.54.61.97) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 05 Sep 2016 14:39:51 +0000 Received: from EUR03-AM5-obe.outbound.protection.outlook.com ([65.55.90.71]) by SNT004-OMC2S46.hotmail.com over TLS secured channel with Microsoft SMTPSVC(7.5.7601.23008); Mon, 5 Sep 2016 07:39:50 -0700 Received: from DB5EUR03FT034.eop-EUR03.prod.protection.outlook.com (10.152.20.56) by DB5EUR03HT005.eop-EUR03.prod.protection.outlook.com (10.152.20.78) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.587.6; Mon, 5 Sep 2016 14:39:48 +0000 Received: from AM4PR0701MB2162.eurprd07.prod.outlook.com (10.152.20.55) by DB5EUR03FT034.mail.protection.outlook.com (10.152.20.87) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.587.6 via Frontend Transport; Mon, 5 Sep 2016 14:39:47 +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.0599.016; Mon, 5 Sep 2016 14:39:47 +0000 From: Bernd Edlinger To: Joseph Myers CC: "gcc-patches@gcc.gnu.org" , Jason Merrill Subject: Re: [PATCHv2] Add a warning for suspicious use of conditional expressions in boolean context Date: Mon, 05 Sep 2016 14:59:00 -0000 Message-ID: References: In-Reply-To: authentication-results: spf=softfail (sender IP is 10.152.20.55) smtp.mailfrom=hotmail.de; codesourcery.com; dkim=none (message not signed) header.d=none;codesourcery.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.20.55 as permitted sender) x-ms-exchange-messagesentrepresentingtype: 1 x-eopattributedmessage: 0 x-forefront-antispam-report: CIP:10.152.20.55;IPV:NLI;CTRY:;EFV:NLI;SFV:NSPM;SFS:(10019020)(98900003);DIR:OUT;SFP:1102;SCL:1;SRVR:DB5EUR03HT005;H:AM4PR0701MB2162.eurprd07.prod.outlook.com;FPR:;SPF:None;LANG:en; x-microsoft-exchange-diagnostics: 1;DB5EUR03HT005;6:9Uc4hJjPh3O74iVcKQ/8eYhNAVOIXBSxh6M5eavgh5GQH1esYkn4fhbwHO1C6ddgc1lxcwmiKcev18NdhZTBOWXhEVH/nnZLkXnClfs46Kob7vfep/dqqO2rVe0DLgwp9nVroeE7ZbW6LWwNmJK4fu4GzEnqyLnbqlHnXUNpivHgD84ntbQ1pLdYBF+ZAJifK8mVaFX0s/gFnxKO9iKYnP7TXznn2xNiafZTm9dCO2z1d+g6uRPj+F+lcoJ4tfFvadDDN8S8lrw3sh3Y+xECdVezYUKURvQBEj2gyBlhhat40BPv5T5290XguEDwSsD+;5:KcpNd3rmq8upX65KtJc4cRZqhK7smUxUAdmGevmHYQjP/Kow5ktVp9LF52Oi22u59ZLyrgZY3s74+xU+GVoUDUYgZTq5TRv3V0WonxIR+Z4dIgt0qshW3EjSOO6iD+f2zddGBTOSr8U4h77Hsoa0aA==;24:ZEr4motJX7lskLZifPSCcvnV82RRul5p776pvwRMMbf7sYcioUNpwu5ZERuN5M45LTJmFMSWfgVe2iljTHElXcRs9vSs4q8NUZKi7uYUmfU=;7:ykREU8At1IYHOsG8G6Y5xGPshikRCm/EKtN/eoq8X7bnMIHvCubW/5OIXxjqh+6JDLLbYgfPvspn7O6gOY2LM65ccifgaJwIdjuW5ul7IZHshOj+4vbpnTq9FkqVHDFWZiZdJoxa0Zl8xBFh/3w8cLyknFA9ELd0dKVREUmz6cmwK3w6YF0GgDONqjUWqsrbaOc85SblJqHukl797Fje+mNKsaTI/84+/DRkqCXBTqGDHwpfClFmg8mTwaskJhDe x-ms-office365-filtering-correlation-id: b7c0615e-ae0d-4c73-0e86-08d3d59a7bac x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(1601124038)(1603103081)(1601125047);SRVR:DB5EUR03HT005; x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(432015012)(82015046);SRVR:DB5EUR03HT005;BCL:0;PCL:0;RULEID:;SRVR:DB5EUR03HT005; x-forefront-prvs: 005671E15D spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="Windows-1252" Content-ID: <6DEBADF15198AA46A2960BB80BC72C86@eurprd07.prod.outlook.com> Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-originalarrivaltime: 05 Sep 2016 14:39:47.7324 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB5EUR03HT005 X-SW-Source: 2016-09/txt/msg00205.txt.bz2 On 09/05/16 13:23, Joseph Myers wrote: > On Sun, 4 Sep 2016, Bernd Edlinger wrote: > >> good to have as well. But this code would still be suspicious >> even if (x << y) is put in parentheses, because the shift count does >> not change the result of the condition, as the integer overflow is >> undefined behavior, and if it does not have side effects or does >> not throw something, it can even be optimized away. > > It's defined in GNU C (when the shift count is nonnegative and less than > the width of the type) - we document that we do not optimize on the basis > of it being undefined (although ubsan will still detect it). > Oh, good to know, thanks for this info. Fortunately this will only be a warning, no optimization. But I think the reasoning is still correct, left shifting in a boolean context is suspicious, even if -fwrapv may make it defined. Do you agree? Bernd.