From: Lishin <[email protected]>
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]>
---
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 5cb4db0e479..0062f30e261 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 55a09c5dd9e..dea3e19359b 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:
--
2.50.1
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.