From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753416AbcIUFEd (ORCPT ); Wed, 21 Sep 2016 01:04:33 -0400 Received: from mail3-relais-sop.national.inria.fr ([192.134.164.104]:23206 "EHLO mail3-relais-sop.national.inria.fr" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750868AbcIUFEb (ORCPT ); Wed, 21 Sep 2016 01:04:31 -0400 X-IronPort-AV: E=Sophos;i="5.30,372,1470693600"; d="scan'208";a="194116252" Date: Wed, 21 Sep 2016 07:04:28 +0200 (CEST) From: Julia Lawall X-X-Sender: jll@hadrien To: Joe Perches cc: Dan Carpenter , LKML Subject: Re: Possible code defects: macros and precedence In-Reply-To: <1474415234.1954.62.camel@perches.com> Message-ID: References: <1472927739.5018.13.camel@perches.com> <1473001581.5018.37.camel@perches.com> <1474147658.1954.1.camel@perches.com> <1474191110.1954.16.camel@perches.com> <1474415234.1954.62.camel@perches.com> User-Agent: Alpine 2.10 (DEB 1266 2009-07-14) MIME-Version: 1.0 Content-Type: MULTIPART/MIXED; BOUNDARY="8323329-1441714774-1474434269=:3346" Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This message is in MIME format. The first part should be readable text, while the remaining parts are likely unreadable without MIME-aware tools. --8323329-1441714774-1474434269=:3346 Content-Type: TEXT/PLAIN; charset=ISO-8859-1 Content-Transfer-Encoding: 8BIT On Tue, 20 Sep 2016, Joe Perches wrote: > On Tue, 2016-09-20 at 15:14 +0200, Julia Lawall wrote: > > The semantic patch below finds a binary operator in a macro and a binary > > operator in the use of the macro, and checks if the priority of the > > operator in the macro is higher (lower number) than the priority of the > > operator in the use.  If this is the case, it adds parentheses in the use, > > which is not what one wants, but serves to show where the problem is. > > > > It doesn't turn up anything, except an occurrence of (u32)-1, which > > Coccinelle parses as a subtraction, due to not having any nearby evidence > > that u32 is a type. > > > > I didn't make any special effort on the include files, which means that > > only local include files and ones with the same name as the C file are > > taken into account.  I can try with more aggressive include options. > > > > This only works with the github version of Coccinelle, as it required > > quite a lot of improvement to the treatmern of #define. > > > > julia > > > > @initialize:ocaml@ > > @@ > > > > let binoptbl = > >     [("*",3);("/",3);("%",3); > > Shouldn't bitwise negation (~) and not (!) be added at 3? > > ("~",3);("!",3); My semantic patch only covers binary operators at the moment, so I didn't put the complete table. I can extend it. julia >   > >       ("+",4);("-",4); > >       ("<<",5);(">>",5); > >       ("<",6);(">",6);("<=",6);(">=",6); > >       ("==",7);("!=",7); > >       ("&",8); > >       ("^",9); > >       ("|",10); > >       ("&&",11); > >       ("||",12)] > > > > @r@ > > identifier i,j; > > identifier list[n] is; > > binary operator b; > > expression e; > > @@ > > > > #define i(is,j,...) (<+... \(j b e \| e b j\) ...+>) > > > > @s@ > > identifier r.i; > > expression list[r.n] es; > > binary operator b1; > > expression e1,e2; > > position p; > > @@ > > > > >  i@p(es,e1 b1 e2,...) > > > > @script:ocaml@ > > _p << s.p; > > b << r.b; > > b1 << s.b1; > > @@ > > > > try > >   let p1 = List.assoc b binoptbl in > >   let p2 = List.assoc b1 binoptbl in > >   if p1 >= p2 then Coccilib.include_match false > > with Not_found -> () > > > > @@ > > identifier r.i; > > expression list[r.n] es; > > expression e; > > position s.p; > > @@ > > > > i@p(es, > > +( > > e > > +) > > ,...) > > > --8323329-1441714774-1474434269=:3346--