diff options
author | Sanjay Patel <spatel@rotateright.com> | 2019-08-16 23:10:34 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2019-08-16 23:10:34 +0000 |
commit | acceedb15f52108d0e36d8090cb25fcdf34a4fc1 (patch) | |
tree | d475e828247adce17001494417c71a00f4996c61 /llvm/test/Transforms/CodeGenPrepare | |
parent | d0797ece4641580d0c2c4a60ff3d6696b657a2e5 (diff) | |
download | bcm5719-llvm-acceedb15f52108d0e36d8090cb25fcdf34a4fc1.tar.gz bcm5719-llvm-acceedb15f52108d0e36d8090cb25fcdf34a4fc1.zip |
[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
Diffstat (limited to 'llvm/test/Transforms/CodeGenPrepare')
-rw-r--r-- | llvm/test/Transforms/CodeGenPrepare/sink-shift-and-trunc.ll | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/llvm/test/Transforms/CodeGenPrepare/sink-shift-and-trunc.ll b/llvm/test/Transforms/CodeGenPrepare/sink-shift-and-trunc.ll index 07ea73b5a5b..929a4f43e4a 100644 --- a/llvm/test/Transforms/CodeGenPrepare/sink-shift-and-trunc.ll +++ b/llvm/test/Transforms/CodeGenPrepare/sink-shift-and-trunc.ll @@ -58,6 +58,23 @@ return: ; preds = %if.then17, %if.end1 ret i32 %retval.0, !dbg !63 } +; CodeGenPrepare was erasing the unused lshr instruction, but then further +; processing the instruction after it was freed. If this bug is still present, +; this test will always crash in an LLVM built with ASAN enabled, and may +; crash even if ASAN is not enabled. + +define i32 @shift_unused(i32 %a) { +; CHECK-LABEL: @shift_unused( +; CHECK-NEXT: BB2: +; CHECK-NEXT: ret i32 [[A:%.*]] +; + %as = lshr i32 %a, 3 + br label %BB2 + +BB2: + ret i32 %a +} + ; CHECK: [[shift1_loc]] = !DILocation(line: 1 ; CHECK: [[trunc1_loc]] = !DILocation(line: 2 ; CHECK: [[shift2_loc]] = !DILocation(line: 3 |