Using Inst->setMetadata(..., NULL) should be safe to remove metadata even when
authorNick Lewycky <nicholas@mxc.ca>
Tue, 27 Dec 2011 01:17:40 +0000 (01:17 +0000)
committerNick Lewycky <nicholas@mxc.ca>
Tue, 27 Dec 2011 01:17:40 +0000 (01:17 +0000)
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).

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

lib/VMCore/Metadata.cpp

index 99664334962a011f1947c014cbd89d687225de4b..993df41b469a627d065f50854b9491692c54b1d2 100644 (file)
@@ -470,9 +470,11 @@ void Instruction::setMetadata(unsigned KindID, MDNode *Node) {
   }
 
   // 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.