diff options
| author | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2016-02-21 19:37:45 +0000 |
|---|---|---|
| committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2016-02-21 19:37:45 +0000 |
| commit | 7b269642d232fadf5f2ce29ddc0fb9106edab8d3 (patch) | |
| tree | 9b04b7a09a2a7ce3959358a5b6fe1216b7fe63b7 /llvm/lib/CodeGen/CodeGenPrepare.cpp | |
| parent | 1b936c0f59b294a3353930a81172728641c4b024 (diff) | |
| download | bcm5719-llvm-7b269642d232fadf5f2ce29ddc0fb9106edab8d3.tar.gz bcm5719-llvm-7b269642d232fadf5f2ce29ddc0fb9106edab8d3.zip | |
CodeGen: Avoid getNodePtrUnchecked() where we need a Value, NFC
`ilist_iterator<NodeTy>::getNodePtrUnchecked()` is documented as being
for internal use only, but CodeGenPrepare was using it anyway. This
code relies on pulling out the `Value*` pointer even after the lifetime
of the iterator is over. But having this pointer available in
ilist_iterator depends on UB in the first place.
Instead, safely pull out the `Value*` when the iterator is alive and
stop using the internal-only API.
There should be no functionality change here.
llvm-svn: 261493
Diffstat (limited to 'llvm/lib/CodeGen/CodeGenPrepare.cpp')
| -rw-r--r-- | llvm/lib/CodeGen/CodeGenPrepare.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/llvm/lib/CodeGen/CodeGenPrepare.cpp b/llvm/lib/CodeGen/CodeGenPrepare.cpp index f8bd3f37203..a4e382d9c85 100644 --- a/llvm/lib/CodeGen/CodeGenPrepare.cpp +++ b/llvm/lib/CodeGen/CodeGenPrepare.cpp @@ -1773,13 +1773,14 @@ bool CodeGenPrepare::optimizeCallInst(CallInst *CI, bool& ModifiedDT) { // Substituting this can cause recursive simplifications, which can // invalidate our iterator. Use a WeakVH to hold onto it in case this // happens. - WeakVH IterHandle(&*CurInstIterator); + Value *CurValue = &*CurInstIterator; + WeakVH IterHandle(CurValue); replaceAndRecursivelySimplify(CI, RetVal, TLInfo, nullptr); // If the iterator instruction was recursively deleted, start over at the // start of the block. - if (IterHandle != CurInstIterator.getNodePtrUnchecked()) { + if (IterHandle != CurValue) { CurInstIterator = BB->begin(); SunkAddrs.clear(); } @@ -3945,12 +3946,13 @@ bool CodeGenPrepare::optimizeMemoryInst(Instruction *MemoryInst, Value *Addr, if (Repl->use_empty()) { // This can cause recursive deletion, which can invalidate our iterator. // Use a WeakVH to hold onto it in case this happens. - WeakVH IterHandle(&*CurInstIterator); + Value *CurValue = &*CurInstIterator; + WeakVH IterHandle(CurValue); BasicBlock *BB = CurInstIterator->getParent(); RecursivelyDeleteTriviallyDeadInstructions(Repl, TLInfo); - if (IterHandle != CurInstIterator.getNodePtrUnchecked()) { + if (IterHandle != CurValue) { // If the iterator instruction was recursively deleted, start over at the // start of the block. CurInstIterator = BB->begin(); |

