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
This commit is contained in:
Nick Lewycky 2011-12-27 01:17:40 +00:00
parent 2b14b80b60
commit 4c131387c3
1 changed files with 4 additions and 2 deletions

View 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.