]> granicus.if.org Git - llvm/commitdiff
[RegionInfo] Fix dangling references created by moving RegionInfo objects
authorPhilip Pfaffe <philip.pfaffe@gmail.com>
Mon, 24 Apr 2017 11:54:37 +0000 (11:54 +0000)
committerPhilip Pfaffe <philip.pfaffe@gmail.com>
Mon, 24 Apr 2017 11:54:37 +0000 (11:54 +0000)
Summary: Region objects capture the address of the creating RegionInfo instance. Because the RegionInfo class is movable, moving a RegionInfo object creates dangling references. This patch fixes these references by walking the Regions post-move, and updating references to the new parent.

Reviewers: Meinersbur, grosser

Reviewed By: Meinersbur, grosser

Subscribers: llvm-commits

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

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

include/llvm/Analysis/RegionInfo.h

index caeb21db613e7a8c5a0b77af6b110e5abc2d5611..16ee07fa317712d8ec3cf2f2d61e387698b36283 100644 (file)
@@ -708,10 +708,24 @@ class RegionInfoBase {
   /// The top level region.
   RegionT *TopLevelRegion;
 
-private:
   /// Map every BB to the smallest region, that contains BB.
   BBtoRegionMap BBtoRegion;
 
+protected:
+  /// \brief Update refences to a RegionInfoT held by the RegionT managed here
+  ///
+  /// This is a post-move helper. Regions hold references to the owning
+  /// RegionInfo object. After a move these need to be fixed.
+  template<typename TheRegionT>
+  void updateRegionTree(RegionInfoT &RI, TheRegionT *R) {
+    if (!R)
+      return;
+    R->RI = &RI;
+    for (auto &SubR : *R)
+      updateRegionTree(RI, SubR.get());
+  }
+
+private:
   /// \brief Wipe this region tree's state without releasing any resources.
   ///
   /// This is essentially a post-move helper only. It leaves the object in an
@@ -879,10 +893,12 @@ public:
 
   ~RegionInfo() override;
 
-  RegionInfo(RegionInfo &&Arg)
-    : Base(std::move(static_cast<Base &>(Arg))) {}
+  RegionInfo(RegionInfo &&Arg) : Base(std::move(static_cast<Base &>(Arg))) {
+    updateRegionTree(*this, TopLevelRegion);
+  }
   RegionInfo &operator=(RegionInfo &&RHS) {
     Base::operator=(std::move(static_cast<Base &>(RHS)));
+    updateRegionTree(*this, TopLevelRegion);
     return *this;
   }