[PATCH] D102744: [OpaquePtr] Make GEPs work with opaque pointers
Arthur Eubanks via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue May 18 20:41:10 PDT 2021
aeubanks created this revision.
aeubanks added a reviewer: dblaikie.
Herald added subscribers: dexonsmith, hiraditya.
aeubanks requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
No verifier changes needed, the verifier currently doesn't check that
the pointer operand's pointee type matches the GEP type. There is a
similar check in GetElementPtrInst::Create() though.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D102744
Files:
llvm/include/llvm/IR/Instructions.h
llvm/lib/AsmParser/LLParser.cpp
llvm/lib/Bitcode/Reader/BitcodeReader.cpp
llvm/test/Assembler/opaque-ptr.ll
Index: llvm/test/Assembler/opaque-ptr.ll
===================================================================
--- llvm/test/Assembler/opaque-ptr.ll
+++ llvm/test/Assembler/opaque-ptr.ll
@@ -40,3 +40,11 @@
store i32 %i, ptr %a
ret void
}
+
+; CHECK: define void @gep(ptr %a)
+; CHECK: %b = getelementptr i8, ptr %a, i32 2
+; CHECK: ret void
+define void @gep(ptr %a) {
+ %b = getelementptr i8, ptr %a, i32 2
+ ret void
+}
Index: llvm/lib/Bitcode/Reader/BitcodeReader.cpp
===================================================================
--- llvm/lib/Bitcode/Reader/BitcodeReader.cpp
+++ llvm/lib/Bitcode/Reader/BitcodeReader.cpp
@@ -4168,7 +4168,8 @@
if (!Ty) {
std::tie(FullTy, Ty) =
getPointerElementTypes(FullBaseTy->getScalarType());
- } else if (Ty != getPointerElementFlatType(FullBaseTy->getScalarType()))
+ } else if (!cast<PointerType>(FullBaseTy->getScalarType())
+ ->isOpaqueOrPointeeTypeMatches(Ty))
return error(
"Explicit gep type does not match pointee type of pointer operand");
Index: llvm/lib/AsmParser/LLParser.cpp
===================================================================
--- llvm/lib/AsmParser/LLParser.cpp
+++ llvm/lib/AsmParser/LLParser.cpp
@@ -7741,7 +7741,7 @@
if (!BasePointerType)
return error(Loc, "base of getelementptr must be a pointer");
- if (Ty != BasePointerType->getElementType()) {
+ if (!BasePointerType->isOpaqueOrPointeeTypeMatches(Ty)) {
return error(
ExplicitTypeLoc,
typeComparisonErrorMessage(
Index: llvm/include/llvm/IR/Instructions.h
===================================================================
--- llvm/include/llvm/IR/Instructions.h
+++ llvm/include/llvm/IR/Instructions.h
@@ -933,13 +933,14 @@
const Twine &NameStr = "",
Instruction *InsertBefore = nullptr) {
unsigned Values = 1 + unsigned(IdxList.size());
- if (!PointeeType)
+ if (!PointeeType) {
PointeeType =
cast<PointerType>(Ptr->getType()->getScalarType())->getElementType();
- else
- assert(
- PointeeType ==
- cast<PointerType>(Ptr->getType()->getScalarType())->getElementType());
+ } else {
+ assert(cast<PointerType>(Ptr->getType()->getScalarType())->isOpaque() ||
+ PointeeType == cast<PointerType>(Ptr->getType()->getScalarType())
+ ->getElementType());
+ }
return new (Values) GetElementPtrInst(PointeeType, Ptr, IdxList, Values,
NameStr, InsertBefore);
}
@@ -949,13 +950,14 @@
const Twine &NameStr,
BasicBlock *InsertAtEnd) {
unsigned Values = 1 + unsigned(IdxList.size());
- if (!PointeeType)
+ if (!PointeeType) {
PointeeType =
cast<PointerType>(Ptr->getType()->getScalarType())->getElementType();
- else
- assert(
- PointeeType ==
- cast<PointerType>(Ptr->getType()->getScalarType())->getElementType());
+ } else {
+ assert(cast<PointerType>(Ptr->getType()->getScalarType())->isOpaque() ||
+ PointeeType == cast<PointerType>(Ptr->getType()->getScalarType())
+ ->getElementType());
+ }
return new (Values) GetElementPtrInst(PointeeType, Ptr, IdxList, Values,
NameStr, InsertAtEnd);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102744.346331.patch
Type: text/x-patch
Size: 3527 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210519/d34c990f/attachment.bin>
More information about the llvm-commits
mailing list