diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Parse/ParseStmt.cpp | 4 | ||||
-rw-r--r-- | lib/Sema/SemaStmt.cpp | 13 |
2 files changed, 8 insertions, 9 deletions
diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp index 2022fa51cf..c87010e356 100644 --- a/lib/Parse/ParseStmt.cpp +++ b/lib/Parse/ParseStmt.cpp @@ -715,9 +715,7 @@ Parser::OwningStmtResult Parser::ParseSwitchStatement(AttributeList *Attr) { FullExprArg FullCond(Actions.FullExpr(Cond)); - OwningStmtResult Switch(Actions); - if (!Cond.isInvalid() || CondVar.get()) - Switch = Actions.ActOnStartOfSwitchStmt(FullCond, CondVar); + OwningStmtResult Switch = Actions.ActOnStartOfSwitchStmt(FullCond, CondVar); // C99 6.8.4p3 - In C99, the body of the switch statement is a scope, even if // there is no compound stmt. C90 does not have this clause. We only do this diff --git a/lib/Sema/SemaStmt.cpp b/lib/Sema/SemaStmt.cpp index b54de3e171..e2b065bb90 100644 --- a/lib/Sema/SemaStmt.cpp +++ b/lib/Sema/SemaStmt.cpp @@ -288,12 +288,8 @@ Sema::ActOnStartOfSwitchStmt(FullExprArg cond, DeclPtrTy CondVar) { if (CondResult.isInvalid()) return StmtError(); } - Expr *ConditionExpr = CondResult.takeAs<Expr>(); - if (!ConditionExpr) - return StmtError(); - - CondResult.release(); - SwitchStmt *SS = new (Context) SwitchStmt(ConditionVar, ConditionExpr); + SwitchStmt *SS = new (Context) SwitchStmt(ConditionVar, + CondResult.takeAs<Expr>()); getSwitchStack().push_back(SS); return Owned(SS); } @@ -496,6 +492,11 @@ Sema::ActOnFinishSwitchStmt(SourceLocation SwitchLoc, StmtArg Switch, SS->setBody(BodyStmt, SwitchLoc); getSwitchStack().pop_back(); + if (SS->getCond() == 0) { + SS->Destroy(Context); + return StmtError(); + } + Expr *CondExpr = SS->getCond(); QualType CondTypeBeforePromotion = GetTypeBeforeIntegralPromotion(CondExpr); |