1 Copyright 2004 Linus Torvalds
2 Copyright 2004 Pavel Machek <pavel@suse.cz>
4 Using sparse for typechecking
5 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7 "__bitwise" is a type attribute, so you have to do something like this:
9 typedef int __bitwise pm_request_t;
12 PM_SUSPEND = (__force pm_request_t) 1,
13 PM_RESUME = (__force pm_request_t) 2
16 which makes PM_SUSPEND and PM_RESUME "bitwise" integers (the "__force" is
17 there because sparse will complain about casting to/from a bitwise type,
18 but in this case we really _do_ want to force the conversion). And because
19 the enum values are all the same type, now "enum pm_request" will be that
22 And with gcc, all the __bitwise/__force stuff goes away, and it all ends
23 up looking just like integers to gcc.
25 Quite frankly, you don't need the enum there. The above all really just
26 boils down to one special "int __bitwise" type.
28 So the simpler way is to just do
30 typedef int __bitwise pm_request_t;
32 #define PM_SUSPEND ((__force pm_request_t) 1)
33 #define PM_RESUME ((__force pm_request_t) 2)
35 and you now have all the infrastructure needed for strict typechecking.
37 One small note: the constant integer "0" is special. You can use a
38 constant zero as a bitwise integer type without sparse ever complaining.
39 This is because "bitwise" (as the name implies) was designed for making
40 sure that bitwise types don't get mixed up (little-endian vs big-endian
41 vs cpu-endian vs whatever), and there the constant "0" really _is_
44 Modify top-level Makefile to say
46 CHECK = sparse -Wbitwise
48 or you don't get any checking at all.
54 With BK, you can just get it from
56 bk://sparse.bkbits.net/sparse
58 and DaveJ has tar-balls at
60 http://www.codemonkey.org.uk/projects/bitkeeper/sparse/
63 Once you have it, just do
68 as your regular user, and it will install sparse in your ~/bin directory.
69 After that, doing a kernel make with "make C=1" will run sparse on all the
70 C files that get recompiled, or with "make C=2" will run sparse on the
71 files whether they need to be recompiled or not (ie the latter is fast way
72 to check the whole tree if you have already built it).