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.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@207203
91177308-0d34-0410-b5e6-
96231b3b80d8
}
void CodeGenPGO::emitInstrumentationData() {
- if (!CGM.getCodeGenOpts().ProfileInstrGenerate)
+ if (!RegionCounters)
return;
// Build the data.
llvm::IndexedInstrProfReader *PGOReader = CGM.getPGOReader();
if (!InstrumentRegions && !PGOReader)
return;
- if (!D)
+ if (D->isImplicit())
return;
setFuncName(Fn);
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();
}
RegionCounterMap.reset();
StmtCountMap.reset();
RegionCounts.reset();
+ RegionCounters = nullptr;
}
/// \brief Calculate what to divide by to scale weights.
--- /dev/null
+// 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() {}