Skip to content

Commit

Permalink
Using Inst->setMetadata(..., NULL) should be safe to remove metadata …
Browse files Browse the repository at this point in the history
…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).


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@147285 91177308-0d34-0410-b5e6-96231b3b80d8
  • Loading branch information
nlewycky committed Dec 27, 2011
1 parent 125ef76 commit da32cc6
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions lib/VMCore/Metadata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit da32cc6

Please sign in to comment.