[PATCH] D105146: OpaquePtr: Support i32** with --force-opaque-pointers
Duncan P. N. Exon Smith via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 29 12:57:28 PDT 2021
dexonsmith created this revision.
dexonsmith added a reviewer: opaque-pointers.
Herald added subscribers: ormris, hiraditya.
dexonsmith requested review of this revision.
Herald added a project: LLVM.
4506f614cb6983a16d117cf77a968608e66d7a5c <https://reviews.llvm.org/rG4506f614cb6983a16d117cf77a968608e66d7a5c> fixed parsing of textual IR to
reject `ptr*`, but inadvertently broke the auto-conversion of `i32**` to
`ptr` with `--force-opaque-pointers`. Get that working again (and add a
test), refactoring LLParser::parseType a little along the way to clarify
the `addrspace` logic.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D105146
Files:
llvm/lib/AsmParser/LLParser.cpp
llvm/test/Other/force-opaque-ptrs.ll
Index: llvm/test/Other/force-opaque-ptrs.ll
===================================================================
--- llvm/test/Other/force-opaque-ptrs.ll
+++ llvm/test/Other/force-opaque-ptrs.ll
@@ -32,3 +32,9 @@
@g.fwd = global i32 0
declare void @fn.fwd(i32)
+
+define void @f2(i32** %p) {
+; CHECK-LABEL: define {{[^@]+}}@f2(
+; CHECK-SAME: ptr {{%.*}}) {
+ unreachable
+}
Index: llvm/lib/AsmParser/LLParser.cpp
===================================================================
--- llvm/lib/AsmParser/LLParser.cpp
+++ llvm/lib/AsmParser/LLParser.cpp
@@ -2586,14 +2586,10 @@
}
}
- if (Result->isOpaquePointerTy()) {
- unsigned AddrSpace;
- if (parseOptionalAddrSpace(AddrSpace))
- return true;
- Result = PointerType::get(getContext(), AddrSpace);
- }
-
- // parse the type suffixes.
+ // Parse the type suffixes. Opaque pointers spelled as 'ptr' should not end
+ // with a '*', but need to check the flag before the loop to support
+ // '--force-opaque-pointers'.
+ bool IsSpelledPtr = Result->isOpaquePointerTy();
while (true) {
switch (Lex.getKind()) {
// End of type.
@@ -2608,7 +2604,7 @@
return tokError("basic block pointers are invalid");
if (Result->isVoidTy())
return tokError("pointers to void are invalid - use i8* instead");
- if (Result->isOpaquePointerTy())
+ if (IsSpelledPtr)
return tokError("ptr* is invalid - use ptr instead");
if (!PointerType::isValidElementType(Result))
return tokError("pointer to this type is invalid");
@@ -2625,7 +2621,9 @@
if (!PointerType::isValidElementType(Result))
return tokError("pointer to this type is invalid");
unsigned AddrSpace;
- if (parseOptionalAddrSpace(AddrSpace) ||
+ if (parseOptionalAddrSpace(AddrSpace))
+ return true;
+ if (!IsSpelledPtr &&
parseToken(lltok::star, "expected '*' in address space"))
return true;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105146.355340.patch
Type: text/x-patch
Size: 1955 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210629/5f46cb1f/attachment.bin>
More information about the llvm-commits
mailing list