1*67e74705SXin Li.\" This file is distributed under the University of Illinois Open Source 2*67e74705SXin Li.\" License. See LICENSE.TXT for details. 3*67e74705SXin Li.\" $Id$ 4*67e74705SXin Li.Dd May 25, 2012 5*67e74705SXin Li.Dt SCAN-BUILD 1 6*67e74705SXin Li.Os "clang" "3.5" 7*67e74705SXin Li.Sh NAME 8*67e74705SXin Li.Nm scan-build 9*67e74705SXin Li.Nd Clang static analyzer 10*67e74705SXin Li.Sh SYNOPSIS 11*67e74705SXin Li.Nm 12*67e74705SXin Li.Op Fl ohkvV 13*67e74705SXin Li.Op Fl analyze-headers 14*67e74705SXin Li.Op Fl enable-checker Op Ar checker_name 15*67e74705SXin Li.Op Fl disable-checker Op Ar checker_name 16*67e74705SXin Li.Op Fl Fl help 17*67e74705SXin Li.Op Fl Fl help-checkers 18*67e74705SXin Li.Op Fl Fl html-title Op Ar =title 19*67e74705SXin Li.Op Fl Fl keep-going 20*67e74705SXin Li.Op Fl plist 21*67e74705SXin Li.Op Fl plist-html 22*67e74705SXin Li.Op Fl Fl status-bugs 23*67e74705SXin Li.Op Fl Fl use-c++ Op Ar =compiler_path 24*67e74705SXin Li.Op Fl Fl use-cc Op Ar =compiler_path 25*67e74705SXin Li.Op Fl Fl view 26*67e74705SXin Li.Op Fl constraints Op Ar model 27*67e74705SXin Li.Op Fl maxloop Ar N 28*67e74705SXin Li.Op Fl no-failure-reports 29*67e74705SXin Li.Op Fl stats 30*67e74705SXin Li.Op Fl store Op Ar model 31*67e74705SXin Li.Ar build_command 32*67e74705SXin Li.Op build_options 33*67e74705SXin Li.\" 34*67e74705SXin Li.\" Sh DESCRIPTION 35*67e74705SXin Li.Sh DESCRIPTION 36*67e74705SXin Li.Nm 37*67e74705SXin Liis a Perl script that invokes the Clang static analyzer. Options used by 38*67e74705SXin Li.Nm 39*67e74705SXin Lior by the analyzer appear first, followed by the 40*67e74705SXin Li.Ar build_command 41*67e74705SXin Liand any 42*67e74705SXin Li.Ar build_options 43*67e74705SXin Linormally used to build the target system. 44*67e74705SXin Li.Pp 45*67e74705SXin LiThe static analyzer employs a long list of checking algorithms, see 46*67e74705SXin Li.Sx CHECKERS . 47*67e74705SXin LiOutput can be written in standard 48*67e74705SXin Li.Li .plist 49*67e74705SXin Liand/or HTML format. 50*67e74705SXin Li.Pp 51*67e74705SXin LiThe following options are supported: 52*67e74705SXin Li.Bl -tag -width indent 53*67e74705SXin Li.It Fl analyze-headers 54*67e74705SXin LiAlso analyze functions in #included files. 55*67e74705SXin Li.It Fl enable-checker Ar checker_name , Fl disable-checker Ar checker_name 56*67e74705SXin LiEnable/disable 57*67e74705SXin Li.Ar checker_name . 58*67e74705SXin LiSee 59*67e74705SXin Li.Sx CHECKERS . 60*67e74705SXin Li.It Fl h , Fl Fl help 61*67e74705SXin LiDisplay this message. 62*67e74705SXin Li.It Fl Fl help-checkers 63*67e74705SXin LiList default checkers, see 64*67e74705SXin Li.Sx CHECKERS . 65*67e74705SXin Li.It Fl Fl html-title Ns Op = Ns Ar title 66*67e74705SXin LiSpecify the title used on generated HTML pages. 67*67e74705SXin LiA default title is generated if 68*67e74705SXin Li.Ar title 69*67e74705SXin Liis not specified. 70*67e74705SXin Li.It Fl k , Fl Fl keep-going 71*67e74705SXin LiAdd a 72*67e74705SXin Li.Dq keep on going 73*67e74705SXin Lioption to 74*67e74705SXin Li.Ar build_command . 75*67e74705SXin LiCurrently supports make and xcodebuild. This is a convenience option; 76*67e74705SXin Lione can specify this behavior directly using build options. 77*67e74705SXin Li.It Fl o 78*67e74705SXin LiTarget directory for HTML report files. Subdirectories will be 79*67e74705SXin Licreated as needed to represent separate invocations 80*67e74705SXin Liof the analyzer. If this option is not specified, a directory is 81*67e74705SXin Licreated in /tmp (TMPDIR on Mac OS X) to store the reports. 82*67e74705SXin Li.It Fl plist 83*67e74705SXin LiOutput the results as a set of 84*67e74705SXin Li.Li .plist 85*67e74705SXin Lifiles. (By default the output of 86*67e74705SXin Li.Nm 87*67e74705SXin Liis a set of HTML files.) 88*67e74705SXin Li.It Fl plist-html 89*67e74705SXin LiOutput the results as a set of HTML and .plist files 90*67e74705SXin Li.It Fl Fl status-bugs 91*67e74705SXin LiSet exit status to 1 if it found potential bugs and 0 otherwise. By 92*67e74705SXin Lidefault the exit status of 93*67e74705SXin Li.Nm 94*67e74705SXin Liis that returned by 95*67e74705SXin Li.Ar build_command . 96*67e74705SXin Li.It Fl Fl use-c++ Ns Op = Ns Ar compiler_path 97*67e74705SXin LiGuess the default compiler for your C++ and Objective-C++ code. Use this 98*67e74705SXin Lioption to specify an alternate compiler. 99*67e74705SXin Li.It Fl Fl use-cc Ns Op = Ns Ar compiler_path 100*67e74705SXin LiGuess the default compiler for your C and Objective-C code. Use this 101*67e74705SXin Lioption to specify an alternate compiler. 102*67e74705SXin Li.It Fl v 103*67e74705SXin LiVerbose output from 104*67e74705SXin Li.Nm 105*67e74705SXin Liand the analyzer. A second and 106*67e74705SXin Lithird 107*67e74705SXin Li.Ar v 108*67e74705SXin Liincreases verbosity. 109*67e74705SXin Li.It Fl V , Fl Fl view 110*67e74705SXin LiView analysis results in a web browser when the build completes. 111*67e74705SXin Li.It Fl constraints Op Ar model 112*67e74705SXin LiSpecify the contraint engine used by the analyzer. By default the 113*67e74705SXin Li.Ql range 114*67e74705SXin Limodel is used. Specifying 115*67e74705SXin Li.Ql basic 116*67e74705SXin Liuses a simpler, less powerful constraint model used by checker-0.160 117*67e74705SXin Liand earlier. 118*67e74705SXin Li.It Fl maxloop Ar N 119*67e74705SXin LiSpecifiy the number of times a block can be visited before giving 120*67e74705SXin Liup. Default is 4. Increase for more comprehensive coverage at a 121*67e74705SXin Licost of speed. 122*67e74705SXin Li.It Fl no-failure-reports 123*67e74705SXin LiDo not create a 124*67e74705SXin Li.Ql failures 125*67e74705SXin Lisubdirectory that includes analyzer crash reports and preprocessed 126*67e74705SXin Lisource files. 127*67e74705SXin Li.It Fl stats 128*67e74705SXin LiGenerates visitation statistics for the project being analyzed. 129*67e74705SXin Li.It Fl store Op Ar model 130*67e74705SXin LiSpecify the store model used by the analyzer. By default, the 131*67e74705SXin Li.Ql region 132*67e74705SXin Listore model is used. 133*67e74705SXin Li.Ql region 134*67e74705SXin Lispecifies a field- 135*67e74705SXin Lisensitive store model. Users can also specify 136*67e74705SXin Li.Ql basic 137*67e74705SXin Liwhich is far less precise but can more quickly analyze code. 138*67e74705SXin Li.Ql basic 139*67e74705SXin Liwas the default store model for checker-0.221 and earlier. 140*67e74705SXin Li.\" 141*67e74705SXin Li.El 142*67e74705SXin Li.Sh EXIT STATUS 143*67e74705SXin Li.Nm 144*67e74705SXin Lireturns the value returned by 145*67e74705SXin Li.Ar build_command 146*67e74705SXin Liunless 147*67e74705SXin Li.Fl Fl status-bugs 148*67e74705SXin Lior 149*67e74705SXin Li.Fl Fl keep-going 150*67e74705SXin Liis used. 151*67e74705SXin Li.\" 152*67e74705SXin Li.\" Other sections not yet used ... 153*67e74705SXin Li.\" .Sh ENVIRONMENT 154*67e74705SXin Li.\" .Sh FILES 155*67e74705SXin Li.\" .Sh DIAGNOSTICS 156*67e74705SXin Li.\" .Sh COMPATIBILITY 157*67e74705SXin Li.\" .Sh HISTORY 158*67e74705SXin Li.\" .Sh BUGS 159*67e74705SXin Li.\" 160*67e74705SXin Li.Sh CHECKERS 161*67e74705SXin LiThe checkers listed below may be enabled/disabled using the 162*67e74705SXin Li.Fl enable-checker 163*67e74705SXin Liand 164*67e74705SXin Li.Fl disable-checker 165*67e74705SXin Lioptions. 166*67e74705SXin LiA default group of checkers is run unless explicitly disabled. 167*67e74705SXin LiExactly which checkers constitute the default group is a function 168*67e74705SXin Liof the operating system in use; they are listed with 169*67e74705SXin Li.Fl Fl help-checkers . 170*67e74705SXin Li.Bl -tag -width indent. 171*67e74705SXin Li.It core.AdjustedReturnValue 172*67e74705SXin LiCheck to see if the return value of a function call is different than 173*67e74705SXin Lithe caller expects (e.g., from calls through function pointers). 174*67e74705SXin Li.It core.AttributeNonNull 175*67e74705SXin LiCheck for null pointers passed as arguments to a function whose arguments are marked with the 176*67e74705SXin Li.Ql nonnull 177*67e74705SXin Liattribute. 178*67e74705SXin Li.It core.CallAndMessage 179*67e74705SXin LiCheck for logical errors for function calls and Objective-C message expressions (e.g., uninitialized arguments, null function pointers). 180*67e74705SXin Li.It core.DivideZero 181*67e74705SXin LiCheck for division by zero. 182*67e74705SXin Li.It core.NullDereference 183*67e74705SXin LiCheck for dereferences of null pointers. 184*67e74705SXin Li.It core.StackAddressEscape 185*67e74705SXin LiCheck that addresses to stack memory do not escape the function. 186*67e74705SXin Li.It core.UndefinedBinaryOperatorResult 187*67e74705SXin LiCheck for undefined results of binary operators. 188*67e74705SXin Li.It core.VLASize 189*67e74705SXin LiCheck for declarations of VLA of undefined or zero size. 190*67e74705SXin Li.It core.builtin.BuiltinFunctions 191*67e74705SXin LiEvaluate compiler builtin functions, e.g. 192*67e74705SXin Li.Fn alloca . 193*67e74705SXin Li.It core.builtin.NoReturnFunctions 194*67e74705SXin LiEvaluate 195*67e74705SXin Li.Ql panic 196*67e74705SXin Lifunctions that are known to not return to the caller. 197*67e74705SXin Li.It core.uninitialized.ArraySubscript 198*67e74705SXin LiCheck for uninitialized values used as array subscripts. 199*67e74705SXin Li.It core.uninitialized.Assign 200*67e74705SXin LiCheck for assigning uninitialized values. 201*67e74705SXin Li.It core.uninitialized.Branch 202*67e74705SXin LiCheck for uninitialized values used as branch conditions. 203*67e74705SXin Li.It core.uninitialized.CapturedBlockVariable 204*67e74705SXin LiCheck for blocks that capture uninitialized values. 205*67e74705SXin Li.It core.uninitialized.UndefReturn 206*67e74705SXin LiCheck for uninitialized values being returned to the caller. 207*67e74705SXin Li.It deadcode.DeadStores 208*67e74705SXin LiCheck for values stored to variables that are never read afterwards. 209*67e74705SXin Li.It debug.DumpCFG 210*67e74705SXin LiDisplay Control-Flow Graphs. 211*67e74705SXin Li.It debug.DumpCallGraph 212*67e74705SXin LiDisplay Call Graph. 213*67e74705SXin Li.It debug.DumpDominators 214*67e74705SXin LiPrint the dominance tree for a given Control-Flow Graph. 215*67e74705SXin Li.It debug.DumpLiveVars 216*67e74705SXin LiPrint results of live variable analysis. 217*67e74705SXin Li.It debug.Stats 218*67e74705SXin LiEmit warnings with analyzer statistics. 219*67e74705SXin Li.It debug.TaintTest 220*67e74705SXin LiMark tainted symbols as such. 221*67e74705SXin Li.It debug.ViewCFG 222*67e74705SXin LiView Control-Flow Graphs using 223*67e74705SXin Li.Ic GraphViz . 224*67e74705SXin Li.It debug.ViewCallGraph 225*67e74705SXin LiView Call Graph using 226*67e74705SXin Li.Ic GraphViz . 227*67e74705SXin Li.It llvm.Conventions 228*67e74705SXin LiCheck code for LLVM codebase conventions. 229*67e74705SXin Li.It osx.API 230*67e74705SXin LiCheck for proper uses of various Mac OS X APIs. 231*67e74705SXin Li.It osx.AtomicCAS 232*67e74705SXin LiEvaluate calls to 233*67e74705SXin Li.Vt OSAtomic 234*67e74705SXin Lifunctions. 235*67e74705SXin Li.It osx.SecKeychainAPI 236*67e74705SXin LiCheck for proper uses of Secure Keychain APIs. 237*67e74705SXin Li.It osx.cocoa.AtSync 238*67e74705SXin LiCheck for null pointers used as mutexes for @synchronized. 239*67e74705SXin Li.It osx.cocoa.ClassRelease 240*67e74705SXin LiCheck for sending 241*67e74705SXin Li.Ql retain , 242*67e74705SXin Li.Ql release, 243*67e74705SXin Lior 244*67e74705SXin Li.Ql autorelease 245*67e74705SXin Lidirectly to a Class. 246*67e74705SXin Li.It osx.cocoa.IncompatibleMethodTypes 247*67e74705SXin LiWarn about Objective-C method signatures with type incompatibilities. 248*67e74705SXin Li.It osx.cocoa.NSAutoreleasePool 249*67e74705SXin LiWarn for suboptimal uses of 250*67e74705SXin Li.Vt NSAutoreleasePool 251*67e74705SXin Liin Objective-C GC mode. 252*67e74705SXin Li.It osx.cocoa.NSError 253*67e74705SXin LiCheck usage of NSError** parameters. 254*67e74705SXin Li.It osx.cocoa.NilArg 255*67e74705SXin LiCheck for prohibited nil arguments to Objective-C method calls. 256*67e74705SXin Li.It osx.cocoa.RetainCount 257*67e74705SXin LiCheck for leaks and improper reference count management. 258*67e74705SXin Li.It osx.cocoa.SelfInit 259*67e74705SXin LiCheck that 260*67e74705SXin Li.Ql self 261*67e74705SXin Liis properly initialized inside an initializer method. 262*67e74705SXin Li.It osx.cocoa.UnusedIvars 263*67e74705SXin LiWarn about private ivars that are never used. 264*67e74705SXin Li.It osx.cocoa.VariadicMethodTypes 265*67e74705SXin LiCheck for passing non-Objective-C types to variadic methods that expect only Objective-C types. 266*67e74705SXin Li.It osx.coreFoundation.CFError 267*67e74705SXin LiCheck usage of CFErrorRef* parameters. 268*67e74705SXin Li.It osx.coreFoundation.CFNumber 269*67e74705SXin LiCheck for proper uses of 270*67e74705SXin Li.Fn CFNumberCreate . 271*67e74705SXin Li.It osx.coreFoundation.CFRetainRelease 272*67e74705SXin LiCheck for null arguments to 273*67e74705SXin Li.Fn CFRetain , 274*67e74705SXin Li.Fn CFRelease , 275*67e74705SXin Liand 276*67e74705SXin Li.Fn CFMakeCollectable . 277*67e74705SXin Li.It osx.coreFoundation.containers.OutOfBounds 278*67e74705SXin LiChecks for index out-of-bounds when using the 279*67e74705SXin Li.Vt CFArray 280*67e74705SXin LiAPI. 281*67e74705SXin Li.It osx.coreFoundation.containers.PointerSizedValues 282*67e74705SXin LiWarns if 283*67e74705SXin Li.Vt CFArray , 284*67e74705SXin Li.Vt CFDictionary , 285*67e74705SXin Lior 286*67e74705SXin Li.Vt CFSet 287*67e74705SXin Liare created with non-pointer-size values. 288*67e74705SXin Li.It security.FloatLoopCounter 289*67e74705SXin LiWarn on using a floating point value as a loop counter (CERT: FLP30-C, FLP30-CPP). 290*67e74705SXin Li.It security.insecureAPI.UncheckedReturn 291*67e74705SXin LiWarn on uses of functions whose return values must be always checked. 292*67e74705SXin Li.It security.insecureAPI.getpw 293*67e74705SXin LiWarn on uses of 294*67e74705SXin Li.Fn getpw . 295*67e74705SXin Li.It security.insecureAPI.gets 296*67e74705SXin LiWarn on uses of 297*67e74705SXin Li.Fn gets . 298*67e74705SXin Li.It security.insecureAPI.mkstemp 299*67e74705SXin LiWarn when 300*67e74705SXin Li.Fn mkstemp 301*67e74705SXin Liis passed fewer than 6 X's in the format string. 302*67e74705SXin Li.It security.insecureAPI.mktemp 303*67e74705SXin LiWarn on uses of 304*67e74705SXin Li.Fn mktemp . 305*67e74705SXin Li.It security.insecureAPI.rand 306*67e74705SXin LiWarn on uses of 307*67e74705SXin Li.Fn rand , 308*67e74705SXin Li.Fn random , 309*67e74705SXin Liand related functions. 310*67e74705SXin Li.It security.insecureAPI.strcpy 311*67e74705SXin LiWarn on uses of 312*67e74705SXin Li.Fn strcpy 313*67e74705SXin Liand 314*67e74705SXin Li.Fn strcat . 315*67e74705SXin Li.It security.insecureAPI.vfork 316*67e74705SXin LiWarn on uses of 317*67e74705SXin Li.Fn vfork . 318*67e74705SXin Li.It unix.API 319*67e74705SXin LiCheck calls to various UNIX/Posix functions. 320*67e74705SXin Li.It unix.Malloc 321*67e74705SXin LiCheck for memory leaks, double free, and use-after-free. 322*67e74705SXin Li.It unix.cstring.BadSizeArg 323*67e74705SXin LiCheck the size argument passed into C string functions for common 324*67e74705SXin Lierroneous patterns. 325*67e74705SXin Li.It unix.cstring.NullArg 326*67e74705SXin LiCheck for null pointers being passed as arguments to C string functions. 327*67e74705SXin Li.El 328*67e74705SXin Li.\" 329*67e74705SXin Li.Sh EXAMPLE 330*67e74705SXin Li.Ic scan-build -o /tmp/myhtmldir make -j4 331*67e74705SXin Li.Pp 332*67e74705SXin LiThe above example causes analysis reports to be deposited into 333*67e74705SXin Lia subdirectory of 334*67e74705SXin Li.Pa /tmp/myhtmldir 335*67e74705SXin Liand to run 336*67e74705SXin Li.Ic make 337*67e74705SXin Liwith the 338*67e74705SXin Li.Fl j4 339*67e74705SXin Lioption. 340*67e74705SXin LiA different subdirectory is created each time 341*67e74705SXin Li.Nm 342*67e74705SXin Lianalyzes a project. 343*67e74705SXin LiThe analyzer should support most parallel builds, but not distributed builds. 344*67e74705SXin Li.Sh AUTHORS 345*67e74705SXin Li.Nm 346*67e74705SXin Liwas written by 347*67e74705SXin Li.An "Ted Kremenek" . 348*67e74705SXin LiDocumentation contributed by 349*67e74705SXin Li.An "James K. Lowden" Aq [email protected] . 350