CLANG-CHECK(1)
πΈ clang-check β NAME π
okay so bestie, clang-check is literally the manual page for clang-check 18. that's it, that's the name, and we're already slaying β¨
π¦ DESCRIPTION
the whole vibe, in one line:
USAGE: clang-check [options] <source0> [... <sourceN>]
and now, the options. buckle up, there's a lot, but we're getting through this together π«Ά
β¨ Generic Options β¨
--helpβ shows you all the available options (and if you want even more chaos, there's--help-hiddenfor that)--help-listβ prints out a list of the available options (again,--help-list-hiddenexists if you're feeling extra)--versionβ tells you what version of this program you're on
π clang-check options π
--analyzeβ runs the static analysis engine. it's giving detective energy π--analyzer-output-path=<string>β writes the output to<file>--ast-dumpβ builds 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. and if you need the list of all the filterable declaration node names, use-ast-list. iykyk π--ast-listβ builds ASTs and prints the list of declaration node qualified names--ast-printβ builds ASTs and then pretty-prints them. pretty-print, pretty slay β¨--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 (yes bestie, order matters, we love that for us)--fix-what-you-canβ applies fix-it advice even when there are unfixable errors hanging around. iconic resilience honestly--fixitβ applies fix-it advice to the input source-p <string>β build path--syntax-tree-dumpβ dumps the syntax tree--tokens-dumpβ dumps the preprocessed tokens
π§ the -p build path situation π§
-p <build-path> is what you use to read a compile command database. fr fr, that's its whole job.
for example, it can be a CMake build directory that has a file named compile_commands.json sitting in it (use the -DCMAKE_EXPORT_COMPILE_COMMANDS=ON CMake option to get that output). when you don't specify a build path, it'll try to search for compile_commands.json through all the parent paths of the first input file. π«
want an example of setting up Clang Tooling on a source tree? here you go:
https://clang.llvm.org/docs/HowToSetupToolingForLLVM.html
π the source files π
<source0> ... is where you specify the paths of your source files. these paths get looked up in the compile command database.
- 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.
also, ./ prefixes in relative files get automatically removed β but the rest of a relative path has to be a suffix of a path in the compile command database. no cap, that's the rule π
π examples, because we love a demonstration π
say you wanna run clang-check on every file in a subtree of the source tree. do this:
find path/in/subtree -name '*.cpp'|xargs clang-check
or, if you wanna use a specific build path:
find path/in/subtree -name '*.cpp'|xargs clang-check -p build/path
heads up bestie β path/in/subtree and your current directory both need to follow the rules we just talked about up there. don't skip that part π
and that's the whole page!! go forth and check some clang, you absolute main character π
this has been clang-check 18, from June 2025, signing off π β¨ π¦
π¦ where this page comes from
- debian trixie: clang-tools-18 1:18.1.8-18+b1 Β· APACHE-2-LLVM-EXCEPTIONS
- ubuntu questing: clang-tools-18 1:18.1.8-18ubuntu2
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms