Skip to content

Commit

Permalink
Reapply [IR] Don't accept nullptr as GEP element type
Browse files Browse the repository at this point in the history
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
  • Loading branch information
nikic committed Jul 9, 2021
1 parent c476566 commit b00cff5
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions llvm/include/llvm/IR/Instructions.h
Original file line number Diff line number Diff line change
Expand Up @@ -956,13 +956,9 @@ class GetElementPtrInst : public Instruction {
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);
}
Expand All @@ -972,13 +968,9 @@ class GetElementPtrInst : public Instruction {
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);
}
Expand Down

0 comments on commit b00cff5

Please sign in to comment.