CLANG-CHECK(1)
π NAME π
clang-check β manual page for clang-check 11. That's it, that's the name section, no notes bestie, we're going straight to the good stuff π
β¨ DESCRIPTION β¨
okay so literally the first thing you need in your life is the usage line, and here it is, verbatim, iconic:
USAGE: clang-check [options] <source0> [... <sourceN>]
and then, the options. the options are the whole personality of this page. let's get into it π«Ά
π OPTIONS π
π Generic Options π
--helpβ shows you all the available options. and if you're extra,--help-hiddenshows you more π--help-listβ prints the list of available options. and yeah,--help-list-hiddenexists for the more version of that too π--versionβ tells you the version of this program. short, sweet, slay.
π clang-check options π
--analyzeβ runs the static analysis engine β¨--ast-dumpβ builds ASTs and then debug dumps them. that's the whole thing. no cap.--ast-dump-filter=<string>β pair this with-ast-dumpor-ast-printand it will only dump/print the AST declaration nodes whose qualified name contains a certain substring. and if you wanna know which declaration node names are even filterable? use-ast-listto list them all π§--ast-listβ builds ASTs and prints out the list of declaration node qualified names--ast-printβ builds ASTs and then pretty-prints them. pretty print for a pretty user, periodt π--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, before means before, iykyk--fix-what-you-canβ applies fix-it advice even when there are unfixable errors in the mix. it's giving "doing its best under pressure" π--fixitβ applies fix-it advice to the input source-p=<string>β build path
so like, <hotpink>-p <build-path></hotpink> is what you use to read a compile command database. let me explain π
for example, it can totally be a CMake build directory that has a file named compile_commands.json in it (use the -DCMAKE_EXPORT_COMPILE_COMMANDS=ON CMake option to get that output, bestie). and when you don't specify a build path at all? it'll attempt a search for compile_commands.json through all the parent paths of the first input file. if you want an example of setting up Clang Tooling on a source tree, look at:
https://clang.llvm.org/docs/HowToSetupToolingForLLVM.html
πΈ real talk: that URL is straight from the page, don't come for me.
now, the sources:
<source0>... β you use these to specify the paths of source files. these paths get looked up in the compile command database. and here's where it gets β¨specificβ¨:- 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 get automatically removed, but the rest of a relative path must be a suffix of a path in the compile command database. no skipping that part π
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, if you're feeling fancy and using a specific build path:
find path/in/subtree -name '*.cpp'|xargs clang-check -p build/path
π note, that path/in/subtree and the current directory should follow the rules described above. yes, those exact rules. go reread them. i'll wait. π«Ά
and that's the whole page, bestie! π this was clang-check 11, dated January 2022, living its best life in the CLANG-CHECK(1) era. go build some ASTs, you absolute icon ππ
π¦ where this page comes from
- ubuntu jammy: clang-tools-11 1:11.1.0-6 Β· APACHE-2-LLVM-EXCEPTIONS
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms