ShiftingChecker is a Clang Static Analyzer checker which checks for improper shifting: shifting by a negative value or by a value too large.
- Build LLVM following the instructions from the Github page. (NOTE: Over 8GiB of RAM highly recommended).
- Copy
ShiftingChecker.cppto thellvm-project/clang/lib/StaticAnalyzer/Checkersfolder. - Edit the
CMakeLists.txtfile in the aforementionedCheckersfolder so thatcmakecould recognize addedShiftingChecker.cppfile. - Add following block of code into
Checkers.tdfile contained inllvm-project/clang/include/clang/StaticAnalyzer/Checkers:
let ParentPackage = UnixAlpha in {
...
def ShiftingChecker : Checker<"ShiftingChecker">,
HelpText<"Check for shifting by negative value or value too large">,
Documentation<NotDocumented>;
...
} // end "alpha.unix"
- In the
builddirectory, runmake clang. This will only rebuild Clang (you can use this command for making any subsequent changes to the checker, as well).
For applications written in C, run:
clang --analyze -Xanalyzer -analyzer-checker=unix,alpha example.c
For applications written in C++, run:
clang++ --analyze -Xanalyzer -analyzer-checker=unix,alpha example.cpp
Both clang and clang++ can be found in llvm-project/build/bin.