From: Lishin <[email protected]>

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]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.


Commit on github: 
https://github.com/Rust-GCC/gccrs/commit/2a1f86dfe935a7309198cc9b66f45d62b9b37cf9

The commit has NOT been mentioned in any issue.

The commit has been mentioned in the following pull-request(s):
 - https://github.com/Rust-GCC/gccrs/pull/4685

 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 25a27ca96..7f67b9382 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});
       }
-- 
2.54.0

Reply via email to