[llvm-commits] [llvm] r113828 - /llvm/trunk/lib/VMCore/Metadata.cpp

Dan Gohman gohman at apple.com
Mon Sep 13 18:37:57 PDT 2010


Author: djg
Date: Mon Sep 13 20:37:57 2010
New Revision: 113828

URL: http://llvm.org/viewvc/llvm-project?rev=113828&view=rev
Log:
When a function-local value with function-local metadata uses gets RAUWed with a
non-function-local value, it may result in the metadata no longer needing to be
function-local. Check for this condition, and clear the isFunctionLocal flag, if
it's still in the uniquing map, since any node in the uniquing map needs to have
an accurate function-local flag.

Also, add an assert to help catch problematic cases.

Modified:
    llvm/trunk/lib/VMCore/Metadata.cpp

Modified: llvm/trunk/lib/VMCore/Metadata.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/VMCore/Metadata.cpp?rev=113828&r1=113827&r2=113828&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Metadata.cpp (original)
+++ llvm/trunk/lib/VMCore/Metadata.cpp Mon Sep 13 20:37:57 2010
@@ -354,6 +354,22 @@
 
   // InsertPoint will have been set by the FindNodeOrInsertPos call.
   pImpl->MDNodeSet.InsertNode(this, InsertPoint);
+
+  // If this MDValue was previously function-local but no longer is, clear
+  // its function-local flag.
+  if (isFunctionLocal() && !isFunctionLocalValue(To)) {
+    bool isStillFunctionLocal = false;
+    for (unsigned i = 0, e = getNumOperands(); i != e; ++i) {
+      Value *V = getOperand(i);
+      if (!V) continue;
+      if (isFunctionLocalValue(V)) {
+        isStillFunctionLocal = true;
+        break;
+      }
+    }
+    if (!isStillFunctionLocal)
+      setValueSubclassData(getSubclassDataFromValue() & ~FunctionLocalBit);
+  }
 }
 
 //===----------------------------------------------------------------------===//
@@ -387,6 +403,8 @@
 
 /// addOperand - Add metadata Operand.
 void NamedMDNode::addOperand(MDNode *M) {
+  assert(!M->isFunctionLocal() &&
+         "NamedMDNode operands must not be function-local!");
   getNMDOps(Operands).push_back(TrackingVH<MDNode>(M));
 }
 





More information about the llvm-commits mailing list