@@ -4131,6 +4131,21 @@ static EvalStmtResult EvaluateStmt(StmtResult &Result, EvalInfo &Info,
4131
4131
// preceded by our switch label.
4132
4132
BlockScopeRAII Scope (Info);
4133
4133
4134
+ // Step into the init statement in case it brings an (uninitialized)
4135
+ // variable into scope.
4136
+ if (const Stmt *Init = IS->getInit ()) {
4137
+ EvalStmtResult ESR = EvaluateStmt (Result, Info, Init, Case);
4138
+ if (ESR != ESR_CaseNotFound) {
4139
+ assert (ESR != ESR_Succeeded);
4140
+ return ESR;
4141
+ }
4142
+ }
4143
+
4144
+ // Condition variable must be initialized if it exists.
4145
+ // FIXME: We can skip evaluating the body if there's a condition
4146
+ // variable, as there can't be any case labels within it.
4147
+ // (The same is true for 'for' statements.)
4148
+
4134
4149
EvalStmtResult ESR = EvaluateStmt (Result, Info, IS->getThen (), Case);
4135
4150
if (ESR != ESR_CaseNotFound || !IS->getElse ())
4136
4151
return ESR;
@@ -4147,6 +4162,18 @@ static EvalStmtResult EvaluateStmt(StmtResult &Result, EvalInfo &Info,
4147
4162
4148
4163
case Stmt::ForStmtClass: {
4149
4164
const ForStmt *FS = cast<ForStmt>(S);
4165
+ BlockScopeRAII Scope (Info);
4166
+
4167
+ // Step into the init statement in case it brings an (uninitialized)
4168
+ // variable into scope.
4169
+ if (const Stmt *Init = FS->getInit ()) {
4170
+ EvalStmtResult ESR = EvaluateStmt (Result, Info, Init, Case);
4171
+ if (ESR != ESR_CaseNotFound) {
4172
+ assert (ESR != ESR_Succeeded);
4173
+ return ESR;
4174
+ }
4175
+ }
4176
+
4150
4177
EvalStmtResult ESR =
4151
4178
EvaluateLoopBody (Result, Info, FS->getBody (), Case);
4152
4179
if (ESR != ESR_Continue)
0 commit comments