|
| 1 | +From 381054a989ebd0b585fee46f2a01a7c5de10acf7 Mon Sep 17 00:00:00 2001 |
| 2 | +From: Roman Lebedev < [email protected]> |
| 3 | +Date: Wed, 24 Jun 2020 21:12:09 +0300 |
| 4 | +Subject: [PATCH] [InstCombine] visitBitCast(): do not crash on weird `bitcast |
| 5 | + <1 x i8*> to i8*` |
| 6 | + |
| 7 | +Even if we know that RHS of a bitcast is a pointer, |
| 8 | +we can't assume LHS is, because it might be |
| 9 | +a single-element vector of pointer. |
| 10 | +--- |
| 11 | + lib/Transforms/InstCombine/InstCombineCasts.cpp | 3 ++- |
| 12 | + test/Transforms/InstCombine/bitcast.ll | 6 ++++++ |
| 13 | + 2 files changed, 8 insertions(+), 1 deletion(-) |
| 14 | + |
| 15 | +diff --git a/lib/Transforms/InstCombine/InstCombineCasts.cpp b/lib/Transforms/InstCombine/InstCombineCasts.cpp |
| 16 | +index 3750f31e3cf..a8c87ea3558 100644 |
| 17 | +--- a/lib/Transforms/InstCombine/InstCombineCasts.cpp |
| 18 | ++++ b/lib/Transforms/InstCombine/InstCombineCasts.cpp |
| 19 | +@@ -2471,8 +2471,9 @@ Instruction *InstCombiner::visitBitCast(BitCastInst &CI) { |
| 20 | + if (DestTy == Src->getType()) |
| 21 | + return replaceInstUsesWith(CI, Src); |
| 22 | + |
| 23 | +- if (PointerType *DstPTy = dyn_cast<PointerType>(DestTy)) { |
| 24 | ++ if (isa<PointerType>(SrcTy) && isa<PointerType>(DestTy)) { |
| 25 | + PointerType *SrcPTy = cast<PointerType>(SrcTy); |
| 26 | ++ PointerType *DstPTy = cast<PointerType>(DestTy); |
| 27 | + Type *DstElTy = DstPTy->getElementType(); |
| 28 | + Type *SrcElTy = SrcPTy->getElementType(); |
| 29 | + |
| 30 | +diff --git a/test/Transforms/InstCombine/bitcast.ll b/test/Transforms/InstCombine/bitcast.ll |
| 31 | +index 0f0cbdb364a..c4ee52f27a8 100644 |
| 32 | +--- a/test/Transforms/InstCombine/bitcast.ll |
| 33 | ++++ b/test/Transforms/InstCombine/bitcast.ll |
| 34 | +@@ -561,3 +561,9 @@ define void @constant_fold_vector_to_half() { |
| 35 | + store volatile half bitcast (<4 x i4> <i4 0, i4 0, i4 0, i4 4> to half), half* undef |
| 36 | + ret void |
| 37 | + } |
| 38 | ++ |
| 39 | ++; Ensure that we do not crash when looking at such a weird bitcast. |
| 40 | ++define i8* @bitcast_from_single_element_pointer_vector_to_pointer(<1 x i8*> %ptrvec) { |
| 41 | ++ %ptr = bitcast <1 x i8*> %ptrvec to i8* |
| 42 | ++ ret i8* %ptr |
| 43 | ++} |
| 44 | +-- |
| 45 | +2.17.1 |
| 46 | + |
0 commit comments