taiki-e / cargo-llvm-cov

Cargo subcommand to easily use LLVM source-based code coverage (-C instrument-coverage).
Apache License 2.0
858 stars 57 forks source link

Add support for MC/DC coverage #363

Open aytey opened 2 months ago

aytey commented 2 months ago

MC/DC coverage recently landed in rustc:

but cargo-llvm-cov doesn't yet pass the -show-mcdc flag to llvm-cov, so we cannot get reports showing MC/DC coverage.

This PR adds support for -show-mcdc to llvm-cov when working with cargo-llvm-cov.

I checked: if RUSTFLAGS contains -Zcoverage-options=branch (i.e., MC/DC is not enabled) then the reports are the same as if you didn't pass -show-mcdc (i.e., you don't get "empty" MC/DC tables).

aytey commented 2 months ago

Oh, I hadn't realise it would fail if you used a non-nightly with that flag.

Is there a way to check if the current version of rustc supports MCDC?

taiki-e commented 2 months ago

Is there a way to check if the current version of rustc supports MCDC?

I think you can check rustc version like:

https://github.com/taiki-e/cargo-llvm-cov/blob/550dc19643ac31cd4fd5dac52e9d3239a1295ea9/src/main.rs#L205-L211

taiki-e commented 2 months ago

The actual error here is due to the version of llvm-cov command (-show-mcdc requires LLVM 18+), so a check like cmd!(&cx.llvm_cov, "show", "--help").read()?.contains("-show-mcdc") might be better.