[PATCH] D105653: [IR] Don't accept nullptr as GEP element type
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 8 12:48:11 PDT 2021
nikic created this revision.
nikic added a reviewer: opaque-pointers.
Herald added a subscriber: dexonsmith.
nikic requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
`GetElementPtrInst::Create()` (and IRBuilder methods based on it) currently accept `nullptr` as the element type, and will fetch the element type from the pointer in that case. Remove this fallback, as it is incompatible with opaque pointers. I've removed a handful of leftover calls using this behavior as a preliminary step.
Out-of-tree code affected by this change should either pass a proper type, or can temporarily explicitly call getPointerElementType(), if the newly added assertion is encountered.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D105653
Files:
llvm/include/llvm/IR/Instructions.h
Index: llvm/include/llvm/IR/Instructions.h
===================================================================
--- llvm/include/llvm/IR/Instructions.h
+++ llvm/include/llvm/IR/Instructions.h
@@ -956,13 +956,9 @@
const Twine &NameStr = "",
Instruction *InsertBefore = nullptr) {
unsigned Values = 1 + unsigned(IdxList.size());
- if (!PointeeType) {
- PointeeType =
- cast<PointerType>(Ptr->getType()->getScalarType())->getElementType();
- } else {
- assert(cast<PointerType>(Ptr->getType()->getScalarType())
- ->isOpaqueOrPointeeTypeMatches(PointeeType));
- }
+ assert(PointeeType && "Must specify element type");
+ assert(cast<PointerType>(Ptr->getType()->getScalarType())
+ ->isOpaqueOrPointeeTypeMatches(PointeeType));
return new (Values) GetElementPtrInst(PointeeType, Ptr, IdxList, Values,
NameStr, InsertBefore);
}
@@ -972,13 +968,9 @@
const Twine &NameStr,
BasicBlock *InsertAtEnd) {
unsigned Values = 1 + unsigned(IdxList.size());
- if (!PointeeType) {
- PointeeType =
- cast<PointerType>(Ptr->getType()->getScalarType())->getElementType();
- } else {
- assert(cast<PointerType>(Ptr->getType()->getScalarType())
- ->isOpaqueOrPointeeTypeMatches(PointeeType));
- }
+ assert(PointeeType && "Must specify element type");
+ assert(cast<PointerType>(Ptr->getType()->getScalarType())
+ ->isOpaqueOrPointeeTypeMatches(PointeeType));
return new (Values) GetElementPtrInst(PointeeType, Ptr, IdxList, Values,
NameStr, InsertAtEnd);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105653.357321.patch
Type: text/x-patch
Size: 1815 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210708/3fb2c4b9/attachment.bin>
More information about the llvm-commits
mailing list