Skip to content

Commit a0bde6e

Browse files
EndilllGeorgeARM
authored andcommitted
[clang][NFC] Convert Sema::VarArgKind to scoped enum
1 parent eca2ae5 commit a0bde6e

File tree

3 files changed

+35
-35
lines changed

3 files changed

+35
-35
lines changed

clang/include/clang/Sema/Sema.h

+10-10
Original file line numberDiff line numberDiff line change
@@ -667,6 +667,16 @@ enum class ArithConvKind {
667667
CompAssign,
668668
};
669669

670+
// Used for determining in which context a type is allowed to be passed to a
671+
// vararg function.
672+
enum class VarArgKind {
673+
Valid,
674+
ValidInCXX11,
675+
Undefined,
676+
MSVCUndefined,
677+
Invalid
678+
};
679+
670680
/// Sema - This implements semantic analysis and AST building for C.
671681
/// \nosubgrouping
672682
class Sema final : public SemaBase {
@@ -7722,16 +7732,6 @@ class Sema final : public SemaBase {
77227732
const FunctionProtoType *Proto,
77237733
Expr *Fn);
77247734

7725-
// Used for determining in which context a type is allowed to be passed to a
7726-
// vararg function.
7727-
enum VarArgKind {
7728-
VAK_Valid,
7729-
VAK_ValidInCXX11,
7730-
VAK_Undefined,
7731-
VAK_MSVCUndefined,
7732-
VAK_Invalid
7733-
};
7734-
77357735
/// Determine the degree of POD-ness for an expression.
77367736
/// Incomplete types are considered POD, since this check can be performed
77377737
/// when we're in an unevaluated context.

clang/lib/Sema/SemaChecking.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -8306,8 +8306,8 @@ CheckPrintfHandler::checkFormatExpr(const analyze_printf::PrintfSpecifier &FS,
83068306
// arguments here.
83078307
bool EmitTypeMismatch = false;
83088308
switch (S.isValidVarArgType(ExprTy)) {
8309-
case Sema::VAK_Valid:
8310-
case Sema::VAK_ValidInCXX11: {
8309+
case VarArgKind::Valid:
8310+
case VarArgKind::ValidInCXX11: {
83118311
unsigned Diag;
83128312
switch (Match) {
83138313
case ArgType::Match:
@@ -8332,8 +8332,8 @@ CheckPrintfHandler::checkFormatExpr(const analyze_printf::PrintfSpecifier &FS,
83328332
E->getBeginLoc(), /*IsStringLocation*/ false, CSR);
83338333
break;
83348334
}
8335-
case Sema::VAK_Undefined:
8336-
case Sema::VAK_MSVCUndefined:
8335+
case VarArgKind::Undefined:
8336+
case VarArgKind::MSVCUndefined:
83378337
if (CallType == VariadicCallType::DoesNotApply) {
83388338
EmitTypeMismatch = true;
83398339
} else {
@@ -8347,7 +8347,7 @@ CheckPrintfHandler::checkFormatExpr(const analyze_printf::PrintfSpecifier &FS,
83478347
}
83488348
break;
83498349

8350-
case Sema::VAK_Invalid:
8350+
case VarArgKind::Invalid:
83518351
if (CallType == VariadicCallType::DoesNotApply)
83528352
EmitTypeMismatch = true;
83538353
else if (ExprTy->isObjCObjectType())

clang/lib/Sema/SemaExpr.cpp

+20-20
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ ExprResult Sema::DefaultArgumentPromotion(Expr *E) {
951951
return E;
952952
}
953953

954-
Sema::VarArgKind Sema::isValidVarArgType(const QualType &Ty) {
954+
VarArgKind Sema::isValidVarArgType(const QualType &Ty) {
955955
if (Ty->isIncompleteType()) {
956956
// C++11 [expr.call]p7:
957957
// After these conversions, if the argument does not have arithmetic,
@@ -962,23 +962,23 @@ Sema::VarArgKind Sema::isValidVarArgType(const QualType &Ty) {
962962
// decay and function-to-pointer decay, the only such type in C++ is cv
963963
// void. This also handles initializer lists as variadic arguments.
964964
if (Ty->isVoidType())
965-
return VAK_Invalid;
965+
return VarArgKind::Invalid;
966966

967967
if (Ty->isObjCObjectType())
968-
return VAK_Invalid;
969-
return VAK_Valid;
968+
return VarArgKind::Invalid;
969+
return VarArgKind::Valid;
970970
}
971971

972972
if (Ty.isDestructedType() == QualType::DK_nontrivial_c_struct)
973-
return VAK_Invalid;
973+
return VarArgKind::Invalid;
974974

975975
if (Context.getTargetInfo().getTriple().isWasm() &&
976976
Ty.isWebAssemblyReferenceType()) {
977-
return VAK_Invalid;
977+
return VarArgKind::Invalid;
978978
}
979979

980980
if (Ty.isCXX98PODType(Context))
981-
return VAK_Valid;
981+
return VarArgKind::Valid;
982982

983983
// C++11 [expr.call]p7:
984984
// Passing a potentially-evaluated argument of class type (Clause 9)
@@ -990,26 +990,26 @@ Sema::VarArgKind Sema::isValidVarArgType(const QualType &Ty) {
990990
if (!Record->hasNonTrivialCopyConstructor() &&
991991
!Record->hasNonTrivialMoveConstructor() &&
992992
!Record->hasNonTrivialDestructor())
993-
return VAK_ValidInCXX11;
993+
return VarArgKind::ValidInCXX11;
994994

995995
if (getLangOpts().ObjCAutoRefCount && Ty->isObjCLifetimeType())
996-
return VAK_Valid;
996+
return VarArgKind::Valid;
997997

998998
if (Ty->isObjCObjectType())
999-
return VAK_Invalid;
999+
return VarArgKind::Invalid;
10001000

10011001
if (getLangOpts().HLSL && Ty->getAs<HLSLAttributedResourceType>())
1002-
return VAK_Valid;
1002+
return VarArgKind::Valid;
10031003

10041004
if (getLangOpts().MSVCCompat)
1005-
return VAK_MSVCUndefined;
1005+
return VarArgKind::MSVCUndefined;
10061006

10071007
if (getLangOpts().HLSL && Ty->getAs<HLSLAttributedResourceType>())
1008-
return VAK_Valid;
1008+
return VarArgKind::Valid;
10091009

10101010
// FIXME: In C++11, these cases are conditionally-supported, meaning we're
10111011
// permitted to reject them. We should consider doing so.
1012-
return VAK_Undefined;
1012+
return VarArgKind::Undefined;
10131013
}
10141014

10151015
void Sema::checkVariadicArgument(const Expr *E, VariadicCallType CT) {
@@ -1019,12 +1019,12 @@ void Sema::checkVariadicArgument(const Expr *E, VariadicCallType CT) {
10191019

10201020
// Complain about passing non-POD types through varargs.
10211021
switch (VAK) {
1022-
case VAK_ValidInCXX11:
1022+
case VarArgKind::ValidInCXX11:
10231023
DiagRuntimeBehavior(
10241024
E->getBeginLoc(), nullptr,
10251025
PDiag(diag::warn_cxx98_compat_pass_non_pod_arg_to_vararg) << Ty << CT);
10261026
[[fallthrough]];
1027-
case VAK_Valid:
1027+
case VarArgKind::Valid:
10281028
if (Ty->isRecordType()) {
10291029
// This is unlikely to be what the user intended. If the class has a
10301030
// 'c_str' member function, the user probably meant to call that.
@@ -1034,14 +1034,14 @@ void Sema::checkVariadicArgument(const Expr *E, VariadicCallType CT) {
10341034
}
10351035
break;
10361036

1037-
case VAK_Undefined:
1038-
case VAK_MSVCUndefined:
1037+
case VarArgKind::Undefined:
1038+
case VarArgKind::MSVCUndefined:
10391039
DiagRuntimeBehavior(E->getBeginLoc(), nullptr,
10401040
PDiag(diag::warn_cannot_pass_non_pod_arg_to_vararg)
10411041
<< getLangOpts().CPlusPlus11 << Ty << CT);
10421042
break;
10431043

1044-
case VAK_Invalid:
1044+
case VarArgKind::Invalid:
10451045
if (Ty.isDestructedType() == QualType::DK_nontrivial_c_struct)
10461046
Diag(E->getBeginLoc(),
10471047
diag::err_cannot_pass_non_trivial_c_struct_to_vararg)
@@ -1087,7 +1087,7 @@ ExprResult Sema::DefaultVariadicArgumentPromotion(Expr *E, VariadicCallType CT,
10871087

10881088
// Diagnostics regarding non-POD argument types are
10891089
// emitted along with format string checking in Sema::CheckFunctionCall().
1090-
if (isValidVarArgType(E->getType()) == VAK_Undefined) {
1090+
if (isValidVarArgType(E->getType()) == VarArgKind::Undefined) {
10911091
// Turn this into a trap.
10921092
CXXScopeSpec SS;
10931093
SourceLocation TemplateKWLoc;

0 commit comments

Comments
 (0)