kernel.return_fixes: add mipi_dsi_device_transfer(), timer_delete() and get_device()
[smatch.git] / sparse.1
blob430b3710b260bd25b8063adc5f770b6d9e84c74e
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 -Wflexible-array-array
261 Warn about arrays of structures containing a flexible array.
263 Sparse issues these warnings by default. To turn them off, use
264 \fB-Wno-flexible-array-array\fR.
267 .B -Wflexible-array-nested
268 Warn about structures containing a flexible array being contained into
269 another structure, union or array.
271 Sparse does not issue these warnings by default.
274 .B -Wflexible-array-sizeof
275 Warn about using the sizeof operator on a structure containing a flexible array,
276 possibly recursively.
278 Sparse does not issue these warnings by default.
281 .B -Wflexible-array-union
282 Enable the warnings regarding flexible arrays and unions.
283 To have any effect, at least one of \fB-Wflexible-array-array\fR,
284 \fB-Wflexible-array-nested\fR or \fB-Wflexible-array-sizeof\fR must also
285 be enabled.
287 Sparse does issue these warnings by default.
290 .B \-Winit\-cstring
291 Warn about initialization of a char array with a too long constant C string.
293 If the size of the char array and the length of the string are the same,
294 there is no space for the last nul char of the string in the array:
297 char s[3] = "abc";
300 If the array is used as a byte array, not as C string, this
301 warning is just noise. However, if the array is passed to functions
302 dealing with C string like printf(%s) and strcmp, it may cause a
303 trouble.
305 Sparse does not issue these warnings by default.
308 .B \-Wmemcpy\-max\-count
309 Warn about call of \fBmemcpy()\fR, \fBmemset()\fR, \fBcopy_from_user()\fR, or
310 \fBcopy_to_user()\fR with a large compile-time byte count.
312 Sparse issues these warnings by default. To turn them off, use
313 \fB\-Wno\-memcpy\-max\-count\fR.
315 The limit can be changed with \fB\-fmemcpy\-max\-count=COUNT\fR,
316 the default being \fB100000\fR.
319 .B \-Wnewline\-eof
320 Warn if the input file doesn't end with a newline.
322 Sparse issues these warnings by default.  To turn them off, use
323 \fB\-Wno\-newline\-eof\fR.
326 .B \-Wnon\-pointer\-null
327 Warn about the use of 0 as a NULL pointer.
329 0 has integer type.  NULL has pointer type.
331 Sparse issues these warnings by default.  To turn them off, use
332 \fB\-Wno\-non\-pointer\-null\fR.
335 .B \-Wold\-initializer
336 Warn about the use of the pre-C99 GCC syntax for designated initializers.
338 C99 provides a standard syntax for designated fields in \fBstruct\fR or
339 \fBunion\fR initializers:
342 struct structname var = { .field = value };
345 GCC also has an old, non-standard syntax for designated initializers which
346 predates C99:
349 struct structname var = { field: value };
352 Sparse will warn about the use of GCC's non-standard syntax for designated
353 initializers.  To fix this warning, convert designated initializers to use the
354 standard C99 syntax.
356 Sparse issues these warnings by default.  To turn them off, use
357 \fB\-Wno\-old\-initializer\fR.
360 .B \-Wone\-bit\-signed\-bitfield
361 Warn about any one-bit \fBsigned\fR bitfields.
363 A one-bit \fBsigned\fR bitfield can only have the values 0 and -1, or with
364 some compilers only 0; this results in unexpected behavior for programs which
365 expected the ability to store 0 and 1.
367 Sparse issues these warnings by default.  To turn them off, use
368 \fB\-Wno\-one\-bit\-signed\-bitfield\fR.
371 .B \-Wparen\-string
372 Warn about the use of a parenthesized string to initialize an array.
374 Standard C syntax does not permit a parenthesized string as an array
375 initializer.  GCC allows this syntax as an extension.  With
376 \fB\-Wparen\-string\fR, Sparse will warn about this syntax.
378 Sparse does not issue these warnings by default.
381 .B -Wpast-deep-designator
382 Warn when, in a initializer-list, a initializer with a deep (nested)
383 designator is followed by a non-designated one.
385 Sparse does not issue these warnings by default.
388 .B \-Wpointer\-arith
389 Warn about anything that depends on the \fBsizeof\fR a void or function type.
391 C99 does not allow the \fBsizeof\fR operator to be applied to function types
392 or to incomplete types such as void. GCC allows \fBsizeof\fR to be applied to
393 these types as an extension and assigns these types a size of \fI1\fR. With
394 \fB\-pointer\-arith\fR, Sparse will warn about pointer arithmetic on void
395 or function pointers, as well as expressions which directly apply the
396 \fBsizeof\fR operator to void or function types.
398 Sparse does not issue these warnings by default.
401 .B \-Wptr\-subtraction\-blows
402 Warn when subtracting two pointers to a type with a non-power-of-two size.
404 Subtracting two pointers to a given type gives a difference in terms of the
405 number of items of that type.  To generate this value, compilers will usually
406 need to divide the difference by the size of the type, an potentially
407 expensive operation for sizes other than powers of two.
409 Code written using pointer subtraction can often use another approach instead,
410 such as array indexing with an explicit array index variable, which may allow
411 compilers to generate more efficient code.
413 Sparse does not issue these warnings by default.
416 .B \-Wreturn\-void
417 Warn if a function with return type void returns a void expression.
419 C99 permits this, and in some cases this allows for more generic code in
420 macros that use typeof or take a type as a macro argument.  However, some
421 programs consider this poor style, and those programs can use
422 \fB\-Wreturn\-void\fR to get warnings about it.
424 Sparse does not issue these warnings by default.
427 .B \-Wshadow
428 Warn when declaring a symbol which shadows a declaration with the same name in
429 an outer scope.
431 Such declarations can lead to error-prone code.
433 Sparse does not issue these warnings by default.
436 .B \-Wshift-count-negative
437 Warn if a shift count is negative.
439 Sparse issues these warnings by default.
442 .B \-Wshift-count-overflow
443 Warn if a shift count is bigger than the operand's width.
445 Sparse issues these warnings by default.
448 .B \-Wsizeof-bool
449 Warn when checking the sizeof a _Bool.
451 C99 does not specify the size of a _Bool. GCC, by default, uses \fI1\fR.
453 Sparse does not issue these warnings by default.
456 .B \-Wtransparent\-union
457 Warn about any declaration using the GCC extension
458 \fB__attribute__((transparent_union))\fR.
460 Sparse issues these warnings by default.  To turn them off, use
461 \fB\-Wno\-transparent\-union\fR.
464 .B \-Wtypesign
465 Warn when converting a pointer to an integer type into a pointer to an integer
466 type with different signedness.
468 Sparse does not issue these warnings by default.
471 .B \-Wundef
472 Warn about preprocessor conditionals that use the value of an undefined
473 preprocessor symbol.
475 Standard C (C99 6.10.1) permits using the value of an undefined preprocessor
476 symbol in preprocessor conditionals, and specifies it has a value of 0.
477 However, this behavior can lead to subtle errors.
479 Sparse does not issue these warnings by default.
482 .B \-Wuniversal\-initializer
483 Do not suppress warnings caused by using '{\ 0\ }' instead of '{\ }' on
484 aggregate types, ignoring its special status as universal initializer.
485 The concerned warnings are, for example, those triggered by
486 \fB\-Wdesignated\-init\fR or \fB\-Wnon\-pointer\-null\fR.
488 Sparse does not issue these warnings by default, processing '{\ 0\ }'
489 the same as '{\ }'.
492 .B -Wunion-cast
493 Warn on casts to union types.
495 Sparse does not issues these warnings by default.
497 .SH MISC OPTIONS
499 .B \-\-arch=\fIARCH\fR
500 Specify the target architecture.
501 For architectures having both a 32-bit and a 64-bit variant (mips, powerpc,
502 riscv and sparc) the architecture name can be suffixed with \fI32\fR or \fI64\fR.
504 The default architecture and size is the one of the machine used to build Sparse.
507 .B \-gcc-base-dir \fIdir\fR
508 Look for compiler-provided system headers in \fIdir\fR/include/ and \fIdir\fR/include-fixed/.
511 .B \-multiarch-dir \fIdir\fR
512 Look for system headers in the multiarch subdirectory \fIdir\fR.
513 The \fIdir\fR name would normally take the form of the target's
514 normalized GNU triplet. (e.g. i386-linux-gnu).
517 .B --os=\fIOS\fR
518 Specify the target Operating System.
519 This only makes a few differences with the predefined types.
520 The accepted values are: linux, unix, freebsd, netbsd, opensd, sunos, darwin
521 and cygwin.
523 The default OS is the one of the machine used to build Sparse if it can be
524 detected, otherwise some generic settings are used.
526 .SH DEBUG OPTIONS
528 .B \-fmem-report
529 Report some statistics about memory allocation used by the tool.
531 .SH OTHER OPTIONS
533 .B \-fdiagnostic-prefix[=PREFIX]
534 Prefix all diagnostics by the given PREFIX, followed by ": ".
535 If no one is given "sparse" is used.
536 The default is to not use a prefix at all.
539 .B \-fmemcpy-max-count=COUNT
540 Set the limit for the warnings given by \fB-Wmemcpy-max-count\fR.
541 A COUNT of 'unlimited' or '0' will effectively disable the warning.
542 The default limit is 100000.
545 .B \-ftabstop=WIDTH
546 Set the distance between tab stops.  This helps sparse report correct
547 column numbers in warnings or errors.  If the value is less than 1 or
548 greater than 100, the option is ignored.  The default is 8.
551 .B \-f[no-]unsigned-bitfields, \-f[no-]signed-bitfields
552 Determine the signedness of bitfields declared without an
553 explicit sign ('signed' or 'unsigned').
554 By default such bitfields are signed, like others plain integers.
557 .B \-f[no-]unsigned-char, \-f[no-]signed-char
558 Let plain 'char' be unsigned or signed.
559 By default chars are signed.
561 .SH SEE ALSO
562 .BR cgcc (1)
564 .SH HOMEPAGE
565 https://sparse.docs.kernel.org
567 .SH MAILING LIST
568 linux-sparse@vger.kernel.org
570 .SH CONTRIBUTING AND REPORTING BUGS
571 Submission of patches and reporting of bugs, as well as discussions
572 related to Sparse, should be done via the mailing list (linux-sparse@vger.kernel.org)
573 where the development and maintenance is primarily done.
574 You do not have to be subscribed to the list to send a message there.
576 Bugs can also be reported and tracked via the Linux kernel's bugzilla:
577 http://bugzilla.kernel.org/enter_bug.cgi?component=Sparse&product=Tools .
579 .SH DOCUMENTATION
580 More documentation about Sparse can be found at
581 https://sparse.docs.kernel.org
583 .SH AUTHORS
584 Sparse was started by Linus Torvalds.
585 The complete list of contributors can be find at
586 https://www.openhub.net/p/sparse/contributors .
588 Luc Van Oostenryck is Sparse's current maintainer.