CLANG-CHECK(1)

πŸ“¦
version 15.0.7 Β· 3 versions
, in ubuntu jammy

πŸ’… CLANG-CHECK(1) πŸ’…

ok so bestie, this is the manual page for clang-check β€” it lives in the User Commands section of the manual, and it's giving "compiler tooling but make it ✨fancy✨". buckle up, we're going in πŸŽ€


🌸 NAME 🌸

clang-check β€” manual page for clang-check 15 πŸ¦‹


✨ DESCRIPTION ✨

ok so here's the whole vibe, the entire usage of this thing, no cap:

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

and now… OPTIONS πŸ‘‘ (yes we're doing options, yes there are a lot, yes we're doing all of them)

πŸ’– Generic Options πŸ’–

these are the basics, the everyday essentials, the main character options fr:

  • --help β€” shows you the available options. and if you want even more, there's --help-hidden for that πŸ’€
  • --help-list β€” shows you the list of available options. and yep, there's --help-list-hidden for even more of them too 🫢
  • --version β€” tells you the version of this program, iconic behaviour honestly ⭐

πŸ¦‹ clang-check options πŸ¦‹

the real ones, the ones you actually came here for:

  • --analyze β€” run the static analysis engine πŸ”
  • --analyzer-output-path=<string> β€” write output to <file> πŸ“
  • --ast-dump β€” build ASTs and then debug dump them 🌳
  • --ast-dump-filter=<string> β€” use with -ast-dump or -ast-print to dump/print only AST declaration nodes having a certain substring in a qualified name. use -ast-list to list all filterable declaration node names πŸ‘€
  • --ast-list β€” build ASTs and print the list of declaration node qualified names πŸ“‹
  • --ast-print β€” build ASTs and then pretty-print them πŸ’… (pretty-print!! she's literally named after us)
  • --extra-arg=<string> β€” additional argument to append to the compiler command line βž•
  • --extra-arg-before=<string> β€” additional argument to prepend to the compiler command line πŸ”Ό
  • --fix-what-you-can β€” apply fix-it advice even in the presence of unfixable errors. like, do what you can bestie, it's fine 😭
  • --fixit β€” apply fix-it advice to the input source πŸ”§
  • -p <string> β€” build path πŸ—‚οΈ
  • --syntax-tree-dump β€” dump the syntax tree 🌲
  • --tokens-dump β€” dump the preprocessed tokens 🎟️

🧚 the -p lore (build path) 🧚

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

for example, it can be a CMake build directory in which a file named compile_commands.json exists (use the -DCMAKE_EXPORT_COMPILE_COMMANDS=ON CMake option to get this output, iykyk). when no build path is specified, a search for compile_commands.json will be attempted through all parent paths of the first input file.

see: https://clang.llvm.org/docs/HowToSetupToolingForLLVM.html for an example of setting up Clang Tooling on a source tree 🌈


🌸 the <source0> ... source files situation 🌸

<source0> ... specify the paths of source files. these paths are looked up in the compile command database. no cap, here are the rules:

  • 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.

πŸ’œ examples, because we love a demonstration πŸ’œ

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 πŸ‘† (yes, the rules we just went over, don't skip them bestie)

and that's the whole page!! πŸŽ€ this was clang-check 15, dated July 2023 πŸ’– thanks for reading, you ate that fr fr πŸ«Άβœ¨πŸ’…

πŸ“¦ where this page comes from