A package designed to run the clang static analyzer against projects with existing compilation databases. The clanganalyzer tool runs the clang static analyzer against a compilation database.
It's available from the Python Package Index and can be installed using pip or uv:
$ pip install scan-build
Or using uv (recommended):
$ uv add scan-build
For development:
$ uv sync --all-extras
Should be working on UNIX operating systems.
- It has been tested on FreeBSD, GNU/Linux, OS X and Windows.
- clang compiler, to compile the sources and have the static analyzer.
- python interpreter (version 3.10 or later). Supported versions: 3.10, 3.11, 3.12, 3.13.
To run the Clang static analyzer against a project with an existing compilation database goes like this:
$ clanganalyzer
Use --help to know more about the command.
The clanganalyzer tool requires:
- An existing compilation database (
compile_commands.json) for your project - The clang static analyzer to be available on your system
You can generate a compilation database using various tools like CMake
(with -DCMAKE_EXPORT_COMPILE_COMMANDS=ON), Bear, or other build systems
that support compilation database generation.
The tool requires a valid compilation database to function. If your project doesn't have one, you'll need to generate it first using your build system or tools like Bear.
To set up a development environment:
$ git clone https://github.com/rizsotto/scan-build.git $ cd scan-build $ uv sync --all-extras
To run tests:
$ uv run pytest tests/unit $ uv run lit -v tests/functional
To run linting and type checking:
$ uv run ruff check . $ uv run ruff format . $ uv run ty clanganalyzer
If you find a bug in this documentation or elsewhere in the program or would like to propose an improvement, please use the project's issue tracker. Please describe the bug and where you found it. If you have a suggestion how to fix it, include that as well. Patches are also welcome.
The project is licensed under University of Illinois/NCSA Open Source License. See LICENSE.TXT for details.