[CodeGenPrepare] Fix use-after-free
authorSanjay Patel <spatel@rotateright.com>
Fri, 16 Aug 2019 23:10:34 +0000 (23:10 +0000)
committerSanjay Patel <spatel@rotateright.com>
Fri, 16 Aug 2019 23:10:34 +0000 (23:10 +0000)
commitacceedb15f52108d0e36d8090cb25fcdf34a4fc1
treed475e828247adce17001494417c71a00f4996c61
parentd0797ece4641580d0c2c4a60ff3d6696b657a2e5
[CodeGenPrepare] Fix use-after-free

If OptimizeExtractBits() encountered a shift instruction with no operands at all,
it would erase the instruction, but still return false.

This previously didn’t matter because its caller would always return after
processing the instruction, but https://reviews.llvm.org/D63233 changed the
function’s caller to fall through if it returned false, which would then cause
a use-after-free detectable by ASAN.

This change makes OptimizeExtractBits return true if it removes a shift
instruction with no users, terminating processing of the instruction.

Patch by: @brentdax (Brent Royal-Gordon)

Differential Revision: https://reviews.llvm.org/D66330

llvm-svn: 369168
llvm/lib/CodeGen/CodeGenPrepare.cpp
llvm/test/Transforms/CodeGenPrepare/sink-shift-and-trunc.ll