LCOV - code coverage report
Current view: top level - gcc/analyzer - record-layout.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 67.4 % 46 31
Test Date: 2024-04-27 14:03:13 Functions: 60.0 % 5 3
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* Implementation of class record_layout.
       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                 :             : #include "config.h"
      22                 :             : #define INCLUDE_MEMORY
      23                 :             : #include "system.h"
      24                 :             : #include "coretypes.h"
      25                 :             : #include "tree.h"
      26                 :             : #include "function.h"
      27                 :             : #include "basic-block.h"
      28                 :             : #include "gimple.h"
      29                 :             : #include "diagnostic-core.h"
      30                 :             : #include "diagnostic.h"
      31                 :             : #include "tree-diagnostic.h"
      32                 :             : #include "analyzer/analyzer.h"
      33                 :             : #include "analyzer/record-layout.h"
      34                 :             : 
      35                 :             : #if ENABLE_ANALYZER
      36                 :             : 
      37                 :             : namespace ana {
      38                 :             : 
      39                 :             : /* class record_layout.  */
      40                 :             : 
      41                 :          17 : record_layout::record_layout (tree record_type)
      42                 :             : {
      43                 :          17 :   gcc_assert (TREE_CODE (record_type) == RECORD_TYPE);
      44                 :             : 
      45                 :          94 :   for (tree iter = TYPE_FIELDS (record_type); iter != NULL_TREE;
      46                 :          77 :        iter = DECL_CHAIN (iter))
      47                 :             :     {
      48                 :          77 :       if (TREE_CODE (iter) == FIELD_DECL)
      49                 :             :         {
      50                 :          77 :           int iter_field_offset = int_bit_position (iter);
      51                 :          77 :           bit_size_t size_in_bits;
      52                 :          77 :           if (!int_size_in_bits (TREE_TYPE (iter), &size_in_bits))
      53                 :           0 :             size_in_bits = 0;
      54                 :             : 
      55                 :          77 :           maybe_pad_to (iter_field_offset);
      56                 :             : 
      57                 :             :           /* Add field.  */
      58                 :          77 :           m_items.safe_push (item (bit_range (iter_field_offset,
      59                 :             :                                               size_in_bits),
      60                 :             :                                    iter, false));
      61                 :             :         }
      62                 :             :     }
      63                 :             : 
      64                 :             :   /* Add any trailing padding.  */
      65                 :          17 :   bit_size_t size_in_bits;
      66                 :          17 :   if (int_size_in_bits (record_type, &size_in_bits))
      67                 :          17 :     maybe_pad_to (size_in_bits);
      68                 :          17 : }
      69                 :             : 
      70                 :             : void
      71                 :           0 : record_layout::dump_to_pp (pretty_printer *pp) const
      72                 :             : {
      73                 :           0 :   unsigned i;
      74                 :           0 :   item *it;
      75                 :           0 :   FOR_EACH_VEC_ELT (m_items, i, it)
      76                 :             :     {
      77                 :           0 :       it->dump_to_pp (pp);
      78                 :           0 :       pp_newline (pp);
      79                 :             :     }
      80                 :           0 : }
      81                 :             : 
      82                 :             : void
      83                 :           0 : record_layout::dump () const
      84                 :             : {
      85                 :           0 :   pretty_printer pp;
      86                 :           0 :   pp_format_decoder (&pp) = default_tree_printer;
      87                 :           0 :   pp.buffer->stream = stderr;
      88                 :           0 :   dump_to_pp (&pp);
      89                 :           0 :   pp_flush (&pp);
      90                 :           0 : }
      91                 :             : 
      92                 :             : const record_layout::item *
      93                 :          55 : record_layout::get_item_at (bit_offset_t offset) const
      94                 :             : {
      95                 :          55 :   unsigned i;
      96                 :          55 :   item *it;
      97                 :         841 :   FOR_EACH_VEC_ELT (m_items, i, it)
      98                 :         841 :     if (it->contains_p (offset))
      99                 :          55 :       return it;
     100                 :             :   return NULL;
     101                 :             : }
     102                 :             : 
     103                 :             : /* Subroutine of ctor.  Add padding item to NEXT_OFFSET if necessary.  */
     104                 :             : 
     105                 :             : void
     106                 :          94 : record_layout::maybe_pad_to (bit_offset_t next_offset)
     107                 :             : {
     108                 :          94 :   if (m_items.length () > 0)
     109                 :             :     {
     110                 :          77 :       const item &last_item = m_items[m_items.length () - 1];
     111                 :          77 :       bit_offset_t offset_after_last_item
     112                 :          77 :         = last_item.get_next_bit_offset ();
     113                 :          77 :       if (next_offset > offset_after_last_item)
     114                 :             :         {
     115                 :          11 :           bit_size_t padding_size
     116                 :          11 :             = next_offset - offset_after_last_item;
     117                 :          11 :           m_items.safe_push (item (bit_range (offset_after_last_item,
     118                 :             :                                               padding_size),
     119                 :          11 :                                    last_item.m_field, true));
     120                 :             :         }
     121                 :             :     }
     122                 :          94 : }
     123                 :             : 
     124                 :             : } // namespace ana
     125                 :             : 
     126                 :             : #endif /* #if ENABLE_ANALYZER  */
        

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.