SCAN-BUILD(1)
π SCAN-BUILD π
okay so bestie, welcome to the scan-build page β that's the Clang static analyzer, and yes it lives in section 1 of your General Commands Manual. pull up a chair, grab a strawberry π, we're doing this.
β¨ NAME β¨
scan-build β the Clang static analyzer, fr fr
β¨ SYNOPSIS β¨
scan-build [-ohkvV] [-analyze-headers] [-enable-checker [checker_name]]
[-disable-checker [checker_name]] [--help] [--help-checkers]
[--html-title [=title]] [--keep-going] [-plist] [-plist-html]
[--status-bugs] [--use-c++ [=compiler_path]]
[--use-cc [=compiler_path]] [--view] [-constraints [model]]
[-maxloop N] [-no-failure-reports] [-stats] [-store [model]]
build_command [build_options]
β¨ DESCRIPTION β¨
so scan-build is a Perl script that invokes the Clang static analyzer. that's the whole vibe. π
the way it works: all the options meant for scan-build or for the analyzer come first, and then you hand it the build_command plus whatever build_options you'd normally use to build the target system. analyzer options, then build stuff. order matters, bestie.
the static analyzer runs a whole long list of checking algorithms β scroll down to CHECKERS for that. and the output? it can be written in standard .plist and/or HTML format. your call. π
the following options are supported:
β¨ OPTIONS β¨
-analyze-headersβ also analyze functions inside#includedfiles. going deep, no cap.-enable-checkerchecker_name ,-disable-checkerchecker_name β turn checker_name on or off. peek at CHECKERS for the roster. β¨-h,--helpβ displays this message. hi, hello, that's the one you're reading.--help-checkersβ lists the default checkers. again, CHECKERS. π--html-title[=*title*]β sets the title used on the generated HTML pages. if you don't pass title, a default title gets generated for you. π-k,--keep-goingβ adds a "keep on going" option to build_command. right now it supportsmakeandxcodebuild. it's a convenience option, ngl β you could just set this behavior directly with build options if you wanted. your choice, main character.-oβ target directory for the HTML report files. subdirectories get created as needed to represent separate invocations of the analyzer. and if you don't specify this option? a directory gets created in/tmp(TMPDIRon Mac OS X) to store the reports. π¦-plistβ outputs the results as a set of.plistfiles. (by default the output ofscan-buildis a set of HTML files, fyi.)-plist-htmlβ outputs the results as a set of HTML and.plistfiles. both. why not. π--status-bugsβ sets the exit status to1if it found potential bugs, and0otherwise. by default the exit status ofscan-buildis whatever build_command returned. π--use-c++[=*compiler_path*]β guesses the default compiler for your C++ and Objective-C++ code. use this option to specify an alternate compiler. π§--use-cc[=*compiler_path*]β guesses the default compiler for your C and Objective-C code. use this option to specify an alternate compiler.-vβ verbose output fromscan-buildand the analyzer. a second and thirdvincreases verbosity. v, vv, vvv β escalating. π-V,--viewβ view the analysis results in a web browser when the build completes. cute lil report, in your browser. πΈ-constraints [*model*]β specify the constraint engine used by the analyzer. by default the'range'model is used. specifying'basic'uses a simpler, less powerful constraint model β the one used bychecker-0.160and earlier.-maxloopN β specify the number of times a block can be visited before giving up. default is4. increase it for more comprehensive coverage, at a cost of speed. πβοΈ-no-failure-reportsβ do not create a'failures'subdirectory that includes analyzer crash reports and preprocessed source files.-statsβ generates visitation statistics for the project being analyzed. π-store [*model*]β specify the store model used by the analyzer. by default, the'region'store model is used.'region'specifies a field-sensitive store model. users can also specify'basic', which is far less precise but can more quickly analyze code.'basic'was the default store model forchecker-0.221and earlier.
β¨ EXIT STATUS β¨
scan-build returns the value returned by build_command β unless --status-bugs or --keep-going is used. π don't forget that part.
β¨ CHECKERS β¨
all the checkers listed below can be enabled/disabled with the -enable-checker and -disable-checker options. a default group of checkers runs unless you explicitly disable them. exactly which checkers make up that default group is a function of the operating system you're on, bestie β and you can list them with --help-checkers. π«Ά
core.AdjustedReturnValueβ check to see if the return value of a function call is different than the caller expects (e.g., from calls through function pointers).core.AttributeNonNullβ check for null pointers passed as arguments to a function whose arguments are marked with the'nonnull'attribute.core.CallAndMessageβ check for logical errors for function calls and Objective-C message expressions (e.g., uninitialized arguments, null function pointers).core.DivideZeroβ check for division by zero.core.NullDereferenceβ check for dereferences of null pointers. π¬core.StackAddressEscapeβ check that addresses to stack memory do not escape the function.core.UndefinedBinaryOperatorResultβ check for undefined results of binary operators.core.VLASizeβ check for declarations of VLA of undefined or zero size.core.builtin.BuiltinFunctionsβ evaluate compiler builtin functions, e.g.alloca().core.builtin.NoReturnFunctionsβ evaluate'panic'functions that are known to not return to the caller.core.uninitialized.ArraySubscriptβ check for uninitialized values used as array subscripts.core.uninitialized.Assignβ check for assigning uninitialized values.core.uninitialized.Branchβ check for uninitialized values used as branch conditions.core.uninitialized.CapturedBlockVariableβ check for blocks that capture uninitialized values.core.uninitialized.UndefReturnβ check for uninitialized values being returned to the caller.deadcode.DeadStoresβ check for values stored to variables that are never read afterwards. rip to those writes.debug.DumpCFGβ display Control-Flow Graphs.debug.DumpCallGraphβ display Call Graph.debug.DumpDominatorsβ print the dominance tree for a given Control-Flow Graph.debug.DumpLiveVarsβ print results of live variable analysis.debug.Statsβ emit warnings with analyzer statistics.debug.TaintTestβ mark tainted symbols as such. πdebug.ViewCFGβ view Control-Flow Graphs using GraphViz.debug.ViewCallGraphβ view Call Graph using GraphViz.llvm.Conventionsβ check code for LLVM codebase conventions.osx.APIβ check for proper uses of various Mac OS X APIs.osx.AtomicCASβ evaluate calls toOSAtomicfunctions.osx.SecKeychainAPIβ check for proper uses of Secure Keychain APIs.osx.cocoa.AtSyncβ check for null pointers used as mutexes for@synchronized.osx.cocoa.ClassReleaseβ check for sending'retain','release,'or'autorelease'directly to a Class.osx.cocoa.IncompatibleMethodTypesβ warn about Objective-C method signatures with type incompatibilities.osx.cocoa.NSAutoreleasePoolβ warn for suboptimal uses ofNSAutoreleasePoolin Objective-C GC mode.osx.cocoa.NSErrorβ check usage ofNSError**parameters.osx.cocoa.NilArgβ check for prohibitednilarguments to Objective-C method calls.osx.cocoa.RetainCountβ check for leaks and improper reference count management.osx.cocoa.SelfInitβ check that'self'is properly initialized inside an initializer method.osx.cocoa.UnusedIvarsβ warn about private ivars that are never used.osx.cocoa.VariadicMethodTypesβ check for passing non-Objective-C types to variadic methods that expect only Objective-C types.osx.coreFoundation.CFErrorβ check usage ofCFErrorRef*parameters.osx.coreFoundation.CFNumberβ check for proper uses ofCFNumberCreate().osx.coreFoundation.CFRetainReleaseβ check for null arguments toCFRetain(),CFRelease(), andCFMakeCollectable().osx.coreFoundation.containers.OutOfBoundsβ checks for index out-of-bounds when using theCFArrayAPI.osx.coreFoundation.containers.PointerSizedValuesβ warns ifCFArray,CFDictionary, orCFSetare created with non-pointer-size values.security.FloatLoopCounterβ warn on using a floating point value as a loop counter (CERT:FLP30-C,FLP30-CPP).security.insecureAPI.UncheckedReturnβ warn on uses of functions whose return values must be always checked.security.insecureAPI.getpwβ warn on uses ofgetpw().security.insecureAPI.getsβ warn on uses ofgets().security.insecureAPI.mkstempβ warn whenmkstemp()is passed fewer than 6X's in the format string.security.insecureAPI.mktempβ warn on uses ofmktemp().security.insecureAPI.randβ warn on uses ofrand(),random(), and related functions.security.insecureAPI.strcpyβ warn on uses ofstrcpy()andstrcat().security.insecureAPI.vforkβ warn on uses ofvfork().unix.APIβ check calls to various UNIX/Posix functions.unix.Mallocβ check for memory leaks, double free, and use-after-free. the big three πunix.cstring.BadSizeArgβ check the size argument passed into C string functions for common erroneous patterns.unix.cstring.NullArgβ check for null pointers being passed as arguments to C string functions.
β¨ EXAMPLE β¨
scan-build -o /tmp/myhtmldir make -j4
the example above makes the analysis reports land in a subdirectory of /tmp/myhtmldir, and runs make with the -j4 option. a different subdirectory gets created every single time scan-build analyzes a project. iconic behavior honestly.
the analyzer should support most parallel builds, but not distributed builds. know the limits, bestie. π«
β¨ AUTHORS β¨
scan-build was written by Ted Kremenek. documentation contributed by James K. Lowden <jklowden@schemamania.org>.
and that's the whole page, babe π this one shipped with clang 3.5, dated May 25, 2012 β old money, still eating. go analyze something. π
β¨
π¦ where this page comes from
- debian bookworm: clang-tools-13 1:13.0.1-11+b2 Β· APACHE-2-LLVM-EXCEPTIONS
- ubuntu jammy: clang-tools-13 1:13.0.1-2ubuntu2 Β· APACHE-2-LLVM-EXCEPTIONS
- ubuntu jammy: clang-tools-13 1:13.0.1-2ubuntu2.2 Β· APACHE-2-LLVM-EXCEPTIONS
- π the page's license: Apache-2.0 WITH LLVM-exception
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms