Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

genhtml errors when last line is empty and contains coverage information #337

Open
zgtm opened this issue Dec 16, 2024 · 1 comment
Open

Comments

@zgtm
Copy link

zgtm commented Dec 16, 2024

Certain lcov files generated by llvm contain coverage information for the line after the final newline character.

For these lcov files, genhtml will report the following error:

genhtml: ERROR: (range) /some/path/supp.h contains only 2 lines but coverage data refers to line 3

Would it make sense to allow the last empty line to contain coverage information and only show this error message if more than the last line contains coverage information?

E.g. ignore the error for n=1 or have it behave as a warning instead of an error?

Reproduce

main.c:

#define FOO();

void foobar() {
   #include "supp.h"
}

int main(){}

supp.h:

#define BAR FOO
BAR()

Run

clang -o main -fcoverage-mapping -fprofile-instr-generate main.c
LLVM_PROFILE_FILE='main.profraw' ./main
llvm-profdata merge -sparse -o main.profdata main.profraw
llvm-cov export -format=lcov -instr-profile=main.profdata main > main.lcov

genhtml main.lcov -o report

Alternatively, this is the lcov file:
main.lcov:

SF:/some/path/main.c
FN:3,foobar
FN:7,main
FNDA:0,foobar
FNDA:1,main
FNF:2
FNH:1
DA:1,0
DA:3,0
DA:4,0
DA:5,0
DA:7,1
BRF:0
BRH:0
LF:4
LH:1
end_of_record
SF:/some/path/supp.h
FNF:0
FNH:0
DA:1,0
DA:2,0
DA:3,0
BRF:0
BRH:0
LF:0
LH:0
end_of_record

Additional Information

$ genhtml --version
genhtml: LCOV version 2.2-13-gb672a74
$ clang --version
Ubuntu clang version 19.1.1 (1ubuntu1)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/lib/llvm-19/bin
$ llvm-profdata --version
Ubuntu LLVM version 19.1.1
  Optimized build.
$ llvm-cov --version
Ubuntu LLVM version 19.1.1
  Optimized build.

On Kubuntu 24.10.a

@henry2cox
Copy link
Collaborator

henry2cox commented Dec 16, 2024

Would it make sense to allow the last empty line to contain coverage information and only show this error message if more than the last line contains coverage information?

Could be done - but what issues do you see with the current solution, which requires you to either:

  • add the --keep-going flag, or
  • add --ignore-errors range, or
  • add --filter range?

Yet another thing you could do, is to write your own annotation callback which had the desired behaviour.

Wrong/inconsistent data is wrong and/or inconsistent - regardless of whether it is just one line, or many.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants