CLANG-CHECK(1)
π NAME π
clang-check β it's the manual page for clang-check 14, bestie, and it's literally a whole vibe π
π DESCRIPTION π
Okay so, first thing, here's how you actually call this thing:
USAGE: clang-check [options] <source0> [... <sourceN>]
And then it's giving... OPTIONS:. Obsessed already.
β¨ Generic Options β¨
The little universal ones, the main characters of every LLVM tool fr fr π«Ά
--helpβ shows you the available options. (Pass--help-hiddenfor more, if you're feeling nosy π)--help-listβ shows you a list of the available options. (Again,--help-list-hiddenfor more π)--versionβ prints the version of this program. Iconic. Short. Perfect.
πΈ clang-check options πΈ
The actual good stuff, no cap π§
--analyzeβ runs the static analysis engine π₯--analyzer-output-path=<string>β writes the output to<file>--ast-dumpβ builds the ASTs and then debug-dumps them--ast-dump-filter=<string>β use this with-ast-dumpor-ast-printto dump/print only the AST declaration nodes that have a certain substring in a qualified name. Wanna see every filterable declaration node name? Use-ast-list, it lists all of them for you π--ast-listβ builds the ASTs and prints out the list of declaration node qualified names--ast-printβ builds the ASTs and then pretty-prints them β¨ (pretty, just like this page)--extra-arg=<string>β an extra argument to append to the compiler command line--extra-arg-before=<string>β an extra argument to prepend to the compiler command line--fix-what-you-canβ applies the fix-it advice even when there are unfixable errors hanging around. brave of you honestly π«‘--fixitβ applies fix-it advice to the input source-p=<string>β the build path--syntax-tree-dumpβ dumps the syntax tree--tokens-dumpβ dumps the preprocessed tokens
π¦ So what's -p <build-path> actually for? π¦
It's used to read a compile command database. That's the whole job. π
For example β and I'm quoting the page here β it can be a CMake build directory in which a file named compile_commands.json exists. To get that output, use the -DCMAKE_EXPORT_COMPILE_COMMANDS=ON CMake option. Cute right?
And when no build path is specified? Then it'll attempt a search for compile_commands.json through all parent paths of the first input file. The way it just goes looking π
See https://clang.llvm.org/docs/HowToSetupToolingForLLVM.html for an example of setting up Clang Tooling on a source tree. iykyk π
π <source0> ... β the source files π
These specify the paths of source files. Those paths get looked up in the compile command database. Here's the tea, and it matters:
- If the path of a file is absolute, it needs to point into CMake's source tree.
- If the path is relative, the current working directory needs to be in the CMake source tree and the file must be in a subdirectory of the current working directory.
"./"prefixes in the relative files will be automatically removed, but the rest of a relative path must be a suffix of a path in the compile command database.
Bestie, read that again before you come for me. The rules are the rules. π
For example, to run clang-check on all files in a subtree of the source tree, use:
find path/in/subtree -name '*.cpp'|xargs clang-check
or, using a specific build path:
find path/in/subtree -name '*.cpp'|xargs clang-check -p build/path
And note, that path/in/subtree and the current directory should follow the rules described above. π
β Little PSA: this page was written for clang-check 14, dated May 2025. That's the version, that's the date, we don't make the rules. Mwah, go run it on something, you've got this ππ¦β¨
π¦ where this page comes from
- ubuntu questing: clang-tools-14 1:14.0.6-20ubuntu3
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms