db: caller info needs to record the -1 parameters
[smatch.git] / sparse.1
blobbde6b6d6c744a14efa261fd414e39738bb2ebe0e
1 .\" Sparse manpage by Josh Triplett
2 .TH sparse "1"
4 .SH NAME
5 sparse \- Semantic Parser for C
7 .SH SYNOPSIS
8 .B sparse
9 [\fIWARNING OPTIONS\fR]... \fIfile.c\fR
11 .SH DESCRIPTION
12 Sparse parses C source and looks for errors, producing warnings on standard
13 error.
15 Sparse accepts options controlling the set of warnings to generate.  To turn
16 on warnings Sparse does not issue by default, use the corresponding warning
17 option \fB\-Wsomething\fR.  Sparse issues some warnings by default; to turn
18 off those warnings, pass the negation of the associated warning option,
19 \fB\-Wno\-something\fR.
21 .SH WARNING OPTIONS
22 .TP
23 .B \-Wsparse\-all
24 Turn on all sparse warnings, except for those explicitly disabled via
25 \fB\-Wno\-something\fR.
26 .TP
27 .B \-Waddress\-space
28 Warn about code which mixes pointers to different address spaces.
30 Sparse allows an extended attribute
31 .BI __attribute__((address_space( num )))
32 on pointers, which designates a pointer target in address space \fInum\fR (a
33 constant integer).  With \fB\-Waddress\-space\fR, Sparse treats pointers with
34 identical target types but different address spaces as distinct types.  To
35 override this warning, such as for functions which convert pointers between
36 address spaces, use a type that includes \fB__attribute__((force))\fR.
38 Sparse issues these warnings by default.  To turn them off, use
39 \fB\-Wno\-address\-space\fR.
41 .TP
42 .B \-Wbitwise
43 Warn about unsupported operations or type mismatches with restricted integer
44 types.
46 Sparse supports an extended attribute, \fB__attribute__((bitwise))\fR, which
47 creates a new restricted integer type from a base integer type, distinct from
48 the base integer type and from any other restricted integer type not declared
49 in the same declaration or \fBtypedef\fR.  For example, this allows programs
50 to create \fBtypedef\fRs for integer types with specific endianness.  With
51 \fB-Wbitwise\fR, Sparse will warn on any use of a restricted type in
52 arithmetic operations other than bitwise operations, and on any conversion of
53 one restricted type into another, except via a cast that includes
54 \fB__attribute__((force))\fR.
56 Sparse does not issue these warnings by default.
58 .TP
59 .B \-Wcast\-to\-as
60 Warn about casts which add an address space to a pointer type.
62 A cast that includes \fB__attribute__((force))\fR will suppress this warning.
64 Sparse does not issue these warnings by default.
66 .TP
67 .B \-Wcast\-truncate
68 Warn about casts that truncate constant values.
70 Sparse issues these warnings by default.  To turn them off, use
71 \fB\-Wno\-cast\-truncate\fR.
73 .TP
74 .B \-Wcontext
75 Warn about potential errors in synchronization or other delimited contexts.
77 Sparse supports several means of designating functions or statements that
78 delimit contexts, such as synchronization.  Functions with the extended
79 attribute
80 .BI __attribute__((context( expression , in_context , out_context ))
81 require the context \fIexpression\fR (for instance, a lock) to have the value
82 \fIin_context\fR (a constant nonnegative integer) when called, and return with
83 the value \fIout_context\fR (a constant nonnegative integer).  For APIs
84 defined via macros, use the statement form
85 .BI __context__( expression , in_value , out_value )
86 in the body of the macro.
88 With \fB-Wcontext\fR Sparse will warn when it sees a function change the
89 context without indicating this with a \fBcontext\fR attribute, either by
90 decreasing a context below zero (such as by releasing a lock without acquiring
91 it), or returning with a changed context (such as by acquiring a lock without
92 releasing it).  Sparse will also warn about blocks of code which may
93 potentially execute with different contexts.
95 Sparse issues these warnings by default.  To turn them off, use
96 \fB\-Wno\-context\fR.
98 .TP
99 .B \-Wdecl
100 Warn about any non-\fBstatic\fR variable or function definition that has no
101 previous declaration.
103 Private symbols (functions and variables) internal to a given source file
104 should use \fBstatic\fR, to allow additional compiler optimizations, allow
105 detection of unused symbols, and prevent other code from relying on these
106 internal symbols.  Public symbols used by other source files will need
107 declarations visible to those other source files, such as in a header file.
108 All declarations should fall into one of these two categories.  Thus, with
109 \fB-Wdecl\fR, Sparse warns about any symbol definition with neither
110 \fBstatic\fR nor a declaration.  To fix this warning, declare private symbols
111 \fBstatic\fR, and ensure that the files defining public symbols have the
112 symbol declarations available first (such as by including the appropriate
113 header file).
115 Sparse issues these warnings by default.  To turn them off, use
116 \fB\-Wno\-decl\fR.
119 .B \-Wdeclaration-after-statement
120 Warn about declarations that are not at the start of a block.
122 These declarations are permitted in C99 but not in C89.
124 Sparse issues these warnings by default only when the C dialect is
125 C89 (i.e. -ansi or -std=c89).  To turn them off, use
126 \fB\-Wno\-declaration\-after\-statement\fR.
129 .B \-Wdefault\-bitfield\-sign
130 Warn about any bitfield with no explicit signedness.
132 Bitfields have no standard-specified default signedness. (C99 6.7.2) A
133 bitfield without an explicit \fBsigned\fR or \fBunsigned\fR creates a
134 portability problem for software that relies on the available range of values.
135 To fix this, specify the bitfield type as \fBsigned\fR or \fBunsigned\fR
136 explicitly.
138 Sparse does not issue these warnings by default.
141 .B \-Wdesignated\-init
142 Warn about positional initialization of structs marked as requiring designated
143 initializers.
145 Sparse allows an attribute
146 .BI __attribute__((designated_init))
147 which marks a struct as requiring designated initializers.  Sparse will warn
148 about positional initialization of a struct variable or struct literal of a
149 type that has this attribute.
151 Requiring designated initializers for a particular struct type will insulate
152 code using that struct type from changes to the layout of the type, avoiding
153 the need to change initializers for that type unless they initialize a removed
154 or incompatibly changed field.
156 Common examples of this type of struct include collections of function pointers
157 for the implementations of a class of related operations, for which the default
158 NULL for an unmentioned field in a designated initializer will correctly
159 indicate the absence of that operation.
161 Sparse issues these warnings by default.  To turn them off, use
162 \fB\-Wno\-designated\-init\fR.
165 .B \-Wdo\-while
166 Warn about do-while loops that do not delimit the loop body with braces.
168 Sparse does not issue these warnings by default.
171 .B \-Wenum\-mismatch
172 Warn about the use of an expression of an incorrect \fBenum\fR type when
173 initializing another \fBenum\fR type, assigning to another \fBenum\fR type, or
174 passing an argument to a function which expects another \fBenum\fR type.
176 Sparse issues these warnings by default.  To turn them off, use
177 \fB\-Wno\-enum\-mismatch\fR.
180 .B \-Wnon\-pointer\-null
181 Warn about the use of 0 as a NULL pointer.
183 0 has integer type.  NULL has pointer type.
185 Sparse issues these warnings by default.  To turn them off, use
186 \fB\-Wno\-non\-pointer\-null\fR.
189 .B \-Wold\-initializer
190 Warn about the use of the pre-C99 GCC syntax for designated initializers.
192 C99 provides a standard syntax for designated fields in \fBstruct\fR or
193 \fBunion\fR initializers:
196 struct structname var = { .field = value };
199 GCC also has an old, non-standard syntax for designated initializers which
200 predates C99:
203 struct structname var = { field: value };
206 Sparse will warn about the use of GCC's non-standard syntax for designated
207 initializers.  To fix this warning, convert designated initializers to use the
208 standard C99 syntax.
210 Sparse issues these warnings by default.  To turn them off, use
211 \fB\-Wno\-old\-initializer\fR.
214 .B \-Wone\-bit\-signed\-bitfield
215 Warn about any one-bit \fBsigned\fR bitfields.
217 A one-bit \fBsigned\fR bitfield can only have the values 0 and -1, or with
218 some compilers only 0; this results in unexpected behavior for programs which
219 expected the ability to store 0 and 1.
221 Sparse issues these warnings by default.  To turn them off, use
222 \fB\-Wno\-one\-bit\-signed\-bitfield\fR.
225 .B \-Wparen\-string
226 Warn about the use of a parenthesized string to initialize an array.
228 Standard C syntax does not permit a parenthesized string as an array
229 initializer.  GCC allows this syntax as an extension.  With
230 \fB\-Wparen\-string\fR, Sparse will warn about this syntax.
232 Sparse does not issue these warnings by default.
235 .B \-Wptr\-subtraction\-blows
236 Warn when subtracting two pointers to a type with a non-power-of-two size.
238 Subtracting two pointers to a given type gives a difference in terms of the
239 number of items of that type.  To generate this value, compilers will usually
240 need to divide the difference by the size of the type, an potentially
241 expensive operation for sizes other than powers of two.
243 Code written using pointer subtraction can often use another approach instead,
244 such as array indexing with an explicit array index variable, which may allow
245 compilers to generate more efficient code.
247 Sparse does not issue these warnings by default.
250 .B \-Wreturn\-void
251 Warn if a function with return type void returns a void expression.
253 C99 permits this, and in some cases this allows for more generic code in
254 macros that use typeof or take a type as a macro argument.  However, some
255 programs consider this poor style, and those programs can use
256 \fB\-Wreturn\-void\fR to get warnings about it.
258 Sparse does not issue these warnings by default.
261 .B \-Wshadow
262 Warn when declaring a symbol which shadows a declaration with the same name in
263 an outer scope.
265 Such declarations can lead to error-prone code.
267 Sparse does not issue these warnings by default.
270 .B \-Wtransparent\-union
271 Warn about any declaration using the GCC extension
272 \fB__attribute__((transparent_union))\fR.
274 Sparse issues these warnings by default.  To turn them off, use
275 \fB\-Wno\-transparent\-union\fR.
278 .B \-Wtypesign
279 Warn when converting a pointer to an integer type into a pointer to an integer
280 type with different signedness.
282 Sparse does not issue these warnings by default.
285 .B \-Wundef
286 Warn about preprocessor conditionals that use the value of an undefined
287 preprocessor symbol.
289 Standard C (C99 6.10.1) permits using the value of an undefined preprocessor
290 symbol in preprocessor conditionals, and specifies it has have a value of 0.
291 However, this behavior can lead to subtle errors.
293 Sparse does not issue these warnings by default.
295 .SH MISC OPTIONS
297 .B \-gcc-base-dir \fIdir\fR
298 Look for compiler-provided system headers in \fIdir\fR/include/ and \fIdir\fR/include-fixed/.
300 .SH OTHER OPTIONS
302 .B \-ftabstop=WIDTH
303 Set the distance between tab stops.  This helps sparse report correct
304 column numbers in warnings or errors.  If the value is less than 1 or
305 greater than 100, the option is ignored.  The default is 8.
307 .SH SEE ALSO
308 .BR cgcc (1)
310 .SH HOMEPAGE
311 http://www.kernel.org/pub/software/devel/sparse/
313 .SH MAILING LIST
314 linux-sparse@vger.kernel.org
316 .SH MAINTAINER
317 Josh Triplett <josh@kernel.org>