82
82
#include "llvm/ADT/DenseMap.h"
83
83
#include "llvm/ADT/FoldingSet.h"
84
84
#include "llvm/ADT/STLExtras.h"
85
+ #include "llvm/ADT/STLForwardCompat.h"
85
86
#include "llvm/ADT/SmallBitVector.h"
86
87
#include "llvm/ADT/SmallPtrSet.h"
87
88
#include "llvm/ADT/SmallString.h"
@@ -3345,7 +3346,7 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto,
3345
3346
// Refuse POD arguments that weren't caught by the format string
3346
3347
// checks above.
3347
3348
auto *FD = dyn_cast_or_null<FunctionDecl>(FDecl);
3348
- if (CallType != VariadicDoesNotApply &&
3349
+ if (CallType != VariadicCallType::DoesNotApply &&
3349
3350
(!FD || FD->getBuiltinID() != Builtin::BI__noop)) {
3350
3351
unsigned NumParams = Proto ? Proto->getNumParams()
3351
3352
: isa_and_nonnull<FunctionDecl>(FDecl)
@@ -3396,7 +3397,7 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto,
3396
3397
if (Context.getTargetInfo().getTriple().isOSAIX() && FDecl && Arg &&
3397
3398
FDecl->hasLinkage() &&
3398
3399
FDecl->getFormalLinkage() != Linkage::Internal &&
3399
- CallType == VariadicDoesNotApply )
3400
+ CallType == VariadicCallType::DoesNotApply )
3400
3401
PPC().checkAIXMemberAlignment((Arg->getExprLoc()), Arg);
3401
3402
3402
3403
QualType ParamTy = Proto->getParamType(ArgIdx);
@@ -3518,8 +3519,9 @@ void Sema::CheckConstructorCall(FunctionDecl *FDecl, QualType ThisType,
3518
3519
ArrayRef<const Expr *> Args,
3519
3520
const FunctionProtoType *Proto,
3520
3521
SourceLocation Loc) {
3521
- VariadicCallType CallType =
3522
- Proto->isVariadic() ? VariadicConstructor : VariadicDoesNotApply;
3522
+ VariadicCallType CallType = Proto->isVariadic()
3523
+ ? VariadicCallType::Constructor
3524
+ : VariadicCallType::DoesNotApply;
3523
3525
3524
3526
auto *Ctor = cast<CXXConstructorDecl>(FDecl);
3525
3527
CheckArgAlignment(
@@ -3630,11 +3632,11 @@ bool Sema::CheckPointerCall(NamedDecl *NDecl, CallExpr *TheCall,
3630
3632
3631
3633
VariadicCallType CallType;
3632
3634
if (!Proto || !Proto->isVariadic()) {
3633
- CallType = VariadicDoesNotApply ;
3635
+ CallType = VariadicCallType::DoesNotApply ;
3634
3636
} else if (Ty->isBlockPointerType()) {
3635
- CallType = VariadicBlock ;
3637
+ CallType = VariadicCallType::Block ;
3636
3638
} else { // Ty->isFunctionPointerType()
3637
- CallType = VariadicFunction ;
3639
+ CallType = VariadicCallType::Function ;
3638
3640
}
3639
3641
3640
3642
checkCall(NDecl, Proto, /*ThisArg=*/nullptr,
@@ -5527,7 +5529,7 @@ bool Sema::BuiltinOSLogFormat(CallExpr *TheCall) {
5527
5529
unsigned FirstDataArg = i;
5528
5530
while (i < NumArgs) {
5529
5531
ExprResult Arg = DefaultVariadicArgumentPromotion(
5530
- TheCall->getArg(i), VariadicFunction , nullptr);
5532
+ TheCall->getArg(i), VariadicCallType::Function , nullptr);
5531
5533
if (Arg.isInvalid())
5532
5534
return true;
5533
5535
CharUnits ArgSize = Context.getTypeSizeInChars(Arg.get()->getType());
@@ -5547,8 +5549,8 @@ bool Sema::BuiltinOSLogFormat(CallExpr *TheCall) {
5547
5549
ArrayRef<const Expr *> Args(TheCall->getArgs(), TheCall->getNumArgs());
5548
5550
bool Success = CheckFormatArguments(
5549
5551
Args, FAPK_Variadic, nullptr, FormatIdx, FirstDataArg,
5550
- FormatStringType::OSLog, VariadicFunction, TheCall->getBeginLoc() ,
5551
- SourceRange(), CheckedVarArgs);
5552
+ FormatStringType::OSLog, VariadicCallType::Function ,
5553
+ TheCall->getBeginLoc(), SourceRange(), CheckedVarArgs);
5552
5554
if (!Success)
5553
5555
return true;
5554
5556
}
@@ -5990,7 +5992,7 @@ static void CheckFormatString(
5990
5992
const StringLiteral *ReferenceFormatString, const Expr *OrigFormatExpr,
5991
5993
ArrayRef<const Expr *> Args, Sema::FormatArgumentPassingKind APK,
5992
5994
unsigned format_idx, unsigned firstDataArg, FormatStringType Type,
5993
- bool inFunctionCall, Sema:: VariadicCallType CallType,
5995
+ bool inFunctionCall, VariadicCallType CallType,
5994
5996
llvm::SmallBitVector &CheckedVarArgs, UncoveredArgHandler &UncoveredArg,
5995
5997
bool IgnoreStringsWithoutSpecifiers);
5996
5998
@@ -6005,7 +6007,7 @@ static StringLiteralCheckType checkFormatStringExpr(
6005
6007
Sema &S, const StringLiteral *ReferenceFormatString, const Expr *E,
6006
6008
ArrayRef<const Expr *> Args, Sema::FormatArgumentPassingKind APK,
6007
6009
unsigned format_idx, unsigned firstDataArg, FormatStringType Type,
6008
- Sema:: VariadicCallType CallType, bool InFunctionCall,
6010
+ VariadicCallType CallType, bool InFunctionCall,
6009
6011
llvm::SmallBitVector &CheckedVarArgs, UncoveredArgHandler &UncoveredArg,
6010
6012
llvm::APSInt Offset, bool IgnoreStringsWithoutSpecifiers = false) {
6011
6013
if (S.isConstantEvaluatedContext())
@@ -6465,7 +6467,8 @@ bool Sema::CheckFormatArguments(const FormatAttr *Format,
6465
6467
llvm::SmallBitVector &CheckedVarArgs) {
6466
6468
FormatStringInfo FSI;
6467
6469
if (getFormatStringInfo(Format->getFormatIdx(), Format->getFirstArg(),
6468
- IsCXXMember, CallType != VariadicDoesNotApply, &FSI))
6470
+ IsCXXMember,
6471
+ CallType != VariadicCallType::DoesNotApply, &FSI))
6469
6472
return CheckFormatArguments(
6470
6473
Args, FSI.ArgPassingKind, nullptr, FSI.FormatIdx, FSI.FirstDataArg,
6471
6474
GetFormatStringType(Format), CallType, Loc, Range, CheckedVarArgs);
@@ -6594,7 +6597,7 @@ class CheckFormatHandler : public analyze_format_string::FormatStringHandler {
6594
6597
bool usesPositionalArgs = false;
6595
6598
bool atFirstArg = true;
6596
6599
bool inFunctionCall;
6597
- Sema:: VariadicCallType CallType;
6600
+ VariadicCallType CallType;
6598
6601
llvm::SmallBitVector &CheckedVarArgs;
6599
6602
UncoveredArgHandler &UncoveredArg;
6600
6603
@@ -6604,7 +6607,7 @@ class CheckFormatHandler : public analyze_format_string::FormatStringHandler {
6604
6607
unsigned firstDataArg, unsigned numDataArgs,
6605
6608
const char *beg, Sema::FormatArgumentPassingKind APK,
6606
6609
ArrayRef<const Expr *> Args, unsigned formatIdx,
6607
- bool inFunctionCall, Sema:: VariadicCallType callType,
6610
+ bool inFunctionCall, VariadicCallType callType,
6608
6611
llvm::SmallBitVector &CheckedVarArgs,
6609
6612
UncoveredArgHandler &UncoveredArg)
6610
6613
: S(s), FExpr(fexpr), OrigFormatExpr(origFormatExpr), FSType(type),
@@ -7052,7 +7055,7 @@ class CheckPrintfHandler : public CheckFormatHandler {
7052
7055
unsigned firstDataArg, unsigned numDataArgs, bool isObjC,
7053
7056
const char *beg, Sema::FormatArgumentPassingKind APK,
7054
7057
ArrayRef<const Expr *> Args, unsigned formatIdx,
7055
- bool inFunctionCall, Sema:: VariadicCallType CallType,
7058
+ bool inFunctionCall, VariadicCallType CallType,
7056
7059
llvm::SmallBitVector &CheckedVarArgs,
7057
7060
UncoveredArgHandler &UncoveredArg)
7058
7061
: CheckFormatHandler(s, fexpr, origFormatExpr, type, firstDataArg,
@@ -7187,7 +7190,7 @@ class DecomposePrintfHandler : public CheckPrintfHandler {
7187
7190
unsigned numDataArgs, bool isObjC, const char *beg,
7188
7191
Sema::FormatArgumentPassingKind APK,
7189
7192
ArrayRef<const Expr *> Args, unsigned formatIdx,
7190
- bool inFunctionCall, Sema:: VariadicCallType CallType,
7193
+ bool inFunctionCall, VariadicCallType CallType,
7191
7194
llvm::SmallBitVector &CheckedVarArgs,
7192
7195
UncoveredArgHandler &UncoveredArg,
7193
7196
llvm::SmallVectorImpl<EquatableFormatArgument> &Specs)
@@ -7461,8 +7464,8 @@ bool DecomposePrintfHandler::GetSpecifiers(
7461
7464
const Expr *PrintfArgs[] = {FSL->getFormatString()};
7462
7465
DecomposePrintfHandler H(S, FSL, FSL->getFormatString(), Type, 0, 0, IsObjC,
7463
7466
Str, Sema::FAPK_Elsewhere, PrintfArgs, 0,
7464
- InFunctionCall, Sema::VariadicDoesNotApply , BV, UA ,
7465
- Args);
7467
+ InFunctionCall, VariadicCallType::DoesNotApply , BV,
7468
+ UA, Args);
7466
7469
7467
7470
if (!analyze_format_string::ParsePrintfString(
7468
7471
H, Str, Str + Data.size(), S.getLangOpts(), S.Context.getTargetInfo(),
@@ -8331,12 +8334,13 @@ CheckPrintfHandler::checkFormatExpr(const analyze_printf::PrintfSpecifier &FS,
8331
8334
}
8332
8335
case Sema::VAK_Undefined:
8333
8336
case Sema::VAK_MSVCUndefined:
8334
- if (CallType == Sema::VariadicDoesNotApply ) {
8337
+ if (CallType == VariadicCallType::DoesNotApply ) {
8335
8338
EmitTypeMismatch = true;
8336
8339
} else {
8337
8340
EmitFormatDiagnostic(
8338
8341
S.PDiag(diag::warn_non_pod_vararg_with_format_string)
8339
- << S.getLangOpts().CPlusPlus11 << ExprTy << CallType
8342
+ << S.getLangOpts().CPlusPlus11 << ExprTy
8343
+ << llvm::to_underlying(CallType)
8340
8344
<< AT.getRepresentativeTypeName(S.Context) << CSR
8341
8345
<< E->getSourceRange(),
8342
8346
E->getBeginLoc(), /*IsStringLocation*/ false, CSR);
@@ -8345,20 +8349,21 @@ CheckPrintfHandler::checkFormatExpr(const analyze_printf::PrintfSpecifier &FS,
8345
8349
break;
8346
8350
8347
8351
case Sema::VAK_Invalid:
8348
- if (CallType == Sema::VariadicDoesNotApply )
8352
+ if (CallType == VariadicCallType::DoesNotApply )
8349
8353
EmitTypeMismatch = true;
8350
8354
else if (ExprTy->isObjCObjectType())
8351
8355
EmitFormatDiagnostic(
8352
8356
S.PDiag(diag::err_cannot_pass_objc_interface_to_vararg_format)
8353
- << S.getLangOpts().CPlusPlus11 << ExprTy << CallType
8357
+ << S.getLangOpts().CPlusPlus11 << ExprTy
8358
+ << llvm::to_underlying(CallType)
8354
8359
<< AT.getRepresentativeTypeName(S.Context) << CSR
8355
8360
<< E->getSourceRange(),
8356
8361
E->getBeginLoc(), /*IsStringLocation*/ false, CSR);
8357
8362
else
8358
8363
// FIXME: If this is an initializer list, suggest removing the braces
8359
8364
// or inserting a cast to the target type.
8360
8365
S.Diag(E->getBeginLoc(), diag::err_cannot_pass_to_vararg_format)
8361
- << isa<InitListExpr>(E) << ExprTy << CallType
8366
+ << isa<InitListExpr>(E) << ExprTy << llvm::to_underlying( CallType)
8362
8367
<< AT.getRepresentativeTypeName(S.Context) << E->getSourceRange();
8363
8368
break;
8364
8369
}
@@ -8395,7 +8400,7 @@ class CheckScanfHandler : public CheckFormatHandler {
8395
8400
unsigned firstDataArg, unsigned numDataArgs,
8396
8401
const char *beg, Sema::FormatArgumentPassingKind APK,
8397
8402
ArrayRef<const Expr *> Args, unsigned formatIdx,
8398
- bool inFunctionCall, Sema:: VariadicCallType CallType,
8403
+ bool inFunctionCall, VariadicCallType CallType,
8399
8404
llvm::SmallBitVector &CheckedVarArgs,
8400
8405
UncoveredArgHandler &UncoveredArg)
8401
8406
: CheckFormatHandler(s, fexpr, origFormatExpr, type, firstDataArg,
@@ -8624,7 +8629,7 @@ static void CheckFormatString(
8624
8629
const StringLiteral *ReferenceFormatString, const Expr *OrigFormatExpr,
8625
8630
ArrayRef<const Expr *> Args, Sema::FormatArgumentPassingKind APK,
8626
8631
unsigned format_idx, unsigned firstDataArg, FormatStringType Type,
8627
- bool inFunctionCall, Sema:: VariadicCallType CallType,
8632
+ bool inFunctionCall, VariadicCallType CallType,
8628
8633
llvm::SmallBitVector &CheckedVarArgs, UncoveredArgHandler &UncoveredArg,
8629
8634
bool IgnoreStringsWithoutSpecifiers) {
8630
8635
// CHECK: is the format string a wide literal?
0 commit comments