[cfe-dev] unexpected coverage results for inline function with conditional #ifdef

Vedant Kumar via cfe-dev cfe-dev at lists.llvm.org
Tue Nov 28 11:45:44 PST 2017


Hi,

Thanks for the report, I'll take a look.

vedant

> On Nov 28, 2017, at 5:15 AM, Sam Toliman via cfe-dev <cfe-dev at lists.llvm.org> wrote:
> 
> Hi all,
> 
> I have faced unexpected coverage results for inline function with conditional #ifdef
> 
> // -- header.h
> #pragma once
> 
> inline int bar(int x) {
>     int y = 10;
> #ifdef IE
>     if (x)
>         y *= 2;
> #else
>     y -= 5;
> #endif
>     return x * y;
> }
> 
> // -- lib1.cpp
> #include "header.h"
> 
> int lib1_foo(int x) {
>     return bar(x) + x;
> }
> 
> // -- main.cpp
> #include <iostream>
> #include "header.h"
> 
> extern int lib1_foo(int);
> 
> int main_foo(int x) {
>     return bar(x) + x;
> }
> 
> int main(int c, char**) {
>     std::cout << lib1_foo(c) << " " << main_foo(c) << std::endl;
>     return 0;
> }
> 
> clang++ -fprofile-instr-generate -fcoverage-mapping -O2 -c -g lib1.cpp -o lib1.o -DIE
> clang++ -fprofile-instr-generate -fcoverage-mapping -O2 -c -g main.cpp -o main.o
> clang++ -fprofile-instr-generate -fcoverage-mapping -O2 -g main.o lib1.o -o bin
> ./bin
> llvm-profdata merge -o merged.prof default.profraw
> llvm-cov export -instr-profile merged.prof -object bin
> 
> Output of the program will be "21 6"
> However, segments for header.h will be:
> [3,23,2,1,1],[5,2,0,0,1],[8,2,2,1,0],[12,2,0,0,0] ("y -= 5;" was performed twice)
> Looks like coverage wasn't able to connect source code with counters properly.
> 
> -Sam
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20171128/447dd619/attachment.html>


More information about the cfe-dev mailing list