Skip to content

Commit 6b8761a

Browse files
authored
[SYCL] Use checkArgCountAtLeast instead (#6380)
Rather than replicate the code, call existing routine checkArgCountAtLeast for similar functionality. Add a similar routine checkArgCountAtMost to check if a call expression's argument count exceeds the most expected. Replace where equivalent with calls to this routine.
1 parent 07201f5 commit 6b8761a

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

clang/lib/Sema/SemaChecking.cpp

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,20 @@ static bool checkArgCountAtLeast(Sema &S, CallExpr *Call,
123123
<< Call->getSourceRange();
124124
}
125125

126+
/// Checks that a call expression's argument count is at most the desired
127+
/// number. This is useful when doing custom type-checking on a variadic
128+
/// function. Returns true on error.
129+
static bool checkArgCountAtMost(Sema &S, CallExpr *Call, unsigned MaxArgCount) {
130+
unsigned ArgCount = Call->getNumArgs();
131+
if (ArgCount <= MaxArgCount)
132+
return false;
133+
134+
return S.Diag(Call->getEndLoc(),
135+
diag::err_typecheck_call_too_many_args_at_most)
136+
<< 0 /*function call*/ << MaxArgCount << ArgCount
137+
<< Call->getSourceRange();
138+
}
139+
126140
/// Checks that a call expression's argument count is the desired number.
127141
/// This is useful when doing custom type-checking. Returns true on error.
128142
static bool checkArgCount(Sema &S, CallExpr *Call, unsigned DesiredArgCount) {
@@ -5489,18 +5503,12 @@ bool Sema::CheckIntelFPGAMemBuiltinFunctionCall(CallExpr *TheCall) {
54895503
unsigned NumArgs = TheCall->getNumArgs();
54905504

54915505
// Make sure we have the minimum number of provided arguments.
5492-
if (NumArgs < MinNumArgs)
5493-
return Diag(TheCall->getEndLoc(),
5494-
diag::err_typecheck_call_too_few_args_at_least)
5495-
<< 0 /* function call */ << MinNumArgs << NumArgs
5496-
<< TheCall->getSourceRange();
5506+
if (checkArgCountAtLeast(*this, TheCall, MinNumArgs))
5507+
return true;
54975508

54985509
// Make sure we don't have too many arguments.
5499-
if (NumArgs > MaxNumArgs)
5500-
return Diag(TheCall->getEndLoc(),
5501-
diag::err_typecheck_call_too_many_args_at_most)
5502-
<< 0 /*function call*/ << MaxNumArgs << NumArgs
5503-
<< TheCall->getSourceRange();
5510+
if (checkArgCountAtMost(*this, TheCall, MaxNumArgs))
5511+
return true;
55045512

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

7666-
if (NumArgs > 3)
7667-
return Diag(TheCall->getEndLoc(),
7668-
diag::err_typecheck_call_too_many_args_at_most)
7669-
<< 0 /*function call*/ << 3 << NumArgs << TheCall->getSourceRange();
7674+
if (checkArgCountAtMost(*this, TheCall, 3))
7675+
return true;
76707676

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

7757-
if (NumArgs > 3)
7758-
return Diag(TheCall->getEndLoc(),
7759-
diag::err_typecheck_call_too_many_args_at_most)
7760-
<< 0 /*function call*/ << 3 << NumArgs << TheCall->getSourceRange();
7763+
if (checkArgCountAtMost(*this, TheCall, 3))
7764+
return true;
77617765

77627766
// The alignment must be a constant integer.
77637767
Expr *Arg = TheCall->getArg(1);
@@ -7801,12 +7805,8 @@ bool Sema::SemaBuiltinOSLogFormat(CallExpr *TheCall) {
78017805
<< 0 /* function call */ << NumRequiredArgs << NumArgs
78027806
<< TheCall->getSourceRange();
78037807
}
7804-
if (NumArgs >= NumRequiredArgs + 0x100) {
7805-
return Diag(TheCall->getEndLoc(),
7806-
diag::err_typecheck_call_too_many_args_at_most)
7807-
<< 0 /* function call */ << (NumRequiredArgs + 0xff) << NumArgs
7808-
<< TheCall->getSourceRange();
7809-
}
7808+
if (checkArgCountAtMost(*this, TheCall, NumRequiredArgs + 0xff))
7809+
return true;
78107810
unsigned i = 0;
78117811

78127812
// For formatting call, check buffer arg.

clang/test/SemaSYCL/intel-fpga-mem-builtin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ void foo(float *A, int *B, State *C) {
3232
x = __builtin_intel_fpga_mem(A, PARAM_1 | PARAM_2, -1);
3333
// expected-error@-1{{builtin parameter must be a non-negative integer constant}}
3434
x = __builtin_intel_fpga_mem(A, PARAM_1 | PARAM_2);
35-
// expected-error@-1{{too few arguments to function call, expected at least 3, have 2}}
35+
// expected-error@-1{{too few arguments to function call, expected 3, have 2}}
3636
y = __builtin_intel_fpga_mem(B, 0, i);
3737
// expected-error@-1{{argument to '__builtin_intel_fpga_mem' must be a constant integer}}
3838
z = __builtin_intel_fpga_mem(C, i, 0);

0 commit comments

Comments
 (0)