cocci.inria.fr archive mirror
 help / color / mirror / Atom feed
From: Julia Lawall <julia.lawall@lip6.fr>
To: Nicholas Mc Guire <der.herr@hofr.at>
Cc: Cocci@systeme.lip6.fr
Subject: Re: [Cocci] RFC catching hidden code in if conditions
Date: Mon, 25 Mar 2019 14:14:20 +0100 (CET)	[thread overview]
Message-ID: <alpine.DEB.2.20.1903251412450.3543@hadrien> (raw)
In-Reply-To: <20190325130358.GA7492@osadl.at>



On Mon, 25 Mar 2019, Nicholas Mc Guire wrote:

>
> HI !
>
>  Noticed that the nuveau driver uses a fair number of if (var=val,boolean-condition){}
>  which while legal C-code just makes it hard to read - and some seems buggy
>  actually. The below spatch find about 50 cases - not sure though if this is
>  actually complete ?

Maybe it would be good to forward it to the nouveau people and see what
they think about it?  I think that checkpatch already complains about
assignments in if conditions, and the whole thing with the comma makes it
look even more unpleasant.

julia

>
> thx!
> hofrat
>
> /// Check for unconditional code "hiding" in an if condition
> /// effectively that code is unconditionally executed before
> /// reaching the actual branch statement - which just makes it
> /// hard to read and thus is always wrong.
> /// Some of the cases found also look buggy
> /// In other cases some excess () are left in place in the
> /// generated patches - so some postprocessing may be needed.
> ///
> /// As of 5.0-rc8 all 50 cases look like they are found and fixed
> /// correctly - incorrectly only in the sense that the patched
> /// code is equivalent to the original code. but as this is in
> /// the nouveau driver only it might well be that this only
> /// fits that specific pattern and others might have wilder ways
> /// to achieve the same - so confidence Low for now
> ///
> // Confidence: Low
> // Comments:
> // Options: --no-includes --include-headers
>
> virtual patch
> virtual report
>
> @badif@
> position p;
> statement S;
> expression E1,E2;
> @@
>
>   if@p (E1,E2) S
>
> @script:python depends on report@
> p << badif.p;
> @@
>
> msg = "unconditional code hiding in if condition"
> coccilib.report.print_report(p[0],msg)
>
> @fixbadif depends on badif && patch@
> position p=badif.p;
> statement S;
> expression E1=badif.E1,E2=badif.E2;
> @@
>
> + E1;
>   if@p (
> - E1,
>   E2)
>   S
>
> _______________________________________________
> Cocci mailing list
> Cocci@systeme.lip6.fr
> https://systeme.lip6.fr/mailman/listinfo/cocci
>
_______________________________________________
Cocci mailing list
Cocci@systeme.lip6.fr
https://systeme.lip6.fr/mailman/listinfo/cocci

  reply	other threads:[~2019-03-25 13:14 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-25 13:03 [Cocci] RFC catching hidden code in if conditions Nicholas Mc Guire
2019-03-25 13:14 ` Julia Lawall [this message]
2019-03-26 19:04 ` Markus Elfring

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=alpine.DEB.2.20.1903251412450.3543@hadrien \
    --to=julia.lawall@lip6.fr \
    --cc=Cocci@systeme.lip6.fr \
    --cc=der.herr@hofr.at \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).