Skip to content

Commit

Permalink
OpaquePtr: Make byval/sret types mandatory
Browse files Browse the repository at this point in the history
  • Loading branch information
arsenm committed Nov 21, 2020
1 parent 79f7546 commit 4108326
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 23 deletions.
6 changes: 2 additions & 4 deletions llvm/include/llvm/IR/Function.h
Original file line number Diff line number Diff line change
Expand Up @@ -472,14 +472,12 @@ class Function : public GlobalObject, public ilist_node<Function> {

/// 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.
Expand Down
20 changes: 2 additions & 18 deletions llvm/lib/AsmParser/LLParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1699,14 +1699,14 @@ bool LLParser::parseOptionalParamAttrs(AttrBuilder &B) {
}
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;
Expand Down Expand Up @@ -2628,22 +2628,6 @@ bool LLParser::parseParameterList(SmallVectorImpl<ParamInfo> &ArgList,
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) {
Expand Down
1 change: 0 additions & 1 deletion llvm/lib/AsmParser/LLParser.h
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,6 @@ namespace llvm {
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);
Expand Down
6 changes: 6 additions & 0 deletions llvm/test/Assembler/byval-parse-error0.ll
Original file line number Diff line number Diff line change
@@ -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
}
6 changes: 6 additions & 0 deletions llvm/test/Assembler/sret-parse-error0.ll
Original file line number Diff line number Diff line change
@@ -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
}

0 comments on commit 4108326

Please sign in to comment.