https://gcc.gnu.org/g:80c98ea9eea1ad1ab3381af0f8f900c2c49bcc5b

commit r17-3096-g80c98ea9eea1ad1ab3381af0f8f900c2c49bcc5b
Author: Lishin <[email protected]>
Date:   Tue Jul 7 15:21:49 2026 +0000

    gccrs: Use EH_ELSE_EXPR in block Drop TRY_FINALLY_EXPR
    
    Use the Drop cleanup as the normal cleanup and an empty statement as
    the exceptional cleanup.
    
    This keeps block-scope Drop cleanup on normal control-flow exits without
    requiring the gccrs EH personality while stack unwinding is not implemented.
    
    gcc/rust/ChangeLog:
    
            * backend/rust-compile-context.h:
            (Context::pop_block_impl): Wrap Drop cleanup in an EH_ELSE_EXPR.
    
    Signed-off-by: Lishin <[email protected]>

Diff:
---
 gcc/rust/backend/rust-compile-context.h | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/gcc/rust/backend/rust-compile-context.h 
b/gcc/rust/backend/rust-compile-context.h
index 25a27ca96281..7f67b9382e05 100644
--- a/gcc/rust/backend/rust-compile-context.h
+++ b/gcc/rust/backend/rust-compile-context.h
@@ -437,8 +437,14 @@ private:
        if (body == NULL_TREE)
          body = build_empty_stmt (cleanup_locus);
 
+       tree exceptional_cleanup = build_empty_stmt (cleanup_locus);
+       tree cleanup_selector
+         = build2_loc (cleanup_locus, EH_ELSE_EXPR, void_type_node, cleanup,
+                       exceptional_cleanup);
+
        tree try_finally
-         = Backend::exception_handler_statement (body, NULL_TREE, cleanup,
+         = Backend::exception_handler_statement (body, NULL_TREE,
+                                                 cleanup_selector,
                                                  cleanup_locus);
        Backend::block_add_statements (block, {try_finally});
       }

Reply via email to