LCOV - code coverage report
Current view: top level - gcc/analyzer - inlining-iterator.h (source / functions) Coverage Total Hit
Test: gcc.info Lines: 100.0 % 49 49
Test Date: 2024-03-23 14:05:01 Functions: 100.0 % 3 3
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* Iterator for walking a chain of inlining locations.
       2                 :             :    Copyright (C) 2022-2024 Free Software Foundation, Inc.
       3                 :             :    Contributed by David Malcolm <dmalcolm@redhat.com>.
       4                 :             : 
       5                 :             : This file is part of GCC.
       6                 :             : 
       7                 :             : GCC is free software; you can redistribute it and/or modify it
       8                 :             : under the terms of the GNU General Public License as published by
       9                 :             : the Free Software Foundation; either version 3, or (at your option)
      10                 :             : any later version.
      11                 :             : 
      12                 :             : GCC is distributed in the hope that it will be useful, but
      13                 :             : WITHOUT ANY WARRANTY; without even the implied warranty of
      14                 :             : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      15                 :             : General Public License for more details.
      16                 :             : 
      17                 :             : You should have received a copy of the GNU General Public License
      18                 :             : along with GCC; see the file COPYING3.  If not see
      19                 :             : <http://www.gnu.org/licenses/>.  */
      20                 :             : 
      21                 :             : #ifndef GCC_ANALYZER_INLINING_ITERATOR_H
      22                 :             : #define GCC_ANALYZER_INLINING_ITERATOR_H
      23                 :             : 
      24                 :             : /* Iterator for walking a chain of inlining locations.
      25                 :             : 
      26                 :             :    The fndecls and locations will be traversed from innermost to outermost.
      27                 :             :    For example, given:
      28                 :             : 
      29                 :             :     inline void inner (void)
      30                 :             :     {
      31                 :             :        ...LOCATION HERE...
      32                 :             :     }
      33                 :             :     void outer (void)
      34                 :             :     {
      35                 :             :        inner (); <-- CALLSITE
      36                 :             :     }
      37                 :             : 
      38                 :             :    then the fndecl will be "inner" on the initial iteration, and "outer" on
      39                 :             :    the second (final) iteration.
      40                 :             : 
      41                 :             :    Compare with lhd_print_error_function, cp_print_error_function,
      42                 :             :    and optrecord_json_writer::inlining_chain_to_json.  */
      43                 :             : 
      44                 :             : class inlining_iterator
      45                 :             : {
      46                 :             : public:
      47                 :       85363 :   inlining_iterator (location_t loc)
      48                 :       85363 :   : m_abstract_origin (LOCATION_BLOCK (loc)),
      49                 :       85363 :     m_callsite (UNKNOWN_LOCATION), m_fndecl (NULL),
      50                 :       85363 :     m_next_abstract_origin (NULL)
      51                 :             :   {
      52                 :       85363 :     prepare_iteration ();
      53                 :       85363 :   }
      54                 :             : 
      55                 :      151634 :   bool done_p () const { return m_abstract_origin == NULL; }
      56                 :             : 
      57                 :       66517 :   void next ()
      58                 :             :   {
      59                 :       66517 :     m_abstract_origin = m_next_abstract_origin;
      60                 :       66404 :     prepare_iteration ();
      61                 :       66404 :   }
      62                 :             : 
      63                 :      132559 :   tree get_fndecl () const { return m_fndecl; }
      64                 :         131 :   location_t get_callsite () const { return m_callsite; }
      65                 :             :   tree get_block () const { return m_abstract_origin; }
      66                 :             : 
      67                 :             : private:
      68                 :      151880 :   void prepare_iteration ()
      69                 :             :   {
      70                 :      151880 :     if (done_p ())
      71                 :             :       return;
      72                 :       66557 :     tree block = m_abstract_origin;
      73                 :       66557 :     m_callsite = BLOCK_SOURCE_LOCATION (block);
      74                 :       66557 :     m_fndecl = NULL;
      75                 :       66557 :     block = BLOCK_SUPERCONTEXT (block);
      76                 :      133355 :     while (block && TREE_CODE (block) == BLOCK
      77                 :       74666 :            && BLOCK_ABSTRACT_ORIGIN (block))
      78                 :             :       {
      79                 :        1370 :         tree ao = BLOCK_ABSTRACT_ORIGIN (block);
      80                 :        1370 :         if (TREE_CODE (ao) == FUNCTION_DECL)
      81                 :             :           {
      82                 :        1129 :             m_fndecl = ao;
      83                 :        1129 :             break;
      84                 :             :           }
      85                 :         241 :         else if (TREE_CODE (ao) != BLOCK)
      86                 :             :           break;
      87                 :             : 
      88                 :         241 :         block = BLOCK_SUPERCONTEXT (block);
      89                 :             :       }
      90                 :       66557 :     if (m_fndecl)
      91                 :        1129 :       m_next_abstract_origin = block;
      92                 :             :     else
      93                 :             :       {
      94                 :       75689 :         while (block && TREE_CODE (block) == BLOCK)
      95                 :       10261 :           block = BLOCK_SUPERCONTEXT (block);
      96                 :             : 
      97                 :       65428 :         if (block && TREE_CODE (block) == FUNCTION_DECL)
      98                 :       65428 :           m_fndecl = block;
      99                 :       65428 :         m_next_abstract_origin = NULL;
     100                 :             :       }
     101                 :             :   }
     102                 :             : 
     103                 :             :   tree m_abstract_origin;
     104                 :             :   location_t m_callsite;
     105                 :             :   tree m_fndecl;
     106                 :             :   tree m_next_abstract_origin;
     107                 :             : };
     108                 :             : 
     109                 :             : /* A class for fixing up fndecls and stack depths in checker_event, based
     110                 :             :    on inlining records.
     111                 :             : 
     112                 :             :    The early inliner runs before the analyzer, which can lead to confusing
     113                 :             :    output.
     114                 :             : 
     115                 :             :    Tne base fndecl and depth within a checker_event are from call strings
     116                 :             :    in program_points, which reflect the call strings after inlining.
     117                 :             :    This class lets us offset the depth and fix up the reported fndecl and
     118                 :             :    stack depth to better reflect the user's original code.  */
     119                 :             : 
     120                 :             : class inlining_info
     121                 :             : {
     122                 :             : public:
     123                 :       66135 :   inlining_info (location_t loc)
     124                 :       66135 :   {
     125                 :       66135 :     inlining_iterator iter (loc);
     126                 :       66135 :     m_inner_fndecl = iter.get_fndecl ();
     127                 :       66135 :     int num_frames = 0;
     128                 :      116833 :     while (!iter.done_p ())
     129                 :             :       {
     130                 :       50698 :         m_outer_fndecl = iter.get_fndecl ();
     131                 :       50698 :         num_frames++;
     132                 :       50698 :         iter.next ();
     133                 :             :       }
     134                 :       66135 :     if (num_frames > 1)
     135                 :         466 :       m_extra_frames = num_frames - 1;
     136                 :             :     else
     137                 :       65669 :       m_extra_frames = 0;
     138                 :       66135 :   }
     139                 :             : 
     140                 :       65933 :   tree get_inner_fndecl () const { return m_inner_fndecl; }
     141                 :       49892 :   int get_extra_frames () const { return m_extra_frames; }
     142                 :             : 
     143                 :             : private:
     144                 :             :   tree m_outer_fndecl;
     145                 :             :   tree m_inner_fndecl;
     146                 :             :   int m_extra_frames;
     147                 :             : };
     148                 :             : 
     149                 :             : #endif /* GCC_ANALYZER_INLINING_ITERATOR_H */
        

Generated by: LCOV version 2.0-1

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.