https://gcc.gnu.org/g:344eb37e793b3dbbd4f45bba18bda789aa3c6715

commit r17-3094-g344eb37e793b3dbbd4f45bba18bda789aa3c6715
Author: Lishin <[email protected]>
Date:   Thu Jul 2 13:56:27 2026 +0000

    gccrs: Add builder for current-scope drop cleanup
    
    Add CompileDrop::build_current_scope_drop_cleanup to build the drop
    calls for the current scope as one statement tree.
    
    This allows a follow-up patch to place the same cleanup tree in a
    TRY_FINALLY_EXPR.
    
    gcc/rust/ChangeLog:
    
            * backend/rust-compile-drop.cc
            (CompileDrop::build_current_scope_drop_cleanup): New function to
            build current scope drop calls as a statement tree.
            (CompileDrop::emit_current_scope_drop_calls): Use it.
            * backend/rust-compile-drop.h
            (CompileDrop::build_current_scope_drop_cleanup): Declare.
    
    Signed-off-by: Lishin <[email protected]>

Diff:
---
 gcc/rust/backend/rust-compile-drop.cc | 21 ++++++++++++++++++---
 gcc/rust/backend/rust-compile-drop.h  |  1 +
 2 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/gcc/rust/backend/rust-compile-drop.cc 
b/gcc/rust/backend/rust-compile-drop.cc
index 5cb4db0e4798..0062f30e2611 100644
--- a/gcc/rust/backend/rust-compile-drop.cc
+++ b/gcc/rust/backend/rust-compile-drop.cc
@@ -90,9 +90,11 @@ CompileDrop::compile_drop_call (Bvariable *var, 
TyTy::BaseType *ty,
   return Backend::call_expression (fn_addr, {var_addr}, nullptr, locus);
 }
 
-void
-CompileDrop::emit_current_scope_drop_calls ()
+tree
+CompileDrop::build_current_scope_drop_cleanup ()
 {
+  std::vector<tree> drop_stmts;
+
   DropBuilder drop_builder (*ctx);
   auto &drop_candidates = drop_builder.peek_block_drop_candidates ();
 
@@ -109,8 +111,21 @@ CompileDrop::emit_current_scope_drop_calls ()
 
       tree drop_call = compile_drop_call (var, ty, it->locus);
       if (drop_call != NULL_TREE)
-       ctx->add_statement (convert_to_void (drop_call, ICV_STATEMENT));
+       drop_stmts.push_back (convert_to_void (drop_call, ICV_STATEMENT));
     }
+
+  if (drop_stmts.empty ())
+    return NULL_TREE;
+
+  return Backend::statement_list (drop_stmts);
+}
+
+void
+CompileDrop::emit_current_scope_drop_calls ()
+{
+  tree cleanup = build_current_scope_drop_cleanup ();
+  if (cleanup != NULL_TREE)
+    ctx->add_statement (cleanup);
 }
 
 } // namespace Compile
diff --git a/gcc/rust/backend/rust-compile-drop.h 
b/gcc/rust/backend/rust-compile-drop.h
index 55a09c5dd9ed..dea3e19359ba 100644
--- a/gcc/rust/backend/rust-compile-drop.h
+++ b/gcc/rust/backend/rust-compile-drop.h
@@ -31,6 +31,7 @@ public:
 
   bool type_has_drop_impl (TyTy::BaseType *ty);
 
+  tree build_current_scope_drop_cleanup ();
   void emit_current_scope_drop_calls ();
 
 private:

Reply via email to