@@ -2477,6 +2477,8 @@ SingleValueStmtExpr *SingleValueStmtExpr::create(ASTContext &ctx, Stmt *S,
24772477
24782478SingleValueStmtExpr *SingleValueStmtExpr::createWithWrappedBranches (
24792479 ASTContext &ctx, Stmt *S, DeclContext *DC, bool mustBeExpr) {
2480+ assert (!(isa<DoStmt>(S) || isa<DoCatchStmt>(S)) ||
2481+ ctx.LangOpts .hasFeature (Feature::DoExpressions));
24802482 auto *SVE = create (ctx, S, DC);
24812483
24822484 // Attempt to wrap any branches that can be wrapped.
@@ -2488,12 +2490,15 @@ SingleValueStmtExpr *SingleValueStmtExpr::createWithWrappedBranches(
24882490
24892491 if (auto *S = BS->getSingleActiveStatement ()) {
24902492 if (mustBeExpr) {
2491- // If this must be an expression, we can eagerly wrap any exhaustive if
2492- // and switch branch .
2493+ // If this must be an expression, we can eagerly wrap any exhaustive if,
2494+ // switch, and do statement .
24932495 if (auto *IS = dyn_cast<IfStmt>(S)) {
24942496 if (!IS->isSyntacticallyExhaustive ())
24952497 continue ;
2496- } else if (!isa<SwitchStmt>(S)) {
2498+ } else if (auto *DCS = dyn_cast<DoCatchStmt>(S)) {
2499+ if (!DCS->isSyntacticallyExhaustive ())
2500+ continue ;
2501+ } else if (!isa<SwitchStmt>(S) && !isa<DoStmt>(S)) {
24972502 continue ;
24982503 }
24992504 } else {
@@ -2576,18 +2581,28 @@ SingleValueStmtExpr::Kind SingleValueStmtExpr::getStmtKind() const {
25762581 return Kind::If;
25772582 case StmtKind::Switch:
25782583 return Kind::Switch;
2584+ case StmtKind::Do:
2585+ return Kind::Do;
2586+ case StmtKind::DoCatch:
2587+ return Kind::DoCatch;
25792588 default :
25802589 llvm_unreachable (" Unhandled kind!" );
25812590 }
25822591}
25832592
25842593ArrayRef<Stmt *>
25852594SingleValueStmtExpr::getBranches (SmallVectorImpl<Stmt *> &scratch) const {
2595+ assert (scratch.empty ());
25862596 switch (getStmtKind ()) {
25872597 case Kind::If:
25882598 return cast<IfStmt>(getStmt ())->getBranches (scratch);
25892599 case Kind::Switch:
25902600 return cast<SwitchStmt>(getStmt ())->getBranches (scratch);
2601+ case Kind::Do:
2602+ scratch.push_back (cast<DoStmt>(getStmt ())->getBody ());
2603+ return scratch;
2604+ case Kind::DoCatch:
2605+ return cast<DoCatchStmt>(getStmt ())->getBranches (scratch);
25912606 }
25922607 llvm_unreachable (" Unhandled case in switch!" );
25932608}
0 commit comments