From 00270df5175e97951836f4aa721d45c902f4b4ee Mon Sep 17 00:00:00 2001 From: Justin Bogner Date: Thu, 22 Jan 2015 02:17:23 +0000 Subject: [PATCH] InstrProf: Avoid creating profile names for symbols in system headers 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. llvm-svn: 226764 --- clang/lib/CodeGen/CodeGenPGO.cpp | 3 +-- clang/test/CoverageMapping/unused_names.c | 21 +++++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 clang/test/CoverageMapping/unused_names.c diff --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang/lib/CodeGen/CodeGenPGO.cpp index 24b035d67598..7f7321320e0b 100644 --- a/clang/lib/CodeGen/CodeGenPGO.cpp +++ b/clang/lib/CodeGen/CodeGenPGO.cpp @@ -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/clang/test/CoverageMapping/unused_names.c b/clang/test/CoverageMapping/unused_names.c new file mode 100644 index 000000000000..b1317209610a --- /dev/null +++ b/clang/test/CoverageMapping/unused_names.c @@ -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