]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.bin/xlint/xlint/lint.1
This commit was generated by cvs2svn to compensate for changes in r64562,
[FreeBSD/FreeBSD.git] / usr.bin / xlint / xlint / lint.1
1 .\"     $NetBSD: lint.1,v 1.3 1995/10/23 13:45:31 jpo Exp $
2 .\"
3 .\" Copyright (c) 1994, 1995 Jochen Pohl
4 .\" All Rights Reserved.
5 .\"
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
8 .\" are met:
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.
20 .\"
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.
31 .\"
32 .\" $FreeBSD$
33 .\"
34 .Dd August 28, 1994
35 .Dt LINT 1
36 .Os FreeBSD
37 .Sh NAME
38 .Nm lint
39 .Nd a C program verifier.
40 .Sh SYNOPSIS
41 .Nm lint
42 .Op Fl abceghprvxzHFV
43 .Op Fl s Ns | Ns Fl t
44 .Op Fl i Ns | Ns Fl nu
45 .Op Fl D Ns Ar name Ns Op =def
46 .Op Fl U Ns Ar name
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
51 .Ar
52 .Nm lint
53 .Op Fl abceghprvzHFV
54 .Op Fl s Ns | Ns Fl t
55 .Fl C Ns Ar library
56 .Op Fl D Ns Ar name Ns Op =def
57 .Op Fl I Ns Ar directory
58 .Op Fl U Ns Ar name
59 .Ar
60 .Sh DESCRIPTION
61 .Nm
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
64 wasteful.
65 It also performs stricter type checking then does
66 the C compiler.
67 .Nm
68 runs the C preprocessor as its first phase, with the
69 preprocessor symbol
70 .Sy lint
71 defined to allow certain questionable code to be altered
72 or skipped by
73 .Nm lint .
74 Therefore, this symbol should be thought of as a reserved
75 word for all code that is to be checked by
76 .Nm lint .
77 .Pp
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
81 with constant values.
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.
90 .Pp
91 Filename arguments ending with
92 .Pa \&.c
93 are taken to be C source files.
94 Filename arguments with
95 names ending with
96 .Pa \&.ln
97 are taken to be the result of an earlier invocation of
98 .Nm lint ,
99 with either the
100 .Fl i ,
101 .Fl o
102 or
103 .Fl C
104 option in effect.
105 The
106 .Pa \&.ln
107 files are analogous to the
108 .Pa \&.o
109 (object) files produced by
110 .Xr cc 1
111 from
112 .Pa \&.c
113 files.
114 .Nm
115 also accepts special libraries specified with the
116 .Fl l
117 option, which contain definitions of library routines and
118 variables.
119 .Pp
120 .Nm
121 takes all the
122 .Pa \&.c , \&.ln ,
123 and
124 .Pa llib-l Ns Ar library Ns Pa \&.ln
125 (lint library) files and processes them in command-line order.
126 By default,
127 .Nm
128 appends the standard C lint library
129 .Pq Pa llib-lc.ln
130 to the end of the list of files.
131 When the
132 .Fl i
133 option is used, the
134 .Pa \&.ln
135 files are ignored.
136 Also, when the
137 .Fl o
138 or
139 .Fl i
140 options are used, the
141 .Pa llib-l Ns Ar library Ns Pa \&.ln
142 files are ignored.
143 When the
144 .Fl i
145 option is
146 .Em omitted
147 the second pass of
148 .Nm
149 checks this list of files for mutual compatibility.
150 At this point,
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
153 a question mark.
154 .Pp
155 .Sy Options
156 .Bl -tag -width Fl
157 .It Fl a
158 Report assignments of
159 .Sy long
160 values to variables that are not
161 .Sy long .
162 .It Fl aa
163 Additional to
164 .Fl a ,
165 report
166 .Em all
167 assignments of integer values to other integer values which
168 cause implicit narrowing conversion.
169 .It Fl b
170 Report
171 .Sy break
172 statements that cannot be reached.
173 This is not the default
174 because, unfortunately, most
175 .Xr lex 1
176 and many
177 .Xr yacc 1
178 outputs produce many such complaints.
179 .It Fl c
180 Complain about casts which have questionable portability.
181 .It Fl e
182 Complain about unusual operations on
183 .Sy enum Ns -Types
184 and combinations of
185 .Sy enum Ns -
186 and
187 .Sy integer Ns -Types.
188 .It Fl g
189 Don't print warnings for some extensions of
190 .Xr gcc 1
191 to the C language.
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
196 integer types.
197 The
198 .Fl g
199 flag also turns on the keywords
200 .Sy asm
201 and
202 .Sy inline
203 (alternate keywords with leading underscores for both
204 .Sy asm
205 and
206 .Sy inline
207 are always available).
208 .It Fl h
209 Apply a number of heuristic tests to attempt to intuit
210 bugs, improve style, and reduce waste.
211 .It Fl i
212 Produce a
213 .Pa \&.ln
214 file for every
215 .Pa \&.c
216 file on the command line.
217 These
218 .Pa \&.ln
219 files are the product of
220 .Nm lint Ns 's
221 first pass only, and are not checked for compatibility
222 between functions.
223 .It Fl n
224 Do not check compatibility against the standard library.
225 .It Fl p
226 Attempt to check portability of code to other dialects of C.
227 .It Fl r
228 In case of redeclarations report the position of the
229 previous declaration.
230 .It Fl s
231 Strict ANSI C mode.
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
235 .Fl s
236 flag,
237 .Li __STRICT_ANSI__
238 is a predefined preprocessor macro.
239 .It Fl t
240 Traditional C mode.
241 .Li __STDC__
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.
246 Preprocessor
247 macros describing the machine type (e.g.
248 .Li sun3 Ns )
249 and machine architecture (e.g.
250 .Li m68k Ns )
251 are defined without leading and trailing underscores.
252 The keywords
253 .Sy const Ns ,
254 .Sy volatile
255 and
256 .Sy signed
257 are not available in traditional C mode (although the alternate
258 keywords with leading underscores still are).
259 .It Fl u
260 Do not complain about functions and external variables used
261 and not defined, or defined and not used (this is suitable
262 for running
263 .Nm
264 on a subset of files comprising part of a larger program).
265 .It Fl v
266 Suppress complaints about unused arguments in functions.
267 .It Fl x
268 Report variables referred to by
269 .Sy extern
270 declarations, but never used.
271 .It Fl z
272 Do not complain about structures that are never defined
273 (for example, using a structure pointer without knowing
274 its contents).
275 .It Fl C Ns Ar library
276 Create a
277 .Nm
278 library with the name
279 .Pa llib-l Ns Ar library Ns Pa .ln .
280 This library is built from all
281 .Pa \&.c
282 and
283 .Pa \&.ln
284 input files.
285 After all global definitions of functions and
286 variables in these files are written to the newly created library,
287 .Nm
288 checks all input files, including libraries specified with the
289 .Fl l
290 option, for mutual compatibility.
291 .It Fl D Ns Ar name Ns Op =def
292 Define
293 .Ar name
294 for
295 .Xr cpp 1 ,
296 as if by a
297 .Li #define
298 directive.
299 If no definition is given,
300 .Ar name
301 is defined as 1.
302 .It Fl I Ns Ar directory
303 Add
304 .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
311 .Ar directory
312 and
313 .Ar directory Ns Pa /lint
314 before searching the standard place.
315 .It Fl F
316 Print pathnames of files.
317 .Nm
318 normally prints the filename without the path.
319 .It Fl H
320 If a complaint stems from an included file
321 .Nm
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
325 Name the output file
326 .Ar outputfile .
327 The output file produced is the input that is given to
328 .Nm lint Ns 's
329 second pass.
330 The
331 .Fl o
332 option simply saves this file in the named output file.
333 If the
334 .Fl i
335 option is also used the files are not checked for compatibility.
336 To produce a
337 .Pa llib-l Ns Ar library Ns Pa \&.ln
338 without extraneous messages, use of the
339 .Fl u
340 option is suggested.
341 The
342 .Fl v
343 option is useful if the source file(s) for the lint library
344 are just external interfaces.
345 .It Fl U Ns Ar name
346 Remove any initial definition of
347 .Ar name
348 for the preprocessor.
349 .It Fl V
350 Print the command lines constructed by the controller program to
351 run the C preprocessor and
352 .Nm lint Ns 's
353 first and second pass.
354 .El
355 .Pp
356 .Sy Input Grammar
357 .Pp
358 .Nm lint Ns 's
359 first pass reads standard C source files.
360 .Nm
361 recognizes the following C comments as commands.
362 .Bl -tag -width Fl
363 .It Li /* ARGSUSED Ns Ar n Li */
364 makes
365 .Nm
366 check only the first
367 .Ar n
368 arguments for usage; a missing
369 .Ar n
370 is taken to be 0 (this option acts like the
371 .Fl v
372 option for the next function).
373 .It Li /* CONSTCOND */ No or Xo
374 .Li /* CONSTANTCOND */ No or
375 .Li /* CONSTANTCONDITION */
376 .Xc
377 suppress complaints about constant operands for the next expression.
378 .It Li /*\ FALLTHRU\ */ No or Xo
379 .Li /* FALLTHROUGH */
380 .Xc
381 suppress complaints about fall through to a
382 .Sy case
383 or
384 .Sy default
385 labelled statement.
386 This directive should be placed immediately
387 preceding the label.
388 .It Li /* LINTLIBRARY */
389 At the beginning of a file, mark all functions and variables defined
390 in this file as
391 .Em used .
392 Also shut off complaints about unused function arguments.
393 .It Li /* LINTED Xo
394 .Op Ar comment
395 .Li */ No or
396 .Li /* NOSTRICT
397 .Op Ar comment
398 .Li */
399 .Xc
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
409 like
410 .Xr exit 3 ).
411 .It Li /* PRINTFLIKE Ns Ar n Li */
412 makes
413 .Nm
414 check the first
415 .Pq Ar n Ns No -1
416 arguments as usual.
417 The
418 .Ar n Ns No -th
419 argument is interpreted as a
420 .Sy printf
421 format string that is used to check the remaining arguments.
422 .It Li /* PROTOLIB Ns Ar n Li */
423 causes
424 .Nm
425 to treat function declaration prototypes as function definitions
426 if
427 .Ar n
428 is non-zero.
429 This directive can only be used in conjunction with
430 the
431 .Li /* LINTLIBRARY */
432 directive.
433 If
434 .Ar n
435 is zero, function prototypes will be treated normally.
436 .It Li /* SCANFLIKE Ns Ar n Li */
437 makes
438 .Nm
439 check the first
440 .Pq Ar n Ns No -1
441 arguments as usual.
442 The
443 .Ar n Ns No -th
444 argument is interpreted as a
445 .Sy scanf
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
451 .Ar n
452 arguments are checked; a missing
453 .Ar n
454 is taken to be 0.
455 .El
456 .Pp
457 The behavior of the
458 .Fl i
459 and the
460 .Fl o
461 options allows for incremental use of
462 .Nm
463 on a set of C source files.
464 Generally, one invokes
465 .Nm
466 once for each source file with the
467 .Fl i
468 option.
469 Each of these invocations produces a
470 .Pa \&.ln
471 file that corresponds to the
472 .Pa \&.c
473 file, and prints all messages that are about just that
474 source file.
475 After all the source files have been separately
476 run through
477 .Nm lint ,
478 it is invoked once more (without the
479 .Fl i
480 option), listing all the
481 .Pa \&.ln
482 files with the needed
483 .Fl l Ns Ar library
484 options. this will print all the inter-file inconsistencies.
485 This
486 scheme works well with
487 .Xr make 1 ;
488 it allows
489 .Xr make 1
490 to be used to
491 .Nm
492 only the source files that have been modified since the last
493 time the set of source files were
494 .Nm lint Ns No ed .
495 .Sh ENVIRONMENT
496 .Bl -tag -width Fl
497 .It Ev LIBDIR
498 the directory where the lint libraries specified by the
499 .Fl l Ns Ar library
500 option must exist.
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.
505 .It Ev TMPDIR
506 usually the path for temporary files can be redefined by setting
507 this environment variable.
508 .El
509 .Sh FILES
510 .Bl -tag -width /usr/libdata/lint/llib-lc.ln -compact
511 .It Pa /usr/libexec/lint Ns Bq 12
512 programs
513 .It Pa /usr/libdata/lint/llib-l*.ln
514 various prebuilt lint libraries
515 .It Pa /tmp/lint*
516 temporaries
517 .Sh SEE ALSO
518 .Xr cc 1 ,
519 .Xr cpp 1 ,
520 .Xr make 1
521 .Sh AUTHORS
522 .An Jochen Pohl
523 .Sh BUGS
524 The routines
525 .Xr exit 3 ,
526 .Xr longjmp 3
527 and other functions that do not return are not understood; this
528 causes various incorrect diagnostics.
529 .Pp
530 Static functions which are used only before their first
531 extern declaration are reported as unused.
532 .Pp
533 Libraries created by the
534 .Fl o
535 option will, when used in later
536 .Nm
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
542 to use the
543 .Fl C
544 option to create lint libraries.