[clang] [codegen] Emit missing cleanups for stmt-expr and coro suspensions [take-2] (PR #85398)

Utkarsh Saxena via cfe-commits cfe-commits at lists.llvm.org
Mon Mar 25 07:01:45 PDT 2024


================
@@ -2503,6 +2505,26 @@ Stmt *BlockExpr::getBody() {
 // Generic Expression Routines
 //===----------------------------------------------------------------------===//
 
+bool Expr::mayBranchOut() const {
+  struct BranchDetector : public RecursiveASTVisitor<BranchDetector> {
+    bool HasBranch = false;
+    bool activate() {
+      HasBranch = true;
+      return false;
+    }
+    // Coroutine suspensions.
+    bool VisitCoawaitExpr(CoawaitExpr *) { return activate(); }
+    bool VisitCoyieldExpr(CoyieldExpr *) { return activate(); }
+    // Control flow in stmt-expressions.
+    bool VisitBreakStmt(BreakStmt *) { return activate(); }
+    bool VisitReturnStmt(ReturnStmt *) { return activate(); }
+    bool VisitGotoStmt(GotoStmt *) { return activate(); }
+  };
----------------
usx95 wrote:

I think it should be fine to stick to non-exceptional control flow out of this expression. `throw` or, for that matter, any call to a throwing function would be branching but that is already dealt with exceptions.

https://github.com/llvm/llvm-project/pull/85398


More information about the cfe-commits mailing list