[AsmParser] Support %ty* in force-opaque-pointers mode
authorNikita Popov <nikita.ppv@gmail.com>
Sat, 28 Aug 2021 20:26:45 +0000 (22:26 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Mon, 30 Aug 2021 17:05:00 +0000 (19:05 +0200)
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

llvm/lib/AsmParser/LLParser.cpp
llvm/test/Other/force-opaque-ptrs.ll

index 62c7253..cfa6240 100644 (file)
@@ -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()) {
index 7d84395..a216a57 100644 (file)
@@ -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