Line data Source code
1 : // Copyright (C) 2026 Free Software Foundation, Inc.
2 :
3 : // This file is part of GCC.
4 :
5 : // GCC is free software; you can redistribute it and/or modify it under
6 : // the terms of the GNU General Public License as published by the Free
7 : // Software Foundation; either version 3, or (at your option) any later
8 : // version.
9 :
10 : // GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11 : // WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 : // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 : // for more details.
14 :
15 : // You should have received a copy of the GNU General Public License
16 : // along with GCC; see the file COPYING3. If not see
17 : // <http://www.gnu.org/licenses/>.
18 :
19 : #include "rust-compile-drop-builder.h"
20 : #include "rust-compile-context.h"
21 : #include "rust-bir-drop-analysis.h"
22 :
23 : namespace Rust {
24 : namespace Compile {
25 :
26 65477 : DropBuilder::DropBuilder (Context &ctx) : ctx (ctx) {}
27 :
28 : void
29 63 : DropBuilder::note_simple_drop_candidate (HirId hirid, location_t locus)
30 : {
31 63 : rust_assert (!ctx.block_drop_candidates.empty ());
32 63 : ctx.block_drop_candidates.back ().emplace_back (hirid, locus);
33 63 : }
34 :
35 : void
36 55 : DropBuilder::maybe_create_drop_flag (HirId hirid, location_t locus,
37 : bool initialized)
38 : {
39 55 : if (!BIR::DropAnalysis::get ().needs_drop_flag (hirid))
40 54 : return;
41 :
42 1 : Bvariable *existing = nullptr;
43 1 : if (ctx.lookup_drop_flag (hirid, &existing))
44 : return;
45 :
46 1 : tree declaration = nullptr;
47 2 : Bvariable *flag = Backend::temporary_variable (
48 1 : ctx.peek_fn ().fndecl, nullptr, boolean_type_node,
49 : Backend::boolean_constant_expression (initialized), false, locus,
50 : &declaration);
51 1 : ctx.add_statement (declaration);
52 1 : ctx.insert_drop_flag (hirid, flag);
53 : }
54 :
55 : tree
56 11956 : DropBuilder::drop_flag_assignment (HirId hirid, bool value, location_t locus)
57 : {
58 11956 : Bvariable *flag = nullptr;
59 11956 : if (!ctx.lookup_drop_flag (hirid, &flag))
60 : return nullptr;
61 :
62 3 : return Backend::assignment_statement (Backend::var_expression (flag, locus),
63 : Backend::boolean_constant_expression (
64 : value),
65 3 : locus);
66 : }
67 :
68 : std::vector<DropCandidate> &
69 39244 : DropBuilder::peek_block_drop_candidates ()
70 : {
71 39244 : rust_assert (!ctx.block_drop_candidates.empty ());
72 39244 : return ctx.block_drop_candidates.back ();
73 : }
74 :
75 : } // namespace Compile
76 : } // namespace Rust
|