CLANG-CHECK(1)

πŸ“¦ version 11.1.0, in ubuntu jammy

πŸ’– 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-hidden shows you more πŸ‘€
  • --help-list β€” prints the list of available options. and yeah, --help-list-hidden exists 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-dump or -ast-print and 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-list to 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