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

Nick Lewycky nicholas at mxc.ca
Mon Dec 26 17:17:40 PST 2011


Author: nicholas
Date: Mon Dec 26 19:17:40 2011
New Revision: 147285

URL: http://llvm.org/viewvc/llvm-project?rev=147285&view=rev
Log:
Using Inst->setMetadata(..., NULL) should be safe to remove metadata even when
there is non of that type to remove. This fixes a crasher in the particular
case where the instruction has metadata but no metadata storage in the context
(this is only possible if the instruction has !dbg but no other metadata info).

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=147285&r1=147284&r2=147285&view=diff
==============================================================================
--- llvm/trunk/lib/VMCore/Metadata.cpp (original)
+++ llvm/trunk/lib/VMCore/Metadata.cpp Mon Dec 26 19:17:40 2011
@@ -470,9 +470,11 @@
   }
 
   // Otherwise, we're removing metadata from an instruction.
-  assert(hasMetadataHashEntry() &&
-         getContext().pImpl->MetadataStore.count(this) &&
+  assert((hasMetadataHashEntry() ==
+          getContext().pImpl->MetadataStore.count(this)) &&
          "HasMetadata bit out of date!");
+  if (!hasMetadataHashEntry())
+    return;  // Nothing to remove!
   LLVMContextImpl::MDMapTy &Info = getContext().pImpl->MetadataStore[this];
 
   // Common case is removing the only entry.





More information about the llvm-commits mailing list