Debian Codegraph @

external/llvm/releases/10.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 2b8d706b19c0e049da3eb62572b08af72ba2e5e6 Mon Sep 17 00:00:00 2001
10 From: Roman Lebedev <[email protected]>
11 Date: Wed, 24 Jun 2020 21:11:49 +0300
12 Subject: [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 here.
16 If either one of these two fixes is missing, the test fill crash.
17 ---
18 llvm/lib/Analysis/ValueTracking.cpp | 2 ++
19 llvm/lib/IR/Value.cpp | 2 ++
20 llvm/test/Transforms/InstSimplify/icmp.ll | 14 ++++++++++++++
21 3 files changed, 18 insertions(+)
22 create mode 100644 llvm/test/Transforms/InstSimplify/icmp.ll
23
24 diff --git a/llvm/lib/Analysis/ValueTracking.cpp b/llvm/lib/Analysis/ValueTracking.cpp
25 index 927add44dda3..9db6aabc728f 100644
26 --- a/llvm/lib/Analysis/ValueTracking.cpp
27 +++ b/llvm/lib/Analysis/ValueTracking.cpp
28 @@ -4147,6 +4147,8 @@ Value *llvm::GetUnderlyingObject(Value *V, const DataLayout &DL,
29 } else if (Operator::getOpcode(V) == Instruction::BitCast ||
30 Operator::getOpcode(V) == Instruction::AddrSpaceCast) {
31 V = cast<Operator>(V)->getOperand(0);
32 + if (!V->getType()->isPointerTy())
33 + return V;
34 } else if (GlobalAlias *GA = dyn_cast<GlobalAlias>(V)) {
35 if (GA->isInterposable())
36 return V;
37 diff --git a/llvm/lib/IR/Value.cpp b/llvm/lib/IR/Value.cpp
38 index 0fd147c3a44d..e264eb1f7d72 100644
39 --- a/llvm/lib/IR/Value.cpp
40 +++ b/llvm/lib/IR/Value.cpp
41 @@ -552,6 +552,8 @@ static const Value *stripPointerCastsAndOffsets(
42 V = GEP->getPointerOperand();
43 } else if (Operator::getOpcode(V) == Instruction::BitCast) {
44 V = cast<Operator>(V)->getOperand(0);
45 + if (!V->getType()->isPointerTy())
46 + return V;
47 } else if (StripKind != PSK_ZeroIndicesSameRepresentation &&
48 Operator::getOpcode(V) == Instruction::AddrSpaceCast) {
49 // TODO: If we know an address space cast will not change the
50 diff --git a/llvm/test/Transforms/InstSimplify/icmp.ll b/llvm/test/Transforms/InstSimplify/icmp.ll
51 new file mode 100644
52 index 000000000000..489f73c9495c
53 --- /dev/null
54 +++ b/llvm/test/Transforms/InstSimplify/icmp.ll
55 @@ -0,0 +1,14 @@
56 +; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
57 +; RUN: opt < %s -instsimplify -S | FileCheck %s
58 +
59 +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"
60 +
61 +declare void @usei8ptr(i8* %ptr)
62 +
63 +; Ensure that we do not crash when looking at such a weird bitcast.
64 +define i1 @bitcast_from_single_element_pointer_vector_to_pointer(<1 x i8*> %ptr1vec, i8* %ptr2) {
65 + %ptr1 = bitcast <1 x i8*> %ptr1vec to i8*
66 + call void @usei8ptr(i8* %ptr1)
67 + %cmp = icmp eq i8* %ptr1, %ptr2
68 + ret i1 %cmp
69 +}
70 --
71 2.25.1
72