Skip to content

Commit 35c99da

Browse files
committed
[docs] Add a small section about running the static analyzer via clang-tidy using compile_commands.json
I have been doing this every once in a while to look for problems. No point in siloing this knowledge in my brain.
1 parent b68ae2e commit 35c99da

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

docs/DebuggingTheCompiler.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -437,6 +437,25 @@ reducing SIL test cases by:
437437
For more information and a high level example, see:
438438
./swift/utils/bug_reducer/README.md.
439439

440+
Using ``clang-tidy`` to run the Static Analyzer
441+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
442+
443+
Recent versions of LLVM package the tool ``clang-tidy``. This can be used in
444+
combination with a json compilation database to run static analyzer checks as
445+
well as cleanups/modernizations on a code-base. Swift's cmake invocation by
446+
default creates one of these json databases at the root path of the swift host
447+
build, for example on macOS::
448+
449+
$PATH_TO_BUILD/swift-macosx-x86_64/compile_commands.json
450+
451+
Using this file, one invokes ``clang-tidy`` on a specific file in the codebase
452+
as follows::
453+
454+
clang-tidy -p=$PATH_TO_BUILD/swift-macosx-x86_64/compile_commands.json $FULL_PATH_TO_FILE
455+
456+
One can also use shell regex to visit multiple files in the same directory. Example::
457+
458+
clang-tidy -p=$PATH_TO_BUILD/swift-macosx-x86_64/compile_commands.json $FULL_PATH_TO_DIR/*.cpp
440459

441460
Debugging Swift Executables
442461
===========================

0 commit comments

Comments
 (0)