Closes #19
If branch coverage is specified as goal, the program is instrumented by adding labels after program branches.
Unfortunately, an empty statement like BRANCH_1:; is fully ignored by llvm gcov and there exists no configuration to change this behaviour. To handle this problem, the instrumented program gets for each branch two new program lines with a goto
statement and a label statement. The goto
statement is noticed by llvm gcov
. For instance:
if(x == 2){
goto BRANCH_0;
BRANCH_0:;
...
} else
goto BRANCH_1;
BRANCH_1:;
...
...
If another coverage is specified (line coverage, condition coverage), branch coverage is None
and the resulting coverage will always return zero as branch coverage.
Note: gcc with gcov/lcov notices empty statements. However, clang with llvm gcov should be still preferred. The tests in test_execution.py
are adapted to clang with llvm gcov. A gcc gcov/lcov version outputs different coverage results compared to the llvm version that emulates gcov 4.2, for instance they differ when looking at lines with just a curly bracket. Moreover, gcc with gcov/lcov always shows coverage greater than zero for the lines in the last else statement in a program, even though these lines are never hit. This seems to be a bug.