CLANG-CHECK(1)

πŸ“¦
version 19.1.7 Β· 5 versions
, in debian bookworm, debian trixie

πŸ’– NAME πŸ’–

okay bestie, say hi to clang-check β€” it's the manual page for clang-check 19, and we're gonna read it together, no cap. πŸ¦‹


✨ DESCRIPTION ✨

so here's the vibe, the whole entire usage in one little line:

USAGE: clang-check [options] <source0> [... <sourceN>]

and then it's OPTIONS o'clock. πŸ‘‘

🌸 Generic Options 🌸

the "everyone gets these" squad, the basics, the little black dress of flags:

  • --help β€” shows you all the available options. and if that's not enough for you (iconic behaviour tbh), there's --help-hidden for the extra secret ones. πŸ’…
  • --help-list β€” prints out a whole list of the available options. and yes, there's a --help-list-hidden version too for the ones that don't want to be seen. πŸ™ˆ
  • --version β€” tells you which version of this program you're running. identity check, love that for you. ✨

πŸŽ€ clang-check options πŸŽ€

the main character flags, the ones with main character energy:

  • --analyze β€” runs the static analysis engine. it's giving detective. πŸ”
  • --analyzer-output-path=<string> β€” writes the output to <file>. put it where you want it bestie. πŸ’–
  • --ast-dump β€” builds ASTs and then debug-dumps them. raw, unfiltered, no editing. πŸ’€
  • --ast-dump-filter=<string> β€” use this alongside -ast-dump or -ast-print to dump/print only the AST declaration nodes that have a certain substring in a qualified name. and if you wanna know what you can even filter by, hit -ast-list to list all the filterable declaration node names. so helpful, so organized. 🧚
  • --ast-list β€” builds ASTs and prints out the list of declaration node qualified names. a whole roster. πŸ“‹
  • --ast-print β€” builds ASTs and then pretty-prints them. glow-up, but for code. ✨
  • --extra-arg=<string> β€” an extra argument to append to the compiler command line. add it at the end, like a little garnish. πŸ“
  • --extra-arg-before=<string> β€” an extra argument to prepend to the compiler command line. this one goes first, front of the line, VIP. πŸ‘‘
  • --fix-what-you-can β€” applies fix-it advice even when there are unfixable errors in the mix. do what you can, we respect the effort. 🫢
  • --fixit β€” applies fix-it advice to the input source. it's literally fixing it for you. slay. πŸ’…
  • -p <string> β€” build path. (more on this below, don't scroll away bestie ⬇️)
  • --syntax-tree-dump β€” dumps the syntax tree. 🌳
  • --tokens-dump β€” dumps the preprocessed tokens. 🎟️

πŸ¦‹ all about that build path, -p <build-path> πŸ¦‹

okay so -p <build-path> is what you use to read a compile command database. no cap, that's the whole job.

for example, it can be a CMake build directory where a file named compile_commands.json lives. and if you need that file to exist, you get it by using the -DCMAKE_EXPORT_COMPILE_COMMANDS=ON CMake option. that's the output you want. πŸ’–

and here's the cute part: when you don't specify a build path, it'll go hunting for compile_commands.json through all the parent paths of the first input file. a little scavenger hunt. πŸ”

wanna see an example of setting up Clang Tooling on a source tree? it's right here:

https://clang.llvm.org/docs/HowToSetupToolingForLLVM.html


🌈 the source files, <source0> ... 🌈

<source0> ... specifies the paths of source files. and these paths get looked up in the compile command database. here are the rules, and yes you have to follow them:

  • 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 shortcuts, bestie. πŸ’€

so, for example, to run clang-check on all files in a subtree of the source tree, you'd do:

find path/in/subtree -name '*.cpp'|xargs clang-check

or, if you want to use 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. don't skip this part, it matters fr fr. 😭

okay that's the whole page! clang-check 19, brought to you June 2025. thanks for reading, you ate that. go run some checks, periodt. πŸ’…βœ¨πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from