]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: add block drop candidate tracking infrastructure
authorlishin <lishin1008@gmail.com>
Fri, 29 May 2026 17:42:13 +0000 (17:42 +0000)
committerArthur Cohen <arthur.cohen@embecosm.com>
Thu, 25 Jun 2026 17:21:34 +0000 (19:21 +0200)
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 <lishin1008@gmail.com>
gcc/rust/backend/rust-compile-context.h

index abc8f1ed5dfc5e89bbf7ea98cd97dcd40c342a3f..4f541d1b3c1d521204c78979102e49e33e266350 100644 (file)
@@ -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>>>