From 4c131387c3104dcac8b16c65ac8ef867bfc26e67 Mon Sep 17 00:00:00 2001 From: Nick Lewycky Date: Tue, 27 Dec 2011 01:17:40 +0000 Subject: [PATCH] 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). llvm-svn: 147285 --- llvm/lib/VMCore/Metadata.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/llvm/lib/VMCore/Metadata.cpp b/llvm/lib/VMCore/Metadata.cpp index 99664334962a..993df41b469a 100644 --- a/llvm/lib/VMCore/Metadata.cpp +++ b/llvm/lib/VMCore/Metadata.cpp @@ -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.