Coverage of the LLVM compiler source code when compiling a program

I’d like to compile some LLVM IR (LLVM code) using the LLVM compiler and check the line coverage and other coverage information on the compiler itself.

I’ve seen other people do something similar by adding their own C code to the test suite and running the test suite with coverage on the LLVM compiler (but they did not document their method, only showed the results).

How should I approach this?

Maybe building using the LLVM_BUILD_INSTRUMENTED_COVERAGE CMake variable will do what you want?


If enabled, source-based code coverage instrumentation is enabled while building llvm. If CMake can locate the code coverage scripts and the llvm-cov and llvm-profdata tools that pair to your compiler, the build will also generate the generate-coverage-report target to generate the code coverage report for LLVM, and the clear-profile-data utility target to delete captured profile data. See documentation for LLVM_CODE_COVERAGE_TARGETS and LLVM_COVERAGE_SOURCE_DIRS for more information on configuring code coverage reports.

1 Like