LCOV - code coverage report
Current view: top level - gcc/analyzer - record-layout.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 77.1 % 48 37
Test Date: 2026-11-14 16:39:50 Functions: 60.0 % 5 3
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Implementation of class record_layout.
       2              :    Copyright (C) 2022-2026 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 "analyzer/common.h"
      22              : 
      23              : #include "tree-diagnostic.h"
      24              : 
      25              : #include "analyzer/record-layout.h"
      26              : 
      27              : #if ENABLE_ANALYZER
      28              : 
      29              : namespace ana {
      30              : 
      31              : /* class record_layout.  */
      32              : 
      33         4700 : record_layout::record_layout (const_tree record_type)
      34              : {
      35         4700 :   gcc_assert (TREE_CODE (record_type) == RECORD_TYPE);
      36              : 
      37        52338 :   for (tree iter = TYPE_FIELDS (record_type); iter != NULL_TREE;
      38        47638 :        iter = DECL_CHAIN (iter))
      39              :     {
      40        47638 :       if (TREE_CODE (iter) == FIELD_DECL)
      41              :         {
      42        21795 :           concrete_bit_offset iter_field_offset = get_bit_position (iter);
      43        21795 :           concrete_bit_size size_in_bits;
      44        21795 :           if (!get_type_size (TREE_TYPE (iter), &size_in_bits))
      45           55 :             size_in_bits = 0_bits;
      46              : 
      47        21795 :           maybe_pad_to (iter_field_offset);
      48              : 
      49              :           /* Add field.  */
      50        87180 :           m_items.safe_push (item (concrete_bit_range (iter_field_offset,
      51        65385 :                                                        size_in_bits),
      52        21795 :                                    iter, false));
      53        21795 :         }
      54              :     }
      55              : 
      56              :   /* Add any trailing padding.  */
      57         4700 :   concrete_bit_size size_in_bits;
      58         4700 :   if (get_type_size (record_type, &size_in_bits))
      59         4617 :     maybe_pad_to (size_in_bits);
      60         4700 : }
      61              : 
      62              : void
      63            0 : record_layout::dump_to_pp (pretty_printer *pp) const
      64              : {
      65            0 :   unsigned i;
      66            0 :   item *it;
      67            0 :   FOR_EACH_VEC_ELT (m_items, i, it)
      68              :     {
      69            0 :       it->dump_to_pp (pp);
      70            0 :       pp_newline (pp);
      71              :     }
      72            0 : }
      73              : 
      74              : void
      75            0 : record_layout::dump () const
      76              : {
      77            0 :   tree_dump_pretty_printer pp (stderr);
      78            0 :   dump_to_pp (&pp);
      79            0 : }
      80              : 
      81              : const record_layout::item *
      82         4698 : record_layout::get_item_at (concrete_bit_offset offset) const
      83              : {
      84         4698 :   unsigned i;
      85         4698 :   item *it;
      86        11865 :   FOR_EACH_VEC_ELT (m_items, i, it)
      87        11712 :     if (it->contains_p (offset))
      88              :       return it;
      89              :   return nullptr;
      90              : }
      91              : 
      92              : /* Subroutine of ctor.  Add padding item to NEXT_OFFSET if necessary.  */
      93              : 
      94              : void
      95        26412 : record_layout::maybe_pad_to (concrete_bit_offset next_offset)
      96              : {
      97        26412 :   if (m_items.length () > 0)
      98              :     {
      99        21789 :       const item &last_item = m_items[m_items.length () - 1];
     100        21789 :       concrete_bit_offset offset_after_last_item
     101        21789 :         = last_item.get_next_offset ();
     102        21789 :       if (next_offset > offset_after_last_item)
     103              :         {
     104         2085 :           concrete_bit_size padding_size
     105         2085 :             = next_offset - offset_after_last_item;
     106         6255 :           m_items.safe_push (item (concrete_bit_range (offset_after_last_item,
     107         6255 :                                                        padding_size),
     108         4170 :                                    last_item.m_field, true));
     109         2085 :         }
     110        21789 :     }
     111        26412 : }
     112              : 
     113              : } // namespace ana
     114              : 
     115              : #endif /* #if ENABLE_ANALYZER  */
        

Generated by: LCOV version 2.5.0-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.