1 .\" $NetBSD: lint.1,v 1.3 1995/10/23 13:45:31 jpo Exp $
3 .\" Copyright (c) 1994, 1995 Jochen Pohl
4 .\" All Rights Reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. All advertising materials mentioning features or use of this software
15 .\" must display the following acknowledgement:
16 .\" This product includes software developed by Jochen Pohl for
17 .\" The NetBSD Project.
18 .\" 4. The name of the author may not be used to endorse or promote products
19 .\" derived from this software without specific prior written permission.
21 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 .\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 .\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 .\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 .\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 .\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 .\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 .\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 .\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 .\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 .Nd a C program verifier.
44 .Op Fl i Ns | Ns Fl nu
45 .Op Fl D Ns Ar name Ns Op =def
47 .Op Fl I Ns Ar directory
48 .Op Fl L Ns Ar directory
49 .Op Fl l Ns Ar library
50 .Op Fl o Ns Ar outputfile
56 .Op Fl D Ns Ar name Ns Op =def
57 .Op Fl I Ns Ar directory
62 attempts to detect features of the named C program files
63 that are likely to be bugs, to be non-portable, or to be
65 It also performs stricter type checking then does
68 runs the C preprocessor as its first phase, with the
71 defined to allow certain questionable code to be altered
74 Therefore, this symbol should be thought of as a reserved
75 word for all code that is to be checked by
78 Among the possible problems that are currently noted are
79 unreachable statements, loops not entered at the top,
80 variables declared and not used, and logical expressions
82 Function calls are checked for
83 inconsistencies, such as calls to functions that return
84 values in some places and not in others, functions called
85 with varying numbers of arguments, function calls that
86 pass arguments of a type other than the type the function
87 expects to receive, functions whose values are not used,
88 and calls to functions not returning values that use
89 the non-existent return value of the function.
91 Filename arguments ending with
93 are taken to be C source files.
94 Filename arguments with
97 are taken to be the result of an earlier invocation of
107 files are analogous to the
109 (object) files produced by
115 also accepts special libraries specified with the
117 option, which contain definitions of library routines and
124 .Pa llib-l Ns Ar library Ns Pa \&.ln
125 (lint library) files and processes them in command-line order.
128 appends the standard C lint library
130 to the end of the list of files.
140 options are used, the
141 .Pa llib-l Ns Ar library Ns Pa \&.ln
149 checks this list of files for mutual compatibility.
151 if a complaint stems not from a given source file, but from one of
152 its included files, the source filename will be printed followed by
158 Report assignments of
160 values to variables that are not
167 assignments of integer values to other integer values which
168 cause implicit narrowing conversion.
172 statements that cannot be reached.
173 This is not the default
174 because, unfortunately, most
178 outputs produce many such complaints.
180 Complain about casts which have questionable portability.
182 Complain about unusual operations on
187 .Sy integer Ns -Types.
189 Don't print warnings for some extensions of
192 Currently these are nonconstant initializers in
193 automatic aggregate initializations, arithmetic on pointer to void,
194 zero sized structures, subscripting of non-lvalue arrays, prototypes
195 overriding old style function declarations and long long
199 flag also turns on the keywords
203 (alternate keywords with leading underscores for both
207 are always available).
209 Apply a number of heuristic tests to attempt to intuit
210 bugs, improve style, and reduce waste.
216 file on the command line.
219 files are the product of
221 first pass only, and are not checked for compatibility
224 Do not check compatibility against the standard library.
226 Attempt to check portability of code to other dialects of C.
228 In case of redeclarations report the position of the
229 previous declaration.
232 Issue warnings and errors required by ANSI C.
233 Also do not produce warnings for constructs which behave
234 differently in traditional C and ANSI C. With the
238 is a predefined preprocessor macro.
242 is not predefined in this mode.
243 Warnings are printed for constructs
244 not allowed in traditional C. Warnings for constructs which behave
245 differently in traditional C and ANSI C are suppressed.
247 macros describing the machine type (e.g.
249 and machine architecture (e.g.
251 are defined without leading and trailing underscores.
257 are not available in traditional C mode (although the alternate
258 keywords with leading underscores still are).
260 Do not complain about functions and external variables used
261 and not defined, or defined and not used (this is suitable
264 on a subset of files comprising part of a larger program).
266 Suppress complaints about unused arguments in functions.
268 Report variables referred to by
270 declarations, but never used.
272 Do not complain about structures that are never defined
273 (for example, using a structure pointer without knowing
275 .It Fl C Ns Ar library
278 library with the name
279 .Pa llib-l Ns Ar library Ns Pa .ln .
280 This library is built from all
285 After all global definitions of functions and
286 variables in these files are written to the newly created library,
288 checks all input files, including libraries specified with the
290 option, for mutual compatibility.
291 .It Fl D Ns Ar name Ns Op =def
299 If no definition is given,
302 .It Fl I Ns Ar directory
305 to the list of directories in which to search for include files.
306 .It Fl l Ns Ar library
307 Include the lint library
308 .Pa llib-l Ns Ar library Ns Pa \&.ln .
309 .It Fl L Ns Ar directory
310 Search for lint libraries in
313 .Ar directory Ns Pa /lint
314 before searching the standard place.
316 Print pathnames of files.
318 normally prints the filename without the path.
320 If a complaint stems from an included file
322 prints the name of the included file instead of the source file name
323 followed by a question mark.
324 .It Fl o Ns Ar outputfile
327 The output file produced is the input that is given to
332 option simply saves this file in the named output file.
335 option is also used the files are not checked for compatibility.
337 .Pa llib-l Ns Ar library Ns Pa \&.ln
338 without extraneous messages, use of the
343 option is useful if the source file(s) for the lint library
344 are just external interfaces.
346 Remove any initial definition of
348 for the preprocessor.
350 Print the command lines constructed by the controller program to
351 run the C preprocessor and
353 first and second pass.
359 first pass reads standard C source files.
361 recognizes the following C comments as commands.
363 .It Li /* ARGSUSED Ns Ar n Li */
368 arguments for usage; a missing
370 is taken to be 0 (this option acts like the
372 option for the next function).
373 .It Li /* CONSTCOND */ No or Xo
374 .Li /* CONSTANTCOND */ No or
375 .Li /* CONSTANTCONDITION */
377 suppress complaints about constant operands for the next expression.
378 .It Li /*\ FALLTHRU\ */ No or Xo
379 .Li /* FALLTHROUGH */
381 suppress complaints about fall through to a
386 This directive should be placed immediately
388 .It Li /* LINTLIBRARY */
389 At the beginning of a file, mark all functions and variables defined
392 Also shut off complaints about unused function arguments.
400 Suppresses any intra-file warning except those dealing with
401 unused variables or functions.
402 This directive should be placed
403 on the line immediately preceding where the lint warning occurred.
404 .It Li /* LONGLONG */
405 Suppress complaints about use of long long integer types.
406 .It Li /* NOTREACHED */
407 At appropriate points, inhibit complaints about unreachable code.
408 (This comment is typically placed just after calls to functions
411 .It Li /* PRINTFLIKE Ns Ar n Li */
419 argument is interpreted as a
421 format string that is used to check the remaining arguments.
422 .It Li /* PROTOLIB Ns Ar n Li */
425 to treat function declaration prototypes as function definitions
429 This directive can only be used in conjunction with
431 .Li /* LINTLIBRARY */
435 is zero, function prototypes will be treated normally.
436 .It Li /* SCANFLIKE Ns Ar n Li */
444 argument is interpreted as a
446 format string that is used to check the remaining arguments.
447 .It Li /* VARARGS Ns Ar n Li */
448 Suppress the usual checking for variable numbers of arguments in
449 the following function declaration.
450 The data types of the first
452 arguments are checked; a missing
461 options allows for incremental use of
463 on a set of C source files.
464 Generally, one invokes
466 once for each source file with the
469 Each of these invocations produces a
471 file that corresponds to the
473 file, and prints all messages that are about just that
475 After all the source files have been separately
478 it is invoked once more (without the
480 option), listing all the
482 files with the needed
484 options. this will print all the inter-file inconsistencies.
486 scheme works well with
492 only the source files that have been modified since the last
493 time the set of source files were
498 the directory where the lint libraries specified by the
501 If this environment variable is undefined,
502 then the default path
503 .Pa /usr/libdata/lint
504 will be used to search for the libraries.
506 usually the path for temporary files can be redefined by setting
507 this environment variable.
510 .Bl -tag -width /usr/libdata/lint/llib-lc.ln -compact
511 .It Pa /usr/libexec/lint Ns Bq 12
513 .It Pa /usr/libdata/lint/llib-l*.ln
514 various prebuilt lint libraries
527 and other functions that do not return are not understood; this
528 causes various incorrect diagnostics.
530 Static functions which are used only before their first
531 extern declaration are reported as unused.
533 Libraries created by the
535 option will, when used in later
537 runs, cause certain errors that were reported when the libraries
538 were created to be reported again, and cause line numbers and file
539 names from the original source used to create those libraries
540 to be reported in error messages.
541 For these reasons, it is recommended
544 option to create lint libraries.