[PATCH] D108876: [AsmParser] Support %ty* in force-opaque-pointers mode

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 28 13:29:12 PDT 2021


nikic created this revision.
nikic added reviewers: opaque-pointers, dexonsmith.
Herald added subscribers: ormris, hiraditya.
nikic requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D108876

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
@@ -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 @@
   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
Index: llvm/lib/AsmParser/LLParser.cpp
===================================================================
--- llvm/lib/AsmParser/LLParser.cpp
+++ llvm/lib/AsmParser/LLParser.cpp
@@ -2217,6 +2217,26 @@
     // 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 @@
   }
   }
 
-  // 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()) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D108876.369277.patch
Type: text/x-patch
Size: 2649 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210828/d2e9ba47/attachment.bin>


More information about the llvm-commits mailing list