3.1. Debug Checks — Clang 22.0.0git documentation (original) (raw)

The analyzer contains a number of checkers which can aid in debugging. Enable them by using the “-analyzer-checker=” flag, followed by the name of the checker.

These checkers are especially useful when analyzing a specific function, using the -analyze-function flag. The flag accepts the function name for C code, like -analyze-function=myfunction. For C++ code, due to overloading, the function name must include the parameter list, like -analyze-function=”myfunction(int, _Bool)”.

Note that bool must be spelled as _Bool in the parameter list. Refer to the output of -analyzer-display-progress to find the fully qualified function name.

There are cases when this name can still collide. For example with template function instances with non-deducible (aka. explicit) template parameters. In such cases, prefer passing a USR instead of a function name can resolve this ambiguity, like this: -analyze-function=”c:@S@Window@F@overloaded#I#”.

Use the clang-extdef-mapping tool to find the USR for different functions.

3.1.1. General Analysis Dumpers

These checkers are used to dump the results of various infrastructural analyses to stderr. Some checkers also have “view” variants, which will display a graph using a ‘dot’ format viewer (such as Graphviz on macOS) instead.

3.1.2. Path Tracking

These checkers print information about the path taken by the analyzer engine.

3.1.3. State Checking

These checkers will print out information about the analyzer state in the form of analysis warnings. They are intended for use with the -verify functionality in regression tests.

(FIXME: debug.ExprInspection should probably be renamed, since it no longer only inspects expressions.)

3.1.3.1. ExprInspection checks

3.1.4. Statistics

The debug.Stats checker collects various information about the analysis of each function, such as how many blocks were reached and if the analyzer timed out.

There is also an additional -analyzer-stats flag, which enables various statistics within the analyzer engine. Note the Stats checker (which produces at least one bug report per function) may actually change the values reported by -analyzer-stats.

3.1.5. Output testing checkers