IR: Update references to temporaries before deleting
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Thu, 22 Jan 2015 21:36:45 +0000 (21:36 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Thu, 22 Jan 2015 21:36:45 +0000 (21:36 +0000)
commit003346177cff3ac5c6f533cbd41a186980116571
tree9f30ec0d7cea185145ed90b8b034a26ffae85cdd
parent40a218658ae01a78f1a5954390610644efcaa90b
IR: Update references to temporaries before deleting

During `MDNode::deleteTemporary()`, call `replaceAllUsesWith(nullptr)`
to update all tracking references to `nullptr`.

This fixes PR22280, where inverted destruction order between tracking
references and the temporaries themselves caused a use-after-free in
`LLParser`.

An alternative fix would be to add an assertion that there are no users,
and continue to fix inverted destruction order in clients (like
`LLParser`), but instead I decided to make getting-teardown-right easy.
(If someone disagrees let me know.)

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@226866 91177308-0d34-0410-b5e6-96231b3b80d8
include/llvm/IR/Metadata.h
lib/IR/Metadata.cpp
test/Assembler/invalid-mdnode-badref.ll [new file with mode: 0644]
unittests/IR/MetadataTest.cpp