[clang] be6497f - [clang][NFC] Convert `Sema::TryCaptureKind` to scoped enum
Vlad Serebrennikov via cfe-commits
cfe-commits at lists.llvm.org
Thu May 1 23:26:04 PDT 2025
Author: Vlad Serebrennikov
Date: 2025-05-02T09:25:58+03:00
New Revision: be6497ff7583248d76a6710dd48cfeb63dd68f27
URL: https://github.com/llvm/llvm-project/commit/be6497ff7583248d76a6710dd48cfeb63dd68f27
DIFF: https://github.com/llvm/llvm-project/commit/be6497ff7583248d76a6710dd48cfeb63dd68f27.diff
LOG: [clang][NFC] Convert `Sema::TryCaptureKind` to scoped enum
Added:
Modified:
clang/include/clang/Sema/Sema.h
clang/lib/Sema/SemaExpr.cpp
clang/lib/Sema/SemaExprCXX.cpp
clang/lib/Sema/SemaLambda.cpp
clang/lib/Sema/SemaOpenMP.cpp
clang/lib/Sema/TreeTransform.h
Removed:
################################################################################
diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h
index 4dc2783b5f83a..734452500dde6 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -646,6 +646,8 @@ enum class TrivialABIHandling {
ConsiderTrivialABI
};
+enum TryCaptureKind { Implicit, ExplicitByVal, ExplicitByRef };
+
/// Sema - This implements semantic analysis and AST building for C.
/// \nosubgrouping
class Sema final : public SemaBase {
@@ -6776,12 +6778,6 @@ class Sema final : public SemaBase {
ExprResult CheckLValueToRValueConversionOperand(Expr *E);
void CleanupVarDeclMarking();
- enum TryCaptureKind {
- TryCapture_Implicit,
- TryCapture_ExplicitByVal,
- TryCapture_ExplicitByRef
- };
-
/// Try to capture the given variable.
///
/// \param Var The variable to capture.
@@ -6823,7 +6819,7 @@ class Sema final : public SemaBase {
/// Try to capture the given variable.
bool tryCaptureVariable(ValueDecl *Var, SourceLocation Loc,
- TryCaptureKind Kind = TryCapture_Implicit,
+ TryCaptureKind Kind = TryCaptureKind::Implicit,
SourceLocation EllipsisLoc = SourceLocation());
/// Checks if the variable must be captured.
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 205556424c67f..87bea36214c91 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -18539,7 +18539,7 @@ MarkVarDeclODRUsed(ValueDecl *V, SourceLocation Loc, Sema &SemaRef,
QualType CaptureType, DeclRefType;
if (SemaRef.LangOpts.OpenMP)
SemaRef.OpenMP().tryCaptureOpenMPLambdas(V);
- SemaRef.tryCaptureVariable(V, Loc, Sema::TryCapture_Implicit,
+ SemaRef.tryCaptureVariable(V, Loc, TryCaptureKind::Implicit,
/*EllipsisLoc*/ SourceLocation(),
/*BuildAndDiagnose*/ true, CaptureType,
DeclRefType, FunctionScopeIndexToStopAt);
@@ -18844,12 +18844,12 @@ static bool captureInBlock(BlockScopeInfo *BSI, ValueDecl *Var,
static bool captureInCapturedRegion(
CapturedRegionScopeInfo *RSI, ValueDecl *Var, SourceLocation Loc,
const bool BuildAndDiagnose, QualType &CaptureType, QualType &DeclRefType,
- const bool RefersToCapturedVariable, Sema::TryCaptureKind Kind,
- bool IsTopScope, Sema &S, bool Invalid) {
+ const bool RefersToCapturedVariable, TryCaptureKind Kind, bool IsTopScope,
+ Sema &S, bool Invalid) {
// By default, capture variables by reference.
bool ByRef = true;
- if (IsTopScope && Kind != Sema::TryCapture_Implicit) {
- ByRef = (Kind == Sema::TryCapture_ExplicitByRef);
+ if (IsTopScope && Kind != TryCaptureKind::Implicit) {
+ ByRef = (Kind == TryCaptureKind::ExplicitByRef);
} else if (S.getLangOpts().OpenMP && RSI->CapRegionKind == CR_OpenMP) {
// Using an LValue reference type is consistent with Lambdas (see below).
if (S.OpenMP().isOpenMPCapturedDecl(Var)) {
@@ -18885,13 +18885,13 @@ static bool captureInLambda(LambdaScopeInfo *LSI, ValueDecl *Var,
SourceLocation Loc, const bool BuildAndDiagnose,
QualType &CaptureType, QualType &DeclRefType,
const bool RefersToCapturedVariable,
- const Sema::TryCaptureKind Kind,
+ const TryCaptureKind Kind,
SourceLocation EllipsisLoc, const bool IsTopScope,
Sema &S, bool Invalid) {
// Determine whether we are capturing by reference or by value.
bool ByRef = false;
- if (IsTopScope && Kind != Sema::TryCapture_Implicit) {
- ByRef = (Kind == Sema::TryCapture_ExplicitByRef);
+ if (IsTopScope && Kind != TryCaptureKind::Implicit) {
+ ByRef = (Kind == TryCaptureKind::ExplicitByRef);
} else {
ByRef = (LSI->ImpCaptureStyle == LambdaScopeInfo::ImpCap_LambdaByref);
}
@@ -19169,7 +19169,7 @@ bool Sema::tryCaptureVariable(
CaptureType = Var->getType();
DeclRefType = CaptureType.getNonReferenceType();
bool Nested = false;
- bool Explicit = (Kind != TryCapture_Implicit);
+ bool Explicit = (Kind != TryCaptureKind::Implicit);
unsigned FunctionScopesIndex = MaxFunctionScopesIndex;
do {
@@ -19411,9 +19411,9 @@ bool Sema::tryCaptureVariable(ValueDecl *Var, SourceLocation Loc,
bool Sema::NeedToCaptureVariable(ValueDecl *Var, SourceLocation Loc) {
QualType CaptureType;
QualType DeclRefType;
- return !tryCaptureVariable(Var, Loc, TryCapture_Implicit, SourceLocation(),
- /*BuildAndDiagnose=*/false, CaptureType,
- DeclRefType, nullptr);
+ return !tryCaptureVariable(
+ Var, Loc, TryCaptureKind::Implicit, SourceLocation(),
+ /*BuildAndDiagnose=*/false, CaptureType, DeclRefType, nullptr);
}
QualType Sema::getCapturedDeclRefType(ValueDecl *Var, SourceLocation Loc) {
@@ -19423,9 +19423,9 @@ QualType Sema::getCapturedDeclRefType(ValueDecl *Var, SourceLocation Loc) {
QualType DeclRefType;
// Determine whether we can capture this variable.
- if (tryCaptureVariable(Var, Loc, TryCapture_Implicit, SourceLocation(),
- /*BuildAndDiagnose=*/false, CaptureType,
- DeclRefType, nullptr))
+ if (tryCaptureVariable(Var, Loc, TryCaptureKind::Implicit, SourceLocation(),
+ /*BuildAndDiagnose=*/false, CaptureType, DeclRefType,
+ nullptr))
return QualType();
return DeclRefType;
@@ -20082,7 +20082,7 @@ static void DoMarkBindingDeclReferenced(Sema &SemaRef, SourceLocation Loc,
OdrUseContext OdrUse = isOdrUseContext(SemaRef);
if (OdrUse == OdrUseContext::Used) {
QualType CaptureType, DeclRefType;
- SemaRef.tryCaptureVariable(BD, Loc, Sema::TryCapture_Implicit,
+ SemaRef.tryCaptureVariable(BD, Loc, TryCaptureKind::Implicit,
/*EllipsisLoc*/ SourceLocation(),
/*BuildAndDiagnose*/ true, CaptureType,
DeclRefType,
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 09edc34936cfd..059613abad36f 100644
--- a/clang/lib/Sema/SemaExprCXX.cpp
+++ b/clang/lib/Sema/SemaExprCXX.cpp
@@ -9119,16 +9119,16 @@ static void CheckIfAnyEnclosingLambdasMustCaptureAnyPotentialCaptures(
// error would get diagnosed when the lambda becomes capture ready.
QualType CaptureType, DeclRefType;
SourceLocation ExprLoc = VarExpr->getExprLoc();
- if (S.tryCaptureVariable(Var, ExprLoc, S.TryCapture_Implicit,
- /*EllipsisLoc*/ SourceLocation(),
- /*BuildAndDiagnose*/false, CaptureType,
- DeclRefType, nullptr)) {
+ if (S.tryCaptureVariable(Var, ExprLoc, TryCaptureKind::Implicit,
+ /*EllipsisLoc*/ SourceLocation(),
+ /*BuildAndDiagnose*/ false, CaptureType,
+ DeclRefType, nullptr)) {
// We will never be able to capture this variable, and we need
// to be able to in any and all instantiations, so diagnose it.
- S.tryCaptureVariable(Var, ExprLoc, S.TryCapture_Implicit,
- /*EllipsisLoc*/ SourceLocation(),
- /*BuildAndDiagnose*/true, CaptureType,
- DeclRefType, nullptr);
+ S.tryCaptureVariable(Var, ExprLoc, TryCaptureKind::Implicit,
+ /*EllipsisLoc*/ SourceLocation(),
+ /*BuildAndDiagnose*/ true, CaptureType,
+ DeclRefType, nullptr);
}
}
});
diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index 1183a04d3bf33..28fcef829ec41 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -207,13 +207,12 @@ UnsignedOrNone clang::getStackIndexOfNearestEnclosingCaptureCapableLambda(
// checking whether all enclosing lambdas of the capture-ready lambda allow
// the capture - i.e. make sure it is capture-capable.
QualType CaptureType, DeclRefType;
- const bool CanCaptureVariable =
- !S.tryCaptureVariable(VarToCapture,
- /*ExprVarIsUsedInLoc*/ SourceLocation(),
- clang::Sema::TryCapture_Implicit,
- /*EllipsisLoc*/ SourceLocation(),
- /*BuildAndDiagnose*/ false, CaptureType,
- DeclRefType, &IndexOfCaptureReadyLambda);
+ const bool CanCaptureVariable = !S.tryCaptureVariable(
+ VarToCapture,
+ /*ExprVarIsUsedInLoc*/ SourceLocation(), TryCaptureKind::Implicit,
+ /*EllipsisLoc*/ SourceLocation(),
+ /*BuildAndDiagnose*/ false, CaptureType, DeclRefType,
+ &IndexOfCaptureReadyLambda);
if (!CanCaptureVariable)
return NoLambdaIsCaptureCapable;
} else {
@@ -1348,8 +1347,9 @@ void Sema::ActOnLambdaExpressionAfterIntroducer(LambdaIntroducer &Intro,
if (C->Init.isUsable()) {
addInitCapture(LSI, cast<VarDecl>(Var), C->Kind == LCK_ByRef);
} else {
- TryCaptureKind Kind = C->Kind == LCK_ByRef ? TryCapture_ExplicitByRef
- : TryCapture_ExplicitByVal;
+ TryCaptureKind Kind = C->Kind == LCK_ByRef
+ ? TryCaptureKind::ExplicitByRef
+ : TryCaptureKind::ExplicitByVal;
tryCaptureVariable(Var, C->Loc, Kind, EllipsisLoc);
}
if (!LSI->Captures.empty())
diff --git a/clang/lib/Sema/SemaOpenMP.cpp b/clang/lib/Sema/SemaOpenMP.cpp
index 274d3b90ff30f..998f55af9410c 100644
--- a/clang/lib/Sema/SemaOpenMP.cpp
+++ b/clang/lib/Sema/SemaOpenMP.cpp
@@ -5546,7 +5546,7 @@ static CapturedStmt *buildLoopVarFunc(Sema &Actions, QualType LoopVarTy,
// it in every iteration, capture it by value before it is modified.
VarDecl *StartVar = cast<VarDecl>(StartExpr->getDecl());
bool Invalid = Actions.tryCaptureVariable(StartVar, {},
- Sema::TryCapture_ExplicitByVal, {});
+ TryCaptureKind::ExplicitByVal, {});
(void)Invalid;
assert(!Invalid && "Expecting capture-by-value to work.");
diff --git a/clang/lib/Sema/TreeTransform.h b/clang/lib/Sema/TreeTransform.h
index 967b44e997837..3946662f807b2 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -15577,11 +15577,10 @@ TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
assert(C->capturesVariable() && "unexpected kind of lambda capture");
// Determine the capture kind for Sema.
- Sema::TryCaptureKind Kind
- = C->isImplicit()? Sema::TryCapture_Implicit
- : C->getCaptureKind() == LCK_ByCopy
- ? Sema::TryCapture_ExplicitByVal
- : Sema::TryCapture_ExplicitByRef;
+ TryCaptureKind Kind = C->isImplicit() ? TryCaptureKind::Implicit
+ : C->getCaptureKind() == LCK_ByCopy
+ ? TryCaptureKind::ExplicitByVal
+ : TryCaptureKind::ExplicitByRef;
SourceLocation EllipsisLoc;
if (C->isPackExpansion()) {
UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
More information about the cfe-commits
mailing list