Author: Vlad Serebrennikov Date: 2025-05-02T11:24:08+03:00 New Revision: d0dcfd4c68171c3b9b863626c08efa7f38cd0c54
URL: https://github.com/llvm/llvm-project/commit/d0dcfd4c68171c3b9b863626c08efa7f38cd0c54 DIFF: https://github.com/llvm/llvm-project/commit/d0dcfd4c68171c3b9b863626c08efa7f38cd0c54.diff LOG: [clang][NFC] Convert `Sema::VarArgKind` to scoped enum Added: Modified: clang/include/clang/Sema/Sema.h clang/lib/Sema/SemaChecking.cpp clang/lib/Sema/SemaExpr.cpp Removed: ################################################################################ diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index b52754bd531f1..e0abc0a3193ac 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -667,6 +667,16 @@ enum class ArithConvKind { CompAssign, }; +// Used for determining in which context a type is allowed to be passed to a +// vararg function. +enum class VarArgKind { + Valid, + ValidInCXX11, + Undefined, + MSVCUndefined, + Invalid +}; + /// Sema - This implements semantic analysis and AST building for C. /// \nosubgrouping class Sema final : public SemaBase { @@ -7722,16 +7732,6 @@ class Sema final : public SemaBase { const FunctionProtoType *Proto, Expr *Fn); - // Used for determining in which context a type is allowed to be passed to a - // vararg function. - enum VarArgKind { - VAK_Valid, - VAK_ValidInCXX11, - VAK_Undefined, - VAK_MSVCUndefined, - VAK_Invalid - }; - /// Determine the degree of POD-ness for an expression. /// Incomplete types are considered POD, since this check can be performed /// when we're in an unevaluated context. diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 6847e9d3028bc..97f623f61a405 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -8306,8 +8306,8 @@ CheckPrintfHandler::checkFormatExpr(const analyze_printf::PrintfSpecifier &FS, // arguments here. bool EmitTypeMismatch = false; switch (S.isValidVarArgType(ExprTy)) { - case Sema::VAK_Valid: - case Sema::VAK_ValidInCXX11: { + case VarArgKind::Valid: + case VarArgKind::ValidInCXX11: { unsigned Diag; switch (Match) { case ArgType::Match: @@ -8332,8 +8332,8 @@ CheckPrintfHandler::checkFormatExpr(const analyze_printf::PrintfSpecifier &FS, E->getBeginLoc(), /*IsStringLocation*/ false, CSR); break; } - case Sema::VAK_Undefined: - case Sema::VAK_MSVCUndefined: + case VarArgKind::Undefined: + case VarArgKind::MSVCUndefined: if (CallType == VariadicCallType::DoesNotApply) { EmitTypeMismatch = true; } else { @@ -8347,7 +8347,7 @@ CheckPrintfHandler::checkFormatExpr(const analyze_printf::PrintfSpecifier &FS, } break; - case Sema::VAK_Invalid: + case VarArgKind::Invalid: if (CallType == VariadicCallType::DoesNotApply) EmitTypeMismatch = true; else if (ExprTy->isObjCObjectType()) diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 4628fb9fe2225..38b04e7c2802b 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -951,7 +951,7 @@ ExprResult Sema::DefaultArgumentPromotion(Expr *E) { return E; } -Sema::VarArgKind Sema::isValidVarArgType(const QualType &Ty) { +VarArgKind Sema::isValidVarArgType(const QualType &Ty) { if (Ty->isIncompleteType()) { // C++11 [expr.call]p7: // After these conversions, if the argument does not have arithmetic, @@ -962,23 +962,23 @@ Sema::VarArgKind Sema::isValidVarArgType(const QualType &Ty) { // decay and function-to-pointer decay, the only such type in C++ is cv // void. This also handles initializer lists as variadic arguments. if (Ty->isVoidType()) - return VAK_Invalid; + return VarArgKind::Invalid; if (Ty->isObjCObjectType()) - return VAK_Invalid; - return VAK_Valid; + return VarArgKind::Invalid; + return VarArgKind::Valid; } if (Ty.isDestructedType() == QualType::DK_nontrivial_c_struct) - return VAK_Invalid; + return VarArgKind::Invalid; if (Context.getTargetInfo().getTriple().isWasm() && Ty.isWebAssemblyReferenceType()) { - return VAK_Invalid; + return VarArgKind::Invalid; } if (Ty.isCXX98PODType(Context)) - return VAK_Valid; + return VarArgKind::Valid; // C++11 [expr.call]p7: // Passing a potentially-evaluated argument of class type (Clause 9) @@ -990,26 +990,26 @@ Sema::VarArgKind Sema::isValidVarArgType(const QualType &Ty) { if (!Record->hasNonTrivialCopyConstructor() && !Record->hasNonTrivialMoveConstructor() && !Record->hasNonTrivialDestructor()) - return VAK_ValidInCXX11; + return VarArgKind::ValidInCXX11; if (getLangOpts().ObjCAutoRefCount && Ty->isObjCLifetimeType()) - return VAK_Valid; + return VarArgKind::Valid; if (Ty->isObjCObjectType()) - return VAK_Invalid; + return VarArgKind::Invalid; if (getLangOpts().HLSL && Ty->getAs<HLSLAttributedResourceType>()) - return VAK_Valid; + return VarArgKind::Valid; if (getLangOpts().MSVCCompat) - return VAK_MSVCUndefined; + return VarArgKind::MSVCUndefined; if (getLangOpts().HLSL && Ty->getAs<HLSLAttributedResourceType>()) - return VAK_Valid; + return VarArgKind::Valid; // FIXME: In C++11, these cases are conditionally-supported, meaning we're // permitted to reject them. We should consider doing so. - return VAK_Undefined; + return VarArgKind::Undefined; } void Sema::checkVariadicArgument(const Expr *E, VariadicCallType CT) { @@ -1019,12 +1019,12 @@ void Sema::checkVariadicArgument(const Expr *E, VariadicCallType CT) { // Complain about passing non-POD types through varargs. switch (VAK) { - case VAK_ValidInCXX11: + case VarArgKind::ValidInCXX11: DiagRuntimeBehavior( E->getBeginLoc(), nullptr, PDiag(diag::warn_cxx98_compat_pass_non_pod_arg_to_vararg) << Ty << CT); [[fallthrough]]; - case VAK_Valid: + case VarArgKind::Valid: if (Ty->isRecordType()) { // This is unlikely to be what the user intended. If the class has a // 'c_str' member function, the user probably meant to call that. @@ -1034,14 +1034,14 @@ void Sema::checkVariadicArgument(const Expr *E, VariadicCallType CT) { } break; - case VAK_Undefined: - case VAK_MSVCUndefined: + case VarArgKind::Undefined: + case VarArgKind::MSVCUndefined: DiagRuntimeBehavior(E->getBeginLoc(), nullptr, PDiag(diag::warn_cannot_pass_non_pod_arg_to_vararg) << getLangOpts().CPlusPlus11 << Ty << CT); break; - case VAK_Invalid: + case VarArgKind::Invalid: if (Ty.isDestructedType() == QualType::DK_nontrivial_c_struct) Diag(E->getBeginLoc(), diag::err_cannot_pass_non_trivial_c_struct_to_vararg) @@ -1087,7 +1087,7 @@ ExprResult Sema::DefaultVariadicArgumentPromotion(Expr *E, VariadicCallType CT, // Diagnostics regarding non-POD argument types are // emitted along with format string checking in Sema::CheckFunctionCall(). - if (isValidVarArgType(E->getType()) == VAK_Undefined) { + if (isValidVarArgType(E->getType()) == VarArgKind::Undefined) { // Turn this into a trap. CXXScopeSpec SS; SourceLocation TemplateKWLoc; _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits