diff options
-rw-r--r-- | clang/lib/CodeGen/CodeGenPGO.cpp | 3 | ||||
-rw-r--r-- | clang/test/Profile/Inputs/cxx-missing-bodies.proftext | 9 | ||||
-rw-r--r-- | clang/test/Profile/cxx-missing-bodies.cpp | 21 |
3 files changed, 33 insertions, 0 deletions
diff --git a/clang/lib/CodeGen/CodeGenPGO.cpp b/clang/lib/CodeGen/CodeGenPGO.cpp index 9e193531d0f..c3d66c1dabc 100644 --- a/clang/lib/CodeGen/CodeGenPGO.cpp +++ b/clang/lib/CodeGen/CodeGenPGO.cpp @@ -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/clang/test/Profile/Inputs/cxx-missing-bodies.proftext b/clang/test/Profile/Inputs/cxx-missing-bodies.proftext new file mode 100644 index 00000000000..c07f297f74d --- /dev/null +++ b/clang/test/Profile/Inputs/cxx-missing-bodies.proftext @@ -0,0 +1,9 @@ +??_GA@@UAEPAXI@Z +1 +1 +1 + +??_DA@@QAEXXZ +1 +1 +1 diff --git a/clang/test/Profile/cxx-missing-bodies.cpp b/clang/test/Profile/cxx-missing-bodies.cpp new file mode 100644 index 00000000000..fe926b3b218 --- /dev/null +++ b/clang/test/Profile/cxx-missing-bodies.cpp @@ -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; +} |