From: Vedant Kumar Date: Mon, 24 Apr 2017 20:52:04 +0000 (+0000) Subject: [Coverage] Avoid null deref in skipRegionMappingForDecl (fixes PR32761) X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=29f0cdc96ead7af40229342c168601dd9f02bcbd;p=clang [Coverage] Avoid null deref in skipRegionMappingForDecl (fixes PR32761) 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 --- diff --git a/lib/CodeGen/CodeGenPGO.cpp b/lib/CodeGen/CodeGenPGO.cpp index 6acedc033a..96fc145229 100644 --- a/lib/CodeGen/CodeGenPGO.cpp +++ b/lib/CodeGen/CodeGenPGO.cpp @@ -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 index 0000000000..cfc29a75c6 --- /dev/null +++ b/test/CoverageMapping/empty-destructor.cpp @@ -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; +}