Clang-static-analyzer plugin

Description

The clang-static-analyzer plugin is used for executing the clang-static-analyzer static code analysis tool.

Mandatory settings

The configuration of the clang-static-analyzer plugin must contain the follwing settings:

build-command

The exec-helper build target command or plugin to execute for the analysis.

Optional settings

The configuration of the clang-static-analyzer plugin may contain the following settings:

patterns

A list of patterns to apply on the command line. See Patterns (5).

command-line

Additional command line parameters to pass as a list of separate arguments. By default no additional arguments are added.

Example

Configuration

commands:                       # Define the commands that can be run
    example: Run the make example
    build: Build the files
    clean: Clean the build

patterns:                       # Define the patterns that can be used
    MAKE_TARGET:                # Define make targets for building
        default-values:         # Only define the default value
            - hello
            - world

example:
    - clean
    - clang-static-analyzer     # Use the clang-static-analyzer plugin when running the 'example' command

build:
    - make

clean:
    - make

clang-static-analyzer:          # Configure clang-static-analyzer
    build-command: build        # Execute the 'build' command for building and analyzing the project
    command-line:               # Add additional arguments to the clang-static-analyzer invocation
        - -enable-checker
        - alpha.clone.CloneChecker

make:
    build:
        patterns:
            - MAKE_TARGET
        command-line:
            - "{MAKE_TARGET}"
    clean:
        command-line:
            - clean

Additional files

In order for the above example to work, the following file hierarchy needs to be created in the directory:

Makefile:

CXX=g++
CXXFLAGS+=-O0 -g --coverage
LDFLAGS+=
SRC_DIR=src
BUILD_DIR=build

hello:
	mkdir -p $(BUILD_DIR)
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $(BUILD_DIR)/hello $(SRC_DIR)/hello.cpp

world:
	mkdir -p $(BUILD_DIR)
	$(CXX) $(CXXFLAGS) $(LDFLAGS) -o $(BUILD_DIR)/world $(SRC_DIR)/world.cpp

clean:
	rm -rf $(BUILD_DIR)

.PHONY: clean

src/hello.cpp:

#include <cstdlib>
#include <iostream>

auto main() -> int {
    std::cout << "Hello" << std::endl;
    return EXIT_SUCCESS;
}

src/world.cpp:

#include <cstdlib>
#include <iostream>

auto main() -> int {
    std::cout << "World!" << std::endl;
    return EXIT_SUCCESS;
}

Usage

Save the example to an exec-helper configuration file and execute in the same directory:

eh example

See also

See exec-helper (1) for information about the usage of exec-helper.

See Configuration (5) for information about the configuration file format.

See Plugins (5) for information about the configuration file format.