<div dir="ltr">I've fixed the style, added the tests and utilized CodeGenerator::<div>HandleInlineMethodDefinition() instead of EmitTopLevelDecl. Please see the attached patch:<br><br>-------------- next part --------------<br>
Index: lib/CodeGen/CodeGenModule.cpp<br>===================================================================<br>--- lib/CodeGen/CodeGenModule.cpp (revision 209778)<br>+++ lib/CodeGen/CodeGenModule.cpp (working copy)<br>
@@ -1083,6 +1083,9 @@<br> if (LangOpts.EmitAllDecls)<br> return false;<br> <br>+ // Always emit declarations when instrumenting.<br>+ if (CodeGenOpts.ProfileInstrGenerate && isa<FunctionDecl>(Global))<br>
+ return false;<br> return !getContext().DeclMustBeEmitted(Global);<br> }<br> <br>Index: lib/CodeGen/ModuleBuilder.cpp<br>===================================================================<br>--- lib/CodeGen/ModuleBuilder.cpp (revision 209778)<br>
+++ lib/CodeGen/ModuleBuilder.cpp (working copy)<br>@@ -90,7 +90,9 @@<br> // We may have member functions that need to be emitted at this point.<br> if (!D->isDependentContext() &&<br> (D->hasAttr<UsedAttr>() || D->hasAttr<ConstructorAttr>() ||<br>
- D->hasAttr<DLLExportAttr>())) {<br>+ D->hasAttr<DLLExportAttr>() ||<br>+ // Always emit methods when instrumenting.<br>+ CodeGenOpts.ProfileInstrGenerate)) {<br>
Builder->EmitTopLevelDecl(D);<br> }<br> }<br>Index: test/Profile/c-general.c<br>===================================================================<br>--- test/Profile/c-general.c (revision 209778)<br>
+++ test/Profile/c-general.c (working copy)<br>@@ -14,8 +14,8 @@<br> // PGOGEN: @[[BOC:__llvm_profile_counters_boolean_operators]] = hidden global [8 x i64] zeroinitializer<br> // PGOGEN: @[[BLC:__llvm_profile_counters_boolop_loops]] = hidden global [9 x i64] zeroinitializer<br>
// PGOGEN: @[[COC:__llvm_profile_counters_conditional_operator]] = hidden global [3 x i64] zeroinitializer<br>+// PGOGEN: @[[STC:__llvm_profile_counters_static_func]] = internal global [2 x i64] zeroinitializer<br> // PGOGEN: @[[MAC:__llvm_profile_counters_main]] = hidden global [1 x i64] zeroinitializer<br>
-// PGOGEN: @[[STC:__llvm_profile_counters_static_func]] = internal global [2 x i64] zeroinitializer<br> <br> // PGOGEN-LABEL: @simple_loops()<br> // PGOUSE-LABEL: @simple_loops()<br>Index: test/Profile/c-unused-static-functions.c<br>
===================================================================<br>--- test/Profile/c-unused-static-functions.c (revision 0)<br>+++ test/Profile/c-unused-static-functions.c (working copy)<br>@@ -0,0 +1,12 @@<br>
+// Check that the unused static functions still emit the counters<br>+<br>+// RUN: %clang_cc1 %s -O2 -triple x86_64-apple-macosx10.9 -main-file-name c-unused-static-functions.cpp -o - -emit-llvm -fprofile-instr-generate | FileCheck %s<br>
+<br>+// CHECK: @__llvm_profile_counters_static_func = internal global [1 x i64] zeroinitializer<br>+<br>+static void static_func() {<br>+}<br>+<br>+int main(int argc, const char *argv[]) {<br>+ return 0;<br>+}<br>Index: test/Profile/cxx-unused-methods.cpp<br>
===================================================================<br>--- test/Profile/cxx-unused-methods.cpp (revision 0)<br>+++ test/Profile/cxx-unused-methods.cpp (working copy)<br>@@ -0,0 +1,42 @@<br>+// Check that the unused methods defined inside a class body<br>
+// and inline methods defined outside of the class body<br>+// still emit the counters<br>+<br>+// RUN: %clang_cc1 -x c++ %s -O2 -triple x86_64-apple-macosx10.9 -main-file-name cxx-unused-methods.cpp -o - -emit-llvm -fprofile-instr-generate | FileCheck %s<br>
+<br>+// CHECK: @__llvm_profile_counters__ZN5Outer6methodEv = linkonce_odr hidden global [1 x i64] zeroinitializer<br>+// CHECK: @__llvm_profile_counters__ZN5Outer13inline_methodEv = linkonce_odr hidden global [1 x i64] zeroinitializer<br>
+// CHECK: @__llvm_profile_counters__ZN5Outer5Inner6methodEv = linkonce_odr hidden global [1 x i64] zeroinitializer<br>+// CHECK: @__llvm_profile_counters__ZN5Outer5Inner13inline_methodEv = linkonce_odr hidden global [1 x i64] zeroinitializer<br>
+<br>+class Outer {<br>+ int Member;<br>+public:<br>+<br>+ Outer(int M) : Member(M) {<br>+ }<br>+<br>+ ~Outer() {<br>+ }<br>+<br>+ void method() {<br>+ }<br>+<br>+ inline void inline_method() {<br>+ }<br>+<br>+ struct Inner {<br>
+<br>+ void method() {<br>+ }<br>+<br>+ void inline_method();<br>+ };<br>+};<br>+<br>+inline void Outer::Inner::inline_method() {<br>+}<br>+<br>+int main(int argc, const char *argv[]) {<br>+ return 0;<br>+}<br>
<br></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">2014-05-28 16:11 GMT-07:00 Eric Christopher <span dir="ltr"><<a href="mailto:echristo@gmail.com" target="_blank">echristo@gmail.com</a>></span>:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">On Wed, May 28, 2014 at 4:08 PM, Duncan P. N. Exon Smith<br>
<<a href="mailto:dexonsmith@apple.com">dexonsmith@apple.com</a>> wrote:<br>
><br>
>> On 2014-May-28, at 15:55, Eric Christopher <<a href="mailto:echristo@gmail.com">echristo@gmail.com</a>> wrote:<br>
>><br>
>> ... I'll bite.<br>
>><br>
>> Why do you want to know "this function wasn't instrumented" versus<br>
>> "this had no calls" for coverage? If it's not instrumented it's<br>
>> definitely not called. Otherwise you need to do this for all functions<br>
>> (and who knows what chaos with special member functions that you<br>
>> didn't have to create... :)<br>
><br>
> I can think of two scenarios:<br>
><br>
> 1. The error/warning messages should be different: "profile out of date" vs.<br>
> "foo() has no coverage".<br>
<br>
</div>This seems ok I guess. Though if you've got a binary you should be<br>
able to say "this code doesn't exist".<br>
<div class=""><br>
><br>
> 2. All you have is source and the profile data (i.e., a gcov-like flow,<br>
> without an AST), and you want to output the list of functions with no<br>
> coverage.<br>
<br>
</div>You could just take the ones that you do have coverage info for and<br>
it's the inverse?<br>
<br>
In general I think forcing emission of things that aren't normally<br>
emitted is probably going to be a bit of a problem.<br>
<br>
-erc<br>
<div class="HOEnZb"><div class="h5">_______________________________________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</div></div></blockquote></div><br></div>