*new* check_macros: find macro precedence bugs1.55
commit75079d5b29d9ffbea0a2c538c3f48dfb8a025fd3
authorDan Carpenter <error27@gmail.com>
Wed, 26 May 2010 10:31:23 +0000 (26 12:31 +0200)
committerDan Carpenter <error27@gmail.com>
Wed, 26 May 2010 10:31:23 +0000 (26 12:31 +0200)
treeaf3b36a39f90f6882e22a099edb482bf7075edc2
parent3c6317abbff40282a8b1de9d374fc19a7849dce6
*new* check_macros: find macro precedence bugs

This check is for find code like:
#define add(a, b) a + b
x = add(1, 1) * 5

The multiply has precedence over the add so x is 6 instead of 10 at the
end.

The way this check works is that it looks at which operations sparse does
first.  The problem with this approach is that it can lead to false
positives.  "x = (1 + 2) + 3;" is the same as "x = 1 + (2 + 3)" so adding
or removing parenthesis doesn't cause a problem.

I made adding, multiplying, bitwise AND and bitwise OR special cases to cut
down on the number of false positives.  There are still some other false
positives, but my feeling now is that it's best to just add parenthesis in
the kernel source to silence the warnings.

Signed-off-by: Dan Carpenter <error27@gmail.com>
check_list.h
check_macros.c [new file with mode: 0644]
validation/sm_macros.c [new file with mode: 0644]