LCOV - code coverage report
Current view: top level - gcc - value-range-pretty-print.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 94.8 % 135 128
Test Date: 2026-11-14 16:39:50 Functions: 100.0 % 9 9
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Pretty print support for value ranges.
       2              :    Copyright (C) 2019-2026 Free Software Foundation, Inc.
       3              :    Contributed by Aldy Hernandez <aldyh@redhat.com>.
       4              : 
       5              : This file is part of GCC.
       6              : 
       7              : GCC is free software; you can redistribute it and/or modify
       8              : it 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,
      13              : but WITHOUT ANY WARRANTY; without even the implied warranty of
      14              : MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15              : GNU 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              : #include "system.h"
      23              : #include "coretypes.h"
      24              : #include "backend.h"
      25              : #include "tree.h"
      26              : #include "gimple.h"
      27              : #include "ssa.h"
      28              : #include "tree-pretty-print.h"
      29              : #include "fold-const.h"
      30              : #include "gimple-range.h"
      31              : #include "value-range-pretty-print.h"
      32              : 
      33              : static void
      34        88182 : print_int_bound (pretty_printer *pp, const wide_int &bound, tree type)
      35              : {
      36        88182 :   wide_int type_min = wi::min_value (TYPE_PRECISION (type), TYPE_SIGN (type));
      37        88182 :   wide_int type_max = wi::max_value (TYPE_PRECISION (type), TYPE_SIGN (type));
      38              : 
      39        88182 :   if (INTEGRAL_TYPE_P (type)
      40        84530 :       && !TYPE_UNSIGNED (type)
      41        22822 :       && bound == type_min
      42        88649 :       && TYPE_PRECISION (type) != 1)
      43          467 :     pp_string (pp, "-INF");
      44        87715 :   else if (bound == type_max && TYPE_PRECISION (type) != 1)
      45        13728 :     pp_string (pp, "+INF");
      46              :   else
      47        73987 :     pp_wide_int (pp, bound, TYPE_SIGN (type));
      48        88182 : }
      49              : 
      50              : static void
      51        40730 : print_irange_bitmasks (pretty_printer *pp, const irange_bitmask &bm)
      52              : {
      53        40730 :   if (bm.unknown_p ())
      54        32527 :     return;
      55              : 
      56         8203 :   pp_string (pp, " MASK ");
      57         8203 :   char buf[WIDE_INT_PRINT_BUFFER_SIZE], *p;
      58         8203 :   unsigned len_mask, len_val;
      59        16406 :   if (print_hex_buf_size (bm.mask (), &len_mask)
      60         8203 :       | print_hex_buf_size (bm.value (), &len_val))
      61            0 :     p = XALLOCAVEC (char, MAX (len_mask, len_val));
      62              :   else
      63              :     p = buf;
      64         8203 :   print_hex (bm.mask (), p);
      65         8203 :   pp_string (pp, p);
      66         8203 :   pp_string (pp, " VALUE ");
      67         8203 :   print_hex (bm.value (), p);
      68         8203 :   pp_string (pp, p);
      69              : }
      70              : 
      71              : void
      72          603 : vrange_printer::visit (const unsupported_range &r) const
      73              : {
      74          603 :   pp_string (pp, "[unsupported_range] ");
      75          603 :   if (r.undefined_p ())
      76              :     {
      77            0 :       pp_string (pp, "UNDEFINED");
      78            0 :       return;
      79              :     }
      80          603 :   if (r.varying_p ())
      81              :     {
      82          603 :       pp_string (pp, "VARYING");
      83          603 :       return;
      84              :     }
      85            0 :   gcc_unreachable ();
      86              : }
      87              : 
      88              : void
      89        41041 : vrange_printer::visit (const irange &r) const
      90              : {
      91        41041 :   pp_string (pp, "[irange] ");
      92        41041 :   if (r.undefined_p ())
      93              :     {
      94           16 :       pp_string (pp, "UNDEFINED");
      95           16 :       return;
      96              :     }
      97        41025 :   dump_generic_node (pp, r.type (), 0, TDF_NONE | TDF_NOUID, false);
      98        41025 :   pp_character (pp, ' ');
      99        41025 :   if (r.varying_p ())
     100              :     {
     101         2121 :       pp_string (pp, "VARYING");
     102         2121 :       return;
     103              :     }
     104        81169 :   for (unsigned i = 0; i < r.num_pairs (); ++i)
     105              :     {
     106        42265 :       pp_character (pp, '[');
     107        42265 :       print_int_bound (pp, r.lower_bound (i), r.type ());
     108        42265 :       pp_string (pp, ", ");
     109        42265 :       print_int_bound (pp, r.upper_bound (i), r.type ());
     110        42265 :       pp_character (pp, ']');
     111              :     }
     112        38904 :   print_irange_bitmasks (pp, r.m_bitmask);
     113              : }
     114              : 
     115              : void
     116         1826 : vrange_printer::print_addr (const prange &r) const
     117              : {
     118         1826 :   bool known_p = false;
     119         1826 :   tree addr = r.addr_known ();
     120              :   if (addr)
     121              :     known_p = true;
     122              :   else
     123         1568 :     addr = r.addr_excluded ();
     124              : 
     125              :   if (addr)
     126              :     {
     127          260 :       if (known_p)
     128          258 :         pp_string (pp, " -> ");
     129              :       else
     130            2 :         pp_string (pp, " ! -> ");
     131          260 :       dump_generic_node (pp, addr, 0, TDF_NONE | TDF_NOUID, false);
     132          260 :       if (known_p)
     133              :         {
     134          258 :           int_range_max sz;
     135          258 :           int_range_max off;
     136          258 :           tree b;
     137          258 :           b = r.addr_base ();
     138          258 :           r.addr_offset(off);
     139          258 :           r.addr_size (sz);
     140          258 :           pp_string (pp, " { Base: ");
     141          258 :           dump_generic_node (pp, b, 0, TDF_NONE | TDF_NOUID, false);
     142          258 :           if (!off.varying_p () && !off.undefined_p () && !off.zero_p ())
     143              :             {
     144            0 :               pp_string (pp, " ; Off: ");
     145            0 :               visit (off);
     146              :             }
     147          258 :           if (!sz.varying_p () && !sz.undefined_p ())
     148              :               {
     149          258 :                 pp_string (pp, " ; Size: ");
     150          258 :                 visit (sz);
     151              :               }
     152          258 :           pp_string (pp, " }");
     153          258 :         }
     154              : 
     155              :     }
     156         1826 : }
     157              : 
     158              : void
     159         1935 : vrange_printer::visit (const prange &r) const
     160              : {
     161         1935 :   pp_string (pp, "[prange] ");
     162         1935 :   if (r.undefined_p ())
     163              :     {
     164            6 :       pp_string (pp, "UNDEFINED");
     165            6 :       return;
     166              :     }
     167         1929 :   dump_generic_node (pp, r.type (), 0, TDF_NONE | TDF_NOUID, false);
     168         1929 :   pp_character (pp, ' ');
     169         1929 :   if (r.varying_p ())
     170              :     {
     171          103 :       pp_string (pp, "VARYING");
     172          103 :       return;
     173              :     }
     174              : 
     175         1826 :   pp_character (pp, '[');
     176         1826 :   print_int_bound (pp, r.lower_bound (), r.type ());
     177         1826 :   pp_string (pp, ", ");
     178         1826 :   print_int_bound (pp, r.upper_bound (), r.type ());
     179         1826 :   pp_character (pp, ']');
     180         1826 :   print_irange_bitmasks (pp, r.m_bitmask);
     181              :   // Dump the address field if there is one.
     182         1826 :   print_addr (r);
     183              : }
     184              : 
     185              : void
     186          390 : vrange_printer::print_real_value (tree type, const REAL_VALUE_TYPE &r) const
     187              : {
     188          390 :   char s[100];
     189          390 :   real_to_decimal_for_mode (s, &r, sizeof (s), 0, 1, TYPE_MODE (type));
     190          390 :   pp_string (pp, s);
     191          390 :   if (!DECIMAL_FLOAT_TYPE_P (type)
     192              :       // real_to_hexadecimal prints infinities and NAN as text.  No
     193              :       // need to print them twice.
     194          390 :       && !real_isinf (&r)
     195          691 :       && !real_isnan (&r))
     196              :     {
     197          301 :       real_to_hexadecimal (s, &r, sizeof (s), 0, 1);
     198          301 :       pp_printf (pp, " (%s)", s);
     199              :     }
     200          390 : }
     201              : 
     202              : // Print an frange.
     203              : 
     204              : void
     205          259 : vrange_printer::visit (const frange &r) const
     206              : {
     207          259 :   pp_string (pp, "[frange] ");
     208          259 :   if (r.undefined_p ())
     209              :     {
     210            5 :       pp_string (pp, "UNDEFINED");
     211            5 :       return;
     212              :     }
     213          254 :   tree type = r.type ();
     214          254 :   dump_generic_node (pp, type, 0, TDF_NONE, false);
     215          254 :   pp_string (pp, " ");
     216          254 :   if (r.varying_p ())
     217              :     {
     218           69 :       pp_string (pp, "VARYING");
     219           69 :       print_frange_nan (r);
     220           69 :       return;
     221              :     }
     222          185 :   if (r.known_isnan ())
     223            3 :     pp_string (pp, "[]");
     224              :   else
     225          377 :     for (unsigned i = 0; i < r.num_pairs (); ++i)
     226              :       {
     227          195 :         pp_character (pp, '[');
     228          195 :         print_real_value (type, r.lower_bound (i));
     229          195 :         pp_string (pp, ", ");
     230          195 :         print_real_value (type, r.upper_bound (i));
     231          195 :         pp_character (pp, ']');
     232              :       }
     233          185 :   print_frange_nan (r);
     234              : }
     235              : 
     236              : // Print the NAN info for an frange.
     237              : 
     238              : void
     239          254 : vrange_printer::print_frange_nan (const frange &r) const
     240              : {
     241          425 :   if (r.maybe_isnan ())
     242              :     {
     243           83 :       if (r.m_pos_nan && r.m_neg_nan)
     244              :         {
     245           70 :           pp_string (pp, " +-NAN");
     246           70 :           return;
     247              :         }
     248           13 :       bool nan_sign = r.m_neg_nan;
     249           13 :       if (nan_sign)
     250            0 :         pp_string (pp, " -NAN");
     251              :       else
     252           13 :         pp_string (pp, " +NAN");
     253              :     }
     254              : }
        

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.