From: lishin Date: Fri, 29 May 2026 17:42:13 +0000 (+0000) Subject: gccrs: add block drop candidate tracking infrastructure X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ce41da7d361b1c7a810fa4a85c21d960f8029db2;p=thirdparty%2Fgcc.git 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 --- diff --git a/gcc/rust/backend/rust-compile-context.h b/gcc/rust/backend/rust-compile-context.h index abc8f1ed5df..4f541d1b3c1 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 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 &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 compiled_labels; std::vector<::std::vector> statements; std::vector scope_stack; + std::vector<::std::vector> block_drop_candidates; std::vector<::Bvariable *> loop_value_stack; std::vector loop_begin_labels; std::map>>