Debian Codegraph @

external/llvm/releases/10.0.0/patches_external/InstCombine-visitBitCast-do-not-crash-on-weird-bitca.patch

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