@@ -582,48 +582,45 @@ CodeGenFunction::EmitCompoundStmtWithoutScope(const CompoundStmt &S,
582582 bool GetLast,
583583 AggValueSlot AggSlot) {
584584
585- const Stmt *ExprResult = S.getStmtExprResult ();
586- assert ((!GetLast || (GetLast && ExprResult)) &&
587- " If GetLast is true then the CompoundStmt must have a StmtExprResult" );
585+ for (CompoundStmt::const_body_iterator I = S.body_begin (),
586+ E = S.body_end () - GetLast;
587+ I != E; ++I)
588+ EmitStmt (*I);
588589
589590 Address RetAlloca = Address::invalid ();
590-
591- for (auto *CurStmt : S.body ()) {
592- if (GetLast && ExprResult == CurStmt) {
593- // We have to special case labels here. They are statements, but when put
594- // at the end of a statement expression, they yield the value of their
595- // subexpression. Handle this by walking through all labels we encounter,
596- // emitting them before we evaluate the subexpr.
597- // Similar issues arise for attributed statements.
598- while (!isa<Expr>(ExprResult)) {
599- if (const auto *LS = dyn_cast<LabelStmt>(ExprResult)) {
600- EmitLabel (LS->getDecl ());
601- ExprResult = LS->getSubStmt ();
602- } else if (const auto *AS = dyn_cast<AttributedStmt>(ExprResult)) {
603- // FIXME: Update this if we ever have attributes that affect the
604- // semantics of an expression.
605- ExprResult = AS->getSubStmt ();
606- } else {
607- llvm_unreachable (" unknown value statement" );
608- }
591+ if (GetLast) {
592+ // We have to special case labels here. They are statements, but when put
593+ // at the end of a statement expression, they yield the value of their
594+ // subexpression. Handle this by walking through all labels we encounter,
595+ // emitting them before we evaluate the subexpr.
596+ // Similar issues arise for attributed statements.
597+ const Stmt *LastStmt = S.body_back ();
598+ while (!isa<Expr>(LastStmt)) {
599+ if (const auto *LS = dyn_cast<LabelStmt>(LastStmt)) {
600+ EmitLabel (LS->getDecl ());
601+ LastStmt = LS->getSubStmt ();
602+ } else if (const auto *AS = dyn_cast<AttributedStmt>(LastStmt)) {
603+ // FIXME: Update this if we ever have attributes that affect the
604+ // semantics of an expression.
605+ LastStmt = AS->getSubStmt ();
606+ } else {
607+ llvm_unreachable (" unknown value statement" );
609608 }
609+ }
610610
611- EnsureInsertPoint ();
611+ EnsureInsertPoint ();
612612
613- const Expr *E = cast<Expr>(ExprResult);
614- QualType ExprTy = E->getType ();
615- if (hasAggregateEvaluationKind (ExprTy)) {
616- EmitAggExpr (E, AggSlot);
617- } else {
618- // We can't return an RValue here because there might be cleanups at
619- // the end of the StmtExpr. Because of that, we have to emit the result
620- // here into a temporary alloca.
621- RetAlloca = CreateMemTemp (ExprTy);
622- EmitAnyExprToMem (E, RetAlloca, Qualifiers (),
623- /* IsInit*/ false );
624- }
613+ const Expr *E = cast<Expr>(LastStmt);
614+ QualType ExprTy = E->getType ();
615+ if (hasAggregateEvaluationKind (ExprTy)) {
616+ EmitAggExpr (E, AggSlot);
625617 } else {
626- EmitStmt (CurStmt);
618+ // We can't return an RValue here because there might be cleanups at
619+ // the end of the StmtExpr. Because of that, we have to emit the result
620+ // here into a temporary alloca.
621+ RetAlloca = CreateMemTemp (ExprTy);
622+ EmitAnyExprToMem (E, RetAlloca, Qualifiers (),
623+ /* IsInit*/ false );
627624 }
628625 }
629626
0 commit comments