CLANG-CHECK(1)

πŸ“¦ version 12.0.1, in ubuntu jammy

πŸŽ€ CLANG-CHECK πŸŽ€

okay so bestie, this is the manual page for clang-check, and she lives in section 1 of the manual β€” user commands, main character energy only. πŸ’… pull up a chair, grab a boba, we're going through every single flag together, and yes we're going through all of them, no skipping. 🫢


πŸ’– NAME πŸ’–

clang-check β€” the manual page for clang-check 12 ✨


πŸ¦‹ DESCRIPTION πŸ¦‹

here's the whole vibe in one line, literally the entire synopsis, iconic:

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

then it's just… options. a whole buffet of them. let's go πŸ“


🌈 OPTIONS 🌈

🌸 Generic Options 🌸

the everyday, everybody-gets-them options, no gatekeeping:

  • --help β€” displays the available options. and if you want even more, there's --help-hidden πŸ™ˆ
  • --help-list β€” displays the list of available options. and yeah, --help-list-hidden exists for more πŸ‘€
  • --version β€” displays the version of this program. flex it. πŸ‘‘

πŸ’… clang-check options πŸ’…

okay this is the good part, the actual clang-check-specific stuff, she ate:

  • --analyze β€” runs the static analysis engine πŸ”₯
  • --ast-dump β€” builds 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. 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 the list of declaration node qualified names
  • --ast-print β€” builds ASTs and then pretty-prints them (pretty!! as promised πŸ’–)
  • --extra-arg=<string> β€” an additional argument to append to the compiler command line
  • --extra-arg-before=<string> β€” an additional argument to prepend to the compiler command line (yes, before. order matters bestie 😭)
  • --fix-what-you-can β€” applies fix-it advice even in the presence of unfixable errors. she does what she can, okay?? πŸ’ͺ
  • --fixit β€” applies fix-it advice to the input source
  • -p=<string> β€” build path πŸ“

okay so about that last one, because -p is a whole situation:

-p <build-path> is used to read a compile command database.

for example, it can be a CMake build directory in which a file named compile_commands.json exists β€” and to get that output you use the -DCMAKE_EXPORT_COMPILE_COMMANDS=ON CMake option. when no build path is specified, a search for compile_commands.json will be attempted through all parent paths of the first input file. and if you want a full example of setting up Clang Tooling on a source tree, it's right here: https://clang.llvm.org/docs/HowToSetupToolingForLLVM.html ✨


πŸ¦‹ about <source0> ... πŸ¦‹

<source0> ... specify the paths of source files. these paths are looked up in the compile command database. now here's the rules, and she is strict:

  • 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. no cap, that's the rule. 🎯

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
note, that path/in/subtree and current directory should follow the rules described above. πŸ‘‘ don't skip this part, it WILL humble you.

and that's the whole page, bestie 🌈 we did it, we read every single line, nobody skipped the boring bits, we're so valid.

clang-check 12 β€” February 2022 β€” CLANG-CHECK(1) 🫢 bye ily, go compile something beautiful πŸ’–βœ¨

πŸ“¦ where this page comes from