From: lishin <[email protected]>

Add the basic structure for saving local variables that may need Drop.

gcc/rust/ChangeLog:

        * backend/rust-compile-context.h (struct DropCandidate): New struct
        for tracking block-local drop candidates.

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/066b6834bebf500d7d16bf46c0c80324684e35e2

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/4564

 gcc/rust/backend/rust-compile-context.h | 23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/gcc/rust/backend/rust-compile-context.h 
b/gcc/rust/backend/rust-compile-context.h
index abc8f1ed5..4f541d1b3 100644
--- a/gcc/rust/backend/rust-compile-context.h
+++ b/gcc/rust/backend/rust-compile-context.h
@@ -50,6 +50,12 @@ struct CustomDeriveInfo
   std::vector<std::string> attributes;
 };
 
+struct DropCandidate
+{
+  HirId hirid;
+  location_t locus;
+};
+
 class Context
 {
 public:
@@ -101,6 +107,7 @@ public:
   {
     scope_stack.push_back (scope);
     statements.push_back ({});
+    block_drop_candidates.emplace_back ();
   }
 
   tree pop_block ()
@@ -111,6 +118,9 @@ public:
     auto stmts = statements.back ();
     statements.pop_back ();
 
+    rust_assert (!block_drop_candidates.empty ());
+    block_drop_candidates.pop_back ();
+
     Backend::block_add_statements (block, stmts);
 
     return block;
@@ -131,6 +141,18 @@ public:
 
   void add_statement (tree stmt) { statements.back ().push_back (stmt); }
 
+  std::vector<DropCandidate> &peek_block_drop_candidates ()
+  {
+    rust_assert (!block_drop_candidates.empty ());
+    return block_drop_candidates.back ();
+  }
+
+  void note_simple_drop_candidate (HirId hirid, location_t locus)
+  {
+    rust_assert (!block_drop_candidates.empty ());
+    block_drop_candidates.back ().push_back ({hirid, locus});
+  }
+
   void insert_var_decl (HirId id, ::Bvariable *decl)
   {
     compiled_var_decls[id] = decl;
@@ -419,6 +441,7 @@ private:
   std::map<HirId, tree> compiled_labels;
   std::vector<::std::vector<tree>> statements;
   std::vector<tree> scope_stack;
+  std::vector<::std::vector<DropCandidate>> block_drop_candidates;
   std::vector<::Bvariable *> loop_value_stack;
   std::vector<tree> loop_begin_labels;
   std::map<DefId, std::vector<std::pair<const TyTy::BaseType *, tree>>>

base-commit: 7a4484b9258617de89901b0eaad22644f9bbff03
-- 
2.54.0

Reply via email to