[cfe-dev] Repeated parameter with side effects passed to macro

Alexander Kornienko alexfh at google.com
Fri Apr 10 18:27:09 PDT 2015


Hi Anders,

I've just noticed your mail while searching something in my inbox. Normally
the patches should go to the cfe-commits list, there they have fewer
chances to come unnoticed. It would also be convenient if you sent
clang-tidy patches using LLVM Phabricator <http://reviews.llvm.org/> (docs
here: http://llvm.org/docs/Phabricator.html): please specify myself as a
reviewer and CC cfe-commits.

The purely preprocessor-based approach has certain advantages, but it
limits the ability to detect code with side effects (which is not easy even
with the AST). I don't know how much this matters on the real code, so it
may make sense to leave this implementation until there are actual examples
of false negatives.

A couple of style-related comments:
  * function names should start with a lower-case letter
  * if `if` body is surrounded by braces, its `else` body should also use
braces and vice versa
  * use range for loops where the resulting code will be more compact

I'd suggest continuing the review on the LLVM Phabricator.

Thanks!

-- Alex

On Fri, Mar 27, 2015 at 1:49 PM, Anders Rönnholm <
Anders.Ronnholm at evidente.se> wrote:

>  Hi!
>
> I have implemented a proof-of-concept clang-tidy checker for this CERT
> rule:
>
>
> https://www.securecoding.cert.org/confluence/display/c/PRE31-C.+Avoid+side+effects+in+arguments+to+unsafe+macros
>
> The checker seems to work. It warns if a macro argument has side effects
> and it is repeated in the macro. Currently it only warns for ++ and -- but
> this can be improved.
>
> The error message can probably be tweaked. Feel free to suggest a better
> message.
>
> Is this approach looking good or should the checker be moved/redesigned?
>
> Best Regards,
> AR
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20150411/23c4dfe2/attachment.html>


More information about the cfe-dev mailing list