LCOV - code coverage report
Current view: top level - gcc/analyzer - svalue.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 71.3 % 1051 749
Test Date: 2026-12-05 16:10:02 Functions: 76.2 % 151 115
Legend: Lines:     hit not hit

            Line data    Source code
       1              : /* Symbolic values.
       2              :    Copyright (C) 2019-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-pretty-print.h"
      24              : #include "gimple-pretty-print.h"
      25              : #include "fold-const.h"
      26              : #include "diagnostic.h"
      27              : #include "tree-diagnostic.h"
      28              : #include "value-relation.h"
      29              : #include "range-op.h"
      30              : 
      31              : #include "text-art/dump.h"
      32              : 
      33              : #include "diagnostics/markup.h"
      34              : 
      35              : #include "analyzer/analyzer-logging.h"
      36              : #include "analyzer/call-string.h"
      37              : #include "analyzer/program-point.h"
      38              : #include "analyzer/store.h"
      39              : #include "analyzer/svalue.h"
      40              : #include "analyzer/region-model.h"
      41              : #include "analyzer/liveness-context.h"
      42              : 
      43              : #if ENABLE_ANALYZER
      44              : 
      45              : namespace ana {
      46              : 
      47              : /* class svalue and its various subclasses.  */
      48              : 
      49              : /* class svalue.  */
      50              : 
      51              : DEBUG_FUNCTION void
      52            0 : svalue::dump () const
      53              : {
      54            0 :   symbolic::dump_node_tree_to_stderr<svalue> (*this);
      55            0 : }
      56              : 
      57              : void
      58         8426 : svalue::print_dump_widget_label (pretty_printer *pp) const
      59              : {
      60         8426 :   if (get_type ())
      61         8426 :     pp_printf (pp, "%qT: ", get_type ());
      62              : 
      63         8426 :   start_any_dump_color (pp);
      64         8426 :   print_svalue_for_dump_widget_label (pp);
      65         8426 :   end_any_dump_color (pp);
      66         8426 : }
      67              : 
      68              : void
      69         7161 : svalue::add_dump_widget_children (text_art::tree_widget &w,
      70              :                                   symbolic::node_dump_state &nds) const
      71              : {
      72              :   /* It's overkill to print the value_range for constants.  */
      73         7161 :   if (get_kind () == SK_CONSTANT)
      74         2210 :     return;
      75              : 
      76         4951 :   value_range out;
      77         4951 :   if (maybe_get_value_range (out))
      78              :     {
      79         2324 :       pretty_printer pp;
      80         2324 :       pp_printf (&pp, "value_range: {");
      81         2324 :       out.print (&pp);
      82         2324 :       pp_string (&pp, "}");
      83         4648 :       w.add_child (text_art::tree_widget::make (nds, &pp));
      84         2324 :     }
      85         4951 : }
      86              : 
      87              : /* Generate a textual representation of this svalue for debugging purposes.  */
      88              : 
      89              : label_text
      90          477 : svalue::get_desc (bool simple) const
      91              : {
      92          477 :   pretty_printer pp;
      93          477 :   pp_format_decoder (&pp) = default_tree_printer;
      94          477 :   dump_to_pp (&pp, simple);
      95          477 :   return label_text::take (xstrdup (pp_formatted_text (&pp)));
      96          477 : }
      97              : 
      98              : std::unique_ptr<json::object>
      99          376 : svalue::make_json_obj (const char *type_name) const
     100              : {
     101          376 :   auto obj = value_node::make_json_obj (type_name);
     102          376 :   if (m_type)
     103          368 :     obj->set ("type", tree_to_json (m_type));
     104          376 :   return obj;
     105              : }
     106              : 
     107              : /* Class for optionally adding open/close paren pairs within
     108              :    svalue::maybe_print_for_user.  */
     109              : 
     110              : class auto_add_parens
     111              : {
     112              : public:
     113            0 :   auto_add_parens (pretty_printer *pp,
     114              :                    const svalue *outer_sval,
     115              :                    const svalue &inner_sval)
     116            0 :   : m_pp (pp),
     117            0 :     m_needs_parens (needs_parens_p (outer_sval, inner_sval))
     118              :   {
     119            0 :     if (m_needs_parens)
     120            0 :       pp_string (m_pp, "(");
     121            0 :   }
     122            0 :   ~auto_add_parens ()
     123              :   {
     124            0 :     if (m_needs_parens)
     125            0 :       pp_string (m_pp, ")");
     126            0 :   }
     127              : 
     128              : private:
     129            0 :   static bool needs_parens_p (const svalue *outer_sval,
     130              :                               const svalue &inner_sval)
     131              :   {
     132            0 :     if (!outer_sval)
     133              :       return false;
     134            0 :     if (inner_sval.get_kind () == SK_BINOP)
     135            0 :       return true;
     136              :     return false;
     137              :   }
     138              : 
     139              :   pretty_printer *m_pp;
     140              :   bool m_needs_parens;
     141              : };
     142              : 
     143              : /* Attempt to print a user-facing description of this svalue to PP,
     144              :    using MODEL for extracting representative tree values if necessary.
     145              :    Use OUTER_SVAL (which can be null) to determine if we need to wrap
     146              :    this value in parentheses.  */
     147              : 
     148              : bool
     149            0 : svalue::maybe_print_for_user (pretty_printer *pp,
     150              :                               const region_model &model,
     151              :                               const svalue *outer_sval) const
     152              : {
     153            0 :   auto_add_parens p (pp, outer_sval, *this);
     154              : 
     155            0 :   switch (get_kind ())
     156              :     {
     157              :     default:
     158              :       break;
     159            0 :     case SK_CONSTANT:
     160            0 :       {
     161            0 :         const constant_svalue *sval = (const constant_svalue *)this;
     162            0 :         pp_printf (pp, "%E", sval->get_constant ());
     163            0 :         return true;
     164              :       }
     165            0 :     case SK_INITIAL:
     166            0 :       {
     167            0 :         const initial_svalue *sval = (const initial_svalue *)this;
     168            0 :         return sval->get_region ()->maybe_print_for_user (pp, model);
     169              :       }
     170            0 :     case SK_UNARYOP:
     171            0 :       {
     172            0 :         const unaryop_svalue *sval = (const unaryop_svalue *)this;
     173            0 :         if (sval->get_op () == NOP_EXPR)
     174              :           {
     175            0 :             if (!sval->get_arg ()->maybe_print_for_user (pp, model, outer_sval))
     176              :               return false;
     177              :             return true;
     178              :           }
     179              :       }
     180              :       break;
     181            0 :     case SK_BINOP:
     182            0 :       {
     183            0 :         const binop_svalue *sval = (const binop_svalue *)this;
     184            0 :         switch (sval->get_op ())
     185              :           {
     186              :           default:
     187              :             break;
     188              : 
     189            0 :           case PLUS_EXPR:
     190            0 :           case MINUS_EXPR:
     191            0 :           case MULT_EXPR:
     192            0 :             {
     193            0 :               if (!sval->get_arg0 ()->maybe_print_for_user (pp, model, this))
     194              :                 return false;
     195            0 :               pp_printf (pp, " %s ", op_symbol_code (sval->get_op ()));
     196            0 :               if (!sval->get_arg1 ()->maybe_print_for_user (pp, model, this))
     197              :                 return false;
     198              :               return true;
     199              :             }
     200              :           }
     201              :       }
     202              :       break;
     203            0 :     case SK_BIT_VECTOR:
     204            0 :       {
     205            0 :         const auto *sval = (const svalue_from_bit_vector *)this;
     206            0 :         auto &bv = sval->get_bit_vector ();
     207            0 :         return bv.maybe_print_for_user (pp, model, outer_sval);
     208              :       }
     209            0 :       break;
     210              :     }
     211              : 
     212            0 :   if (tree expr = model.get_representative_tree (this))
     213              :     {
     214            0 :       expr = remove_ssa_names (expr);
     215            0 :       print_expr_for_user (pp, expr);
     216            0 :       return true;
     217              :     }
     218              : 
     219              :   return false;
     220            0 : }
     221              : 
     222              : iter_result
     223        42556 : svalue::for_each_svalue (iter_result (*cb) (const svalue &sval,
     224              :                                       void *user_data),
     225              :                          void *user_data) const
     226              : {
     227        42556 :   return cb (*this, user_data);
     228              : }
     229              : 
     230              : /* Return true iff this svalue has a concrete size.
     231              :    If OUT is non-null, and returning true, then also write
     232              :    the size to *OUT.  */
     233              : 
     234              : bool
     235      4054491 : svalue::
     236              : has_concrete_size_p (concrete_bit_size *out,
     237              :                      symbolic::scalar_manager<concrete_bit_size> &bit_mgr) const
     238              : {
     239      4054491 :   if (!get_type ())
     240              :     {
     241           82 :       if (tree cst = maybe_get_constant ())
     242           82 :         if (TREE_CODE (cst) == RAW_DATA_CST)
     243              :           {
     244           82 :             concrete_byte_size byte_length (RAW_DATA_LENGTH (cst));
     245           82 :             if (out)
     246           82 :               *out = bits_from_bytes (byte_length);
     247           82 :             return true;
     248           82 :           }
     249            0 :       if (get_kind () == SK_POINTER)
     250              :         {
     251            0 :           if (out)
     252            0 :             *out = concrete_bit_size
     253            0 :                      (convert_from_integer_cst (TYPE_SIZE (ptr_type_node)));
     254              :           return true;
     255              :         }
     256            0 :       if (auto *init_sval = dyn_cast_initial_svalue ())
     257            0 :         if (auto *sym_bit_size
     258            0 :             = init_sval->get_region ()->maybe_get_bit_size (bit_mgr))
     259              :           {
     260            0 :             concrete_bit_size conc_bit_size;
     261            0 :             if (concrete_from_symbolic (*sym_bit_size, &conc_bit_size))
     262              :               {
     263            0 :                 if (out)
     264            0 :                   *out = conc_bit_size;
     265            0 :                 return true;
     266              :               }
     267            0 :           }
     268              :       return false;
     269              :     }
     270              : 
     271      4054409 :   tree type = get_type ();
     272      4054409 :   if (INTEGRAL_TYPE_P (type))
     273              :     {
     274      3858689 :       if (out)
     275      3858689 :         *out = concrete_bit_size (TYPE_PRECISION (type));
     276              :       return true;
     277              :     }
     278              : 
     279       195720 :   tree type_size = TYPE_SIZE (type);
     280       195720 :   if (!type_size)
     281              :     return false;
     282       195720 :   if (TREE_CODE (type_size) != INTEGER_CST)
     283              :     return false;
     284       195720 :   if (out)
     285       195720 :     *out = concrete_bit_size (convert_from_integer_cst (type_size));
     286              :   return true;
     287              : }
     288              : 
     289              : /* If this svalue is a constant_svalue, return the underlying tree constant.
     290              :    Otherwise return NULL_TREE.  */
     291              : 
     292              : tree
     293      8105296 : svalue::maybe_get_constant () const
     294              : {
     295      8105296 :   const svalue *sval = unwrap_any_unmergeable ();
     296      8105296 :   if (const constant_svalue *cst_sval = sval->dyn_cast_constant_svalue ())
     297      2721030 :     return cst_sval->get_constant ();
     298              :   else
     299              :     return NULL_TREE;
     300              : }
     301              : 
     302              : /* If this svalue is a pointer_svalue, return a pointer to its
     303              :    symbolic::pointer.
     304              :    Otherwise return nullptr.  */
     305              : 
     306              : const symbolic::pointer *
     307     26453281 : svalue::maybe_get_symbolic_pointer () const
     308              : {
     309     26453281 :   if (const pointer_svalue *ptr_sval = dyn_cast_pointer_svalue ())
     310      5891229 :     return &ptr_sval->get_symbolic_pointer ();
     311              :   else
     312              :     return nullptr;
     313              : }
     314              : 
     315              : /* If this svalue is a cast (i.e a unaryop NOP_EXPR or VIEW_CONVERT_EXPR),
     316              :    return the underlying svalue.
     317              :    Otherwise return nullptr.  */
     318              : 
     319              : const svalue *
     320     13533939 : svalue::maybe_undo_cast () const
     321              : {
     322     13533939 :   if (const unaryop_svalue *unaryop_sval = dyn_cast_unaryop_svalue ())
     323              :     {
     324      2050767 :       enum tree_code op = unaryop_sval->get_op ();
     325      2050767 :       if (op == NOP_EXPR || op == VIEW_CONVERT_EXPR)
     326      1983501 :         return unaryop_sval->get_arg ();
     327              :     }
     328              :   return nullptr;
     329              : }
     330              : 
     331              : /* If this svalue is an unmergeable decorator around another svalue, return
     332              :    the underlying svalue.
     333              :    Otherwise return this svalue.  */
     334              : 
     335              : const svalue *
     336     10879251 : svalue::unwrap_any_unmergeable () const
     337              : {
     338     10879251 :   if (const unmergeable_svalue *unmergeable = dyn_cast_unmergeable_svalue ())
     339        13589 :     return unmergeable->get_arg ();
     340              :   return this;
     341              : }
     342              : 
     343              : /* Attempt to merge THIS with OTHER, returning the merged svalue.
     344              :    Return nullptr if not mergeable.  */
     345              : 
     346              : const svalue *
     347        63300 : svalue::can_merge_p (const svalue *other,
     348              :                      region_model_manager *mgr,
     349              :                      model_merger *merger) const
     350              : {
     351        63300 :   if (this == other)
     352              :     return this;
     353              : 
     354        63099 :   if (!(get_type () && other->get_type ()))
     355              :     return nullptr;
     356              : 
     357        63099 :   if (!types_compatible_p (get_type (), other->get_type ()))
     358              :     return nullptr;
     359              : 
     360              :   /* Reject attempts to merge unmergeable svalues.  */
     361        63099 :   if ((get_kind () == SK_UNMERGEABLE)
     362        63099 :       || (other->get_kind () == SK_UNMERGEABLE))
     363              :     return nullptr;
     364              : 
     365              :   /* Reject attempts to merge poisoned svalues with other svalues
     366              :      (either non-poisoned, or other kinds of poison), so that e.g.
     367              :      we identify paths in which a variable is conditionally uninitialized.  */
     368        62212 :   if (get_kind () == SK_POISONED
     369        62212 :       || other->get_kind () == SK_POISONED)
     370              :     return nullptr;
     371              : 
     372              :   /* Reject attempts to merge NULL pointers with not-NULL-pointers.  */
     373        62212 :   if (POINTER_TYPE_P (get_type ()))
     374              :     {
     375        26623 :       bool null0 = false;
     376        26623 :       bool null1 = false;
     377        26623 :       if (tree cst0 = maybe_get_constant ())
     378         5682 :         if (zerop (cst0))
     379        26623 :           null0 = true;
     380        26623 :       if (tree cst1 = other->maybe_get_constant ())
     381         6340 :         if (zerop (cst1))
     382        26623 :           null1 = true;
     383        26623 :       if (null0 != null1)
     384              :         return nullptr;
     385              :     }
     386              : 
     387              :   /* Reject merging svalues that have non-purgeable sm-state,
     388              :      to avoid falsely reporting memory leaks by merging them
     389              :      with something else.  */
     390        50204 :   if (!merger->mergeable_svalue_p (this))
     391              :     return nullptr;
     392        50204 :   if (!merger->mergeable_svalue_p (other))
     393              :     return nullptr;
     394              : 
     395              :   /* Handle merger of symbolic pointers.  */
     396        50204 :   if (auto *sym_ptr_this = maybe_get_symbolic_pointer ())
     397         7392 :     if (auto *sym_ptr_other = other->maybe_get_symbolic_pointer ())
     398              :       {
     399         4425 :         auto &this_region = sym_ptr_this->get_base_region ();
     400         4425 :         auto &other_region = sym_ptr_other->get_base_region ();
     401              :         /* Same base region?  Consider merger of offsets.  */
     402         4425 :         if (&this_region == &other_region)
     403              :           {
     404         3422 :             const svalue *this_offset_sval
     405              :               = mgr->get_svalue_from_scalar<concrete_byte_offset>
     406         3422 :                  (ptrdiff_type_node, sym_ptr_this->get_byte_offset ());
     407         3422 :             const svalue *other_offset_sval
     408              :               = mgr->get_svalue_from_scalar<concrete_byte_offset>
     409         3422 :                   (ptrdiff_type_node, sym_ptr_other->get_byte_offset ());
     410         6844 :             if (auto *merged_offset
     411         3422 :                   = this_offset_sval->can_merge_p (other_offset_sval,
     412              :                                                    mgr,
     413              :                                                    merger))
     414              :               {
     415         3422 :                 auto &byte_mgr
     416         3422 :                   = mgr->get_node_manager ().get_scalars ().get_bytes ();
     417         3422 :                 auto &merged_byte_offset
     418         3422 :                   = byte_mgr.get_scalar_from_svalue (*merged_offset);
     419         3422 :                 symbolic::pointer merged_ptr (this_region,
     420         3422 :                                               merged_byte_offset);
     421         3422 :                 return mgr->get_ptr_svalue (get_type (), merged_ptr);
     422              :               }
     423              :             else
     424              :               return nullptr;
     425              :           }
     426              : 
     427              :         /* Reject merger where the base regions are different,
     428              :            except where both are strings.  */
     429         1003 :         if (this_region.get_kind () != RK_STRING
     430         1003 :               || other_region.get_kind () != RK_STRING)
     431              :             return nullptr;
     432              :       }
     433              : 
     434              :   /* Widening.  */
     435              :   /* Merge: (new_cst, existing_cst) -> widen (existing, new).  */
     436        45802 :   if (maybe_get_constant () && other->maybe_get_constant ())
     437         2267 :     return mgr->get_or_create_widening_svalue (other->get_type (),
     438              :                                                merger->get_supernode (),
     439         2267 :                                                other, this);
     440              : 
     441              :   /* Merger of:
     442              :          this: BINOP (X, OP, CST)
     443              :         other: X, where X is non-widening
     444              :            to: WIDENING (other, this).  */
     445        43535 :   if (const binop_svalue *binop_sval = dyn_cast_binop_svalue ())
     446         6494 :     if (binop_sval->get_arg0 () == other
     447         2130 :         && binop_sval->get_arg1 ()->get_kind () == SK_CONSTANT
     448         7940 :         && other->get_kind () != SK_WIDENING)
     449          480 :       return mgr->get_or_create_widening_svalue (other->get_type (),
     450              :                                                  merger->get_supernode (),
     451          480 :                                                  other, this);
     452              : 
     453              :   /* Merge: (Widen(existing_val, V), existing_val) -> Widen (existing_val, V)
     454              :      and thus get a fixed point.  */
     455        43055 :   if (const widening_svalue *widen_sval = dyn_cast_widening_svalue ())
     456              :     {
     457         7214 :       if (other == widen_sval->get_base_svalue ())
     458              :         return this;
     459         1347 :       if (other == widen_sval->get_iter_svalue ())
     460              :         return this;
     461              :     }
     462              : 
     463        36275 :   if (const binop_svalue *binop_sval = dyn_cast_binop_svalue ())
     464         6014 :     if (const widening_svalue *widen_arg0
     465         6014 :         = binop_sval->get_arg0 ()->dyn_cast_widening_svalue ())
     466              :       {
     467         3892 :         if (other == binop_sval->get_arg1 ())
     468              :           {
     469              :             /* Merger of: (Widen(..., OTHER) BINOP X)
     470              :                and      : OTHER
     471              :                to       : (Widen(..., OTHER) BINOP X)
     472              :                e.g. merge of Widen(0, 1) + 1 with 1 to the Widen(0, 1) + 1.  */
     473              :             return this;
     474              :           }
     475              : 
     476              :         /* Merger of : (Widen() BINOP X)
     477              :            and       : Widen()
     478              :            to        : Widen()
     479              :            e.g. merge of Widen(0, 1) + 1 and Widen(0, 1) to Widen(0, 1).
     480              :            However, we want to update constraints for this case, since we're
     481              :            considering another iteration.
     482              :            Presumably we also want to ensure that it converges; we don't want
     483              :            a descending chain of constraints.  */
     484         2428 :         if (other == widen_arg0)
     485              :           {
     486          966 :             merger->on_widening_reuse (widen_arg0);
     487          966 :             return widen_arg0;
     488              :           }
     489              : 
     490              :         /* Merger of:
     491              :             this: BINOP(WIDENING(BASE, BINOP(BASE, X)), X)
     492              :            other: BINOP(BASE, X)
     493              :               to: WIDENING(BASE, BINOP(BASE, X)).  */
     494         1462 :         if (widen_arg0->get_iter_svalue () == other)
     495         1376 :           if (const binop_svalue *other_binop_sval
     496          688 :                 = other->dyn_cast_binop_svalue ())
     497          489 :             if (other_binop_sval->get_arg0 () == widen_arg0->get_base_svalue ()
     498          489 :                 && other_binop_sval->get_arg1 () == binop_sval->get_arg1 ())
     499              :               return widen_arg0;
     500              :       }
     501              : 
     502        33356 :   return mgr->get_or_create_unknown_svalue (get_type ());
     503              : }
     504              : 
     505              : /* Comparator for imposing a deterministic order on constants that are
     506              :    of the same type.  */
     507              : 
     508              : static int
     509     30988206 : cmp_csts_same_type (const_tree cst1, const_tree cst2)
     510              : {
     511     30988206 :   gcc_assert (TREE_TYPE (cst1) == TREE_TYPE (cst2));
     512     30988206 :   gcc_assert (TREE_CODE (cst1) == TREE_CODE (cst2));
     513     30988206 :   switch (TREE_CODE (cst1))
     514              :     {
     515            0 :     default:
     516            0 :       gcc_unreachable ();
     517     30984291 :     case INTEGER_CST:
     518     30984291 :       return tree_int_cst_compare (cst1, cst2);
     519          890 :     case STRING_CST:
     520          890 :       if (TREE_STRING_LENGTH (cst1) < TREE_STRING_LENGTH (cst2))
     521              :         return -1;
     522          890 :       if (TREE_STRING_LENGTH (cst1) > TREE_STRING_LENGTH (cst2))
     523              :         return 1;
     524          890 :       return memcmp (TREE_STRING_POINTER (cst1),
     525          890 :                      TREE_STRING_POINTER (cst2),
     526          890 :                      TREE_STRING_LENGTH (cst1));
     527           16 :     case RAW_DATA_CST:
     528           16 :       if (RAW_DATA_LENGTH (cst1) < RAW_DATA_LENGTH (cst2))
     529              :         return -1;
     530           16 :       if (RAW_DATA_LENGTH (cst1) > RAW_DATA_LENGTH (cst2))
     531              :         return 1;
     532           16 :       return memcmp (RAW_DATA_POINTER (cst1),
     533           16 :                      RAW_DATA_POINTER (cst2),
     534           16 :                      RAW_DATA_LENGTH (cst1));
     535         2486 :     case REAL_CST:
     536              :       /* Impose an arbitrary but deterministic order.  */
     537         2486 :       return memcmp (TREE_REAL_CST_PTR (cst1),
     538         2486 :                      TREE_REAL_CST_PTR (cst2),
     539         2486 :                      sizeof (real_value));
     540          327 :     case COMPLEX_CST:
     541          327 :       if (int cmp_real = cmp_csts_and_types (TREE_REALPART (cst1),
     542          327 :                                              TREE_REALPART (cst2)))
     543              :         return cmp_real;
     544          248 :       return cmp_csts_and_types (TREE_IMAGPART (cst1), TREE_IMAGPART (cst2));
     545          196 :     case VECTOR_CST:
     546          196 :       if (int cmp_log2_npatterns
     547          196 :             = ((int)VECTOR_CST_LOG2_NPATTERNS (cst1)
     548          196 :                - (int)VECTOR_CST_LOG2_NPATTERNS (cst2)))
     549              :         return cmp_log2_npatterns;
     550          196 :       if (int cmp_nelts_per_pattern
     551          196 :             = ((int)VECTOR_CST_NELTS_PER_PATTERN (cst1)
     552          196 :                - (int)VECTOR_CST_NELTS_PER_PATTERN (cst2)))
     553              :         return cmp_nelts_per_pattern;
     554          196 :       unsigned encoded_nelts = vector_cst_encoded_nelts (cst1);
     555          600 :       for (unsigned i = 0; i < encoded_nelts; i++)
     556              :         {
     557          208 :           const_tree elt1 = VECTOR_CST_ENCODED_ELT (cst1, i);
     558          208 :           const_tree elt2 = VECTOR_CST_ENCODED_ELT (cst2, i);
     559          208 :           if (int el_cmp = cmp_csts_and_types (elt1, elt2))
     560              :             return el_cmp;
     561              :         }
     562              :       return 0;
     563              :     }
     564              : }
     565              : 
     566              : int
     567    101578606 : cmp_types (const_tree a, const_tree b)
     568              : {
     569    101578606 :   int t1 = a ? TYPE_UID (a) : -1;
     570    101578606 :   int t2 = b ? TYPE_UID (b) : -1;
     571    101578606 :   return t1 - t2;
     572              : }
     573              : 
     574              : /* Comparator for imposing a deterministic order on constants that might
     575              :    not be of the same type.  */
     576              : 
     577              : int
     578          783 : cmp_csts_and_types (const_tree cst1, const_tree cst2)
     579              : {
     580          783 :   int t1 = TYPE_UID (TREE_TYPE (cst1));
     581          783 :   int t2 = TYPE_UID (TREE_TYPE (cst2));
     582          783 :   if (int cmp_type = t1 - t2)
     583              :     return cmp_type;
     584          759 :   return cmp_csts_same_type (cst1, cst2);
     585              : }
     586              : 
     587              : /* Comparator for imposing a deterministic order on svalues.  */
     588              : 
     589              : int
     590     22513174 : svalue::cmp_ptr (const svalue *sval1, const svalue *sval2)
     591              : {
     592     22513174 :   return cmp (*sval1, *sval2);
     593              : }
     594              : 
     595              : /* Comparator for use by vec<const svalue *>::qsort.  */
     596              : 
     597              : int
     598      1418899 : svalue::cmp_ptr_ptr (const void *p1, const void *p2)
     599              : {
     600      1418899 :   const svalue *sval1 = *(const svalue * const *)p1;
     601      1418899 :   const svalue *sval2 = *(const svalue * const *)p2;
     602      1418899 :   return cmp_ptr (sval1, sval2);
     603              : }
     604              : 
     605              : /* Base implementation of svalue::all_zeroes_p.
     606              :    Return true if this value is known to be all zeroes.  */
     607              : 
     608              : bool
     609       539091 : svalue::all_zeroes_p () const
     610              : {
     611       539091 :   return false;
     612              : }
     613              : 
     614              : /* If this svalue is a pointer, attempt to determine the base region it points
     615              :    to.  Return nullptr on any problems.  */
     616              : 
     617              : const region *
     618        20309 : svalue::maybe_get_deref_base_region () const
     619              : {
     620        20309 :   const svalue *iter = this;
     621        20625 :   while (1)
     622              :     {
     623        20467 :       switch (iter->get_kind ())
     624              :         {
     625              :         default:
     626              :           return nullptr;
     627              : 
     628         8875 :         case SK_POINTER:
     629         8875 :           {
     630         8875 :             auto *ptr_sval = as_a<const pointer_svalue *> (iter);
     631         8875 :             return &ptr_sval->get_base_region ();
     632              :           }
     633              : 
     634          321 :         case SK_BINOP:
     635          321 :           {
     636          321 :             const binop_svalue *binop_sval
     637          321 :               = as_a <const binop_svalue *> (iter);
     638          321 :             switch (binop_sval->get_op ())
     639              :               {
     640          158 :               case POINTER_PLUS_EXPR:
     641              :                 /* If we have a symbolic value expressing pointer arithmetic,
     642              :                    use the LHS.  */
     643          158 :                 iter = binop_sval->get_arg0 ();
     644          158 :                 continue;
     645              : 
     646              :               default:
     647              :                 return nullptr;
     648              :               }
     649              :             return nullptr;
     650              :           }
     651              :         }
     652          158 :     }
     653              : }
     654              : 
     655              : /* If this svalue is a pointer to the typeinfo instance for a particular
     656              :    type, return that type.  Otherwise return NULL_TREE.  */
     657              : 
     658              : tree
     659          855 : svalue::maybe_get_type_from_typeinfo () const
     660              : {
     661          855 :   if (auto *sym_ptr = maybe_get_symbolic_pointer ())
     662          660 :     if (sym_ptr->get_byte_offset ().is_zero_p ())
     663              :       {
     664          660 :         auto &base_reg = sym_ptr->get_base_region ();
     665          660 :         if (const decl_region *decl_reg = base_reg.dyn_cast_decl_region ())
     666          660 :           return TREE_TYPE (DECL_NAME (decl_reg->get_decl ()));
     667              :       }
     668              : 
     669              :   return NULL_TREE;
     670              : }
     671              : 
     672              : /* Base implementation of svalue::conjured_p.  */
     673              : 
     674              : bool
     675       962367 : svalue::conjured_p () const
     676              : {
     677       962367 :   return false;
     678              : }
     679              : 
     680              : /* Return true if this svalue is the initial value of a region,
     681              :    or derived directly from such a value (e.g. by casting or cropping).  */
     682              : 
     683              : bool
     684        49243 : svalue::derived_from_initial_value_p () const
     685              : {
     686        49464 :   switch (get_kind ())
     687              :     {
     688              :     default:
     689              :       return false;
     690              : 
     691        33952 :     case SK_INITIAL:
     692        33952 :       return true;
     693              : 
     694          221 :     case SK_UNARYOP:
     695          221 :       {
     696          221 :         const unaryop_svalue &unaryop = *as_a<const unaryop_svalue *> (this);
     697          221 :         return unaryop.get_arg ()->derived_from_initial_value_p ();
     698              :       }
     699              : 
     700         8967 :     case SK_BIT_VECTOR:
     701         8967 :       {
     702         8967 :         const svalue_from_bit_vector &from_bv
     703         8967 :           = *as_a<const svalue_from_bit_vector *> (this);
     704         8967 :         return from_bv.get_bit_vector ().derived_from_initial_value_p ();
     705              :       }
     706              :     }
     707              : }
     708              : 
     709              : /* Return true if we can get a value_range for TYPE (which could be
     710              :    NULL_TREE); false otherwise.  */
     711              : 
     712              : static bool
     713       251298 : type_can_have_value_range_p (tree type)
     714              : {
     715       251298 :   if (!type)
     716              :     return false;
     717       251298 :   if (irange::supports_p (type))
     718              :     return true;
     719        46367 :   if (frange::supports_p (type))
     720              :     return true;
     721              :   return false;
     722              : }
     723              : 
     724              : /* Base implementation of svalue::maybe_get_value_range_1 vfunc.
     725              :    If there is a suitable underlying type, write a "varying" for it to OUT
     726              :    (for "any value of that type") and return true; otherwise return false.  */
     727              : 
     728              : bool
     729        83010 : svalue::maybe_get_value_range_1 (value_range &out) const
     730              : {
     731        83010 :   tree type = get_type ();
     732        83010 :   if (!type_can_have_value_range_p (type))
     733              :     return false;
     734              : 
     735        48238 :   out.set_varying (type);
     736        48238 :   return true;
     737              : }
     738              : 
     739              : /* class pointer_svalue : public svalue.  */
     740              : 
     741              : bool
     742     17301656 : pointer_svalue::key_t::operator< (const key_t &other) const
     743              : {
     744     17301656 :   if (int c = cmp_types (m_type, other.m_type))
     745      5844014 :     return c < 0;
     746     11457642 :   if (int c = m_ptr.cmp (other.m_ptr))
     747      5982280 :     return c < 0;
     748              :   return false;
     749              : }
     750              : 
     751              : complexity
     752        44589 : pointer_svalue::key_t::get_complexity () const
     753              : {
     754        44589 :   return complexity::from_pair (m_ptr.get_base_region (),
     755        44589 :                                 m_ptr.get_byte_offset ());
     756              : }
     757              : 
     758              : /* Implementation of svalue::dump_to_pp vfunc for pointer_svalue.  */
     759              : 
     760              : void
     761          977 : pointer_svalue::dump_to_pp (pretty_printer *pp, bool simple) const
     762              : {
     763          977 :   if (simple)
     764              :     {
     765          977 :       pp_string (pp, "&");
     766          977 :       get_base_region ().dump_to_pp (pp, simple);
     767              : 
     768          977 :       auto &byte_offset = get_byte_offset ();
     769          977 :       if (!byte_offset.is_zero_p ())
     770              :         {
     771          253 :           pp_string (pp, " +(bytes) ");
     772          253 :           byte_offset.dump_to_pp (pp);
     773              :         }
     774              :     }
     775              :   else
     776              :     {
     777            0 :       pp_printf (pp, "POINTER_SVALUE(reg: (%i), offset: (%i))",
     778            0 :                  get_base_region ().get_id (),
     779            0 :                  get_byte_offset ().get_id ());
     780              :     }
     781          977 : }
     782              : 
     783              : /* Implementation of svalue::print_svalue_for_dump_widget_label vfunc for
     784              :    pointer_svalue.  */
     785              : 
     786              : void
     787         1608 : pointer_svalue::print_svalue_for_dump_widget_label (pretty_printer *pp) const
     788              : {
     789         1608 :   pp_string (pp, "pointer_svalue:");
     790         1608 : }
     791              : 
     792              : /* Implementation of svalue::add_dump_widget_children vfunc for
     793              :    pointer_svalue.  */
     794              : 
     795              : void
     796         1265 : pointer_svalue::
     797              : add_dump_widget_children (text_art::tree_widget &w,
     798              :                           symbolic::node_dump_state &nds) const
     799              : {
     800         1265 :   svalue::add_dump_widget_children (w, nds);
     801         2530 :   w.add_child (m_ptr.make_dump_widget (nds));
     802         1265 : }
     803              : 
     804              : void
     805      4115368 : pointer_svalue::accept_node_visitor (symbolic::node_visitor &v) const
     806              : {
     807      4115368 :   if (v.visit_svalue (*this))
     808      4115368 :     m_ptr.accept_node_visitor (v);
     809      4115368 : }
     810              : 
     811              : std::unique_ptr<json::object>
     812          105 : pointer_svalue::to_json () const
     813              : {
     814          105 :   auto obj = svalue::make_json_obj ("pointer_svalue");
     815          105 :   obj->set ("ptr", m_ptr.to_json ());
     816          105 :   return obj;
     817              : }
     818              : 
     819              : std::unique_ptr<diagnostics::markup::node>
     820            0 : pointer_svalue::make_markup_node (symbolic::markup_context &markup_ctxt) const
     821              : {
     822            0 :   if (get_byte_offset ().is_zero_p ())
     823              :     {
     824            0 :       auto markup = std::make_unique<diagnostics::markup::compound_node> ();
     825            0 :       markup->add_child ("&");
     826              :       // TODO: parens?
     827            0 :       markup->add_child (get_base_region ().make_markup_node (markup_ctxt));
     828            0 :       return markup;
     829            0 :     }
     830            0 :   return diagnostics::markup::make_text_node ("pointer_svalue");
     831              : }
     832              : 
     833              : /* Implementation of svalue::accept vfunc for pointer_svalue.  */
     834              : 
     835              : void
     836          135 : pointer_svalue::accept (visitor *v) const
     837              : {
     838          135 :   m_ptr.get_base_region ().accept (v);
     839          135 :   v->visit_pointer_svalue (this);
     840          135 : }
     841              : 
     842              : /* Implementation of svalue::implicitly_live_p vfunc for pointer_svalue.  */
     843              : 
     844              : bool
     845       219944 : pointer_svalue::
     846              : implicitly_live_p (symbolic::liveness_context &liveness_ctxt) const
     847              : {
     848              :   /* Pointers into clusters that have escaped should be treated as live.  */
     849       219944 :   const region &base_reg = get_base_region ();
     850       219944 :   const store *store = liveness_ctxt.get_model ()->get_store ();
     851       219944 :   if (const binding_cluster *c = store->get_cluster (&base_reg))
     852       181370 :     if (c->escaped_p ())
     853              :       return true;
     854              : 
     855              :   /* Any known-live pointer to BASE_REG in LIVENESS_CTXT allows us to
     856              :      treat all pointers to BASE_REG as live, so that different
     857              :      (X*)ptr and (Y*)ptr are effectively the same from
     858              :      a liveness perspective.  */
     859       185664 :   if (liveness_ctxt.known_live_ptr_to_base_region_p (base_reg))
     860              :     return true;
     861              : 
     862              :   return false;
     863              : }
     864              : 
     865              : /* class constant_svalue : public svalue.  */
     866              : 
     867              : bool
     868     45764788 : constant_svalue::key_t::operator< (const key_t &other) const
     869              : {
     870     45764788 :   if (int c = cmp_types (m_type, other.m_type))
     871     14777341 :     return c < 0;
     872     30987447 :   if (int c = cmp_types (TREE_TYPE (m_cst), TREE_TYPE (other.m_cst)))
     873            0 :     return c < 0;
     874     30987447 :   gcc_assert (TREE_CODE (m_cst) == TREE_CODE (other.m_cst));
     875     30987447 :   return cmp_csts_same_type (m_cst, other.m_cst) < 0;
     876              : }
     877              : 
     878              : /* Implementation of svalue::dump_to_pp vfunc for constant_svalue.  */
     879              : 
     880              : void
     881         7866 : constant_svalue::dump_to_pp (pretty_printer *pp, bool simple) const
     882              : {
     883         7866 :   if (simple)
     884              :     {
     885         7859 :       pp_string (pp, "(");
     886         7859 :       dump_tree (pp, get_type ());
     887         7859 :       pp_string (pp, ")");
     888         7859 :       dump_tree (pp, m_cst_expr);
     889              :     }
     890              :   else
     891              :     {
     892            7 :       pp_string (pp, "constant_svalue(");
     893            7 :       if (get_type ())
     894              :         {
     895            7 :           print_quoted_type (pp, get_type ());
     896            7 :           pp_string (pp, ", ");
     897              :         }
     898            7 :       dump_tree (pp, m_cst_expr);
     899            7 :       pp_string (pp, ")");
     900              :     }
     901         7866 : }
     902              : 
     903              : /* Implementation of svalue::print_svalue_for_dump_widget_label vfunc for
     904              :    constant_svalue.  */
     905              : 
     906              : void
     907         2400 : constant_svalue::print_svalue_for_dump_widget_label (pretty_printer *pp) const
     908              : {
     909         2400 :   pp_printf (pp, "constant_svalue (%qE)", m_cst_expr);
     910         2400 : }
     911              : 
     912              : void
     913     15663521 : constant_svalue::accept_node_visitor (symbolic::node_visitor &v) const
     914              : {
     915     15663521 :   v.visit_svalue (*this);
     916     15663521 : }
     917              : 
     918              : std::unique_ptr<json::object>
     919          194 : constant_svalue::to_json () const
     920              : {
     921          194 :   auto obj = svalue::make_json_obj ("constant_svalue");
     922          194 :   obj->set ("constant", tree_to_json (m_cst_expr));
     923          194 :   return obj;
     924              : }
     925              : 
     926              : std::unique_ptr<diagnostics::markup::node>
     927           12 : constant_svalue::make_markup_node (symbolic::markup_context &) const
     928              : {
     929           12 :   pretty_printer pp;
     930           12 :   pp_format_decoder (&pp) = default_tree_printer;
     931           12 :   pp_printf (&pp, "%E", m_cst_expr);
     932           12 :   return std::make_unique<diagnostics::markup::text> (pp_formatted_text (&pp));
     933           12 : }
     934              : 
     935              : /* Implementation of svalue::accept vfunc for constant_svalue.  */
     936              : 
     937              : void
     938         8021 : constant_svalue::accept (visitor *v) const
     939              : {
     940         8021 :   v->visit_constant_svalue (this);
     941         8021 : }
     942              : 
     943              : /* Implementation of svalue::implicitly_live_p vfunc for constant_svalue.
     944              :    Constants are implicitly live.  */
     945              : 
     946              : bool
     947        95091 : constant_svalue::implicitly_live_p (symbolic::liveness_context &) const
     948              : {
     949        95091 :   return true;
     950              : }
     951              : 
     952              : /* Given EXPR, a non-NULL expression of boolean type, convert to
     953              :    a tristate based on whether this is known to be true, false,
     954              :    or is not known.  */
     955              : 
     956              : static tristate
     957        10852 : tristate_from_boolean_tree_node (tree expr)
     958              : {
     959        10852 :   gcc_assert (TREE_TYPE (expr) == boolean_type_node);
     960              : 
     961        10852 :   if (expr == boolean_true_node)
     962         7867 :     return tristate (tristate::TS_TRUE);
     963         2985 :   else if (expr == boolean_false_node)
     964         2985 :     return tristate (tristate::TS_FALSE);
     965              :   else
     966            0 :     return tristate (tristate::TS_UNKNOWN);
     967              : }
     968              : 
     969              : /* Evaluate the condition LHS OP RHS.
     970              :    Subroutine of region_model::eval_condition for when we have a pair of
     971              :    constants.  */
     972              : 
     973              : tristate
     974        11227 : constant_svalue::eval_condition (const constant_svalue *lhs,
     975              :                                  enum tree_code op,
     976              :                                  const constant_svalue *rhs)
     977              : {
     978        11227 :   tree lhs_const = lhs->get_constant ();
     979        11227 :   tree rhs_const = rhs->get_constant ();
     980              : 
     981        11227 :   gcc_assert (CONSTANT_CLASS_P (lhs_const));
     982        11227 :   gcc_assert (CONSTANT_CLASS_P (rhs_const));
     983              : 
     984        11227 :   if ((lhs->get_type () == NULL_TREE || rhs->get_type () == NULL_TREE)
     985            0 :       && TREE_CODE (lhs_const) == INTEGER_CST
     986        11227 :       && TREE_CODE (rhs_const) == INTEGER_CST
     987              :       )
     988              :     {
     989            0 :      if (tree tree_cmp = const_binop (op, boolean_type_node,
     990              :                                       lhs_const, rhs_const))
     991              :        {
     992            0 :          tristate ts = tristate_from_boolean_tree_node (tree_cmp);
     993            0 :          if (ts.is_known ())
     994            0 :            return ts;
     995              :        }
     996              :     }
     997              : 
     998              :   /* Check for comparable types.  */
     999        11227 :   if (types_compatible_p (TREE_TYPE (lhs_const), TREE_TYPE (rhs_const)))
    1000              :     {
    1001        10852 :       tree tree_cmp
    1002        10852 :         = fold_binary (op, boolean_type_node, lhs_const, rhs_const);
    1003        10852 :       tristate ts = tristate_from_boolean_tree_node (tree_cmp);
    1004        10852 :       if (ts.is_known ())
    1005        10852 :         return ts;
    1006              :     }
    1007          375 :   return tristate::TS_UNKNOWN;
    1008              : }
    1009              : 
    1010              : /* Implementation of svalue::all_zeroes_p for constant_svalue.  */
    1011              : 
    1012              : bool
    1013       219700 : constant_svalue::all_zeroes_p () const
    1014              : {
    1015       219700 :   return zerop (m_cst_expr);
    1016              : }
    1017              : 
    1018              : 
    1019              : /* Implementation of svalue::maybe_get_value_range_1 for constant_svalue.
    1020              :    If there is a suitable underlying type, write the value_range for the
    1021              :    single value of m_cst_expr to OUT and return true; otherwise return
    1022              :    false.  */
    1023              : 
    1024              : bool
    1025        74003 : constant_svalue::maybe_get_value_range_1 (value_range &out) const
    1026              : {
    1027        74003 :   if (!type_can_have_value_range_p (get_type ()))
    1028              :     return false;
    1029              : 
    1030              :   /* Reject NaN.  */
    1031        73885 :   if (TREE_CODE (m_cst_expr) == REAL_CST
    1032        73885 :       && REAL_VALUE_ISNAN (TREE_REAL_CST (m_cst_expr)))
    1033              :     return false;
    1034              : 
    1035        73883 :   out = value_range (m_cst_expr, m_cst_expr);
    1036        73883 :   return true;
    1037              : }
    1038              : 
    1039              : /* class unknown_svalue : public svalue.  */
    1040              : 
    1041              : /* Implementation of svalue::dump_to_pp vfunc for unknown_svalue.  */
    1042              : 
    1043              : void
    1044          107 : unknown_svalue::dump_to_pp (pretty_printer *pp, bool simple) const
    1045              : {
    1046          107 :   if (simple)
    1047              :     {
    1048          107 :       pp_string (pp, "UNKNOWN(");
    1049          107 :       if (get_type ())
    1050          104 :         dump_tree (pp, get_type ());
    1051          107 :       pp_character (pp, ')');
    1052              :     }
    1053              :   else
    1054              :     {
    1055            0 :       pp_string (pp, "unknown_svalue(");
    1056            0 :       if (get_type ())
    1057            0 :         dump_tree (pp, get_type ());
    1058            0 :       pp_character (pp, ')');
    1059              :     }
    1060          107 : }
    1061              : 
    1062              : /* Implementation of svalue::print_svalue_for_dump_widget_label vfunc for
    1063              :    unknown_svalue.  */
    1064              : 
    1065              : void
    1066          290 : unknown_svalue::print_svalue_for_dump_widget_label (pretty_printer *pp) const
    1067              : {
    1068          290 :   pp_printf (pp, "unknown_svalue");
    1069          290 : }
    1070              : 
    1071              : void
    1072       136020 : unknown_svalue::accept_node_visitor (symbolic::node_visitor &v) const
    1073              : {
    1074       136020 :   v.visit_svalue (*this);
    1075       136020 : }
    1076              : 
    1077              : std::unique_ptr<json::object>
    1078            4 : unknown_svalue::to_json () const
    1079              : {
    1080            4 :   return svalue::make_json_obj ("unknown_svalue");
    1081              : }
    1082              : 
    1083              : std::unique_ptr<diagnostics::markup::node>
    1084            5 : unknown_svalue::make_markup_node (symbolic::markup_context &) const
    1085              : {
    1086            5 :   return diagnostics::markup::make_text_node ("unknown");
    1087              : }
    1088              : 
    1089              : /* Implementation of svalue::accept vfunc for unknown_svalue.  */
    1090              : 
    1091              : void
    1092         3399 : unknown_svalue::accept (visitor *v) const
    1093              : {
    1094         3399 :   v->visit_unknown_svalue (this);
    1095         3399 : }
    1096              : 
    1097              : bool
    1098        54428 : unknown_svalue::maybe_get_value_range_1 (value_range &) const
    1099              : {
    1100              :   /* Don't attempt to participate in range ops.  */
    1101        54428 :   return false;
    1102              : }
    1103              : 
    1104              : 
    1105              : /* Get a string for KIND for use in debug dumps.  */
    1106              : 
    1107              : const char *
    1108           40 : poison_kind_to_str (enum poison_kind kind)
    1109              : {
    1110           40 :   switch (kind)
    1111              :     {
    1112            0 :     default:
    1113            0 :       gcc_unreachable ();
    1114              :     case poison_kind::uninit:
    1115              :       return "uninit";
    1116           12 :     case poison_kind::freed:
    1117           12 :       return "freed";
    1118            0 :     case poison_kind::deleted:
    1119            0 :       return "deleted";
    1120            0 :     case poison_kind::popped_stack:
    1121            0 :       return "popped stack";
    1122              :     }
    1123              : }
    1124              : 
    1125              : /* class poisoned_svalue : public svalue.  */
    1126              : 
    1127              : /* Implementation of svalue::dump_to_pp vfunc for poisoned_svalue.  */
    1128              : 
    1129              : void
    1130            0 : poisoned_svalue::dump_to_pp (pretty_printer *pp, bool simple) const
    1131              : {
    1132            0 :   if (simple)
    1133              :     {
    1134            0 :       pp_string (pp, "POISONED(");
    1135            0 :       print_quoted_type (pp, get_type ());
    1136            0 :       pp_printf (pp, ", %s)", poison_kind_to_str (m_kind));
    1137              :     }
    1138              :   else
    1139              :     {
    1140            0 :       pp_string (pp, "poisoned_svalue(");
    1141            0 :       print_quoted_type (pp, get_type ());
    1142            0 :       pp_printf (pp, ", %s)", poison_kind_to_str (m_kind));
    1143              :     }
    1144            0 : }
    1145              : 
    1146              : /* Implementation of svalue::print_svalue_for_dump_widget_label vfunc for
    1147              :    poisoned_svalue.  */
    1148              : 
    1149              : void
    1150            0 : poisoned_svalue::print_svalue_for_dump_widget_label (pretty_printer *pp) const
    1151              : {
    1152            0 :   pp_printf (pp, "poisoned_svalue(%s)", poison_kind_to_str (m_kind));
    1153            0 : }
    1154              : 
    1155              : void
    1156            0 : poisoned_svalue::accept_node_visitor (symbolic::node_visitor &v) const
    1157              : {
    1158            0 :   v.visit_svalue (*this);
    1159            0 : }
    1160              : 
    1161              : std::unique_ptr<json::object>
    1162            0 : poisoned_svalue::to_json () const
    1163              : {
    1164            0 :   auto obj = svalue::make_json_obj ("poisoned_svalue");
    1165            0 :   obj->set_string ("kind", poison_kind_to_str (m_kind));
    1166            0 :   return obj;
    1167              : }
    1168              : 
    1169              : std::unique_ptr<diagnostics::markup::node>
    1170            0 : poisoned_svalue::make_markup_node (symbolic::markup_context &) const
    1171              : {
    1172            0 :   return diagnostics::markup::make_text_node ("poisoned_svalue");
    1173              : }
    1174              : 
    1175              : /* Implementation of svalue::accept vfunc for poisoned_svalue.  */
    1176              : 
    1177              : void
    1178            0 : poisoned_svalue::accept (visitor *v) const
    1179              : {
    1180            0 :   v->visit_poisoned_svalue (this);
    1181            0 : }
    1182              : 
    1183              : /* class setjmp_svalue's implementation is in setjmp-longjmp.cc.  */
    1184              : 
    1185              : /* class initial_svalue : public svalue.  */
    1186              : 
    1187              : /* Implementation of svalue::dump_to_pp vfunc for initial_svalue.  */
    1188              : 
    1189        22407 : initial_svalue::initial_svalue (symbolic::node::id_t id, tree type, const region *reg)
    1190        22407 : : svalue (complexity (reg), id, type), m_reg (reg)
    1191              : {
    1192        22407 :   gcc_assert (m_reg != nullptr);
    1193              : 
    1194              :   /* Must be a base region.  */
    1195        22407 :   gcc_assert (m_reg->base_region_p ());
    1196              : 
    1197              :   /* TODO(once we have a m_node_mgr):
    1198              :      assert that m_reg->region_has_meaningful_size_p (m_node_mgr) ???  */
    1199        22407 : }
    1200              : 
    1201              : void
    1202          348 : initial_svalue::dump_to_pp (pretty_printer *pp, bool simple) const
    1203              : {
    1204          348 :   if (simple)
    1205              :     {
    1206          348 :       pp_string (pp, "INIT_VAL(");
    1207          348 :       m_reg->dump_to_pp (pp, simple);
    1208          348 :       pp_string (pp, ")");
    1209              :     }
    1210              :   else
    1211              :     {
    1212            0 :       pp_string (pp, "initial_svalue(");
    1213            0 :       if (get_type ())
    1214              :         {
    1215            0 :           print_quoted_type (pp, get_type ());
    1216            0 :           pp_string (pp, ", ");
    1217              :         }
    1218            0 :       m_reg->dump_to_pp (pp, simple);
    1219            0 :       pp_string (pp, ")");
    1220              :     }
    1221          348 : }
    1222              : 
    1223              : /* Implementation of svalue::print_svalue_for_dump_widget_label vfunc for
    1224              :    initial_svalue.  */
    1225              : 
    1226              : void
    1227          296 : initial_svalue::print_svalue_for_dump_widget_label (pretty_printer *pp) const
    1228              : {
    1229          296 :   pp_printf (pp, "initial_svalue");
    1230          296 : }
    1231              : 
    1232              : /* Implementation of svalue::add_dump_widget_children vfunc for
    1233              :    initial_svalue.  */
    1234              : 
    1235              : void
    1236          227 : initial_svalue::
    1237              : add_dump_widget_children (text_art::tree_widget &w,
    1238              :                           symbolic::node_dump_state &nds) const
    1239              : {
    1240          227 :   svalue::add_dump_widget_children (w, nds);
    1241          454 :   w.add_child (m_reg->make_dump_widget (nds, "m_reg"));
    1242          227 : }
    1243              : 
    1244              : void
    1245     10525628 : initial_svalue::accept_node_visitor (symbolic::node_visitor &v) const
    1246              : {
    1247     10525628 :   if (v.visit_svalue (*this))
    1248     10525628 :     m_reg->accept_node_visitor (v);
    1249     10525628 : }
    1250              : 
    1251              : std::unique_ptr<json::object>
    1252           73 : initial_svalue::to_json () const
    1253              : {
    1254           73 :   auto obj = svalue::make_json_obj ("initial_svalue");
    1255           73 :   obj->set ("reg", m_reg->to_json ());
    1256           73 :   return obj;
    1257              : }
    1258              : 
    1259              : std::unique_ptr<diagnostics::markup::node>
    1260           38 : initial_svalue::make_markup_node (symbolic::markup_context &markup_ctxt) const
    1261              : {
    1262              :   // TODO: show 'initial_value()' ?
    1263           38 :   return m_reg->make_markup_node (markup_ctxt);
    1264              : }
    1265              : 
    1266              : /* Implementation of svalue::accept vfunc for initial_svalue.  */
    1267              : 
    1268              : void
    1269         1250 : initial_svalue::accept (visitor *v) const
    1270              : {
    1271         1250 :   m_reg->accept (v);
    1272         1250 :   v->visit_initial_svalue (this);
    1273         1250 : }
    1274              : 
    1275              : /* Implementation of svalue::implicitly_live_p vfunc for initial_svalue.  */
    1276              : 
    1277              : bool
    1278      1127690 : initial_svalue::
    1279              : implicitly_live_p (symbolic::liveness_context &liveness_ctxt) const
    1280              : {
    1281              :   /* This svalue may be implicitly live if the region still implicitly
    1282              :      has its initial value and is reachable.  */
    1283              : 
    1284              :   /* It must be a region that exists; we don't want to consider
    1285              :      INIT_VAL(R) as still being implicitly reachable if R is in
    1286              :      a popped stack frame.  */
    1287      1127690 :   auto *model = liveness_ctxt.get_model ();
    1288      1127690 :   if (model->region_exists_p (m_reg))
    1289              :     {
    1290      1113102 :       const svalue *reg_sval = model->get_store_value (m_reg, nullptr);
    1291      1113102 :       if (reg_sval == this)
    1292              :         return true;
    1293              :     }
    1294              : 
    1295              :   /* Assume that the initial values of params for the top level frame
    1296              :      are still live, because (presumably) they're still
    1297              :      live in the external caller.  */
    1298        62670 :   if (initial_value_of_param_p ())
    1299        13636 :     if (const frame_region *frame_reg = m_reg->maybe_get_frame_region ())
    1300        13636 :       if (frame_reg->get_calling_frame () == nullptr)
    1301        13636 :         return true;
    1302              : 
    1303              :   return false;
    1304              : }
    1305              : 
    1306              : /* Return true if this is the initial value of a function parameter.  */
    1307              : 
    1308              : bool
    1309        63117 : initial_svalue::initial_value_of_param_p () const
    1310              : {
    1311        63117 :   if (tree reg_decl = m_reg->maybe_get_decl ())
    1312        61556 :     if (TREE_CODE (reg_decl) == SSA_NAME)
    1313              :       {
    1314        13725 :         tree ssa_name = reg_decl;
    1315        13725 :         if (SSA_NAME_IS_DEFAULT_DEF (ssa_name)
    1316        13725 :             && SSA_NAME_VAR (ssa_name)
    1317        27450 :             && TREE_CODE (SSA_NAME_VAR (ssa_name)) == PARM_DECL)
    1318        13708 :           return true;
    1319              :       }
    1320              :   return false;
    1321              : }
    1322              : 
    1323              : /* class unaryop_svalue : public svalue.  */
    1324              : 
    1325              : bool
    1326       861362 : unaryop_svalue::key_t::operator< (const key_t &other) const
    1327              : {
    1328       861362 :   if (int c = (int)m_op - (int)other.m_op)
    1329         4612 :     return c < 0;
    1330       856750 :   if (int c = cmp_types (m_type, other.m_type))
    1331       184801 :     return c < 0;
    1332       671949 :   if (int c = symbolic::node::cmp_ids (m_arg, other.m_arg))
    1333       385351 :     return c < 0;
    1334              :   return false;
    1335              : }
    1336              : 
    1337              : /* Implementation of svalue::dump_to_pp vfunc for unaryop_svalue.  */
    1338              : 
    1339              : void
    1340          247 : unaryop_svalue::dump_to_pp (pretty_printer *pp, bool simple) const
    1341              : {
    1342          247 :   if (simple)
    1343              :     {
    1344          247 :       if (m_op == VIEW_CONVERT_EXPR || m_op == NOP_EXPR)
    1345              :         {
    1346          246 :           pp_string (pp, "CAST(");
    1347          246 :           dump_tree (pp, get_type ());
    1348          246 :           pp_string (pp, ", ");
    1349          246 :           m_arg->dump_to_pp (pp, simple);
    1350          246 :           pp_character (pp, ')');
    1351              :         }
    1352              :       else
    1353              :         {
    1354            1 :           pp_character (pp, '(');
    1355            1 :           pp_string (pp, get_tree_code_name (m_op));
    1356              :           //pp_string (pp, op_symbol_code (m_op));
    1357            1 :           m_arg->dump_to_pp (pp, simple);
    1358            1 :           pp_character (pp, ')');
    1359              :         }
    1360              :     }
    1361              :   else
    1362              :     {
    1363            0 :       pp_string (pp, "unaryop_svalue (");
    1364            0 :       pp_string (pp, get_tree_code_name (m_op));
    1365            0 :       pp_string (pp, ", ");
    1366            0 :       m_arg->dump_to_pp (pp, simple);
    1367            0 :       pp_character (pp, ')');
    1368              :     }
    1369          247 : }
    1370              : 
    1371              : /* Implementation of svalue::print_svalue_for_dump_widget_label vfunc for
    1372              :    unaryop_svalue.  */
    1373              : 
    1374              : void
    1375          519 : unaryop_svalue::print_svalue_for_dump_widget_label (pretty_printer *pp) const
    1376              : {
    1377          519 :   pp_printf (pp,
    1378              :              "unaryop_svalue(%s)",
    1379          519 :              get_tree_code_name (m_op));
    1380          519 : }
    1381              : 
    1382              : /* Implementation of svalue::add_dump_widget_children vfunc for
    1383              :    unaryop_svalue.  */
    1384              : 
    1385              : void
    1386          508 : unaryop_svalue::
    1387              : add_dump_widget_children (text_art::tree_widget &w,
    1388              :                           symbolic::node_dump_state &nds) const
    1389              : {
    1390          508 :   svalue::add_dump_widget_children (w, nds);
    1391         1016 :   w.add_child (m_arg->make_dump_widget (nds));
    1392          508 : }
    1393              : 
    1394              : void
    1395     13927653 : unaryop_svalue::accept_node_visitor (symbolic::node_visitor &v) const
    1396              : {
    1397     13927653 :   if (v.visit_svalue (*this))
    1398     13927653 :     m_arg->accept_node_visitor (v);
    1399     13927653 : }
    1400              : 
    1401              : std::unique_ptr<json::object>
    1402            0 : unaryop_svalue::to_json () const
    1403              : {
    1404            0 :   auto obj = svalue::make_json_obj ("unaryop_svalue");
    1405            0 :   obj->set ("arg", m_arg->to_json ());
    1406            0 :   return obj;
    1407              : }
    1408              : 
    1409              : std::unique_ptr<diagnostics::markup::node>
    1410            0 : unaryop_svalue::make_markup_node (symbolic::markup_context &markup_ctxt) const
    1411              : {
    1412            0 :   gcc_assert (m_op == NOP_EXPR); // FIXME!!!
    1413            0 :   return m_arg->make_markup_node (markup_ctxt);
    1414              : }
    1415              : 
    1416              : /* Implementation of svalue::accept vfunc for unaryop_svalue.  */
    1417              : 
    1418              : void
    1419          736 : unaryop_svalue::accept (visitor *v) const
    1420              : {
    1421          736 :   m_arg->accept (v);
    1422          736 :   v->visit_unaryop_svalue (this);
    1423          736 : }
    1424              : 
    1425              : /* Implementation of svalue::implicitly_live_p vfunc for unaryop_svalue.  */
    1426              : 
    1427              : bool
    1428        86295 : unaryop_svalue::
    1429              : implicitly_live_p (symbolic::liveness_context &liveness_ctxt) const
    1430              : {
    1431        86295 :   return liveness_ctxt.node_live_p (*get_arg ());
    1432              : }
    1433              : 
    1434              : /* Implementation of svalue::maybe_get_value_range_1 for unaryop_svalue.  */
    1435              : 
    1436              : bool
    1437        19148 : unaryop_svalue::maybe_get_value_range_1 (value_range &out) const
    1438              : {
    1439        19148 :   tree type = get_type ();
    1440        19148 :   if (!type_can_have_value_range_p (type))
    1441              :     return false;
    1442              : 
    1443        18996 :   value_range arg_vr;
    1444        18996 :   if (m_arg->maybe_get_value_range (arg_vr))
    1445              :     {
    1446        17167 :       range_op_handler handler (m_op);
    1447        17167 :       if (handler
    1448        34334 :           && handler.operand_check_p (type, arg_vr.type (), type))
    1449              :         {
    1450              :           /* For unary ops, range_op_hander::fold_range expects
    1451              :              a VARYING of the unknown value as the 2nd operand.  */
    1452        17165 :           value_range varying (type);
    1453        17165 :           varying.set_varying (type);
    1454        17165 :           out.set_range_class (type);
    1455        17165 :           if (handler.fold_range (out, type, arg_vr, varying))
    1456        17165 :             return true;
    1457        17165 :         }
    1458              :     }
    1459              :   return false;
    1460        18996 : }
    1461              : 
    1462              : /* class binop_svalue : public svalue.  */
    1463              : 
    1464              : bool
    1465       360375 : binop_svalue::key_t::operator< (const key_t &other) const
    1466              : {
    1467       360375 :   if (int c = (int)m_op - (int)other.m_op)
    1468        87691 :     return c < 0;
    1469       272684 :   if (int c = cmp_types (m_type, other.m_type))
    1470        37334 :     return c < 0;
    1471       235350 :   if (int c = symbolic::node::cmp_ids (m_arg0, other.m_arg0))
    1472       143673 :     return c < 0;
    1473        91677 :   if (int c = symbolic::node::cmp_ids (m_arg1, other.m_arg1))
    1474        18795 :     return c < 0;
    1475              :   return false;
    1476              : }
    1477              : 
    1478              : /* Return whether OP be printed as an infix operator.  */
    1479              : 
    1480              : static bool
    1481          794 : infix_p (enum tree_code op)
    1482              : {
    1483            0 :   switch (op)
    1484              :     {
    1485              :     default:
    1486              :       return true;
    1487            0 :     case MAX_EXPR:
    1488            0 :     case MIN_EXPR:
    1489            0 :       return false;
    1490              :     }
    1491              : }
    1492              : 
    1493              : /* Implementation of svalue::dump_to_pp vfunc for binop_svalue.  */
    1494              : 
    1495              : void
    1496          794 : binop_svalue::dump_to_pp (pretty_printer *pp, bool simple) const
    1497              : {
    1498          794 :   if (simple)
    1499              :     {
    1500          794 :       if (infix_p (m_op))
    1501              :         {
    1502              :           /* Print "(A OP B)".  */
    1503          794 :           pp_character (pp, '(');
    1504          794 :           m_arg0->dump_to_pp (pp, simple);
    1505          794 :           pp_string (pp, op_symbol_code (m_op));
    1506          794 :           m_arg1->dump_to_pp (pp, simple);
    1507          794 :           pp_character (pp, ')');
    1508              :         }
    1509              :       else
    1510              :         {
    1511              :           /* Print "OP(A, B)".  */
    1512            0 :           pp_string (pp, op_symbol_code (m_op));
    1513            0 :           pp_character (pp, '(');
    1514            0 :           m_arg0->dump_to_pp (pp, simple);
    1515            0 :           pp_string (pp, ", ");
    1516            0 :           m_arg1->dump_to_pp (pp, simple);
    1517            0 :           pp_character (pp, ')');
    1518              :         }
    1519              :     }
    1520              :   else
    1521              :     {
    1522            0 :       pp_string (pp, "binop_svalue (");
    1523            0 :       pp_string (pp, get_tree_code_name (m_op));
    1524            0 :       pp_string (pp, ", ");
    1525            0 :       m_arg0->dump_to_pp (pp, simple);
    1526            0 :       pp_string (pp, ", ");
    1527            0 :       m_arg1->dump_to_pp (pp, simple);
    1528            0 :       pp_character (pp, ')');
    1529              :     }
    1530          794 : }
    1531              : 
    1532              : /* Implementation of svalue::print_svalue_for_dump_widget_label vfunc for
    1533              :    binop_svalue.  */
    1534              : 
    1535              : void
    1536          765 : binop_svalue::print_svalue_for_dump_widget_label (pretty_printer *pp) const
    1537              : {
    1538          765 :   pp_printf (pp,
    1539              :              "binop_svalue(%s: %qs)",
    1540          765 :              get_tree_code_name (m_op),
    1541          765 :              op_symbol_code (m_op));
    1542          765 : }
    1543              : 
    1544              : /* Implementation of svalue::add_dump_widget_children vfunc for
    1545              :    binop_svalue.  */
    1546              : 
    1547              : void
    1548          632 : binop_svalue::
    1549              : add_dump_widget_children (text_art::tree_widget &w,
    1550              :                           symbolic::node_dump_state &nds) const
    1551              : {
    1552          632 :   svalue::add_dump_widget_children (w, nds);
    1553         1264 :   w.add_child (m_arg0->make_dump_widget (nds));
    1554         1264 :   w.add_child (m_arg1->make_dump_widget (nds));
    1555          632 : }
    1556              : 
    1557              : void
    1558     18089505 : binop_svalue::accept_node_visitor (symbolic::node_visitor &v) const
    1559              : {
    1560     18089505 :   if (v.visit_svalue (*this))
    1561              :     {
    1562     18089505 :       m_arg0->accept_node_visitor (v);
    1563     18089505 :       m_arg1->accept_node_visitor (v);
    1564              :     }
    1565     18089505 : }
    1566              : 
    1567              : std::unique_ptr<json::object>
    1568            0 : binop_svalue::to_json () const
    1569              : {
    1570            0 :   auto obj = svalue::make_json_obj ("binop_svalue");
    1571            0 :   obj->set ("arg0", m_arg0->to_json ());
    1572            0 :   obj->set ("arg1", m_arg1->to_json ());
    1573              :   // FIXME: op?
    1574            0 :   return obj;
    1575              : }
    1576              : 
    1577              : std::unique_ptr<diagnostics::markup::node>
    1578            4 : binop_svalue::make_markup_node (symbolic::markup_context &markup_ctxt) const
    1579              : {
    1580            4 :   return std::make_unique<diagnostics::markup::code::infix_binary_op>
    1581            4 :     (m_arg0->make_markup_node (markup_ctxt),
    1582            4 :      op_symbol_code (m_op),
    1583           12 :      m_arg1->make_markup_node (markup_ctxt));
    1584              : }
    1585              : 
    1586              : /* Implementation of svalue::accept vfunc for binop_svalue.  */
    1587              : 
    1588              : void
    1589         1397 : binop_svalue::accept (visitor *v) const
    1590              : {
    1591         1397 :   m_arg0->accept (v);
    1592         1397 :   m_arg1->accept (v);
    1593         1397 :   v->visit_binop_svalue (this);
    1594         1397 : }
    1595              : 
    1596              : /* Implementation of svalue::implicitly_live_p vfunc for binop_svalue.  */
    1597              : 
    1598              : bool
    1599       225002 : binop_svalue::
    1600              : implicitly_live_p (symbolic::liveness_context &liveness_ctxt) const
    1601              : {
    1602       225002 :   return (liveness_ctxt.node_live_p (*get_arg0 ())
    1603       225002 :           && liveness_ctxt.node_live_p (*get_arg1 ()));
    1604              : }
    1605              : 
    1606              : /* Implementation of svalue::maybe_get_value_range_1 for binop_svalue.  */
    1607              : 
    1608              : bool
    1609        39775 : binop_svalue::maybe_get_value_range_1 (value_range &out) const
    1610              : {
    1611        39775 :   tree type = get_type ();
    1612        39775 :   if (!type_can_have_value_range_p (type))
    1613              :     return false;
    1614              : 
    1615              :   /* Avoid cases where we have been sloppy about types.  */
    1616        38487 :   if (!m_arg0->get_type ())
    1617              :     return false;
    1618        38487 :   if (!m_arg1->get_type ())
    1619              :     return false;
    1620        38487 :   if (!range_compatible_p (m_arg0->get_type (), m_arg1->get_type ()))
    1621              :     return false;
    1622              : 
    1623        38133 :   value_range lhs, rhs;
    1624        38133 :   if (m_arg0->maybe_get_value_range (lhs))
    1625        35245 :     if (m_arg1->maybe_get_value_range (rhs))
    1626              :       {
    1627        35119 :         range_op_handler handler (m_op);
    1628        35119 :         if (handler
    1629        70238 :             && handler.operand_check_p (type, lhs.type (), rhs.type ()))
    1630              :           {
    1631        35119 :             out.set_range_class (type);
    1632        35119 :             if (handler.fold_range (out, get_type (), lhs, rhs))
    1633        35119 :               return true;
    1634              :           }
    1635              :       }
    1636              :   return false;
    1637        38133 : }
    1638              : 
    1639              : /* class svalue_from_bit_vector : public svalue.  */
    1640              : 
    1641              : bool
    1642      6379513 : svalue_from_bit_vector::key_t::operator< (const key_t &other) const
    1643              : {
    1644      6379513 :   if (int c = cmp_types (m_type, other.m_type))
    1645      1621974 :     return c < 0;
    1646      4757539 :   if (int c = symbolic::node::cmp_ids (m_bv, other.m_bv))
    1647      2880295 :     return c < 0;
    1648              :   return false;
    1649              : }
    1650              : 
    1651              : /* svalue_from_bit_vector'c ctor.  */
    1652              : 
    1653        39600 : svalue_from_bit_vector::
    1654              : svalue_from_bit_vector (symbolic::node::id_t id,
    1655              :                         tree type,
    1656              :                         const symbolic::bit_vector &bv)
    1657              : : svalue (/* Reuse the complexity of BV rather than adding one to it for now,
    1658              :              to stay closer to pre-symbolic::node behavior.  */
    1659        39600 :           bv.get_complexity (),
    1660              :           id, type),
    1661        39600 :   m_bv (bv)
    1662              : {
    1663        39600 :   if (CHECKING_P)
    1664              :     {
    1665              :       /* TODO: should we assert that the type's size matches that
    1666              :          of the bit_vector?  */
    1667              : 
    1668              :       // No nesting:
    1669        39600 :       gcc_assert (!m_bv.dyn_cast_bit_vector_from_svalue ());
    1670              : 
    1671              :       // All-zeros/all-ones of integral type should have been folded to constant
    1672        39600 :       if (auto *tristate_bv = m_bv.dyn_cast_tristate_bit_vector ())
    1673          310 :         if (type && INTEGRAL_TYPE_P (type))
    1674            0 :           gcc_assert (tristate_bv->get_bit_value () == tristate::unknown ());
    1675              :     }
    1676        39600 : }
    1677              : 
    1678              : /* Implementation of svalue::dump_to_pp vfunc for svalue_from_bit_vector.  */
    1679              : 
    1680              : void
    1681         1063 : svalue_from_bit_vector::dump_to_pp (pretty_printer *pp, bool simple) const
    1682              : {
    1683         1063 :   if (simple)
    1684              :     {
    1685         1063 :       pp_string (pp, "SVALUE_FROM_BIT_VECTOR(");
    1686         1063 :       if (get_type ())
    1687              :         {
    1688         1055 :           print_quoted_type (pp, get_type ());
    1689         1055 :           pp_string (pp, ", ");
    1690              :         }
    1691         1063 :       pp_printf (pp, "bit_vector: (%i)", m_bv.get_id ());
    1692         1063 :       pp_character (pp, ')');
    1693              :     }
    1694              :   else
    1695              :     {
    1696            0 :       pp_string (pp, "svalue_from_bit_vector (");
    1697            0 :       if (get_type ())
    1698              :         {
    1699            0 :           print_quoted_type (pp, get_type ());
    1700            0 :           pp_string (pp, ", ");
    1701              :         }
    1702            0 :       pp_printf (pp, "bits: (%i)", m_bv.get_id ());
    1703            0 :       pp_character (pp, ')');
    1704              :     }
    1705         1063 : }
    1706              : 
    1707              : /* Implementation of svalue::print_svalue_for_dump_widget_label vfunc for
    1708              :    svalue_from_bit_vector.  */
    1709              : 
    1710              : void
    1711          699 : svalue_from_bit_vector::
    1712              : print_svalue_for_dump_widget_label (pretty_printer *pp) const
    1713              : {
    1714          699 :   pp_string (pp, "svalue_from_bit_vector");
    1715          699 : }
    1716              : 
    1717              : /* Implementation of svalue::add_dump_widget_children vfunc for
    1718              :    svalue_from_bit_vector.  */
    1719              : 
    1720              : void
    1721          699 : svalue_from_bit_vector::
    1722              : add_dump_widget_children (text_art::tree_widget &w,
    1723              :                           symbolic::node_dump_state &nds) const
    1724              : {
    1725          699 :   svalue::add_dump_widget_children (w, nds);
    1726         1398 :   w.add_child (m_bv.make_dump_widget (nds, "m_bv"));
    1727          699 : }
    1728              : 
    1729              : void
    1730     13620003 : svalue_from_bit_vector::accept_node_visitor (symbolic::node_visitor &v) const
    1731              : {
    1732     13620003 :   if (v.visit_svalue (*this))
    1733     13620003 :     m_bv.accept_node_visitor (v);
    1734     13620003 : }
    1735              : 
    1736              : std::unique_ptr<json::object>
    1737            0 : svalue_from_bit_vector::to_json () const
    1738              : {
    1739            0 :   auto obj = svalue::make_json_obj ("svalue_from_bit_vector");
    1740            0 :   obj->set ("bit_vector", m_bv.to_json ());
    1741            0 :   return obj;
    1742              : }
    1743              : 
    1744              : std::unique_ptr<diagnostics::markup::node>
    1745           12 : svalue_from_bit_vector::
    1746              : make_markup_node (symbolic::markup_context &markup_ctxt) const
    1747              : {
    1748           12 :   return m_bv.make_markup_node (markup_ctxt);
    1749              : }
    1750              : 
    1751              : /* Implementation of svalue::accept vfunc for svalue_from_bit_vector.  */
    1752              : 
    1753              : void
    1754          435 : svalue_from_bit_vector::accept (visitor *v) const
    1755              : {
    1756              :   // FIXME:
    1757              :   // m_bv.accept_node_visitor (v);
    1758              : 
    1759          435 :   v->visit_svalue_from_bit_vector (this);
    1760          435 : }
    1761              : 
    1762              : /* Implementation of svalue::implicitly_live_p vfunc for svalue_from_bit_vector.  */
    1763              : 
    1764              : bool
    1765       486229 : svalue_from_bit_vector::
    1766              : implicitly_live_p (symbolic::liveness_context &liveness_ctxt) const
    1767              : {
    1768       486229 :   return liveness_ctxt.node_live_p (m_bv);
    1769              : }
    1770              : 
    1771              : /* Implementation of svalue::all_zeroes_p for constant_svalue.  */
    1772              : 
    1773              : bool
    1774        82752 : svalue_from_bit_vector::all_zeroes_p () const
    1775              : {
    1776        82752 :   if (auto *ts = m_bv.dyn_cast_tristate_bit_vector ())
    1777           96 :     return ts->get_bit_value ().is_false ();
    1778              :   return false;
    1779              : }
    1780              : 
    1781              : bool
    1782        35362 : svalue_from_bit_vector::maybe_get_value_range_1 (value_range &out) const
    1783              : {
    1784        35362 :   tree type = get_type ();
    1785        35362 :   if (!type_can_have_value_range_p (type))
    1786              :     return false;
    1787              : 
    1788        25511 :   out.set_varying (type);
    1789              : 
    1790        25511 :   irange_bitmask bm;
    1791        25511 :   if (m_bv.maybe_get_irange_bitmask (&bm))
    1792        25495 :     out.update_bitmask (bm);
    1793              : 
    1794        25511 :   return true;
    1795        25511 : }
    1796              : 
    1797              : bool
    1798       147502 : svalue_from_bit_vector::conjured_p () const
    1799              : {
    1800       147502 :   return m_bv.conjured_p ();
    1801              : }
    1802              : 
    1803              : /* class widening_svalue : public svalue.  */
    1804              : 
    1805              : bool
    1806        11475 : widening_svalue::key_t::operator< (const key_t &other) const
    1807              : {
    1808        11475 :   if (int c = cmp_types (m_type, other.m_type))
    1809         2620 :     return c < 0;
    1810         8855 :   if (int c = m_snode->m_id - other.m_snode->m_id)
    1811         5674 :     return c < 0;
    1812         3181 :   if (int c = symbolic::node::cmp_ids (m_base_sval, other.m_base_sval))
    1813          721 :     return c < 0;
    1814         2460 :   if (int c = symbolic::node::cmp_ids (m_iter_sval, other.m_iter_sval))
    1815          148 :     return c < 0;
    1816              :   return false;
    1817              : }
    1818              : 
    1819              : /* Implementation of svalue::dump_to_pp vfunc for widening_svalue.  */
    1820              : 
    1821              : void
    1822           60 : widening_svalue::dump_to_pp (pretty_printer *pp, bool simple) const
    1823              : {
    1824           60 :   if (simple)
    1825              :     {
    1826           60 :       pp_string (pp, "WIDENING(");
    1827           60 :       pp_character (pp, '{');
    1828           60 :       m_snode->print (pp);
    1829           60 :       pp_string (pp, "}, ");
    1830           60 :       m_base_sval->dump_to_pp (pp, simple);
    1831           60 :       pp_string (pp, ", ");
    1832           60 :       m_iter_sval->dump_to_pp (pp, simple);
    1833           60 :       pp_character (pp, ')');
    1834              :     }
    1835              :   else
    1836              :     {
    1837            0 :       pp_string (pp, "widening_svalue (");
    1838            0 :       pp_string (pp, ", ");
    1839            0 :       pp_character (pp, '{');
    1840            0 :       m_snode->print (pp);
    1841            0 :       pp_string (pp, "}, ");
    1842            0 :       m_base_sval->dump_to_pp (pp, simple);
    1843            0 :       pp_string (pp, ", ");
    1844            0 :       m_iter_sval->dump_to_pp (pp, simple);
    1845            0 :       pp_character (pp, ')');
    1846              :     }
    1847           60 : }
    1848              : 
    1849              : /* Implementation of svalue::print_svalue_for_dump_widget_label vfunc for
    1850              :    widening_svalue.  */
    1851              : 
    1852              : void
    1853          647 : widening_svalue::print_svalue_for_dump_widget_label (pretty_printer *pp) const
    1854              : {
    1855          647 :   pp_printf (pp, "widening_svalue at ");
    1856          647 :   m_snode->print (pp);
    1857          647 : }
    1858              : 
    1859              : /* Implementation of svalue::add_dump_widget_children vfunc for
    1860              :    widening_svalue.  */
    1861              : 
    1862              : void
    1863          590 : widening_svalue::
    1864              : add_dump_widget_children (text_art::tree_widget &w,
    1865              :                           symbolic::node_dump_state &nds) const
    1866              : {
    1867          590 :   svalue::add_dump_widget_children (w, nds);
    1868         1180 :   w.add_child (m_base_sval->make_dump_widget (nds, "m_base_sval"));
    1869         1180 :   w.add_child (m_iter_sval->make_dump_widget (nds, "m_iter_sval"));
    1870          590 : }
    1871              : 
    1872              : void
    1873      1022062 : widening_svalue::accept_node_visitor (symbolic::node_visitor &v) const
    1874              : {
    1875      1022062 :   if (v.visit_svalue (*this))
    1876              :     {
    1877      1022062 :       m_base_sval->accept_node_visitor (v);
    1878      1022062 :       m_iter_sval->accept_node_visitor (v);
    1879              :     }
    1880      1022062 : }
    1881              : 
    1882              : std::unique_ptr<json::object>
    1883            0 : widening_svalue::to_json () const
    1884              : {
    1885            0 :   auto obj = svalue::make_json_obj ("widening_svalue");
    1886            0 :   obj->set ("base_sval", m_base_sval->to_json ());
    1887            0 :   obj->set ("iter_sval", m_iter_sval->to_json ());
    1888            0 :   return obj;
    1889              : }
    1890              : 
    1891              : std::unique_ptr<diagnostics::markup::node>
    1892            0 : widening_svalue::make_markup_node (symbolic::markup_context &) const
    1893              : {
    1894            0 :   return diagnostics::markup::make_text_node ("widening_svalue");
    1895              : }
    1896              : 
    1897              : /* Implementation of svalue::accept vfunc for widening_svalue.  */
    1898              : 
    1899              : void
    1900           36 : widening_svalue::accept (visitor *v) const
    1901              : {
    1902           36 :   m_base_sval->accept (v);
    1903           36 :   m_iter_sval->accept (v);
    1904           36 :   v->visit_widening_svalue (this);
    1905           36 : }
    1906              : 
    1907              : /* Attempt to determine in which direction this value is changing
    1908              :    w.r.t. the initial value.  */
    1909              : 
    1910              : enum widening_svalue::direction_t
    1911         1743 : widening_svalue::get_direction () const
    1912              : {
    1913         1743 :   tree base_cst = m_base_sval->maybe_get_constant ();
    1914         1743 :   if (base_cst == NULL_TREE)
    1915              :     return DIR_UNKNOWN;
    1916         1743 :   tree iter_cst = m_iter_sval->maybe_get_constant ();
    1917         1743 :   if (iter_cst == NULL_TREE)
    1918              :     return DIR_UNKNOWN;
    1919              : 
    1920         1743 :   tree iter_gt_base = fold_binary (GT_EXPR, boolean_type_node,
    1921              :                                    iter_cst, base_cst);
    1922         1743 :   if (iter_gt_base == boolean_true_node)
    1923              :     return DIR_ASCENDING;
    1924              : 
    1925          357 :   tree iter_lt_base = fold_binary (LT_EXPR, boolean_type_node,
    1926              :                                    iter_cst, base_cst);
    1927          357 :   if (iter_lt_base == boolean_true_node)
    1928          357 :     return DIR_DESCENDING;
    1929              : 
    1930              :   return DIR_UNKNOWN;
    1931              : }
    1932              : 
    1933              : /* Compare this value against constant RHS_CST.  */
    1934              : 
    1935              : tristate
    1936         2668 : widening_svalue::eval_condition_without_cm (enum tree_code op,
    1937              :                                             tree rhs_cst) const
    1938              : {
    1939         2668 :   tree base_cst = m_base_sval->maybe_get_constant ();
    1940         2668 :   if (base_cst == NULL_TREE)
    1941          933 :     return tristate::TS_UNKNOWN;
    1942         1735 :   tree iter_cst = m_iter_sval->maybe_get_constant ();
    1943         1735 :   if (iter_cst == NULL_TREE)
    1944            0 :     return tristate::TS_UNKNOWN;
    1945              : 
    1946         1735 :   switch (get_direction ())
    1947              :     {
    1948            0 :     default:
    1949            0 :       gcc_unreachable ();
    1950         1378 :     case DIR_ASCENDING:
    1951              :       /* LHS is in [base_cst, +ve infinity), assuming no overflow.  */
    1952         1378 :       switch (op)
    1953              :         {
    1954          254 :         case LE_EXPR:
    1955          254 :         case LT_EXPR:
    1956          254 :           {
    1957              :             /* [BASE, +INF) OP RHS:
    1958              :                This is either true or false at +ve infinity,
    1959              :                It can be true for points X where X OP RHS, so we have either
    1960              :                "false", or "unknown".  */
    1961          254 :             tree base_op_rhs = fold_binary (op, boolean_type_node,
    1962              :                                             base_cst, rhs_cst);
    1963          254 :             if (base_op_rhs == boolean_true_node)
    1964          238 :               return tristate::TS_UNKNOWN;
    1965              :             else
    1966           16 :               return tristate::TS_FALSE;
    1967              :           }
    1968              : 
    1969          870 :         case GE_EXPR:
    1970          870 :         case GT_EXPR:
    1971          870 :           {
    1972              :             /* [BASE, +INF) OP RHS:
    1973              :                This is true at +ve infinity.  It will be true everywhere
    1974              :                in the range if BASE >= RHS.  */
    1975          870 :             tree base_op_rhs = fold_binary (op, boolean_type_node,
    1976              :                                             base_cst, rhs_cst);
    1977          870 :             if (base_op_rhs == boolean_true_node)
    1978           49 :               return tristate::TS_TRUE;
    1979              :             else
    1980          821 :               return tristate::TS_UNKNOWN;
    1981              :           }
    1982              : 
    1983          124 :         case EQ_EXPR:
    1984          124 :           {
    1985              :             /* [BASE, +INF) == RHS:
    1986              :                Could this be true at any point in the range?  If so we
    1987              :                have "unknown", otherwise we have "false".  */
    1988          124 :             tree base_le_rhs = fold_binary (LE_EXPR, boolean_type_node,
    1989              :                                             base_cst, rhs_cst);
    1990          124 :             if (base_le_rhs == boolean_true_node)
    1991          116 :               return tristate::TS_UNKNOWN;
    1992              :             else
    1993            8 :               return tristate::TS_FALSE;
    1994              :           }
    1995              : 
    1996          130 :         case NE_EXPR:
    1997          130 :           {
    1998              :             /* [BASE, +INF) != RHS:
    1999              :                Could we have equality at any point in the range?  If so we
    2000              :                have "unknown", otherwise we have "true".  */
    2001          130 :             tree base_le_rhs = fold_binary (LE_EXPR, boolean_type_node,
    2002              :                                             base_cst, rhs_cst);
    2003          130 :             if (base_le_rhs == boolean_true_node)
    2004          122 :               return tristate::TS_UNKNOWN;
    2005              :             else
    2006            8 :               return tristate::TS_TRUE;
    2007              :           }
    2008              : 
    2009            0 :         default:
    2010            0 :           return tristate::TS_UNKNOWN;
    2011              :         }
    2012              : 
    2013          357 :     case DIR_DESCENDING:
    2014              :       /* LHS is in (-ve infinity, base_cst], assuming no overflow.  */
    2015          357 :       return tristate::TS_UNKNOWN;
    2016              : 
    2017            0 :     case DIR_UNKNOWN:
    2018            0 :       return tristate::TS_UNKNOWN;
    2019              :     }
    2020              : }
    2021              : 
    2022              : /* class placeholder_svalue : public svalue.  */
    2023              : 
    2024              : /* Implementation of svalue::dump_to_pp vfunc for placeholder_svalue.  */
    2025              : 
    2026              : void
    2027            0 : placeholder_svalue::dump_to_pp (pretty_printer *pp, bool simple) const
    2028              : {
    2029            0 :   if (simple)
    2030            0 :     pp_printf (pp, "PLACEHOLDER(%qs)", m_name);
    2031              :   else
    2032            0 :     pp_printf (pp, "placeholder_svalue (%qs)", m_name);
    2033            0 : }
    2034              : 
    2035              : /* Implementation of svalue::print_svalue_for_dump_widget_label vfunc for
    2036              :    placeholder_svalue.  */
    2037              : 
    2038              : void
    2039            0 : placeholder_svalue::print_svalue_for_dump_widget_label (pretty_printer *pp) const
    2040              : {
    2041            0 :   pp_printf (pp, "placeholder_svalue: %qs", m_name);
    2042            0 : }
    2043              : 
    2044              : void
    2045        82136 : placeholder_svalue::accept_node_visitor (symbolic::node_visitor &v) const
    2046              : {
    2047        82136 :   v.visit_svalue (*this);
    2048        82136 : }
    2049              : 
    2050              : std::unique_ptr<json::object>
    2051            0 : placeholder_svalue::to_json () const
    2052              : {
    2053            0 :   auto obj = svalue::make_json_obj ("placeholder_svalue");
    2054            0 :   obj->set_string ("name", m_name);
    2055            0 :   return obj;
    2056              : }
    2057              : 
    2058              : std::unique_ptr<diagnostics::markup::node>
    2059            0 : placeholder_svalue::make_markup_node (symbolic::markup_context &) const
    2060              : {
    2061            0 :   return diagnostics::markup::make_text_node (m_name);
    2062              : }
    2063              : 
    2064              : /* Implementation of svalue::accept vfunc for placeholder_svalue.  */
    2065              : 
    2066              : void
    2067           11 : placeholder_svalue::accept (visitor *v) const
    2068              : {
    2069           11 :   v->visit_placeholder_svalue (this);
    2070           11 : }
    2071              : 
    2072              : /* class unmergeable_svalue : public svalue.  */
    2073              : 
    2074              : /* Implementation of svalue::dump_to_pp vfunc for unmergeable_svalue.  */
    2075              : 
    2076              : void
    2077            0 : unmergeable_svalue::dump_to_pp (pretty_printer *pp, bool simple) const
    2078              : {
    2079            0 :   if (simple)
    2080              :     {
    2081            0 :       pp_string (pp, "UNMERGEABLE(");
    2082            0 :       m_arg->dump_to_pp (pp, simple);
    2083            0 :       pp_character (pp, ')');
    2084              :     }
    2085              :   else
    2086              :     {
    2087            0 :       pp_string (pp, "unmergeable_svalue (");
    2088            0 :       m_arg->dump_to_pp (pp, simple);
    2089            0 :       pp_character (pp, ')');
    2090              :     }
    2091            0 : }
    2092              : 
    2093              : /* Implementation of svalue::print_svalue_for_dump_widget_label vfunc for
    2094              :    unmergeable_svalue.  */
    2095              : 
    2096              : void
    2097            0 : unmergeable_svalue::print_svalue_for_dump_widget_label (pretty_printer *pp) const
    2098              : {
    2099            0 :   pp_printf (pp, "unmergeable_svalue");
    2100            0 : }
    2101              : 
    2102              : /* Implementation of svalue::add_dump_widget_children vfunc for
    2103              :    unmergeable_svalue.  */
    2104              : 
    2105              : void
    2106            0 : unmergeable_svalue::
    2107              : add_dump_widget_children (text_art::tree_widget &w,
    2108              :                           symbolic::node_dump_state &nds) const
    2109              : {
    2110            0 :   svalue::add_dump_widget_children (w, nds);
    2111            0 :   w.add_child (m_arg->make_dump_widget (nds));
    2112            0 : }
    2113              : 
    2114              : void
    2115        83054 : unmergeable_svalue::accept_node_visitor (symbolic::node_visitor &v) const
    2116              : {
    2117        83054 :   if (v.visit_svalue (*this))
    2118        83054 :     m_arg->accept_node_visitor (v);
    2119        83054 : }
    2120              : 
    2121              : std::unique_ptr<json::object>
    2122            0 : unmergeable_svalue::to_json () const
    2123              : {
    2124            0 :   auto obj = svalue::make_json_obj ("unmergeable_svalue");
    2125            0 :   obj->set ("arg", m_arg->to_json ());
    2126            0 :   return obj;
    2127              : }
    2128              : 
    2129              : std::unique_ptr<diagnostics::markup::node>
    2130            0 : unmergeable_svalue::
    2131              : make_markup_node (symbolic::markup_context &markup_ctxt) const
    2132              : {
    2133            0 :   if (markup_ctxt.m_user_facing)
    2134            0 :     return m_arg->make_markup_node (markup_ctxt);
    2135              :   else
    2136            0 :     return diagnostics::markup::make_text_node ("unmergeable_svalue");
    2137              : }
    2138              : 
    2139              : /* Implementation of svalue::accept vfunc for unmergeable_svalue.  */
    2140              : 
    2141              : void
    2142            0 : unmergeable_svalue::accept (visitor *v) const
    2143              : {
    2144            0 :   m_arg->accept (v);
    2145            0 :   v->visit_unmergeable_svalue (this);
    2146            0 : }
    2147              : 
    2148              : /* Implementation of svalue::implicitly_live_p vfunc for unmergeable_svalue.  */
    2149              : 
    2150              : bool
    2151          810 : unmergeable_svalue::
    2152              : implicitly_live_p (symbolic::liveness_context &liveness_ctxt) const
    2153              : {
    2154          810 :   return liveness_ctxt.node_live_p (*get_arg ());
    2155              : }
    2156              : 
    2157              : /* class asm_output_svalue : public svalue.  */
    2158              : 
    2159              : bool
    2160         1025 : asm_output_svalue::key_t::operator< (const key_t &other) const
    2161              : {
    2162         1025 :   if (int c = cmp_types (m_type, other.m_type))
    2163           36 :     return c < 0;
    2164          989 :   if (int c = strcmp (m_asm_string, other.m_asm_string))
    2165           99 :     return c < 0;
    2166          890 :   if (int c = (int)m_output_idx - (int)other.m_output_idx)
    2167          191 :     return c < 0;
    2168          699 :   if (int c = (int)m_num_inputs - (int)other.m_num_inputs)
    2169            0 :     return c < 0;
    2170         1267 :   for (unsigned i = 0; i < m_num_inputs; i++)
    2171         1035 :     if (int c = symbolic::node::cmp_ids (m_input_arr[i], other.m_input_arr[i]))
    2172          467 :       return c < 0;
    2173              :   return false;
    2174              : }
    2175              : 
    2176              : /* Implementation of svalue::dump_to_pp vfunc for asm_output_svalue.  */
    2177              : 
    2178              : void
    2179            6 : asm_output_svalue::dump_to_pp (pretty_printer *pp, bool simple) const
    2180              : {
    2181            6 :   if (simple)
    2182              :     {
    2183            6 :       pp_printf (pp, "ASM_OUTPUT(%qs, %%%i, {",
    2184              :                  get_asm_string (),
    2185              :                  get_output_idx ());
    2186           18 :       for (unsigned i = 0; i < m_num_inputs; i++)
    2187              :         {
    2188            6 :           if (i > 0)
    2189            0 :             pp_string (pp, ", ");
    2190            6 :           dump_input (pp, 0, m_input_arr[i], simple);
    2191              :         }
    2192            6 :       pp_string (pp, "})");
    2193              :     }
    2194              :   else
    2195              :     {
    2196            0 :       pp_printf (pp, "asm_output_svalue (%qs, %%%i, {",
    2197              :                  get_asm_string (),
    2198              :                  get_output_idx ());
    2199            0 :       for (unsigned i = 0; i < m_num_inputs; i++)
    2200              :         {
    2201            0 :           if (i > 0)
    2202            0 :             pp_string (pp, ", ");
    2203            0 :           dump_input (pp, 0, m_input_arr[i], simple);
    2204              :         }
    2205            0 :       pp_string (pp, "})");
    2206              :     }
    2207            6 : }
    2208              : 
    2209              : /* Implementation of svalue::print_svalue_for_dump_widget_label vfunc for
    2210              :    asm_output_svalue.  */
    2211              : 
    2212              : void
    2213            0 : asm_output_svalue::print_svalue_for_dump_widget_label (pretty_printer *pp) const
    2214              : {
    2215            0 :   pp_printf (pp, "asm_output_svalue(%qs, %%%i)",
    2216              :              get_asm_string (),
    2217              :              get_output_idx ());
    2218            0 : }
    2219              : 
    2220              : /* Implementation of svalue::add_dump_widget_children vfunc for
    2221              :    asm_output_svalue.  */
    2222              : 
    2223              : void
    2224            0 : asm_output_svalue::
    2225              : add_dump_widget_children (text_art::tree_widget &w,
    2226              :                           symbolic::node_dump_state &nds) const
    2227              : {
    2228            0 :   svalue::add_dump_widget_children (w, nds);
    2229            0 :   for (unsigned i = 0; i < m_num_inputs; i++)
    2230              :     {
    2231            0 :       pretty_printer pp;
    2232            0 :       pp_printf (&pp, "arg %i", i);
    2233            0 :       w.add_child (m_input_arr[i]->make_dump_widget (nds,
    2234              :                                                      pp_formatted_text (&pp)));
    2235            0 :     }
    2236            0 : }
    2237              : 
    2238              : void
    2239        56513 : asm_output_svalue::accept_node_visitor (symbolic::node_visitor &v) const
    2240              : {
    2241        56513 :   if (v.visit_svalue (*this))
    2242       156212 :     for (unsigned i = 0; i < m_num_inputs; i++)
    2243        99699 :       m_input_arr[i]->accept_node_visitor (v);
    2244        56513 : }
    2245              : 
    2246              : std::unique_ptr<json::object>
    2247            0 : asm_output_svalue::to_json () const
    2248              : {
    2249            0 :   auto obj = svalue::make_json_obj ("asm_output_svalue");
    2250            0 :   obj->set_string ("id_reg", get_asm_string ());
    2251            0 :   obj->set_integer ("output_idx", get_output_idx ());
    2252            0 :   auto arr = std::make_unique<json::array> ();
    2253            0 :   for (unsigned i = 0; i < m_num_inputs; i++)
    2254            0 :     arr->append (m_input_arr[i]->to_json ());
    2255            0 :   obj->set ("input_arr", std::move (arr));
    2256            0 :   return obj;
    2257            0 : }
    2258              : 
    2259              : std::unique_ptr<diagnostics::markup::node>
    2260            0 : asm_output_svalue::
    2261              : make_markup_node (symbolic::markup_context &) const
    2262              : {
    2263            0 :   return diagnostics::markup::make_text_node ("asm_output_svalue");
    2264              : }
    2265              : 
    2266              : /* Subroutine of asm_output_svalue::dump_to_pp.  */
    2267              : 
    2268              : void
    2269            6 : asm_output_svalue::dump_input (pretty_printer *pp,
    2270              :                                unsigned input_idx,
    2271              :                                const svalue *sval,
    2272              :                                bool simple) const
    2273              : {
    2274            6 :   pp_printf (pp, "%%%i: ", input_idx_to_asm_idx (input_idx));
    2275            6 :   sval->dump_to_pp (pp, simple);
    2276            6 : }
    2277              : 
    2278              : /* Convert INPUT_IDX from an index into the array of inputs
    2279              :    into the index of all operands for the asm stmt.  */
    2280              : 
    2281              : unsigned
    2282            6 : asm_output_svalue::input_idx_to_asm_idx (unsigned input_idx) const
    2283              : {
    2284            6 :   return input_idx + m_num_outputs;
    2285              : }
    2286              : 
    2287              : /* Implementation of svalue::accept vfunc for asm_output_svalue.  */
    2288              : 
    2289              : void
    2290            0 : asm_output_svalue::accept (visitor *v) const
    2291              : {
    2292            0 :   for (unsigned i = 0; i < m_num_inputs; i++)
    2293            0 :     m_input_arr[i]->accept (v);
    2294            0 :   v->visit_asm_output_svalue (this);
    2295            0 : }
    2296              : 
    2297              : /* class const_fn_result_svalue : public svalue.  */
    2298              : 
    2299              : bool
    2300         1897 : const_fn_result_svalue::key_t::operator< (const key_t &other) const
    2301              : {
    2302         1897 :   if (int c = cmp_types (m_type, other.m_type))
    2303           14 :     return c < 0;
    2304         1883 :   if (int c = DECL_UID (m_fndecl) - DECL_UID (other.m_fndecl))
    2305          373 :     return c < 0;
    2306         1510 :   if (int c = (int)m_num_inputs - (int)other.m_num_inputs)
    2307           52 :     return c < 0;
    2308         2405 :   for (unsigned i = 0; i < m_num_inputs; i++)
    2309         1431 :     if (int c = symbolic::node::cmp_ids (m_input_arr[i], other.m_input_arr[i]))
    2310          484 :       return c < 0;
    2311              :   return false;
    2312              : }
    2313              : 
    2314              : /* Implementation of svalue::dump_to_pp vfunc for const_fn_result_svalue.  */
    2315              : 
    2316              : void
    2317          368 : const_fn_result_svalue::dump_to_pp (pretty_printer *pp, bool simple) const
    2318              : {
    2319          368 :   if (simple)
    2320              :     {
    2321          368 :       pp_printf (pp, "CONST_FN_RESULT(%qD, {", m_fndecl);
    2322          756 :       for (unsigned i = 0; i < m_num_inputs; i++)
    2323              :         {
    2324           20 :           if (i > 0)
    2325            0 :             pp_string (pp, ", ");
    2326           20 :           dump_input (pp, i, m_input_arr[i], simple);
    2327              :         }
    2328          368 :       pp_string (pp, "})");
    2329              :     }
    2330              :   else
    2331              :     {
    2332            0 :       pp_printf (pp, "CONST_FN_RESULT(%qD, {", m_fndecl);
    2333            0 :       for (unsigned i = 0; i < m_num_inputs; i++)
    2334              :         {
    2335            0 :           if (i > 0)
    2336            0 :             pp_string (pp, ", ");
    2337            0 :           dump_input (pp, i, m_input_arr[i], simple);
    2338              :         }
    2339            0 :       pp_string (pp, "})");
    2340              :     }
    2341          368 : }
    2342              : 
    2343              : /* Implementation of svalue::print_svalue_for_dump_widget_label vfunc for
    2344              :    const_fn_result_svalue.  */
    2345              : 
    2346              : void
    2347         1202 : const_fn_result_svalue::print_svalue_for_dump_widget_label (pretty_printer *pp) const
    2348              : {
    2349         1202 :   pp_printf (pp, "const_fn_result_svalue: %qD", m_fndecl);
    2350         1202 : }
    2351              : 
    2352              : /* Implementation of svalue::add_dump_widget_children vfunc for
    2353              :    const_fn_result_svalue.  */
    2354              : 
    2355              : void
    2356          740 : const_fn_result_svalue::
    2357              : add_dump_widget_children (text_art::tree_widget &w,
    2358              :                           symbolic::node_dump_state &nds) const
    2359              : {
    2360          740 :   svalue::add_dump_widget_children (w, nds);
    2361         1480 :   for (unsigned i = 0; i < m_num_inputs; i++)
    2362              :     {
    2363            0 :       pretty_printer pp;
    2364            0 :       pp_printf (&pp, "arg %i", i);
    2365            0 :       w.add_child (m_input_arr[i]->make_dump_widget (nds,
    2366              :                                                      pp_formatted_text (&pp)));
    2367            0 :     }
    2368          740 : }
    2369              : 
    2370              : void
    2371        78197 : const_fn_result_svalue::accept_node_visitor (symbolic::node_visitor &v) const
    2372              : {
    2373        78197 :   if (v.visit_svalue (*this))
    2374       140842 :     for (unsigned i = 0; i < m_num_inputs; i++)
    2375        62645 :       m_input_arr[i]->accept_node_visitor (v);
    2376        78197 : }
    2377              : 
    2378              : std::unique_ptr<json::object>
    2379            0 : const_fn_result_svalue::to_json () const
    2380              : {
    2381            0 :   auto obj = svalue::make_json_obj ("const_fn_result_svalue");
    2382            0 :   obj->set ("fn_decl", tree_to_json (m_fndecl));
    2383            0 :   auto arr = std::make_unique<json::array> ();
    2384            0 :   for (unsigned i = 0; i < m_num_inputs; i++)
    2385            0 :     arr->append (m_input_arr[i]->to_json ());
    2386            0 :   obj->set ("input_arr", std::move (arr));
    2387            0 :   return obj;
    2388            0 : }
    2389              : 
    2390              : std::unique_ptr<diagnostics::markup::node>
    2391            0 : const_fn_result_svalue::
    2392              : make_markup_node (symbolic::markup_context &) const
    2393              : {
    2394            0 :   return diagnostics::markup::make_text_node ("const_fn_result_svalue");
    2395              : }
    2396              : 
    2397              : /* Subroutine of const_fn_result_svalue::dump_to_pp.  */
    2398              : 
    2399              : void
    2400           20 : const_fn_result_svalue::dump_input (pretty_printer *pp,
    2401              :                                     unsigned input_idx,
    2402              :                                     const svalue *sval,
    2403              :                                     bool simple) const
    2404              : {
    2405           20 :   pp_printf (pp, "arg%i: ", input_idx);
    2406           20 :   sval->dump_to_pp (pp, simple);
    2407           20 : }
    2408              : 
    2409              : /* Implementation of svalue::accept vfunc for const_fn_result_svalue.  */
    2410              : 
    2411              : void
    2412            0 : const_fn_result_svalue::accept (visitor *v) const
    2413              : {
    2414            0 :   for (unsigned i = 0; i < m_num_inputs; i++)
    2415            0 :     m_input_arr[i]->accept (v);
    2416            0 :   v->visit_const_fn_result_svalue (this);
    2417            0 : }
    2418              : 
    2419              : } // namespace ana
    2420              : 
    2421              : #endif /* #if ENABLE_ANALYZER */
        

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