[PATCH] D104938: OpaquePtr: Reject 'ptr*' again when parsing textual IR

Duncan P. N. Exon Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 25 11:56:39 PDT 2021


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

Bring back the testcase dropped in
1e6303e60ca5af4fbe7ca728572fd65666a98271 <https://reviews.llvm.org/rG1e6303e60ca5af4fbe7ca728572fd65666a98271> and get it passing by checking
explicitly for `ptr*` in LLParser. Added `Type::isOpaquePointerTy()` for
convenience.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D104938

Files:
  llvm/include/llvm/IR/Type.h
  llvm/lib/AsmParser/LLParser.cpp
  llvm/test/Assembler/invalid-opaque-ptr-addrspace.ll
  llvm/test/Assembler/invalid-opaque-ptr.ll


Index: llvm/test/Assembler/invalid-opaque-ptr.ll
===================================================================
--- /dev/null
+++ llvm/test/Assembler/invalid-opaque-ptr.ll
@@ -0,0 +1,7 @@
+; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s
+
+; CHECK: ptr* is invalid - use ptr instead
+define void @f(ptr %a) {
+    %b = bitcast ptr %a to ptr*
+    ret void
+}
Index: llvm/test/Assembler/invalid-opaque-ptr-addrspace.ll
===================================================================
--- /dev/null
+++ llvm/test/Assembler/invalid-opaque-ptr-addrspace.ll
@@ -0,0 +1,7 @@
+; RUN: not llvm-as < %s -disable-output 2>&1 | FileCheck %s
+
+; CHECK: ptr* is invalid - use ptr instead
+define void @f(ptr addrspace(3) %a) {
+    %b = bitcast ptr addrspace(3) %a to ptr addrspace(3)*
+    ret void
+}
Index: llvm/lib/AsmParser/LLParser.cpp
===================================================================
--- llvm/lib/AsmParser/LLParser.cpp
+++ llvm/lib/AsmParser/LLParser.cpp
@@ -2597,6 +2597,8 @@
         return tokError("basic block pointers are invalid");
       if (Result->isVoidTy())
         return tokError("pointers to void are invalid - use i8* instead");
+      if (Result->isOpaquePointerTy())
+        return tokError("ptr* is invalid - use ptr instead");
       if (!PointerType::isValidElementType(Result))
         return tokError("pointer to this type is invalid");
       Result = PointerType::getUnqual(Result);
Index: llvm/include/llvm/IR/Type.h
===================================================================
--- llvm/include/llvm/IR/Type.h
+++ llvm/include/llvm/IR/Type.h
@@ -227,6 +227,9 @@
   /// True if this is an instance of PointerType.
   bool isPointerTy() const { return getTypeID() == PointerTyID; }
 
+  /// True if this is an instance of PointerType that's opaque.
+  bool isOpaquePointerTy() const { return isPointerTy() && !NumContainedTys; }
+
   /// Return true if this is a pointer type or a vector of pointer types.
   bool isPtrOrPtrVectorTy() const { return getScalarType()->isPointerTy(); }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D104938.354567.patch
Type: text/x-patch
Size: 2055 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210625/0148f846/attachment.bin>


More information about the llvm-commits mailing list