r306883 - [Profile] Do not assign counters to functions without bodies

Vedant Kumar via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 30 14:02:15 PDT 2017


Author: vedantk
Date: Fri Jun 30 14:02:14 2017
New Revision: 306883

URL: http://llvm.org/viewvc/llvm-project?rev=306883&view=rev
Log:
[Profile] Do not assign counters to functions without bodies

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.

Added:
    cfe/trunk/test/Profile/Inputs/cxx-missing-bodies.proftext
    cfe/trunk/test/Profile/cxx-missing-bodies.cpp
Modified:
    cfe/trunk/lib/CodeGen/CodeGenPGO.cpp

Modified: cfe/trunk/lib/CodeGen/CodeGenPGO.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CodeGenPGO.cpp?rev=306883&r1=306882&r2=306883&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CodeGenPGO.cpp (original)
+++ cfe/trunk/lib/CodeGen/CodeGenPGO.cpp Fri Jun 30 14:02:14 2017
@@ -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)

Added: cfe/trunk/test/Profile/Inputs/cxx-missing-bodies.proftext
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Profile/Inputs/cxx-missing-bodies.proftext?rev=306883&view=auto
==============================================================================
--- cfe/trunk/test/Profile/Inputs/cxx-missing-bodies.proftext (added)
+++ cfe/trunk/test/Profile/Inputs/cxx-missing-bodies.proftext Fri Jun 30 14:02:14 2017
@@ -0,0 +1,9 @@
+??_GA@@UAEPAXI at Z
+1
+1
+1
+
+??_DA@@QAEXXZ
+1
+1
+1

Added: cfe/trunk/test/Profile/cxx-missing-bodies.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Profile/cxx-missing-bodies.cpp?rev=306883&view=auto
==============================================================================
--- cfe/trunk/test/Profile/cxx-missing-bodies.cpp (added)
+++ cfe/trunk/test/Profile/cxx-missing-bodies.cpp Fri Jun 30 14:02:14 2017
@@ -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 at Z
+// GEN-NOT: __profn{{.*}}??_DA@@QAEXXZ
+
+struct A {
+  virtual ~A();
+};
+struct B : A {
+  virtual ~B();
+};
+
+B::~B() {}
+
+void foo() {
+  B c;
+}




More information about the cfe-commits mailing list