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