[llvm] r223849 - IR: Metadata: Detect an RAUW recursion

Duncan P. N. Exon Smith dexonsmith at apple.com
Tue Dec 9 15:04:59 PST 2014


Author: dexonsmith
Date: Tue Dec  9 17:04:59 2014
New Revision: 223849

URL: http://llvm.org/viewvc/llvm-project?rev=223849&view=rev
Log:
IR: Metadata: Detect an RAUW recursion

Speculatively handle a recursion in
`GenericMDNode::handleChangedOperand()`.  I'm hoping this fixes the
failing hexagon bot [1].

[1]: http://lab.llvm.org:8011/builders/llvm-hexagon-elf/builds/13434

Modified:
    llvm/trunk/include/llvm/IR/Metadata.h
    llvm/trunk/lib/IR/Metadata.cpp

Modified: llvm/trunk/include/llvm/IR/Metadata.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Metadata.h?rev=223849&r1=223848&r2=223849&view=diff
==============================================================================
--- llvm/trunk/include/llvm/IR/Metadata.h (original)
+++ llvm/trunk/include/llvm/IR/Metadata.h Tue Dec  9 17:04:59 2014
@@ -49,6 +49,7 @@ class Metadata {
 protected:
   /// \brief Storage flag for non-uniqued, otherwise unowned, metadata.
   bool IsDistinctInContext : 1;
+  bool InRAUW : 1;
   // TODO: expose remaining bits to subclasses.
 
   unsigned short SubclassData16;
@@ -65,8 +66,8 @@ public:
 
 protected:
   Metadata(unsigned ID)
-      : SubclassID(ID), IsDistinctInContext(false), SubclassData16(0),
-        SubclassData32(0) {}
+      : SubclassID(ID), IsDistinctInContext(false), InRAUW(false),
+        SubclassData16(0), SubclassData32(0) {}
   ~Metadata() {}
 
   /// \brief Store this in a big non-uniqued untyped bucket.

Modified: llvm/trunk/lib/IR/Metadata.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/IR/Metadata.cpp?rev=223849&r1=223848&r2=223849&view=diff
==============================================================================
--- llvm/trunk/lib/IR/Metadata.cpp (original)
+++ llvm/trunk/lib/IR/Metadata.cpp Tue Dec  9 17:04:59 2014
@@ -495,6 +495,14 @@ void GenericMDNode::handleChangedOperand
     setOperand(Op, New);
     return;
   }
+  if (InRAUW) {
+    // We just hit a recursion due to RAUW.  Set the operand and move on, since
+    // we're about to be deleted.
+    //
+    // FIXME: Can this cycle really happen?
+    setOperand(Op, New);
+    return;
+  }
 
   auto &Store = getContext().pImpl->MDNodeSet;
   Store.erase(this);
@@ -550,6 +558,7 @@ void GenericMDNode::handleChangedOperand
   // Collision.
   if (!isResolved()) {
     // Still unresolved, so RAUW.
+    InRAUW = true;
     ReplaceableUses->replaceAllUsesWith(*I);
     delete this;
     return;





More information about the llvm-commits mailing list