Skip to content

Commit cf6d868

Browse files
EndilllGeorgeARM
authored andcommitted
[clang][NFC] Convert Sema::ArithConvKind to scoped enum
1 parent 5858448 commit cf6d868

File tree

4 files changed

+59
-53
lines changed

4 files changed

+59
-53
lines changed

clang/include/clang/Sema/Sema.h

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -653,6 +653,20 @@ enum class AllowFoldKind {
653653
Allow,
654654
};
655655

656+
/// Context in which we're performing a usual arithmetic conversion.
657+
enum class ArithConvKind {
658+
/// An arithmetic operation.
659+
Arithmetic,
660+
/// A bitwise operation.
661+
BitwiseOp,
662+
/// A comparison.
663+
Comparison,
664+
/// A conditional (?:) operator.
665+
Conditional,
666+
/// A compound assignment expression.
667+
CompAssign,
668+
};
669+
656670
/// Sema - This implements semantic analysis and AST building for C.
657671
/// \nosubgrouping
658672
class Sema final : public SemaBase {
@@ -7582,20 +7596,6 @@ class Sema final : public SemaBase {
75827596
SourceLocation Loc,
75837597
BinaryOperatorKind Opc);
75847598

7585-
/// Context in which we're performing a usual arithmetic conversion.
7586-
enum ArithConvKind {
7587-
/// An arithmetic operation.
7588-
ACK_Arithmetic,
7589-
/// A bitwise operation.
7590-
ACK_BitwiseOp,
7591-
/// A comparison.
7592-
ACK_Comparison,
7593-
/// A conditional (?:) operator.
7594-
ACK_Conditional,
7595-
/// A compound assignment expression.
7596-
ACK_CompAssign,
7597-
};
7598-
75997599
// type checking for sizeless vector binary operators.
76007600
QualType CheckSizelessVectorOperands(ExprResult &LHS, ExprResult &RHS,
76017601
SourceLocation Loc, bool IsCompAssign,
@@ -7758,7 +7758,7 @@ class Sema final : public SemaBase {
77587758
// Check that the usual arithmetic conversions can be performed on this pair
77597759
// of expressions that might be of enumeration type.
77607760
void checkEnumArithmeticConversions(Expr *LHS, Expr *RHS, SourceLocation Loc,
7761-
Sema::ArithConvKind ACK);
7761+
ArithConvKind ACK);
77627762

77637763
// UsualArithmeticConversions - performs the UsualUnaryConversions on it's
77647764
// operands and then handles various conversions that are common to binary

clang/lib/Sema/SemaChecking.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5060,7 +5060,7 @@ bool Sema::BuiltinUnorderedCompare(CallExpr *TheCall, unsigned BuiltinID) {
50605060
// Do standard promotions between the two arguments, returning their common
50615061
// type.
50625062
QualType Res = UsualArithmeticConversions(
5063-
OrigArg0, OrigArg1, TheCall->getExprLoc(), ACK_Comparison);
5063+
OrigArg0, OrigArg1, TheCall->getExprLoc(), ArithConvKind::Comparison);
50645064
if (OrigArg0.isInvalid() || OrigArg1.isInvalid())
50655065
return true;
50665066

clang/lib/Sema/SemaExpr.cpp

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1509,7 +1509,7 @@ static QualType handleFixedPointConversion(Sema &S, QualType LHSTy,
15091509
/// expressions that might be of enumeration type.
15101510
void Sema::checkEnumArithmeticConversions(Expr *LHS, Expr *RHS,
15111511
SourceLocation Loc,
1512-
Sema::ArithConvKind ACK) {
1512+
ArithConvKind ACK) {
15131513
// C++2a [expr.arith.conv]p1:
15141514
// If one operand is of enumeration type and the other operand is of a
15151515
// different enumeration type or a floating-point type, this behavior is
@@ -1521,7 +1521,7 @@ void Sema::checkEnumArithmeticConversions(Expr *LHS, Expr *RHS,
15211521
R = RHS->getEnumCoercedType(Context);
15221522
bool LEnum = L->isUnscopedEnumerationType(),
15231523
REnum = R->isUnscopedEnumerationType();
1524-
bool IsCompAssign = ACK == Sema::ACK_CompAssign;
1524+
bool IsCompAssign = ACK == ArithConvKind::CompAssign;
15251525
if ((!IsCompAssign && LEnum && R->isFloatingType()) ||
15261526
(REnum && L->isFloatingType())) {
15271527
Diag(Loc, getLangOpts().CPlusPlus26 ? diag::err_arith_conv_enum_float_cxx26
@@ -1545,13 +1545,13 @@ void Sema::checkEnumArithmeticConversions(Expr *LHS, Expr *RHS,
15451545
DiagID = getLangOpts().CPlusPlus20
15461546
? diag::warn_arith_conv_mixed_anon_enum_types_cxx20
15471547
: diag::warn_arith_conv_mixed_anon_enum_types;
1548-
} else if (ACK == Sema::ACK_Conditional) {
1548+
} else if (ACK == ArithConvKind::Conditional) {
15491549
// Conditional expressions are separated out because they have
15501550
// historically had a different warning flag.
15511551
DiagID = getLangOpts().CPlusPlus20
15521552
? diag::warn_conditional_mixed_enum_types_cxx20
15531553
: diag::warn_conditional_mixed_enum_types;
1554-
} else if (ACK == Sema::ACK_Comparison) {
1554+
} else if (ACK == ArithConvKind::Comparison) {
15551555
// Comparison expressions are separated out because they have
15561556
// historically had a different warning flag.
15571557
DiagID = getLangOpts().CPlusPlus20
@@ -1576,7 +1576,7 @@ QualType Sema::UsualArithmeticConversions(ExprResult &LHS, ExprResult &RHS,
15761576
ArithConvKind ACK) {
15771577
checkEnumArithmeticConversions(LHS.get(), RHS.get(), Loc, ACK);
15781578

1579-
if (ACK != ACK_CompAssign) {
1579+
if (ACK != ArithConvKind::CompAssign) {
15801580
LHS = UsualUnaryConversions(LHS.get());
15811581
if (LHS.isInvalid())
15821582
return QualType();
@@ -1611,7 +1611,7 @@ QualType Sema::UsualArithmeticConversions(ExprResult &LHS, ExprResult &RHS,
16111611
QualType LHSBitfieldPromoteTy = Context.isPromotableBitField(LHS.get());
16121612
if (!LHSBitfieldPromoteTy.isNull())
16131613
LHSType = LHSBitfieldPromoteTy;
1614-
if (LHSType != LHSUnpromotedType && ACK != ACK_CompAssign)
1614+
if (LHSType != LHSUnpromotedType && ACK != ArithConvKind::CompAssign)
16151615
LHS = ImpCastExprToType(LHS.get(), LHSType, CK_IntegralCast);
16161616

16171617
// If both types are identical, no conversion is needed.
@@ -1628,24 +1628,24 @@ QualType Sema::UsualArithmeticConversions(ExprResult &LHS, ExprResult &RHS,
16281628
// Handle complex types first (C99 6.3.1.8p1).
16291629
if (LHSType->isComplexType() || RHSType->isComplexType())
16301630
return handleComplexConversion(*this, LHS, RHS, LHSType, RHSType,
1631-
ACK == ACK_CompAssign);
1631+
ACK == ArithConvKind::CompAssign);
16321632

16331633
// Now handle "real" floating types (i.e. float, double, long double).
16341634
if (LHSType->isRealFloatingType() || RHSType->isRealFloatingType())
16351635
return handleFloatConversion(*this, LHS, RHS, LHSType, RHSType,
1636-
ACK == ACK_CompAssign);
1636+
ACK == ArithConvKind::CompAssign);
16371637

16381638
// Handle GCC complex int extension.
16391639
if (LHSType->isComplexIntegerType() || RHSType->isComplexIntegerType())
16401640
return handleComplexIntConversion(*this, LHS, RHS, LHSType, RHSType,
1641-
ACK == ACK_CompAssign);
1641+
ACK == ArithConvKind::CompAssign);
16421642

16431643
if (LHSType->isFixedPointType() || RHSType->isFixedPointType())
16441644
return handleFixedPointConversion(*this, LHSType, RHSType);
16451645

16461646
// Finally, we have two differing integer types.
1647-
return handleIntegerConversion<doIntegralCast, doIntegralCast>
1648-
(*this, LHS, RHS, LHSType, RHSType, ACK == ACK_CompAssign);
1647+
return handleIntegerConversion<doIntegralCast, doIntegralCast>(
1648+
*this, LHS, RHS, LHSType, RHSType, ACK == ArithConvKind::CompAssign);
16491649
}
16501650

16511651
//===----------------------------------------------------------------------===//
@@ -8537,8 +8537,8 @@ QualType Sema::CheckConditionalOperands(ExprResult &Cond, ExprResult &LHS,
85378537
/*AllowBooleanOperation*/ false,
85388538
/*ReportInvalid*/ true);
85398539

8540-
QualType ResTy =
8541-
UsualArithmeticConversions(LHS, RHS, QuestionLoc, ACK_Conditional);
8540+
QualType ResTy = UsualArithmeticConversions(LHS, RHS, QuestionLoc,
8541+
ArithConvKind::Conditional);
85428542
if (LHS.isInvalid() || RHS.isInvalid())
85438543
return QualType();
85448544

@@ -10521,7 +10521,7 @@ QualType Sema::CheckSizelessVectorOperands(ExprResult &LHS, ExprResult &RHS,
1052110521
const BuiltinType *RHSBuiltinTy = RHSType->getAs<BuiltinType>();
1052210522

1052310523
unsigned DiagID = diag::err_typecheck_invalid_operands;
10524-
if ((OperationKind == ACK_Arithmetic) &&
10524+
if ((OperationKind == ArithConvKind::Arithmetic) &&
1052510525
((LHSBuiltinTy && LHSBuiltinTy->isSVEBool()) ||
1052610526
(RHSBuiltinTy && RHSBuiltinTy->isSVEBool()))) {
1052710527
Diag(Loc, DiagID) << LHSType << RHSType << LHS.get()->getSourceRange()
@@ -10730,7 +10730,7 @@ QualType Sema::CheckMultiplyDivideOperands(ExprResult &LHS, ExprResult &RHS,
1073010730
/*ReportInvalid*/ true);
1073110731
if (LHSTy->isSveVLSBuiltinType() || RHSTy->isSveVLSBuiltinType())
1073210732
return CheckSizelessVectorOperands(LHS, RHS, Loc, IsCompAssign,
10733-
ACK_Arithmetic);
10733+
ArithConvKind::Arithmetic);
1073410734
if (!IsDiv &&
1073510735
(LHSTy->isConstantMatrixType() || RHSTy->isConstantMatrixType()))
1073610736
return CheckMatrixMultiplyOperands(LHS, RHS, Loc, IsCompAssign);
@@ -10740,7 +10740,8 @@ QualType Sema::CheckMultiplyDivideOperands(ExprResult &LHS, ExprResult &RHS,
1074010740
return CheckMatrixElementwiseOperands(LHS, RHS, Loc, IsCompAssign);
1074110741

1074210742
QualType compType = UsualArithmeticConversions(
10743-
LHS, RHS, Loc, IsCompAssign ? ACK_CompAssign : ACK_Arithmetic);
10743+
LHS, RHS, Loc,
10744+
IsCompAssign ? ArithConvKind::CompAssign : ArithConvKind::Arithmetic);
1074410745
if (LHS.isInvalid() || RHS.isInvalid())
1074510746
return QualType();
1074610747

@@ -10796,13 +10797,14 @@ QualType Sema::CheckRemainderOperands(
1079610797
if (LHS.get()->getType()->hasIntegerRepresentation() &&
1079710798
RHS.get()->getType()->hasIntegerRepresentation())
1079810799
return CheckSizelessVectorOperands(LHS, RHS, Loc, IsCompAssign,
10799-
ACK_Arithmetic);
10800+
ArithConvKind::Arithmetic);
1080010801

1080110802
return InvalidOperands(Loc, LHS, RHS);
1080210803
}
1080310804

1080410805
QualType compType = UsualArithmeticConversions(
10805-
LHS, RHS, Loc, IsCompAssign ? ACK_CompAssign : ACK_Arithmetic);
10806+
LHS, RHS, Loc,
10807+
IsCompAssign ? ArithConvKind::CompAssign : ArithConvKind::Arithmetic);
1080610808
if (LHS.isInvalid() || RHS.isInvalid())
1080710809
return QualType();
1080810810

@@ -11115,8 +11117,8 @@ QualType Sema::CheckAdditionOperands(ExprResult &LHS, ExprResult &RHS,
1111511117

1111611118
if (LHS.get()->getType()->isSveVLSBuiltinType() ||
1111711119
RHS.get()->getType()->isSveVLSBuiltinType()) {
11118-
QualType compType =
11119-
CheckSizelessVectorOperands(LHS, RHS, Loc, CompLHSTy, ACK_Arithmetic);
11120+
QualType compType = CheckSizelessVectorOperands(LHS, RHS, Loc, CompLHSTy,
11121+
ArithConvKind::Arithmetic);
1112011122
if (CompLHSTy)
1112111123
*CompLHSTy = compType;
1112211124
return compType;
@@ -11132,7 +11134,8 @@ QualType Sema::CheckAdditionOperands(ExprResult &LHS, ExprResult &RHS,
1113211134
}
1113311135

1113411136
QualType compType = UsualArithmeticConversions(
11135-
LHS, RHS, Loc, CompLHSTy ? ACK_CompAssign : ACK_Arithmetic);
11137+
LHS, RHS, Loc,
11138+
CompLHSTy ? ArithConvKind::CompAssign : ArithConvKind::Arithmetic);
1113611139
if (LHS.isInvalid() || RHS.isInvalid())
1113711140
return QualType();
1113811141

@@ -11238,8 +11241,8 @@ QualType Sema::CheckSubtractionOperands(ExprResult &LHS, ExprResult &RHS,
1123811241

1123911242
if (LHS.get()->getType()->isSveVLSBuiltinType() ||
1124011243
RHS.get()->getType()->isSveVLSBuiltinType()) {
11241-
QualType compType =
11242-
CheckSizelessVectorOperands(LHS, RHS, Loc, CompLHSTy, ACK_Arithmetic);
11244+
QualType compType = CheckSizelessVectorOperands(LHS, RHS, Loc, CompLHSTy,
11245+
ArithConvKind::Arithmetic);
1124311246
if (CompLHSTy)
1124411247
*CompLHSTy = compType;
1124511248
return compType;
@@ -11255,7 +11258,8 @@ QualType Sema::CheckSubtractionOperands(ExprResult &LHS, ExprResult &RHS,
1125511258
}
1125611259

1125711260
QualType compType = UsualArithmeticConversions(
11258-
LHS, RHS, Loc, CompLHSTy ? ACK_CompAssign : ACK_Arithmetic);
11261+
LHS, RHS, Loc,
11262+
CompLHSTy ? ArithConvKind::CompAssign : ArithConvKind::Arithmetic);
1125911263
if (LHS.isInvalid() || RHS.isInvalid())
1126011264
return QualType();
1126111265

@@ -12277,7 +12281,7 @@ static QualType checkArithmeticOrEnumeralThreeWayCompare(Sema &S,
1227712281
// C++2a [expr.spaceship]p4: If both operands have arithmetic types, the
1227812282
// usual arithmetic conversions are applied to the operands.
1227912283
QualType Type =
12280-
S.UsualArithmeticConversions(LHS, RHS, Loc, Sema::ACK_Comparison);
12284+
S.UsualArithmeticConversions(LHS, RHS, Loc, ArithConvKind::Comparison);
1228112285
if (LHS.isInvalid() || RHS.isInvalid())
1228212286
return QualType();
1228312287
if (Type.isNull())
@@ -12310,7 +12314,7 @@ static QualType checkArithmeticOrEnumeralCompare(Sema &S, ExprResult &LHS,
1231012314

1231112315
// C99 6.5.8p3 / C99 6.5.9p4
1231212316
QualType Type =
12313-
S.UsualArithmeticConversions(LHS, RHS, Loc, Sema::ACK_Comparison);
12317+
S.UsualArithmeticConversions(LHS, RHS, Loc, ArithConvKind::Comparison);
1231412318
if (LHS.isInvalid() || RHS.isInvalid())
1231512319
return QualType();
1231612320
if (Type.isNull())
@@ -12972,7 +12976,7 @@ QualType Sema::CheckSizelessVectorCompareOperands(ExprResult &LHS,
1297212976
// Check to make sure we're operating on vectors of the same type and width,
1297312977
// Allowing one side to be a scalar of element type.
1297412978
QualType vType = CheckSizelessVectorOperands(
12975-
LHS, RHS, Loc, /*isCompAssign*/ false, ACK_Comparison);
12979+
LHS, RHS, Loc, /*isCompAssign*/ false, ArithConvKind::Comparison);
1297612980

1297712981
if (vType.isNull())
1297812982
return vType;
@@ -13282,7 +13286,7 @@ inline QualType Sema::CheckBitwiseOperands(ExprResult &LHS, ExprResult &RHS,
1328213286
if (LHS.get()->getType()->hasIntegerRepresentation() &&
1328313287
RHS.get()->getType()->hasIntegerRepresentation())
1328413288
return CheckSizelessVectorOperands(LHS, RHS, Loc, IsCompAssign,
13285-
ACK_BitwiseOp);
13289+
ArithConvKind::BitwiseOp);
1328613290
return InvalidOperands(Loc, LHS, RHS);
1328713291
}
1328813292

@@ -13291,7 +13295,7 @@ inline QualType Sema::CheckBitwiseOperands(ExprResult &LHS, ExprResult &RHS,
1329113295
if (LHS.get()->getType()->hasIntegerRepresentation() &&
1329213296
RHS.get()->getType()->hasIntegerRepresentation())
1329313297
return CheckSizelessVectorOperands(LHS, RHS, Loc, IsCompAssign,
13294-
ACK_BitwiseOp);
13298+
ArithConvKind::BitwiseOp);
1329513299
return InvalidOperands(Loc, LHS, RHS);
1329613300
}
1329713301

@@ -13304,7 +13308,8 @@ inline QualType Sema::CheckBitwiseOperands(ExprResult &LHS, ExprResult &RHS,
1330413308

1330513309
ExprResult LHSResult = LHS, RHSResult = RHS;
1330613310
QualType compType = UsualArithmeticConversions(
13307-
LHSResult, RHSResult, Loc, IsCompAssign ? ACK_CompAssign : ACK_BitwiseOp);
13311+
LHSResult, RHSResult, Loc,
13312+
IsCompAssign ? ArithConvKind::CompAssign : ArithConvKind::BitwiseOp);
1330813313
if (LHSResult.isInvalid() || RHSResult.isInvalid())
1330913314
return QualType();
1331013315
LHS = LHSResult.get();

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7191,7 +7191,7 @@ QualType Sema::CheckVectorConditionalTypes(ExprResult &Cond, ExprResult &LHS,
71917191
Context.hasSameType(LHSType, RHSType)
71927192
? Context.getCommonSugaredType(LHSType, RHSType)
71937193
: UsualArithmeticConversions(LHS, RHS, QuestionLoc,
7194-
ACK_Conditional);
7194+
ArithConvKind::Conditional);
71957195

71967196
if (ResultElementTy->isEnumeralType()) {
71977197
Diag(QuestionLoc, diag::err_conditional_vector_operand_type)
@@ -7263,8 +7263,9 @@ QualType Sema::CheckSizelessVectorConditionalTypes(ExprResult &Cond,
72637263
}
72647264
ResultType = LHSType;
72657265
} else if (LHSBT || RHSBT) {
7266-
ResultType = CheckSizelessVectorOperands(
7267-
LHS, RHS, QuestionLoc, /*IsCompAssign*/ false, ACK_Conditional);
7266+
ResultType = CheckSizelessVectorOperands(LHS, RHS, QuestionLoc,
7267+
/*IsCompAssign*/ false,
7268+
ArithConvKind::Conditional);
72687269
if (ResultType.isNull())
72697270
return QualType();
72707271
} else {
@@ -7276,8 +7277,8 @@ QualType Sema::CheckSizelessVectorConditionalTypes(ExprResult &Cond,
72767277
if (Context.hasSameType(LHSType, RHSType))
72777278
ResultElementTy = LHSType;
72787279
else
7279-
ResultElementTy =
7280-
UsualArithmeticConversions(LHS, RHS, QuestionLoc, ACK_Conditional);
7280+
ResultElementTy = UsualArithmeticConversions(LHS, RHS, QuestionLoc,
7281+
ArithConvKind::Conditional);
72817282

72827283
if (ResultElementTy->isEnumeralType()) {
72837284
Diag(QuestionLoc, diag::err_conditional_vector_operand_type)
@@ -7565,8 +7566,8 @@ QualType Sema::CXXCheckConditionalOperands(ExprResult &Cond, ExprResult &LHS,
75657566
// the usual arithmetic conversions are performed to bring them to a
75667567
// common type, and the result is of that type.
75677568
if (LTy->isArithmeticType() && RTy->isArithmeticType()) {
7568-
QualType ResTy =
7569-
UsualArithmeticConversions(LHS, RHS, QuestionLoc, ACK_Conditional);
7569+
QualType ResTy = UsualArithmeticConversions(LHS, RHS, QuestionLoc,
7570+
ArithConvKind::Conditional);
75707571
if (LHS.isInvalid() || RHS.isInvalid())
75717572
return QualType();
75727573
if (ResTy.isNull()) {

0 commit comments

Comments
 (0)