Skip to content

Commit b00cff5

Browse files
committed
Reapply [IR] Don't accept nullptr as GEP element type
Reapply after fixing another occurrence in lldb that was relying on this in the preceding commit. ----- 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. Differential Revision: https://reviews.llvm.org/D105653
1 parent c476566 commit b00cff5

File tree

1 file changed

+6
-14
lines changed

1 file changed

+6
-14
lines changed

llvm/include/llvm/IR/Instructions.h

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -956,13 +956,9 @@ class GetElementPtrInst : public Instruction {
956956
const Twine &NameStr = "",
957957
Instruction *InsertBefore = nullptr) {
958958
unsigned Values = 1 + unsigned(IdxList.size());
959-
if (!PointeeType) {
960-
PointeeType =
961-
cast<PointerType>(Ptr->getType()->getScalarType())->getElementType();
962-
} else {
963-
assert(cast<PointerType>(Ptr->getType()->getScalarType())
964-
->isOpaqueOrPointeeTypeMatches(PointeeType));
965-
}
959+
assert(PointeeType && "Must specify element type");
960+
assert(cast<PointerType>(Ptr->getType()->getScalarType())
961+
->isOpaqueOrPointeeTypeMatches(PointeeType));
966962
return new (Values) GetElementPtrInst(PointeeType, Ptr, IdxList, Values,
967963
NameStr, InsertBefore);
968964
}
@@ -972,13 +968,9 @@ class GetElementPtrInst : public Instruction {
972968
const Twine &NameStr,
973969
BasicBlock *InsertAtEnd) {
974970
unsigned Values = 1 + unsigned(IdxList.size());
975-
if (!PointeeType) {
976-
PointeeType =
977-
cast<PointerType>(Ptr->getType()->getScalarType())->getElementType();
978-
} else {
979-
assert(cast<PointerType>(Ptr->getType()->getScalarType())
980-
->isOpaqueOrPointeeTypeMatches(PointeeType));
981-
}
971+
assert(PointeeType && "Must specify element type");
972+
assert(cast<PointerType>(Ptr->getType()->getScalarType())
973+
->isOpaqueOrPointeeTypeMatches(PointeeType));
982974
return new (Values) GetElementPtrInst(PointeeType, Ptr, IdxList, Values,
983975
NameStr, InsertAtEnd);
984976
}

0 commit comments

Comments
 (0)