1 .\" $NetBSD: lint.1,v 1.21 2002/01/03 04:25:18 thorpej Exp $
3 .\" Copyright (c) 1996 Christopher G. Demetriou. All Rights Reserved.
4 .\" Copyright (c) 1994, 1995 Jochen Pohl
5 .\" All Rights Reserved.
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\" notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\" notice, this list of conditions and the following disclaimer in the
14 .\" documentation and/or other materials provided with the distribution.
15 .\" 3. All advertising materials mentioning features or use of this software
16 .\" must display the following acknowledgement:
17 .\" This product includes software developed by Jochen Pohl for
18 .\" The NetBSD Project.
19 .\" 4. The name of the author may not be used to endorse or promote products
20 .\" derived from this software without specific prior written permission.
22 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 .\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 .Nd a C program verifier
44 .Op Fl abceghprvwxzHFV
47 .Op Fl D Ar name Ns Op = Ns Ar def
53 .Op Fl o Ar outputfile
55 .Op Fl X Ar id Ns Op , Ns Ar id ...
61 .Op Fl D Ar name Ns Op = Ns Ar def
66 .Op Fl X Ar id Ns Op , Ns Ar id ...
72 utility attempts to detect features of the named C program files
73 that are likely to be bugs, to be non-portable, or to be
75 It also performs stricter type checking than does
79 utility runs the C preprocessor as its first phase, with the
82 defined to allow certain questionable code to be altered
85 Therefore, this symbol should be thought of as a reserved
86 word for all code that is to be checked by
89 Among the possible problems that are currently noted are
90 unreachable statements, loops not entered at the top,
91 variables declared and not used, and logical expressions
93 Function calls are checked for
94 inconsistencies, such as calls to functions that return
95 values in some places and not in others, functions called
96 with varying numbers of arguments, function calls that
97 pass arguments of a type other than the type the function
98 expects to receive, functions whose values are not used,
99 and calls to functions not returning values that use
100 the non-existent return value of the function.
102 Filename arguments ending with
104 are taken to be C source files.
105 Filename arguments with
108 are taken to be the result of an earlier invocation of
117 files are analogous to the
119 (object) files produced by
126 utility also accepts special libraries specified with the
128 option, which contain definitions of library routines and
133 utility takes all the
136 .Pa llib-l Ns Ar library Ns Pa .ln
137 (lint library) files and processes them in command-line order.
140 appends the standard C lint library
142 to the end of the list of files.
152 options are used, the
153 .Pa llib-l Ns Ar library Ns Pa .ln
161 checks this list of files for mutual compatibility.
163 if a complaint stems not from a given source file, but from one of
164 its included files, the source filename will be printed followed by
167 The special input file name
171 to take input from standard input (until end of file) and process
179 is named as one of the input files, the
181 flag must also be specified to provide an output file name.
182 The options are as follows:
183 .Bl -tag -width indent
185 Report assignments of
187 values to variables that are not
194 assignments of integer values to other integer values which
195 cause implicit narrowing conversion.
199 statements that cannot be reached.
200 This is not the default
201 because, unfortunately, most
205 outputs produce many such complaints.
207 Complain about casts which have questionable portability.
209 Complain about unusual operations on
214 .Sy integer Ns -Types .
216 Do not print warnings for some extensions of
219 Currently these are nonconstant initializers in
220 automatic aggregate initializations, arithmetic on pointer to void,
223 declarations, C++ -style
226 zero sized structures, subscripting of non-lvalue arrays, prototypes
227 overriding old style function declarations and long long
231 flag also turns on the keywords
235 (alternative keywords with leading underscores for both
239 are always available).
241 Apply a number of heuristic tests to attempt to intuit
242 bugs, improve style, and reduce waste.
248 file on the command line.
251 files are the product of
253 first pass only, and are not checked for compatibility
256 Do not check compatibility against the standard library.
258 Attempt to check portability of code to other dialects of C.
260 In case of redeclarations report the position of the
261 previous declaration.
264 Issue warnings and errors required by ANSI C.
265 Also do not produce warnings for constructs which behave
266 differently in traditional C and ANSI C.
271 is a predefined preprocessor macro.
275 is not predefined in this mode.
276 Warnings are printed for constructs
277 not allowed in traditional C.
278 Warnings for constructs which behave
279 differently in traditional C and ANSI C are suppressed.
281 macros describing the machine type (e.g.,
283 and machine architecture (e.g.,
285 are defined without leading and trailing underscores.
290 are not available in traditional C mode (although the alternative
291 keywords with leading underscores still are).
293 Do not complain about functions and external variables used
294 and not defined, or defined and not used (this is suitable
297 on a subset of files comprising part of a larger program).
299 Suppress complaints about unused arguments in functions.
301 Report variables referred to by
303 declarations, but never used.
305 Do not complain about structures that are never defined
306 (for example, using a structure pointer without knowing
309 Path to use when looking for the
319 library with the name
320 .Pa llib-l Ns Ar library Ns Pa .ln .
321 This library is built from all
326 After all global definitions of functions and
327 variables in these files are written to the newly created library,
329 checks all input files, including libraries specified with the
331 option, for mutual compatibility.
332 .It Fl D Ar name Ns Op = Ns Ar def
340 If no definition is given,
343 .It Fl I Ar directory
346 to the list of directories in which to search for include files.
347 .It Fl d Ar directory
352 as the default place to find include files.
354 Include the lint library
355 .Pa llib-l Ns Ar library Ns Pa .ln .
356 .It Fl L Ar directory
357 Search for lint libraries in
360 .Ar directory Ns Pa /lint
361 before searching the standard place.
363 Print pathnames of files.
366 utility normally prints the filename without the path.
368 If a complaint stems from an included file
370 prints the name of the included file instead of the source file name
371 followed by a question mark.
372 .It Fl o Ar outputfile
375 The output file produced is the input that is given to
380 option simply saves this file in the named output file.
383 option is also used the files are not checked for compatibility.
385 .Pa llib-l Ns Ar library Ns Pa .ln
386 without extraneous messages, use of the
391 option is useful if the source file(s) for the lint library
392 are just external interfaces.
394 Remove any initial definition of
396 for the preprocessor.
398 Print the command lines constructed by the controller program to
399 run the C preprocessor and
401 first and second pass.
403 Treat warnings as errors.
404 .It Fl X Ar id Ns Op , Ns Ar id ...
405 Suppress error messages identified by the list of ids.
407 and ids can be found in
412 first pass reads standard C source files.
415 utility recognizes the following C comments as commands.
416 .Bl -tag -width indent
417 .It Li /* ARGSUSED Ns Ar n Li */
422 arguments for usage; a missing
424 is taken to be 0 (this option acts like the
426 option for the next function).
427 .It Li /* BITFIELDTYPE */
428 Suppress error messages about illegal bitfield types if the type
429 is an integer type, and suppress non-portable bitfield type warnings.
433 .Li /* CONSTANTCOND */
435 .Li /* CONSTANTCONDITION */
437 suppress complaints about constant operands for the next expression.
441 .Li /* FALLTHROUGH */
443 suppress complaints about fall through to a
448 This directive should be placed immediately
450 .It Li /* LINTLIBRARY */
451 At the beginning of a file, mark all functions and variables defined
454 Also shut off complaints about unused function arguments.
456 .Li /* LINTED Oo Ar comment Oc Li */
458 .Li /* NOSTRICT Oo Ar comment Oc Li */
460 Suppresses any intra-file warning except those dealing with
461 unused variables or functions.
462 This directive should be placed
463 on the line immediately preceding where the
466 .It Li /* LONGLONG */
467 Suppress complaints about use of long long integer types.
468 .It Li /* NOTREACHED */
469 At appropriate points, inhibit complaints about unreachable code.
470 (This comment is typically placed just after calls to functions
473 .It Li /* PRINTFLIKE Ns Ar n Li */
481 argument is interpreted as a
483 format string that is used to check the remaining arguments.
484 .It Li /* PROTOLIB Ns Ar n Li */
487 to treat function declaration prototypes as function definitions
491 This directive can only be used in conjunction with
493 .Li /* LINTLIBRARY */
497 is zero, function prototypes will be treated normally.
498 .It Li /* SCANFLIKE Ns Ar n Li */
506 argument is interpreted as a
508 format string that is used to check the remaining arguments.
509 .It Li /* VARARGS Ns Ar n Li */
510 Suppress the usual checking for variable numbers of arguments in
511 the following function declaration.
512 The data types of the first
514 arguments are checked; a missing
523 options allows for incremental use of
525 on a set of C source files.
526 Generally, one invokes
528 once for each source file with the
531 Each of these invocations produces a
533 file that corresponds to the
535 file, and prints all messages that are about just that
537 After all the source files have been separately
540 it is invoked once more (without the
542 option), listing all the
544 files with the needed
547 This will print all the inter-file inconsistencies.
549 scheme works well with
555 only the source files that have been modified since the last
556 time the set of source files were
559 .Bl -tag -width LIBDIR
561 the directory where the lint libraries specified by the
566 If this environment variable is undefined,
567 then the default path
568 .Pa /usr/libdata/lint
569 will be used to search for the libraries.
571 usually the path for temporary files can be redefined by setting
572 this environment variable.
574 Location of the C compiler program.
579 .Bl -tag -width /usr/libdata/lint/llib-lc.ln -compact
580 .It Pa /usr/libexec/lint Ns Bq Pa 12
582 .It Pa /usr/libdata/lint/llib-l*.ln
583 various prebuilt lint libraries
599 and other functions that do not return are not understood; this
600 causes various incorrect diagnostics.
602 Static functions which are used only before their first
603 extern declaration are reported as unused.
605 Libraries created by the
607 option will, when used in later
609 runs, cause certain errors that were reported when the libraries
610 were created to be reported again, and cause line numbers and file
611 names from the original source used to create those libraries
612 to be reported in error messages.
613 For these reasons, it is recommended
616 option to create lint libraries.