https://gcc.gnu.org/g:ce41da7d361b1c7a810fa4a85c21d960f8029db2

commit r17-1891-gce41da7d361b1c7a810fa4a85c21d960f8029db2
Author: lishin <[email protected]>
Date:   Fri May 29 17:42:13 2026 +0000

    gccrs: add block drop candidate tracking infrastructure
    
    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]>

Diff:
---
 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 abc8f1ed5dfc..4f541d1b3c1d 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>>>

Reply via email to