Skip to contentSkip to conversation

sparse: Fix BUILD_BUG_ON_{ZERO,NULL} definitions

PATCH In review Ben Hutchings 2 participants 3 messages Jun 24, 2011

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sparse: Fix BUILD_BUG_ON_{ZERO,NULL} definitions

Commit 903c0c7cdc21f2ccb7562a7bbc70289c0c2b16ad ('sparse: define dummy BUILD_BUG_ON definition for sparse') left these two broken. The ZERO or NULL suffix specifies what the macro should expand to, not the value that would indicate a bug.

---
sparse currently reports a syntax error and no useful warnings for any source file which uses one of these macros. Since module_param() uses BUILD_BUG_ON_ZERO(), that's a lot of source files.

Ben.

 include/linux/kernel.h |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
include/linux/kernel.h +2 -2
index fb0e732..fccd366 100644
@@ -671,8 +671,8 @@ struct sysinfo {
 
 #ifdef __CHECKER__
 #define BUILD_BUG_ON_NOT_POWER_OF_2(n)
-#define BUILD_BUG_ON_ZERO(e)
-#define BUILD_BUG_ON_NULL(e)
+#define BUILD_BUG_ON_ZERO(e) ((size_t)0)
+#define BUILD_BUG_ON_NULL(e) ((void *)0)
 #define BUILD_BUG_ON(condition)
 #else /* __CHECKER__ */
 
Signature · 7 lines
1.7.4.4


-- 
Ben Hutchings, Senior Software Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
#1 lore raw
Quoted 5 lines · On Fri, 24 Jun 2011 22:45:12 +0100 Ben Hutchings wrote:

Commit 903c0c7cdc21f2ccb7562a7bbc70289c0c2b16ad ('sparse: define dummy BUILD_BUG_ON definition for sparse') left these two broken. The ZERO or NULL suffix specifies what the macro should expand to, not the value that would indicate a bug.

Quoted 7 lines

---
sparse currently reports a syntax error and no useful warnings for any source file which uses one of these macros. Since module_param() uses BUILD_BUG_ON_ZERO(), that's a lot of source files.

Ben.

This patch from 2011-MAY-30 also fixes these warnings, but the typecasting in yours is probably better. :)

http://marc.info/?l=linux-kernel&m=130677145629121&w=2

Wait, 3.0-rc4 already has the above patch. Is yours still needed?

Quoted 9 lines
 include/linux/kernel.h |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
include/linux/kernel.h +0 -0
index fb0e732..fccd366 100644

include/linux/kernel.h struct sysinfo { · line 678

Quoted 10 lines
include/linux/kernel.h +2 -2
@@ -671,8 +671,8 @@ struct sysinfo {
 
 #ifdef __CHECKER__
 #define BUILD_BUG_ON_NOT_POWER_OF_2(n)
-#define BUILD_BUG_ON_ZERO(e)
-#define BUILD_BUG_ON_NULL(e)
+#define BUILD_BUG_ON_ZERO(e) ((size_t)0)
+#define BUILD_BUG_ON_NULL(e) ((void *)0)
 #define BUILD_BUG_ON(condition)
 #else /* __CHECKER__ */
 

---
~Randy
*** Remember to use Documentation/SubmitChecklist when testing your code ***

#2 lore raw
Quoted 13 lines · Randy Dunlap
Quoted 11 lines · On Fri, 24 Jun 2011 22:45:12 +0100 Ben Hutchings wrote:

Commit 903c0c7cdc21f2ccb7562a7bbc70289c0c2b16ad ('sparse: define dummy BUILD_BUG_ON definition for sparse') left these two broken. The ZERO or NULL suffix specifies what the macro should expand to, not the value that would indicate a bug.

---
sparse currently reports a syntax error and no useful warnings for any source file which uses one of these macros. Since module_param() uses BUILD_BUG_ON_ZERO(), that's a lot of source files.

Quoted 8 lines
Quoted 1 line

Ben.

This patch from 2011-MAY-30 also fixes these warnings, but the typecasting in yours is probably better. :)

http://marc.info/?l=linux-kernel&m=130677145629121&w=2

Wait, 3.0-rc4 already has the above patch. Is yours still needed?

[...]

Sorry, my baseline was a little out of date.

I'm not sure whether the type of BUILD_BUG_ON_ZERO() should be size_t; that's just what the non-sparse definition works out as. In some cases it could make a difference whether it's signed or not.

Ben.

Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.