<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Hi,<div class=""><br class=""></div><div class="">Thanks for the report, I'll take a look.</div><div class=""><br class=""></div><div class="">vedant</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Nov 28, 2017, at 5:15 AM, Sam Toliman via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="">Hi all,<br class=""></div><div class=""><br class=""></div><div class="">I have faced unexpected coverage results for inline function with conditional #ifdef</div><div class=""><br class=""></div><div class="">// -- header.h<br class=""></div><div class="">#pragma once<br class=""><br class="">inline int bar(int x) {<br class=""> int y = 10;<br class="">#ifdef IE<br class=""> if (x)<br class=""> y *= 2;<br class="">#else<br class=""> y -= 5;<br class="">#endif<br class=""> return x * y;<br class="">}</div><div class=""><br class=""></div><div class="">// -- lib1.cpp</div><div class="">#include "header.h"<br class=""><br class="">int lib1_foo(int x) {<br class=""> return bar(x) + x;<br class="">}<br class=""></div><div class=""><br class=""></div><div class="">// -- main.cpp</div><div class="">#include <iostream><br class="">#include "header.h"<br class=""><br class="">extern int lib1_foo(int);<br class=""><br class="">int main_foo(int x) {<br class=""> return bar(x) + x;<br class="">}<br class=""><br class="">int main(int c, char**) {<br class=""> std::cout << lib1_foo(c) << " " << main_foo(c) << std::endl;<br class=""> return 0;<br class="">}</div><div class=""><br class=""></div><div class="">clang++ -fprofile-instr-generate -fcoverage-mapping -O2 -c -g lib1.cpp -o lib1.o <b class="">-DIE</b><br class="">clang++ -fprofile-instr-generate -fcoverage-mapping -O2 -c -g main.cpp -o main.o<br class="">clang++ -fprofile-instr-generate -fcoverage-mapping -O2 -g main.o lib1.o -o bin<br class="">./bin<br class="">llvm-profdata merge -o merged.prof default.profraw<br class="">llvm-cov export -instr-profile merged.prof -object bin<br class=""></div><div class=""><br class=""></div><div class="">Output of the program will be "21 6"</div><div class="">However, segments for header.h will be:</div><div class="">[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)<br class=""></div><div class="">Looks like coverage wasn't able to connect source code with counters properly.<br class=""></div><div class=""><br class=""></div>-Sam<br class=""></div>
_______________________________________________<br class="">cfe-dev mailing list<br class=""><a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a><br class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev<br class=""></div></blockquote></div><br class=""></div></body></html>