The sheer number of sparse warnings in the kernel
Subsystems (2)
The number of sparse errors in the current kernel is staggering, and it makes sparse a lot less valuable of a tool that it otherwise could be. On a build of x86-64 allyesconfig I'm getting 20,676 sparse messages. Out of those, 12,358 come from linux/err.h. Given that the latter basically spams *everything*, I can only conclude that almost noone uses sparse unless they have a filter script.
So a lot of these are certainly nuisance problems, like the <linux/err.h> stuff which has to do with the handling of error values, but some of these look like real bugs.
What do we need to do to actually make our tools be able to do work for us? Newbie projects to clean up? Trying to get the larger Linux companies to put resources on it?
-hpa
Quoted 2 lines · H. Peter Anvin
What do we need to do to actually make our tools be able to do work for us? Newbie projects to clean up?
It certainly would be a much better way for newbies to get involved than all the useless OCD-jerking off that floats back and forth nowadays. And who knows, newbies might *actually* even learn something while doing that.
Btw, rw could help with the newbie project, I think.
Signature · 5 lines
Regards/Gruss,
Boris.
Sent from a fat crate under my desk. Formatting is fine.
--Quoted 6 lines · H. Peter Anvin
The number of sparse errors in the current kernel is staggering, and it makes sparse a lot less valuable of a tool that it otherwise could be. On a build of x86-64 allyesconfig I'm getting 20,676 sparse messages. Out of those, 12,358 come from
linux/err.h. Given that the latter basically spams *everything*, I can only conclude that almost noone uses sparse unless they have a filter script.
What errors are you seeing from err.h? I don't see those when building different subdirectories with sparse (which is how I normally use it.)
And what version of sparse are you running:
$ sparse --version v0.4.5-rc1-407-g345e8943fc36
Quoted 7 lines
So a lot of these are certainly nuisance problems, like the <
linux/err.h> stuff which has to do with the handling of error values, but some of these look like real bugs.What do we need to do to actually make our tools be able to do work for us? Newbie projects to clean up? Trying to get the larger Linux companies to put resources on it?
It's not the easiest "newbie" project as usually the first reflex to "just cast it away" is wrong for a lot of sparse warnings. I know this from people trying to fix up the sparse warnings in drivers/staging/
thanks,
greg k-h
Quoted 8 lines · Greg KH
Quoted 6 lines · H. Peter Anvin
The number of sparse errors in the current kernel is staggering, and it makes sparse a lot less valuable of a tool that it otherwise could be. On a build of x86-64 allyesconfig I'm getting 20,676 sparse messages. Out of those, 12,358 come from
linux/err.h. Given that the latter basically spams *everything*, I can only conclude that almost noone uses sparse unless they have a filter script.
Quoted 6 lines
What errors are you seeing from
err.h? I don't see those when building different subdirectories with sparse (which is how I normally use it.)And what version of sparse are you running:
$ sparse --version v0.4.5-rc1-407-g345e8943fc36
Ah, 0.5.0 is now out, maybe you should update to that version?
thanks,
greg k-h
Quoted 9 lines · Greg KH
Quoted 8 lines · Greg KH
Quoted 6 lines · H. Peter Anvin
The number of sparse errors in the current kernel is staggering, and it makes sparse a lot less valuable of a tool that it otherwise could be. On a build of x86-64 allyesconfig I'm getting 20,676 sparse messages. Out of those, 12,358 come from
linux/err.h. Given that the latter basically spams *everything*, I can only conclude that almost noone uses sparse unless they have a filter script.
Quoted 9 lines
Quoted 6 lines
What errors are you seeing from
err.h? I don't see those when building different subdirectories with sparse (which is how I normally use it.)And what version of sparse are you running:
$ sparse --version v0.4.5-rc1-407-g345e8943fc36Ah, 0.5.0 is now out, maybe you should update to that version?
Yes... it looks like the 0.4.5-rc1 that shipped in Fedora is indeed out of date. With 0.5.0 I "only" see 8,207 messages, which means that at least the linux/err.h issue is gone.
-hpa
Quoted 17 lines · H. Peter Anvin
Quoted 16 lines · Greg KH
Quoted 14 lines · Greg KH
Quoted 6 lines · H. Peter Anvin
The number of sparse errors in the current kernel is staggering, and it makes sparse a lot less valuable of a tool that it otherwise could be. On a build of x86-64 allyesconfig I'm getting 20,676 sparse messages. Out of those, 12,358 come from
linux/err.h. Given that the latter basically spams *everything*, I can only conclude that almost noone uses sparse unless they have a filter script.What errors are you seeing from
err.h? I don't see those when building different subdirectories with sparse (which is how I normally use it.)And what version of sparse are you running:
$ sparse --version v0.4.5-rc1-407-g345e8943fc36
Quoted 7 lines
Quoted 2 lines
Ah, 0.5.0 is now out, maybe you should update to that version?
Yes... it looks like the 0.4.5-rc1 that shipped in Fedora is indeed out of date. With 0.5.0 I "only" see 8,207 messages, which means that at least the
linux/err.hissue is gone.
For what it's worth, the rpm is called sparse-0.4.5.rc1-2.fc19.x86_64 and sparse --version reports 0.4.4...
-hpa
Quoted 9 lines · Greg KH
Quoted 4 lines
What do we need to do to actually make our tools be able to do work for us? Newbie projects to clean up? Trying to get the larger Linux companies to put resources on it?
It's not the easiest "newbie" project as usually the first reflex to "just cast it away" is wrong for a lot of sparse warnings. I know this from people trying to fix up the sparse warnings in
drivers/staging/
I have seen this phenomenon, too. I also see a bunch of sparse warnings which are clearly bogus, for example complaining about sizeof(bool) when in bits like:
__this_cpu_write(swallow_nmi, false);
So getting this to the point where it is genuinely useful and can be made a ubiquitous part of the Linux development process is going to take more work and probably involve improvements to sparse so we can indicate in the kernel sources when something is okay or removing completely bogus warnings, and so on.
The bigger question, again, is what do we need to do to make this happen, assuming it is worth doing? We certainly have had bugs, including security holes, which sparse would have caught. At the same time, this kind of work tends to not be the kind that attract the top hackers, unfortunately, as it is not "fun".
-hpa
Quoted 7 lines · H. Peter Anvin
The number of sparse errors in the current kernel is staggering, and it makes sparse a lot less valuable of a tool that it otherwise could be. On a build of x86-64 allyesconfig I'm getting 20,676 sparse messages. Out of those, 12,358 come from
linux/err.h. Given that the latter basically spams *everything*, I can only conclude that almost noone uses sparse unless they have a filter script.
Quoted 7 lines
So a lot of these are certainly nuisance problems, like the <
linux/err.h> stuff which has to do with the handling of error values, but some of these look like real bugs.What do we need to do to actually make our tools be able to do work for us? Newbie projects to clean up? Trying to get the larger Linux companies to put resources on it?
gcc 4.8 does annoyingly warn on all unsigned/signed mismatches/implicit conversions too.
err.h could also return bool instead of long for the IS_ERR and IS_ERR_OR_NULL tests.
Maybe something like this could be useful.
Shut up the unsigned<->signed pointer conversions and implicit conversions in the Makefile.
Use bool not long for IS_ERR and IS_ERR_OR_NULL
Update the dentry description of kernel pointers left over from 2002's move to err.h
unsigned...
--- Makefile | 1 + include/linux/err.h | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-)
Makefile +1 -0
@@ -381,6 +381,7 @@ KBUILD_CPPFLAGS := -D__KERNEL__ KBUILD_CFLAGS := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \ -fno-strict-aliasing -fno-common \ -Werror-implicit-function-declaration \ + -Wno-sign-conversion -Wno-pointer-sign \ -Wno-format-security \ -fno-delete-null-pointer-checks KBUILD_AFLAGS_KERNEL :=
include/linux/err.h +4 -3
@@ -2,12 +2,13 @@#define _LINUX_ERR_H#include <linux/compiler.h> +#include <linux/types.h> #include <asm/errno.h> /* * Kernel pointers have redundant information, so we can use a -* scheme where we can return either an error code or a dentry +* scheme where we can return either an error code or a normal * pointer with the same return value. * * This should be a per-architecture thing, to allow different
@@ -29,12 +30,12 @@ static inline long __must_check PTR_ERR(__force const void *ptr)return (long ) ptr; } -static inline long __must_check IS_ERR (__force const void *ptr) +static inline bool __must_check IS_ERR (__force const void *ptr) {return IS_ERR_VALUE ((unsigned long )ptr); } -static inline long __must_check IS_ERR_OR_NULL (__force const void *ptr) +static inline bool __must_check IS_ERR_OR_NULL (__force const void *ptr) {return !ptr ||IS_ERR_VALUE ((unsigned long )ptr); }
Quoted 2 lines · Joe Perches
err.hcould also return bool instead of long for theIS_ERRandIS_ERR_OR_NULLtests.
This is definitely true... although we should check that that doesn't make the code worse as this is used *all over* the kernel.
Quoted 4 lines
Maybe something like this could be useful.
Shut up the unsigned<->signed pointer conversions
and implicit conversions in theMakefile.
Sounds like two separate patches to me.
-hpa
Quoted 6 lines · H. Peter Anvin
Quoted 2 lines · Joe Perches
err.hcould also return bool instead of long for theIS_ERRandIS_ERR_OR_NULLtests.This is definitely true... although we should check that that doesn't make the code worse as this is used *all over* the kernel.
I tested using arch/x86/crypto/ x86-64 and 32
and there are no .o file differences using
bool or long via objdump -d new and old
Quoted 6 lines
Quoted 4 lines
Maybe something like this could be useful.
Shut up the unsigned<->signed pointer conversions
and implicit conversions in theMakefile.Sounds like two separate patches to me.
Yeah, it was just for discussion.
I think gcc 4.8 is overly noisy about those 2.
Quoted 21 lines · H. Peter Anvin
Quoted 20 lines · H. Peter Anvin
Quoted 18 lines · Greg KH
Quoted 8 lines · Greg KH
Quoted 6 lines · H. Peter Anvin
The number of sparse errors in the current kernel is staggering, and it makes sparse a lot less valuable of a tool that it otherwise could be. On a build of x86-64 allyesconfig I'm getting 20,676 sparse messages. Out of those, 12,358 come from
linux/err.h. Given that the latter basically spams *everything*, I can only conclude that almost noone uses sparse unless they have a filter script.Quoted 6 lines
What errors are you seeing from
err.h? I don't see those when building different subdirectories with sparse (which is how I normally use it.)And what version of sparse are you running:
$ sparse --version v0.4.5-rc1-407-g345e8943fc36Ah, 0.5.0 is now out, maybe you should update to that version?
Quoted 7 lines
Quoted 4 lines
Yes... it looks like the 0.4.5-rc1 that shipped in Fedora is indeed out of date. With 0.5.0 I "only" see 8,207 messages, which means that at least the
linux/err.hissue is gone.For what it's worth, the rpm is called sparse-0.4.5.rc1-2.fc19.x86_64 and sparse --version reports 0.4.4...
Fedora rawhide has sparse-0.5.0-1.fc21. If it matters, we could probably update F20 and F19 with that.
josh
That would be good.
Quoted 43 lines · Josh Boyer
Quoted 5 lines · H. Peter Anvin
Quoted 4 lines · H. Peter Anvin
Quoted 3 lines · Greg KH
Quoted 2 lines · Greg KH
Quoted 1 line · H. Peter Anvin
The number of sparse errors in the current kernel is staggering,
and it
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
makes sparse a lot less valuable of a tool that it otherwise
could be.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
On a build of x86-64 allyesconfig I'm getting 20,676 sparse
messages.
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Out of those, 12,358 come from
linux/err.h. Given that thelatter
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
basically spams *everything*, I can only conclude that almost
noone uses
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 1 line
sparse unless they have a filter script.
What errors are you seeing from
err.h? I don't see those whenbuilding
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
different subdirectories with sparse (which is how I normally use
it.)
Quoted 9 lines
Quoted 9 lines
Quoted 7 lines
Quoted 4 lines
And what version of sparse are you running:
$ sparse --version v0.4.5-rc1-407-g345e8943fc36Ah, 0.5.0 is now out, maybe you should update to that version?
Yes... it looks like the 0.4.5-rc1 that shipped in Fedora is indeed
out
Quoted 1 line
Quoted 1 line
of date. With 0.5.0 I "only" see 8,207 messages, which means that
at
Quoted 5 lines
Quoted 2 lines
least the
linux/err.hissue is gone.For what it's worth, the rpm is called sparse-0.4.5.rc1-2.fc19.x86_64 and sparse --version reports 0.4.4...
Fedora rawhide has sparse-0.5.0-1.fc21. If it matters, we could probably update F20 and F19 with that.
josh
Signature · 1 line
Sent from my mobile phone. Please pardon brevity and lack of formatting.
Quoted 15 lines · H. Peter Anvin
Quoted 9 lines · Greg KH
Quoted 4 lines
What do we need to do to actually make our tools be able to do work for us? Newbie projects to clean up? Trying to get the larger Linux companies to put resources on it?
It's not the easiest "newbie" project as usually the first reflex to "just cast it away" is wrong for a lot of sparse warnings. I know this from people trying to fix up the sparse warnings in
drivers/staging/I have seen this phenomenon, too. I also see a bunch of sparse warnings which are clearly bogus, for example complaining about sizeof(bool) when in bits like:
Quoted 7 lines
__this_cpu_write(swallow_nmi, false);So getting this to the point where it is genuinely useful and can be made a ubiquitous part of the Linux development process is going to take more work and probably involve improvements to sparse so we can indicate in the kernel sources when something is okay or removing completely bogus warnings, and so on.
Yes, for some areas of the kernel it will take some work, but for others, sparse works really well. As an example, building all of drivers/usb/* with sparse only brings up 2 issues, both of which should probably be fixed (or annotated properly in the case of the locking warning.) So keeping things "sparse clean" there is quite easy and part of taking new patches.
Quoted 5 lines
The bigger question, again, is what do we need to do to make this happen, assuming it is worth doing? We certainly have had bugs, including security holes, which sparse would have caught. At the same time, this kind of work tends to not be the kind that attract the top hackers, unfortunately, as it is not "fun".
I guess the first thing would be to do is look to try to fix things like the "bool" issue you have here. And just grind away at the issues, one by one. Some of us like doing those types of things, so I'm sure you can find people willing to do it if you get the word out.
Once we hit a "tipping point" of the kernel being almost sparse clean, having the main subsystem maintainers always run it would be good. I know the 0-day bot runs it, as I get patches all the time from it to fix up some sparse warnings.
greg k-h
PATCH 1/1 err.h: Use bool for IS_ERR and IS_ERR_OR_NULL
In reply to H. Peter AnvinUse the more natural return of bool for these tests.
No difference observed in .o files produced by gcc for x86.
Remove the dentry description of kernel pointers
left over from the 90's and 2002's cleanup move
of parts of fs.h to err.h.
--- include/linux/err.h | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
include/linux/err.h +4 -3
@@ -2,12 +2,13 @@#define _LINUX_ERR_H#include <linux/compiler.h> +#include <linux/types.h> #include <asm/errno.h> /* * Kernel pointers have redundant information, so we can use a -* scheme where we can return either an error code or a dentry +* scheme where we can return either an error code or a normal * pointer with the same return value. * * This should be a per-architecture thing, to allow different
@@ -29,12 +30,12 @@ static inline long __must_check PTR_ERR(__force const void *ptr)return (long ) ptr; } -static inline long __must_check IS_ERR (__force const void *ptr) +static inline bool __must_check IS_ERR (__force const void *ptr) {return IS_ERR_VALUE ((unsigned long )ptr); } -static inline long __must_check IS_ERR_OR_NULL (__force const void *ptr) +static inline bool __must_check IS_ERR_OR_NULL (__force const void *ptr) {return !ptr ||IS_ERR_VALUE ((unsigned long )ptr); }
Quoted 23 lines · H. Peter Anvin
Quoted 9 lines · Greg KH
Quoted 4 lines
What do we need to do to actually make our tools be able to do work for us? Newbie projects to clean up? Trying to get the larger Linux companies to put resources on it?
It's not the easiest "newbie" project as usually the first reflex to "just cast it away" is wrong for a lot of sparse warnings. I know this from people trying to fix up the sparse warnings in
drivers/staging/I have seen this phenomenon, too. I also see a bunch of sparse warnings which are clearly bogus, for example complaining about sizeof(bool) when in bits like:
__this_cpu_write(swallow_nmi, false);So getting this to the point where it is genuinely useful and can be made a ubiquitous part of the Linux development process is going to take more work and probably involve improvements to sparse so we can indicate in the kernel sources when something is okay or removing completely bogus warnings, and so on.
Quoted 5 lines
The bigger question, again, is what do we need to do to make this happen, assuming it is worth doing? We certainly have had bugs, including security holes, which sparse would have caught. At the same time, this kind of work tends to not be the kind that attract the top hackers, unfortunately, as it is not "fun".
Well there was that "should we do a bug-fix-only 4.0 release?" message from Linus back at the 3.12 release.
Or do like Geert does with the build message regressions/fixes. I always scan that to make sure none of my work is in it :) (And that could be chunked up by maintainer).
Just a thought.
Regards,
Peter Hurley
PATCH 1/1 sparse: Allow override of sizeof(bool) warning
In reply to H. Peter AnvinAllow an override to emit or not the sizeof(bool) warning
--- evaluate.c | 3 ++- lib.c | 2 ++ lib.h | 1 + 3 files changed, 5 insertions(+), 1 deletion(-)
evaluate.c +2 -1
@@ -2057,7 +2057,8 @@ static struct symbol *evaluate_sizeof(struct expression *expr) }if (size ==1 &&is_bool_type (type)) { -warning (expr->pos,"expression using sizeof bool" ); +if (Wsizeof_bool) +warning (expr->pos,"expression using sizeof bool" ); size = bits_in_char; }
lib.c +2 -0
@@ -225,6 +225,7 @@ int Wone_bit_signed_bitfield = 1;int Wparen_string =0 ;int Wptr_subtraction_blows =0 ;int Wreturn_void =0 ; +int Wsizeof_bool =1 ;int Wshadow =0 ;int Wtransparent_union =0 ;int Wtypesign =0 ;
@@ -437,6 +438,7 @@ static const struct warning { { "paren-string", &Wparen_string }, { "ptr-subtraction-blows", &Wptr_subtraction_blows }, { "return-void", &Wreturn_void }, + { "sizeof-bool", &Wsizeof_bool }, { "shadow", &Wshadow }, { "transparent-union", &Wtransparent_union }, { "typesign", &Wtypesign },
lib.h +1 -0
@@ -119,6 +119,7 @@ extern int Wone_bit_signed_bitfield;extern int Wparen_string;extern int Wptr_subtraction_blows;extern int Wreturn_void; +extern int Wsizeof_bool;extern int Wshadow;extern int Wtransparent_union;extern int Wtypesign;
Signature · 1 line
1.8.1.2.459.gbcd45b4.dirty
RFC PATCH 1/1 Makefile: sparse - don't check sizeof(bool)
Add an override for sizeof(bool)
Requires sparse 0.5.0+ if -Wsizeof-bool is accepted there.
--- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Makefile +1 -1
@@ -350,7 +350,7 @@ PERL = perl CHECK = sparse CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \ - -Wbitwise -Wno-return-void $(CF) + -Wbitwise -Wno-return-void -Wno-sizeof-bool $(CF) CFLAGS_MODULE = AFLAGS_MODULE = LDFLAGS_MODULE =
Quoted 6 lines · Greg KH
Quoted 5 lines · H. Peter Anvin
I have seen this phenomenon, too. I also see a bunch of sparse warnings which are clearly bogus, for example complaining about sizeof(bool) when in bits like:
__this_cpu_write(swallow_nmi, false);
[]
Quoted 2 lines
I guess the first thing would be to do is look to try to fix things like the "bool" issue you have here.
I wonder what the "fix" would be as by standard_Bool doesn't have a defined size.
Probably another sparse -Wno-sizeof-bool flag.
(just added and submitted)
Re: [PATCH] sparse: Allow override of sizeof(bool) warning
In reply to Joe PerchesQuoted 3 lines · Joe Perches
Allow an override to emit or not the sizeof(bool) warning
Signed-off-by Joe Perches <[email protected]>
Seems reasonable. However, please document the new flag in the manpage.
Quoted 60 lines
evaluate.c | 3 ++- lib.c | 2 ++ lib.h | 1 + 3 files changed, 5 insertions(+), 1 deletion(-)evaluate.c +2
-1@@ -2057,7 +2057,8 @@ static struct symbol *evaluate_sizeof(struct expression *expr) }if (size ==1 &&is_bool_type (type)) { -warning (expr->pos,"expression using sizeof bool" ); +if (Wsizeof_bool) +warning (expr->pos,"expression using sizeof bool" ); size = bits_in_char; }lib.c +2
-0@@ -225,6 +225,7 @@ int Wone_bit_signed_bitfield = 1;int Wparen_string =0 ;int Wptr_subtraction_blows =0 ;int Wreturn_void =0 ; +int Wsizeof_bool =1 ;int Wshadow =0 ;int Wtransparent_union =0 ;int Wtypesign =0 ;@@ -437,6 +438,7 @@ static const struct warning { { "paren-string", &Wparen_string }, { "ptr-subtraction-blows", &Wptr_subtraction_blows }, { "return-void", &Wreturn_void }, + { "sizeof-bool", &Wsizeof_bool }, { "shadow", &Wshadow }, { "transparent-union", &Wtransparent_union }, { "typesign", &Wtypesign },lib.h +1
-0@@ -119,6 +119,7 @@ extern int Wone_bit_signed_bitfield;extern int Wparen_string;extern int Wptr_subtraction_blows;extern int Wreturn_void; +extern int Wsizeof_bool;extern int Wshadow;extern int Wtransparent_union;extern int Wtypesign;Signature · 8 lines
1.8.1.2.459.gbcd45b4.dirty -- To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v2 1/1 sparse: Allow override of sizeof(bool) warning
Allow an override to emit or not the sizeof(bool) warning Add a description to the manpage.
--- evaluate.c | 3 ++- lib.c | 2 ++ lib.h | 1 + sparse.1 | 9 +++++++++ 4 files changed, 14 insertions(+), 1 deletion(-)
evaluate.c +2 -1
@@ -2057,7 +2057,8 @@ static struct symbol *evaluate_sizeof(struct expression *expr) }if (size ==1 &&is_bool_type (type)) { -warning (expr->pos,"expression using sizeof bool" ); +if (Wsizeof_bool) +warning (expr->pos,"expression using sizeof bool" ); size = bits_in_char; }
lib.c +2 -0
@@ -225,6 +225,7 @@ int Wone_bit_signed_bitfield = 1;int Wparen_string =0 ;int Wptr_subtraction_blows =0 ;int Wreturn_void =0 ; +int Wsizeof_bool =1 ;int Wshadow =0 ;int Wtransparent_union =0 ;int Wtypesign =0 ;
@@ -437,6 +438,7 @@ static const struct warning { { "paren-string", &Wparen_string }, { "ptr-subtraction-blows", &Wptr_subtraction_blows }, { "return-void", &Wreturn_void }, + { "sizeof-bool", &Wsizeof_bool }, { "shadow", &Wshadow }, { "transparent-union", &Wtransparent_union }, { "typesign", &Wtypesign },
lib.h +1 -0
@@ -119,6 +119,7 @@ extern int Wone_bit_signed_bitfield;extern int Wparen_string;extern int Wptr_subtraction_blows;extern int Wreturn_void; +extern int Wsizeof_bool;extern int Wshadow;extern int Wtransparent_union;extern int Wtypesign;
sparse.1 +9 -0
@@ -288,6 +288,15 @@ programs consider this poor style, and those programs can use Sparse does not issue these warnings by default. . .TP +.B \-Wsizeof-bool +Warn when checking the sizeof a _Bool. + +C99 does not specify the sizeof a _Bool. gcc uses 1. + +Sparse issues these warnings by default. To turn them off, use +\fB\-Wno\-sizeof\-bool\fR. +. +.TP .B \-Wshadow Warn when declaring a symbol which shadows a declaration with the same name in an outer scope.
Signature · 1 line
1.8.1.2.459.gbcd45b4.dirty
Re: [PATCH V2] sparse: Allow override of sizeof(bool) warning
Quoted 4 lines · Joe Perches
Allow an override to emit or not the sizeof(bool) warning Add a description to the manpage.
Signed-off-by Joe Perches <[email protected]>
Quoted 81 lines
evaluate.c | 3 ++- lib.c | 2 ++ lib.h | 1 + sparse.1 | 9 +++++++++ 4 files changed, 14 insertions(+), 1 deletion(-)evaluate.c +2
-1@@ -2057,7 +2057,8 @@ static struct symbol *evaluate_sizeof(struct expression *expr) }if (size ==1 &&is_bool_type (type)) { -warning (expr->pos,"expression using sizeof bool" ); +if (Wsizeof_bool) +warning (expr->pos,"expression using sizeof bool" ); size = bits_in_char; }lib.c +2
-0@@ -225,6 +225,7 @@ int Wone_bit_signed_bitfield = 1;int Wparen_string =0 ;int Wptr_subtraction_blows =0 ;int Wreturn_void =0 ; +int Wsizeof_bool =1 ;int Wshadow =0 ;int Wtransparent_union =0 ;int Wtypesign =0 ;@@ -437,6 +438,7 @@ static const struct warning { { "paren-string", &Wparen_string }, { "ptr-subtraction-blows", &Wptr_subtraction_blows }, { "return-void", &Wreturn_void }, + { "sizeof-bool", &Wsizeof_bool }, { "shadow", &Wshadow }, { "transparent-union", &Wtransparent_union }, { "typesign", &Wtypesign },lib.h +1
-0@@ -119,6 +119,7 @@ extern int Wone_bit_signed_bitfield;extern int Wparen_string;extern int Wptr_subtraction_blows;extern int Wreturn_void; +extern int Wsizeof_bool;extern int Wshadow;extern int Wtransparent_union;extern int Wtypesign;sparse.1 +9
-0@@ -288,6 +288,15 @@ programs consider this poor style, and those programs can use Sparse does not issue these warnings by default. . .TP +.B \-Wsizeof-bool +Warn when checking the sizeof a _Bool. + +C99 does not specify the sizeof a _Bool. gcc uses 1. + +Sparse issues these warnings by default. To turn them off, use +\fB\-Wno\-sizeof\-bool\fR. +. +.TP .B \-Wshadow Warn when declaring a symbol which shadows a declaration with the same name in an outer scope.Signature · 8 lines
1.8.1.2.459.gbcd45b4.dirty -- To unsubscribe from this list: send the line "unsubscribe linux-sparse" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html
PATCH v3 1/1 sparse: Allow override of sizeof(bool) warning
Allow an override to emit or not the sizeof(bool) warning. Add a "-Wsizeof-bool" description to the manpage.
---
v2: Add manpage
v3: gah. Joe knows his alphabet (sometimes). (shadow _then_ sizeof)
evaluate.c | 3 ++- lib.c | 2 ++ lib.h | 1 + sparse.1 | 9 +++++++++ 4 files changed, 14 insertions(+), 1 deletion(-)
evaluate.c +2 -1
@@ -2057,7 +2057,8 @@ static struct symbol *evaluate_sizeof(struct expression *expr) }if (size ==1 &&is_bool_type (type)) { -warning (expr->pos,"expression using sizeof bool" ); +if (Wsizeof_bool) +warning (expr->pos,"expression using sizeof bool" ); size = bits_in_char; }
lib.c +2 -0
@@ -226,6 +226,7 @@ int Wparen_string = 0;int Wptr_subtraction_blows =0 ;int Wreturn_void =0 ;int Wshadow =0 ; +int Wsizeof_bool =1 ;int Wtransparent_union =0 ;int Wtypesign =0 ;int Wundef =0 ;
@@ -438,6 +439,7 @@ static const struct warning { { "ptr-subtraction-blows", &Wptr_subtraction_blows }, { "return-void", &Wreturn_void }, { "shadow", &Wshadow }, + { "sizeof-bool", &Wsizeof_bool }, { "transparent-union", &Wtransparent_union }, { "typesign", &Wtypesign }, { "undef", &Wundef },
lib.h +1 -0
@@ -120,6 +120,7 @@ extern int Wparen_string;extern int Wptr_subtraction_blows;extern int Wreturn_void;extern int Wshadow; +extern int Wsizeof_bool;extern int Wtransparent_union;extern int Wtypesign;extern int Wundef;
sparse.1 +9 -0
@@ -297,6 +297,15 @@ Such declarations can lead to error-prone code. Sparse does not issue these warnings by default. . .TP +.B \-Wsizeof-bool +Warn when checking the sizeof a _Bool. + +C99 does not specify the sizeof a _Bool. gcc uses 1. + +Sparse issues these warnings by default. To turn them off, use +\fB\-Wno\-sizeof\-bool\fR. +. +.TP .B \-Wtransparent\-union Warn about any declaration using the GCC extension \fB__attribute__((transparent_union))\fR.
Signature · 1 line
1.8.1.2.459.gbcd45b4.dirty
Re: [PATCH V2] sparse: Allow override of sizeof(bool) warning
In reply to Josh TriplettQuoted 8 lines · Josh Triplett
Quoted 4 lines · Joe Perches
Allow an override to emit or not the sizeof(bool) warning Add a description to the manpage.
Signed-off-by Joe Perches <[email protected]>Reviewed-by Josh Triplett <[email protected]>
I have to admit that this particular warning is a bit odd to me. I'm wondering what kind of bugs it was intended to catch.
In particular, things that incorrectly assumes the size of bool to be anything in particular would seem unlikely to actually use sizeof().
-hpa
Re: [PATCH V2] sparse: Allow override of sizeof(bool) warning
(adding Ben Pfaff and Christopher Li)
Quoted 7 lines · H. Peter Anvin
Quoted 6 lines · Josh Triplett
Quoted 4 lines · Joe Perches
Allow an override to emit or not the sizeof(bool) warning Add a description to the manpage.
Signed-off-by Joe Perches <[email protected]>
Quoted 8 lines
Quoted 2 lines
Reviewed-by Josh Triplett <[email protected]>I have to admit that this particular warning is a bit odd to me. I'm wondering what kind of bugs it was intended to catch.
In particular, things that incorrectly assumes the size of bool to be anything in particular would seem unlikely to actually use
sizeof().
Dunno, the commit log for the commit that added it doesn't quite match the code and is seemingly unaware that the c99 spec doesn't specify sizeof(bool).
Ben Pfaff <[email protected]>
Date: Wed May 4 16:39:54 2011 -0700
evaluate: Allow sizeof(_Bool) to succeed.
Without this commit, sizeof(_Bool) provokes an error with "cannot size expression" because _Bool is a 1-bit type and thus not a multiple of a full byte in size. But sizeof(_Bool) is valid C that should evaluate to 1, so this commit fixes the problem and adds a regression test.
Quoted 5 lines · Greg KH
Yes, for some areas of the kernel it will take some work, but for others, sparse works really well. As an example, building all of
drivers/usb/*with sparse only brings up 2 issues, both of which should probably be fixed (or annotated properly in the case of the locking warning.)
Hm. I see 102 in drivers/usb. Mostly in gadget.
http://paste.fedoraproject.org/80787/39347077/raw/
(Note that some of those are duplicates, which would be nice if sparse would be quieter about)
Dave
Re: [PATCH V2] sparse: Allow override of sizeof(bool) warning
In reply to Joe Perchessizeof(_Bool), like for many other types, is ABI-dependent, but that doesn't mean it is illegitimate.
I don't think C99 says that it is invalid (which means C99 doesn't permit is to be a packed bitmap.)
Quoted 37 lines · Joe Perches
(adding Ben Pfaff and Christopher Li)
Quoted 7 lines · H. Peter Anvin
Quoted 6 lines · Josh Triplett
Quoted 4 lines · Joe Perches
Allow an override to emit or not the sizeof(bool) warning Add a description to the manpage.
Signed-off-by Joe Perches <[email protected]>Quoted 8 lines
Quoted 2 lines
Reviewed-by Josh Triplett <[email protected]>I have to admit that this particular warning is a bit odd to me. I'm wondering what kind of bugs it was intended to catch.
In particular, things that incorrectly assumes the size of bool to be anything in particular would seem unlikely to actually use
sizeof().Dunno, the commit log for the commit that added it doesn't quite match the code and is seemingly unaware that the c99 spec doesn't specify sizeof(bool).
Ben Pfaff <[email protected]>
Date: Wed May 4 16:39:54 2011 -0700evaluate: Allow
sizeof(_Bool)to succeed.Without this commit,
sizeof(_Bool)provokes an error with "cannot size expression" because_Boolis a 1-bit type and thus not a multiple of a full
byte in size. Butsizeof(_Bool)is valid C that should evaluate to 1, so
this commit fixes the problem and adds a regression test.Signed-off-by Ben Pfaff <[email protected]>Signed-off-by Christopher Li <[email protected]>
Signature · 1 line
Sent from my mobile phone. Please pardon brevity and lack of formatting.
Re: [PATCH V2] sparse: Allow override of sizeof(bool) warning
In reply to Joe PerchesQuoted 16 lines · Joe Perches
(adding Ben Pfaff and Christopher Li)
Quoted 13 lines · H. Peter Anvin
Quoted 8 lines · Josh Triplett
Quoted 4 lines · Joe Perches
Allow an override to emit or not the sizeof(bool) warning Add a description to the manpage.
Signed-off-by Joe Perches <[email protected]>Reviewed-by Josh Triplett <[email protected]>I have to admit that this particular warning is a bit odd to me. I'm wondering what kind of bugs it was intended to catch.
Quoted 6 lines
Quoted 2 lines
In particular, things that incorrectly assumes the size of bool to be anything in particular would seem unlikely to actually use
sizeof().Dunno, the commit log for the commit that added it doesn't quite match the code and is seemingly unaware that the c99 spec doesn't specify sizeof(bool).
The commit *relaxed* sparse behavior: because previously sizeof(bool) was an error. I'm not in favor of any diagnostic at all for sizeof(bool), but my recollection is that a sparse maintainer wanted it to yield one.
I don't care about the particular result for sizeof(bool) as long as it matches the ABI.
Quoted 4 lines · Peter Hurley
Well there was that "should we do a bug-fix-only 4.0 release?" message from Linus back at the 3.12 release.
Sure... but will it actually happen?
-hpa
Re: [PATCH V2] sparse: Allow override of sizeof(bool) warning
In reply to Ben PfaffQuoted 6 lines · Ben Pfaff
The commit *relaxed* sparse behavior: because previously sizeof(bool) was an error. I'm not in favor of any diagnostic at all for sizeof(bool), but my recollection is that a sparse maintainer wanted it to yield one.
Still not clear as to why.
-hpa
Re: [PATCH V2] sparse: Allow override of sizeof(bool) warning
Quoted 8 lines · H. Peter Anvin
Quoted 5 lines · Ben Pfaff
The commit *relaxed* sparse behavior: because previously sizeof(bool) was an error. I'm not in favor of any diagnostic at all for sizeof(bool), but my recollection is that a sparse maintainer wanted it to yield one.
Still not clear as to why.
The discussion is here:
http://comments.gmane.org/gmane.comp.parsers.sparse/2462
Quoting from that discussion, the core of Christopher Li's argument was this:
Quoted 17 lines · On Mon, May 9, 2011 at 1:02 PM, Ben Pfaff <blp <at> nicira.com> wrote:
Quoted 5 lines
Thank you for applying my patch. It does work for me, in the sense that I get a warning instead of an error now, but I'm not so happy to get any diagnostic at all. Is there some reason why
sizeof(_Bool)warrants a warning when, say, sizeof(long) does not? After all, both sizes are implementation defined.Because
sizeof(_Bool)is a little bit special compare to sizeof(long). In the case of long, all sizeof(long) * 8 bits are use in the actual value. But for the_Bool, only the 1 bit is used in the 8 bits size. In other words, the_Boolhas a special case of the actual bit size is not a multiple of 8.Sparse has two hats, it is a C compiler front end, and more often it is used in the Linux kernel source sanitize checking. Depending on the sizeof
_Boolsounds a little bit suspicious in the kernel. I would love to the heard your actual usage case of thesizeof(_Bool). Why do you care about this warning?
Quoted 7 lines · H. Peter Anvin
Quoted 4 lines · Peter Hurley
Well there was that "should we do a bug-fix-only 4.0 release?" message from Linus back at the 3.12 release.
Sure... but will it actually happen?
I sure hope not, the backlog it would cause would be immense.
greg k-h
Quoted 10 lines · Dave Jones
Quoted 5 lines · Greg KH
Yes, for some areas of the kernel it will take some work, but for others, sparse works really well. As an example, building all of
drivers/usb/*with sparse only brings up 2 issues, both of which should probably be fixed (or annotated properly in the case of the locking warning.)Hm. I see 102 in
drivers/usb. Mostly in gadget.
http://paste.fedoraproject.org/80787/39347077/raw/
Ick, gadget, I don't build that for my systems as I don't have that hardware, sorry, I forgot to take that into consideration here.
Hey, at least I know what I'm going to be doing tomorrow :)
greg k-h
Re: [PATCH V2] sparse: Allow override of sizeof(bool) warning
In reply to Ben PfaffQuoted 5 lines · Ben Pfaff
Quoted 5 lines
Because
sizeof(_Bool)is a little bit special compare to sizeof(long). In the case of long, all sizeof(long) * 8 bits are use in the actual value. But for the_Bool, only the 1 bit is used in the 8 bits size. In other words, the_Boolhas a special case of the actual bit size is not a multiple of 8.
Quite frankly, this is silly in my opinion, *and* it is not guaranteed by C either (read about "trap representations").
Quoted 5 lines
Quoted 5 lines
Sparse has two hats, it is a C compiler front end, and more often it is used in the Linux kernel source sanitize checking. Depending on the sizeof
_Boolsounds a little bit suspicious in the kernel. I would love to the heard your actual usage case of thesizeof(_Bool). Why do you care about this warning?
Anything that moves data around in a generic fashion. It can be as simple as:
memcpy(foo, bar, sizeof *foo); -hpa
Re: [PATCH V2] sparse: Allow override of sizeof(bool) warning
In reply to H. Peter AnvinQuoted 5 lines · H. Peter Anvin
sizeof(_Bool), like for many other types, is ABI-dependent, but that doesn't mean it is illegitimate.I don't think C99 says that it is invalid (which means C99 doesn't permit is to be a packed bitmap.)
Ok, but what can be said about the __pcpu_size_call() use case where we do sizeof(bool)? We have there accessors for sizes 1,2,4 and 8. Can we simply assume that the ABI will give us a size of bool which is one of those?
What if sizeof(bool) is 3?
Or, are we saying that sizeof(bool) will always be of some natural, native size like byte, short, int or long so we're good there?
Thanks.
Signature · 5 lines
Regards/Gruss,
Boris.
Sent from a fat crate under my desk. Formatting is fine.
--Am 27.02.2014 00:25, schrieb Borislav Petkov:
Quoted 10 lines · H. Peter Anvin
Quoted 2 lines
What do we need to do to actually make our tools be able to do work for us? Newbie projects to clean up?
It certainly would be a much better way for newbies to get involved than all the useless OCD-jerking off that floats back and forth nowadays. And who knows, newbies might *actually* even learn something while doing that.
Btw, rw could help with the newbie project, I think.
Yeah, on #kernelnewbies newbies often ask how they can help. Maybe a short info on http://kernelnewbies.org/ how to deal with sparse would help too.
Thanks,
//richard
Quoted 6 lines · Peter Hurley
Quoted 5 lines
The bigger question, again, is what do we need to do to make this happen, assuming it is worth doing? We certainly have had bugs, including security holes, which sparse would have caught. At the same time, this kind of work tends to not be the kind that attract the top hackers, unfortunately, as it is not "fun".
Quoted 7 lines
Well there was that "should we do a bug-fix-only 4.0 release?" message from Linus back at the 3.12 release.
Or do like Geert does with the build message regressions/fixes. I always scan
that to make sure none of my work is in it :) (And that could be chunked up by maintainer).
A quick test shows that my scripts would catch (many) sparse errors and warnings too, iff they would be in the kissb build logs.
So as soon as kissb starts building with C=1, we can start tracking sparse regressions. The first report would contain _lots_ of regressions, though ;-)
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]
In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
Quoted 9 lines
Quoted 6 lines
So getting this to the point where it is genuinely useful and can be made a ubiquitous part of the Linux development process is going to take more work and probably involve improvements to sparse so we can indicate in the kernel sources when something is okay or removing completely bogus warnings, and so on.
Yes, for some areas of the kernel it will take some work, but for others, sparse works really well. As an example, building all of
Works quite nicely for me. I run both spatch and smatch on drivers/hwmon and (partially) on drivers/watchdog. There is only one (false) warning in hwmon from spatch, plus about a dozen smatch warnings. I find it very valuable; even if warnings are false positives they often point to less than perfect code.
I filter out some noise from smatch, but at least so far I did not have to do any filtering for spatch.
Guenter
Quoted 6 lines · * H. Peter Anvin ([email protected]) wrote:
The number of sparse errors in the current kernel is staggering, and it makes sparse a lot less valuable of a tool that it otherwise could be. On a build of x86-64 allyesconfig I'm getting 20,676 sparse messages. Out of those, 12,358 come from
linux/err.h. Given that the latter basically spams *everything*, I can only conclude that almost noone uses sparse unless they have a filter script.
I did a bit of sparse fixing a few years ago; my strategy then was to get used to which types of warnings were more likely to be real and ignore all the rest - it was the only way to find anything useful from them.
There were some that were very fruitful; the warnings for gfp_t types were great at spotting where someone had swapped the parameters to kmalloc for example.
Dave
Signature · 4 lines
-----Open up your eyes, open up your mind, open up your code ------- / Dr. David Alan Gilbert | Running GNU/Linux | Happy \ \ gro.gilbert @ treblig.org | | In Hex / \ _________________________|_____ http://www.treblig.org |_______/
Re: [PATCH V2] sparse: Allow override of sizeof(bool) warning
In reply to Borislav PetkovKeep in mind, too, that for the kernel we don't care about the full C standard but a subset. We rely on extrastandard behavior all over the place. For all ABIs supported by the kernel, sizeof(_Book) == 1 and so everything is sane.
Quoted 18 lines · Borislav Petkov
Quoted 5 lines · H. Peter Anvin
sizeof(_Bool), like for many other types, is ABI-dependent, but that doesn't mean it is illegitimate.I don't think C99 says that it is invalid (which means C99 doesn't permit is to be a packed bitmap.)
Ok, but what can be said about the
__pcpu_size_call()use case where we do sizeof(bool)? We have there accessors for sizes 1,2,4 and 8. Can we simply assume that the ABI will give us a size of bool which is one of those?What if sizeof(bool) is 3?
Or, are we saying that sizeof(bool) will always be of some natural, native size like byte, short, int or long so we're good there?
Thanks.
Signature · 1 line
Sent from my mobile phone. Please pardon brevity and lack of formatting.
Re: [PATCH V2] sparse: Allow override of sizeof(bool) warning
Quoted 4 lines · H. Peter Anvin
Keep in mind, too, that for the kernel we don't care about the full C standard but a subset. We rely on extrastandard behavior all over the place. For all ABIs supported by the kernel,
sizeof(_Book)== 1 and so everything is sane.
Do we have a fairly comprehensive list of what these extrastandard requirements / assumptions are? It might be a good idea to have one that we can point to, so that (a) people who are trying to define a new architecture knows what they need to handle, (b) and so we can give a list of things that static code analyzers like smatch and coverity and sparse should be able to suppress (perhaps in a Linux kernel-only mode).
- Ted
Re: [PATCH V2] sparse: Allow override of sizeof(bool) warning
Quoted 6 lines · Theodore Ts'o
Quoted 4 lines · H. Peter Anvin
Keep in mind, too, that for the kernel we don't care about the full C standard but a subset. We rely on extrastandard behavior all over the place. For all ABIs supported by the kernel,
sizeof(_Book)== 1 and so everything is sane.
Quoted 8 lines
Do we have a fairly comprehensive list of what these extrastandard requirements / assumptions are? It might be a good idea to have one that we can point to, so that (a) people who are trying to define a new architecture knows what they need to handle, (b) and so we can give a list of things that static code analyzers like smatch and coverity and sparse should be able to suppress (perhaps in a Linux kernel-only mode).
No, but I think we can certainly make a list... a lot of it right now sits in various people's heads.
Here are a couple:
- Bytes are 8 bits
- Signed integers will be 2's complement
- sizeof char, short, int, long, and long long will be 1, 2, 4, 4, 8 or 1, 2, 4, 8, 8 on 32- and 64-bit processors, respectively.
- sizeof(long) == sizeof(void *)
- NULL is represented by all zero
- Structures will not add padding as long as all the members are naturally aligned.
Someone want to set up a collaborative document of some kind and collect more?
-hpa
Re: [PATCH V2] sparse: Allow override of sizeof(bool) warning
Quoted 8 lines · H. Peter Anvin
No, but I think we can certainly make a list... a lot of it right now sits in various people's heads.
Here are a couple:
- Bytes are 8 bits
- Signed integers will be 2's complement
- sizeof char, short, int, long, and long long will be 1, 2, 4, 4, 8 or
^ ^ bool, ,1 ,
Quoted 8 lines
1, 2, 4, 8, 8 on 32- and 64-bit processors, respectively.
- sizeof(long) ==sizeof(void *)
- NULL is represented by all zero
- Structures will not add padding as long as all the members are naturally aligned.Someone want to set up a collaborative document of some kind and collect more?
https://wiki.kernel.org/ but I hear spammers love it.
Signature · 5 lines
Regards/Gruss,
Boris.
Sent from a fat crate under my desk. Formatting is fine.
--Re: [PATCH V2] sparse: Allow override of sizeof(bool) warning
In reply to H. Peter AnvinQuoted 14 lines · H. Peter Anvin
Quoted 8 lines
Do we have a fairly comprehensive list of what these extrastandard requirements / assumptions are? It might be a good idea to have one that we can point to, so that (a) people who are trying to define a new architecture knows what they need to handle, (b) and so we can give a list of things that static code analyzers like smatch and coverity and sparse should be able to suppress (perhaps in a Linux kernel-only mode).
No, but I think we can certainly make a list... a lot of it right now sits in various people's heads.
Here are a couple:
Quoted 9 lines
- Bytes are 8 bits
- Signed integers will be 2's complement
- sizeof char, short, int, long, and long long will be 1, 2, 4, 4, 8 or 1, 2, 4, 8, 8 on 32- and 64-bit processors, respectively.
- sizeof(long) ==sizeof(void *)
- NULL is represented by all zero
- Structures will not add padding as long as all the members are naturally aligned.
That last assumption has to change for the Meta architecture.
https://lwn.net/Articles/522188/
On meta, the structs and unions are padded to 4 bytes unless they are explicitly marked as __packed.
regards,
dan carpenter
Re: [PATCH V2] sparse: Allow override of sizeof(bool) warning
Quoted 8 lines · Dan Carpenter
That last assumption has to change for the Meta architecture.
https://lwn.net/Articles/522188/
On meta, the structs and unions are padded to 4 bytes unless they are explicitly marked as
__packed.
One have to wonder how likely they are to have that not continually break...
-hpa
Re: [PATCH V2] sparse: Allow override of sizeof(bool) warning
Quoted 11 lines · H. Peter Anvin
Quoted 8 lines · Dan Carpenter
That last assumption has to change for the Meta architecture.
https://lwn.net/Articles/522188/
On meta, the structs and unions are padded to 4 bytes unless they are explicitly marked as
__packed.One have to wonder how likely they are to have that not continually break...
Well it's only when it deals with stored/portable data formats that it's an issue, and in those cases some amount of care over packing has usually already been taken. It most often causes problems when one small struct/union containing only chars or shorts is nested inside another struct which is marked as packed (on the unfortunately mistaken assumption that the inner struct cannot have padding at the end so doesn't need packing itself).
But yeh, it is a PITA.
Cheers
James
Christopher Li
maintainerRe: [PATCH V2] sparse: Allow override of sizeof(bool) warning
In reply to H. Peter AnvinQuoted 8 lines · H. Peter Anvin
Quite frankly, this is silly in my opinion, *and* it is not guaranteed by C either (read about "trap representations").
Quoted 1 line
Anything that moves data around in a generic fashion. It can be as simple as:
memcpy(foo, bar, sizeof *foo);
OK. I get it nobody wants a sizeof(_Bool) warning.
I am going to apply this patch.
Should we change the default to off then?
Thanks.
Chris
Re: [PATCH V2] sparse: Allow override of sizeof(bool) warning
I would.
Quoted 20 lines · Christopher Li
Quoted 2 lines · H. Peter Anvin
Quite frankly, this is silly in my opinion, *and* it is not
guaranteed
Quoted 6 lines
by C either (read about "trap representations").
Quoted 1 line
Anything that moves data around in a generic fashion. It can be as simple as:
memcpy(foo, bar, sizeof *foo);OK. I get it nobody wants a
sizeof(_Bool)warning.I am going to apply this patch.
Should we change the default to off then?
Thanks.
Chris
Signature · 1 line
Sent from my mobile phone. Please pardon brevity and lack of formatting.
Re: [PATCH V2] sparse: Allow override of sizeof(bool) warning
Quoted 3 lines · H. Peter Anvin
Quoted 2 lines · Christopher Li
OK. I get it nobody wants a
sizeof(_Bool)warning. I am going to apply this patch.
Please use V3 as I stuffed up the alphabetic order of sizeof and shadow.
Quoted 2 lines
Quoted 1 line
Should we change the default to off then?
I would.
I'm not sure it matters much, but the linux-kernel Makefile wouldn't need to be changed if Wsizeof_bool is default 0.
Here's a couple of other nits:
Maybe the evaluate.c "size = bits_in_char;" assignment
if (size == 1 && is_bool_type(type)) {
- warning(expr->pos, "expression using sizeof bool");
+ if (Wsizeof_bool)
+ warning(expr->pos, "expression using sizeof bool");
size = bits_in_char;
}should be
size = sizeof(_Bool) * 8;
And also, in sparse.1, Josh Triplett is shown as the maintainer. Maybe that should be changed to Christopher Li
Re: [PATCH V2] sparse: Allow override of sizeof(bool) warning
In reply to H. Peter AnvinQuoted 2 lines · H. Peter Anvin
I would.
Joe, I assume you are OK with this patch, the default is now off.
Chris
Allow an override to emit or not the sizeof(bool) warning. Add a "-Wsizeof-bool" description to the manpage.
--- evaluate.c | 3 ++- lib.c | 2 ++ lib.h | 1 + sparse.1 | 8 ++++++++ 4 files changed, 13 insertions(+), 1 deletion(-)
evaluate.c +0 -0
@@ -2057,7 +2057,8 @@ static struct symbol *evaluate_sizeof(struct
expression *expr)
}
if (size == 1 && is_bool_type(type)) {
- warning(expr->pos, "expression using sizeof bool");
+ if (Wsizeof_bool)
+ warning(expr->pos, "expression using sizeof bool");
size = bits_in_char;
}lib.c +2 -0
@@ -226,6 +226,7 @@ int Wparen_string = 0;int Wptr_subtraction_blows =0 ;int Wreturn_void =0 ;int Wshadow =0 ; +int Wsizeof_bool =0 ;int Wtransparent_union =0 ;int Wtypesign =0 ;int Wundef =0 ;
@@ -438,6 +439,7 @@ static const struct warning { { "ptr-subtraction-blows", &Wptr_subtraction_blows }, { "return-void", &Wreturn_void }, { "shadow", &Wshadow }, + { "sizeof-bool", &Wsizeof_bool }, { "transparent-union", &Wtransparent_union }, { "typesign", &Wtypesign }, { "undef", &Wundef },
lib.h +1 -0
@@ -120,6 +120,7 @@ extern int Wparen_string;extern int Wptr_subtraction_blows;extern int Wreturn_void;extern int Wshadow; +extern int Wsizeof_bool;extern int Wtransparent_union;extern int Wtypesign;extern int Wundef;
sparse.1 +8 -0
@@ -297,6 +297,14 @@ Such declarations can lead to error-prone code. Sparse does not issue these warnings by default. . .TP +.B \-Wsizeof-bool +Warn when checking the sizeof a _Bool. + +C99 does not specify the sizeof a _Bool. gcc uses 1. + +Sparse does not issue these warnings by default. +. +.TP .B \-Wtransparent\-union Warn about any declaration using the GCC extension \fB__attribute__((transparent_union))\fR.
Signature · 1 line
1.8.5.3
Christopher Li
maintainerRe: [PATCH V2] sparse: Allow override of sizeof(bool) warning
In reply to Joe PerchesQuoted 2 lines · Joe Perches
Please use V3 as I stuffed up the alphabetic order of sizeof and shadow.
Please send it your V3 then :-)
Quoted 4 lines
I'm not sure it matters much, but the linux-kernel
Makefilewouldn't need to be changed ifWsizeof_boolis default 0.
It seems default to off is the right thing to do.
Quoted 12 lines
Here's a couple of other nits:
Maybe the
evaluate.c"size =bits_in_char;" assignmentif (size == 1 && is_bool_type(type)) {(quoted diff) +2
-1- warning(expr->pos, "expression using sizeof bool"); + if (Wsizeof_bool) + warning(expr->pos, "expression using sizeof bool"); size = bits_in_char; }
Quoted 3 lines
should be
size = sizeof(_Bool) * 8;
The reason to use bits_in_xxxx is to allow sparse application to over write the size of int etc. If you don't like the bits_in_char here. You can introduce bits_in_bool and set that to sizeof(Bool)*8 by default. That way you don't hard code it.
Quoted 3 lines
And also, in sparse.1, Josh Triplett is shown as the maintainer. Maybe that should be changed to Christopher Li
Maybe a separate patch.
Waiting for your V3.
Chris
Re: [PATCH V2] sparse: Allow override of sizeof(bool) warning
In reply to Christopher LiQuoted 3 lines · Christopher Li
Quoted 1 line · H. Peter Anvin
I would.
Joe, I assume you are OK with this patch, the default is now off.
Of course
lib.c
Quoted 1 line
lib.c +0
-0
[]
Quoted 2 lines
lib.c +1
-0@@ -226,6 +226,7 @@ int Wparen_string = 0; +int Wsizeof_bool =0 ;
Christopher Li
maintainerRe: [PATCH V2] sparse: Allow override of sizeof(bool) warning
Quoted 6 lines · Joe Perches
Quoted 3 lines · Christopher Li
Quoted 1 line · H. Peter Anvin
I would.
Joe, I assume you are OK with this patch, the default is now off.
Of course
Let me know if you are going to have a V3 or not.
Thanks
Chris
Christopher Li
maintainerRe: [PATCH V2] sparse: Allow override of sizeof(bool) warning
In reply to Joe PerchesQuoted 2 lines · Joe Perches
Of course
The change has applied and pushed.
Chris
Re: [PATCH V2] sparse: Allow override of sizeof(bool) warning
In reply to Christopher LiQuoted 11 lines · Christopher Li
Quoted 9 lines · Joe Perches
Maybe the
evaluate.c"size =bits_in_char;" assignmentif (size == 1 && is_bool_type(type)) {(quoted diff) +2
-1- warning(expr->pos, "expression using sizeof bool"); + if (Wsizeof_bool) + warning(expr->pos, "expression using sizeof bool"); size = bits_in_char; }
Quoted 8 lines
Quoted 3 lines
should be
size = sizeof(_Bool) * 8;The reason to use
bits_in_xxxxis to allow sparse application to over write the size of int etc. If you don't like thebits_in_charhere. You can introducebits_in_booland set that to sizeof(Bool)*8 by default. That way you don't hard code it.
There already is a bits_in_bool and it's default 1.
$ git grep -E "\bbits_in_\w+\s*=[^=]" lib.c: bits_in_long = 64; lib.c: bits_in_pointer = 64; target.c:int bits_in_bool = 1; target.c:int bits_in_char = 8; target.c:int bits_in_short = 16; target.c:int bits_in_int = 32; target.c:int bits_in_long = 32; target.c:int bits_in_longlong = 64; target.c:int bits_in_longlonglong = 128; target.c:int bits_in_float = 32; target.c:int bits_in_double = 64; target.c:int bits_in_longdouble = 80; target.c:int bits_in_pointer = 32; target.c:int bits_in_enum = 32;
Quoted 5 lines
Quoted 3 lines
And also, in sparse.1, Josh Triplett is shown as
the maintainer. Maybe that should be changed to
Christopher LiMaybe a separate patch.
That's fine with me too. If you're the maintainer, I think you should do that patch. I don't see a need for me to send any more right now though.
cheers, Joe
Quoted 3 lines · H. Peter Anvin
Yes... it looks like the 0.4.5-rc1 that shipped in Fedora is indeed out of date. With 0.5.0 I "only" see 8,207 messages, which means that at least the
linux/err.hissue is gone.
Unfortunately, that's not true, at least with the Fedora Rawhide version of sparse. From yesterday's build of next-20140403:
[/usr/src/linux-next] sparse --version
0.5.0
[/usr/src/linux-next] grep err.h build.default | sort | uniq -c
1491 include/linux/err.h:29:23: warning: dereference of noderef expression
2 include/linux/err.h:29:23: warning: too many warnings
2493 include/linux/err.h:34:16: warning: dereference of noderef expression
59 include/linux/err.h:39:17: warning: dereference of noderef expression 59 include/linux/err.h:39:24: warning: dereference of noderef expression
124 include/linux/err.h:52:25: warning: dereference of noderef expression
18 include/linux/err.h:57:20: warning: dereference of noderef expression 18 include/linux/err.h:58:32: warning: dereference of noderef expression
(Oddly enough, the tarball in the .src.rpm seems to match the one on kernel.org, and nothing fishy in the .spec file, so I'm confused now...)