Fix for a dangling point bug in DeadStoreElimination pass
authorAnkit <quic_aankit@quicinc.com>
Fri, 3 Jan 2020 14:13:55 +0000 (14:13 +0000)
committerFlorian Hahn <flo@fhahn.com>
Fri, 3 Jan 2020 14:28:44 +0000 (14:28 +0000)
commit369a919514403196dcff7b6bdfa0668dcc733fee
tree06951e21e45fefa04977c0be047611d11153f4ca
parent164058274364670c8b59055b4689ae7e1720268e
Fix for a dangling point bug in DeadStoreElimination pass

The patch makes sure that the LastThrowing pointer does not point to any instruction deleted by call to DeleteDeadInstruction.

While iterating through the instructions the pass maintains a pointer to the lastThrowing Instruction. A call to deleteDeadInstruction deletes a dead store and other instructions feeding the original dead instruction which also become dead. The instruction pointed by the lastThrowing pointer could also be deleted by the call to DeleteDeadInstruction and thus it becomes a dangling pointer. Because of this, we see an error in the next iteration.

In the patch, we maintain a list of throwing instructions encountered previously and use the last non deleted throwing instruction from the container.

Reviewers: fhahn, bcahoon, efriedma

Reviewed By: fhahn

Differential Revision: https://reviews.llvm.org/D65326
llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp
llvm/test/Transforms/DeadStoreElimination/DeleteThrowableInst.ll [new file with mode: 0644]