1sparse(1)                   General Commands Manual                  sparse(1)
2
3
4

NAME

6       sparse - Semantic Parser for C
7

SYNOPSIS

9       sparse [WARNING OPTIONS]... file.c
10

DESCRIPTION

12       Sparse  parses  C  source  and  looks for errors, producing warnings on
13       standard error.
14
15       Sparse accepts options controlling the set of warnings to generate.  To
16       turn  on warnings Sparse does not issue by default, use the correspond‐
17       ing  warning  option  -Wsomething.   Sparse  issues  some  warnings  by
18       default;  to  turn off those warnings, pass the negation of the associ‐
19       ated warning option, -Wno-something.
20

WARNING OPTIONS

22       -Waddress-space
23              Warn about code which mixes pointers to different  address  spa‐
24              ces.
25
26              Sparse         allows        an        extended        attribute
27              __attribute__((address_space(num))) on  pointers,  which  desig‐
28              nates  a  pointer  target in address space num (a constant inte‐
29              ger).  With -Waddress-space, Sparse treats pointers with identi‐
30              cal target types but different address spaces as distinct types.
31              To override this warning, such as for  functions  which  convert
32              pointers  between  address  spaces,  use  a  type  that includes
33              __attribute__((force)).
34
35              Sparse issues these warnings by default.  To turn them off,  use
36              -Wno-address-space.
37
38       -Wbitwise
39              Warn  about  unsupported  operations  or  type  mismatches  with
40              restricted integer types.
41
42              Sparse supports an extended attribute, __attribute__((bitwise)),
43              which  creates a new restricted integer type from a base integer
44              type, distinct from the base integer type  and  from  any  other
45              restricted  integer type not declared in the same declaration or
46              typedef.  For example, this allows programs to  create  typedefs
47              for  integer  types  with  specific endianness.  With -Wbitwise,
48              Sparse will warn on any use of a restricted type  in  arithmetic
49              operations  other than bitwise operations, and on any conversion
50              of one restricted type into another,  except  via  a  cast  that
51              includes __attribute__((force)).
52
53              Sparse does not issue these warnings by default.
54
55       -Wcast-to-as
56              Warn about casts which add an address space to a pointer type.
57
58              A  cast  that includes __attribute__((force)) will suppress this
59              warning.
60
61              Sparse does not issue these warnings by default.
62
63       -Wcast-truncate
64              Warn about casts that truncate constant values.
65
66              Sparse issues these warnings by default.  To turn them off,  use
67              -Wno-cast-truncate.
68
69       -Wcontext
70              Warn  about  potential errors in synchronization or other delim‐
71              ited contexts.
72
73              Sparse supports several means of designating functions or state‐
74              ments that delimit contexts, such as synchronization.  Functions
75              with  the  extended   attribute   __attribute__((context(expres‐
76              sion,in_context,out_context))  require  the  context  expression
77              (for instance, a lock) to have the value in_context (a  constant
78              nonnegative  integer)  when  called,  and  return with the value
79              out_context (a constant nonnegative integer).  For APIs  defined
80              via   macros,   use   the   statement  form  __context__(expres‐
81              sion,in_value,out_value) in the body of the macro.
82
83              With -Wcontext Sparse will warn when it sees a  function  change
84              the  context  without  indicating this with a context attribute,
85              either by decreasing a context below zero (such as by  releasing
86              a  lock  without acquiring it), or returning with a changed con‐
87              text (such as by acquiring a lock without releasing it).  Sparse
88              will  also  warn about blocks of code which may potentially exe‐
89              cute with different contexts.
90
91              Sparse issues these warnings by default.  To turn them off,  use
92              -Wno-context.
93
94       -Wdecl Warn  about  any non-static variable or function definition that
95              has no previous declaration.
96
97              Private symbols (functions and variables) internal  to  a  given
98              source  file  should  use  static,  to allow additional compiler
99              optimizations, allow detection of unused  symbols,  and  prevent
100              other  code from relying on these internal symbols.  Public sym‐
101              bols used by other source files will need  declarations  visible
102              to those other source files, such as in a header file.  All dec‐
103              larations should fall into one of these two  categories.   Thus,
104              with  -Wdecl, Sparse warns about any symbol definition with nei‐
105              ther static nor a declaration.  To  fix  this  warning,  declare
106              private  symbols static, and ensure that the files defining pub‐
107              lic symbols have the symbol declarations available  first  (such
108              as by including the appropriate header file).
109
110              Sparse  issues these warnings by default.  To turn them off, use
111              -Wno-decl.
112
113       -Wdefault-bitfield-sign
114              Warn about any bitfield with no explicit signedness.
115
116              Bitfields have no standard-specified  default  signedness.  (C99
117              6.7.2) A bitfield without an explicit signed or unsigned creates
118              a portability problem for software that relies on the  available
119              range  of  values.   To  fix  this, specify the bitfield type as
120              signed or unsigned explicitly.
121
122              Sparse does not issue these warnings by default.
123
124       -Wdo-while
125              Warn about do-while loops that do not delimit the loop body with
126              braces.
127
128              Sparse does not issue these warnings by default.
129
130       -Wenum-mismatch
131              Warn  about  the  use of an expression of an incorrect enum type
132              when initializing another enum type, assigning to  another  enum
133              type, or passing an argument to a function which expects another
134              enum type.
135
136              Sparse issues these warnings by default.  To turn them off,  use
137              -Wno-enum-mismatch.
138
139       -Wnon-pointer-null
140              Warn about the use of 0 as a NULL pointer.
141
142              0 has integer type.  NULL has pointer type.
143
144              Sparse  issues these warnings by default.  To turn them off, use
145              -Wno-non-pointer-null.
146
147       -Wold-initializer
148              Warn about the use of the pre-C99 GCC syntax for designated ini‐
149              tializers.
150
151              C99  provides  a standard syntax for designated fields in struct
152              or union initializers:
153
154              struct structname var = { .field = value };
155
156              GCC also has an old, non-standard syntax for designated initial‐
157              izers which predates C99:
158
159              struct structname var = { field: value };
160
161              Sparse  will warn about the use of GCC's non-standard syntax for
162              designated initializers.  To fix this  warning,  convert  desig‐
163              nated initializers to use the standard C99 syntax.
164
165              Sparse  issues these warnings by default.  To turn them off, use
166              -Wno-old-initializer.
167
168       -Wone-bit-signed-bitfield
169              Warn about any one-bit signed bitfields.
170
171              A one-bit signed bitfield can only have the values 0 and -1,  or
172              with  some compilers only 0; this results in unexpected behavior
173              for programs which expected the ability to store 0 and 1.
174
175              Sparse issues these warnings by default.  To turn them off,  use
176              -Wno-one-bit-signed-bitfield.
177
178       -Wparen-string
179              Warn  about  the  use of a parenthesized string to initialize an
180              array.
181
182              Standard C syntax does not permit a parenthesized string  as  an
183              array  initializer.   GCC  allows  this  syntax as an extension.
184              With -Wparen-string, Sparse will warn about this syntax.
185
186              Sparse does not issue these warnings by default.
187
188       -Wptr-subtraction-blows
189              Warn when subtracting two pointers to a type with  a  non-power-
190              of-two size.
191
192              Subtracting  two  pointers to a given type gives a difference in
193              terms of the number of items of that  type.   To  generate  this
194              value,  compilers  will usually need to divide the difference by
195              the size of the type, an  potentially  expensive  operation  for
196              sizes other than powers of two.
197
198              Code  written  using  pointer  subtraction can often use another
199              approach instead, such as array indexing with an explicit  array
200              index variable, which may allow compilers to generate more effi‐
201              cient code.
202
203              Sparse does not issue these warnings by default.
204
205       -Wreturn-void
206              Warn if a function with return type void returns a void  expres‐
207              sion.
208
209              C99 permits this, and in some cases this allows for more generic
210              code in macros that use typeof or take a type as a  macro  argu‐
211              ment.   However,  some  programs  consider  this poor style, and
212              those programs can use -Wreturn-void to get warnings about it.
213
214              Sparse does not issue these warnings by default.
215
216       -Wshadow
217              Warn when declaring a symbol which shadows  a  declaration  with
218              the same name in an outer scope.
219
220              Such declarations can lead to error-prone code.
221
222              Sparse does not issue these warnings by default.
223
224       -Wtransparent-union
225              Warn   about   any   declaration   using   the   GCC   extension
226              __attribute__((transparent_union)).
227
228              Sparse issues these warnings by default.  To turn them off,  use
229              -Wno-transparent-union.
230
231       -Wtypesign
232              Warn when converting a pointer to an integer type into a pointer
233              to an integer type with different signedness.
234
235              Sparse does not issue these warnings by default.
236
237       -Wundef
238              Warn about preprocessor conditionals that use the  value  of  an
239              undefined preprocessor symbol.
240
241              Standard  C (C99 6.10.1) permits using the value of an undefined
242              preprocessor symbol in preprocessor conditionals, and  specifies
243              it  has  have  a value of 0.  However, this behavior can lead to
244              subtle errors.
245
246              Sparse does not issue these warnings by default.
247

SEE ALSO

249       cgcc(1)
250

HOMEPAGE

252       http://www.kernel.org/pub/software/devel/sparse/
253

MAILING LIST

255       linux-sparse@vger.kernel.org
256

MAINTAINER

258       Josh Triplett <josh@kernel.org>
259
260
261
262                                                                     sparse(1)
Impressum