CodeChecker Documentation

repository·master·Indexed 25 days ago

https://github.com/ericsson/codechecker

A static analysis infrastructure built on the LLVM/Clang Static Analyzer toolchain that provides a unified interface for multiple C/C++ and other language analyzers. It enables developers to log builds via a JSON Compilation Database, perform incremental analysis, and manage results through a centralized web-based reporting system. The toolset includes a Build Logger for intercepting compiler calls, a statistics collector, and integration with code review systems like GitLab and Gerrit.

Tokens
112.1K
Snippets
199
Records
508
Agent score
81%

What's inside CodeChecker

  1. Overview of CodeChecker command line tooling

    master

    CodeChecker provides a command-line interface to perform static code analysis and store the resulting reports in a web-based storage.

    Key analysis-related workflows include:

    • Integrating analysis with your build system using log.
    • Executing static analysis using analyze.
    • Viewing analysis results in the command line using parse.
    • Applying code fixes using fixit.
    • Suppressing false positives using source-code comments.

    Note: Analysis workflows can be completed entirely without a web-server.

  2. Overview of CodeChecker Thrift APIs

    master
    CodeChecker uses Thrift APIs for all client-server communication. Any new client should interact with the database exclusively through these APIs rather than direct database access. The APIs are organized into several functional layers including report management, authentication, product management, and configuration.
  3. Overview of CodeChecker

    master
    CodeChecker is a static analysis infrastructure built on the LLVM/Clang Static Analyzer toolchain. It is designed to replace scan-build in Linux or macOS development environments. It provides a unified interface for executing multiple analyzers, storing results in a web-based database, and integrating with code review systems like GitLab and Gerrit.
  4. Overview of CodeChecker Command Line Interface

    master

    The CodeChecker CLI is divided into two main categories of sub-commands:

    1. Analysis sub-commands: Used for executing analyzers and performing local analysis (e.g., analyze, check, checkers, analyzers, log, parse).
    2. Web sub-commands: Used for interacting with a running CodeChecker web server (e.g., server, store, cmd, version).

    The CodeChecker client communicates with the server exclusively via the HTTP(S) protocol.

    CodeChecker --help
  5. CodeChecker Visual Studio Code plugin

    master

    The CodeChecker VSCode extension allows you to integrate static analysis directly into your editor workflow.

    Key Features:

    • Run CodeChecker analysis from the editor and view results automatically.
    • Re-analyze the current file upon saving.
    • Use commands and build tasks to run CodeChecker as part of a build system.
    • Browse reports and view reproduction steps directly within the code.
    • Navigate between different reproduction steps.
  6. Compare CodeChecker Command-line and Web GUI features

    master

    CodeChecker provides two primary interfaces: the Command-line and the Web GUI. Choosing between them depends on whether you need to perform analysis, manage reports, or administer the server.

    Core Interface Responsibilities

    • Analysis Invocation: Analyzers can only be invoked via the command-line analyze command. Analysis runs locally on the user's machine.
    • Report Storage: Storing reports to a server can only be done via the command-line store command.
    • Server Administration: Starting the server and handling schema upgrades is done via the command-line CodeChecker server command.

    Feature Availability Matrix

    Feature CategoryCommand-lineWeb GUI
    Report Navigation
    Basic summary (file, check message, etc.)
    Advanced summary (detection status, review, etc.)
    Basic filtering (file path, check name, etc.)
    Advanced filtering (detection status, date, etc.)
    Visualisation of bug path in codeHTML export only
    Report Management & Triaging
    Commenting/Editing/Deleting comments
    Changing review status
    Difference of two runs
    Difference of stored run vs local folder
    Statistics & Summaries
    Run overview (detailed)
    Breakdown of reports per run/check
    Exporting breakdown to CSV
    Run & Product Management
    Listing runs in a product
    Listing store actions (history)
    Deleting runs
    Listing/Adding/Modifying/Removing products
    Administration
    Configuring authentication systemConfig file
    Managing user permissions
  7. Configure `store` connection via `PRODUCT_URL`

    master

    The store and cmd commands require a PRODUCT_URL to identify which server and Product to target.

    Format: [http[s]://]host:port/ProductEndpoint

    • Protocol: http (default) or https.
    • Host/Port: The server's address and listening port.
    • ProductEndpoint: The case-sensitive unique endpoint for the product (configured by administrators).

    Defaults: If no URL is provided, it defaults to http://localhost:8001/Default.

    Example: https://codechecker.example.org:9999/SampleProduct connects to codechecker.example.org on port 9999 via HTTPS using the SampleProduct endpoint.

  8. Handle partial functions to prevent false positives

    master

    A partial function is one that only works on a specific subset of input values. If the analyzer doesn't know these preconditions, it may report errors for the 'missing' cases.

    To fix this, you can:

    1. Use a default case in a switch statement with an assert(false).
    2. Use an Immediately-Invoked Function Expression (IIFE) with a lambda (C++11 or later) to ensure variables are assigned valid values immediately.
    // Option 1: Using default assert
    int f(MyEnum Val) {
      int x = 0;
      switch (Val) {
        case MyEnumA: x = 1; break;
        case MyEnumB: x = 5; break;
        default: assert(false); break;
      }
      return 5/x;
    }
    
    // Option 2: Using IIFE (C++11+)
    int f(MyEnum Val) {
      const int x = [&] {
        switch (Val) {
          case MyEnumA: return 1;
          case MyEnumB: return 5;
          default: assert(false); return 0;
        }
      } ();
      return 5/x;
    }
  9. Configure Report Storage and Viewer Server

    master

    The Report Storage and Viewer server manages the lifecycle of analysis results. Key features include:

    • Thrift API: Used to store and query analysis results.
    • Deduplication: Automatically detects duplicate results (e.g., a result in a header file detected by multiple analyzer runs) so each source file is stored only once.
    • Database Management: Uses SQLAlchemy to connect to backends. It manages multiple Products, where each product can reside in a separate database.
    • Authentication: Supports user authentication (e.g., LDAP).
    • Web Interface: Provides an HTTPS webserver for viewing reports.
  10. Understand Checker Labels and Severities

    master

    CodeChecker uses labels in the checker/labels directory to categorize checkers by profile, guideline, or severity. These labels allow users to filter or group analysis results.

    Severity Levels

    When analyzing code, checkers are assigned one of the following severity levels:

    LevelDescription
    STYLEViolations of coding guidelines or readability improvements (e.g., LLVM Coding Guideline violations).
    LOWCode that is hard to read, understand, or could be easily optimized (e.g., unused variables, dead code).
    MEDIUMCode that may not cause a runtime error yet but is prone to error (e.g., redundant expressions).
    HIGHCode that will cause a runtime error (e.g., out of bounds array access, division by zero, memory leaks).
    CRITICALIndicates compilation errors.
    UNSPECIFIEDThe checker severity is not defined.

    Other Labels

    • profile: A grouping of checkers that can be managed using --enable or --disable flags during analysis.
    • guideline: The specific coding guideline (e.g., sei-cert-c, sei-cert-cpp) covered by the checker.