lcov: "line is hit but no branches on line have been evaluated."

Open
#555 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
57/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
c, perl

Research direction

Start by running the supplied GCC coverage reproduction and compare the tracefile after lcov --capture with what happens during lcov -a aggregation. The issue gives no project file or test path, so trace the aggregation path that reads tracefiles and add a regression test for this example; done means aggregation accepts the tracefile without the reported consistency error while retaining consistency checks.

Written by the indexing model from the issue text.

Description

Hi,

when using lcov on postgres, I was repeatedly hit with "line is hit but no branches on line have been evaluated". Interestingly this seems to not happen when actually parsing the coverage output, but when lcov is reading lcov output, e.g. during aggregation.

int f(void)
{
	return 1;
}

int main(int argc, char **argv)
{
	/* removing newline avoids the spurious error */
	return argc &&
		(f() || argc);
}

processing that with:

export GCC_VER=16 PATH="/home/andres/src/lcov/bin/:$PATH"
rm -f *.gcno *.gcda *.gcov *.info.* *.json.gz
gcc-${GCC_VER} --coverage coverage_bug_b.c -o coverage_bug_b
 ./coverage_bug_b || true
lcov --capture --branch-coverage --gcov-tool gcov-${GCC_VER} -o coverage.info.run -d . 
lcov -a coverage.info.run -o coverage.info.combined --branch-coverage

triggers the following output:

...
Reading tracefile coverage.info.run.
lcov: ERROR: (corrupt) unable to read trace file 'coverage.info.run': lcov: ERROR: (inconsistent) "/home/andres/tmp/coverage_bugs/coverage_bug_b.c":10: line is hit but no branches on line have been evaluated.
	To skip consistency checks, see the 'check_data_consistency' section in man lcovrc(5).
	(use "lcov --ignore-errors inconsistent ..." to bypass this error)
	(use "lcov --ignore-errors corrupt ..." to bypass this error)
...

This happens across a wide range of gcc versions, at least back to gcc 8.

At least that repro does not reproduce with lcov 2.1, but does reproduce with 2.2.

I don't think the gcov output here is incorrect, but I'm far from an expert on any of this. It seems legal for a line to execute, even if all of the associated branch block have not executed. In this case the executed branch is on line 9.

Greetings,

Andres

Dominant language
Shell
Stars
1.1k
Forks
272
Avg merge
44m
Merged PRs (30d)
8

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from linux-test-project/lcov

All issues in linux-test-project/lcov

Similar issues

More Shell/Bash issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.