]> granicus.if.org Git - clang/commitdiff
[Profile] Do not assign counters to functions without bodies
authorVedant Kumar <vsk@apple.com>
Fri, 30 Jun 2017 21:02:14 +0000 (21:02 +0000)
committerVedant Kumar <vsk@apple.com>
Fri, 30 Jun 2017 21:02:14 +0000 (21:02 +0000)
The root cause of the issues reported in D32406 and D34680 is that clang
instruments functions without bodies. Make it stop doing that, and also
teach it how to use old (incorrectly generated) profiles without
crashing.

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

lib/CodeGen/CodeGenPGO.cpp
test/Profile/Inputs/cxx-missing-bodies.proftext [new file with mode: 0644]
test/Profile/cxx-missing-bodies.cpp [new file with mode: 0644]

index 9e193531d0f60b7c01ede811d707f490b9613662..c3d66c1dabc5eaca166cd6647cbd15fd4719a429 100644 (file)
@@ -617,6 +617,9 @@ uint64_t PGOHash::finalize() {
 
 void CodeGenPGO::assignRegionCounters(GlobalDecl GD, llvm::Function *Fn) {
   const Decl *D = GD.getDecl();
+  if (!D->hasBody())
+    return;
+
   bool InstrumentRegions = CGM.getCodeGenOpts().hasProfileClangInstr();
   llvm::IndexedInstrProfReader *PGOReader = CGM.getPGOReader();
   if (!InstrumentRegions && !PGOReader)
diff --git a/test/Profile/Inputs/cxx-missing-bodies.proftext b/test/Profile/Inputs/cxx-missing-bodies.proftext
new file mode 100644 (file)
index 0000000..c07f297
--- /dev/null
@@ -0,0 +1,9 @@
+??_GA@@UAEPAXI@Z
+1
+1
+1
+
+??_DA@@QAEXXZ
+1
+1
+1
diff --git a/test/Profile/cxx-missing-bodies.cpp b/test/Profile/cxx-missing-bodies.cpp
new file mode 100644 (file)
index 0000000..fe926b3
--- /dev/null
@@ -0,0 +1,21 @@
+// RUN: %clang_cc1 -emit-llvm %s -std=c++11 -S -emit-llvm -o - -triple=i386-pc-win32 -fno-rtti -fprofile-instrument=clang | FileCheck %s --check-prefix=GEN
+//
+// Don't crash when presented profile data for functions without bodies:
+// RUN: llvm-profdata merge %S/Inputs/cxx-missing-bodies.proftext -o %t.profdata
+// RUN: %clang_cc1 -emit-llvm %s -std=c++11 -S -emit-llvm -o /dev/null -triple=i386-pc-win32 -fno-rtti -fprofile-instrument-use-path=%t.profdata -w
+
+// GEN-NOT: __profn{{.*}}??_GA@@UAEPAXI@Z
+// GEN-NOT: __profn{{.*}}??_DA@@QAEXXZ
+
+struct A {
+  virtual ~A();
+};
+struct B : A {
+  virtual ~B();
+};
+
+B::~B() {}
+
+void foo() {
+  B c;
+}