From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 34735 invoked by alias); 12 Sep 2016 21:13:32 -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 34718 invoked by uid 89); 12 Sep 2016 21:13:31 -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=Hx-spam-relays-external:sk:blu004-, HX-HELO:sk:BLU004-, H*RU:sk:blu004-, Hx-spam-relays-external:sk:BLU004- X-HELO: BLU004-OMC4S20.hotmail.com Received: from blu004-omc4s20.hotmail.com (HELO BLU004-OMC4S20.hotmail.com) (65.55.111.159) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 12 Sep 2016 21:13:21 +0000 Received: from EUR01-VE1-obe.outbound.protection.outlook.com ([65.55.111.135]) by BLU004-OMC4S20.hotmail.com over TLS secured channel with Microsoft SMTPSVC(7.5.7601.23008); Mon, 12 Sep 2016 14:13:19 -0700 Received: from VE1EUR01FT051.eop-EUR01.prod.protection.outlook.com (10.152.2.60) by VE1EUR01HT190.eop-EUR01.prod.protection.outlook.com (10.152.3.229) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.619.6; Mon, 12 Sep 2016 21:13:12 +0000 Received: from AM4PR0701MB2162.eurprd07.prod.outlook.com (10.152.2.52) by VE1EUR01FT051.mail.protection.outlook.com (10.152.3.8) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.619.6 via Frontend Transport; Mon, 12 Sep 2016 21:13:12 +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.0619.011; Mon, 12 Sep 2016 21:13:12 +0000 From: Bernd Edlinger To: Jeff Law , "gcc-patches@gcc.gnu.org" , Joseph Myers , "Jason Merrill" Subject: Re: [PATCH] Add a warning for suspicious use of conditional expressions in boolean context Date: Mon, 12 Sep 2016 21:28:00 -0000 Message-ID: References: <4fd68972-b48b-560a-b8e2-ae7d607b9b87@redhat.com> <48602fe1-c295-fce5-a6fe-e7e259532f44@redhat.com> In-Reply-To: <48602fe1-c295-fce5-a6fe-e7e259532f44@redhat.com> authentication-results: spf=softfail (sender IP is 10.152.2.52) 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.2.52 as permitted sender) x-ms-exchange-messagesentrepresentingtype: 1 x-eopattributedmessage: 0 x-forefront-antispam-report: CIP:10.152.2.52;IPV:NLI;CTRY:;EFV:NLI;SFV:NSPM;SFS:(10019020)(98900003);DIR:OUT;SFP:1102;SCL:1;SRVR:VE1EUR01HT190;H:AM4PR0701MB2162.eurprd07.prod.outlook.com;FPR:;SPF:None;LANG:en; x-microsoft-exchange-diagnostics: 1;VE1EUR01HT190;6:+NFn0+V82TQBLk1w1wIvS5kqiwpTnpFZqo6L0LcrZi4UWUSE9uwAAexGKFk4/71dyMIS2DBbAnM9m8Pi2F6rpAMQ92fPt2CsBhMNdsPtlXIn6vWJt7O05fMUadqyknmZk38DcOqxRTKpsTgbxn6f4Y/ZqwYFhLnZWRPIIjZ2oEWwXkHvy+FGFTHWOlP5dwOQ/WgmACO/QWVGPKCiL02RDY6nFche8Eq1TZc0j1DMcP6fqdES+4Pa2Dj/BKOyRugYbtUiX2NP2JfPMGU/L7AfTZ0+g612io6j+KGSbIIgcr03U0EXlSJ+URIYo/h2YhS4;5:ACWBITaRD/P0o8BoJW0NmFxfL+tojpRtUs4nkJQxAO+z/xhHHUlxNJ/AVrGszxKBVQQKO0gJytdVLHhr2xVta1H7sZ/4A1w0AXvrSTDeKaQZaKAAjxfL4h+PDgSZVSenrlHTQhi5bIOVBI+afLD1Ew==;24:Ul2JXSZqMiz8uanAPG8Nweky7lZRXN96XydpRtagymKrQ0bhtjCB+IdtcR9C+XUQC0z+stdTEXHQu5vWjvBdN8DGzgH/eCLYmk4cpKT/x9s=;7:Q7lBFTrXEy3r7Eq7ZUtgzr1UFDEP0BS1prx4CCCLme4iShybpofnPwOcmmo82QFOCN83+Ia38qqvaH3ffP7B8QmJOXaRKqQASQt1jaF8U8i0HGoQnlsk97oQPZiL6ICscqc0q00wM9j28rQlgYaUwCi6uL71aAqFWBHBYAlhlh5CKmH+p3SLE5jsysd4wxdwcqanDy68tDxwmOmy2N6+mJe06jNli2jQ4GR0CWAmbnja04xCA6NPr57If1+LkAb7 x-ms-office365-filtering-correlation-id: e3232097-c686-4fa7-92aa-08d3db5199ec x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(1601124038)(1603103081)(1601125047);SRVR:VE1EUR01HT190; x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(432015012)(82015046);SRVR:VE1EUR01HT190;BCL:0;PCL:0;RULEID:;SRVR:VE1EUR01HT190; x-forefront-prvs: 006339698F spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="Windows-1252" Content-ID: <081FD242D8A9C64691F890AA5EDC6895@eurprd07.prod.outlook.com> Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-originalarrivaltime: 12 Sep 2016 21:13:12.3384 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1EUR01HT190 X-SW-Source: 2016-09/txt/msg00673.txt.bz2 On 09/12/16 22:08, Jeff Law wrote: > On 09/12/2016 02:00 PM, Bernd Edlinger wrote: > >> Yes, I will update the patch accordingly. >> >> I agree, a statement like "if (x ? 0 : 2)" can be called suspicious as >> well, even if the result of x is not ignored as in "if (x ? 1 : 2)". >> >> After I posted this patch, I extended the patch to cover also >> suspicious int shift-left operations, at >> https://gcc.gnu.org/ml/gcc-patches/2016-09/msg00155.html >> [PATCHv2] Add a warning for suspicious use of conditional expressions in >> boolean context >> >> Therefore, I would like to rename the warning to -Wint-in-bool-context >> so that the other patch can extend that instead of creating even more >> warning names with much longer names. >> >> >> Is renaming the warning OK as well, or could you have a look at the >> follow-up patch please? > Renaming is OK as well. > Hmm, well. There is a problem. If I change the warning to warn if either of the integer constants is not [0|1] the boot-strap fails here: ./../gcc-trunk/gcc/gensupport.c: In function 'void=20 compute_test_codes(rtx, file_location, char*)': ../../gcc-trunk/gcc/gensupport.c:202:25: error: ?: using integer=20 constants in boolean context [-Werror=3Dint-in-bool-context] ((a) =3D=3D I ? ((b) =3D=3D N ? N : I) : \ ~~~~~~~~~~^~~~~~~~ ../../gcc-trunk/gcc/gensupport.c:209:5: note: in definition of macro=20 'TRISTATE_OR' (a) || (b)) ^ ../../gcc-trunk/gcc/gensupport.c:256:26: note: in expansion of macro=20 'TRISTATE_AND' codes[i] =3D TRISTATE_OR (TRISTATE_AND (op0_codes[i], op1_codes[i]), ^~~~~~~~~~~~ ../../gcc-trunk/gcc/gensupport.c:203:25: error: ?: using integer=20 constants in boolean context [-Werror=3Dint-in-bool-context] (b) =3D=3D I ? ((a) =3D=3D N ? N : I) : \ ~~~~~~~~~~^~~~~~~~ ../../gcc-trunk/gcc/gensupport.c:209:5: note: in definition of macro=20 'TRISTATE_OR' (a) || (b)) ^ ../../gcc-trunk/gcc/gensupport.c:256:26: note: in expansion of macro=20 'TRISTATE_AND' codes[i] =3D TRISTATE_OR (TRISTATE_AND (op0_codes[i], op1_codes[i]), ^~~~~~~~~~~~ ../../gcc-trunk/gcc/gensupport.c:202:25: error: ?: using integer=20 constants in boolean context [-Werror=3Dint-in-bool-context] ((a) =3D=3D I ? ((b) =3D=3D N ? N : I) : \ ~~~~~~~~~~^~~~~~~~ ../../gcc-trunk/gcc/gensupport.c:209:5: note: in definition of macro=20 'TRISTATE_OR' (a) || (b)) ^ ../../gcc-trunk/gcc/gensupport.c:256:26: note: in expansion of macro=20 'TRISTATE_AND' codes[i] =3D TRISTATE_OR (TRISTATE_AND (op0_codes[i], op1_codes[i]), ^~~~~~~~~~~~ ../../gcc-trunk/gcc/gensupport.c:203:25: error: ?: using integer=20 constants in boolean context [-Werror=3Dint-in-bool-context] (b) =3D=3D I ? ((a) =3D=3D N ? N : I) : \ ~~~~~~~~~~^~~~~~~~ ../../gcc-trunk/gcc/gensupport.c:209:5: note: in definition of macro=20 'TRISTATE_OR' (a) || (b)) ^ ../../gcc-trunk/gcc/gensupport.c:256:26: note: in expansion of macro=20 'TRISTATE_AND' codes[i] =3D TRISTATE_OR (TRISTATE_AND (op0_codes[i], op1_codes[i]), ^~~~~~~~~~~~ ../../gcc-trunk/gcc/gensupport.c:202:25: error: ?: using integer=20 constants in boolean context [-Werror=3Dint-in-bool-context] ((a) =3D=3D I ? ((b) =3D=3D N ? N : I) : \ ~~~~~~~~~~^~~~~~~~ ../../gcc-trunk/gcc/gensupport.c:209:12: note: in definition of macro=20 'TRISTATE_OR' (a) || (b)) ^ ../../gcc-trunk/gcc/gensupport.c:257:5: note: in expansion of macro=20 'TRISTATE_AND' TRISTATE_AND (TRISTATE_NOT (op0_codes[i]), ^~~~~~~~~~~~ ../../gcc-trunk/gcc/gensupport.c:203:25: error: ?: using integer=20 constants in boolean context [-Werror=3Dint-in-bool-context] (b) =3D=3D I ? ((a) =3D=3D N ? N : I) : \ ~~~~~~~~~~^~~~~~~~ ../../gcc-trunk/gcc/gensupport.c:209:12: note: in definition of macro=20 'TRISTATE_OR' (a) || (b)) ^ ../../gcc-trunk/gcc/gensupport.c:257:5: note: in expansion of macro=20 'TRISTATE_AND' TRISTATE_AND (TRISTATE_NOT (op0_codes[i]), ^~~~~~~~~~~~ ../../gcc-trunk/gcc/gensupport.c:202:25: error: ?: using integer=20 constants in boolean context [-Werror=3Dint-in-bool-context] ((a) =3D=3D I ? ((b) =3D=3D N ? N : I) : \ ~~~~~~~~~~^~~~~~~~ ../../gcc-trunk/gcc/gensupport.c:209:12: note: in definition of macro=20 'TRISTATE_OR' (a) || (b)) ^ ../../gcc-trunk/gcc/gensupport.c:257:5: note: in expansion of macro=20 'TRISTATE_AND' TRISTATE_AND (TRISTATE_NOT (op0_codes[i]), ^~~~~~~~~~~~ ../../gcc-trunk/gcc/gensupport.c:203:25: error: ?: using integer=20 constants in boolean context [-Werror=3Dint-in-bool-context] (b) =3D=3D I ? ((a) =3D=3D N ? N : I) : \ ~~~~~~~~~~^~~~~~~~ ../../gcc-trunk/gcc/gensupport.c:209:12: note: in definition of macro=20 'TRISTATE_OR' (a) || (b)) ^ ../../gcc-trunk/gcc/gensupport.c:257:5: note: in expansion of macro=20 'TRISTATE_AND' TRISTATE_AND (TRISTATE_NOT (op0_codes[i]), ^~~~~~~~~~~~ cc1plus: all warnings being treated as errors I had not seen that with the un-symmetric version of the warning. But that is of course possible because it warns on a few more cases than before. At first sight that code looks bogus. But I think it could fix the warning: Index: gensupport.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- gensupport.c (revision 240097) +++ gensupport.c (working copy) @@ -201,15 +201,15 @@ #define TRISTATE_AND(a,b) \ ((a) =3D=3D I ? ((b) =3D=3D N ? N : I) : \ (b) =3D=3D I ? ((a) =3D=3D N ? N : I) : \ - (a) && (b)) + (a) =3D=3D Y && (b) =3D=3D Y ? Y : N) #define TRISTATE_OR(a,b) \ ((a) =3D=3D I ? ((b) =3D=3D Y ? Y : I) : \ (b) =3D=3D I ? ((a) =3D=3D Y ? Y : I) : \ - (a) || (b)) + (a) =3D=3D Y || (b) =3D=3D Y ? Y : N) #define TRISTATE_NOT(a) \ - ((a) =3D=3D I ? I : !(a)) + ((a) =3D=3D I ? I : (a) =3D=3D Y ? N : Y) /* 0 means no warning about that code yet, 1 means warned. */ static char did_you_mean_codes[NUM_RTX_CODE]; I think the warning is justified on code like that, what do you think? Bernd.