Skip to content

Commit 1a3e41f

Browse files
committed
Address comments from mizvekov
1 parent 50e5ef6 commit 1a3e41f

File tree

8 files changed

+45
-65
lines changed

8 files changed

+45
-65
lines changed

clang/lib/AST/ByteCode/Compiler.cpp

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5105,12 +5105,12 @@ bool Compiler<Emitter>::visitCompoundStmt(const CompoundStmt *S) {
51055105
}
51065106

51075107
template <class Emitter>
5108-
bool Compiler<Emitter>::emitDecompositionVarInit(const DecompositionDecl *DD) {
5109-
for (auto *BD : DD->bindings())
5110-
if (auto *KD = BD->getHoldingVar()) {
5111-
if (!this->visitVarDecl(KD))
5108+
bool Compiler<Emitter>::maybeEmitDeferredVarInit(const VarDecl *VD) {
5109+
if (auto *DD = dyn_cast_if_present<DecompositionDecl>(VD)) {
5110+
for (auto *BD : DD->bindings())
5111+
if (auto *KD = BD->getHoldingVar(); KD && !this->visitVarDecl(KD))
51125112
return false;
5113-
}
5113+
}
51145114
return true;
51155115
}
51165116

@@ -5129,11 +5129,8 @@ bool Compiler<Emitter>::visitDeclStmt(const DeclStmt *DS,
51295129
return false;
51305130

51315131
// Register decomposition decl holding vars.
5132-
if (const auto *DD = dyn_cast<DecompositionDecl>(VD);
5133-
EvaluateConditionDecl && DD) {
5134-
if (!this->emitDecompositionVarInit(DD))
5135-
return false;
5136-
}
5132+
if (EvaluateConditionDecl && !this->maybeEmitDeferredVarInit(VD))
5133+
return false;
51375134
}
51385135

51395136
return true;
@@ -5198,10 +5195,8 @@ template <class Emitter> bool Compiler<Emitter>::visitIfStmt(const IfStmt *IS) {
51985195
return false;
51995196
}
52005197

5201-
if (auto *DD =
5202-
dyn_cast_if_present<DecompositionDecl>(IS->getConditionVariable()))
5203-
if (!this->emitDecompositionVarInit(DD))
5204-
return false;
5198+
if (!this->maybeEmitDeferredVarInit(IS->getConditionVariable()))
5199+
return false;
52055200

52065201
if (const Stmt *Else = IS->getElse()) {
52075202
LabelTy LabelElse = this->getLabel();
@@ -5264,10 +5259,8 @@ bool Compiler<Emitter>::visitWhileStmt(const WhileStmt *S) {
52645259
if (!this->visitBool(Cond))
52655260
return false;
52665261

5267-
if (auto *DD =
5268-
dyn_cast_if_present<DecompositionDecl>(S->getConditionVariable()))
5269-
if (!this->emitDecompositionVarInit(DD))
5270-
return false;
5262+
if (!this->maybeEmitDeferredVarInit(S->getConditionVariable()))
5263+
return false;
52715264

52725265
if (!this->jumpFalse(EndLabel))
52735266
return false;
@@ -5350,10 +5343,8 @@ bool Compiler<Emitter>::visitForStmt(const ForStmt *S) {
53505343
return false;
53515344
}
53525345

5353-
if (auto *DD =
5354-
dyn_cast_if_present<DecompositionDecl>(S->getConditionVariable()))
5355-
if (!this->emitDecompositionVarInit(DD))
5356-
return false;
5346+
if (!this->maybeEmitDeferredVarInit(S->getConditionVariable()))
5347+
return false;
53575348

53585349
if (Body && !this->visitStmt(Body))
53595350
return false;
@@ -5477,10 +5468,8 @@ bool Compiler<Emitter>::visitSwitchStmt(const SwitchStmt *S) {
54775468
if (!this->emitSetLocal(CondT, CondVar, S))
54785469
return false;
54795470

5480-
if (auto *DD =
5481-
dyn_cast_if_present<DecompositionDecl>(S->getConditionVariable()))
5482-
if (!this->emitDecompositionVarInit(DD))
5483-
return false;
5471+
if (!this->maybeEmitDeferredVarInit(S->getConditionVariable()))
5472+
return false;
54845473

54855474
CaseMap CaseLabels;
54865475
// Create labels and comparison ops for all case statements.

clang/lib/AST/ByteCode/Compiler.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ class Compiler : public ConstStmtVisitor<Compiler<Emitter>, bool>,
386386
bool compileUnionAssignmentOperator(const CXXMethodDecl *MD);
387387

388388
bool checkLiteralType(const Expr *E);
389-
bool emitDecompositionVarInit(const DecompositionDecl *DD);
389+
bool maybeEmitDeferredVarInit(const VarDecl *VD);
390390

391391
protected:
392392
/// Variable to storage mapping.

clang/lib/AST/ExprConstant.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5244,6 +5244,15 @@ static bool EvaluateDecompositionDeclInit(EvalInfo &Info,
52445244
return OK;
52455245
}
52465246

5247+
static bool MaybeEvaluateDeferredVarDeclInit(EvalInfo &Info,
5248+
const VarDecl *VD) {
5249+
if (auto *DD = dyn_cast_if_present<DecompositionDecl>(VD)) {
5250+
if (!EvaluateDecompositionDeclInit(Info, DD))
5251+
return false;
5252+
}
5253+
return true;
5254+
}
5255+
52475256
static bool EvaluateDependentExpr(const Expr *E, EvalInfo &Info) {
52485257
assert(E->isValueDependent());
52495258
if (Info.noteSideEffect())
@@ -5263,8 +5272,7 @@ static bool EvaluateCond(EvalInfo &Info, const VarDecl *CondDecl,
52635272
return false;
52645273
if (!EvaluateAsBooleanCondition(Cond, Result, Info))
52655274
return false;
5266-
if (auto *DD = dyn_cast_if_present<DecompositionDecl>(CondDecl);
5267-
DD && !EvaluateDecompositionDeclInit(Info, DD))
5275+
if (!MaybeEvaluateDeferredVarDeclInit(Info, CondDecl))
52685276
return false;
52695277
return Scope.destroy();
52705278
}
@@ -5350,9 +5358,7 @@ static EvalStmtResult EvaluateSwitch(StmtResult &Result, EvalInfo &Info,
53505358
if (!EvaluateInteger(SS->getCond(), Value, Info))
53515359
return ESR_Failed;
53525360

5353-
if (auto *DD =
5354-
dyn_cast_if_present<DecompositionDecl>(SS->getConditionVariable());
5355-
DD && !EvaluateDecompositionDeclInit(Info, DD))
5361+
if (!MaybeEvaluateDeferredVarDeclInit(Info, SS->getConditionVariable()))
53565362
return ESR_Failed;
53575363

53585364
if (!CondScope.destroy())

clang/lib/CodeGen/CGDecl.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,8 @@ void CodeGenFunction::EmitDecl(const Decl &D, bool EvaluateConditionDecl) {
164164
assert(VD.isLocalVarDecl() &&
165165
"Should not see file-scope variables inside a function!");
166166
EmitVarDecl(VD);
167-
if (auto *DD = dyn_cast<DecompositionDecl>(&VD);
168-
EvaluateConditionDecl && DD)
169-
EmitDecompositionVarInit(*DD);
167+
if (EvaluateConditionDecl)
168+
MaybeEmitDeferredVarDeclInit(&VD);
170169

171170
return;
172171
}
@@ -2056,10 +2055,12 @@ void CodeGenFunction::EmitAutoVarInit(const AutoVarEmission &emission) {
20562055
/*IsAutoInit=*/false);
20572056
}
20582057

2059-
void CodeGenFunction::EmitDecompositionVarInit(const DecompositionDecl &DD) {
2060-
for (auto *B : DD.flat_bindings())
2061-
if (auto *HD = B->getHoldingVar())
2062-
EmitVarDecl(*HD);
2058+
void CodeGenFunction::MaybeEmitDeferredVarDeclInit(const VarDecl *VD) {
2059+
if (auto *DD = dyn_cast_if_present<DecompositionDecl>(VD)) {
2060+
for (auto *B : DD->flat_bindings())
2061+
if (auto *HD = B->getHoldingVar())
2062+
EmitVarDecl(*HD);
2063+
}
20632064
}
20642065

20652066
/// Emit an expression as an initializer for an object (variable, field, etc.)

clang/lib/CodeGen/CGStmt.cpp

Lines changed: 6 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -913,9 +913,7 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) {
913913
if (CondConstant)
914914
incrementProfileCounter(&S);
915915
if (Executed) {
916-
if (auto *DD = dyn_cast_if_present<DecompositionDecl>(
917-
S.getConditionVariable()))
918-
EmitDecompositionVarInit(*DD);
916+
MaybeEmitDeferredVarDeclInit(S.getConditionVariable());
919917
RunCleanupsScope ExecutedScope(*this);
920918
EmitStmt(Executed);
921919
}
@@ -961,9 +959,7 @@ void CodeGenFunction::EmitIfStmt(const IfStmt &S) {
961959
/*ConditionalDecl=*/S.getConditionVariable());
962960
} else {
963961
llvm::Value *BoolCondVal = EvaluateExprAsBool(S.getCond());
964-
if (auto *DD =
965-
dyn_cast_if_present<DecompositionDecl>(S.getConditionVariable()))
966-
EmitDecompositionVarInit(*DD);
962+
MaybeEmitDeferredVarDeclInit(S.getConditionVariable());
967963
Builder.CreateCondBr(BoolCondVal, ThenBlock, ElseBlock);
968964
}
969965

@@ -1107,9 +1103,7 @@ void CodeGenFunction::EmitWhileStmt(const WhileStmt &S,
11071103
// execution of the loop body.
11081104
llvm::Value *BoolCondVal = EvaluateExprAsBool(S.getCond());
11091105

1110-
if (auto *DD =
1111-
dyn_cast_if_present<DecompositionDecl>(S.getConditionVariable()))
1112-
EmitDecompositionVarInit(*DD);
1106+
MaybeEmitDeferredVarDeclInit(S.getConditionVariable());
11131107

11141108
// while(1) is common, avoid extra exit blocks. Be sure
11151109
// to correctly handle break/continue though.
@@ -1345,9 +1339,7 @@ void CodeGenFunction::EmitForStmt(const ForStmt &S,
13451339
// compares unequal to 0. The condition must be a scalar type.
13461340
llvm::Value *BoolCondVal = EvaluateExprAsBool(S.getCond());
13471341

1348-
if (auto *DD =
1349-
dyn_cast_if_present<DecompositionDecl>(S.getConditionVariable()))
1350-
EmitDecompositionVarInit(*DD);
1342+
MaybeEmitDeferredVarDeclInit(S.getConditionVariable());
13511343

13521344
llvm::MDNode *Weights =
13531345
createProfileWeightsForLoop(S.getCond(), getProfileCount(S.getBody()));
@@ -2244,11 +2236,7 @@ void CodeGenFunction::EmitSwitchStmt(const SwitchStmt &S) {
22442236
// Emit the condition variable if needed inside the entire cleanup scope
22452237
// used by this special case for constant folded switches.
22462238
if (S.getConditionVariable())
2247-
EmitDecl(*S.getConditionVariable());
2248-
2249-
if (auto *DD =
2250-
dyn_cast_if_present<DecompositionDecl>(S.getConditionVariable()))
2251-
EmitDecompositionVarInit(*DD);
2239+
EmitDecl(*S.getConditionVariable(), /*EvaluateConditionDecl=*/true);
22522240

22532241
// At this point, we are no longer "within" a switch instance, so
22542242
// we can temporarily enforce this to ensure that any embedded case
@@ -2280,10 +2268,7 @@ void CodeGenFunction::EmitSwitchStmt(const SwitchStmt &S) {
22802268
if (S.getConditionVariable())
22812269
EmitDecl(*S.getConditionVariable());
22822270
llvm::Value *CondV = EmitScalarExpr(S.getCond());
2283-
2284-
if (auto *DD =
2285-
dyn_cast_if_present<DecompositionDecl>(S.getConditionVariable()))
2286-
EmitDecompositionVarInit(*DD);
2271+
MaybeEmitDeferredVarDeclInit(S.getConditionVariable());
22872272

22882273
// Create basic block to hold stuff that comes after switch
22892274
// statement. We also need to create a default block now so that

clang/lib/CodeGen/CodeGenFunction.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2048,8 +2048,7 @@ void CodeGenFunction::EmitBranchOnBoolExpr(
20482048
CondV = EvaluateExprAsBool(Cond);
20492049
}
20502050

2051-
if (auto *DD = dyn_cast_if_present<DecompositionDecl>(ConditionalDecl))
2052-
EmitDecompositionVarInit(*DD);
2051+
MaybeEmitDeferredVarDeclInit(ConditionalDecl);
20532052

20542053
// If not at the top of the logical operator nest, update MCDC temp with the
20552054
// boolean result of the evaluated condition.

clang/lib/CodeGen/CodeGenFunction.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3474,7 +3474,7 @@ class CodeGenFunction : public CodeGenTypeCache {
34743474
void emitAutoVarTypeCleanup(const AutoVarEmission &emission,
34753475
QualType::DestructionKind dtorKind);
34763476

3477-
void EmitDecompositionVarInit(const DecompositionDecl &var);
3477+
void MaybeEmitDeferredVarDeclInit(const VarDecl *var);
34783478

34793479
/// Emits the alloca and debug information for the size expressions for each
34803480
/// dimension of an array. It registers the association of its (1-dimensional)

clang/lib/Sema/SemaDeclCXX.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -743,10 +743,10 @@ Sema::ActOnDecompositionDeclarator(Scope *S, Declarator &D,
743743
unsigned DiagID;
744744
if (!getLangOpts().CPlusPlus17)
745745
DiagID = diag::ext_decomp_decl;
746-
else if (D.getContext() == DeclaratorContext::Condition) {
746+
else if (D.getContext() == DeclaratorContext::Condition)
747747
DiagID = getLangOpts().CPlusPlus26 ? diag::warn_cxx26_decomp_decl_cond
748748
: diag::ext_decomp_decl_cond;
749-
} else
749+
else
750750
DiagID = diag::warn_cxx14_compat_decomp_decl;
751751

752752
Diag(Decomp.getLSquareLoc(), DiagID) << Decomp.getSourceRange();

0 commit comments

Comments
 (0)