Repeated parameter with side effects passed to macro

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

MacroRepeated.diff (11.5 KB)

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 (docs here: http://llvm.org/docs/Phabricator.html): please specify myself as a reviewer and CC cfe-commits.