Author: Vlad Serebrennikov Date: 2025-05-02T11:02:01+03:00 New Revision: db247ddc9d5411ace70b478f7119eb44a43a8e5c
URL: https://github.com/llvm/llvm-project/commit/db247ddc9d5411ace70b478f7119eb44a43a8e5c DIFF: https://github.com/llvm/llvm-project/commit/db247ddc9d5411ace70b478f7119eb44a43a8e5c.diff LOG: [clang][NFC] Convert `Sema::ArithConvKind` to scoped enum Added: Modified: clang/include/clang/Sema/Sema.h clang/lib/Sema/SemaChecking.cpp clang/lib/Sema/SemaExpr.cpp clang/lib/Sema/SemaExprCXX.cpp Removed: ################################################################################ diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h index e5388fa4fe39d..b52754bd531f1 100644 --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -653,6 +653,20 @@ enum class AllowFoldKind { Allow, }; +/// Context in which we're performing a usual arithmetic conversion. +enum class ArithConvKind { + /// An arithmetic operation. + Arithmetic, + /// A bitwise operation. + BitwiseOp, + /// A comparison. + Comparison, + /// A conditional (?:) operator. + Conditional, + /// A compound assignment expression. + CompAssign, +}; + /// Sema - This implements semantic analysis and AST building for C. /// \nosubgrouping class Sema final : public SemaBase { @@ -7582,20 +7596,6 @@ class Sema final : public SemaBase { SourceLocation Loc, BinaryOperatorKind Opc); - /// Context in which we're performing a usual arithmetic conversion. - enum ArithConvKind { - /// An arithmetic operation. - ACK_Arithmetic, - /// A bitwise operation. - ACK_BitwiseOp, - /// A comparison. - ACK_Comparison, - /// A conditional (?:) operator. - ACK_Conditional, - /// A compound assignment expression. - ACK_CompAssign, - }; - // type checking for sizeless vector binary operators. QualType CheckSizelessVectorOperands(ExprResult &LHS, ExprResult &RHS, SourceLocation Loc, bool IsCompAssign, @@ -7758,7 +7758,7 @@ class Sema final : public SemaBase { // Check that the usual arithmetic conversions can be performed on this pair // of expressions that might be of enumeration type. void checkEnumArithmeticConversions(Expr *LHS, Expr *RHS, SourceLocation Loc, - Sema::ArithConvKind ACK); + ArithConvKind ACK); // UsualArithmeticConversions - performs the UsualUnaryConversions on it's // operands and then handles various conversions that are common to binary diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index fe80eea61f6d3..6847e9d3028bc 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -5060,7 +5060,7 @@ bool Sema::BuiltinUnorderedCompare(CallExpr *TheCall, unsigned BuiltinID) { // Do standard promotions between the two arguments, returning their common // type. QualType Res = UsualArithmeticConversions( - OrigArg0, OrigArg1, TheCall->getExprLoc(), ACK_Comparison); + OrigArg0, OrigArg1, TheCall->getExprLoc(), ArithConvKind::Comparison); if (OrigArg0.isInvalid() || OrigArg1.isInvalid()) return true; diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index a4d26aa49c90c..4628fb9fe2225 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -1509,7 +1509,7 @@ static QualType handleFixedPointConversion(Sema &S, QualType LHSTy, /// expressions that might be of enumeration type. void Sema::checkEnumArithmeticConversions(Expr *LHS, Expr *RHS, SourceLocation Loc, - Sema::ArithConvKind ACK) { + ArithConvKind ACK) { // C++2a [expr.arith.conv]p1: // If one operand is of enumeration type and the other operand is of a // diff erent enumeration type or a floating-point type, this behavior is @@ -1521,7 +1521,7 @@ void Sema::checkEnumArithmeticConversions(Expr *LHS, Expr *RHS, R = RHS->getEnumCoercedType(Context); bool LEnum = L->isUnscopedEnumerationType(), REnum = R->isUnscopedEnumerationType(); - bool IsCompAssign = ACK == Sema::ACK_CompAssign; + bool IsCompAssign = ACK == ArithConvKind::CompAssign; if ((!IsCompAssign && LEnum && R->isFloatingType()) || (REnum && L->isFloatingType())) { Diag(Loc, getLangOpts().CPlusPlus26 ? diag::err_arith_conv_enum_float_cxx26 @@ -1545,13 +1545,13 @@ void Sema::checkEnumArithmeticConversions(Expr *LHS, Expr *RHS, DiagID = getLangOpts().CPlusPlus20 ? diag::warn_arith_conv_mixed_anon_enum_types_cxx20 : diag::warn_arith_conv_mixed_anon_enum_types; - } else if (ACK == Sema::ACK_Conditional) { + } else if (ACK == ArithConvKind::Conditional) { // Conditional expressions are separated out because they have // historically had a diff erent warning flag. DiagID = getLangOpts().CPlusPlus20 ? diag::warn_conditional_mixed_enum_types_cxx20 : diag::warn_conditional_mixed_enum_types; - } else if (ACK == Sema::ACK_Comparison) { + } else if (ACK == ArithConvKind::Comparison) { // Comparison expressions are separated out because they have // historically had a diff erent warning flag. DiagID = getLangOpts().CPlusPlus20 @@ -1576,7 +1576,7 @@ QualType Sema::UsualArithmeticConversions(ExprResult &LHS, ExprResult &RHS, ArithConvKind ACK) { checkEnumArithmeticConversions(LHS.get(), RHS.get(), Loc, ACK); - if (ACK != ACK_CompAssign) { + if (ACK != ArithConvKind::CompAssign) { LHS = UsualUnaryConversions(LHS.get()); if (LHS.isInvalid()) return QualType(); @@ -1611,7 +1611,7 @@ QualType Sema::UsualArithmeticConversions(ExprResult &LHS, ExprResult &RHS, QualType LHSBitfieldPromoteTy = Context.isPromotableBitField(LHS.get()); if (!LHSBitfieldPromoteTy.isNull()) LHSType = LHSBitfieldPromoteTy; - if (LHSType != LHSUnpromotedType && ACK != ACK_CompAssign) + if (LHSType != LHSUnpromotedType && ACK != ArithConvKind::CompAssign) LHS = ImpCastExprToType(LHS.get(), LHSType, CK_IntegralCast); // If both types are identical, no conversion is needed. @@ -1628,24 +1628,24 @@ QualType Sema::UsualArithmeticConversions(ExprResult &LHS, ExprResult &RHS, // Handle complex types first (C99 6.3.1.8p1). if (LHSType->isComplexType() || RHSType->isComplexType()) return handleComplexConversion(*this, LHS, RHS, LHSType, RHSType, - ACK == ACK_CompAssign); + ACK == ArithConvKind::CompAssign); // Now handle "real" floating types (i.e. float, double, long double). if (LHSType->isRealFloatingType() || RHSType->isRealFloatingType()) return handleFloatConversion(*this, LHS, RHS, LHSType, RHSType, - ACK == ACK_CompAssign); + ACK == ArithConvKind::CompAssign); // Handle GCC complex int extension. if (LHSType->isComplexIntegerType() || RHSType->isComplexIntegerType()) return handleComplexIntConversion(*this, LHS, RHS, LHSType, RHSType, - ACK == ACK_CompAssign); + ACK == ArithConvKind::CompAssign); if (LHSType->isFixedPointType() || RHSType->isFixedPointType()) return handleFixedPointConversion(*this, LHSType, RHSType); // Finally, we have two diff ering integer types. - return handleIntegerConversion<doIntegralCast, doIntegralCast> - (*this, LHS, RHS, LHSType, RHSType, ACK == ACK_CompAssign); + return handleIntegerConversion<doIntegralCast, doIntegralCast>( + *this, LHS, RHS, LHSType, RHSType, ACK == ArithConvKind::CompAssign); } //===----------------------------------------------------------------------===// @@ -8537,8 +8537,8 @@ QualType Sema::CheckConditionalOperands(ExprResult &Cond, ExprResult &LHS, /*AllowBooleanOperation*/ false, /*ReportInvalid*/ true); - QualType ResTy = - UsualArithmeticConversions(LHS, RHS, QuestionLoc, ACK_Conditional); + QualType ResTy = UsualArithmeticConversions(LHS, RHS, QuestionLoc, + ArithConvKind::Conditional); if (LHS.isInvalid() || RHS.isInvalid()) return QualType(); @@ -10521,7 +10521,7 @@ QualType Sema::CheckSizelessVectorOperands(ExprResult &LHS, ExprResult &RHS, const BuiltinType *RHSBuiltinTy = RHSType->getAs<BuiltinType>(); unsigned DiagID = diag::err_typecheck_invalid_operands; - if ((OperationKind == ACK_Arithmetic) && + if ((OperationKind == ArithConvKind::Arithmetic) && ((LHSBuiltinTy && LHSBuiltinTy->isSVEBool()) || (RHSBuiltinTy && RHSBuiltinTy->isSVEBool()))) { Diag(Loc, DiagID) << LHSType << RHSType << LHS.get()->getSourceRange() @@ -10730,7 +10730,7 @@ QualType Sema::CheckMultiplyDivideOperands(ExprResult &LHS, ExprResult &RHS, /*ReportInvalid*/ true); if (LHSTy->isSveVLSBuiltinType() || RHSTy->isSveVLSBuiltinType()) return CheckSizelessVectorOperands(LHS, RHS, Loc, IsCompAssign, - ACK_Arithmetic); + ArithConvKind::Arithmetic); if (!IsDiv && (LHSTy->isConstantMatrixType() || RHSTy->isConstantMatrixType())) return CheckMatrixMultiplyOperands(LHS, RHS, Loc, IsCompAssign); @@ -10740,7 +10740,8 @@ QualType Sema::CheckMultiplyDivideOperands(ExprResult &LHS, ExprResult &RHS, return CheckMatrixElementwiseOperands(LHS, RHS, Loc, IsCompAssign); QualType compType = UsualArithmeticConversions( - LHS, RHS, Loc, IsCompAssign ? ACK_CompAssign : ACK_Arithmetic); + LHS, RHS, Loc, + IsCompAssign ? ArithConvKind::CompAssign : ArithConvKind::Arithmetic); if (LHS.isInvalid() || RHS.isInvalid()) return QualType(); @@ -10796,13 +10797,14 @@ QualType Sema::CheckRemainderOperands( if (LHS.get()->getType()->hasIntegerRepresentation() && RHS.get()->getType()->hasIntegerRepresentation()) return CheckSizelessVectorOperands(LHS, RHS, Loc, IsCompAssign, - ACK_Arithmetic); + ArithConvKind::Arithmetic); return InvalidOperands(Loc, LHS, RHS); } QualType compType = UsualArithmeticConversions( - LHS, RHS, Loc, IsCompAssign ? ACK_CompAssign : ACK_Arithmetic); + LHS, RHS, Loc, + IsCompAssign ? ArithConvKind::CompAssign : ArithConvKind::Arithmetic); if (LHS.isInvalid() || RHS.isInvalid()) return QualType(); @@ -11115,8 +11117,8 @@ QualType Sema::CheckAdditionOperands(ExprResult &LHS, ExprResult &RHS, if (LHS.get()->getType()->isSveVLSBuiltinType() || RHS.get()->getType()->isSveVLSBuiltinType()) { - QualType compType = - CheckSizelessVectorOperands(LHS, RHS, Loc, CompLHSTy, ACK_Arithmetic); + QualType compType = CheckSizelessVectorOperands(LHS, RHS, Loc, CompLHSTy, + ArithConvKind::Arithmetic); if (CompLHSTy) *CompLHSTy = compType; return compType; @@ -11132,7 +11134,8 @@ QualType Sema::CheckAdditionOperands(ExprResult &LHS, ExprResult &RHS, } QualType compType = UsualArithmeticConversions( - LHS, RHS, Loc, CompLHSTy ? ACK_CompAssign : ACK_Arithmetic); + LHS, RHS, Loc, + CompLHSTy ? ArithConvKind::CompAssign : ArithConvKind::Arithmetic); if (LHS.isInvalid() || RHS.isInvalid()) return QualType(); @@ -11238,8 +11241,8 @@ QualType Sema::CheckSubtractionOperands(ExprResult &LHS, ExprResult &RHS, if (LHS.get()->getType()->isSveVLSBuiltinType() || RHS.get()->getType()->isSveVLSBuiltinType()) { - QualType compType = - CheckSizelessVectorOperands(LHS, RHS, Loc, CompLHSTy, ACK_Arithmetic); + QualType compType = CheckSizelessVectorOperands(LHS, RHS, Loc, CompLHSTy, + ArithConvKind::Arithmetic); if (CompLHSTy) *CompLHSTy = compType; return compType; @@ -11255,7 +11258,8 @@ QualType Sema::CheckSubtractionOperands(ExprResult &LHS, ExprResult &RHS, } QualType compType = UsualArithmeticConversions( - LHS, RHS, Loc, CompLHSTy ? ACK_CompAssign : ACK_Arithmetic); + LHS, RHS, Loc, + CompLHSTy ? ArithConvKind::CompAssign : ArithConvKind::Arithmetic); if (LHS.isInvalid() || RHS.isInvalid()) return QualType(); @@ -12277,7 +12281,7 @@ static QualType checkArithmeticOrEnumeralThreeWayCompare(Sema &S, // C++2a [expr.spaceship]p4: If both operands have arithmetic types, the // usual arithmetic conversions are applied to the operands. QualType Type = - S.UsualArithmeticConversions(LHS, RHS, Loc, Sema::ACK_Comparison); + S.UsualArithmeticConversions(LHS, RHS, Loc, ArithConvKind::Comparison); if (LHS.isInvalid() || RHS.isInvalid()) return QualType(); if (Type.isNull()) @@ -12310,7 +12314,7 @@ static QualType checkArithmeticOrEnumeralCompare(Sema &S, ExprResult &LHS, // C99 6.5.8p3 / C99 6.5.9p4 QualType Type = - S.UsualArithmeticConversions(LHS, RHS, Loc, Sema::ACK_Comparison); + S.UsualArithmeticConversions(LHS, RHS, Loc, ArithConvKind::Comparison); if (LHS.isInvalid() || RHS.isInvalid()) return QualType(); if (Type.isNull()) @@ -12972,7 +12976,7 @@ QualType Sema::CheckSizelessVectorCompareOperands(ExprResult &LHS, // Check to make sure we're operating on vectors of the same type and width, // Allowing one side to be a scalar of element type. QualType vType = CheckSizelessVectorOperands( - LHS, RHS, Loc, /*isCompAssign*/ false, ACK_Comparison); + LHS, RHS, Loc, /*isCompAssign*/ false, ArithConvKind::Comparison); if (vType.isNull()) return vType; @@ -13282,7 +13286,7 @@ inline QualType Sema::CheckBitwiseOperands(ExprResult &LHS, ExprResult &RHS, if (LHS.get()->getType()->hasIntegerRepresentation() && RHS.get()->getType()->hasIntegerRepresentation()) return CheckSizelessVectorOperands(LHS, RHS, Loc, IsCompAssign, - ACK_BitwiseOp); + ArithConvKind::BitwiseOp); return InvalidOperands(Loc, LHS, RHS); } @@ -13291,7 +13295,7 @@ inline QualType Sema::CheckBitwiseOperands(ExprResult &LHS, ExprResult &RHS, if (LHS.get()->getType()->hasIntegerRepresentation() && RHS.get()->getType()->hasIntegerRepresentation()) return CheckSizelessVectorOperands(LHS, RHS, Loc, IsCompAssign, - ACK_BitwiseOp); + ArithConvKind::BitwiseOp); return InvalidOperands(Loc, LHS, RHS); } @@ -13304,7 +13308,8 @@ inline QualType Sema::CheckBitwiseOperands(ExprResult &LHS, ExprResult &RHS, ExprResult LHSResult = LHS, RHSResult = RHS; QualType compType = UsualArithmeticConversions( - LHSResult, RHSResult, Loc, IsCompAssign ? ACK_CompAssign : ACK_BitwiseOp); + LHSResult, RHSResult, Loc, + IsCompAssign ? ArithConvKind::CompAssign : ArithConvKind::BitwiseOp); if (LHSResult.isInvalid() || RHSResult.isInvalid()) return QualType(); LHS = LHSResult.get(); diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp index 2ddad292f7636..998a45477d3d6 100644 --- a/clang/lib/Sema/SemaExprCXX.cpp +++ b/clang/lib/Sema/SemaExprCXX.cpp @@ -7191,7 +7191,7 @@ QualType Sema::CheckVectorConditionalTypes(ExprResult &Cond, ExprResult &LHS, Context.hasSameType(LHSType, RHSType) ? Context.getCommonSugaredType(LHSType, RHSType) : UsualArithmeticConversions(LHS, RHS, QuestionLoc, - ACK_Conditional); + ArithConvKind::Conditional); if (ResultElementTy->isEnumeralType()) { Diag(QuestionLoc, diag::err_conditional_vector_operand_type) @@ -7263,8 +7263,9 @@ QualType Sema::CheckSizelessVectorConditionalTypes(ExprResult &Cond, } ResultType = LHSType; } else if (LHSBT || RHSBT) { - ResultType = CheckSizelessVectorOperands( - LHS, RHS, QuestionLoc, /*IsCompAssign*/ false, ACK_Conditional); + ResultType = CheckSizelessVectorOperands(LHS, RHS, QuestionLoc, + /*IsCompAssign*/ false, + ArithConvKind::Conditional); if (ResultType.isNull()) return QualType(); } else { @@ -7276,8 +7277,8 @@ QualType Sema::CheckSizelessVectorConditionalTypes(ExprResult &Cond, if (Context.hasSameType(LHSType, RHSType)) ResultElementTy = LHSType; else - ResultElementTy = - UsualArithmeticConversions(LHS, RHS, QuestionLoc, ACK_Conditional); + ResultElementTy = UsualArithmeticConversions(LHS, RHS, QuestionLoc, + ArithConvKind::Conditional); if (ResultElementTy->isEnumeralType()) { Diag(QuestionLoc, diag::err_conditional_vector_operand_type) @@ -7565,8 +7566,8 @@ QualType Sema::CXXCheckConditionalOperands(ExprResult &Cond, ExprResult &LHS, // the usual arithmetic conversions are performed to bring them to a // common type, and the result is of that type. if (LTy->isArithmeticType() && RTy->isArithmeticType()) { - QualType ResTy = - UsualArithmeticConversions(LHS, RHS, QuestionLoc, ACK_Conditional); + QualType ResTy = UsualArithmeticConversions(LHS, RHS, QuestionLoc, + ArithConvKind::Conditional); if (LHS.isInvalid() || RHS.isInvalid()) return QualType(); if (ResTy.isNull()) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits