[PATCH] D44817: Fix a block color copying problem in LICM

Andy Kaylor via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 22 21:40:47 PDT 2018


andrew.w.kaylor created this revision.
andrew.w.kaylor added reviewers: junbuml, rnk.

This fixes a problem in LICM where copying the ColorVector in SafetyInfo::BlockColors from one block to another can cause a crash if creating the new entry forces the map to be re-allocated. I have seen this problem occur in a real-world situation, but I don't have a small reproducer.


Repository:
  rL LLVM

https://reviews.llvm.org/D44817

Files:
  lib/Transforms/Scalar/LICM.cpp


Index: lib/Transforms/Scalar/LICM.cpp
===================================================================
--- lib/Transforms/Scalar/LICM.cpp
+++ lib/Transforms/Scalar/LICM.cpp
@@ -893,8 +893,14 @@
       // Since we do not allow splitting EH-block with BlockColors in
       // canSplitPredecessors(), we can simply assign predecessor's color to
       // the new block.
-      if (!BlockColors.empty())
-        BlockColors[NewPred] = BlockColors[PredBB];
+      if (!BlockColors.empty()) {
+        // Grab a reference to the ColorVector to be inserted before getting the
+        // reference to the vector we are copying because inserting the new
+        // element in BlockColors might cause the map to be reallocated.
+        ColorVector &ColorsForNewBlock = BlockColors[NewPred];
+        ColorVector &ColorsForOldBlock = BlockColors[PredBB];
+        ColorsForNewBlock = ColorsForOldBlock;
+      }
     }
     PredBBs.remove(PredBB);
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44817.139558.patch
Type: text/x-patch
Size: 950 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180323/09193589/attachment.bin>


More information about the llvm-commits mailing list