public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* Possible code defects: macros and precedence
@ 2016-09-03 18:35 Joe Perches
  2016-09-03 20:18 ` Dan Carpenter
  2016-09-04 10:10 ` Possible code defects: macros " Julia Lawall
  0 siblings, 2 replies; 17+ messages in thread
From: Joe Perches @ 2016-09-03 18:35 UTC (permalink / raw)
  To: Julia Lawall, Dan Carpenter; +Cc: LKML

There are many nominally incorrect macro definitions
in linux-kernel source where parentheses are not used
for various macros arguments with calculations.

Does coccinelle or smatch have the ability to detect
potential macro misuse where arguments passed to the
macro are not correctly parenthesized by the macro?

Something like:

	#define A 1
	#define B 2
	#define shift(val) (val << 1)

where a use is:

	int c = shift(A | B)

where the actual result is 5 but the expected result is 6?

Can either tool suggest changing the macro to

	#define shift(val) ((val) << 1)

?

^ permalink raw reply	[flat|nested] 17+ messages in thread

end of thread, other threads:[~2016-09-21  5:04 UTC | newest]

Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-09-03 18:35 Possible code defects: macros and precedence Joe Perches
2016-09-03 20:18 ` Dan Carpenter
2016-09-03 22:20   ` [PATCH] checkpatch: Add a --strict test for macro argument reuse " Joe Perches
2016-09-04 14:42     ` Joe Perches
2016-09-04 10:10 ` Possible code defects: macros " Julia Lawall
2016-09-04 15:06   ` Joe Perches
     [not found]     ` <alpine.DEB.2.10.1609172221110.3124@hadrien>
2016-09-17 21:27       ` Joe Perches
2016-09-18  5:09         ` Julia Lawall
2016-09-18  9:31           ` Joe Perches
2016-09-20 13:14             ` Julia Lawall
2016-09-20 17:07               ` Joe Perches
2016-09-20 18:03                 ` Joe Perches
2016-09-20 23:47               ` Joe Perches
2016-09-21  5:04                 ` Julia Lawall
2016-09-17 21:57       ` Joe Perches
2016-09-18  4:57         ` Julia Lawall
2016-09-18  9:27           ` Joe Perches

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox