[llvm] 881677b - [AsmParser] Support %ty* in force-opaque-pointers mode
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 30 10:05:08 PDT 2021
Author: Nikita Popov
Date: 2021-08-30T19:05:00+02:00
New Revision: 881677b58a1f88076fccee5f32152d981de66b74
URL: https://github.com/llvm/llvm-project/commit/881677b58a1f88076fccee5f32152d981de66b74
DIFF: https://github.com/llvm/llvm-project/commit/881677b58a1f88076fccee5f32152d981de66b74.diff
LOG: [AsmParser] Support %ty* in force-opaque-pointers mode
Only enforce that ptr* is illegal if the base type is a simple type,
not when it is something like %ty, where %ty may resolve to an
opaque pointer in force-opaque-pointers mode.
Differential Revision: https://reviews.llvm.org/D108876
Added:
Modified:
llvm/lib/AsmParser/LLParser.cpp
llvm/test/Other/force-opaque-ptrs.ll
Removed:
################################################################################
diff --git a/llvm/lib/AsmParser/LLParser.cpp b/llvm/lib/AsmParser/LLParser.cpp
index 62c72533398e4..cfa62407c6955 100644
--- a/llvm/lib/AsmParser/LLParser.cpp
+++ b/llvm/lib/AsmParser/LLParser.cpp
@@ -2217,6 +2217,26 @@ bool LLParser::parseType(Type *&Result, const Twine &Msg, bool AllowVoid) {
// Type ::= 'float' | 'void' (etc)
Result = Lex.getTyVal();
Lex.Lex();
+
+ // Handle (explicit) opaque pointer types (not --force-opaque-pointers).
+ //
+ // Type ::= ptr ('addrspace' '(' uint32 ')')?
+ if (Result->isOpaquePointerTy()) {
+ unsigned AddrSpace;
+ if (parseOptionalAddrSpace(AddrSpace))
+ return true;
+ Result = PointerType::get(getContext(), AddrSpace);
+
+ // Give a nice error for 'ptr*'.
+ if (Lex.getKind() == lltok::star)
+ return tokError("ptr* is invalid - use ptr instead");
+
+ // Fall through to parsing the type suffixes only if this 'ptr' is a
+ // function return. Otherwise, return success, implicitly rejecting other
+ // suffixes.
+ if (Lex.getKind() != lltok::lparen)
+ return false;
+ }
break;
case lltok::lbrace:
// Type ::= StructType
@@ -2270,26 +2290,6 @@ bool LLParser::parseType(Type *&Result, const Twine &Msg, bool AllowVoid) {
}
}
- // Handle (explicit) opaque pointer types (not --force-opaque-pointers).
- //
- // Type ::= ptr ('addrspace' '(' uint32 ')')?
- if (Result->isOpaquePointerTy()) {
- unsigned AddrSpace;
- if (parseOptionalAddrSpace(AddrSpace))
- return true;
- Result = PointerType::get(getContext(), AddrSpace);
-
- // Give a nice error for 'ptr*'.
- if (Lex.getKind() == lltok::star)
- return tokError("ptr* is invalid - use ptr instead");
-
- // Fall through to parsing the type suffixes only if this 'ptr' is a
- // function return. Otherwise, return success, implicitly rejecting other
- // suffixes.
- if (Lex.getKind() != lltok::lparen)
- return false;
- }
-
// parse the type suffixes.
while (true) {
switch (Lex.getKind()) {
diff --git a/llvm/test/Other/force-opaque-ptrs.ll b/llvm/test/Other/force-opaque-ptrs.ll
index 7d843950ea703..a216a5703a8f9 100644
--- a/llvm/test/Other/force-opaque-ptrs.ll
+++ b/llvm/test/Other/force-opaque-ptrs.ll
@@ -3,6 +3,8 @@
; RUN: llvm-as < %s | llvm-dis --force-opaque-pointers | FileCheck %s
; RUN: opt --force-opaque-pointers < %s -S | FileCheck %s
+%ty = type i32*
+
; CHECK: @g = external global i16
@g = external global i16
@@ -49,6 +51,14 @@ define void @f3(i32 addrspace(1)* addrspace(2)* %p) {
unreachable
}
+define void @f4(%ty* %p) {
+; CHECK-LABEL: define {{[^@]+}}@f4
+; CHECK-SAME: (ptr [[P:%.*]]) {
+; CHECK-NEXT: unreachable
+;
+ unreachable
+}
+
define void @remangle_intrinsic() {
; CHECK-LABEL: define {{[^@]+}}@remangle_intrinsic() {
; CHECK-NEXT: [[A:%.*]] = alloca ptr, align 8
More information about the llvm-commits
mailing list