Skip to content

Commit 99f72e9

Browse files
EndilllGeorgeARM
authored andcommitted
[clang][NFC] Convert Sema::AllowFoldKind to scoped enum
1 parent 47446e4 commit 99f72e9

File tree

10 files changed

+42
-37
lines changed

10 files changed

+42
-37
lines changed

clang/include/clang/Sema/Sema.h

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -648,6 +648,11 @@ enum class TrivialABIHandling {
648648

649649
enum class TryCaptureKind { Implicit, ExplicitByVal, ExplicitByRef };
650650

651+
enum class AllowFoldKind {
652+
No,
653+
Allow,
654+
};
655+
651656
/// Sema - This implements semantic analysis and AST building for C.
652657
/// \nosubgrouping
653658
class Sema final : public SemaBase {
@@ -7424,25 +7429,23 @@ class Sema final : public SemaBase {
74247429
virtual ~VerifyICEDiagnoser() {}
74257430
};
74267431

7427-
enum AllowFoldKind {
7428-
NoFold,
7429-
AllowFold,
7430-
};
7431-
74327432
/// VerifyIntegerConstantExpression - Verifies that an expression is an ICE,
74337433
/// and reports the appropriate diagnostics. Returns false on success.
74347434
/// Can optionally return the value of the expression.
7435-
ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result,
7436-
VerifyICEDiagnoser &Diagnoser,
7437-
AllowFoldKind CanFold = NoFold);
7438-
ExprResult VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result,
7439-
unsigned DiagID,
7440-
AllowFoldKind CanFold = NoFold);
7441-
ExprResult VerifyIntegerConstantExpression(Expr *E,
7442-
llvm::APSInt *Result = nullptr,
7443-
AllowFoldKind CanFold = NoFold);
7444-
ExprResult VerifyIntegerConstantExpression(Expr *E,
7445-
AllowFoldKind CanFold = NoFold) {
7435+
ExprResult
7436+
VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result,
7437+
VerifyICEDiagnoser &Diagnoser,
7438+
AllowFoldKind CanFold = AllowFoldKind::No);
7439+
ExprResult
7440+
VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result,
7441+
unsigned DiagID,
7442+
AllowFoldKind CanFold = AllowFoldKind::No);
7443+
ExprResult
7444+
VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result = nullptr,
7445+
AllowFoldKind CanFold = AllowFoldKind::No);
7446+
ExprResult
7447+
VerifyIntegerConstantExpression(Expr *E,
7448+
AllowFoldKind CanFold = AllowFoldKind::No) {
74467449
return VerifyIntegerConstantExpression(E, nullptr, CanFold);
74477450
}
74487451

clang/lib/Parse/ParseOpenMP.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3669,7 +3669,7 @@ bool Parser::ParseOpenMPIndirectClause(
36693669
return false;
36703670
llvm::APSInt Result;
36713671
Ret = Actions.VerifyIntegerConstantExpression(Val.get(), &Result,
3672-
Sema::AllowFold);
3672+
AllowFoldKind::Allow);
36733673
if (Ret.isInvalid())
36743674
return false;
36753675
DTCI.Indirect = Val.get();

clang/lib/Sema/SemaDecl.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18606,7 +18606,8 @@ ExprResult Sema::VerifyBitField(SourceLocation FieldLoc,
1860618606
return BitWidth;
1860718607

1860818608
llvm::APSInt Value;
18609-
ExprResult ICE = VerifyIntegerConstantExpression(BitWidth, &Value, AllowFold);
18609+
ExprResult ICE =
18610+
VerifyIntegerConstantExpression(BitWidth, &Value, AllowFoldKind::Allow);
1861018611
if (ICE.isInvalid())
1861118612
return ICE;
1861218613
BitWidth = ICE.get();
@@ -19849,9 +19850,9 @@ EnumConstantDecl *Sema::CheckEnumConstant(EnumDecl *Enum,
1984919850
else
1985019851
Val = Converted.get();
1985119852
} else if (!Val->isValueDependent() &&
19852-
!(Val =
19853-
VerifyIntegerConstantExpression(Val, &EnumVal, AllowFold)
19854-
.get())) {
19853+
!(Val = VerifyIntegerConstantExpression(Val, &EnumVal,
19854+
AllowFoldKind::Allow)
19855+
.get())) {
1985519856
// C99 6.7.2.2p2: Make sure we have an integer constant expression.
1985619857
} else {
1985719858
if (Enum->isComplete()) {

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17851,13 +17851,13 @@ Decl *Sema::BuildStaticAssertDeclaration(SourceLocation StaticAssertLoc,
1785117851

1785217852
llvm::APSInt Cond;
1785317853
Expr *BaseExpr = AssertExpr;
17854-
AllowFoldKind FoldKind = NoFold;
17854+
AllowFoldKind FoldKind = AllowFoldKind::No;
1785517855

1785617856
if (!getLangOpts().CPlusPlus) {
1785717857
// In C mode, allow folding as an extension for better compatibility with
1785817858
// C++ in terms of expressions like static_assert("test") or
1785917859
// static_assert(nullptr).
17860-
FoldKind = AllowFold;
17860+
FoldKind = AllowFoldKind::Allow;
1786117861
}
1786217862

1786317863
if (!Failed && VerifyIntegerConstantExpression(

clang/lib/Sema/SemaExpr.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17463,7 +17463,7 @@ Sema::VerifyIntegerConstantExpression(Expr *E, llvm::APSInt *Result,
1746317463
Notes.clear();
1746417464
}
1746517465

17466-
if (!Folded || !CanFold) {
17466+
if (!Folded || CanFold == AllowFoldKind::No) {
1746717467
if (!Diagnoser.Suppress) {
1746817468
Diagnoser.diagnoseNotICE(*this, DiagLoc) << E->getSourceRange();
1746917469
for (const PartialDiagnosticAt &Note : Notes)

clang/lib/Sema/SemaExprCXX.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2060,10 +2060,10 @@ Sema::ActOnCXXNew(SourceLocation StartLoc, bool UseGlobal,
20602060
CCEK_ArrayBound)
20612061
.get();
20622062
} else {
2063-
Array.NumElts =
2064-
VerifyIntegerConstantExpression(
2065-
NumElts, nullptr, diag::err_new_array_nonconst, AllowFold)
2066-
.get();
2063+
Array.NumElts = VerifyIntegerConstantExpression(
2064+
NumElts, nullptr, diag::err_new_array_nonconst,
2065+
AllowFoldKind::Allow)
2066+
.get();
20672067
}
20682068
if (!Array.NumElts)
20692069
return ExprError();

clang/lib/Sema/SemaInit.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3510,7 +3510,7 @@ CheckArrayDesignatorExpr(Sema &S, Expr *Index, llvm::APSInt &Value) {
35103510

35113511
// Make sure this is an integer constant expression.
35123512
ExprResult Result =
3513-
S.VerifyIntegerConstantExpression(Index, &Value, Sema::AllowFold);
3513+
S.VerifyIntegerConstantExpression(Index, &Value, AllowFoldKind::Allow);
35143514
if (Result.isInvalid())
35153515
return Result;
35163516

clang/lib/Sema/SemaOpenMP.cpp

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6909,7 +6909,7 @@ SemaOpenMP::DeclGroupPtrTy SemaOpenMP::ActOnOpenMPDeclareSimdDirective(
69096909
if (NewStep)
69106910
NewStep = SemaRef
69116911
.VerifyIntegerConstantExpression(
6912-
NewStep, /*FIXME*/ Sema::AllowFold)
6912+
NewStep, /*FIXME*/ AllowFoldKind::Allow)
69136913
.get();
69146914
}
69156915
NewSteps.push_back(NewStep);
@@ -15866,10 +15866,11 @@ ExprResult SemaOpenMP::VerifyPositiveIntegerConstantInClause(
1586615866
}
1586715867
} Diagnoser;
1586815868
ICE = SemaRef.VerifyIntegerConstantExpression(E, &Result, Diagnoser,
15869-
Sema::AllowFold);
15869+
AllowFoldKind::Allow);
1587015870
} else {
15871-
ICE = SemaRef.VerifyIntegerConstantExpression(E, &Result,
15872-
/*FIXME*/ Sema::AllowFold);
15871+
ICE =
15872+
SemaRef.VerifyIntegerConstantExpression(E, &Result,
15873+
/*FIXME*/ AllowFoldKind::Allow);
1587315874
}
1587415875
if (ICE.isInvalid())
1587515876
return ExprError();
@@ -16470,7 +16471,7 @@ OMPClause *SemaOpenMP::ActOnOpenMPPermutationClause(ArrayRef<Expr *> PermExprs,
1647016471

1647116472
llvm::APSInt PermVal;
1647216473
ExprResult PermEvalExpr = SemaRef.VerifyIntegerConstantExpression(
16473-
PermExpr, &PermVal, Sema::AllowFold);
16474+
PermExpr, &PermVal, AllowFoldKind::Allow);
1647416475
bool IsValid = PermEvalExpr.isUsable();
1647516476
if (IsValid)
1647616477
PermExpr = PermEvalExpr.get();

clang/lib/Sema/SemaStmt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ Sema::ActOnCaseExpr(SourceLocation CaseLoc, ExprResult Val) {
526526

527527
ExprResult ER = E;
528528
if (!E->isValueDependent())
529-
ER = VerifyIntegerConstantExpression(E, AllowFold);
529+
ER = VerifyIntegerConstantExpression(E, AllowFoldKind::Allow);
530530
if (!ER.isInvalid())
531531
ER = DefaultLvalueConversion(ER.get());
532532
if (!ER.isInvalid())

clang/lib/Sema/SemaType.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1946,8 +1946,8 @@ QualType Sema::BuildBitIntType(bool IsUnsigned, Expr *BitWidth,
19461946
return Context.getDependentBitIntType(IsUnsigned, BitWidth);
19471947

19481948
llvm::APSInt Bits(32);
1949-
ExprResult ICE =
1950-
VerifyIntegerConstantExpression(BitWidth, &Bits, /*FIXME*/ AllowFold);
1949+
ExprResult ICE = VerifyIntegerConstantExpression(
1950+
BitWidth, &Bits, /*FIXME*/ AllowFoldKind::Allow);
19511951

19521952
if (ICE.isInvalid())
19531953
return QualType();

0 commit comments

Comments
 (0)