Hi,

The current state of flags for controlling the code coverage features is a bit messy. GCC uses these options to enable different kinds of coverage:

-ftest-coverage
-fcondition-coverage
-fpath-coverage
--coverage

There's also -fprofile-arcs which is implied by --coverage, but -fprofile-arcs is useful outside of coverage for profile-guided optimizations, maybe other uses. Unlike -fprofile-arcs, the -fcondition-coverage and -fpath-coverage does not make sense without also enabling -ftest-coverage, I have a patch fixing that [1]. --coverage has historically been the flag intended to be used by users, as it also tells to linker to link libgcov. It never really makes sense to use -fcondition-coverage or -fpath-coverage without -ftest-coverage.

To make matters a bit more confusing, -fcondition-coverage measures masking MC/DC [2], and -fpath-coverage measures prime path coverage [3][4], and neither is immediately obvious from the flags. For comparison, clang uses -fmcdc for its (unique-cause) MC/DC support. Both these flags were added by me, and the intention at the time was for them to maybe include options later for specifying what form of condition- and path coverage to measure, with the current behaviour remaining the default. We can still do this, of course, but either way it's still a bit of a mess.

I propose to either extend the --coverage flag with an option, or add a new flag, similar to the -fsanitize=... family, maybe with some defaults. Example usage:

gcc a.c -o a --coverage # line and branch coverage
gcc a.c -o a --coverage=prime-path,mcdc # implies masking MC/DC
gcc a.c -o a --coverage=prime-path,masking-mcdc # explicitly masking MC/DC
gcc a.c -o a --coverage=prime-path --coverage=masking-mcdc # repeated use is ok too

An alternative to overloading the --coverage flag is adding a new -fcoverage=... flag, similar to -fsanitize.

Thoughts, alternatives?

Thanks,
Jørgen

[1] https://gcc.gnu.org/pipermail/gcc-patches/2025-November/699758.html
[2] https://en.wikipedia.org/wiki/Modified_condition/decision_coverage
[3] https://cs.gmu.edu/~johnsonb/fall20/Lecture_19-AOCh7(2).pdf
[4] https://patch.no/static/papers/prime-path-coverage-in-gcc-2025-03-27.pdf

Reply via email to