[clang] 048befe - Revert "[clang][NFC] Convert `Sema::TryCaptureKind` to scoped enum"
Vlad Serebrennikov via cfe-commits
cfe-commits at lists.llvm.org
Thu May 1 23:29:45 PDT 2025
Author: Vlad Serebrennikov
Date: 2025-05-02T09:29:35+03:00
New Revision: 048befe9ef7edab3580a922d69664b21e2a532fa
URL: https://github.com/llvm/llvm-project/commit/048befe9ef7edab3580a922d69664b21e2a532fa
DIFF: https://github.com/llvm/llvm-project/commit/048befe9ef7edab3580a922d69664b21e2a532fa.diff
LOG: Revert "[clang][NFC] Convert `Sema::TryCaptureKind` to scoped enum"
This reverts commit be6497ff7583248d76a6710dd48cfeb63dd68f27.
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 734452500dde6..4dc2783b5f83a 100644
--- a/clang/include/clang/Sema/Sema.h
+++ b/clang/include/clang/Sema/Sema.h
@@ -646,8 +646,6 @@ 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 {
@@ -6778,6 +6776,12 @@ 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.
@@ -6819,7 +6823,7 @@ class Sema final : public SemaBase {
/// Try to capture the given variable.
bool tryCaptureVariable(ValueDecl *Var, SourceLocation Loc,
- TryCaptureKind Kind = TryCaptureKind::Implicit,
+ TryCaptureKind Kind = TryCapture_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 87bea36214c91..205556424c67f 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, TryCaptureKind::Implicit,
+ SemaRef.tryCaptureVariable(V, Loc, Sema::TryCapture_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, TryCaptureKind Kind, bool IsTopScope,
- Sema &S, bool Invalid) {
+ const bool RefersToCapturedVariable, Sema::TryCaptureKind Kind,
+ bool IsTopScope, Sema &S, bool Invalid) {
// By default, capture variables by reference.
bool ByRef = true;
- if (IsTopScope && Kind != TryCaptureKind::Implicit) {
- ByRef = (Kind == TryCaptureKind::ExplicitByRef);
+ if (IsTopScope && Kind != Sema::TryCapture_Implicit) {
+ ByRef = (Kind == Sema::TryCapture_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 TryCaptureKind Kind,
+ const Sema::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 != TryCaptureKind::Implicit) {
- ByRef = (Kind == TryCaptureKind::ExplicitByRef);
+ if (IsTopScope && Kind != Sema::TryCapture_Implicit) {
+ ByRef = (Kind == Sema::TryCapture_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 != TryCaptureKind::Implicit);
+ bool Explicit = (Kind != TryCapture_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, TryCaptureKind::Implicit, SourceLocation(),
- /*BuildAndDiagnose=*/false, CaptureType, DeclRefType, nullptr);
+ return !tryCaptureVariable(Var, Loc, TryCapture_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, TryCaptureKind::Implicit, SourceLocation(),
- /*BuildAndDiagnose=*/false, CaptureType, DeclRefType,
- nullptr))
+ if (tryCaptureVariable(Var, Loc, TryCapture_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, TryCaptureKind::Implicit,
+ SemaRef.tryCaptureVariable(BD, Loc, Sema::TryCapture_Implicit,
/*EllipsisLoc*/ SourceLocation(),
/*BuildAndDiagnose*/ true, CaptureType,
DeclRefType,
diff --git a/clang/lib/Sema/SemaExprCXX.cpp b/clang/lib/Sema/SemaExprCXX.cpp
index 059613abad36f..09edc34936cfd 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, TryCaptureKind::Implicit,
- /*EllipsisLoc*/ SourceLocation(),
- /*BuildAndDiagnose*/ false, CaptureType,
- DeclRefType, nullptr)) {
+ if (S.tryCaptureVariable(Var, ExprLoc, S.TryCapture_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, TryCaptureKind::Implicit,
- /*EllipsisLoc*/ SourceLocation(),
- /*BuildAndDiagnose*/ true, CaptureType,
- DeclRefType, nullptr);
+ S.tryCaptureVariable(Var, ExprLoc, S.TryCapture_Implicit,
+ /*EllipsisLoc*/ SourceLocation(),
+ /*BuildAndDiagnose*/true, CaptureType,
+ DeclRefType, nullptr);
}
}
});
diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index 28fcef829ec41..1183a04d3bf33 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -207,12 +207,13 @@ 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(), TryCaptureKind::Implicit,
- /*EllipsisLoc*/ SourceLocation(),
- /*BuildAndDiagnose*/ false, CaptureType, DeclRefType,
- &IndexOfCaptureReadyLambda);
+ const bool CanCaptureVariable =
+ !S.tryCaptureVariable(VarToCapture,
+ /*ExprVarIsUsedInLoc*/ SourceLocation(),
+ clang::Sema::TryCapture_Implicit,
+ /*EllipsisLoc*/ SourceLocation(),
+ /*BuildAndDiagnose*/ false, CaptureType,
+ DeclRefType, &IndexOfCaptureReadyLambda);
if (!CanCaptureVariable)
return NoLambdaIsCaptureCapable;
} else {
@@ -1347,9 +1348,8 @@ 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
- ? TryCaptureKind::ExplicitByRef
- : TryCaptureKind::ExplicitByVal;
+ TryCaptureKind Kind = C->Kind == LCK_ByRef ? TryCapture_ExplicitByRef
+ : TryCapture_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 998f55af9410c..274d3b90ff30f 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, {},
- TryCaptureKind::ExplicitByVal, {});
+ Sema::TryCapture_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 3946662f807b2..967b44e997837 100644
--- a/clang/lib/Sema/TreeTransform.h
+++ b/clang/lib/Sema/TreeTransform.h
@@ -15577,10 +15577,11 @@ TreeTransform<Derived>::TransformLambdaExpr(LambdaExpr *E) {
assert(C->capturesVariable() && "unexpected kind of lambda capture");
// Determine the capture kind for Sema.
- TryCaptureKind Kind = C->isImplicit() ? TryCaptureKind::Implicit
- : C->getCaptureKind() == LCK_ByCopy
- ? TryCaptureKind::ExplicitByVal
- : TryCaptureKind::ExplicitByRef;
+ Sema::TryCaptureKind Kind
+ = C->isImplicit()? Sema::TryCapture_Implicit
+ : C->getCaptureKind() == LCK_ByCopy
+ ? Sema::TryCapture_ExplicitByVal
+ : Sema::TryCapture_ExplicitByRef;
SourceLocation EllipsisLoc;
if (C->isPackExpansion()) {
UnexpandedParameterPack Unexpanded(C->getCapturedVar(), C->getLocation());
More information about the cfe-commits
mailing list