Issue 120071
Summary [llvm-cov] lcov-export generates invalid lcov files
Labels new issue
Assignees
Reporter zgtm
    In certain cases, `llvm-cov export` exports lcov files, that seem to be invalid. They contain coverage information for the line after the final newline character.

For these lcov files, `genhtml` (part of the lcov project) will report the following error:

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

## Reproduce

`main.c`:
```C
#define FOO();

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

int main(){}
```

`supp.h`:
```C
#define BAR FOO
BAR()
```

Run
```sh
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 > main.lcov
```

## Expected Behaviour

`main.lcov` does not contain

```
DA:3,0
```

For `supp.h`.


## Actual Behaviour

`main.lcov` contains

```
SF:/some/path/supp.h
…
DA:3,0
```

However, there is no line 3 in `supp.h`.

`genhtml main.lcov` will report "genhtml: ERROR: (range) /some/path/supp.h contains only 2 lines but coverage data refers to line 3"

## Additional Information

```
$ 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

_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to