LCOV - code coverage report
Current view: top level - gcc/custom-sarif-properties - state-graphs.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 100.0 % 18 18
Test Date: 2025-10-18 14:39:06 Functions: 100.0 % 6 6
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: - 0 0

             Branch data     Line data    Source code
       1                 :             : /* Properties for capturing state graphs in SARIF property bags.
       2                 :             :    Copyright (C) 2025 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 under
       8                 :             : the terms of the GNU General Public License as published by the Free
       9                 :             : Software Foundation; either version 3, or (at your option) any later
      10                 :             : version.
      11                 :             : 
      12                 :             : GCC is distributed in the hope that it will be useful, but WITHOUT ANY
      13                 :             : WARRANTY; without even the implied warranty of MERCHANTABILITY or
      14                 :             : FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
      15                 :             : 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                 :             : #include "system.h"
      23                 :             : #include "coretypes.h"
      24                 :             : #include "json.h"
      25                 :             : #include "custom-sarif-properties/state-graphs.h"
      26                 :             : 
      27                 :             : /* graph.  */
      28                 :             : namespace graph = custom_sarif_properties::state_graphs::graph;
      29                 :             : #define STATE_GRAPH_PREFIX "gcc/diagnostic_state_graph/"
      30                 :             : const char *const graph::prefix = STATE_GRAPH_PREFIX;
      31                 :             : #undef STATE_GRAPH_PREFIX
      32                 :             : 
      33                 :             : /* node.  */
      34                 :             : namespace node = custom_sarif_properties::state_graphs::node;
      35                 :             : #define STATE_NODE_PREFIX "gcc/diagnostic_state_node/"
      36                 :             : 
      37                 :             : const json::enum_property<enum node::kind_t>
      38                 :             :   node::kind_prop (STATE_NODE_PREFIX "kind");
      39                 :             : 
      40                 :             : const json::string_property node::function (STATE_NODE_PREFIX "function");
      41                 :             : 
      42                 :             : const json::string_property node::dynamic_extents
      43                 :             :   (STATE_NODE_PREFIX "dynamic-extents");
      44                 :             : 
      45                 :             : const json::string_property node::name (STATE_NODE_PREFIX "name");
      46                 :             : const json::string_property node::type (STATE_NODE_PREFIX "type");
      47                 :             : const json::json_property node::value (STATE_NODE_PREFIX "value");
      48                 :             : const json::string_property node::value_str (STATE_NODE_PREFIX "value_str");
      49                 :             : 
      50                 :             : const json::string_property node::index (STATE_NODE_PREFIX "index");
      51                 :             : 
      52                 :             : const json::string_property node::bits (STATE_NODE_PREFIX "bits");
      53                 :             : 
      54                 :             : const json::string_property node::num_bits (STATE_NODE_PREFIX "num_bits");
      55                 :             : 
      56                 :             : const json::string_property node::deallocator (STATE_NODE_PREFIX "deallocator");
      57                 :             : 
      58                 :             : const json::string_property node::expected_deallocators
      59                 :             :   (STATE_NODE_PREFIX "expected-deallocators");
      60                 :             : 
      61                 :             : const json::enum_property<enum node::dynalloc_state_t>
      62                 :             :   node::dynalloc_state_prop (STATE_NODE_PREFIX "dynalloc-state");
      63                 :             : 
      64                 :             : #undef STATE_NODE_PREFIX
      65                 :             : 
      66                 :             : 
      67                 :             : /* edge.  */
      68                 :             : namespace edge_props = custom_sarif_properties::state_graphs::edge;
      69                 :             : #define STATE_EDGE_PREFIX "gcc/diagnostic_state_edge/"
      70                 :             : extern const char *const edge_props::prefix = STATE_EDGE_PREFIX;
      71                 :             : #undef STATE_EDGE_PREFIX
      72                 :             : 
      73                 :             : // Traits for enum node:kind_t
      74                 :             : 
      75                 :             : namespace json {
      76                 :             : 
      77                 :             : template<>
      78                 :             : enum node::kind_t
      79                 :           4 : json::enum_traits<enum node::kind_t>::get_unknown_value ()
      80                 :             : {
      81                 :           4 :   return node::kind_t::other;
      82                 :             : }
      83                 :             : 
      84                 :             : static const char * const node_kind_strs[] = {
      85                 :             :   "globals",
      86                 :             :   "code",
      87                 :             :   "function",
      88                 :             :   "stack",
      89                 :             :   "stack-frame",
      90                 :             :   "heap",
      91                 :             :   "thread-local",
      92                 :             :   "dynalloc-buffer",
      93                 :             :   "variable",
      94                 :             :   "field",
      95                 :             :   "padding",
      96                 :             :   "element",
      97                 :             :   "other",
      98                 :             : };
      99                 :             : 
     100                 :             : template<>
     101                 :             : bool
     102                 :          16 : json::enum_traits<enum node::kind_t>::
     103                 :             : maybe_get_value_from_string (const char *str,
     104                 :             :                              enum_t &out)
     105                 :             : {
     106                 :         129 :   for (size_t i = 0; i < ARRAY_SIZE (node_kind_strs); ++i)
     107                 :         129 :     if (!strcmp (node_kind_strs[i], str))
     108                 :             :       {
     109                 :          16 :         out = static_cast<enum_t> (i);
     110                 :          16 :         return true;
     111                 :             :       }
     112                 :             :   return false;
     113                 :             : }
     114                 :             : 
     115                 :             : template<>
     116                 :             : const char *
     117                 :         546 : json::enum_traits<enum node::kind_t>::get_string_for_value (enum_t value)
     118                 :             : {
     119                 :         546 :   return node_kind_strs[static_cast<int> (value)];
     120                 :             : }
     121                 :             : 
     122                 :             : // Traits for enum node:dynalloc_state_t
     123                 :             : 
     124                 :             : template<>
     125                 :             : enum node::dynalloc_state_t
     126                 :           4 : json::enum_traits<enum node::dynalloc_state_t>::get_unknown_value ()
     127                 :             : {
     128                 :           4 :   return node::dynalloc_state_t::unknown;
     129                 :             : }
     130                 :             : 
     131                 :             : static const char * const dynalloc_state_strs[] = {
     132                 :             :   "unknown",
     133                 :             :   "nonnull",
     134                 :             :   "unchecked",
     135                 :             :   "freed"
     136                 :             : };
     137                 :             : 
     138                 :             : template<>
     139                 :             : bool
     140                 :           4 : json::enum_traits<enum node::dynalloc_state_t>::
     141                 :             : maybe_get_value_from_string (const char *str,
     142                 :             :                              enum_t &out)
     143                 :             : {
     144                 :          16 :   for (size_t i = 0; i < ARRAY_SIZE (dynalloc_state_strs); ++i)
     145                 :          16 :     if (!strcmp (dynalloc_state_strs[i], str))
     146                 :             :       {
     147                 :           4 :         out = static_cast<enum_t> (i);
     148                 :           4 :         return true;
     149                 :             :       }
     150                 :             :   return false;
     151                 :             : }
     152                 :             : 
     153                 :             : template<>
     154                 :             : const char *
     155                 :          48 : json::enum_traits<enum node::dynalloc_state_t>::
     156                 :             : get_string_for_value (enum_t value)
     157                 :             : {
     158                 :          48 :   return dynalloc_state_strs[static_cast <size_t> (value)];
     159                 :             : }
     160                 :             : 
     161                 :             : } // namespace json
        

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.