---
title: "Static analysis"
---

# Static analysis

Cppcheck with the MISRA C:2012 addon on SDK applications with the target's types and macros, suppressions with a reason, an exported report, and sparse and checkpatch.pl on kernel drivers.

The checkers run as separate processes on the build host (or on this computer for an SDK installed here); nothing is bundled.

**State:** modelled with Cppcheck 2.13.0 and its MISRA addon on a daemon in C and C++ with planted defects, configured by CMake 3.28.3 with an aarch64 GCC 13.3.0 stand-in SDK, here and over OpenSSH 9.6p1; a defect found only with the target's macros; line and inline suppressions honoured on the next run; sparse 0.6.4 through `make M= C=2` on Linux 6.6.52 (an in-tree CAN driver with the tree left unchanged, another in-tree driver, an out-of-tree driver); checkpatch.pl 0.32 on a driver and a `git format-patch` patch; the running app. Not run with a real Yocto, Wind River or vendor SDK, with your MISRA rule texts, with Cppcheck other than 2.13.0, on a BitBake-built kernel, on Windows, against a real build server, or at realistic code-base size. MISRA C++ is not checked.

## Cppcheck on an application

1. Configure the application once (see [SDK applications](https://neuralinverse.com/docs/modules/embedded-linux/sdk-applications/)) so it has `compile_commands.json`.
2. Run **Analyse Application with Cppcheck...**, or **Analyse Current File with Cppcheck** for one file. The working copy is sent first.
3. Cppcheck runs over the compile commands with the target compiler's predefined macros and a platform file of the target's type sizes taken from the same compiler (Cppcheck's own arm64 platform file has a 32-bit `long`), and the std, posix and gnu library configurations.
4. Findings land in Problems with severity, rule id and related locations.

Settings, all under `neuralInverse.embeddedLinux.analysis.`:

| Setting | Meaning |
|---|---|
| `cppcheckPath` | Cppcheck on the machine where the SDK is (2.13 or later); empty for `cppcheck` on PATH |
| `checks` | Check groups besides errors: `warning`, `style`, `performance`, `portability` |
| `misra` | Runs the MISRA C:2012 addon on C files (python3 is needed where Cppcheck runs) |
| `misraRuleTexts` | The company's MISRA C:2012 rule texts file, from your licensed copy; none is shipped. Without it, findings name only the rule number |
| `suppressionsFile` | The project's suppressions file, relative to the source tree |
| `exclude` | Glob patterns of source files not analysed |
| `sparsePath` | sparse on the build host for the kernel check |

## Suppress a finding with a reason

1. On a finding, press Ctrl+. and choose **Suppress ... with a Reason...**.
2. Pick where it is recorded: **This Line**, **This File** or **Every File of the Application** (in the project's suppressions file), or **Inline Comment Above the Line** in the source itself.
3. Enter the reason. The confirmation shows the file and the exact lines.

![Cppcheck and MISRA C:2012 findings in Problems with the quick fix to suppress a rule with a reason.](https://neuralinverse.com/docs-images/modules/embedded-linux/static-analysis-cppcheck-quick-fix.webp)

![The choice of where a suppression is recorded: this line, this file, every file of the application, or an inline comment.](https://neuralinverse.com/docs-images/modules/embedded-linux/static-analysis-suppress-scope.webp)

## Export the report

**Export Static Analysis Report...** writes Markdown (tool, version, command line, configuration, the SHA-256 of the rule texts and suppressions files, findings, suppression reasons, the MISRA compliance summary and its limits) or CSV.

## Kernel drivers: sparse and checkpatch.pl

- **Check Kernel Driver with sparse...** builds a temporary copy of a driver folder with `make M= C=2 CHECK=sparse` against the kernel recipe's prepared build folder and `KERNEL_CC` from `bitbake -e virtual/kernel`. Neither the source nor the build folder is written. Findings land on the driver's lines. Build the kernel once first, without `rm_work`.
- **Check Current File or Patch with checkpatch.pl** runs the kernel's own script on a source file or a patch (for example one written by devtool finish); findings stand on the patch's own lines.

## Agent tools

Five read-only tools read findings and run the checks; writing a suppression always asks first.

Next: [Targets](https://neuralinverse.com/docs/modules/embedded-linux/targets/).
