[IR] Fix replaceUsesWithIf ponetial issue with constants
authorStanislav Mekhanoshin <Stanislav.Mekhanoshin@amd.com>
Mon, 28 Jun 2021 20:37:45 +0000 (13:37 -0700)
committerStanislav Mekhanoshin <Stanislav.Mekhanoshin@amd.com>
Mon, 28 Jun 2021 22:55:55 +0000 (15:55 -0700)
commitb608053efb88378900d0f08148662e433aa609db
tree8e4342c43677390c2527df21d1e32dcb8331e716
parentaaad46e6f5f7a16bc6be278d92671f8334156d3a
[IR] Fix replaceUsesWithIf ponetial issue with constants

There can be a use after free in the Value::replaceUsesWithIf()
if two uses point to the same constant. Patch defers handling
of the constants past the iterator scan.

Another potential issue is that handleOperandChange updates all
the uses in a given Constant, not just the one passed to
ShouldReplace. Added a FIXME comment.

Both issues are not currently exploitable as the only use of
this call with constants avoids it.

Differential Revision: https://reviews.llvm.org/D105061
llvm/lib/IR/Value.cpp