archrelease: copy trunk to extra-x86_64
[arch-packages.git] / llvm / trunk / don-t-accept-nullptr-as-GEP-element-type.patch
blob28ab9cbe7e528da257bcd7a07ca9e37571e544ee
1 From b00cff56cfb15cbfa74cb512c9cee1c402cce55b Mon Sep 17 00:00:00 2001
2 From: Nikita Popov <nikita.ppv@gmail.com>
3 Date: Thu, 8 Jul 2021 20:56:05 +0200
4 Subject: [PATCH] Reapply [IR] Don't accept nullptr as GEP element type
6 Reapply after fixing another occurrence in lldb that was relying
7 on this in the preceding commit.
9 -----
11 GetElementPtrInst::Create() (and IRBuilder methods based on it)
12 currently accept nullptr as the element type, and will fetch the
13 element type from the pointer in that case. Remove this fallback,
14 as it is incompatible with opaque pointers. I've removed a handful
15 of leftover calls using this behavior as a preliminary step.
17 Out-of-tree code affected by this change should either pass a proper
18 type, or can temporarily explicitly call getPointerElementType(),
19 if the newly added assertion is encountered.
21 Differential Revision: https://reviews.llvm.org/D105653
22 ---
23 llvm/include/llvm/IR/Instructions.h | 20 ++++++--------------
24 1 file changed, 6 insertions(+), 14 deletions(-)
26 diff --git a/llvm/include/llvm/IR/Instructions.h b/llvm/include/llvm/IR/Instructions.h
27 index a5cebf0a4626..0c43a56daa33 100644
28 --- a/llvm/include/llvm/IR/Instructions.h
29 +++ b/llvm/include/llvm/IR/Instructions.h
30 @@ -956,13 +956,9 @@ public:
31 const Twine &NameStr = "",
32 Instruction *InsertBefore = nullptr) {
33 unsigned Values = 1 + unsigned(IdxList.size());
34 - if (!PointeeType) {
35 - PointeeType =
36 - cast<PointerType>(Ptr->getType()->getScalarType())->getElementType();
37 - } else {
38 - assert(cast<PointerType>(Ptr->getType()->getScalarType())
39 - ->isOpaqueOrPointeeTypeMatches(PointeeType));
40 - }
41 + assert(PointeeType && "Must specify element type");
42 + assert(cast<PointerType>(Ptr->getType()->getScalarType())
43 + ->isOpaqueOrPointeeTypeMatches(PointeeType));
44 return new (Values) GetElementPtrInst(PointeeType, Ptr, IdxList, Values,
45 NameStr, InsertBefore);
47 @@ -972,13 +968,9 @@ public:
48 const Twine &NameStr,
49 BasicBlock *InsertAtEnd) {
50 unsigned Values = 1 + unsigned(IdxList.size());
51 - if (!PointeeType) {
52 - PointeeType =
53 - cast<PointerType>(Ptr->getType()->getScalarType())->getElementType();
54 - } else {
55 - assert(cast<PointerType>(Ptr->getType()->getScalarType())
56 - ->isOpaqueOrPointeeTypeMatches(PointeeType));
57 - }
58 + assert(PointeeType && "Must specify element type");
59 + assert(cast<PointerType>(Ptr->getType()->getScalarType())
60 + ->isOpaqueOrPointeeTypeMatches(PointeeType));
61 return new (Values) GetElementPtrInst(PointeeType, Ptr, IdxList, Values,
62 NameStr, InsertAtEnd);