summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustin Bogner <mail@justinbogner.com>2014-04-25 07:20:05 +0000
committerJustin Bogner <mail@justinbogner.com>2014-04-25 07:20:05 +0000
commit3212b18bbf8458cc9eabbb8938ffcef68af7473c (patch)
treea6a34cfd94abda04f87803cc83aaf126c18a3573
parent6b88e3a5454219ee265e5624015a113266cce463 (diff)
downloadbcm5719-llvm-3212b18bbf8458cc9eabbb8938ffcef68af7473c.tar.gz
bcm5719-llvm-3212b18bbf8458cc9eabbb8938ffcef68af7473c.zip
CodeGen: Avoid instrumenting implicit Decls more effectively
We don't assign counters for implicit Decls, but we were emitting code to increment the (non-existent) counters and adding empty counter lists in the output. This fixes the checks in assignRegionCounters and emitInstrumentationData to do the right thing, and adds an assert for the pathological case of emitting zero counters. llvm-svn: 207203
-rw-r--r--clang/lib/CodeGen/CodeGenPGO.cpp6
-rw-r--r--clang/test/Profile/cxx-implicit.cpp17
2 files changed, 21 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang/lib/CodeGen/CodeGenPGO.cpp
index 6991e40f97c..9d4aaff8888 100644
--- a/clang/lib/CodeGen/CodeGenPGO.cpp
+++ b/clang/lib/CodeGen/CodeGenPGO.cpp
@@ -146,7 +146,7 @@ llvm::GlobalVariable *CodeGenPGO::buildDataVar() {
}
void CodeGenPGO::emitInstrumentationData() {
- if (!CGM.getCodeGenOpts().ProfileInstrGenerate)
+ if (!RegionCounters)
return;
// Build the data.
@@ -803,7 +803,7 @@ void CodeGenPGO::assignRegionCounters(const Decl *D, llvm::Function *Fn) {
llvm::IndexedInstrProfReader *PGOReader = CGM.getPGOReader();
if (!InstrumentRegions && !PGOReader)
return;
- if (!D)
+ if (D->isImplicit())
return;
setFuncName(Fn);
@@ -845,6 +845,7 @@ void CodeGenPGO::mapRegionCounters(const Decl *D) {
Walker.TraverseDecl(const_cast<BlockDecl *>(BD));
else if (const CapturedDecl *CD = dyn_cast_or_null<CapturedDecl>(D))
Walker.TraverseDecl(const_cast<CapturedDecl *>(CD));
+ assert(Walker.NextCounter > 0 && "no entry counter mapped for decl");
NumRegionCounters = Walker.NextCounter;
FunctionHash = Walker.Hash.finalize();
}
@@ -920,6 +921,7 @@ void CodeGenPGO::destroyRegionCounters() {
RegionCounterMap.reset();
StmtCountMap.reset();
RegionCounts.reset();
+ RegionCounters = nullptr;
}
/// \brief Calculate what to divide by to scale weights.
diff --git a/clang/test/Profile/cxx-implicit.cpp b/clang/test/Profile/cxx-implicit.cpp
new file mode 100644
index 00000000000..79840ad9385
--- /dev/null
+++ b/clang/test/Profile/cxx-implicit.cpp
@@ -0,0 +1,17 @@
+// Ensure that implicit methods aren't instrumented.
+
+// RUN: %clang_cc1 -x c++ %s -triple %itanium_abi_triple -main-file-name cxx-implicit.cpp -o - -emit-llvm -fprofile-instr-generate | FileCheck %s
+
+// An implicit constructor is generated for Base. We should not emit counters
+// for it.
+// CHECK-NOT: @__llvm_profile_counters__ZN4BaseC2Ev =
+
+struct Base {
+ virtual void foo();
+};
+
+struct Derived : public Base {
+ Derived();
+};
+
+Derived::Derived() {}
OpenPOWER on IntegriCloud