Menu

Misra addon slow when including large header files.

2026-01-14
2026-01-19
  • Jonathan Forrest

    I currently have some very simple c files in an embedded project that are taking ~25 seconds to run cppcheck so I started digging into why this is.
    From --showtime it is apparent that the misra addon is taking the majority of the time.
    I have managed to work out that it is happening to any file that is directly or indirectly including one particular header file.
    That header file is a 17000 line header file from ST micro that contains all of the data structures and address mapping for the microcontroller peripherals, as well as further includes from ARM for core definitions.

    Any there any good options for speeding this up?
    I am suppressing any warnings from the included header file, but that doesn't impact the run time at all.

    Obviously I can chose to not specify the include path for the header file in question and suppress all of the unknown variable (misra-config) and implicit function (misra-c2012-17.3) warnings whenever I am using registers, register bit definitions or inline functions from the header file ( like NVIC_EnableIRQ from core_cm4.h, etc.).
    On a couple of test files this does improve the cppcheck run time from 25 & 29 seconds down to 0.3 and 0.2 seconds. But this also loses a lot of functionality as a whole lot of rules won't be able to be properly checked whenever I am using definitions from those header files.

     
  • Andrew C Aitchison

    https://cppcheck.sourceforge.io/manual.pdf chapter 17 (library-configuration) has some general advice about speeding up analysis.

    Another option, which would be a non-trivial amount of work and I am
    only guessing that this would ultimately be faster than cppcheck
    reading the header, is to write a custom .cfg library for this header.
    "You can use the Library Editor in the Cppcheck GUI to edit configuration
    files. It is available in the View menu."

    See manual.pdf chapter 14, and https://cppcheck.sourceforge.io/reference-cfg-format.pdf

    Maybe someone familiar with the misra addon can suggest which bits
    would be most useful to put into the .cfg first ?

     
  • Andrew C Aitchison

    I assume that you are using a Cppcheck build folder: option --cppcheck-build-dir=...
    This wont speed up analysis of individual files, but will avoid having to re-analyze files that have not changed. This option does not seem to be in man cppcheckbut is mentioned in cppcheck --help and in manual.pdf chapter 3.

     

    Last edit: Andrew C Aitchison 2026-01-19

Log in to post a comment.