[PATCH] clang-tidy: check for repeated side effects in macro
Daniel Marjamäki
daniel.marjamaki at evidente.se
Tue May 5 06:31:28 PDT 2015
This is a new clang-tidy checker that warns when there is side effects in a macro argument that is repeated in the macro expansion.
I am running tests. Right now it has been tested on 7678 files in 180 projects. And there has been in total 7 warnings. As far as I see all these 7 warnings are real bugs.
Interestingly I get a couple of warnings for standard functions that are implemented as macros. As far as I see my headers are not standard-compliant:
format.c:774:28: warning: Side effects in macro argument is repeated in macro expansion [misc-macro-repeated-side-effects]
tblt->instr[0] = toupper(*p++);
^
/usr/include/ctype.h:229:11: note: 'toupper' macro defined here
# define toupper(c) __tobody (c, toupper, *__ctype_toupper_loc (), (c))
^
tunnel.c:73:25: warning: Side effects in macro argument is repeated in macro expansion [misc-macro-repeated-side-effects]
char *q = strchr (++p, '"');
^
/usr/include/x86_64-linux-gnu/bits/string2.h:395:11: note: 'strchr' macro defined here
# define strchr(s, c) \
(__extension__ (__builtin_constant_p (c) && !__builtin_constant_p (s) \
&& (c) == '\0' \
? (char *) __rawmemchr (s, c) \
: __builtin_strchr (s, c)))
...
http://reviews.llvm.org/D9496
Files:
clang-tidy/misc/CMakeLists.txt
clang-tidy/misc/MacroRepeatedSideEffectsCheck.cpp
clang-tidy/misc/MacroRepeatedSideEffectsCheck.h
clang-tidy/misc/MiscTidyModule.cpp
test/clang-tidy/misc-repeated-side-effects-in-macro.c
EMAIL PREFERENCES
http://reviews.llvm.org/settings/panel/emailpreferences/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D9496.24943.patch
Type: text/x-patch
Size: 7682 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20150505/6b700863/attachment.bin>
More information about the cfe-commits
mailing list