2012-05-25 04:13:47 +08:00
|
|
|
.\" This file is distributed under the University of Illinois Open Source
|
|
|
|
.\" License. See LICENSE.TXT for details.
|
|
|
|
.\" $Id$
|
|
|
|
.Dd May 25, 2012
|
|
|
|
.Os "clang" "3.1"
|
|
|
|
.Dt SCAN-BUILD \&1 CLANG
|
2012-05-11 03:10:47 +08:00
|
|
|
.Sh NAME
|
|
|
|
.Nm scan-build
|
|
|
|
.Nd Clang static analyzer
|
|
|
|
.Sh SYNOPSIS
|
|
|
|
.Nm
|
|
|
|
.Op Fl ohkvV
|
|
|
|
.Op Fl analyze-headers
|
|
|
|
.Op Fl enable-checker Op Ar checker_name
|
|
|
|
.Op Fl disable-checker Op Ar checker_name
|
2012-05-25 04:13:47 +08:00
|
|
|
.Op Fl Fl help
|
|
|
|
.Op Fl Fl help-checkers
|
|
|
|
.Op Fl Fl html-title Op Ar =title
|
|
|
|
.Op Fl Fl keep-going
|
|
|
|
.Op Fl plist
|
|
|
|
.Op Fl plist-html
|
|
|
|
.Op Fl Fl status-bugs
|
|
|
|
.Op Fl Fl use-c++ Op Ar =compiler_path
|
|
|
|
.Op Fl Fl use-cc Op Ar =compiler_path
|
|
|
|
.Op Fl Fl view
|
2012-05-11 03:10:47 +08:00
|
|
|
.Op Fl constraints Op Ar model
|
|
|
|
.Op Fl maxloop Ar N
|
|
|
|
.Op Fl no-failure-reports
|
|
|
|
.Op Fl stats
|
|
|
|
.Op Fl store Op Ar model
|
|
|
|
.Ar build_command
|
|
|
|
.Op build_options
|
|
|
|
.\"
|
|
|
|
.\" Sh DESCRIPTION
|
2012-05-25 04:13:47 +08:00
|
|
|
.Sh DESCRIPTION
|
|
|
|
.Nm
|
|
|
|
is a Perl script that invokes the Clang static analyzer. Options used by
|
|
|
|
.Nm
|
|
|
|
or by the analyzer appear first, followed by the
|
|
|
|
.Ar build_command
|
|
|
|
and any
|
|
|
|
.Ar build_options
|
|
|
|
normally used to build the target system.
|
|
|
|
.Pp
|
|
|
|
The static analyzer employs a long list of checking algorithms, see
|
|
|
|
.Sx CHECKERS .
|
|
|
|
Output can be written in standard
|
|
|
|
.Li .plist
|
|
|
|
and/or HTML format.
|
|
|
|
.Pp
|
|
|
|
The following options are supported:
|
2012-05-11 03:10:47 +08:00
|
|
|
.Bl -tag -width indent
|
|
|
|
.It Fl analyze-headers
|
|
|
|
Also analyze functions in #included files.
|
2012-05-25 04:13:47 +08:00
|
|
|
.It Fl enable-checker Ar checker_name , Fl disable-checker Ar checker_name
|
2012-05-11 03:10:47 +08:00
|
|
|
Enable/disable
|
|
|
|
.Ar checker_name .
|
2012-05-25 04:13:47 +08:00
|
|
|
See
|
|
|
|
.Sx CHECKERS .
|
|
|
|
.It Fl h , Fl Fl help
|
|
|
|
Display this message.
|
|
|
|
.It Fl Fl help-checkers
|
|
|
|
List default checkers, see
|
|
|
|
.Sx CHECKERS .
|
|
|
|
.It Fl Fl html-title Ns Op = Ns Ar title
|
2012-05-11 03:10:47 +08:00
|
|
|
Specify the title used on generated HTML pages.
|
2012-05-25 04:13:47 +08:00
|
|
|
A default title is generated if
|
|
|
|
.Ar title
|
|
|
|
is not specified.
|
|
|
|
.It Fl k , Fl Fl keep-going
|
|
|
|
Add a
|
2012-05-11 03:10:47 +08:00
|
|
|
.Dq keep on going
|
2012-05-25 04:13:47 +08:00
|
|
|
option to
|
|
|
|
.Ar build_command .
|
|
|
|
Currently supports make and xcodebuild. This is a convenience option;
|
|
|
|
one can specify this behavior directly using build options.
|
2012-05-11 03:10:47 +08:00
|
|
|
.It Fl o
|
|
|
|
Target directory for HTML report files. Subdirectories will be
|
2012-05-25 04:13:47 +08:00
|
|
|
created as needed to represent separate invocations
|
2012-05-11 03:10:47 +08:00
|
|
|
of the analyzer. If this option is not specified, a directory is
|
|
|
|
created in /tmp (TMPDIR on Mac OS X) to store the reports.
|
2012-05-25 04:13:47 +08:00
|
|
|
.It Fl plist
|
|
|
|
Output the results as a set of
|
|
|
|
.Li .plist
|
2012-05-11 03:10:47 +08:00
|
|
|
files. (By default the output of
|
|
|
|
.Nm
|
|
|
|
is a set of HTML files.)
|
2012-05-25 04:13:47 +08:00
|
|
|
.It Fl plist-html
|
2012-05-11 03:10:47 +08:00
|
|
|
Output the results as a set of HTML and .plist files
|
2012-05-25 04:13:47 +08:00
|
|
|
.It Fl Fl status-bugs
|
2012-05-11 03:10:47 +08:00
|
|
|
Set exit status to 1 if it found potential bugs and 0 otherwise. By
|
|
|
|
default the exit status of
|
|
|
|
.Nm
|
2012-05-25 04:13:47 +08:00
|
|
|
is that returned by
|
|
|
|
.Ar build_command .
|
|
|
|
.It Fl Fl use-c++ Ns Op = Ns Ar compiler_path
|
2012-05-11 03:10:47 +08:00
|
|
|
Guess the default compiler for your C++ and Objective-C++ code. Use this
|
|
|
|
option to specify an alternate compiler.
|
2012-05-25 04:13:47 +08:00
|
|
|
.It Fl Fl use-cc Ns Op = Ns Ar compiler_path
|
2012-05-11 03:10:47 +08:00
|
|
|
Guess the default compiler for your C and Objective-C code. Use this
|
|
|
|
option to specify an alternate compiler.
|
|
|
|
.It Fl v
|
|
|
|
Verbose output from
|
|
|
|
.Nm
|
|
|
|
and the analyzer. A second and
|
2012-05-25 04:13:47 +08:00
|
|
|
third
|
2012-05-11 03:10:47 +08:00
|
|
|
.Ar v
|
|
|
|
increases verbosity.
|
2012-05-25 04:13:47 +08:00
|
|
|
.It Fl V , Fl Fl view
|
2012-05-11 03:10:47 +08:00
|
|
|
View analysis results in a web browser when the build completes.
|
|
|
|
.It Fl constraints Op Ar model
|
|
|
|
Specify the contraint engine used by the analyzer. By default the
|
|
|
|
.Ql range
|
2012-05-25 04:13:47 +08:00
|
|
|
model is used. Specifying
|
2012-05-11 03:10:47 +08:00
|
|
|
.Ql basic
|
|
|
|
uses a simpler, less powerful constraint model used by checker-0.160
|
|
|
|
and earlier.
|
|
|
|
.It Fl maxloop Ar N
|
|
|
|
Specifiy the number of times a block can be visited before giving
|
|
|
|
up. Default is 4. Increase for more comprehensive coverage at a
|
|
|
|
cost of speed.
|
|
|
|
.It Fl no-failure-reports
|
|
|
|
Do not create a
|
|
|
|
.Ql failures
|
|
|
|
subdirectory that includes analyzer crash reports and preprocessed
|
|
|
|
source files.
|
|
|
|
.It Fl stats
|
|
|
|
Generates visitation statistics for the project being analyzed.
|
|
|
|
.It Fl store Op Ar model
|
|
|
|
Specify the store model used by the analyzer. By default, the
|
|
|
|
.Ql region
|
|
|
|
store model is used.
|
|
|
|
.Ql region
|
|
|
|
specifies a field-
|
|
|
|
sensitive store model. Users can also specify
|
|
|
|
.Ql basic
|
2012-05-25 04:13:47 +08:00
|
|
|
which is far less precise but can more quickly analyze code.
|
2012-05-11 03:10:47 +08:00
|
|
|
.Ql basic
|
|
|
|
was the default store model for checker-0.221 and earlier.
|
2012-05-25 04:13:47 +08:00
|
|
|
.\"
|
2012-05-11 03:10:47 +08:00
|
|
|
.El
|
|
|
|
.Sh RETURN VALUES
|
|
|
|
.Nm
|
2012-05-25 04:13:47 +08:00
|
|
|
returns the value returned by
|
|
|
|
.Ar build_command
|
|
|
|
unless
|
|
|
|
.Fl Fl status-bugs
|
|
|
|
or
|
|
|
|
.Fl Fl keep-going
|
2012-05-11 03:10:47 +08:00
|
|
|
is used.
|
|
|
|
.\"
|
|
|
|
.\" Other sections not yet used ...
|
|
|
|
.\" .Sh ENVIRONMENT
|
|
|
|
.\" .Sh FILES
|
|
|
|
.\" .Sh DIAGNOSTICS
|
|
|
|
.\" .Sh COMPATIBILITY
|
|
|
|
.\" .Sh HISTORY
|
|
|
|
.\" .Sh BUGS
|
|
|
|
.\"
|
2012-05-25 04:13:47 +08:00
|
|
|
.Sh CHECKERS
|
2012-05-11 03:10:47 +08:00
|
|
|
The checkers listed below may be enabled/disabled using the
|
|
|
|
.Fl enable-checker
|
2012-05-25 04:13:47 +08:00
|
|
|
and
|
2012-05-11 03:10:47 +08:00
|
|
|
.Fl disable-checker
|
2012-05-25 04:13:47 +08:00
|
|
|
options.
|
|
|
|
A default group of checkers is run unless explicitly disabled.
|
|
|
|
Exactly which checkers constitute the default group is a function
|
|
|
|
of the operating system in use; they are listed with
|
|
|
|
.Fl Fl help-checkers .
|
|
|
|
.Bl -tag -width indent.
|
2012-05-11 03:10:47 +08:00
|
|
|
.It core.AdjustedReturnValue
|
|
|
|
Check to see if the return value of a function call is different than
|
2012-05-25 04:13:47 +08:00
|
|
|
the caller expects (e.g., from calls through function pointers).
|
2012-05-11 03:10:47 +08:00
|
|
|
.It core.AttributeNonNull
|
|
|
|
Check for null pointers passed as arguments to a function whose arguments are marked with the
|
2012-05-25 04:13:47 +08:00
|
|
|
.Ql nonnull
|
|
|
|
attribute.
|
2012-05-11 03:10:47 +08:00
|
|
|
.It core.CallAndMessage
|
2012-05-25 04:13:47 +08:00
|
|
|
Check for logical errors for function calls and Objective-C message expressions (e.g., uninitialized arguments, null function pointers).
|
2012-05-11 03:10:47 +08:00
|
|
|
.It core.DivideZero
|
2012-05-25 04:13:47 +08:00
|
|
|
Check for division by zero.
|
2012-05-11 03:10:47 +08:00
|
|
|
.It core.NullDereference
|
2012-05-25 04:13:47 +08:00
|
|
|
Check for dereferences of null pointers.
|
2012-05-11 03:10:47 +08:00
|
|
|
.It core.StackAddressEscape
|
2012-05-25 04:13:47 +08:00
|
|
|
Check that addresses to stack memory do not escape the function.
|
2012-05-11 03:10:47 +08:00
|
|
|
.It core.UndefinedBinaryOperatorResult
|
2012-05-25 04:13:47 +08:00
|
|
|
Check for undefined results of binary operators.
|
2012-05-11 03:10:47 +08:00
|
|
|
.It core.VLASize
|
2012-05-25 04:13:47 +08:00
|
|
|
Check for declarations of VLA of undefined or zero size.
|
2012-05-11 03:10:47 +08:00
|
|
|
.It core.builtin.BuiltinFunctions
|
2012-05-25 04:13:47 +08:00
|
|
|
Evaluate compiler builtin functions, e.g.
|
|
|
|
.Fn alloca .
|
|
|
|
.It core.builtin.NoReturnFunctions
|
|
|
|
Evaluate
|
|
|
|
.Ql panic
|
|
|
|
functions that are known to not return to the caller.
|
2012-05-11 03:10:47 +08:00
|
|
|
.It core.uninitialized.ArraySubscript
|
2012-05-25 04:13:47 +08:00
|
|
|
Check for uninitialized values used as array subscripts.
|
2012-05-11 03:10:47 +08:00
|
|
|
.It core.uninitialized.Assign
|
2012-05-25 04:13:47 +08:00
|
|
|
Check for assigning uninitialized values.
|
|
|
|
.It core.uninitialized.Branch
|
|
|
|
Check for uninitialized values used as branch conditions.
|
2012-05-11 03:10:47 +08:00
|
|
|
.It core.uninitialized.CapturedBlockVariable
|
2012-05-25 04:13:47 +08:00
|
|
|
Check for blocks that capture uninitialized values.
|
|
|
|
.It core.uninitialized.UndefReturn
|
|
|
|
Check for uninitialized values being returned to the caller.
|
2012-05-11 03:10:47 +08:00
|
|
|
.It deadcode.DeadStores
|
2012-05-25 04:13:47 +08:00
|
|
|
Check for values stored to variables that are never read afterwards.
|
2012-05-11 03:10:47 +08:00
|
|
|
.It debug.DumpCFG
|
2012-05-25 04:13:47 +08:00
|
|
|
Display Control-Flow Graphs.
|
2012-05-11 03:10:47 +08:00
|
|
|
.It debug.DumpCallGraph
|
2012-05-25 04:13:47 +08:00
|
|
|
Display Call Graph.
|
2012-05-11 03:10:47 +08:00
|
|
|
.It debug.DumpDominators
|
2012-05-25 04:13:47 +08:00
|
|
|
Print the dominance tree for a given Control-Flow Graph.
|
2012-05-11 03:10:47 +08:00
|
|
|
.It debug.DumpLiveVars
|
2012-05-25 04:13:47 +08:00
|
|
|
Print results of live variable analysis.
|
2012-05-11 03:10:47 +08:00
|
|
|
.It debug.Stats
|
2012-05-25 04:13:47 +08:00
|
|
|
Emit warnings with analyzer statistics.
|
2012-05-11 03:10:47 +08:00
|
|
|
.It debug.TaintTest
|
|
|
|
Mark tainted symbols as such.
|
|
|
|
.It debug.ViewCFG
|
2012-05-25 04:13:47 +08:00
|
|
|
View Control-Flow Graphs using
|
|
|
|
.Ic GraphViz .
|
2012-05-11 03:10:47 +08:00
|
|
|
.It debug.ViewCallGraph
|
2012-05-25 04:13:47 +08:00
|
|
|
View Call Graph using
|
|
|
|
.Ic GraphViz .
|
2012-05-11 03:10:47 +08:00
|
|
|
.It llvm.Conventions
|
2012-05-25 04:13:47 +08:00
|
|
|
Check code for LLVM codebase conventions.
|
2012-05-11 03:10:47 +08:00
|
|
|
.It osx.API
|
2012-05-25 04:13:47 +08:00
|
|
|
Check for proper uses of various Mac OS X APIs.
|
2012-05-11 03:10:47 +08:00
|
|
|
.It osx.AtomicCAS
|
2012-05-25 04:13:47 +08:00
|
|
|
Evaluate calls to
|
|
|
|
.Vt OSAtomic
|
|
|
|
functions.
|
2012-05-11 03:10:47 +08:00
|
|
|
.It osx.SecKeychainAPI
|
2012-05-25 04:13:47 +08:00
|
|
|
Check for proper uses of Secure Keychain APIs.
|
2012-05-11 03:10:47 +08:00
|
|
|
.It osx.cocoa.AtSync
|
2012-05-25 04:13:47 +08:00
|
|
|
Check for null pointers used as mutexes for @synchronized.
|
2012-05-11 03:10:47 +08:00
|
|
|
.It osx.cocoa.ClassRelease
|
2012-05-25 04:13:47 +08:00
|
|
|
Check for sending
|
|
|
|
.Ql retain ,
|
|
|
|
.Ql release,
|
|
|
|
or
|
|
|
|
.Ql autorelease
|
|
|
|
directly to a Class.
|
2012-05-11 03:10:47 +08:00
|
|
|
.It osx.cocoa.IncompatibleMethodTypes
|
2012-05-25 04:13:47 +08:00
|
|
|
Warn about Objective-C method signatures with type incompatibilities.
|
2012-05-11 03:10:47 +08:00
|
|
|
.It osx.cocoa.NSAutoreleasePool
|
2012-05-25 04:13:47 +08:00
|
|
|
Warn for suboptimal uses of
|
|
|
|
.Vt NSAutoreleasePool
|
|
|
|
in Objective-C GC mode.
|
2012-05-11 03:10:47 +08:00
|
|
|
.It osx.cocoa.NSError
|
2012-05-25 04:13:47 +08:00
|
|
|
Check usage of NSError** parameters.
|
2012-05-11 03:10:47 +08:00
|
|
|
.It osx.cocoa.NilArg
|
2012-05-25 04:13:47 +08:00
|
|
|
Check for prohibited nil arguments to Objective-C method calls.
|
2012-05-11 03:10:47 +08:00
|
|
|
.It osx.cocoa.RetainCount
|
2012-05-25 04:13:47 +08:00
|
|
|
Check for leaks and improper reference count management.
|
2012-05-11 03:10:47 +08:00
|
|
|
.It osx.cocoa.SelfInit
|
2012-05-25 04:13:47 +08:00
|
|
|
Check that
|
|
|
|
.Ql self
|
|
|
|
is properly initialized inside an initializer method.
|
2012-05-11 03:10:47 +08:00
|
|
|
.It osx.cocoa.UnusedIvars
|
2012-05-25 04:13:47 +08:00
|
|
|
Warn about private ivars that are never used.
|
2012-05-11 03:10:47 +08:00
|
|
|
.It osx.cocoa.VariadicMethodTypes
|
2012-05-25 04:13:47 +08:00
|
|
|
Check for passing non-Objective-C types to variadic methods that expect only Objective-C types.
|
2012-05-11 03:10:47 +08:00
|
|
|
.It osx.coreFoundation.CFError
|
2012-05-25 04:13:47 +08:00
|
|
|
Check usage of CFErrorRef* parameters.
|
2012-05-11 03:10:47 +08:00
|
|
|
.It osx.coreFoundation.CFNumber
|
2012-05-25 04:13:47 +08:00
|
|
|
Check for proper uses of
|
|
|
|
.Fn CFNumberCreate .
|
2012-05-11 03:10:47 +08:00
|
|
|
.It osx.coreFoundation.CFRetainRelease
|
2012-05-25 04:13:47 +08:00
|
|
|
Check for null arguments to
|
|
|
|
.Fn CFRetain
|
|
|
|
and
|
|
|
|
.Fn CFRelease .
|
2012-05-11 03:10:47 +08:00
|
|
|
.It osx.coreFoundation.containers.OutOfBounds
|
2012-05-25 04:13:47 +08:00
|
|
|
Checks for index out-of-bounds when using the
|
|
|
|
.Vt CFArray
|
|
|
|
API.
|
2012-05-11 03:10:47 +08:00
|
|
|
.It osx.coreFoundation.containers.PointerSizedValues
|
2012-05-25 04:13:47 +08:00
|
|
|
Warns if
|
|
|
|
.Vt CFArray ,
|
|
|
|
.Vt CFDictionary ,
|
|
|
|
or
|
|
|
|
.Vt CFSet
|
|
|
|
are created with non-pointer-size values.
|
2012-05-11 03:10:47 +08:00
|
|
|
.It security.FloatLoopCounter
|
2012-05-25 04:13:47 +08:00
|
|
|
Warn on using a floating point value as a loop counter (CERT: FLP30-C, FLP30-CPP).
|
2012-05-11 03:10:47 +08:00
|
|
|
.It security.insecureAPI.UncheckedReturn
|
2012-05-25 04:13:47 +08:00
|
|
|
Warn on uses of functions whose return values must be always checked.
|
2012-05-11 03:10:47 +08:00
|
|
|
.It security.insecureAPI.getpw
|
2012-05-25 04:13:47 +08:00
|
|
|
Warn on uses of
|
|
|
|
.Fn getpw .
|
2012-05-11 03:10:47 +08:00
|
|
|
.It security.insecureAPI.gets
|
2012-05-25 04:13:47 +08:00
|
|
|
Warn on uses of
|
|
|
|
.Fn gets .
|
2012-05-11 03:10:47 +08:00
|
|
|
.It security.insecureAPI.mkstemp
|
2012-05-25 04:13:47 +08:00
|
|
|
Warn when
|
|
|
|
.Fn mkstemp
|
|
|
|
is passed fewer than 6 X's in the format string.
|
2012-05-11 03:10:47 +08:00
|
|
|
.It security.insecureAPI.mktemp
|
2012-05-25 04:13:47 +08:00
|
|
|
Warn on uses of
|
|
|
|
.Fn mktemp .
|
2012-05-11 03:10:47 +08:00
|
|
|
.It security.insecureAPI.rand
|
2012-05-25 04:13:47 +08:00
|
|
|
Warn on uses of
|
|
|
|
.Fn rand ,
|
|
|
|
.Fn random ,
|
|
|
|
and related functions.
|
2012-05-11 03:10:47 +08:00
|
|
|
.It security.insecureAPI.strcpy
|
2012-05-25 04:13:47 +08:00
|
|
|
Warn on uses of
|
|
|
|
.Fn strcpy
|
|
|
|
and
|
|
|
|
.Fn strcat .
|
2012-05-11 03:10:47 +08:00
|
|
|
.It security.insecureAPI.vfork
|
2012-05-25 04:13:47 +08:00
|
|
|
Warn on uses of
|
|
|
|
.Fn vfork .
|
2012-05-11 03:10:47 +08:00
|
|
|
.It unix.API
|
2012-05-25 04:13:47 +08:00
|
|
|
Check calls to various UNIX/Posix functions.
|
2012-05-11 03:10:47 +08:00
|
|
|
.It unix.Malloc
|
2012-05-25 04:13:47 +08:00
|
|
|
Check for memory leaks, double free, and use-after-free.
|
2012-05-11 03:10:47 +08:00
|
|
|
.It unix.cstring.BadSizeArg
|
2012-05-25 04:13:47 +08:00
|
|
|
Check the size argument passed into C string functions for common
|
|
|
|
erroneous patterns.
|
2012-05-11 03:10:47 +08:00
|
|
|
.It unix.cstring.NullArg
|
2012-05-25 04:13:47 +08:00
|
|
|
Check for null pointers being passed as arguments to C string functions.
|
2012-05-11 03:10:47 +08:00
|
|
|
.El
|
|
|
|
.\"
|
|
|
|
.Sh EXAMPLE
|
|
|
|
.Ic scan-build -o /tmp/myhtmldir make -j4
|
|
|
|
.Pp
|
|
|
|
The above example causes analysis reports to be deposited into
|
|
|
|
a subdirectory of
|
2012-05-25 04:13:47 +08:00
|
|
|
.Pa /tmp/myhtmldir
|
2012-05-11 03:10:47 +08:00
|
|
|
and to run
|
2012-05-25 04:13:47 +08:00
|
|
|
.Ic make
|
2012-05-11 03:10:47 +08:00
|
|
|
with the
|
2012-05-25 04:13:47 +08:00
|
|
|
.Fl j4
|
2012-05-11 03:10:47 +08:00
|
|
|
option.
|
|
|
|
A different subdirectory is created each time
|
|
|
|
.Nm
|
|
|
|
analyzes a project.
|
|
|
|
The analyzer should support most parallel builds, but not distributed builds.
|
2012-05-25 04:13:47 +08:00
|
|
|
.Sh AUTHORS
|
|
|
|
.Nm
|
|
|
|
was written by
|
|
|
|
.An "Ted Kremenek" .
|
|
|
|
Documentation contributed by
|
|
|
|
.An "James K. Lowden" Aq jklowden@schemamania.org .
|