How do I enable coverage reports with Clang?

Enabling coverage reports in Clang allows you to analyze the code you have tested and how much of it is executed during the tests. This can be incredibly helpful for identifying untested portions of your codebase and improving overall quality.

To enable coverage reports using Clang, you typically use the following flags when compiling your code:

clang -fprofile-arcs -ftest-coverage -o my_program my_source_file.c

After compiling your code with the coverage options, you can run your program as usual. Once the program has executed, you can use the following command to generate a coverage report:

llvm-cov report my_program

To generate an HTML report specifically, use:

llvm-cov show my_program -format=html -output-dir=coverage_html

Clang Coverage Reports LLVM Code Coverage Testing Software Quality