Skip to content

EgorkaZ/itiviti-cpp-analyzer

 
 

Repository files navigation

itiviti-cpp-analyzer

itiviti-cpp-analyzer (or ICA) is a Clang plugin, which brings several static analysis checks (listed here).

If you want to contribute to the project, see CONTRIBUTING.md.

Building

Prerequisites

You need Clang and CMake to build the plugin. Also you need libclang-10-dev and libclang-cpp10-dev packages. Optionally, you may need Boost 1.68+ headers (it can be downloaded during the build instead).

Currently, ICA only works with clang-10

Build guide

[ ! -d build ] && mkdir build
cd build

cmake \
    -DGCC_TOOLCHAIN=<path/to/gcc/toolchain (probably, /usr/lib)> \
    -DBOOST_FROM_INTERNET=ON \
    -DTARGET_COMPILER=clang++-10 \
    ../

cmake --build . --parallel
  • BOOST_FROM_INTERNET is only needed if you haven't Boost headers
  • BOOST_ROOT can be specified instead
  • TARGET_COMPILER is the compiler used for tests. Specify if you don't use clang-10 for compilation

The built plugin will be in ./build/libica-plugin.so

Usage

You need libica-plugin.so and clang-10

Checks list

A comma separated list of checks with optionally specified emit levels

Check names are listed here. Alias to list all the checks - all

Emit levels:

  • nothing - none - check is disabled
  • warning - warn - default
  • error - err

Example:

all=warn,-redundant-noexcept,erase-in-loop=err

will enable all checks with warning level, disable redundant-noexcept and set error level for erase-in-loop check

Bare compiler

You need additional flags:

  • -load path/to/libica-plugin.so
  • -add-plugin ica-plugin
  • -plugin-arg-ica-plugin checks=$CHECKS
  • -plugin-arg-ica-plugin no-url - optionally disable integrating url to the check info

CHECKS is the check list

Every argument for the compiler frontend is passed with -Xclang, so the final list looks like that:

-Xclang -load -Xclang ../build/libica-plugin.so \
    -Xclang -add-plugin -Xclang ica-plugin \
    -Xclang -plugin-arg-ica-plugin -Xclang checks=$CHECKS

CMake integration

If you have a CMake project, there are options to use ICA easily, either as an external project or a subdirectory in your workspace.

Use as an external project

First you need to have your ICA built (see) and installed:

cd build && cmake --install --install-prefix /path/to/ica/installation/

And add this to your CMakeLists.txt

# If ICA is installed in unusual location
list(APPEND CMAKE_PREFIX_PATH "/path/to/ica/installation")

find_package(ICA CONFIG REQUIRED)
ica_set_checks(<your checks list>)

target_link_libraries(<your target> ICA::ICAChecks)

Use as a subdirectory

Add ICA sources as subdirectory to your project (probably through git submodule) and add this to your CMakeLists.txt

# Set any other cache variables here: GCC_TOOLCHAIN, LLVM_ROOT, ...
set(BOOST_FROM_INTERNET ON)

add_subdirectory(itiviti-cpp-analyzer)
ica_set_checks(<your checks list>)

target_link_libraries(<your target> ICAChecks)

Supress a warning

// NOLINT comment will suppress any warning on the line

map.emplace(0, std::string{}); // NOLINT

emplace-default-value check will be suppressed here

About

Clang plugin with several static analysis checks

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C++ 94.8%
  • CMake 4.3%
  • Other 0.9%