CLANG-CHECK(1)

πŸ“¦
version 14.0.6 Β· 5 versions
, in ubuntu questing

πŸ’– 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-hidden for more, if you're feeling nosy πŸ‘€)
  • --help-list β€” shows you a list of the available options. (Again, --help-list-hidden for 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-dump or -ast-print to 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