LCOV - code coverage report
Current view: top level - gcc/rust/checks/lints - rust-lint-marklive.h (source / functions) Coverage Total Hit
Test: gcc.info Lines: 92.5 % 146 135
Test Date: 2025-06-28 16:12:38 Functions: 91.9 % 37 34
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : // Copyright (C) 2021-2025 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                 :             : #ifndef RUST_HIR_LIVENESS
      20                 :             : #define RUST_HIR_LIVENESS
      21                 :             : 
      22                 :             : #include "rust-hir-full-decls.h"
      23                 :             : #include "rust-hir-map.h"
      24                 :             : #include "rust-lint-marklive-base.h"
      25                 :             : #include "rust-name-resolver.h"
      26                 :             : 
      27                 :             : namespace Rust {
      28                 :             : namespace Analysis {
      29                 :             : 
      30                 :             : class MarkLive : public MarkLiveBase
      31                 :             : {
      32                 :             :   using Rust::Analysis::MarkLiveBase::visit;
      33                 :             : 
      34                 :             : public:
      35                 :             :   static std::set<HirId> Analysis (HIR::Crate &crate);
      36                 :             :   void go (HIR::Crate &crate);
      37                 :             : 
      38                 :             :   void visit (HIR::PathInExpression &expr) override;
      39                 :             :   void visit (HIR::FieldAccessExpr &expr) override;
      40                 :             :   void visit (HIR::TupleIndexExpr &expr) override;
      41                 :             :   void visit (HIR::MethodCallExpr &expr) override;
      42                 :             :   void visit (HIR::TypeAlias &alias) override;
      43                 :             : 
      44                 :        1152 :   void visit (HIR::BorrowExpr &expr) override
      45                 :             :   {
      46                 :        1152 :     expr.get_expr ().accept_vis (*this);
      47                 :        1152 :   }
      48                 :             : 
      49                 :         244 :   void visit (HIR::DereferenceExpr &expr) override
      50                 :             :   {
      51                 :         244 :     expr.get_expr ().accept_vis (*this);
      52                 :         244 :   }
      53                 :             : 
      54                 :         325 :   void visit (HIR::NegationExpr &expr) override
      55                 :             :   {
      56                 :         325 :     expr.get_expr ().accept_vis (*this);
      57                 :         325 :   }
      58                 :             : 
      59                 :        1020 :   void visit (HIR::LazyBooleanExpr &expr) override
      60                 :             :   {
      61                 :        1020 :     expr.get_lhs ().accept_vis (*this);
      62                 :        1020 :     expr.get_rhs ().accept_vis (*this);
      63                 :        1020 :   }
      64                 :             : 
      65                 :        6855 :   void visit (HIR::TypeCastExpr &expr) override
      66                 :             :   {
      67                 :        6855 :     expr.get_expr ().accept_vis (*this);
      68                 :        6855 :   }
      69                 :             : 
      70                 :         228 :   void visit (HIR::GroupedExpr &expr) override
      71                 :             :   {
      72                 :         228 :     expr.get_expr_in_parens ().accept_vis (*this);
      73                 :         228 :   }
      74                 :             : 
      75                 :         328 :   void visit (HIR::ArrayExpr &expr) override
      76                 :             :   {
      77                 :         328 :     expr.get_internal_elements ().accept_vis (*this);
      78                 :         328 :   }
      79                 :             : 
      80                 :         281 :   void visit (HIR::ArrayIndexExpr &expr) override
      81                 :             :   {
      82                 :         281 :     expr.get_array_expr ().accept_vis (*this);
      83                 :         281 :     expr.get_index_expr ().accept_vis (*this);
      84                 :         281 :   }
      85                 :             : 
      86                 :         233 :   void visit (HIR::ArrayElemsValues &expr) override
      87                 :             :   {
      88                 :        1396 :     for (auto &elem : expr.get_values ())
      89                 :             :       {
      90                 :        1163 :         elem->accept_vis (*this);
      91                 :             :       }
      92                 :         233 :   }
      93                 :             : 
      94                 :         495 :   void visit (HIR::TupleExpr &expr) override
      95                 :             :   {
      96                 :        1226 :     for (auto &elem : expr.get_tuple_elems ())
      97                 :             :       {
      98                 :         731 :         elem->accept_vis (*this);
      99                 :             :       }
     100                 :         495 :   }
     101                 :             : 
     102                 :       17111 :   void visit (HIR::BlockExpr &expr) override
     103                 :             :   {
     104                 :       43493 :     for (auto &s : expr.get_statements ())
     105                 :             :       {
     106                 :       26382 :         s->accept_vis (*this);
     107                 :             :       }
     108                 :       17111 :     if (expr.has_expr ())
     109                 :             :       {
     110                 :        9593 :         expr.get_final_expr ().accept_vis (*this);
     111                 :             :       }
     112                 :       17111 :   }
     113                 :             : 
     114                 :        3465 :   void visit (HIR::UnsafeBlockExpr &expr) override
     115                 :             :   {
     116                 :        3465 :     expr.get_block_expr ().accept_vis (*this);
     117                 :        3465 :   }
     118                 :             : 
     119                 :         127 :   void visit (HIR::LoopExpr &expr) override
     120                 :             :   {
     121                 :         127 :     expr.get_loop_block ().accept_vis (*this);
     122                 :         127 :   }
     123                 :             : 
     124                 :          91 :   void visit (HIR::BreakExpr &expr) override
     125                 :             :   {
     126                 :          91 :     if (expr.has_break_expr ())
     127                 :          18 :       expr.get_expr ().accept_vis (*this);
     128                 :          91 :   }
     129                 :             : 
     130                 :         121 :   void visit (HIR::WhileLoopExpr &expr) override
     131                 :             :   {
     132                 :         121 :     expr.get_loop_block ().accept_vis (*this);
     133                 :         121 :     expr.get_predicate_expr ().accept_vis (*this);
     134                 :         121 :   }
     135                 :             : 
     136                 :       10174 :   void visit (HIR::Function &function) override
     137                 :             :   {
     138                 :       10174 :     function.get_definition ().accept_vis (*this);
     139                 :       10174 :   }
     140                 :             : 
     141                 :        1076 :   void visit (HIR::ReturnExpr &expr) override
     142                 :             :   {
     143                 :        1076 :     if (expr.has_return_expr ())
     144                 :        1060 :       expr.get_expr ().accept_vis (*this);
     145                 :        1076 :   }
     146                 :             : 
     147                 :           0 :   void visit (HIR::WhileLetLoopExpr &expr) override
     148                 :             :   {
     149                 :           0 :     expr.get_loop_block ().accept_vis (*this);
     150                 :           0 :     expr.get_cond ().accept_vis (*this);
     151                 :           0 :   }
     152                 :             : 
     153                 :       10632 :   void visit (HIR::ExprStmt &stmt) override
     154                 :             :   {
     155                 :       10632 :     stmt.get_expr ().accept_vis (*this);
     156                 :       10632 :   }
     157                 :             : 
     158                 :       10376 :   void visit (HIR::CallExpr &expr) override
     159                 :             :   {
     160                 :       10376 :     expr.get_fnexpr ().accept_vis (*this);
     161                 :       22335 :     for (auto &argument : expr.get_arguments ())
     162                 :       11959 :       argument->accept_vis (*this);
     163                 :       10376 :   }
     164                 :             : 
     165                 :        2531 :   void visit (HIR::ArithmeticOrLogicalExpr &expr) override
     166                 :             :   {
     167                 :        2531 :     expr.visit_lhs (*this);
     168                 :        2531 :     expr.visit_rhs (*this);
     169                 :        2531 :   }
     170                 :        1999 :   void visit (HIR::ComparisonExpr &expr) override
     171                 :             :   {
     172                 :        1999 :     expr.get_lhs ().accept_vis (*this);
     173                 :        1999 :     expr.get_rhs ().accept_vis (*this);
     174                 :        1999 :   }
     175                 :             : 
     176                 :        2546 :   void visit (HIR::AssignmentExpr &expr) override
     177                 :             :   {
     178                 :        2546 :     expr.visit_lhs (*this);
     179                 :        2546 :     expr.visit_rhs (*this);
     180                 :        2546 :   }
     181                 :             : 
     182                 :         273 :   void visit (HIR::CompoundAssignmentExpr &expr) override
     183                 :             :   {
     184                 :         273 :     expr.visit_lhs (*this);
     185                 :         273 :     expr.visit_rhs (*this);
     186                 :         273 :   }
     187                 :             : 
     188                 :         419 :   void visit (HIR::IfExpr &expr) override
     189                 :             :   {
     190                 :         419 :     expr.get_if_condition ().accept_vis (*this);
     191                 :         419 :     expr.get_if_block ().accept_vis (*this);
     192                 :         419 :   }
     193                 :             : 
     194                 :         546 :   void visit (HIR::IfExprConseqElse &expr) override
     195                 :             :   {
     196                 :         546 :     expr.get_if_condition ().accept_vis (*this);
     197                 :         546 :     expr.get_if_block ().accept_vis (*this);
     198                 :         546 :     expr.get_else_block ().accept_vis (*this);
     199                 :         546 :   }
     200                 :             : 
     201                 :         988 :   void visit (HIR::MatchExpr &expr) override
     202                 :             :   {
     203                 :         988 :     expr.get_scrutinee_expr ().accept_vis (*this);
     204                 :         988 :     std::vector<HIR::MatchCase> &cases = expr.get_match_cases ();
     205                 :        3471 :     for (auto &&caz : cases)
     206                 :             :       {
     207                 :        2483 :         auto case_arm = caz.get_arm ();
     208                 :        2483 :         if (case_arm.has_match_arm_guard ())
     209                 :           0 :           case_arm.get_guard_expr ().accept_vis (*this);
     210                 :        2483 :         caz.get_expr ().accept_vis (*this);
     211                 :        2483 :       }
     212                 :         988 :   }
     213                 :             : 
     214                 :           0 :   void visit (HIR::TraitItemFunc &item) override
     215                 :             :   {
     216                 :           0 :     item.get_block_expr ().accept_vis (*this);
     217                 :           0 :   }
     218                 :             : 
     219                 :         232 :   void visit (HIR::ImplBlock &impl) override
     220                 :             :   {
     221                 :         464 :     for (auto &&item : impl.get_impl_items ())
     222                 :             :       {
     223                 :         232 :         item->accept_vis (*this);
     224                 :             :       }
     225                 :         232 :   }
     226                 :             : 
     227                 :       15289 :   void visit (HIR::LetStmt &stmt) override
     228                 :             :   {
     229                 :       15289 :     if (stmt.has_init_expr ())
     230                 :             :       {
     231                 :       14047 :         stmt.get_init_expr ().accept_vis (*this);
     232                 :             :       }
     233                 :       15289 :   }
     234                 :             : 
     235                 :          57 :   void visit (HIR::StructExprStruct &stct) override
     236                 :             :   {
     237                 :          57 :     stct.get_struct_name ().accept_vis (*this);
     238                 :          57 :   }
     239                 :             : 
     240                 :        1017 :   void visit (HIR::StructExprStructFields &stct) override
     241                 :             :   {
     242                 :        3500 :     for (auto &field : stct.get_fields ())
     243                 :             :       {
     244                 :        2483 :         field->accept_vis (*this);
     245                 :             :       }
     246                 :             : 
     247                 :        1017 :     stct.get_struct_name ().accept_vis (*this);
     248                 :        1017 :     if (stct.has_struct_base ())
     249                 :             :       {
     250                 :          72 :         stct.get_struct_base ().get_base ().accept_vis (*this);
     251                 :             :       }
     252                 :        1017 :   }
     253                 :             : 
     254                 :        2311 :   virtual void visit (HIR::StructExprFieldIdentifierValue &field) override
     255                 :             :   {
     256                 :        2311 :     field.get_value ().accept_vis (*this);
     257                 :        2311 :   }
     258                 :             : 
     259                 :           0 :   void visit (HIR::StructExprStructBase &stct) override
     260                 :             :   {
     261                 :           0 :     stct.get_struct_base ().get_base ().accept_vis (*this);
     262                 :           0 :   }
     263                 :             : 
     264                 :         535 :   void visit (HIR::Module &module) override
     265                 :             :   {
     266                 :        1746 :     for (auto &item : module.get_items ())
     267                 :        1211 :       item->accept_vis (*this);
     268                 :         535 :   }
     269                 :             : 
     270                 :          60 :   void visit (HIR::ClosureExpr &expr) override
     271                 :             :   {
     272                 :          60 :     expr.get_expr ().accept_vis (*this);
     273                 :          60 :   }
     274                 :             : 
     275                 :             : private:
     276                 :             :   std::vector<HirId> worklist;
     277                 :             :   std::set<HirId> liveSymbols;
     278                 :             :   std::set<HirId> scannedSymbols;
     279                 :             :   Analysis::Mappings &mappings;
     280                 :             :   Resolver::Resolver *resolver;
     281                 :             :   Resolver::TypeCheckContext *tyctx;
     282                 :        4203 :   MarkLive (std::vector<HirId> worklist)
     283                 :        4203 :     : worklist (worklist), mappings (Analysis::Mappings::get ()),
     284                 :        4203 :       resolver (Resolver::Resolver::get ()),
     285                 :        8406 :       tyctx (Resolver::TypeCheckContext::get ()){};
     286                 :             : 
     287                 :             :   void mark_hir_id (HirId);
     288                 :             :   bool visit_path_segment (HIR::PathExprSegment);
     289                 :             :   void find_ref_node_id (NodeId ast_node_id, NodeId &ref_node_id);
     290                 :             : };
     291                 :             : 
     292                 :             : } // namespace Analysis
     293                 :             : } // namespace Rust
     294                 :             : 
     295                 :             : #endif
        

Generated by: LCOV version 2.1-beta

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.