user_data: delete debug code
[smatch.git] / sparse.1
blob48dab7a9a5c103927f3f9524b7b3d8339670f4c1
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 \-fmax-errors=COUNT
24 Set the maximum number of displayed errors to COUNT, which should be
25 a numerical value or 'unlimited'.
26 The default limit is 100.
28 .TP
29 .B \-fmax-warnings=COUNT
30 Set the maximum number of displayed warnings to COUNT, which should be
31 a numerical value or 'unlimited'.
32 The default limit is 100.
34 .TP
35 .B \-Wsparse\-all
36 Turn on all sparse warnings, except for those explicitly disabled via
37 \fB\-Wno\-something\fR.
38 .TP
39 .B \-Wsparse\-error
40 Turn all sparse warnings into errors.
41 .TP
42 .B \-Waddress\-space
43 Warn about code which mixes pointers to different address spaces.
45 Sparse allows an extended attribute
46 .BI __attribute__((address_space( id )))
47 on pointers, which designates a pointer target in address space \fIid\fR (an
48 identifier or a constant integer).
49 With \fB\-Waddress\-space\fR, Sparse treats pointers with
50 identical target types but different address spaces as distinct types and
51 will warn accordingly.
53 Sparse will also warn on casts which remove the address space (casts to an
54 integer type or to a plain pointer type). An exception to this is when the
55 destination type is \fBuintptr_t\fR (or \fBunsigned long\fR) since such casts
56 are often used to "get a pointer value representation in an integer type" and
57 such values are independent of the address space.
59 To override these warnings, use a type that includes \fB__attribute__((force))\fR.
61 Sparse issues these warnings by default.  To turn them off, use
62 \fB\-Wno\-address\-space\fR.
64 .TP
65 .B \-Wbitwise
66 Warn about unsupported operations or type mismatches with restricted integer
67 types.
69 Sparse supports an extended attribute, \fB__attribute__((bitwise))\fR, which
70 creates a new restricted integer type from a base integer type, distinct from
71 the base integer type and from any other restricted integer type not declared
72 in the same declaration or \fBtypedef\fR.  For example, this allows programs
73 to create \fBtypedef\fRs for integer types with specific endianness.  With
74 \fB-Wbitwise\fR, Sparse will warn on any use of a restricted type in
75 arithmetic operations other than bitwise operations, and on any conversion of
76 one restricted type into another, except via a cast that includes
77 \fB__attribute__((force))\fR.
79 __bitwise ends up being a "stronger integer separation", one that
80 doesn't allow you to mix with non-bitwise integers, so now it's much
81 harder to lose the type by mistake.
83 __bitwise is for *unique types* that cannot be mixed with other
84 types, and that you'd never want to just use as a random integer (the
85 integer 0 is special, though, and gets silently accepted iirc - it's
86 kind of like "NULL" for pointers). So "gfp_t" or the "safe endianness"
87 types would be __bitwise: you can only operate on them by doing
88 specific operations that know about *that* particular type.
90 Sparse issues these warnings by default.  To turn them off, use
91 \fB\-Wno\-bitwise\fR.
93 .TP
94 .B \-Wbitwise\-pointer
95 Same as \fB\-Wbitwise\fR but for casts to or from pointers to bitwise types.
97 Sparse does not issue these warnings by default.
99 .TP
100 .B \-Wcast\-from\-as
101 Warn about casts which remove an address space from a pointer type.
103 This is similar to \fB\-Waddress\-space\fR but will also warn
104 on casts to \fBunsigned long\fR.
106 Sparse does not issues these warnings by default.
109 .B \-Wcast\-to\-as
110 Warn about casts which add an address space to a pointer type.
112 A cast that includes \fB__attribute__((force))\fR will suppress this warning.
113 No warning is generated if the original type is \fBuintptr_t\fR
114 (or \fBunsigned long\fR).
116 Sparse does not issue these warnings by default.
119 .B \-Wcast\-truncate
120 Warn about casts that truncate constant values.
122 Sparse issues these warnings by default.  To turn them off, use
123 \fB\-Wno\-cast\-truncate\fR.
126 .B \-Wconstant\-suffix
127 Warn if an integer constant is larger than the maximum representable value
128 of the type indicated by its type suffix (if any). For example, on a
129 system where ints are 32-bit and longs 64-bit, the constant \fB0x100000000U\fR
130 is larger than can be represented by an \fBunsigned int\fR but fits in an
131 \fBunsigned long\fR. So its type is \fBunsigned long\fR but this is not
132 indicated by its suffix. In this case, the warning could be suppressed by
133 using the suffix \fBUL\fR: \fB0x100000000UL\fR.
135 Sparse does not issue these warnings by default.
138 .B \-Wconstexpr-not-const
139 Warn if a non-constant expression is encountered when really expecting a
140 constant expression instead.
141 Currently, this warns when initializing an object of static storage duration
142 with an initializer which is not a constant expression.
144 Sparse does not issue these warnings by default.
147 .B \-Wcontext
148 Warn about potential errors in synchronization or other delimited contexts.
150 Sparse supports several means of designating functions or statements that
151 delimit contexts, such as synchronization.  Functions with the extended
152 attribute
153 .BI __attribute__((context( expression , in_context , out_context ))
154 require the context \fIexpression\fR (for instance, a lock) to have the value
155 \fIin_context\fR (a constant nonnegative integer) when called, and return with
156 the value \fIout_context\fR (a constant nonnegative integer).  For APIs
157 defined via macros, use the statement form
158 .BI __context__( expression , in_value , out_value )
159 in the body of the macro.
161 With \fB-Wcontext\fR Sparse will warn when it sees a function change the
162 context without indicating this with a \fBcontext\fR attribute, either by
163 decreasing a context below zero (such as by releasing a lock without acquiring
164 it), or returning with a changed context (such as by acquiring a lock without
165 releasing it).  Sparse will also warn about blocks of code which may
166 potentially execute with different contexts.
168 Sparse issues these warnings by default.  To turn them off, use
169 \fB\-Wno\-context\fR.
172 .B \-Wdecl
173 Warn about any non-\fBstatic\fR variable or function definition that has no
174 previous declaration.
176 Private symbols (functions and variables) internal to a given source file
177 should use \fBstatic\fR, to allow additional compiler optimizations, allow
178 detection of unused symbols, and prevent other code from relying on these
179 internal symbols.  Public symbols used by other source files will need
180 declarations visible to those other source files, such as in a header file.
181 All declarations should fall into one of these two categories.  Thus, with
182 \fB-Wdecl\fR, Sparse warns about any symbol definition with neither
183 \fBstatic\fR nor a declaration.  To fix this warning, declare private symbols
184 \fBstatic\fR, and ensure that the files defining public symbols have the
185 symbol declarations available first (such as by including the appropriate
186 header file).
188 Sparse issues these warnings by default.  To turn them off, use
189 \fB\-Wno\-decl\fR.
192 .B \-Wdeclaration-after-statement
193 Warn about declarations that are not at the start of a block.
195 These declarations are permitted in C99 but not in C89.
197 Sparse issues these warnings by default only when the C dialect is
198 C89 (i.e. -ansi or -std=c89).  To turn them off, use
199 \fB\-Wno\-declaration\-after\-statement\fR.
202 .B \-Wdefault\-bitfield\-sign
203 Warn about any bitfield with no explicit signedness.
205 Bitfields have no standard-specified default signedness. (C99 6.7.2) A
206 bitfield without an explicit \fBsigned\fR or \fBunsigned\fR creates a
207 portability problem for software that relies on the available range of values.
208 To fix this, specify the bitfield type as \fBsigned\fR or \fBunsigned\fR
209 explicitly.
211 Sparse does not issue these warnings by default.
214 .B \-Wdesignated\-init
215 Warn about positional initialization of structs marked as requiring designated
216 initializers.
218 Sparse allows an attribute
219 .BI __attribute__((designated_init))
220 which marks a struct as requiring designated initializers.  Sparse will warn
221 about positional initialization of a struct variable or struct literal of a
222 type that has this attribute.
224 Requiring designated initializers for a particular struct type will insulate
225 code using that struct type from changes to the layout of the type, avoiding
226 the need to change initializers for that type unless they initialize a removed
227 or incompatibly changed field.
229 Common examples of this type of struct include collections of function pointers
230 for the implementations of a class of related operations, for which the default
231 NULL for an unmentioned field in a designated initializer will correctly
232 indicate the absence of that operation.
234 Sparse issues these warnings by default.  To turn them off, use
235 \fB\-Wno\-designated\-init\fR.
238 .B \-Wdo\-while
239 Warn about do-while loops that do not delimit the loop body with braces.
241 Sparse does not issue these warnings by default.
244 .B \-Wenum\-mismatch
245 Warn about the use of an expression of an incorrect \fBenum\fR type when
246 initializing another \fBenum\fR type, assigning to another \fBenum\fR type, or
247 passing an argument to a function which expects another \fBenum\fR type.
249 Sparse issues these warnings by default.  To turn them off, use
250 \fB\-Wno\-enum\-mismatch\fR.
253 .B \-Wexternal\-function\-has\-definition
254 Warn about function definitions that are declared with external linkage.
256 Sparse issues these warnings by default.  To turn them off, use
257 \fB\-Wno\-external\-function\-has\-definition\fR.
260 .B \-Winit\-cstring
261 Warn about initialization of a char array with a too long constant C string.
263 If the size of the char array and the length of the string are the same,
264 there is no space for the last nul char of the string in the array:
267 char s[3] = "abc";
270 If the array is used as a byte array, not as C string, this
271 warning is just noise. However, if the array is passed to functions
272 dealing with C string like printf(%s) and strcmp, it may cause a
273 trouble.
275 Sparse does not issue these warnings by default.
278 .B \-Wmemcpy\-max\-count
279 Warn about call of \fBmemcpy()\fR, \fBmemset()\fR, \fBcopy_from_user()\fR, or
280 \fBcopy_to_user()\fR with a large compile-time byte count.
282 Sparse issues these warnings by default. To turn them off, use
283 \fB\-Wno\-memcpy\-max\-count\fR.
285 The limit can be changed with \fB\-fmemcpy\-max\-count=COUNT\fR,
286 the default being \fB100000\fR.
289 .B \-Wnewline\-eof
290 Warn if the input file doesn't end with a newline.
292 Sparse issues these warnings by default.  To turn them off, use
293 \fB\-Wno\-newline\-eof\fR.
296 .B \-Wnon\-pointer\-null
297 Warn about the use of 0 as a NULL pointer.
299 0 has integer type.  NULL has pointer type.
301 Sparse issues these warnings by default.  To turn them off, use
302 \fB\-Wno\-non\-pointer\-null\fR.
305 .B \-Wold\-initializer
306 Warn about the use of the pre-C99 GCC syntax for designated initializers.
308 C99 provides a standard syntax for designated fields in \fBstruct\fR or
309 \fBunion\fR initializers:
312 struct structname var = { .field = value };
315 GCC also has an old, non-standard syntax for designated initializers which
316 predates C99:
319 struct structname var = { field: value };
322 Sparse will warn about the use of GCC's non-standard syntax for designated
323 initializers.  To fix this warning, convert designated initializers to use the
324 standard C99 syntax.
326 Sparse issues these warnings by default.  To turn them off, use
327 \fB\-Wno\-old\-initializer\fR.
330 .B \-Wone\-bit\-signed\-bitfield
331 Warn about any one-bit \fBsigned\fR bitfields.
333 A one-bit \fBsigned\fR bitfield can only have the values 0 and -1, or with
334 some compilers only 0; this results in unexpected behavior for programs which
335 expected the ability to store 0 and 1.
337 Sparse issues these warnings by default.  To turn them off, use
338 \fB\-Wno\-one\-bit\-signed\-bitfield\fR.
341 .B \-Wparen\-string
342 Warn about the use of a parenthesized string to initialize an array.
344 Standard C syntax does not permit a parenthesized string as an array
345 initializer.  GCC allows this syntax as an extension.  With
346 \fB\-Wparen\-string\fR, Sparse will warn about this syntax.
348 Sparse does not issue these warnings by default.
351 .B -Wpast-deep-designator
352 Warn when, in a initializer-list, a initializer with a deep (nested)
353 designator is followed by a non-designated one.
355 Sparse does not issue these warnings by default.
358 .B \-Wpointer\-arith
359 Warn about anything that depends on the \fBsizeof\fR a void or function type.
361 C99 does not allow the \fBsizeof\fR operator to be applied to function types
362 or to incomplete types such as void. GCC allows \fBsizeof\fR to be applied to
363 these types as an extension and assigns these types a size of \fI1\fR. With
364 \fB\-pointer\-arith\fR, Sparse will warn about pointer arithmetic on void
365 or function pointers, as well as expressions which directly apply the
366 \fBsizeof\fR operator to void or function types.
368 Sparse does not issue these warnings by default.
371 .B \-Wptr\-subtraction\-blows
372 Warn when subtracting two pointers to a type with a non-power-of-two size.
374 Subtracting two pointers to a given type gives a difference in terms of the
375 number of items of that type.  To generate this value, compilers will usually
376 need to divide the difference by the size of the type, an potentially
377 expensive operation for sizes other than powers of two.
379 Code written using pointer subtraction can often use another approach instead,
380 such as array indexing with an explicit array index variable, which may allow
381 compilers to generate more efficient code.
383 Sparse does not issue these warnings by default.
386 .B \-Wreturn\-void
387 Warn if a function with return type void returns a void expression.
389 C99 permits this, and in some cases this allows for more generic code in
390 macros that use typeof or take a type as a macro argument.  However, some
391 programs consider this poor style, and those programs can use
392 \fB\-Wreturn\-void\fR to get warnings about it.
394 Sparse does not issue these warnings by default.
397 .B \-Wshadow
398 Warn when declaring a symbol which shadows a declaration with the same name in
399 an outer scope.
401 Such declarations can lead to error-prone code.
403 Sparse does not issue these warnings by default.
406 .B \-Wshift-count-negative
407 Warn if a shift count is negative.
409 Sparse issues these warnings by default.
412 .B \-Wshift-count-overflow
413 Warn if a shift count is bigger than the operand's width.
415 Sparse issues these warnings by default.
418 .B \-Wsizeof-bool
419 Warn when checking the sizeof a _Bool.
421 C99 does not specify the size of a _Bool. GCC, by default, uses \fI1\fR.
423 Sparse does not issue these warnings by default.
426 .B \-Wtransparent\-union
427 Warn about any declaration using the GCC extension
428 \fB__attribute__((transparent_union))\fR.
430 Sparse issues these warnings by default.  To turn them off, use
431 \fB\-Wno\-transparent\-union\fR.
434 .B \-Wtypesign
435 Warn when converting a pointer to an integer type into a pointer to an integer
436 type with different signedness.
438 Sparse does not issue these warnings by default.
441 .B \-Wundef
442 Warn about preprocessor conditionals that use the value of an undefined
443 preprocessor symbol.
445 Standard C (C99 6.10.1) permits using the value of an undefined preprocessor
446 symbol in preprocessor conditionals, and specifies it has a value of 0.
447 However, this behavior can lead to subtle errors.
449 Sparse does not issue these warnings by default.
452 .B \-Wuniversal\-initializer
453 Do not suppress warnings caused by using '{\ 0\ }' instead of '{\ }' on
454 aggregate types, ignoring its special status as universal initializer.
455 The concerned warnings are, for example, those triggered by
456 \fB\-Wdesignated\-init\fR or \fB\-Wnon\-pointer\-null\fR.
458 Sparse does not issue these warnings by default, processing '{\ 0\ }'
459 the same as '{\ }'.
462 .B -Wunion-cast
463 Warn on casts to union types.
465 Sparse does not issues these warnings by default.
467 .SH MISC OPTIONS
469 .B \-\-arch=\fIARCH\fR
470 Specify the target architecture.
471 For architectures having both a 32-bit and a 64-bit variant (mips, powerpc,
472 riscv and sparc) the architecture name can be suffixed with \fI32\fR or \fI64\fR.
474 The default architecture and size is the one of the machine used to build Sparse.
477 .B \-gcc-base-dir \fIdir\fR
478 Look for compiler-provided system headers in \fIdir\fR/include/ and \fIdir\fR/include-fixed/.
481 .B \-multiarch-dir \fIdir\fR
482 Look for system headers in the multiarch subdirectory \fIdir\fR.
483 The \fIdir\fR name would normally take the form of the target's
484 normalized GNU triplet. (e.g. i386-linux-gnu).
487 .B --os=\fIOS\fR
488 Specify the target Operating System.
489 This only makes a few differences with the predefined types.
490 The accepted values are: linux, unix, freebsd, netbsd, opensd, sunos, darwin
491 and cygwin.
493 The default OS is the one of the machine used to build Sparse if it can be
494 detected, otherwise some generic settings are used.
496 .SH DEBUG OPTIONS
498 .B \-fmem-report
499 Report some statistics about memory allocation used by the tool.
501 .SH OTHER OPTIONS
503 .B \-fdiagnostic-prefix[=PREFIX]
504 Prefix all diagnostics by the given PREFIX, followed by ": ".
505 If no one is given "sparse" is used.
506 The default is to not use a prefix at all.
509 .B \-fmemcpy-max-count=COUNT
510 Set the limit for the warnings given by \fB-Wmemcpy-max-count\fR.
511 A COUNT of 'unlimited' or '0' will effectively disable the warning.
512 The default limit is 100000.
515 .B \-ftabstop=WIDTH
516 Set the distance between tab stops.  This helps sparse report correct
517 column numbers in warnings or errors.  If the value is less than 1 or
518 greater than 100, the option is ignored.  The default is 8.
521 .B \-f[no-]unsigned-char, \-f[no-]signed-char
522 Let plain 'char' be unsigned or signed.
523 By default chars are signed.
525 .SH SEE ALSO
526 .BR cgcc (1)
528 .SH HOMEPAGE
529 https://sparse.docs.kernel.org
531 .SH MAILING LIST
532 linux-sparse@vger.kernel.org
534 .SH CONTRIBUTING AND REPORTING BUGS
535 Submission of patches and reporting of bugs, as well as discussions
536 related to Sparse, should be done via the mailing list (linux-sparse@vger.kernel.org)
537 where the development and maintenance is primarily done.
538 You do not have to be subscribed to the list to send a message there.
540 Bugs can also be reported and tracked via the Linux kernel's bugzilla:
541 http://bugzilla.kernel.org/enter_bug.cgi?component=Sparse&product=Tools .
543 .SH DOCUMENTATION
544 More documentation about Sparse can be found at
545 https://sparse.docs.kernel.org
547 .SH AUTHORS
548 Sparse was started by Linus Torvalds.
549 The complete list of contributors can be find at
550 https://www.openhub.net/p/sparse/contributors .
552 Luc Van Oostenryck is Sparse's current maintainer.