SCAN-BUILD(1)
π
SCAN-BUILD β the scan-build(1) page, but make it a vibe π
okay bestie, sit down, we're doing a General Commands Manual moment and honestly? it's iconic. this is the scan-build page, and no cap, it's literally the Clang static analyzer β the thing that reads your code and goes "girlβ¦" π
β¨ NAME β¨
scan-build β Clang static analyzer π¦
π 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]
likeβ¦ she has RANGE π
πΈ DESCRIPTION πΈ
scan-build is a Perl script that invokes the Clang static analyzer. the whole deal is: you give her your options, she gives you the analysis. so the options that scan-build or the analyzer use come first, and then you drop in the build_command plus any build_options you'd normally use to build the target system. periodt β¨
the static analyzer runs a whole long list of checking algorithms, so go peek at βCHECKERSβ for that. and the output? she can write it in standard .plist and/or HTML format, your choice, your era π«Ά
here's the tea on the options that are supported:
-analyze-headersβ also analyze functions inside files that got#included. yep, she goes there π-enable-checkerchecker_name,-disable-checkerchecker_nameβ turnchecker_nameon, or turn it off. check βCHECKERSβ for the whole roster π-h,--helpβ display this message. hi, that's the one you're reading π--help-checkersβ list the default checkers, see βCHECKERSβ. the default squad, if you will π--html-title[=*title*]β specify the title used on the generated HTML pages. if you don't hand over atitle, a default title gets generated for you, no stress β¨-k,--keep-goingβ adds a βkeep on goingβ option tobuild_command. currently this supportsmakeandxcodebuild. it's a convenience option, bestie β you could just specify this behavior directly using build options if you wanted π¦-oβ the target directory for HTML report files. subdirectories get created as needed to represent separate invocations of the analyzer. if you don't specify this option, a directory gets created in/tmp(TMPDIRon Mac OS X) to store the reports πΈ-plistβ output the results as a set of.plistfiles. (by default, the output ofscan-buildis a set of HTML files, so this is you switching up the fit π )-plist-htmlβ output the results as a set of HTML and.plistfiles. why choose one π--status-bugsβ set exit status to1if it found potential bugs, and0otherwise. by default the exit status ofscan-buildis whateverbuild_commandreturned. so this one is her taking the wheel π₯--use-c++[=*compiler_path*]β guess the default compiler for your C++ and Objective-C++ code. use this option to specify an alternate compiler, iykyk π--use-cc[=*compiler_path*]β guess the default compiler for your C and Objective-C code. use this option to specify an alternate compiler, same energy π-vβ verbose output fromscan-buildand the analyzer. a second and thirdvincreases verbosity. stack 'em, girl π-V,--viewβ view analysis results in a web browser when the build completes. main character reveal π-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. vintage, but like, in a limited way π-maxloop *N*β 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. more thorough, less fast, the eternal tradeoff β¨-no-failure-reportsβ do not create a βfailuresβ subdirectory that includes analyzer crash reports and preprocessed source files. sometimes you just don't want the receipts π-statsβ generates visitation statistics for the project being analyzed. numbers, but make it gossip π-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. so basically βregionβ is the glow-up πΈ
π EXIT STATUS π
scan-build returns the value returned by build_command β unless --status-bugs or --keep-going is used, in which case she's got opinions of her own. periodt.
π CHECKERS π
okay so the checkers listed below may be enabled/disabled using the -enable-checker and -disable-checker options. a default group of checkers gets run unless you explicitly disable them. exactly which checkers make up that default group is a function of the operating system in use, and you can see them listed with --help-checkers. go off, OS-dependent queen π¦
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). the audacity πcore.AttributeNonNullβ check for null pointers passed as arguments to a function whose arguments are marked with the βnonnullβ attribute. she said no nulls, and she meant it πcore.CallAndMessageβ check for logical errors for function calls and Objective-C message expressions (e.g., uninitialized arguments, null function pointers). mess detected πcore.DivideZeroβ check for division by zero. math said absolutely not πcore.NullDereferenceβ check for dereferences of null pointers. the classic. the legend. the thing that ends careers πcore.StackAddressEscapeβ check that addresses to stack memory do not escape the function. stay in your lane, address πcore.UndefinedBinaryOperatorResultβ check for undefined results of binary operators. undefined behavior is not a personality β¨core.VLASizeβ check for declarations of VLA of undefined or zero size. girl, what size πcore.builtin.BuiltinFunctionsβ evaluate compiler builtin functions, e.g.alloca(). builtin behavior, evaluated πΈcore.builtin.NoReturnFunctionsβ evaluate βpanicβ functions that are known to not return to the caller. they're not coming back, bestie πcore.uninitialized.ArraySubscriptβ check for uninitialized values used as array subscripts. indexing with vibes only, and that's the problem π₯core.uninitialized.Assignβ check for assigning uninitialized values. she clocked it πcore.uninitialized.Branchβ check for uninitialized values used as branch conditions. your if-statement is running on nothing πcore.uninitialized.CapturedBlockVariableβ check for blocks that capture uninitialized values. the block said πcore.uninitialized.UndefReturnβ check for uninitialized values being returned to the caller. returning mystery, iconic but bad πdeadcode.DeadStoresβ check for values stored to variables that are never read afterwards. written and never readβ¦ not even the group chat πdebug.DumpCFGβ display Control-Flow Graphs. the graph, dumped π¦debug.DumpCallGraphβ display Call Graph. same energy, call edition πdebug.DumpDominatorsβ print the dominance tree for a given Control-Flow Graph. she's printing the dominance tree, and honestly? dominating πdebug.DumpLiveVarsβ print results of live variable analysis. live vars, live results β¨debug.Statsβ emit warnings with analyzer statistics. stats but with a warning attached πdebug.TaintTestβ mark tainted symbols as such. label it, bestie π·οΈdebug.ViewCFGβ view Control-Flow Graphs using GraphViz. now you can actually look at it πdebug.ViewCallGraphβ view Call Graph using GraphViz. same, but calls πllvm.Conventionsβ check code for LLVM codebase conventions. dress code enforcement, but for code πΈosx.APIβ check for proper uses of various Mac OS X APIs. Apple said use me correctly πosx.AtomicCASβ evaluate calls toOSAtomicfunctions. atomic, evaluated βοΈosx.SecKeychainAPIβ check for proper uses of Secure Keychain APIs. keychain etiquette, no cap πosx.cocoa.AtSyncβ check for null pointers used as mutexes for@synchronized. synchronizing on nothing? ma'am πosx.cocoa.ClassReleaseβ check for sending βretainβ, βrelease,β or βautoreleaseβ directly to a Class. class, not instance, bestie πosx.cocoa.IncompatibleMethodTypesβ warn about Objective-C method signatures with type incompatibilities. the types do not match and it shows πosx.cocoa.NSAutoreleasePoolβ warn for suboptimal uses ofNSAutoreleasePoolin Objective-C GC mode. suboptimal. she said it, not me πosx.cocoa.NSErrorβ check usage ofNSError**parameters. two stars, one responsibility β¨osx.cocoa.NilArgβ check for prohibitednilarguments to Objective-C method calls.nilis not welcome here πosx.cocoa.RetainCountβ check for leaks and improper reference count management. the reference counts are NOT counting correctly πosx.cocoa.SelfInitβ check that βselfβ is properly initialized inside an initializer method. self-care, literally π«Άosx.cocoa.UnusedIvarsβ warn about private ivars that are never used. a private ivar nobody readsβ¦ relatable πosx.cocoa.VariadicMethodTypesβ check for passing non-Objective-C types to variadic methods that expect only Objective-C types. variadic said ObjC only πosx.coreFoundation.CFErrorβ check usage ofCFErrorRef*parameters. errors, but handled with respect πΈosx.coreFoundation.CFNumberβ check for proper uses ofCFNumberCreate(). create her correctly or not at all πosx.coreFoundation.CFRetainReleaseβ check for null arguments toCFRetain(),CFRelease(), andCFMakeCollectable(). null in, chaos out π₯osx.coreFoundation.containers.OutOfBoundsβ checks for index out-of-bounds when using theCFArrayAPI. out of bounds means out of the group chat πosx.coreFoundation.containers.PointerSizedValuesβ warns ifCFArray,CFDictionary, orCFSetare created with non-pointer-size values. pointer-sized or nothing πsecurity.FloatLoopCounterβ warn on using a floating point value as a loop counter (CERT:FLP30-C,FLP30-CPP). floats and loop counters? no ma'am, CERT said so too πsecurity.insecureAPI.UncheckedReturnβ warn on uses of functions whose return values must be always checked. always checked. ALWAYS π¨security.insecureAPI.getpwβ warn on uses ofgetpw(). insecure, flagged β¨security.insecureAPI.getsβ warn on uses ofgets(). girl.gets(). you know better πsecurity.insecureAPI.mkstempβ warn whenmkstemp()is passed fewer than 6X's in the format string. count your X's, bestie, all six of them πsecurity.insecureAPI.mktempβ warn on uses ofmktemp(). insecure, flagged πsecurity.insecureAPI.randβ warn on uses ofrand(),random(), and related functions. randomness said not like this πΈsecurity.insecureAPI.strcpyβ warn on uses ofstrcpy()andstrcat(). the classics that ruin everything πsecurity.insecureAPI.vforkβ warn on uses ofvfork(). flagged, warned, noted π¦unix.APIβ check calls to various UNIX/Posix functions. unix said use me properly πunix.Mallocβ check for memory leaks, double free, and use-after-free. the holy trinity of pain πunix.cstring.BadSizeArgβ check the size argument passed into C string functions for common erroneous patterns. size matters, and she's checking π₯unix.cstring.NullArgβ check for null pointers being passed as arguments to C string functions. null args, denied β¨
π EXAMPLE π
scan-build -o /tmp/myhtmldir make -j4
so what's happening here: the above example causes analysis reports to be deposited into a subdirectory of /tmp/myhtmldir, and runs make with the -j4 option. a different subdirectory is created each time scan-build analyzes a project. and the analyzer should support most parallel builds β but not distributed builds. parallel yes, distributed no, know the difference bestie π
π«Ά AUTHORS π«Ά
scan-build was written by Ted Kremenek. documentation contributed by James K. Lowden <jklowden@schemamania.org>. legends, both of them, we thank them for their service π
and that's the whole page, bestie β every flag, every checker, every vibe, preserved exactly. go forth and analyze β¨
this was clang 18, dated Sep 21, 2023 β SCAN-BUILD(1), signing off π
π¦ where this page comes from
- debian trixie: clang-tools-18 1:18.1.8-18+b1 Β· APACHE-2-LLVM-EXCEPTIONS
- ubuntu noble: clang-tools-18 1:18.1.3-1 Β· APACHE-2-LLVM-EXCEPTIONS
- ubuntu noble: clang-tools-18 1:18.1.3-1ubuntu1 Β· APACHE-2-LLVM-EXCEPTIONS
- ubuntu questing: clang-tools-18 1:18.1.8-18ubuntu2
- ubuntu resolute: clang-tools-18 1:18.1.8-20ubuntu8 Β· APACHE-2-LLVM-EXCEPTIONS
- ubuntu stonking: clang-tools-18 1:18.1.8-20ubuntu11 Β· 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