From a86d5883e9ccbef4fe47efa17ca4d6827f19ef3a Mon Sep 17 00:00:00 2001 From: zhaoxuhui Date: Tue, 11 Apr 2023 11:40:28 +0800 Subject: [PATCH] [BSC] bugfix_for_too_few_arguments_call --- clang/include/clang/AST/Decl.h | 5 +++-- clang/lib/AST/Decl.cpp | 7 ++++--- clang/lib/Sema/SemaExpr.cpp | 3 ++- .../Method/BuiltInType/int_too_few_arguments_call.cbs | 9 +++++++++ 4 files changed, 18 insertions(+), 6 deletions(-) create mode 100644 clang/test/BSC/Method/BuiltInType/int_too_few_arguments_call.cbs diff --git a/clang/include/clang/AST/Decl.h b/clang/include/clang/AST/Decl.h index 254e050b7777..a23159fcec00 100644 --- a/clang/include/clang/AST/Decl.h +++ b/clang/include/clang/AST/Decl.h @@ -2482,8 +2482,9 @@ public: /// Returns the minimum number of arguments needed to call this function. This /// may be fewer than the number of function parameters, if some of the - /// parameters have default arguments (in C++). - unsigned getMinRequiredArguments() const; + /// parameters have default arguments (in C++) or contain "this" parameter (in + /// BSC). + unsigned getMinRequiredArguments(bool HasBSCScopeSpec = false) const; /// Determine whether this function has a single parameter, or multiple /// parameters where all but the first have default arguments. diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index 5eb716705731..5069c6ea574b 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -3339,9 +3339,10 @@ void FunctionDecl::setParams(ASTContext &C, /// getMinRequiredArguments - Returns the minimum number of arguments /// needed to call this function. This may be fewer than the number of /// function parameters, if some of the parameters have default -/// arguments (in C++) or are parameter packs (C++11). -unsigned FunctionDecl::getMinRequiredArguments() const { - if (getASTContext().getLangOpts().BSC) { +/// arguments (in C++) or are parameter packs (C++11) or contain "this" +/// parameter (in BSC). +unsigned FunctionDecl::getMinRequiredArguments(bool HasBSCScopeSpec) const { + if (getASTContext().getLangOpts().BSC && !HasBSCScopeSpec) { int num = getNumParams(); if (num > 0 && parameters()[0] && parameters()[0]->IsThisParam) { num--; diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 7d53cc7cdcce..d18a2f80c849 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -5803,7 +5803,8 @@ Sema::ConvertArgumentsForCall(CallExpr *Call, Expr *Fn, // assignment, to the types of the corresponding parameter, ... unsigned NumParams = Proto->getNumParams(); bool Invalid = false; - unsigned MinArgs = FDecl ? FDecl->getMinRequiredArguments() : NumParams; + unsigned MinArgs = + FDecl ? FDecl->getMinRequiredArguments(Fn->HasBSCScopeSpec) : NumParams; unsigned FnKind = Fn->getType()->isBlockPointerType() ? 1 /* block */ : (IsExecConfig ? 3 /* kernel function (exec config) */ diff --git a/clang/test/BSC/Method/BuiltInType/int_too_few_arguments_call.cbs b/clang/test/BSC/Method/BuiltInType/int_too_few_arguments_call.cbs new file mode 100644 index 000000000000..9a89f2e6fc0a --- /dev/null +++ b/clang/test/BSC/Method/BuiltInType/int_too_few_arguments_call.cbs @@ -0,0 +1,9 @@ +// RUN: %clang_cc1 -verify %s + +void int::increase(int* this) { // expected-note {{'increase' declared here}} +} + +int main() { + int::increase(); // expected-error {{too few arguments to function call, single argument 'this' was not specified}} + return 0; +} \ No newline at end of file -- Gitee