CLANG-CHECK(1)

πŸ“¦
version 17.0.6 Β· 4 versions
, in debian trixie, ubuntu questing

πŸ’… clang-check β€” the manual page for clang-check 17 ✨

okay bestie, welcome to the group chat, pull up a chair 🫢 this is the manual page for clang-check 17, and I'm gonna walk you through it like we're texting at 2am. no cap, every single flag is staying right here. let's get into it πŸ’–


🌸 NAME 🌸

clang-check β€” literally the manual page for clang-check 17, that's it, that's the name, periodt πŸ’…


πŸ¦‹ DESCRIPTION πŸ¦‹

here's how you run it, okay? the usage vibe is:

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

and then we have OPTIONS, which is giving very much main character energy, so let's go πŸ‘‘


✨ Generic Options ✨

the basics, the essentials, the ones everyone needs 🌈

  • --help β€” shows you all the available options (and if you want even more, there's --help-hidden πŸ‘€)
  • --help-list β€” prints out a list of the available options (and yeah, --help-list-hidden exists too if you wanna go feral)
  • --version β€” tells you which version of this program you're running, iconic

πŸ’œ clang-check options πŸ’œ

this is the good stuff, the real ones, the flags that do the thing πŸ”₯

  • --analyze β€” runs the static analysis engine, like it's putting your code under a microscope πŸ”¬
  • --analyzer-output-path=<string> β€” writes the output to <file>, so you can yeet it somewhere specific
  • --ast-dump β€” builds up those ASTs and then debug-dumps them, very raw, very real
  • --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. and if you wanna see all the filterable declaration node names, use -ast-list for that πŸŽ€
  • --ast-list β€” builds ASTs and prints out the list of declaration node qualified names
  • --ast-print β€” builds ASTs and then pretty-prints them, so they're all dressed up and cute πŸ’…
  • --extra-arg=<string> β€” an extra argument that gets appended to the compiler command line
  • --extra-arg-before=<string> β€” an extra argument that gets prepended to the compiler command line (yes, before, it goes first, it's the main character of arguments)
  • --fix-what-you-can β€” applies fix-it advice even when there are unfixable errors hanging around. like, it's doing its best okay 😭
  • --fixit β€” applies fix-it advice to the input source
  • -p <string> β€” build path, that's the vibe
  • --syntax-tree-dump β€” dumps the syntax tree
  • --tokens-dump β€” dumps the preprocessed tokens

🧚 the build path situation 🧚

so -p <build-path> is what you use to read a compile command database, got it? 🌟

for example, it can be a CMake build directory where a file named compile_commands.json lives (use the -DCMAKE_EXPORT_COMPILE_COMMANDS=ON CMake option to get that output, bestie, that's the whole trick). and when no build path is specified, it'll try to search for compile_commands.json through all the parent paths of the first input file. lowkey convenient, highkey useful.

and if you want an example of setting up Clang Tooling on a source tree, it's right here: https://clang.llvm.org/docs/HowToSetupToolingForLLVM.html β€” go look, iykyk 🫢


🌈 source files, the rules, no cap 🌈

<source0> ... is where you specify the paths of your source files. these paths get looked up in the compile command database. and here's the deal, okay, listen up:

  • 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.
fr fr, those rules are strict. the path has to line up exactly, no wiggle room πŸ’€

⭐ examples, because we love a demo ⭐

wanna run clang-check on all the files in a subtree of the source tree? say less:

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

or, if you're using a specific build path, do it like this:

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

and note β€” path/in/subtree and the current directory should follow the rules described above πŸ‘† don't skip the rules, they will humble you πŸ™ˆ


heads up bestie: those find-and-xargs examples are exactly as written. copy them character for character and you're golden ✨

πŸŽ€ a cute little sign-off πŸŽ€

and that's the whole page, you ate that πŸ’– this manual is for clang-check 17, dated June 2025, and that's a wrap. go forth, check your clang, be the main character of your own source tree πŸ‘‘πŸ¦‹πŸ’…

πŸ“¦ where this page comes from