[InstCombine] avoid crash from deleting an instruction that still has uses (PR43723...
authorSanjay Patel <spatel@rotateright.com>
Sun, 10 Nov 2019 22:24:48 +0000 (17:24 -0500)
committerSanjay Patel <spatel@rotateright.com>
Sun, 10 Nov 2019 22:26:36 +0000 (17:26 -0500)
commit56b2aee1875a1ee47ddf859a6584f8728787fb7b
treee202d5463f8a4cb63ed08a493fe861952248e9ff
parentc250ebf7bcaa85f5366c651c2efdda828258cb27
[InstCombine] avoid crash from deleting an instruction that still has uses (PR43723) (2nd try)

Re-try rGef02831f0a4e (reverted due to use-after-free), but bail out completely
if we encounter an unexpected llvm.invariant.start.

We gather a set of white-listed instructions in isAllocSiteRemovable() and then
replace/erase them. But we don't know in general if the instructions in the set
have uses amongst themselves, so order of deletion makes a difference.

There's already a special-case for the llvm.objectsize intrinsic, so add another
for llvm.invariant.end.

Should fix:
https://bugs.llvm.org/show_bug.cgi?id=43723

Differential Revision: https://reviews.llvm.org/D69977
llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
llvm/test/Transforms/InstCombine/builtin-object-size-ptr.ll