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.
I think you need a TrackingVH here, instead of a raw pointer. Suppose you have something like the following:
ConstantStruct(ConstantStruct(C, C), C)
Say we replaceUsesWithIf on C. Calling handleOperandChange on the inner ConstantStruct will invalidate pointers to the outer CostantStruct. So depending on the use-list order, you might have a dangling pointer.