Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

llvm-cov gcov does not add "(throw)" to branch statements #47131

Open Quuxplusone opened 3 years ago

Quuxplusone commented 3 years ago
Bugzilla Link PR48162
Status NEW
Importance P enhancement
Reported by John Forrest (John.Forrest@gbgplc.com)
Reported on 2020-11-12 08:58:07 -0800
Last modified on 2020-11-12 08:58:07 -0800
Version trunk
Hardware PC Linux
CC llvm-bugs@lists.llvm.org
Fixed by commit(s)
Attachments temp-gcov-example.zip (1739 bytes, application/x-zip-compressed)
Blocks
Blocked by
See also
Created attachment 24158
Sample files

I am using clang++ to generate coverage reports as part of Sonarqube analysis.
This expects the output from gcovr and we use the latter telling it to use
"llvm-cov gcov" as documented. We've hit the common(?) problem where the
reported coverage figures are low, due it seems to extra branches being added
for exception support. The recommended approach is to add flags --exclude-throw-
branches --exclude-unreachable-branches to gcovr. This has been observed to
help a little but not much.

Experimentation suggests that this relates to the llvm toolchain. gcov itself
(obviously what gcovr expects) adds extra tags to the branch statements with
"(throw)" and "(fallthrough)". It is these tags that gcovr uses to support --
exclude-throw=branches. llvm-cov does not, so gcovr assumes they are "normal"
branches - it has no option. E.g. compare (gcc/gcov):

branch  1 taken 1 (fallthrough)
branch  2 taken 0 (throw)

with (clang/llvm-cov gcov):

branch  0 taken 1
branch  1 taken 0

The attached zip contains a sample program and the respective output of
compiling (with "-O0 -g --coverage"), running and then extracting coverage with
flags "--branch-counts --branch-probabilities --preserve-paths". gcc is v8.3.1.
llvm is 11.0.
Quuxplusone commented 3 years ago

Attached temp-gcov-example.zip (1739 bytes, application/x-zip-compressed): Sample files