blob: 10ddc7fafba802323d39cd1657420534477ae3f2 [file] [log] [blame]
Ted Kremenek8db26ce2012-05-24 20:13:47 +00001.\" This file is distributed under the University of Illinois Open Source
2.\" License. See LICENSE.TXT for details.
3.\" $Id$
4.Dd May 25, 2012
Sean Silvaab482682012-10-23 16:35:44 +00005.Dt SCAN-BUILD 1
Ted Kremenek8db26ce2012-05-24 20:13:47 +00006.Os "clang" "3.1"
Ted Kremenek33ee1592012-05-10 19:10:47 +00007.Sh NAME
8.Nm scan-build
9.Nd Clang static analyzer
10.Sh SYNOPSIS
11.Nm
12.Op Fl ohkvV
13.Op Fl analyze-headers
14.Op Fl enable-checker Op Ar checker_name
15.Op Fl disable-checker Op Ar checker_name
Ted Kremenek8db26ce2012-05-24 20:13:47 +000016.Op Fl Fl help
17.Op Fl Fl help-checkers
18.Op Fl Fl html-title Op Ar =title
19.Op Fl Fl keep-going
20.Op Fl plist
21.Op Fl plist-html
22.Op Fl Fl status-bugs
23.Op Fl Fl use-c++ Op Ar =compiler_path
24.Op Fl Fl use-cc Op Ar =compiler_path
25.Op Fl Fl view
Ted Kremenek33ee1592012-05-10 19:10:47 +000026.Op Fl constraints Op Ar model
27.Op Fl maxloop Ar N
28.Op Fl no-failure-reports
29.Op Fl stats
30.Op Fl store Op Ar model
31.Ar build_command
32.Op build_options
33.\"
34.\" Sh DESCRIPTION
Ted Kremenek8db26ce2012-05-24 20:13:47 +000035.Sh DESCRIPTION
36.Nm
37is a Perl script that invokes the Clang static analyzer. Options used by
38.Nm
39or by the analyzer appear first, followed by the
40.Ar build_command
41and any
42.Ar build_options
43normally used to build the target system.
44.Pp
45The static analyzer employs a long list of checking algorithms, see
46.Sx CHECKERS .
47Output can be written in standard
48.Li .plist
49and/or HTML format.
50.Pp
51The following options are supported:
Ted Kremenek33ee1592012-05-10 19:10:47 +000052.Bl -tag -width indent
53.It Fl analyze-headers
54Also analyze functions in #included files.
Ted Kremenek8db26ce2012-05-24 20:13:47 +000055.It Fl enable-checker Ar checker_name , Fl disable-checker Ar checker_name
Ted Kremenek33ee1592012-05-10 19:10:47 +000056Enable/disable
57.Ar checker_name .
Ted Kremenek8db26ce2012-05-24 20:13:47 +000058See
59.Sx CHECKERS .
60.It Fl h , Fl Fl help
61Display this message.
62.It Fl Fl help-checkers
63List default checkers, see
64.Sx CHECKERS .
65.It Fl Fl html-title Ns Op = Ns Ar title
Ted Kremenek33ee1592012-05-10 19:10:47 +000066Specify the title used on generated HTML pages.
Ted Kremenek8db26ce2012-05-24 20:13:47 +000067A default title is generated if
68.Ar title
69is not specified.
70.It Fl k , Fl Fl keep-going
71Add a
Ted Kremenek33ee1592012-05-10 19:10:47 +000072.Dq keep on going
Ted Kremenek8db26ce2012-05-24 20:13:47 +000073option to
74.Ar build_command .
75Currently supports make and xcodebuild. This is a convenience option;
76one can specify this behavior directly using build options.
Ted Kremenek33ee1592012-05-10 19:10:47 +000077.It Fl o
78Target directory for HTML report files. Subdirectories will be
Ted Kremenek8db26ce2012-05-24 20:13:47 +000079created as needed to represent separate invocations
Ted Kremenek33ee1592012-05-10 19:10:47 +000080of the analyzer. If this option is not specified, a directory is
81created in /tmp (TMPDIR on Mac OS X) to store the reports.
Ted Kremenek8db26ce2012-05-24 20:13:47 +000082.It Fl plist
83Output the results as a set of
84.Li .plist
Ted Kremenek33ee1592012-05-10 19:10:47 +000085files. (By default the output of
86.Nm
87is a set of HTML files.)
Ted Kremenek8db26ce2012-05-24 20:13:47 +000088.It Fl plist-html
Ted Kremenek33ee1592012-05-10 19:10:47 +000089Output the results as a set of HTML and .plist files
Ted Kremenek8db26ce2012-05-24 20:13:47 +000090.It Fl Fl status-bugs
Ted Kremenek33ee1592012-05-10 19:10:47 +000091Set exit status to 1 if it found potential bugs and 0 otherwise. By
92default the exit status of
93.Nm
Ted Kremenek8db26ce2012-05-24 20:13:47 +000094is that returned by
95.Ar build_command .
96.It Fl Fl use-c++ Ns Op = Ns Ar compiler_path
Ted Kremenek33ee1592012-05-10 19:10:47 +000097Guess the default compiler for your C++ and Objective-C++ code. Use this
98option to specify an alternate compiler.
Ted Kremenek8db26ce2012-05-24 20:13:47 +000099.It Fl Fl use-cc Ns Op = Ns Ar compiler_path
Ted Kremenek33ee1592012-05-10 19:10:47 +0000100Guess the default compiler for your C and Objective-C code. Use this
101option to specify an alternate compiler.
102.It Fl v
103Verbose output from
104.Nm
105and the analyzer. A second and
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000106third
Ted Kremenek33ee1592012-05-10 19:10:47 +0000107.Ar v
108increases verbosity.
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000109.It Fl V , Fl Fl view
Ted Kremenek33ee1592012-05-10 19:10:47 +0000110View analysis results in a web browser when the build completes.
111.It Fl constraints Op Ar model
112Specify the contraint engine used by the analyzer. By default the
113.Ql range
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000114model is used. Specifying
Ted Kremenek33ee1592012-05-10 19:10:47 +0000115.Ql basic
116uses a simpler, less powerful constraint model used by checker-0.160
117and earlier.
118.It Fl maxloop Ar N
119Specifiy the number of times a block can be visited before giving
120up. Default is 4. Increase for more comprehensive coverage at a
121cost of speed.
122.It Fl no-failure-reports
123Do not create a
124.Ql failures
125subdirectory that includes analyzer crash reports and preprocessed
126source files.
127.It Fl stats
128Generates visitation statistics for the project being analyzed.
129.It Fl store Op Ar model
130Specify the store model used by the analyzer. By default, the
131.Ql region
132store model is used.
133.Ql region
134specifies a field-
135sensitive store model. Users can also specify
136.Ql basic
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000137which is far less precise but can more quickly analyze code.
Ted Kremenek33ee1592012-05-10 19:10:47 +0000138.Ql basic
139was the default store model for checker-0.221 and earlier.
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000140.\"
Ted Kremenek33ee1592012-05-10 19:10:47 +0000141.El
Sean Silvaab482682012-10-23 16:35:44 +0000142.Sh EXIT STATUS
Ted Kremenek33ee1592012-05-10 19:10:47 +0000143.Nm
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000144returns the value returned by
145.Ar build_command
146unless
147.Fl Fl status-bugs
148or
149.Fl Fl keep-going
Ted Kremenek33ee1592012-05-10 19:10:47 +0000150is used.
151.\"
152.\" Other sections not yet used ...
153.\" .Sh ENVIRONMENT
154.\" .Sh FILES
155.\" .Sh DIAGNOSTICS
156.\" .Sh COMPATIBILITY
157.\" .Sh HISTORY
Ted Kremenek33ee1592012-05-10 19:10:47 +0000158.\" .Sh BUGS
159.\"
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000160.Sh CHECKERS
Ted Kremenek33ee1592012-05-10 19:10:47 +0000161The checkers listed below may be enabled/disabled using the
162.Fl enable-checker
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000163and
Ted Kremenek33ee1592012-05-10 19:10:47 +0000164.Fl disable-checker
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000165options.
166A default group of checkers is run unless explicitly disabled.
167Exactly which checkers constitute the default group is a function
168of the operating system in use; they are listed with
169.Fl Fl help-checkers .
170.Bl -tag -width indent.
Ted Kremenek33ee1592012-05-10 19:10:47 +0000171.It core.AdjustedReturnValue
172Check to see if the return value of a function call is different than
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000173the caller expects (e.g., from calls through function pointers).
Ted Kremenek33ee1592012-05-10 19:10:47 +0000174.It core.AttributeNonNull
175Check for null pointers passed as arguments to a function whose arguments are marked with the
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000176.Ql nonnull
177attribute.
Ted Kremenek33ee1592012-05-10 19:10:47 +0000178.It core.CallAndMessage
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000179Check for logical errors for function calls and Objective-C message expressions (e.g., uninitialized arguments, null function pointers).
Ted Kremenek33ee1592012-05-10 19:10:47 +0000180.It core.DivideZero
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000181Check for division by zero.
Ted Kremenek33ee1592012-05-10 19:10:47 +0000182.It core.NullDereference
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000183Check for dereferences of null pointers.
Ted Kremenek33ee1592012-05-10 19:10:47 +0000184.It core.StackAddressEscape
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000185Check that addresses to stack memory do not escape the function.
Ted Kremenek33ee1592012-05-10 19:10:47 +0000186.It core.UndefinedBinaryOperatorResult
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000187Check for undefined results of binary operators.
Ted Kremenek33ee1592012-05-10 19:10:47 +0000188.It core.VLASize
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000189Check for declarations of VLA of undefined or zero size.
Ted Kremenek33ee1592012-05-10 19:10:47 +0000190.It core.builtin.BuiltinFunctions
Sean Silvaab482682012-10-23 16:35:44 +0000191Evaluate compiler builtin functions, e.g.
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000192.Fn alloca .
193.It core.builtin.NoReturnFunctions
Sean Silvaab482682012-10-23 16:35:44 +0000194Evaluate
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000195.Ql panic
196functions that are known to not return to the caller.
Ted Kremenek33ee1592012-05-10 19:10:47 +0000197.It core.uninitialized.ArraySubscript
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000198Check for uninitialized values used as array subscripts.
Ted Kremenek33ee1592012-05-10 19:10:47 +0000199.It core.uninitialized.Assign
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000200Check for assigning uninitialized values.
201.It core.uninitialized.Branch
202Check for uninitialized values used as branch conditions.
Ted Kremenek33ee1592012-05-10 19:10:47 +0000203.It core.uninitialized.CapturedBlockVariable
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000204Check for blocks that capture uninitialized values.
205.It core.uninitialized.UndefReturn
206Check for uninitialized values being returned to the caller.
Ted Kremenek33ee1592012-05-10 19:10:47 +0000207.It deadcode.DeadStores
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000208Check for values stored to variables that are never read afterwards.
Ted Kremenek33ee1592012-05-10 19:10:47 +0000209.It debug.DumpCFG
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000210Display Control-Flow Graphs.
Ted Kremenek33ee1592012-05-10 19:10:47 +0000211.It debug.DumpCallGraph
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000212Display Call Graph.
Ted Kremenek33ee1592012-05-10 19:10:47 +0000213.It debug.DumpDominators
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000214Print the dominance tree for a given Control-Flow Graph.
Ted Kremenek33ee1592012-05-10 19:10:47 +0000215.It debug.DumpLiveVars
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000216Print results of live variable analysis.
Ted Kremenek33ee1592012-05-10 19:10:47 +0000217.It debug.Stats
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000218Emit warnings with analyzer statistics.
Ted Kremenek33ee1592012-05-10 19:10:47 +0000219.It debug.TaintTest
220Mark tainted symbols as such.
Ted Kremenek33ee1592012-05-10 19:10:47 +0000221.It debug.ViewCFG
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000222View Control-Flow Graphs using
223.Ic GraphViz .
Ted Kremenek33ee1592012-05-10 19:10:47 +0000224.It debug.ViewCallGraph
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000225View Call Graph using
226.Ic GraphViz .
Ted Kremenek33ee1592012-05-10 19:10:47 +0000227.It llvm.Conventions
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000228Check code for LLVM codebase conventions.
Ted Kremenek33ee1592012-05-10 19:10:47 +0000229.It osx.API
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000230Check for proper uses of various Mac OS X APIs.
Ted Kremenek33ee1592012-05-10 19:10:47 +0000231.It osx.AtomicCAS
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000232Evaluate calls to
233.Vt OSAtomic
234functions.
Ted Kremenek33ee1592012-05-10 19:10:47 +0000235.It osx.SecKeychainAPI
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000236Check for proper uses of Secure Keychain APIs.
Ted Kremenek33ee1592012-05-10 19:10:47 +0000237.It osx.cocoa.AtSync
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000238Check for null pointers used as mutexes for @synchronized.
Ted Kremenek33ee1592012-05-10 19:10:47 +0000239.It osx.cocoa.ClassRelease
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000240Check for sending
241.Ql retain ,
242.Ql release,
243or
244.Ql autorelease
245directly to a Class.
Ted Kremenek33ee1592012-05-10 19:10:47 +0000246.It osx.cocoa.IncompatibleMethodTypes
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000247Warn about Objective-C method signatures with type incompatibilities.
Ted Kremenek33ee1592012-05-10 19:10:47 +0000248.It osx.cocoa.NSAutoreleasePool
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000249Warn for suboptimal uses of
250.Vt NSAutoreleasePool
251in Objective-C GC mode.
Ted Kremenek33ee1592012-05-10 19:10:47 +0000252.It osx.cocoa.NSError
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000253Check usage of NSError** parameters.
Ted Kremenek33ee1592012-05-10 19:10:47 +0000254.It osx.cocoa.NilArg
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000255Check for prohibited nil arguments to Objective-C method calls.
Ted Kremenek33ee1592012-05-10 19:10:47 +0000256.It osx.cocoa.RetainCount
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000257Check for leaks and improper reference count management.
Ted Kremenek33ee1592012-05-10 19:10:47 +0000258.It osx.cocoa.SelfInit
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000259Check that
260.Ql self
261is properly initialized inside an initializer method.
Ted Kremenek33ee1592012-05-10 19:10:47 +0000262.It osx.cocoa.UnusedIvars
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000263Warn about private ivars that are never used.
Ted Kremenek33ee1592012-05-10 19:10:47 +0000264.It osx.cocoa.VariadicMethodTypes
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000265Check for passing non-Objective-C types to variadic methods that expect only Objective-C types.
Ted Kremenek33ee1592012-05-10 19:10:47 +0000266.It osx.coreFoundation.CFError
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000267Check usage of CFErrorRef* parameters.
Ted Kremenek33ee1592012-05-10 19:10:47 +0000268.It osx.coreFoundation.CFNumber
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000269Check for proper uses of
270.Fn CFNumberCreate .
Ted Kremenek33ee1592012-05-10 19:10:47 +0000271.It osx.coreFoundation.CFRetainRelease
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000272Check for null arguments to
Jordan Rose0fe4d402012-11-07 17:12:37 +0000273.Fn CFRetain ,
274.Fn CFRelease ,
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000275and
Jordan Rose0fe4d402012-11-07 17:12:37 +0000276.Fn CFMakeCollectable .
Ted Kremenek33ee1592012-05-10 19:10:47 +0000277.It osx.coreFoundation.containers.OutOfBounds
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000278Checks for index out-of-bounds when using the
279.Vt CFArray
280API.
Ted Kremenek33ee1592012-05-10 19:10:47 +0000281.It osx.coreFoundation.containers.PointerSizedValues
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000282Warns if
283.Vt CFArray ,
284.Vt CFDictionary ,
285or
286.Vt CFSet
287are created with non-pointer-size values.
Ted Kremenek33ee1592012-05-10 19:10:47 +0000288.It security.FloatLoopCounter
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000289Warn on using a floating point value as a loop counter (CERT: FLP30-C, FLP30-CPP).
Ted Kremenek33ee1592012-05-10 19:10:47 +0000290.It security.insecureAPI.UncheckedReturn
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000291Warn on uses of functions whose return values must be always checked.
Ted Kremenek33ee1592012-05-10 19:10:47 +0000292.It security.insecureAPI.getpw
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000293Warn on uses of
294.Fn getpw .
Ted Kremenek33ee1592012-05-10 19:10:47 +0000295.It security.insecureAPI.gets
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000296Warn on uses of
297.Fn gets .
Ted Kremenek33ee1592012-05-10 19:10:47 +0000298.It security.insecureAPI.mkstemp
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000299Warn when
300.Fn mkstemp
301is passed fewer than 6 X's in the format string.
Ted Kremenek33ee1592012-05-10 19:10:47 +0000302.It security.insecureAPI.mktemp
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000303Warn on uses of
304.Fn mktemp .
Ted Kremenek33ee1592012-05-10 19:10:47 +0000305.It security.insecureAPI.rand
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000306Warn on uses of
307.Fn rand ,
308.Fn random ,
309and related functions.
Ted Kremenek33ee1592012-05-10 19:10:47 +0000310.It security.insecureAPI.strcpy
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000311Warn on uses of
312.Fn strcpy
313and
314.Fn strcat .
Ted Kremenek33ee1592012-05-10 19:10:47 +0000315.It security.insecureAPI.vfork
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000316Warn on uses of
317.Fn vfork .
Ted Kremenek33ee1592012-05-10 19:10:47 +0000318.It unix.API
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000319Check calls to various UNIX/Posix functions.
Ted Kremenek33ee1592012-05-10 19:10:47 +0000320.It unix.Malloc
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000321Check for memory leaks, double free, and use-after-free.
Ted Kremenek33ee1592012-05-10 19:10:47 +0000322.It unix.cstring.BadSizeArg
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000323Check the size argument passed into C string functions for common
324erroneous patterns.
Ted Kremenek33ee1592012-05-10 19:10:47 +0000325.It unix.cstring.NullArg
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000326Check for null pointers being passed as arguments to C string functions.
Ted Kremenek33ee1592012-05-10 19:10:47 +0000327.El
328.\"
329.Sh EXAMPLE
330.Ic scan-build -o /tmp/myhtmldir make -j4
331.Pp
332The above example causes analysis reports to be deposited into
333a subdirectory of
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000334.Pa /tmp/myhtmldir
Ted Kremenek33ee1592012-05-10 19:10:47 +0000335and to run
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000336.Ic make
Ted Kremenek33ee1592012-05-10 19:10:47 +0000337with the
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000338.Fl j4
Ted Kremenek33ee1592012-05-10 19:10:47 +0000339option.
340A different subdirectory is created each time
341.Nm
342analyzes a project.
343The analyzer should support most parallel builds, but not distributed builds.
Ted Kremenek8db26ce2012-05-24 20:13:47 +0000344.Sh AUTHORS
345.Nm
346was written by
347.An "Ted Kremenek" .
348Documentation contributed by
349.An "James K. Lowden" Aq jklowden@schemamania.org .