Debian Codegraph @

external/llvm/releases/9.0.0/patches_external/IR-GetUnderlyingObject-stripPointerCastsAndOffsets-d.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 6ed8606c9b1c6d4150225da3da6399bcc9b749f8 Mon Sep 17 00:00:00 2001
10 From: Roman Lebedev <[email protected]>
11 Date: Fri, 28 Jan 2022 20:33:41 +0300
12 Subject: [PATCH] [PATCH] [IR] GetUnderlyingObject(), stripPointerCastsAndOffsets():
13 don't crash on `bitcast <1 x i8*> to i8*`
14
15 I'm not sure how to write standalone tests for each of two changes
16 here.
17 If either one of these two fixes is missing, the test fill crash.
18 ---
19 llvm/lib/Analysis/ValueTracking.cpp | 2 ++
20 llvm/lib/IR/Value.cpp | 2 ++
21 llvm/test/Transforms/InstSimplify/icmp.ll | 14 ++++++++++++++
22 3 files changed, 18 insertions(+)
23 create mode 100644 llvm/test/Transforms/InstSimplify/icmp.ll
24
25 diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
26 index c70906dcc629..7ba473527f4e 100644
27 --- a/llvm/lib/Analysis/ValueTracking.cpp
28 +++ b/llvm/lib/Analysis/ValueTracking.cpp
29 @@ -3707,6 +3707,8 @@ Value *llvm::GetUnderlyingObject(Value *V, const DataLayout &DL,
30 } else if (Operator::getOpcode(V) == Instruction::BitCast ||
31 Operator::getOpcode(V) == Instruction::AddrSpaceCast) {
32 V = cast<Operator>(V)->getOperand(0);
33 + if (!V->getType()->isPointerTy())
34 + return V;
35 } else if (GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
36 if (GA->isInterposable())
37 return V;
38 diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp
39 index b7f77dc3043e..e1d24af11d2b 100644
40 --- a/llvm/lib/IR/Value.cpp
41 +++ b/llvm/lib/IR/Value.cpp
42 @@ -498,6 +498,8 @@ static const Value *stripPointerCastsAndOffsets(const Value *V) {
43 V = GEP->getPointerOperand();
44 } else if (Operator::getOpcode(V) == Instruction::BitCast) {
45 V = cast<Operator>(V)->getOperand(0);
46 + if (!V->getType()->isPointerTy())
47 + return V;
48 } else if (StripKind != PSK_ZeroIndicesAndAliasesSameRepresentation &&
49 Operator::getOpcode(V) == Instruction::AddrSpaceCast) {
50 // TODO: If we know an address space cast will not change the
51 diff --git a/llvm/test/Transforms/InstSimplify/icmp.ll b/llvm/test/Transforms/InstSimplify/icmp.ll
52 new file mode 100644
53 index 000000000000..489f73c9495c
54 --- /dev/null
55 +++ b/llvm/test/Transforms/InstSimplify/icmp.ll
56 @@ -0,0 +1,14 @@
57 +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
58 +; RUN: opt < %s -instsimplify -S | FileCheck %s
59 +
60 +target datalayout = "e-p:64:64:64-p1:16:16:16-p2:32:32:32-p3:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64"
61 +
62 +declare void @usei8ptr(i8* %ptr)
63 +
64 +; Ensure that we do not crash when looking at such a weird bitcast.
65 +define i1 @bitcast_from_single_element_pointer_vector_to_pointer(<1 x i8*> %ptr1vec, i8* %ptr2) {
66 + %ptr1 = bitcast <1 x i8*> %ptr1vec to i8*
67 + call void @usei8ptr(i8* %ptr1)
68 + %cmp = icmp eq i8* %ptr1, %ptr2
69 + ret i1 %cmp
70 +}
71 --
72 2.25.1
73