Skip to content

Commit

Permalink
Fix use-after-free error.
Browse files Browse the repository at this point in the history
We were looking up Op->getUser() after we removed the user. Put in a continue to
fix the issue.

I am going to clean up this code path in a subsequent commit.
  • Loading branch information
gottesmm committed Nov 15, 2015
1 parent 0e55301 commit aedd6c0
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions lib/SILPasses/SILCombiner/SILCombinerMiscVisitors.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -255,20 +255,25 @@ SILInstruction *SILCombiner::visitAllocStackInst(AllocStackInst *AS) {
SILValue(IEI, 0).replaceAllUsesWith(ConcAlloc->getAddressResult());
eraseInstFromFunction(*IEI);


for (Operand *Op: AS->getUses()) {
for (auto UI = AS->use_begin(), UE = AS->use_end(); UI != UE;) {
auto *Op = *UI;
++UI;
if (auto *DA = dyn_cast<DestroyAddrInst>(Op->getUser())) {
Builder.setInsertionPoint(DA);
Builder.createDestroyAddr(DA->getLoc(), SILValue(ConcAlloc, 1))
->setDebugScope(DA->getDebugScope());
eraseInstFromFunction(*DA);
continue;
}
if (auto *DS = dyn_cast<DeallocStackInst>(Op->getUser())) {
Builder.setInsertionPoint(DS);
Builder.createDeallocStack(DS->getLoc(), SILValue(ConcAlloc, 0))

if (!isa<DeallocStackInst>(Op->getUser()))
continue;

auto *DS = cast<DeallocStackInst>(Op->getUser());
Builder.setInsertionPoint(DS);
Builder.createDeallocStack(DS->getLoc(), SILValue(ConcAlloc, 0))
->setDebugScope(DS->getDebugScope());
eraseInstFromFunction(*DS);
}
eraseInstFromFunction(*DS);
}

eraseInstFromFunction(*AS);
Expand Down

0 comments on commit aedd6c0

Please sign in to comment.