[llvm] b00cff5 - Reapply [IR] Don't accept nullptr as GEP element type
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Jul 9 12:14:52 PDT 2021
Author: Nikita Popov
Date: 2021-07-09T21:14:41+02:00
New Revision: b00cff56cfb15cbfa74cb512c9cee1c402cce55b
URL: https://github.com/llvm/llvm-project/commit/b00cff56cfb15cbfa74cb512c9cee1c402cce55b
DIFF: https://github.com/llvm/llvm-project/commit/b00cff56cfb15cbfa74cb512c9cee1c402cce55b.diff
LOG: 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
Added:
Modified:
llvm/include/llvm/IR/Instructions.h
Removed:
################################################################################
diff --git a/llvm/include/llvm/IR/Instructions.h b/llvm/include/llvm/IR/Instructions.h
index a5cebf0a4626..0c43a56daa33 100644
--- a/llvm/include/llvm/IR/Instructions.h
+++ b/llvm/include/llvm/IR/Instructions.h
@@ -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);
}
@@ -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);
}
More information about the llvm-commits
mailing list