[PATCH] D91900: OpaquePtr: Make byval/sret types mandatory

Matt Arsenault via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 20 18:01:02 PST 2020


arsenm updated this revision to Diff 306813.
arsenm added a comment.

Add parse error tests


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91900/new/

https://reviews.llvm.org/D91900

Files:
  llvm/include/llvm/IR/Function.h
  llvm/lib/AsmParser/LLParser.cpp
  llvm/lib/AsmParser/LLParser.h
  llvm/test/Assembler/byval-parse-error0.ll
  llvm/test/Assembler/sret-parse-error0.ll


Index: llvm/test/Assembler/sret-parse-error0.ll
===================================================================
--- /dev/null
+++ llvm/test/Assembler/sret-parse-error0.ll
@@ -0,0 +1,6 @@
+; RUN: not llvm-as < %s 2>&1 | FileCheck %s
+
+; CHECK: <stdin>:[[@LINE+1]]:32: error: expected '('{{$}}
+define void @test_sret(i8* sret) {
+  ret void
+}
Index: llvm/test/Assembler/byval-parse-error0.ll
===================================================================
--- /dev/null
+++ llvm/test/Assembler/byval-parse-error0.ll
@@ -0,0 +1,6 @@
+; RUN: not llvm-as < %s 2>&1 | FileCheck %s
+
+; CHECK: <stdin>:[[@LINE+1]]:34: error: expected '('{{$}}
+define void @test_byval(i8* byval) {
+  ret void
+}
Index: llvm/lib/AsmParser/LLParser.h
===================================================================
--- llvm/lib/AsmParser/LLParser.h
+++ llvm/lib/AsmParser/LLParser.h
@@ -328,7 +328,6 @@
     bool parseFnAttributeValuePairs(AttrBuilder &B,
                                     std::vector<unsigned> &FwdRefAttrGrps,
                                     bool inAttrGrp, LocTy &BuiltinLoc);
-    bool parseOptionalTypeAttr(Type *&Result, lltok::Kind AttrName);
     bool parseRequiredTypeAttr(Type *&Result, lltok::Kind AttrName);
     bool parsePreallocated(Type *&Result);
     bool parseByRef(Type *&Result);
Index: llvm/lib/AsmParser/LLParser.cpp
===================================================================
--- llvm/lib/AsmParser/LLParser.cpp
+++ llvm/lib/AsmParser/LLParser.cpp
@@ -1699,14 +1699,14 @@
     }
     case lltok::kw_byval: {
       Type *Ty;
-      if (parseOptionalTypeAttr(Ty, lltok::kw_byval))
+      if (parseRequiredTypeAttr(Ty, lltok::kw_byval))
         return true;
       B.addByValAttr(Ty);
       continue;
     }
     case lltok::kw_sret: {
       Type *Ty;
-      if (parseOptionalTypeAttr(Ty, lltok::kw_sret))
+      if (parseRequiredTypeAttr(Ty, lltok::kw_sret))
         return true;
       B.addStructRetAttr(Ty);
       continue;
@@ -2628,22 +2628,6 @@
   return false;
 }
 
-/// parseByValWithOptionalType
-///   ::= byval
-///   ::= byval(<ty>)
-bool LLParser::parseOptionalTypeAttr(Type *&Result, lltok::Kind AttrName) {
-  Result = nullptr;
-  if (!EatIfPresent(AttrName))
-    return true;
-  if (!EatIfPresent(lltok::lparen))
-    return false;
-  if (parseType(Result))
-    return true;
-  if (!EatIfPresent(lltok::rparen))
-    return error(Lex.getLoc(), "expected ')'");
-  return false;
-}
-
 /// parseRequiredTypeAttr
 ///   ::= attrname(<ty>)
 bool LLParser::parseRequiredTypeAttr(Type *&Result, lltok::Kind AttrName) {
Index: llvm/include/llvm/IR/Function.h
===================================================================
--- llvm/include/llvm/IR/Function.h
+++ llvm/include/llvm/IR/Function.h
@@ -472,14 +472,12 @@
 
   /// Extract the byval type for a parameter.
   Type *getParamByValType(unsigned ArgNo) const {
-    Type *Ty = AttributeSets.getParamByValType(ArgNo);
-    return Ty ? Ty : (arg_begin() + ArgNo)->getType()->getPointerElementType();
+    return AttributeSets.getParamByValType(ArgNo);
   }
 
   /// Extract the sret type for a parameter.
   Type *getParamStructRetType(unsigned ArgNo) const {
-    Type *Ty = AttributeSets.getParamStructRetType(ArgNo);
-    return Ty ? Ty : (arg_begin() + ArgNo)->getType()->getPointerElementType();
+    return AttributeSets.getParamStructRetType(ArgNo);
   }
 
   /// Extract the byref type for a parameter.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91900.306813.patch
Type: text/x-patch
Size: 3430 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201121/410ff669/attachment.bin>


More information about the llvm-commits mailing list