Building and Running LLVM-Clang Static Analyzer
Building LLVM From source
I am documenting how I am building LLVM Clang in my Mac Air 2015.
- macOS Mojave 10.14.6
- 1.6 GHz Intel Core i5
- 8 GB Memory
Get the source code
git clone https://github.com/llvm/llvm-project.git
Build the code (I am using ninja to build)
1 | mkdir $ROOT/llvm-project/build |
Apparently we need to build libc++: by running ninja cxx
other wise we get some header errors.
Running LLVM-Clang Static Analyzer
To run a static analyzer on test.cpp
file, we can use scan-build
utility with below command.
1 | $ROOT/llvm-project/clang/tools/scan-build/bin/scan-build -k -V \ |
Options
-V
option it will open the report in the browser-k
keep on going optionc
Only run preprocess, compile, and assemble steps
Or we can use it via clang
to run a specific check. Here for example NullDereference
1 | $ROOT/llvm-project/build/bin/clang++ -cc1 -analyze -analyzer-checker=core.NullDereference test.cpp |
Summary
Full build took around 2.5 hours in my machine.
Building after a small change took around 1 minute.