]> granicus.if.org Git - clang/commitdiff
[Coverage] Avoid null deref in skipRegionMappingForDecl (fixes PR32761)
authorVedant Kumar <vsk@apple.com>
Mon, 24 Apr 2017 20:52:04 +0000 (20:52 +0000)
committerVedant Kumar <vsk@apple.com>
Mon, 24 Apr 2017 20:52:04 +0000 (20:52 +0000)
Patch by Adam Folwarczny!

Differential Revision: https://reviews.llvm.org/D32406

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

lib/CodeGen/CodeGenPGO.cpp
test/CoverageMapping/empty-destructor.cpp [new file with mode: 0644]

index 6acedc033a6ea1d61b1958c2351968fef11a6a52..96fc1452293885362f2acc67fd4793f2be0d5eb8 100644 (file)
@@ -669,6 +669,9 @@ bool CodeGenPGO::skipRegionMappingForDecl(const Decl *D) {
   if (SkipCoverageMapping)
     return true;
 
+  if (!D->getBody())
+    return true;
+
   // Don't map the functions in system headers.
   const auto &SM = CGM.getContext().getSourceManager();
   auto Loc = D->getBody()->getLocStart();
diff --git a/test/CoverageMapping/empty-destructor.cpp b/test/CoverageMapping/empty-destructor.cpp
new file mode 100644 (file)
index 0000000..cfc29a7
--- /dev/null
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple i686-windows -emit-llvm-only -fcoverage-mapping -dump-coverage-mapping -fprofile-instrument=clang %s | FileCheck %s
+
+struct A {
+  virtual ~A();
+};
+
+// CHECK: ?PR32761@@YAXXZ:
+// CHECK-NEXT: File 0, [[@LINE+1]]:16 -> [[@LINE+3]]:2 = #0
+void PR32761() {
+  A a;
+}