<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class="">Hey Yuanfang,<div class=""><br class=""></div><div class="">It seems like you’re looking for -femit-all-decls (<a href="https://godbolt.org/z/3uw-wF" class="">https://godbolt.org/z/3uw-wF</a>). This interoperates just fine with -fcoverage-mapping. Any duplicate coverage mapping records for functions emitted in multiple TUs will be merged by the linker.</div><div class=""><br class=""></div><div class="">best,</div><div class="">vedant</div><div class=""><div><br class=""><blockquote type="cite" class=""><div class="">On Jun 2, 2020, at 4:43 PM, Chen, Yuanfang via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Hello,<br class=""><br class="">We have a user that wants to get the code coverage report for his library without turning on instrumentation for the library clients or change how they are built (only the library is instrumented). It seems like the inline member functions defined in headers are not instrumented in this case because the clients are not instrumented. The library itself does not have a copy of the inline methods either.<br class=""><br class="">In below example,<br class=""><blockquote type="cite" class="">clang++ -fprofile-instr-generate -fcoverage-mapping -c foobar.cpp -o foobar.o<br class="">clang++ main.cpp foobar.o -o foobar<br class="">LLVM_PROFILE_FILE="foo.profraw" ./foobar<br class="">llvm-profdata merge -sparse foo.profraw -o foo.profdata<br class="">llvm-cov show ./foobar -instr-profile=foo.profdata<br class=""></blockquote><br class="">"""<br class=""> 1| |#include "foobar.h"<br class=""> 2| |<br class=""> 3| |<br class=""> 4| |void FooBar::foo(void)<br class=""> 5| 1|{<br class=""> 6| 1| printf("foo\n");<br class=""> 7| 1|}<br class=""> 8| |<br class="">"""<br class=""><br class=""><br class=""><br class="">foobar.h<br class="">"""<br class="">#pragma once<br class="">#include <stdio.h><br class=""><br class="">class FooBar {<br class="">public:<br class=""> void foo(void);<br class=""> void bar(void) {<br class=""> printf("bar\n");<br class=""> }<br class="">};<br class="">"""<br class=""><br class="">foobar.cpp<br class="">"""<br class="">#include "foobar.h"<br class="">void FooBar::foo(void) {<br class=""> printf("foo\n");<br class="">}<br class="">"""<br class=""><br class="">main.cpp<br class="">"""<br class="">#include "foobar.h"<br class="">int main(int argc, const char *argv[]) {<br class=""> FooBar foobar;<br class=""> foobar.foo();<br class=""> foobar.bar();<br class=""> return 0<br class="">}<br class="">"""<br class=""><br class="">My question are:<br class="">- Is there an existing solution to this use case?<br class="">- If not, is there a compiler switch to use when compiling foobar library to make inline function methods behave like an out-of-line non-inline function? (there are hundreds of inline function methods which makes doing this manually hard)<br class="">- Is there some function attribute such as [[instrument-for-coverage]] to say: I want this function to be instrumented no matter what the command switches are? If not, is it a good idea?<br class=""><br class=""><br class="">Thanks,<br class="">- Yuanfang<br class="">_______________________________________________<br class="">LLVM Developers mailing list<br class=""><a href="mailto:llvm-dev@lists.llvm.org" class="">llvm-dev@lists.llvm.org</a><br class="">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev<br class=""></div></div></blockquote></div><br class=""></div></body></html>