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: 2026-11-14 16:39:50 Functions: 100.0 % 6 6
Legend: Lines:     hit not hit

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

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.