[clang][NFC] Reland "Convert Sema::TryCaptureKind to scoped enum"
This commit is contained in:
@@ -646,6 +646,8 @@ enum class TrivialABIHandling {
|
||||
ConsiderTrivialABI
|
||||
};
|
||||
|
||||
enum class TryCaptureKind { Implicit, ExplicitByVal, ExplicitByRef };
|
||||
|
||||
/// Sema - This implements semantic analysis and AST building for C.
|
||||
/// \nosubgrouping
|
||||
class Sema final : public SemaBase {
|
||||
@@ -6776,12 +6778,6 @@ public:
|
||||
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 @@ public:
|
||||
|
||||
/// 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.
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -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())
|
||||
|
||||
@@ -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.");
|
||||
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user