All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joe Perches <joe@perches.com>
To: Julia Lawall <julia.lawall@lip6.fr>
Cc: Dan Carpenter <error27@gmail.com>, LKML <linux-kernel@vger.kernel.org>
Subject: Re: Possible code defects: macros and precedence
Date: Tue, 20 Sep 2016 16:47:14 -0700	[thread overview]
Message-ID: <1474415234.1954.62.camel@perches.com> (raw)
In-Reply-To: <alpine.DEB.2.10.1609201503260.2914@hadrien>

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
> +)
> ,...)
> 

  parent reply	other threads:[~2016-09-20 23:47 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-09-03 18:35 Possible code defects: macros and precedence Joe Perches
2016-09-03 20:18 ` Dan Carpenter
2016-09-03 22:20   ` [PATCH] checkpatch: Add a --strict test for macro argument reuse " Joe Perches
2016-09-04 14:42     ` Joe Perches
2016-09-04 10:10 ` Possible code defects: macros " Julia Lawall
2016-09-04 15:06   ` Joe Perches
     [not found]     ` <alpine.DEB.2.10.1609172221110.3124@hadrien>
2016-09-17 21:27       ` Joe Perches
2016-09-18  5:09         ` Julia Lawall
2016-09-18  9:31           ` Joe Perches
2016-09-20 13:14             ` Julia Lawall
2016-09-20 17:07               ` Joe Perches
2016-09-20 18:03                 ` Joe Perches
2016-09-20 23:47               ` Joe Perches [this message]
2016-09-21  5:04                 ` Julia Lawall
2016-09-17 21:57       ` Joe Perches
2016-09-18  4:57         ` Julia Lawall
2016-09-18  9:27           ` Joe Perches

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1474415234.1954.62.camel@perches.com \
    --to=joe@perches.com \
    --cc=error27@gmail.com \
    --cc=julia.lawall@lip6.fr \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.