Skip to content

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

Closed as not planned
@zgtm

Description

@zgtm

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions