Skip to content

[SYCL] Use checkArgCountAtLeast instead #6380

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 24 additions & 24 deletions clang/lib/Sema/SemaChecking.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,20 @@ static bool checkArgCountAtLeast(Sema &S, CallExpr *Call,
<< Call->getSourceRange();
}

/// Checks that a call expression's argument count is at most the desired
/// number. This is useful when doing custom type-checking on a variadic
/// function. Returns true on error.
static bool checkArgCountAtMost(Sema &S, CallExpr *Call, unsigned MaxArgCount) {
unsigned ArgCount = Call->getNumArgs();
if (ArgCount <= MaxArgCount)
return false;

return S.Diag(Call->getEndLoc(),
diag::err_typecheck_call_too_many_args_at_most)
<< 0 /*function call*/ << MaxArgCount << ArgCount
<< Call->getSourceRange();
}

/// Checks that a call expression's argument count is the desired number.
/// This is useful when doing custom type-checking. Returns true on error.
static bool checkArgCount(Sema &S, CallExpr *Call, unsigned DesiredArgCount) {
Expand Down Expand Up @@ -5489,18 +5503,12 @@ bool Sema::CheckIntelFPGAMemBuiltinFunctionCall(CallExpr *TheCall) {
unsigned NumArgs = TheCall->getNumArgs();

// Make sure we have the minimum number of provided arguments.
if (NumArgs < MinNumArgs)
return Diag(TheCall->getEndLoc(),
diag::err_typecheck_call_too_few_args_at_least)
<< 0 /* function call */ << MinNumArgs << NumArgs
<< TheCall->getSourceRange();
if (checkArgCountAtLeast(*this, TheCall, MinNumArgs))
return true;

// Make sure we don't have too many arguments.
if (NumArgs > MaxNumArgs)
return Diag(TheCall->getEndLoc(),
diag::err_typecheck_call_too_many_args_at_most)
<< 0 /*function call*/ << MaxNumArgs << NumArgs
<< TheCall->getSourceRange();
if (checkArgCountAtMost(*this, TheCall, MaxNumArgs))
return true;

Expr *PointerArg = TheCall->getArg(0);
QualType PointerArgType = PointerArg->getType();
Expand Down Expand Up @@ -7663,10 +7671,8 @@ ExprResult Sema::SemaConvertVectorExpr(Expr *E, TypeSourceInfo *TInfo,
bool Sema::SemaBuiltinPrefetch(CallExpr *TheCall) {
unsigned NumArgs = TheCall->getNumArgs();

if (NumArgs > 3)
return Diag(TheCall->getEndLoc(),
diag::err_typecheck_call_too_many_args_at_most)
<< 0 /*function call*/ << 3 << NumArgs << TheCall->getSourceRange();
if (checkArgCountAtMost(*this, TheCall, 3))
return true;

// Argument 0 is checked for us and the remaining arguments must be
// constant integers.
Expand Down Expand Up @@ -7754,10 +7760,8 @@ bool Sema::SemaBuiltinAllocaWithAlign(CallExpr *TheCall) {
bool Sema::SemaBuiltinAssumeAligned(CallExpr *TheCall) {
unsigned NumArgs = TheCall->getNumArgs();

if (NumArgs > 3)
return Diag(TheCall->getEndLoc(),
diag::err_typecheck_call_too_many_args_at_most)
<< 0 /*function call*/ << 3 << NumArgs << TheCall->getSourceRange();
if (checkArgCountAtMost(*this, TheCall, 3))
return true;

// The alignment must be a constant integer.
Expr *Arg = TheCall->getArg(1);
Expand Down Expand Up @@ -7801,12 +7805,8 @@ bool Sema::SemaBuiltinOSLogFormat(CallExpr *TheCall) {
<< 0 /* function call */ << NumRequiredArgs << NumArgs
<< TheCall->getSourceRange();
}
if (NumArgs >= NumRequiredArgs + 0x100) {
return Diag(TheCall->getEndLoc(),
diag::err_typecheck_call_too_many_args_at_most)
<< 0 /* function call */ << (NumRequiredArgs + 0xff) << NumArgs
<< TheCall->getSourceRange();
}
if (checkArgCountAtMost(*this, TheCall, NumRequiredArgs + 0xff))
return true;
unsigned i = 0;

// For formatting call, check buffer arg.
Expand Down
2 changes: 1 addition & 1 deletion clang/test/SemaSYCL/intel-fpga-mem-builtin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void foo(float *A, int *B, State *C) {
x = __builtin_intel_fpga_mem(A, PARAM_1 | PARAM_2, -1);
// expected-error@-1{{builtin parameter must be a non-negative integer constant}}
x = __builtin_intel_fpga_mem(A, PARAM_1 | PARAM_2);
// expected-error@-1{{too few arguments to function call, expected at least 3, have 2}}
// expected-error@-1{{too few arguments to function call, expected 3, have 2}}
y = __builtin_intel_fpga_mem(B, 0, i);
// expected-error@-1{{argument to '__builtin_intel_fpga_mem' must be a constant integer}}
z = __builtin_intel_fpga_mem(C, i, 0);
Expand Down