From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754124AbcITXrT (ORCPT ); Tue, 20 Sep 2016 19:47:19 -0400 Received: from smtprelay0112.hostedemail.com ([216.40.44.112]:34010 "EHLO smtprelay.hostedemail.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1751729AbcITXrS (ORCPT ); Tue, 20 Sep 2016 19:47:18 -0400 X-Session-Marker: 6A6F6540706572636865732E636F6D X-Spam-Summary: 2,0,0,,d41d8cd98f00b204,joe@perches.com,:::::,RULES_HIT:41:355:379:541:599:960:982:988:989:1260:1277:1311:1313:1314:1345:1359:1373:1437:1515:1516:1518:1534:1542:1593:1594:1711:1730:1747:1777:1792:2393:2559:2562:2828:2890:3138:3139:3140:3141:3142:3354:3622:3865:3866:3867:3868:3870:3871:3872:3874:4042:4321:5007:6119:7903:7904:9008:9010:10004:10400:10848:11232:11658:11783:11914:12043:12295:12296:12740:13141:13230:13439:13894:14181:14659:14721:21080:21324:21450:21451:30001:30012:30029:30034:30054:30062:30091,0,RBL:none,CacheIP:none,Bayesian:0.5,0.5,0.5,Netcheck:none,DomainCache:0,MSF:not bulk,SPF:fn,MSBL:0,DNSBL:none,Custom_rules:0:0:0,LFtime:1,LUA_SUMMARY:none X-HE-Tag: turn01_2255a3ad4b663 X-Filterd-Recvd-Size: 3124 Message-ID: <1474415234.1954.62.camel@perches.com> Subject: Re: Possible code defects: macros and precedence From: Joe Perches To: Julia Lawall Cc: Dan Carpenter , LKML Date: Tue, 20 Sep 2016 16:47:14 -0700 In-Reply-To: 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> Content-Type: text/plain; charset="ISO-8859-1" X-Mailer: Evolution 3.21.91-1ubuntu1 Mime-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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);   >       ("+",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 > +) > ,...) >