zero9178 / C-Cpp-Coverage-for-CLion

Get coverage data in CLion using gcov or llvm-cov
MIT License
38 stars 2 forks source link

Documentation seems incorrect for clang 9 #12

Closed vlebourl closed 4 years ago

vlebourl commented 4 years ago

Documentation suggest using flags -fprofile-instr-generate -fcoverage-mapping for clang compiler, but this raises the following error with clang 9 on macOs:

clang-9: error: unknown argument: '-fprofile-instr-generate -fcoverage-mapping'

vlebourl commented 4 years ago

Using --coverage does generate the gcno and gcda files, but then llvm-profdata fails error:

llvm-profdata returned error code 1 with error output:
error: No input files specified. See llvm-profdata merge -help
zero9178 commented 4 years ago

Using --coverage with clang makes it write gcno and gcda files that are compatible with older versions of GCC (some 4.x.x version I believe). One would need a matching gcov version for this to work. Gcov however is much less powerful than clangs own source based coverage implementation so this is not recommended at all.

Why your clang does not have those options I have no clue. AFAIK clang supports source based coverage since version 3.9 (https://releases.llvm.org/3.9.0/tools/clang/docs/SourceBasedCodeCoverage.html) and still does in the latest (https://clang.llvm.org/docs/SourceBasedCodeCoverage.html and source code for 9.0.0 tree here https://github.com/llvm-mirror/clang/blob/release_90/include/clang/Driver/Options.td#L744). This seems to be an issue with your clang or more likely the way you pass the options to the compiler