8282#include "llvm/ADT/DenseMap.h"
8383#include "llvm/ADT/FoldingSet.h"
8484#include "llvm/ADT/STLExtras.h"
85+ #include "llvm/ADT/STLForwardCompat.h"
8586#include "llvm/ADT/SmallBitVector.h"
8687#include "llvm/ADT/SmallPtrSet.h"
8788#include "llvm/ADT/SmallString.h"
@@ -3345,7 +3346,7 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto,
33453346 // Refuse POD arguments that weren't caught by the format string
33463347 // checks above.
33473348 auto *FD = dyn_cast_or_null<FunctionDecl>(FDecl);
3348- if (CallType != VariadicDoesNotApply &&
3349+ if (CallType != VariadicCallType::DoesNotApply &&
33493350 (!FD || FD->getBuiltinID() != Builtin::BI__noop)) {
33503351 unsigned NumParams = Proto ? Proto->getNumParams()
33513352 : isa_and_nonnull<FunctionDecl>(FDecl)
@@ -3396,7 +3397,7 @@ void Sema::checkCall(NamedDecl *FDecl, const FunctionProtoType *Proto,
33963397 if (Context.getTargetInfo().getTriple().isOSAIX() && FDecl && Arg &&
33973398 FDecl->hasLinkage() &&
33983399 FDecl->getFormalLinkage() != Linkage::Internal &&
3399- CallType == VariadicDoesNotApply )
3400+ CallType == VariadicCallType::DoesNotApply )
34003401 PPC().checkAIXMemberAlignment((Arg->getExprLoc()), Arg);
34013402
34023403 QualType ParamTy = Proto->getParamType(ArgIdx);
@@ -3518,8 +3519,9 @@ void Sema::CheckConstructorCall(FunctionDecl *FDecl, QualType ThisType,
35183519 ArrayRef<const Expr *> Args,
35193520 const FunctionProtoType *Proto,
35203521 SourceLocation Loc) {
3521- VariadicCallType CallType =
3522- Proto->isVariadic() ? VariadicConstructor : VariadicDoesNotApply;
3522+ VariadicCallType CallType = Proto->isVariadic()
3523+ ? VariadicCallType::Constructor
3524+ : VariadicCallType::DoesNotApply;
35233525
35243526 auto *Ctor = cast<CXXConstructorDecl>(FDecl);
35253527 CheckArgAlignment(
@@ -3630,11 +3632,11 @@ bool Sema::CheckPointerCall(NamedDecl *NDecl, CallExpr *TheCall,
36303632
36313633 VariadicCallType CallType;
36323634 if (!Proto || !Proto->isVariadic()) {
3633- CallType = VariadicDoesNotApply ;
3635+ CallType = VariadicCallType::DoesNotApply ;
36343636 } else if (Ty->isBlockPointerType()) {
3635- CallType = VariadicBlock ;
3637+ CallType = VariadicCallType::Block ;
36363638 } else { // Ty->isFunctionPointerType()
3637- CallType = VariadicFunction ;
3639+ CallType = VariadicCallType::Function ;
36383640 }
36393641
36403642 checkCall(NDecl, Proto, /*ThisArg=*/nullptr,
@@ -5527,7 +5529,7 @@ bool Sema::BuiltinOSLogFormat(CallExpr *TheCall) {
55275529 unsigned FirstDataArg = i;
55285530 while (i < NumArgs) {
55295531 ExprResult Arg = DefaultVariadicArgumentPromotion(
5530- TheCall->getArg(i), VariadicFunction , nullptr);
5532+ TheCall->getArg(i), VariadicCallType::Function , nullptr);
55315533 if (Arg.isInvalid())
55325534 return true;
55335535 CharUnits ArgSize = Context.getTypeSizeInChars(Arg.get()->getType());
@@ -5547,8 +5549,8 @@ bool Sema::BuiltinOSLogFormat(CallExpr *TheCall) {
55475549 ArrayRef<const Expr *> Args(TheCall->getArgs(), TheCall->getNumArgs());
55485550 bool Success = CheckFormatArguments(
55495551 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);
55525554 if (!Success)
55535555 return true;
55545556 }
@@ -5990,7 +5992,7 @@ static void CheckFormatString(
59905992 const StringLiteral *ReferenceFormatString, const Expr *OrigFormatExpr,
59915993 ArrayRef<const Expr *> Args, Sema::FormatArgumentPassingKind APK,
59925994 unsigned format_idx, unsigned firstDataArg, FormatStringType Type,
5993- bool inFunctionCall, Sema:: VariadicCallType CallType,
5995+ bool inFunctionCall, VariadicCallType CallType,
59945996 llvm::SmallBitVector &CheckedVarArgs, UncoveredArgHandler &UncoveredArg,
59955997 bool IgnoreStringsWithoutSpecifiers);
59965998
@@ -6005,7 +6007,7 @@ static StringLiteralCheckType checkFormatStringExpr(
60056007 Sema &S, const StringLiteral *ReferenceFormatString, const Expr *E,
60066008 ArrayRef<const Expr *> Args, Sema::FormatArgumentPassingKind APK,
60076009 unsigned format_idx, unsigned firstDataArg, FormatStringType Type,
6008- Sema:: VariadicCallType CallType, bool InFunctionCall,
6010+ VariadicCallType CallType, bool InFunctionCall,
60096011 llvm::SmallBitVector &CheckedVarArgs, UncoveredArgHandler &UncoveredArg,
60106012 llvm::APSInt Offset, bool IgnoreStringsWithoutSpecifiers = false) {
60116013 if (S.isConstantEvaluatedContext())
@@ -6465,7 +6467,8 @@ bool Sema::CheckFormatArguments(const FormatAttr *Format,
64656467 llvm::SmallBitVector &CheckedVarArgs) {
64666468 FormatStringInfo FSI;
64676469 if (getFormatStringInfo(Format->getFormatIdx(), Format->getFirstArg(),
6468- IsCXXMember, CallType != VariadicDoesNotApply, &FSI))
6470+ IsCXXMember,
6471+ CallType != VariadicCallType::DoesNotApply, &FSI))
64696472 return CheckFormatArguments(
64706473 Args, FSI.ArgPassingKind, nullptr, FSI.FormatIdx, FSI.FirstDataArg,
64716474 GetFormatStringType(Format), CallType, Loc, Range, CheckedVarArgs);
@@ -6594,7 +6597,7 @@ class CheckFormatHandler : public analyze_format_string::FormatStringHandler {
65946597 bool usesPositionalArgs = false;
65956598 bool atFirstArg = true;
65966599 bool inFunctionCall;
6597- Sema:: VariadicCallType CallType;
6600+ VariadicCallType CallType;
65986601 llvm::SmallBitVector &CheckedVarArgs;
65996602 UncoveredArgHandler &UncoveredArg;
66006603
@@ -6604,7 +6607,7 @@ class CheckFormatHandler : public analyze_format_string::FormatStringHandler {
66046607 unsigned firstDataArg, unsigned numDataArgs,
66056608 const char *beg, Sema::FormatArgumentPassingKind APK,
66066609 ArrayRef<const Expr *> Args, unsigned formatIdx,
6607- bool inFunctionCall, Sema:: VariadicCallType callType,
6610+ bool inFunctionCall, VariadicCallType callType,
66086611 llvm::SmallBitVector &CheckedVarArgs,
66096612 UncoveredArgHandler &UncoveredArg)
66106613 : S(s), FExpr(fexpr), OrigFormatExpr(origFormatExpr), FSType(type),
@@ -7052,7 +7055,7 @@ class CheckPrintfHandler : public CheckFormatHandler {
70527055 unsigned firstDataArg, unsigned numDataArgs, bool isObjC,
70537056 const char *beg, Sema::FormatArgumentPassingKind APK,
70547057 ArrayRef<const Expr *> Args, unsigned formatIdx,
7055- bool inFunctionCall, Sema:: VariadicCallType CallType,
7058+ bool inFunctionCall, VariadicCallType CallType,
70567059 llvm::SmallBitVector &CheckedVarArgs,
70577060 UncoveredArgHandler &UncoveredArg)
70587061 : CheckFormatHandler(s, fexpr, origFormatExpr, type, firstDataArg,
@@ -7187,7 +7190,7 @@ class DecomposePrintfHandler : public CheckPrintfHandler {
71877190 unsigned numDataArgs, bool isObjC, const char *beg,
71887191 Sema::FormatArgumentPassingKind APK,
71897192 ArrayRef<const Expr *> Args, unsigned formatIdx,
7190- bool inFunctionCall, Sema:: VariadicCallType CallType,
7193+ bool inFunctionCall, VariadicCallType CallType,
71917194 llvm::SmallBitVector &CheckedVarArgs,
71927195 UncoveredArgHandler &UncoveredArg,
71937196 llvm::SmallVectorImpl<EquatableFormatArgument> &Specs)
@@ -7461,8 +7464,8 @@ bool DecomposePrintfHandler::GetSpecifiers(
74617464 const Expr *PrintfArgs[] = {FSL->getFormatString()};
74627465 DecomposePrintfHandler H(S, FSL, FSL->getFormatString(), Type, 0, 0, IsObjC,
74637466 Str, Sema::FAPK_Elsewhere, PrintfArgs, 0,
7464- InFunctionCall, Sema::VariadicDoesNotApply , BV, UA ,
7465- Args);
7467+ InFunctionCall, VariadicCallType::DoesNotApply , BV,
7468+ UA, Args);
74667469
74677470 if (!analyze_format_string::ParsePrintfString(
74687471 H, Str, Str + Data.size(), S.getLangOpts(), S.Context.getTargetInfo(),
@@ -8331,12 +8334,13 @@ CheckPrintfHandler::checkFormatExpr(const analyze_printf::PrintfSpecifier &FS,
83318334 }
83328335 case Sema::VAK_Undefined:
83338336 case Sema::VAK_MSVCUndefined:
8334- if (CallType == Sema::VariadicDoesNotApply ) {
8337+ if (CallType == VariadicCallType::DoesNotApply ) {
83358338 EmitTypeMismatch = true;
83368339 } else {
83378340 EmitFormatDiagnostic(
83388341 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)
83408344 << AT.getRepresentativeTypeName(S.Context) << CSR
83418345 << E->getSourceRange(),
83428346 E->getBeginLoc(), /*IsStringLocation*/ false, CSR);
@@ -8345,20 +8349,21 @@ CheckPrintfHandler::checkFormatExpr(const analyze_printf::PrintfSpecifier &FS,
83458349 break;
83468350
83478351 case Sema::VAK_Invalid:
8348- if (CallType == Sema::VariadicDoesNotApply )
8352+ if (CallType == VariadicCallType::DoesNotApply )
83498353 EmitTypeMismatch = true;
83508354 else if (ExprTy->isObjCObjectType())
83518355 EmitFormatDiagnostic(
83528356 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)
83548359 << AT.getRepresentativeTypeName(S.Context) << CSR
83558360 << E->getSourceRange(),
83568361 E->getBeginLoc(), /*IsStringLocation*/ false, CSR);
83578362 else
83588363 // FIXME: If this is an initializer list, suggest removing the braces
83598364 // or inserting a cast to the target type.
83608365 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)
83628367 << AT.getRepresentativeTypeName(S.Context) << E->getSourceRange();
83638368 break;
83648369 }
@@ -8395,7 +8400,7 @@ class CheckScanfHandler : public CheckFormatHandler {
83958400 unsigned firstDataArg, unsigned numDataArgs,
83968401 const char *beg, Sema::FormatArgumentPassingKind APK,
83978402 ArrayRef<const Expr *> Args, unsigned formatIdx,
8398- bool inFunctionCall, Sema:: VariadicCallType CallType,
8403+ bool inFunctionCall, VariadicCallType CallType,
83998404 llvm::SmallBitVector &CheckedVarArgs,
84008405 UncoveredArgHandler &UncoveredArg)
84018406 : CheckFormatHandler(s, fexpr, origFormatExpr, type, firstDataArg,
@@ -8624,7 +8629,7 @@ static void CheckFormatString(
86248629 const StringLiteral *ReferenceFormatString, const Expr *OrigFormatExpr,
86258630 ArrayRef<const Expr *> Args, Sema::FormatArgumentPassingKind APK,
86268631 unsigned format_idx, unsigned firstDataArg, FormatStringType Type,
8627- bool inFunctionCall, Sema:: VariadicCallType CallType,
8632+ bool inFunctionCall, VariadicCallType CallType,
86288633 llvm::SmallBitVector &CheckedVarArgs, UncoveredArgHandler &UncoveredArg,
86298634 bool IgnoreStringsWithoutSpecifiers) {
86308635 // CHECK: is the format string a wide literal?
0 commit comments