]> granicus.if.org Git - clang/commitdiff
InstrProf: Avoid creating profile names for symbols in system headers
authorJustin Bogner <mail@justinbogner.com>
Thu, 22 Jan 2015 02:17:23 +0000 (02:17 +0000)
committerJustin Bogner <mail@justinbogner.com>
Thu, 22 Jan 2015 02:17:23 +0000 (02:17 +0000)
We don't emit any coverage mapping for uncovered functions that come
from system headers, but we were creating a GlobalVariable with each
of their names. This is wasteful since the linker will need to dead
strip the unused symbols, and it can lead to issues when merging
coverage with others TUs that do have coverage for those functions.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@226764 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CodeGenPGO.cpp
test/CoverageMapping/unused_names.c [new file with mode: 0644]

index 24b035d67598b975d2fc5fe9c8bc1989c6caa2dd..7f7321320e0b8b8a76bd91d5268b428ba153a98d 100644 (file)
@@ -732,8 +732,6 @@ CodeGenPGO::emitEmptyCounterMapping(const Decl *D, StringRef FuncName,
                                     llvm::GlobalValue::LinkageTypes Linkage) {
   if (SkipCoverageMapping)
     return;
-  setFuncName(FuncName, Linkage);
-
   // Don't map the functions inside the system headers
   auto Loc = D->getBody()->getLocStart();
   if (CGM.getContext().getSourceManager().isInSystemHeader(Loc))
@@ -750,6 +748,7 @@ CodeGenPGO::emitEmptyCounterMapping(const Decl *D, StringRef FuncName,
   if (CoverageMapping.empty())
     return;
 
+  setFuncName(FuncName, Linkage);
   CGM.getCoverageMapping()->addFunctionMappingRecord(
       FuncNameVar, FuncName, FunctionHash, CoverageMapping);
 }
diff --git a/test/CoverageMapping/unused_names.c b/test/CoverageMapping/unused_names.c
new file mode 100644 (file)
index 0000000..b131720
--- /dev/null
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -fprofile-instr-generate -fcoverage-mapping -emit-llvm -o - %s | FileCheck %s
+
+// Since foo is never emitted, there should not be a profile name for it.
+
+// CHECK-NOT: @__llvm_profile_name_foo =
+// CHECK: @__llvm_profile_name_bar =
+// CHECK-NOT: @__llvm_profile_name_foo =
+
+#ifdef IS_SYSHEADER
+
+#pragma clang system_header
+inline int foo() { return 0; }
+
+#else
+
+#define IS_SYSHEADER
+#include __FILE__
+
+int bar() { return 0; }
+
+#endif