[PATCH] D32406: [Coverage][Windows] Null pointer dereference in CodeGenPGO::skipRegionMappingForDecl (fixes PR32761)

Adam Folwarczny via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Apr 23 13:56:02 PDT 2017


adamf created this revision.

In function CodeGenPGO::skipRegionMappingForDecl there is possible NULL pointer dereference on line:
auto Loc = D->getBody()->getLocStart();
Value returned by getBody may be NULL. 
In corresponding test it happens during processing the virtual destructor ~A.

(minor)
The variable SkipCoverageMapping in the same function is always false. We can remove it.


https://reviews.llvm.org/D32406

Files:
  lib/CodeGen/CodeGenPGO.cpp
  lib/CodeGen/CodeGenPGO.h
  test/CoverageMapping/empty-destructor.cpp


Index: test/CoverageMapping/empty-destructor.cpp
===================================================================
--- test/CoverageMapping/empty-destructor.cpp
+++ test/CoverageMapping/empty-destructor.cpp
@@ -0,0 +1,23 @@
+// RUN: %clang_cc1 -cc1 -triple i686-pc-windows-msvc19.0.0 -emit-obj -fprofile-instrument=clang -std=c++14 -fdelayed-template-parsing -fcoverage-mapping -dump-coverage-mapping -emit-llvm-only -main-file-name empty-destructor.cpp -o - %s
+
+class A
+{
+public:
+  A();
+  virtual ~A();
+};
+
+class B : public A
+{
+public:
+  B(const A& base)
+    : A(base)
+  {}
+};
+
+void Test()
+{
+  A a;
+  B b(a);
+}
+
Index: lib/CodeGen/CodeGenPGO.h
===================================================================
--- lib/CodeGen/CodeGenPGO.h
+++ lib/CodeGen/CodeGenPGO.h
@@ -40,14 +40,11 @@
   std::unique_ptr<llvm::InstrProfRecord> ProfRecord;
   std::vector<uint64_t> RegionCounts;
   uint64_t CurrentRegionCount;
-  /// \brief A flag that is set to true when this function doesn't need
-  /// to have coverage mapping data.
-  bool SkipCoverageMapping;
 
 public:
   CodeGenPGO(CodeGenModule &CGM)
       : CGM(CGM), NumValueSites({{0}}), NumRegionCounters(0),
-        FunctionHash(0), CurrentRegionCount(0), SkipCoverageMapping(false) {}
+        FunctionHash(0), CurrentRegionCount(0) {}
 
   /// Whether or not we have PGO region data for the current function. This is
   /// false both when we have no data at all and when our data has been
Index: lib/CodeGen/CodeGenPGO.cpp
===================================================================
--- lib/CodeGen/CodeGenPGO.cpp
+++ lib/CodeGen/CodeGenPGO.cpp
@@ -666,7 +666,7 @@
 }
 
 bool CodeGenPGO::skipRegionMappingForDecl(const Decl *D) {
-  if (SkipCoverageMapping)
+  if (!D->hasBody())
     return true;
 
   // Don't map the functions in system headers.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D32406.96321.patch
Type: text/x-patch
Size: 1841 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170423/11047e84/attachment.bin>


More information about the cfe-commits mailing list