@@ -123,6 +123,20 @@ static bool checkArgCountAtLeast(Sema &S, CallExpr *Call,
123
123
<< Call->getSourceRange();
124
124
}
125
125
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
+
126
140
/// Checks that a call expression's argument count is the desired number.
127
141
/// This is useful when doing custom type-checking. Returns true on error.
128
142
static bool checkArgCount(Sema &S, CallExpr *Call, unsigned DesiredArgCount) {
@@ -5489,18 +5503,12 @@ bool Sema::CheckIntelFPGAMemBuiltinFunctionCall(CallExpr *TheCall) {
5489
5503
unsigned NumArgs = TheCall->getNumArgs();
5490
5504
5491
5505
// 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;
5497
5508
5498
5509
// 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;
5504
5512
5505
5513
Expr *PointerArg = TheCall->getArg(0);
5506
5514
QualType PointerArgType = PointerArg->getType();
@@ -7663,10 +7671,8 @@ ExprResult Sema::SemaConvertVectorExpr(Expr *E, TypeSourceInfo *TInfo,
7663
7671
bool Sema::SemaBuiltinPrefetch(CallExpr *TheCall) {
7664
7672
unsigned NumArgs = TheCall->getNumArgs();
7665
7673
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;
7670
7676
7671
7677
// Argument 0 is checked for us and the remaining arguments must be
7672
7678
// constant integers.
@@ -7754,10 +7760,8 @@ bool Sema::SemaBuiltinAllocaWithAlign(CallExpr *TheCall) {
7754
7760
bool Sema::SemaBuiltinAssumeAligned(CallExpr *TheCall) {
7755
7761
unsigned NumArgs = TheCall->getNumArgs();
7756
7762
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;
7761
7765
7762
7766
// The alignment must be a constant integer.
7763
7767
Expr *Arg = TheCall->getArg(1);
@@ -7801,12 +7805,8 @@ bool Sema::SemaBuiltinOSLogFormat(CallExpr *TheCall) {
7801
7805
<< 0 /* function call */ << NumRequiredArgs << NumArgs
7802
7806
<< TheCall->getSourceRange();
7803
7807
}
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;
7810
7810
unsigned i = 0;
7811
7811
7812
7812
// For formatting call, check buffer arg.
0 commit comments