LCOV - code coverage report
Current view: top level - gcc/analyzer - svalue.cc (source / functions) Coverage Total Hit
Test: gcc.info Lines: 71.2 % 1046 745
Test Date: 2026-11-14 16:39:50 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         6357 : svalue::print_dump_widget_label (pretty_printer *pp) const
      59              : {
      60         6357 :   if (get_type ())
      61         6357 :     pp_printf (pp, "%qT: ", get_type ());
      62              : 
      63         6357 :   start_any_dump_color (pp);
      64         6357 :   print_svalue_for_dump_widget_label (pp);
      65         6357 :   end_any_dump_color (pp);
      66         6357 : }
      67              : 
      68              : void
      69         5952 : 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         5952 :   if (get_kind () == SK_CONSTANT)
      74         1724 :     return;
      75              : 
      76         4228 :   value_range out;
      77         4228 :   if (maybe_get_value_range (out))
      78              :     {
      79         1866 :       pretty_printer pp;
      80         1866 :       pp_printf (&pp, "value_range: {");
      81         1866 :       out.print (&pp);
      82         1866 :       pp_string (&pp, "}");
      83         3732 :       w.add_child (text_art::tree_widget::make (nds, &pp));
      84         1866 :     }
      85         4228 : }
      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        49655 : svalue::for_each_svalue (iter_result (*cb) (const svalue &sval,
     224              :                                       void *user_data),
     225              :                          void *user_data) const
     226              : {
     227        49655 :   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      3972591 : svalue::
     236              : has_concrete_size_p (concrete_bit_size *out,
     237              :                      symbolic::scalar_manager<concrete_bit_size> &bit_mgr) const
     238              : {
     239      3972591 :   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      3972509 :   tree type = get_type ();
     272      3972509 :   if (INTEGRAL_TYPE_P (type))
     273              :     {
     274      3778083 :       if (out)
     275      3778083 :         *out = concrete_bit_size (TYPE_PRECISION (type));
     276              :       return true;
     277              :     }
     278              : 
     279       194426 :   tree type_size = TYPE_SIZE (type);
     280       194426 :   if (!type_size)
     281              :     return false;
     282       194426 :   if (TREE_CODE (type_size) != INTEGER_CST)
     283              :     return false;
     284       194426 :   if (out)
     285       194426 :     *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      7873225 : svalue::maybe_get_constant () const
     294              : {
     295      7873225 :   const svalue *sval = unwrap_any_unmergeable ();
     296      7873225 :   if (const constant_svalue *cst_sval = sval->dyn_cast_constant_svalue ())
     297      2675236 :     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     26228998 : svalue::maybe_get_symbolic_pointer () const
     308              : {
     309     26228998 :   if (const pointer_svalue *ptr_sval = dyn_cast_pointer_svalue ())
     310      5824694 :     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     13768185 : svalue::maybe_undo_cast () const
     321              : {
     322     13768185 :   if (const unaryop_svalue *unaryop_sval = dyn_cast_unaryop_svalue ())
     323              :     {
     324      2173935 :       enum tree_code op = unaryop_sval->get_op ();
     325      2173935 :       if (op == NOP_EXPR || op == VIEW_CONVERT_EXPR)
     326      2106711 :         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     10576939 : svalue::unwrap_any_unmergeable () const
     337              : {
     338     10576939 :   if (const unmergeable_svalue *unmergeable = dyn_cast_unmergeable_svalue ())
     339        13492 :     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        59327 : svalue::can_merge_p (const svalue *other,
     348              :                      region_model_manager *mgr,
     349              :                      model_merger *merger) const
     350              : {
     351        59327 :   if (this == other)
     352              :     return this;
     353              : 
     354        59132 :   if (!(get_type () && other->get_type ()))
     355              :     return nullptr;
     356              : 
     357        59132 :   if (!types_compatible_p (get_type (), other->get_type ()))
     358              :     return nullptr;
     359              : 
     360              :   /* Reject attempts to merge unmergeable svalues.  */
     361        59132 :   if ((get_kind () == SK_UNMERGEABLE)
     362        59132 :       || (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        58245 :   if (get_kind () == SK_POISONED
     369        58245 :       || other->get_kind () == SK_POISONED)
     370              :     return nullptr;
     371              : 
     372              :   /* Reject attempts to merge NULL pointers with not-NULL-pointers.  */
     373        58245 :   if (POINTER_TYPE_P (get_type ()))
     374              :     {
     375        26065 :       bool null0 = false;
     376        26065 :       bool null1 = false;
     377        26065 :       if (tree cst0 = maybe_get_constant ())
     378         5700 :         if (zerop (cst0))
     379        26065 :           null0 = true;
     380        26065 :       if (tree cst1 = other->maybe_get_constant ())
     381         6379 :         if (zerop (cst1))
     382        26065 :           null1 = true;
     383        26065 :       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        46180 :   if (!merger->mergeable_svalue_p (this))
     391              :     return nullptr;
     392        46180 :   if (!merger->mergeable_svalue_p (other))
     393              :     return nullptr;
     394              : 
     395              :   /* Handle merger of symbolic pointers.  */
     396        46180 :   if (auto *sym_ptr_this = maybe_get_symbolic_pointer ())
     397         6597 :     if (auto *sym_ptr_other = other->maybe_get_symbolic_pointer ())
     398              :       {
     399         3386 :         auto &this_region = sym_ptr_this->get_base_region ();
     400         3386 :         auto &other_region = sym_ptr_other->get_base_region ();
     401              :         /* Same base region?  Consider merger of offsets.  */
     402         3386 :         if (&this_region == &other_region)
     403              :           {
     404         2383 :             const svalue *this_offset_sval
     405              :               = mgr->get_svalue_from_scalar<concrete_byte_offset>
     406         2383 :                  (ptrdiff_type_node, sym_ptr_this->get_byte_offset ());
     407         2383 :             const svalue *other_offset_sval
     408              :               = mgr->get_svalue_from_scalar<concrete_byte_offset>
     409         2383 :                   (ptrdiff_type_node, sym_ptr_other->get_byte_offset ());
     410         4766 :             if (auto *merged_offset
     411         2383 :                   = this_offset_sval->can_merge_p (other_offset_sval,
     412              :                                                    mgr,
     413              :                                                    merger))
     414              :               {
     415         2383 :                 auto &byte_mgr
     416         2383 :                   = mgr->get_node_manager ().get_scalars ().get_bytes ();
     417         2383 :                 auto &merged_byte_offset
     418         2383 :                   = byte_mgr.get_scalar_from_svalue (*merged_offset);
     419         2383 :                 symbolic::pointer merged_ptr (this_region,
     420         2383 :                                               merged_byte_offset);
     421         2383 :                 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        42817 :   if (maybe_get_constant () && other->maybe_get_constant ())
     437         2153 :     return mgr->get_or_create_widening_svalue (other->get_type (),
     438              :                                                merger->get_supernode (),
     439         2153 :                                                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        40664 :   if (const binop_svalue *binop_sval = dyn_cast_binop_svalue ())
     446         5429 :     if (binop_sval->get_arg0 () == other
     447         1469 :         && binop_sval->get_arg1 ()->get_kind () == SK_CONSTANT
     448         6824 :         && other->get_kind () != SK_WIDENING)
     449          476 :       return mgr->get_or_create_widening_svalue (other->get_type (),
     450              :                                                  merger->get_supernode (),
     451          476 :                                                  other, this);
     452              : 
     453              :   /* Merge: (Widen(existing_val, V), existing_val) -> Widen (existing_val, V)
     454              :      and thus get a fixed point.  */
     455        40188 :   if (const widening_svalue *widen_sval = dyn_cast_widening_svalue ())
     456              :     {
     457         6576 :       if (other == widen_sval->get_base_svalue ())
     458              :         return this;
     459         1269 :       if (other == widen_sval->get_iter_svalue ())
     460              :         return this;
     461              :     }
     462              : 
     463        33968 :   if (const binop_svalue *binop_sval = dyn_cast_binop_svalue ())
     464         4953 :     if (const widening_svalue *widen_arg0
     465         4953 :         = binop_sval->get_arg0 ()->dyn_cast_widening_svalue ())
     466              :       {
     467         3709 :         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         2313 :         if (other == widen_arg0)
     485              :           {
     486          919 :             merger->on_widening_reuse (widen_arg0);
     487          919 :             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         1394 :         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        31164 :   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     30465106 : cmp_csts_same_type (const_tree cst1, const_tree cst2)
     510              : {
     511     30465106 :   gcc_assert (TREE_TYPE (cst1) == TREE_TYPE (cst2));
     512     30465106 :   gcc_assert (TREE_CODE (cst1) == TREE_CODE (cst2));
     513     30465106 :   switch (TREE_CODE (cst1))
     514              :     {
     515            0 :     default:
     516            0 :       gcc_unreachable ();
     517     30461199 :     case INTEGER_CST:
     518     30461199 :       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         2478 :     case REAL_CST:
     536              :       /* Impose an arbitrary but deterministic order.  */
     537         2478 :       return memcmp (TREE_REAL_CST_PTR (cst1),
     538         2478 :                      TREE_REAL_CST_PTR (cst2),
     539         2478 :                      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     99131505 : cmp_types (const_tree a, const_tree b)
     568              : {
     569     99131505 :   int t1 = a ? TYPE_UID (a) : -1;
     570     99131505 :   int t2 = b ? TYPE_UID (b) : -1;
     571     99131505 :   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     20445675 : svalue::cmp_ptr (const svalue *sval1, const svalue *sval2)
     591              : {
     592     20445675 :   return cmp (*sval1, *sval2);
     593              : }
     594              : 
     595              : /* Comparator for use by vec<const svalue *>::qsort.  */
     596              : 
     597              : int
     598      1357297 : svalue::cmp_ptr_ptr (const void *p1, const void *p2)
     599              : {
     600      1357297 :   const svalue *sval1 = *(const svalue * const *)p1;
     601      1357297 :   const svalue *sval2 = *(const svalue * const *)p2;
     602      1357297 :   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       514653 : svalue::all_zeroes_p () const
     610              : {
     611       514653 :   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        20204 : svalue::maybe_get_deref_base_region () const
     619              : {
     620        20204 :   const svalue *iter = this;
     621        20520 :   while (1)
     622              :     {
     623        20362 :       switch (iter->get_kind ())
     624              :         {
     625              :         default:
     626              :           return nullptr;
     627              : 
     628         8791 :         case SK_POINTER:
     629         8791 :           {
     630         8791 :             auto *ptr_sval = as_a<const pointer_svalue *> (iter);
     631         8791 :             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       961482 : svalue::conjured_p () const
     676              : {
     677       961482 :   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        49862 : svalue::derived_from_initial_value_p () const
     685              : {
     686        50083 :   switch (get_kind ())
     687              :     {
     688              :     default:
     689              :       return false;
     690              : 
     691        33903 :     case SK_INITIAL:
     692        33903 :       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         9296 :     case SK_BIT_VECTOR:
     701         9296 :       {
     702         9296 :         const svalue_from_bit_vector &from_bv
     703         9296 :           = *as_a<const svalue_from_bit_vector *> (this);
     704         9296 :         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       243735 : type_can_have_value_range_p (tree type)
     714              : {
     715       243735 :   if (!type)
     716              :     return false;
     717       243735 :   if (irange::supports_p (type))
     718              :     return true;
     719        44574 :   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        81310 : svalue::maybe_get_value_range_1 (value_range &out) const
     730              : {
     731        81310 :   tree type = get_type ();
     732        81310 :   if (!type_can_have_value_range_p (type))
     733              :     return false;
     734              : 
     735        48037 :   out.set_varying (type);
     736        48037 :   return true;
     737              : }
     738              : 
     739              : /* class pointer_svalue : public svalue.  */
     740              : 
     741              : bool
     742     16866727 : pointer_svalue::key_t::operator< (const key_t &other) const
     743              : {
     744     16866727 :   if (int c = cmp_types (m_type, other.m_type))
     745      5786077 :     return c < 0;
     746     11080650 :   if (int c = m_ptr.cmp (other.m_ptr))
     747      5732344 :     return c < 0;
     748              :   return false;
     749              : }
     750              : 
     751              : complexity
     752        44256 : pointer_svalue::key_t::get_complexity () const
     753              : {
     754        44256 :   return complexity::from_pair (m_ptr.get_base_region (),
     755        44256 :                                 m_ptr.get_byte_offset ());
     756              : }
     757              : 
     758              : /* Implementation of svalue::dump_to_pp vfunc for pointer_svalue.  */
     759              : 
     760              : void
     761         1368 : pointer_svalue::dump_to_pp (pretty_printer *pp, bool simple) const
     762              : {
     763         1368 :   if (simple)
     764              :     {
     765         1368 :       pp_string (pp, "&");
     766         1368 :       get_base_region ().dump_to_pp (pp, simple);
     767              : 
     768         1368 :       auto &byte_offset = get_byte_offset ();
     769         1368 :       if (!byte_offset.is_zero_p ())
     770              :         {
     771          480 :           pp_string (pp, " +(bytes) ");
     772          480 :           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         1368 : }
     782              : 
     783              : /* Implementation of svalue::print_svalue_for_dump_widget_label vfunc for
     784              :    pointer_svalue.  */
     785              : 
     786              : void
     787         1217 : pointer_svalue::print_svalue_for_dump_widget_label (pretty_printer *pp) const
     788              : {
     789         1217 :   pp_string (pp, "pointer_svalue:");
     790         1217 : }
     791              : 
     792              : /* Implementation of svalue::add_dump_widget_children vfunc for
     793              :    pointer_svalue.  */
     794              : 
     795              : void
     796         1217 : pointer_svalue::
     797              : add_dump_widget_children (text_art::tree_widget &w,
     798              :                           symbolic::node_dump_state &nds) const
     799              : {
     800         1217 :   svalue::add_dump_widget_children (w, nds);
     801         2434 :   w.add_child (m_ptr.make_dump_widget (nds));
     802         1217 : }
     803              : 
     804              : void
     805      4122910 : pointer_svalue::accept_node_visitor (symbolic::node_visitor &v) const
     806              : {
     807      4122910 :   if (v.visit_svalue (*this))
     808      4122910 :     m_ptr.accept_node_visitor (v);
     809      4122910 : }
     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          119 : pointer_svalue::accept (visitor *v) const
     837              : {
     838          119 :   m_ptr.get_base_region ().accept (v);
     839          119 :   v->visit_pointer_svalue (this);
     840          119 : }
     841              : 
     842              : /* Implementation of svalue::implicitly_live_p vfunc for pointer_svalue.  */
     843              : 
     844              : bool
     845       219285 : 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       219285 :   const region &base_reg = get_base_region ();
     850       219285 :   const store *store = liveness_ctxt.get_model ()->get_store ();
     851       219285 :   if (const binding_cluster *c = store->get_cluster (&base_reg))
     852       180807 :     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       184983 :   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     45177782 : constant_svalue::key_t::operator< (const key_t &other) const
     869              : {
     870     45177782 :   if (int c = cmp_types (m_type, other.m_type))
     871     14713435 :     return c < 0;
     872     30464347 :   if (int c = cmp_types (TREE_TYPE (m_cst), TREE_TYPE (other.m_cst)))
     873            0 :     return c < 0;
     874     30464347 :   gcc_assert (TREE_CODE (m_cst) == TREE_CODE (other.m_cst));
     875     30464347 :   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         8231 : constant_svalue::dump_to_pp (pretty_printer *pp, bool simple) const
     882              : {
     883         8231 :   if (simple)
     884              :     {
     885         8224 :       pp_string (pp, "(");
     886         8224 :       dump_tree (pp, get_type ());
     887         8224 :       pp_string (pp, ")");
     888         8224 :       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         8231 : }
     902              : 
     903              : /* Implementation of svalue::print_svalue_for_dump_widget_label vfunc for
     904              :    constant_svalue.  */
     905              : 
     906              : void
     907         1859 : constant_svalue::print_svalue_for_dump_widget_label (pretty_printer *pp) const
     908              : {
     909         1859 :   pp_printf (pp, "constant_svalue (%qE)", m_cst_expr);
     910         1859 : }
     911              : 
     912              : void
     913     15527311 : constant_svalue::accept_node_visitor (symbolic::node_visitor &v) const
     914              : {
     915     15527311 :   v.visit_svalue (*this);
     916     15527311 : }
     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         7945 : constant_svalue::accept (visitor *v) const
     939              : {
     940         7945 :   v->visit_constant_svalue (this);
     941         7945 : }
     942              : 
     943              : /* Implementation of svalue::implicitly_live_p vfunc for constant_svalue.
     944              :    Constants are implicitly live.  */
     945              : 
     946              : bool
     947        92445 : constant_svalue::implicitly_live_p (symbolic::liveness_context &) const
     948              : {
     949        92445 :   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        10769 : tristate_from_boolean_tree_node (tree expr)
     958              : {
     959        10769 :   gcc_assert (TREE_TYPE (expr) == boolean_type_node);
     960              : 
     961        10769 :   if (expr == boolean_true_node)
     962         7817 :     return tristate (tristate::TS_TRUE);
     963         2952 :   else if (expr == boolean_false_node)
     964         2952 :     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        11010 : constant_svalue::eval_condition (const constant_svalue *lhs,
     975              :                                  enum tree_code op,
     976              :                                  const constant_svalue *rhs)
     977              : {
     978        11010 :   tree lhs_const = lhs->get_constant ();
     979        11010 :   tree rhs_const = rhs->get_constant ();
     980              : 
     981        11010 :   gcc_assert (CONSTANT_CLASS_P (lhs_const));
     982        11010 :   gcc_assert (CONSTANT_CLASS_P (rhs_const));
     983              : 
     984        11010 :   if ((lhs->get_type () == NULL_TREE || rhs->get_type () == NULL_TREE)
     985            0 :       && TREE_CODE (lhs_const) == INTEGER_CST
     986        11010 :       && 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        11010 :   if (types_compatible_p (TREE_TYPE (lhs_const), TREE_TYPE (rhs_const)))
    1000              :     {
    1001        10769 :       tree tree_cmp
    1002        10769 :         = fold_binary (op, boolean_type_node, lhs_const, rhs_const);
    1003        10769 :       tristate ts = tristate_from_boolean_tree_node (tree_cmp);
    1004        10769 :       if (ts.is_known ())
    1005        10769 :         return ts;
    1006              :     }
    1007          241 :   return tristate::TS_UNKNOWN;
    1008              : }
    1009              : 
    1010              : /* Implementation of svalue::all_zeroes_p for constant_svalue.  */
    1011              : 
    1012              : bool
    1013       216468 : constant_svalue::all_zeroes_p () const
    1014              : {
    1015       216468 :   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        72597 : constant_svalue::maybe_get_value_range_1 (value_range &out) const
    1026              : {
    1027        72597 :   if (!type_can_have_value_range_p (get_type ()))
    1028              :     return false;
    1029              : 
    1030        72479 :   out = value_range (m_cst_expr, m_cst_expr);
    1031        72479 :   return true;
    1032              : }
    1033              : 
    1034              : /* class unknown_svalue : public svalue.  */
    1035              : 
    1036              : /* Implementation of svalue::dump_to_pp vfunc for unknown_svalue.  */
    1037              : 
    1038              : void
    1039          107 : unknown_svalue::dump_to_pp (pretty_printer *pp, bool simple) const
    1040              : {
    1041          107 :   if (simple)
    1042              :     {
    1043          107 :       pp_string (pp, "UNKNOWN(");
    1044          107 :       if (get_type ())
    1045          104 :         dump_tree (pp, get_type ());
    1046          107 :       pp_character (pp, ')');
    1047              :     }
    1048              :   else
    1049              :     {
    1050            0 :       pp_string (pp, "unknown_svalue(");
    1051            0 :       if (get_type ())
    1052            0 :         dump_tree (pp, get_type ());
    1053            0 :       pp_character (pp, ')');
    1054              :     }
    1055          107 : }
    1056              : 
    1057              : /* Implementation of svalue::print_svalue_for_dump_widget_label vfunc for
    1058              :    unknown_svalue.  */
    1059              : 
    1060              : void
    1061          290 : unknown_svalue::print_svalue_for_dump_widget_label (pretty_printer *pp) const
    1062              : {
    1063          290 :   pp_printf (pp, "unknown_svalue");
    1064          290 : }
    1065              : 
    1066              : void
    1067       133153 : unknown_svalue::accept_node_visitor (symbolic::node_visitor &v) const
    1068              : {
    1069       133153 :   v.visit_svalue (*this);
    1070       133153 : }
    1071              : 
    1072              : std::unique_ptr<json::object>
    1073            4 : unknown_svalue::to_json () const
    1074              : {
    1075            4 :   return svalue::make_json_obj ("unknown_svalue");
    1076              : }
    1077              : 
    1078              : std::unique_ptr<diagnostics::markup::node>
    1079            5 : unknown_svalue::make_markup_node (symbolic::markup_context &) const
    1080              : {
    1081            5 :   return diagnostics::markup::make_text_node ("unknown");
    1082              : }
    1083              : 
    1084              : /* Implementation of svalue::accept vfunc for unknown_svalue.  */
    1085              : 
    1086              : void
    1087         3443 : unknown_svalue::accept (visitor *v) const
    1088              : {
    1089         3443 :   v->visit_unknown_svalue (this);
    1090         3443 : }
    1091              : 
    1092              : bool
    1093        54274 : unknown_svalue::maybe_get_value_range_1 (value_range &) const
    1094              : {
    1095              :   /* Don't attempt to participate in range ops.  */
    1096        54274 :   return false;
    1097              : }
    1098              : 
    1099              : 
    1100              : /* Get a string for KIND for use in debug dumps.  */
    1101              : 
    1102              : const char *
    1103           40 : poison_kind_to_str (enum poison_kind kind)
    1104              : {
    1105           40 :   switch (kind)
    1106              :     {
    1107            0 :     default:
    1108            0 :       gcc_unreachable ();
    1109              :     case poison_kind::uninit:
    1110              :       return "uninit";
    1111           12 :     case poison_kind::freed:
    1112           12 :       return "freed";
    1113            0 :     case poison_kind::deleted:
    1114            0 :       return "deleted";
    1115            0 :     case poison_kind::popped_stack:
    1116            0 :       return "popped stack";
    1117              :     }
    1118              : }
    1119              : 
    1120              : /* class poisoned_svalue : public svalue.  */
    1121              : 
    1122              : /* Implementation of svalue::dump_to_pp vfunc for poisoned_svalue.  */
    1123              : 
    1124              : void
    1125            0 : poisoned_svalue::dump_to_pp (pretty_printer *pp, bool simple) const
    1126              : {
    1127            0 :   if (simple)
    1128              :     {
    1129            0 :       pp_string (pp, "POISONED(");
    1130            0 :       print_quoted_type (pp, get_type ());
    1131            0 :       pp_printf (pp, ", %s)", poison_kind_to_str (m_kind));
    1132              :     }
    1133              :   else
    1134              :     {
    1135            0 :       pp_string (pp, "poisoned_svalue(");
    1136            0 :       print_quoted_type (pp, get_type ());
    1137            0 :       pp_printf (pp, ", %s)", poison_kind_to_str (m_kind));
    1138              :     }
    1139            0 : }
    1140              : 
    1141              : /* Implementation of svalue::print_svalue_for_dump_widget_label vfunc for
    1142              :    poisoned_svalue.  */
    1143              : 
    1144              : void
    1145            0 : poisoned_svalue::print_svalue_for_dump_widget_label (pretty_printer *pp) const
    1146              : {
    1147            0 :   pp_printf (pp, "poisoned_svalue(%s)", poison_kind_to_str (m_kind));
    1148            0 : }
    1149              : 
    1150              : void
    1151            0 : poisoned_svalue::accept_node_visitor (symbolic::node_visitor &v) const
    1152              : {
    1153            0 :   v.visit_svalue (*this);
    1154            0 : }
    1155              : 
    1156              : std::unique_ptr<json::object>
    1157            0 : poisoned_svalue::to_json () const
    1158              : {
    1159            0 :   auto obj = svalue::make_json_obj ("poisoned_svalue");
    1160            0 :   obj->set_string ("kind", poison_kind_to_str (m_kind));
    1161            0 :   return obj;
    1162              : }
    1163              : 
    1164              : std::unique_ptr<diagnostics::markup::node>
    1165            0 : poisoned_svalue::make_markup_node (symbolic::markup_context &) const
    1166              : {
    1167            0 :   return diagnostics::markup::make_text_node ("poisoned_svalue");
    1168              : }
    1169              : 
    1170              : /* Implementation of svalue::accept vfunc for poisoned_svalue.  */
    1171              : 
    1172              : void
    1173            0 : poisoned_svalue::accept (visitor *v) const
    1174              : {
    1175            0 :   v->visit_poisoned_svalue (this);
    1176            0 : }
    1177              : 
    1178              : /* class setjmp_svalue's implementation is in setjmp-longjmp.cc.  */
    1179              : 
    1180              : /* class initial_svalue : public svalue.  */
    1181              : 
    1182              : /* Implementation of svalue::dump_to_pp vfunc for initial_svalue.  */
    1183              : 
    1184        22281 : initial_svalue::initial_svalue (symbolic::node::id_t id, tree type, const region *reg)
    1185        22281 : : svalue (complexity (reg), id, type), m_reg (reg)
    1186              : {
    1187        22281 :   gcc_assert (m_reg != nullptr);
    1188              : 
    1189              :   /* Must be a base region.  */
    1190        22281 :   gcc_assert (m_reg->base_region_p ());
    1191              : 
    1192              :   /* TODO(once we have a m_node_mgr):
    1193              :      assert that m_reg->region_has_meaningful_size_p (m_node_mgr) ???  */
    1194        22281 : }
    1195              : 
    1196              : void
    1197          460 : initial_svalue::dump_to_pp (pretty_printer *pp, bool simple) const
    1198              : {
    1199          460 :   if (simple)
    1200              :     {
    1201          460 :       pp_string (pp, "INIT_VAL(");
    1202          460 :       m_reg->dump_to_pp (pp, simple);
    1203          460 :       pp_string (pp, ")");
    1204              :     }
    1205              :   else
    1206              :     {
    1207            0 :       pp_string (pp, "initial_svalue(");
    1208            0 :       if (get_type ())
    1209              :         {
    1210            0 :           print_quoted_type (pp, get_type ());
    1211            0 :           pp_string (pp, ", ");
    1212              :         }
    1213            0 :       m_reg->dump_to_pp (pp, simple);
    1214            0 :       pp_string (pp, ")");
    1215              :     }
    1216          460 : }
    1217              : 
    1218              : /* Implementation of svalue::print_svalue_for_dump_widget_label vfunc for
    1219              :    initial_svalue.  */
    1220              : 
    1221              : void
    1222          184 : initial_svalue::print_svalue_for_dump_widget_label (pretty_printer *pp) const
    1223              : {
    1224          184 :   pp_printf (pp, "initial_svalue");
    1225          184 : }
    1226              : 
    1227              : /* Implementation of svalue::add_dump_widget_children vfunc for
    1228              :    initial_svalue.  */
    1229              : 
    1230              : void
    1231          152 : initial_svalue::
    1232              : add_dump_widget_children (text_art::tree_widget &w,
    1233              :                           symbolic::node_dump_state &nds) const
    1234              : {
    1235          152 :   svalue::add_dump_widget_children (w, nds);
    1236          304 :   w.add_child (m_reg->make_dump_widget (nds, "m_reg"));
    1237          152 : }
    1238              : 
    1239              : void
    1240     10581354 : initial_svalue::accept_node_visitor (symbolic::node_visitor &v) const
    1241              : {
    1242     10581354 :   if (v.visit_svalue (*this))
    1243     10581354 :     m_reg->accept_node_visitor (v);
    1244     10581354 : }
    1245              : 
    1246              : std::unique_ptr<json::object>
    1247           73 : initial_svalue::to_json () const
    1248              : {
    1249           73 :   auto obj = svalue::make_json_obj ("initial_svalue");
    1250           73 :   obj->set ("reg", m_reg->to_json ());
    1251           73 :   return obj;
    1252              : }
    1253              : 
    1254              : std::unique_ptr<diagnostics::markup::node>
    1255           34 : initial_svalue::make_markup_node (symbolic::markup_context &markup_ctxt) const
    1256              : {
    1257              :   // TODO: show 'initial_value()' ?
    1258           34 :   return m_reg->make_markup_node (markup_ctxt);
    1259              : }
    1260              : 
    1261              : /* Implementation of svalue::accept vfunc for initial_svalue.  */
    1262              : 
    1263              : void
    1264         1258 : initial_svalue::accept (visitor *v) const
    1265              : {
    1266         1258 :   m_reg->accept (v);
    1267         1258 :   v->visit_initial_svalue (this);
    1268         1258 : }
    1269              : 
    1270              : /* Implementation of svalue::implicitly_live_p vfunc for initial_svalue.  */
    1271              : 
    1272              : bool
    1273      1125038 : initial_svalue::
    1274              : implicitly_live_p (symbolic::liveness_context &liveness_ctxt) const
    1275              : {
    1276              :   /* This svalue may be implicitly live if the region still implicitly
    1277              :      has its initial value and is reachable.  */
    1278              : 
    1279              :   /* It must be a region that exists; we don't want to consider
    1280              :      INIT_VAL(R) as still being implicitly reachable if R is in
    1281              :      a popped stack frame.  */
    1282      1125038 :   auto *model = liveness_ctxt.get_model ();
    1283      1125038 :   if (model->region_exists_p (m_reg))
    1284              :     {
    1285      1110525 :       const svalue *reg_sval = model->get_store_value (m_reg, nullptr);
    1286      1110525 :       if (reg_sval == this)
    1287              :         return true;
    1288              :     }
    1289              : 
    1290              :   /* Assume that the initial values of params for the top level frame
    1291              :      are still live, because (presumably) they're still
    1292              :      live in the external caller.  */
    1293        62640 :   if (initial_value_of_param_p ())
    1294        13561 :     if (const frame_region *frame_reg = m_reg->maybe_get_frame_region ())
    1295        13561 :       if (frame_reg->get_calling_frame () == nullptr)
    1296        13561 :         return true;
    1297              : 
    1298              :   return false;
    1299              : }
    1300              : 
    1301              : /* Return true if this is the initial value of a function parameter.  */
    1302              : 
    1303              : bool
    1304        63087 : initial_svalue::initial_value_of_param_p () const
    1305              : {
    1306        63087 :   if (tree reg_decl = m_reg->maybe_get_decl ())
    1307        61526 :     if (TREE_CODE (reg_decl) == SSA_NAME)
    1308              :       {
    1309        13650 :         tree ssa_name = reg_decl;
    1310        13650 :         if (SSA_NAME_IS_DEFAULT_DEF (ssa_name)
    1311        13650 :             && SSA_NAME_VAR (ssa_name)
    1312        27300 :             && TREE_CODE (SSA_NAME_VAR (ssa_name)) == PARM_DECL)
    1313        13633 :           return true;
    1314              :       }
    1315              :   return false;
    1316              : }
    1317              : 
    1318              : /* class unaryop_svalue : public svalue.  */
    1319              : 
    1320              : bool
    1321       485912 : unaryop_svalue::key_t::operator< (const key_t &other) const
    1322              : {
    1323       485912 :   if (int c = (int)m_op - (int)other.m_op)
    1324         4619 :     return c < 0;
    1325       481293 :   if (int c = cmp_types (m_type, other.m_type))
    1326       114286 :     return c < 0;
    1327       367007 :   if (int c = symbolic::node::cmp_ids (m_arg, other.m_arg))
    1328       192919 :     return c < 0;
    1329              :   return false;
    1330              : }
    1331              : 
    1332              : /* Implementation of svalue::dump_to_pp vfunc for unaryop_svalue.  */
    1333              : 
    1334              : void
    1335          312 : unaryop_svalue::dump_to_pp (pretty_printer *pp, bool simple) const
    1336              : {
    1337          312 :   if (simple)
    1338              :     {
    1339          312 :       if (m_op == VIEW_CONVERT_EXPR || m_op == NOP_EXPR)
    1340              :         {
    1341          311 :           pp_string (pp, "CAST(");
    1342          311 :           dump_tree (pp, get_type ());
    1343          311 :           pp_string (pp, ", ");
    1344          311 :           m_arg->dump_to_pp (pp, simple);
    1345          311 :           pp_character (pp, ')');
    1346              :         }
    1347              :       else
    1348              :         {
    1349            1 :           pp_character (pp, '(');
    1350            1 :           pp_string (pp, get_tree_code_name (m_op));
    1351              :           //pp_string (pp, op_symbol_code (m_op));
    1352            1 :           m_arg->dump_to_pp (pp, simple);
    1353            1 :           pp_character (pp, ')');
    1354              :         }
    1355              :     }
    1356              :   else
    1357              :     {
    1358            0 :       pp_string (pp, "unaryop_svalue (");
    1359            0 :       pp_string (pp, get_tree_code_name (m_op));
    1360            0 :       pp_string (pp, ", ");
    1361            0 :       m_arg->dump_to_pp (pp, simple);
    1362            0 :       pp_character (pp, ')');
    1363              :     }
    1364          312 : }
    1365              : 
    1366              : /* Implementation of svalue::print_svalue_for_dump_widget_label vfunc for
    1367              :    unaryop_svalue.  */
    1368              : 
    1369              : void
    1370          392 : unaryop_svalue::print_svalue_for_dump_widget_label (pretty_printer *pp) const
    1371              : {
    1372          392 :   pp_printf (pp,
    1373              :              "unaryop_svalue(%s)",
    1374          392 :              get_tree_code_name (m_op));
    1375          392 : }
    1376              : 
    1377              : /* Implementation of svalue::add_dump_widget_children vfunc for
    1378              :    unaryop_svalue.  */
    1379              : 
    1380              : void
    1381          381 : unaryop_svalue::
    1382              : add_dump_widget_children (text_art::tree_widget &w,
    1383              :                           symbolic::node_dump_state &nds) const
    1384              : {
    1385          381 :   svalue::add_dump_widget_children (w, nds);
    1386          762 :   w.add_child (m_arg->make_dump_widget (nds));
    1387          381 : }
    1388              : 
    1389              : void
    1390     14324691 : unaryop_svalue::accept_node_visitor (symbolic::node_visitor &v) const
    1391              : {
    1392     14324691 :   if (v.visit_svalue (*this))
    1393     14324691 :     m_arg->accept_node_visitor (v);
    1394     14324691 : }
    1395              : 
    1396              : std::unique_ptr<json::object>
    1397            0 : unaryop_svalue::to_json () const
    1398              : {
    1399            0 :   auto obj = svalue::make_json_obj ("unaryop_svalue");
    1400            0 :   obj->set ("arg", m_arg->to_json ());
    1401            0 :   return obj;
    1402              : }
    1403              : 
    1404              : std::unique_ptr<diagnostics::markup::node>
    1405            0 : unaryop_svalue::make_markup_node (symbolic::markup_context &markup_ctxt) const
    1406              : {
    1407            0 :   gcc_assert (m_op == NOP_EXPR); // FIXME!!!
    1408            0 :   return m_arg->make_markup_node (markup_ctxt);
    1409              : }
    1410              : 
    1411              : /* Implementation of svalue::accept vfunc for unaryop_svalue.  */
    1412              : 
    1413              : void
    1414          740 : unaryop_svalue::accept (visitor *v) const
    1415              : {
    1416          740 :   m_arg->accept (v);
    1417          740 :   v->visit_unaryop_svalue (this);
    1418          740 : }
    1419              : 
    1420              : /* Implementation of svalue::implicitly_live_p vfunc for unaryop_svalue.  */
    1421              : 
    1422              : bool
    1423        82926 : unaryop_svalue::
    1424              : implicitly_live_p (symbolic::liveness_context &liveness_ctxt) const
    1425              : {
    1426        82926 :   return liveness_ctxt.node_live_p (*get_arg ());
    1427              : }
    1428              : 
    1429              : /* Implementation of svalue::maybe_get_value_range_1 for unaryop_svalue.  */
    1430              : 
    1431              : bool
    1432        18449 : unaryop_svalue::maybe_get_value_range_1 (value_range &out) const
    1433              : {
    1434        18449 :   tree type = get_type ();
    1435        18449 :   if (!type_can_have_value_range_p (type))
    1436              :     return false;
    1437              : 
    1438        18297 :   value_range arg_vr;
    1439        18297 :   if (m_arg->maybe_get_value_range (arg_vr))
    1440              :     {
    1441        16653 :       range_op_handler handler (m_op);
    1442        16653 :       if (handler
    1443        33306 :           && handler.operand_check_p (type, arg_vr.type (), type))
    1444              :         {
    1445              :           /* For unary ops, range_op_hander::fold_range expects
    1446              :              a VARYING of the unknown value as the 2nd operand.  */
    1447        16651 :           value_range varying (type);
    1448        16651 :           varying.set_varying (type);
    1449        16651 :           out.set_range_class (type);
    1450        16651 :           if (handler.fold_range (out, type, arg_vr, varying))
    1451        16651 :             return true;
    1452        16651 :         }
    1453              :     }
    1454              :   return false;
    1455        18297 : }
    1456              : 
    1457              : /* class binop_svalue : public svalue.  */
    1458              : 
    1459              : bool
    1460       354562 : binop_svalue::key_t::operator< (const key_t &other) const
    1461              : {
    1462       354562 :   if (int c = (int)m_op - (int)other.m_op)
    1463        87073 :     return c < 0;
    1464       267489 :   if (int c = cmp_types (m_type, other.m_type))
    1465        34534 :     return c < 0;
    1466       232955 :   if (int c = symbolic::node::cmp_ids (m_arg0, other.m_arg0))
    1467       142186 :     return c < 0;
    1468        90769 :   if (int c = symbolic::node::cmp_ids (m_arg1, other.m_arg1))
    1469        18713 :     return c < 0;
    1470              :   return false;
    1471              : }
    1472              : 
    1473              : /* Return whether OP be printed as an infix operator.  */
    1474              : 
    1475              : static bool
    1476          714 : infix_p (enum tree_code op)
    1477              : {
    1478            0 :   switch (op)
    1479              :     {
    1480              :     default:
    1481              :       return true;
    1482            0 :     case MAX_EXPR:
    1483            0 :     case MIN_EXPR:
    1484            0 :       return false;
    1485              :     }
    1486              : }
    1487              : 
    1488              : /* Implementation of svalue::dump_to_pp vfunc for binop_svalue.  */
    1489              : 
    1490              : void
    1491          714 : binop_svalue::dump_to_pp (pretty_printer *pp, bool simple) const
    1492              : {
    1493          714 :   if (simple)
    1494              :     {
    1495          714 :       if (infix_p (m_op))
    1496              :         {
    1497              :           /* Print "(A OP B)".  */
    1498          714 :           pp_character (pp, '(');
    1499          714 :           m_arg0->dump_to_pp (pp, simple);
    1500          714 :           pp_string (pp, op_symbol_code (m_op));
    1501          714 :           m_arg1->dump_to_pp (pp, simple);
    1502          714 :           pp_character (pp, ')');
    1503              :         }
    1504              :       else
    1505              :         {
    1506              :           /* Print "OP(A, B)".  */
    1507            0 :           pp_string (pp, op_symbol_code (m_op));
    1508            0 :           pp_character (pp, '(');
    1509            0 :           m_arg0->dump_to_pp (pp, simple);
    1510            0 :           pp_string (pp, ", ");
    1511            0 :           m_arg1->dump_to_pp (pp, simple);
    1512            0 :           pp_character (pp, ')');
    1513              :         }
    1514              :     }
    1515              :   else
    1516              :     {
    1517            0 :       pp_string (pp, "binop_svalue (");
    1518            0 :       pp_string (pp, get_tree_code_name (m_op));
    1519            0 :       pp_string (pp, ", ");
    1520            0 :       m_arg0->dump_to_pp (pp, simple);
    1521            0 :       pp_string (pp, ", ");
    1522            0 :       m_arg1->dump_to_pp (pp, simple);
    1523            0 :       pp_character (pp, ')');
    1524              :     }
    1525          714 : }
    1526              : 
    1527              : /* Implementation of svalue::print_svalue_for_dump_widget_label vfunc for
    1528              :    binop_svalue.  */
    1529              : 
    1530              : void
    1531          541 : binop_svalue::print_svalue_for_dump_widget_label (pretty_printer *pp) const
    1532              : {
    1533          541 :   pp_printf (pp,
    1534              :              "binop_svalue(%s: %qs)",
    1535          541 :              get_tree_code_name (m_op),
    1536          541 :              op_symbol_code (m_op));
    1537          541 : }
    1538              : 
    1539              : /* Implementation of svalue::add_dump_widget_children vfunc for
    1540              :    binop_svalue.  */
    1541              : 
    1542              : void
    1543          489 : binop_svalue::
    1544              : add_dump_widget_children (text_art::tree_widget &w,
    1545              :                           symbolic::node_dump_state &nds) const
    1546              : {
    1547          489 :   svalue::add_dump_widget_children (w, nds);
    1548          978 :   w.add_child (m_arg0->make_dump_widget (nds));
    1549          978 :   w.add_child (m_arg1->make_dump_widget (nds));
    1550          489 : }
    1551              : 
    1552              : void
    1553     18024521 : binop_svalue::accept_node_visitor (symbolic::node_visitor &v) const
    1554              : {
    1555     18024521 :   if (v.visit_svalue (*this))
    1556              :     {
    1557     18024521 :       m_arg0->accept_node_visitor (v);
    1558     18024521 :       m_arg1->accept_node_visitor (v);
    1559              :     }
    1560     18024521 : }
    1561              : 
    1562              : std::unique_ptr<json::object>
    1563            0 : binop_svalue::to_json () const
    1564              : {
    1565            0 :   auto obj = svalue::make_json_obj ("binop_svalue");
    1566            0 :   obj->set ("arg0", m_arg0->to_json ());
    1567            0 :   obj->set ("arg1", m_arg1->to_json ());
    1568              :   // FIXME: op?
    1569            0 :   return obj;
    1570              : }
    1571              : 
    1572              : std::unique_ptr<diagnostics::markup::node>
    1573            4 : binop_svalue::make_markup_node (symbolic::markup_context &markup_ctxt) const
    1574              : {
    1575            4 :   return std::make_unique<diagnostics::markup::code::infix_binary_op>
    1576            4 :     (m_arg0->make_markup_node (markup_ctxt),
    1577            4 :      op_symbol_code (m_op),
    1578           12 :      m_arg1->make_markup_node (markup_ctxt));
    1579              : }
    1580              : 
    1581              : /* Implementation of svalue::accept vfunc for binop_svalue.  */
    1582              : 
    1583              : void
    1584         1311 : binop_svalue::accept (visitor *v) const
    1585              : {
    1586         1311 :   m_arg0->accept (v);
    1587         1311 :   m_arg1->accept (v);
    1588         1311 :   v->visit_binop_svalue (this);
    1589         1311 : }
    1590              : 
    1591              : /* Implementation of svalue::implicitly_live_p vfunc for binop_svalue.  */
    1592              : 
    1593              : bool
    1594       202719 : binop_svalue::
    1595              : implicitly_live_p (symbolic::liveness_context &liveness_ctxt) const
    1596              : {
    1597       202719 :   return (liveness_ctxt.node_live_p (*get_arg0 ())
    1598       202719 :           && liveness_ctxt.node_live_p (*get_arg1 ()));
    1599              : }
    1600              : 
    1601              : /* Implementation of svalue::maybe_get_value_range_1 for binop_svalue.  */
    1602              : 
    1603              : bool
    1604        37874 : binop_svalue::maybe_get_value_range_1 (value_range &out) const
    1605              : {
    1606        37874 :   tree type = get_type ();
    1607        37874 :   if (!type_can_have_value_range_p (type))
    1608              :     return false;
    1609              : 
    1610              :   /* Avoid cases where we have been sloppy about types.  */
    1611        36646 :   if (!m_arg0->get_type ())
    1612              :     return false;
    1613        36646 :   if (!m_arg1->get_type ())
    1614              :     return false;
    1615        36646 :   if (!range_compatible_p (m_arg0->get_type (), m_arg1->get_type ()))
    1616              :     return false;
    1617              : 
    1618        36292 :   value_range lhs, rhs;
    1619        36292 :   if (m_arg0->maybe_get_value_range (lhs))
    1620        33696 :     if (m_arg1->maybe_get_value_range (rhs))
    1621              :       {
    1622        33640 :         range_op_handler handler (m_op);
    1623        33640 :         if (handler
    1624        67280 :             && handler.operand_check_p (type, lhs.type (), rhs.type ()))
    1625              :           {
    1626        33640 :             out.set_range_class (type);
    1627        33640 :             if (handler.fold_range (out, get_type (), lhs, rhs))
    1628        33640 :               return true;
    1629              :           }
    1630              :       }
    1631              :   return false;
    1632        36292 : }
    1633              : 
    1634              : /* class svalue_from_bit_vector : public svalue.  */
    1635              : 
    1636              : bool
    1637      5858685 : svalue_from_bit_vector::key_t::operator< (const key_t &other) const
    1638              : {
    1639      5858685 :   if (int c = cmp_types (m_type, other.m_type))
    1640      1543877 :     return c < 0;
    1641      4314808 :   if (int c = symbolic::node::cmp_ids (m_bv, other.m_bv))
    1642      2580104 :     return c < 0;
    1643              :   return false;
    1644              : }
    1645              : 
    1646              : /* svalue_from_bit_vector'c ctor.  */
    1647              : 
    1648        39190 : svalue_from_bit_vector::
    1649              : svalue_from_bit_vector (symbolic::node::id_t id,
    1650              :                         tree type,
    1651              :                         const symbolic::bit_vector &bv)
    1652              : : svalue (/* Reuse the complexity of BV rather than adding one to it for now,
    1653              :              to stay closer to pre-symbolic::node behavior.  */
    1654        39190 :           bv.get_complexity (),
    1655              :           id, type),
    1656        39190 :   m_bv (bv)
    1657              : {
    1658        39190 :   if (CHECKING_P)
    1659              :     {
    1660              :       /* TODO: should we assert that the type's size matches that
    1661              :          of the bit_vector?  */
    1662              : 
    1663              :       // No nesting:
    1664        39190 :       gcc_assert (!m_bv.dyn_cast_bit_vector_from_svalue ());
    1665              :     }
    1666        39190 : }
    1667              : 
    1668              : /* Implementation of svalue::dump_to_pp vfunc for svalue_from_bit_vector.  */
    1669              : 
    1670              : void
    1671         1177 : svalue_from_bit_vector::dump_to_pp (pretty_printer *pp, bool simple) const
    1672              : {
    1673         1177 :   if (simple)
    1674              :     {
    1675         1177 :       pp_string (pp, "SVALUE_FROM_BIT_VECTOR(");
    1676         1177 :       if (get_type ())
    1677              :         {
    1678         1169 :           print_quoted_type (pp, get_type ());
    1679         1169 :           pp_string (pp, ", ");
    1680              :         }
    1681         1177 :       pp_printf (pp, "bit_vector: (%i)", m_bv.get_id ());
    1682         1177 :       pp_character (pp, ')');
    1683              :     }
    1684              :   else
    1685              :     {
    1686            0 :       pp_string (pp, "svalue_from_bit_vector (");
    1687            0 :       if (get_type ())
    1688              :         {
    1689            0 :           print_quoted_type (pp, get_type ());
    1690            0 :           pp_string (pp, ", ");
    1691              :         }
    1692            0 :       pp_printf (pp, "bits: (%i)", m_bv.get_id ());
    1693            0 :       pp_character (pp, ')');
    1694              :     }
    1695         1177 : }
    1696              : 
    1697              : /* Implementation of svalue::print_svalue_for_dump_widget_label vfunc for
    1698              :    svalue_from_bit_vector.  */
    1699              : 
    1700              : void
    1701          411 : svalue_from_bit_vector::
    1702              : print_svalue_for_dump_widget_label (pretty_printer *pp) const
    1703              : {
    1704          411 :   pp_string (pp, "svalue_from_bit_vector");
    1705          411 : }
    1706              : 
    1707              : /* Implementation of svalue::add_dump_widget_children vfunc for
    1708              :    svalue_from_bit_vector.  */
    1709              : 
    1710              : void
    1711          411 : svalue_from_bit_vector::
    1712              : add_dump_widget_children (text_art::tree_widget &w,
    1713              :                           symbolic::node_dump_state &nds) const
    1714              : {
    1715          411 :   svalue::add_dump_widget_children (w, nds);
    1716          822 :   w.add_child (m_bv.make_dump_widget (nds, "m_bv"));
    1717          411 : }
    1718              : 
    1719              : void
    1720     13195116 : svalue_from_bit_vector::accept_node_visitor (symbolic::node_visitor &v) const
    1721              : {
    1722     13195116 :   if (v.visit_svalue (*this))
    1723     13195116 :     m_bv.accept_node_visitor (v);
    1724     13195116 : }
    1725              : 
    1726              : std::unique_ptr<json::object>
    1727            0 : svalue_from_bit_vector::to_json () const
    1728              : {
    1729            0 :   auto obj = svalue::make_json_obj ("svalue_from_bit_vector");
    1730            0 :   obj->set ("bit_vector", m_bv.to_json ());
    1731            0 :   return obj;
    1732              : }
    1733              : 
    1734              : std::unique_ptr<diagnostics::markup::node>
    1735           12 : svalue_from_bit_vector::
    1736              : make_markup_node (symbolic::markup_context &markup_ctxt) const
    1737              : {
    1738           12 :   return m_bv.make_markup_node (markup_ctxt);
    1739              : }
    1740              : 
    1741              : /* Implementation of svalue::accept vfunc for svalue_from_bit_vector.  */
    1742              : 
    1743              : void
    1744          363 : svalue_from_bit_vector::accept (visitor *v) const
    1745              : {
    1746              :   // FIXME:
    1747              :   // m_bv.accept_node_visitor (v);
    1748              : 
    1749          363 :   v->visit_svalue_from_bit_vector (this);
    1750          363 : }
    1751              : 
    1752              : /* Implementation of svalue::implicitly_live_p vfunc for svalue_from_bit_vector.  */
    1753              : 
    1754              : bool
    1755       470776 : svalue_from_bit_vector::
    1756              : implicitly_live_p (symbolic::liveness_context &liveness_ctxt) const
    1757              : {
    1758       470776 :   return liveness_ctxt.node_live_p (m_bv);
    1759              : }
    1760              : 
    1761              : /* Implementation of svalue::all_zeroes_p for constant_svalue.  */
    1762              : 
    1763              : bool
    1764        80045 : svalue_from_bit_vector::all_zeroes_p () const
    1765              : {
    1766        80045 :   if (auto *ts = m_bv.dyn_cast_tristate_bit_vector ())
    1767           96 :     return ts->get_bit_value ().is_false ();
    1768              :   return false;
    1769              : }
    1770              : 
    1771              : bool
    1772        33505 : svalue_from_bit_vector::maybe_get_value_range_1 (value_range &out) const
    1773              : {
    1774        33505 :   tree type = get_type ();
    1775        33505 :   if (!type_can_have_value_range_p (type))
    1776              :     return false;
    1777              : 
    1778        23886 :   out.set_varying (type);
    1779              : 
    1780        23886 :   irange_bitmask bm;
    1781        23886 :   if (m_bv.maybe_get_irange_bitmask (&bm))
    1782        23870 :     out.update_bitmask (bm);
    1783              : 
    1784        23886 :   return true;
    1785        23886 : }
    1786              : 
    1787              : bool
    1788       148673 : svalue_from_bit_vector::conjured_p () const
    1789              : {
    1790       148673 :   return m_bv.conjured_p ();
    1791              : }
    1792              : 
    1793              : /* class widening_svalue : public svalue.  */
    1794              : 
    1795              : bool
    1796        10901 : widening_svalue::key_t::operator< (const key_t &other) const
    1797              : {
    1798        10901 :   if (int c = cmp_types (m_type, other.m_type))
    1799         2423 :     return c < 0;
    1800         8478 :   if (int c = m_snode->m_id - other.m_snode->m_id)
    1801         5535 :     return c < 0;
    1802         2943 :   if (int c = symbolic::node::cmp_ids (m_base_sval, other.m_base_sval))
    1803          705 :     return c < 0;
    1804         2238 :   if (int c = symbolic::node::cmp_ids (m_iter_sval, other.m_iter_sval))
    1805          148 :     return c < 0;
    1806              :   return false;
    1807              : }
    1808              : 
    1809              : /* Implementation of svalue::dump_to_pp vfunc for widening_svalue.  */
    1810              : 
    1811              : void
    1812           60 : widening_svalue::dump_to_pp (pretty_printer *pp, bool simple) const
    1813              : {
    1814           60 :   if (simple)
    1815              :     {
    1816           60 :       pp_string (pp, "WIDENING(");
    1817           60 :       pp_character (pp, '{');
    1818           60 :       m_snode->print (pp);
    1819           60 :       pp_string (pp, "}, ");
    1820           60 :       m_base_sval->dump_to_pp (pp, simple);
    1821           60 :       pp_string (pp, ", ");
    1822           60 :       m_iter_sval->dump_to_pp (pp, simple);
    1823           60 :       pp_character (pp, ')');
    1824              :     }
    1825              :   else
    1826              :     {
    1827            0 :       pp_string (pp, "widening_svalue (");
    1828            0 :       pp_string (pp, ", ");
    1829            0 :       pp_character (pp, '{');
    1830            0 :       m_snode->print (pp);
    1831            0 :       pp_string (pp, "}, ");
    1832            0 :       m_base_sval->dump_to_pp (pp, simple);
    1833            0 :       pp_string (pp, ", ");
    1834            0 :       m_iter_sval->dump_to_pp (pp, simple);
    1835            0 :       pp_character (pp, ')');
    1836              :     }
    1837           60 : }
    1838              : 
    1839              : /* Implementation of svalue::print_svalue_for_dump_widget_label vfunc for
    1840              :    widening_svalue.  */
    1841              : 
    1842              : void
    1843          645 : widening_svalue::print_svalue_for_dump_widget_label (pretty_printer *pp) const
    1844              : {
    1845          645 :   pp_printf (pp, "widening_svalue at ");
    1846          645 :   m_snode->print (pp);
    1847          645 : }
    1848              : 
    1849              : /* Implementation of svalue::add_dump_widget_children vfunc for
    1850              :    widening_svalue.  */
    1851              : 
    1852              : void
    1853          590 : widening_svalue::
    1854              : add_dump_widget_children (text_art::tree_widget &w,
    1855              :                           symbolic::node_dump_state &nds) const
    1856              : {
    1857          590 :   svalue::add_dump_widget_children (w, nds);
    1858         1180 :   w.add_child (m_base_sval->make_dump_widget (nds, "m_base_sval"));
    1859         1180 :   w.add_child (m_iter_sval->make_dump_widget (nds, "m_iter_sval"));
    1860          590 : }
    1861              : 
    1862              : void
    1863      1005297 : widening_svalue::accept_node_visitor (symbolic::node_visitor &v) const
    1864              : {
    1865      1005297 :   if (v.visit_svalue (*this))
    1866              :     {
    1867      1005297 :       m_base_sval->accept_node_visitor (v);
    1868      1005297 :       m_iter_sval->accept_node_visitor (v);
    1869              :     }
    1870      1005297 : }
    1871              : 
    1872              : std::unique_ptr<json::object>
    1873            0 : widening_svalue::to_json () const
    1874              : {
    1875            0 :   auto obj = svalue::make_json_obj ("widening_svalue");
    1876            0 :   obj->set ("base_sval", m_base_sval->to_json ());
    1877            0 :   obj->set ("iter_sval", m_iter_sval->to_json ());
    1878            0 :   return obj;
    1879              : }
    1880              : 
    1881              : std::unique_ptr<diagnostics::markup::node>
    1882            0 : widening_svalue::make_markup_node (symbolic::markup_context &) const
    1883              : {
    1884            0 :   return diagnostics::markup::make_text_node ("widening_svalue");
    1885              : }
    1886              : 
    1887              : /* Implementation of svalue::accept vfunc for widening_svalue.  */
    1888              : 
    1889              : void
    1890           36 : widening_svalue::accept (visitor *v) const
    1891              : {
    1892           36 :   m_base_sval->accept (v);
    1893           36 :   m_iter_sval->accept (v);
    1894           36 :   v->visit_widening_svalue (this);
    1895           36 : }
    1896              : 
    1897              : /* Attempt to determine in which direction this value is changing
    1898              :    w.r.t. the initial value.  */
    1899              : 
    1900              : enum widening_svalue::direction_t
    1901         1227 : widening_svalue::get_direction () const
    1902              : {
    1903         1227 :   tree base_cst = m_base_sval->maybe_get_constant ();
    1904         1227 :   if (base_cst == NULL_TREE)
    1905              :     return DIR_UNKNOWN;
    1906         1227 :   tree iter_cst = m_iter_sval->maybe_get_constant ();
    1907         1227 :   if (iter_cst == NULL_TREE)
    1908              :     return DIR_UNKNOWN;
    1909              : 
    1910         1227 :   tree iter_gt_base = fold_binary (GT_EXPR, boolean_type_node,
    1911              :                                    iter_cst, base_cst);
    1912         1227 :   if (iter_gt_base == boolean_true_node)
    1913              :     return DIR_ASCENDING;
    1914              : 
    1915          343 :   tree iter_lt_base = fold_binary (LT_EXPR, boolean_type_node,
    1916              :                                    iter_cst, base_cst);
    1917          343 :   if (iter_lt_base == boolean_true_node)
    1918          343 :     return DIR_DESCENDING;
    1919              : 
    1920              :   return DIR_UNKNOWN;
    1921              : }
    1922              : 
    1923              : /* Compare this value against constant RHS_CST.  */
    1924              : 
    1925              : tristate
    1926         2149 : widening_svalue::eval_condition_without_cm (enum tree_code op,
    1927              :                                             tree rhs_cst) const
    1928              : {
    1929         2149 :   tree base_cst = m_base_sval->maybe_get_constant ();
    1930         2149 :   if (base_cst == NULL_TREE)
    1931          930 :     return tristate::TS_UNKNOWN;
    1932         1219 :   tree iter_cst = m_iter_sval->maybe_get_constant ();
    1933         1219 :   if (iter_cst == NULL_TREE)
    1934            0 :     return tristate::TS_UNKNOWN;
    1935              : 
    1936         1219 :   switch (get_direction ())
    1937              :     {
    1938            0 :     default:
    1939            0 :       gcc_unreachable ();
    1940          876 :     case DIR_ASCENDING:
    1941              :       /* LHS is in [base_cst, +ve infinity), assuming no overflow.  */
    1942          876 :       switch (op)
    1943              :         {
    1944          254 :         case LE_EXPR:
    1945          254 :         case LT_EXPR:
    1946          254 :           {
    1947              :             /* [BASE, +INF) OP RHS:
    1948              :                This is either true or false at +ve infinity,
    1949              :                It can be true for points X where X OP RHS, so we have either
    1950              :                "false", or "unknown".  */
    1951          254 :             tree base_op_rhs = fold_binary (op, boolean_type_node,
    1952              :                                             base_cst, rhs_cst);
    1953          254 :             if (base_op_rhs == boolean_true_node)
    1954          238 :               return tristate::TS_UNKNOWN;
    1955              :             else
    1956           16 :               return tristate::TS_FALSE;
    1957              :           }
    1958              : 
    1959          368 :         case GE_EXPR:
    1960          368 :         case GT_EXPR:
    1961          368 :           {
    1962              :             /* [BASE, +INF) OP RHS:
    1963              :                This is true at +ve infinity.  It will be true everywhere
    1964              :                in the range if BASE >= RHS.  */
    1965          368 :             tree base_op_rhs = fold_binary (op, boolean_type_node,
    1966              :                                             base_cst, rhs_cst);
    1967          368 :             if (base_op_rhs == boolean_true_node)
    1968           49 :               return tristate::TS_TRUE;
    1969              :             else
    1970          319 :               return tristate::TS_UNKNOWN;
    1971              :           }
    1972              : 
    1973          124 :         case EQ_EXPR:
    1974          124 :           {
    1975              :             /* [BASE, +INF) == RHS:
    1976              :                Could this be true at any point in the range?  If so we
    1977              :                have "unknown", otherwise we have "false".  */
    1978          124 :             tree base_le_rhs = fold_binary (LE_EXPR, boolean_type_node,
    1979              :                                             base_cst, rhs_cst);
    1980          124 :             if (base_le_rhs == boolean_true_node)
    1981          116 :               return tristate::TS_UNKNOWN;
    1982              :             else
    1983            8 :               return tristate::TS_FALSE;
    1984              :           }
    1985              : 
    1986          130 :         case NE_EXPR:
    1987          130 :           {
    1988              :             /* [BASE, +INF) != RHS:
    1989              :                Could we have equality at any point in the range?  If so we
    1990              :                have "unknown", otherwise we have "true".  */
    1991          130 :             tree base_le_rhs = fold_binary (LE_EXPR, boolean_type_node,
    1992              :                                             base_cst, rhs_cst);
    1993          130 :             if (base_le_rhs == boolean_true_node)
    1994          122 :               return tristate::TS_UNKNOWN;
    1995              :             else
    1996            8 :               return tristate::TS_TRUE;
    1997              :           }
    1998              : 
    1999            0 :         default:
    2000            0 :           return tristate::TS_UNKNOWN;
    2001              :         }
    2002              : 
    2003          343 :     case DIR_DESCENDING:
    2004              :       /* LHS is in (-ve infinity, base_cst], assuming no overflow.  */
    2005          343 :       return tristate::TS_UNKNOWN;
    2006              : 
    2007            0 :     case DIR_UNKNOWN:
    2008            0 :       return tristate::TS_UNKNOWN;
    2009              :     }
    2010              : }
    2011              : 
    2012              : /* class placeholder_svalue : public svalue.  */
    2013              : 
    2014              : /* Implementation of svalue::dump_to_pp vfunc for placeholder_svalue.  */
    2015              : 
    2016              : void
    2017            0 : placeholder_svalue::dump_to_pp (pretty_printer *pp, bool simple) const
    2018              : {
    2019            0 :   if (simple)
    2020            0 :     pp_printf (pp, "PLACEHOLDER(%qs)", m_name);
    2021              :   else
    2022            0 :     pp_printf (pp, "placeholder_svalue (%qs)", m_name);
    2023            0 : }
    2024              : 
    2025              : /* Implementation of svalue::print_svalue_for_dump_widget_label vfunc for
    2026              :    placeholder_svalue.  */
    2027              : 
    2028              : void
    2029            0 : placeholder_svalue::print_svalue_for_dump_widget_label (pretty_printer *pp) const
    2030              : {
    2031            0 :   pp_printf (pp, "placeholder_svalue: %qs", m_name);
    2032            0 : }
    2033              : 
    2034              : void
    2035        82167 : placeholder_svalue::accept_node_visitor (symbolic::node_visitor &v) const
    2036              : {
    2037        82167 :   v.visit_svalue (*this);
    2038        82167 : }
    2039              : 
    2040              : std::unique_ptr<json::object>
    2041            0 : placeholder_svalue::to_json () const
    2042              : {
    2043            0 :   auto obj = svalue::make_json_obj ("placeholder_svalue");
    2044            0 :   obj->set_string ("name", m_name);
    2045            0 :   return obj;
    2046              : }
    2047              : 
    2048              : std::unique_ptr<diagnostics::markup::node>
    2049            0 : placeholder_svalue::make_markup_node (symbolic::markup_context &) const
    2050              : {
    2051            0 :   return diagnostics::markup::make_text_node (m_name);
    2052              : }
    2053              : 
    2054              : /* Implementation of svalue::accept vfunc for placeholder_svalue.  */
    2055              : 
    2056              : void
    2057           15 : placeholder_svalue::accept (visitor *v) const
    2058              : {
    2059           15 :   v->visit_placeholder_svalue (this);
    2060           15 : }
    2061              : 
    2062              : /* class unmergeable_svalue : public svalue.  */
    2063              : 
    2064              : /* Implementation of svalue::dump_to_pp vfunc for unmergeable_svalue.  */
    2065              : 
    2066              : void
    2067            0 : unmergeable_svalue::dump_to_pp (pretty_printer *pp, bool simple) const
    2068              : {
    2069            0 :   if (simple)
    2070              :     {
    2071            0 :       pp_string (pp, "UNMERGEABLE(");
    2072            0 :       m_arg->dump_to_pp (pp, simple);
    2073            0 :       pp_character (pp, ')');
    2074              :     }
    2075              :   else
    2076              :     {
    2077            0 :       pp_string (pp, "unmergeable_svalue (");
    2078            0 :       m_arg->dump_to_pp (pp, simple);
    2079            0 :       pp_character (pp, ')');
    2080              :     }
    2081            0 : }
    2082              : 
    2083              : /* Implementation of svalue::print_svalue_for_dump_widget_label vfunc for
    2084              :    unmergeable_svalue.  */
    2085              : 
    2086              : void
    2087            0 : unmergeable_svalue::print_svalue_for_dump_widget_label (pretty_printer *pp) const
    2088              : {
    2089            0 :   pp_printf (pp, "unmergeable_svalue");
    2090            0 : }
    2091              : 
    2092              : /* Implementation of svalue::add_dump_widget_children vfunc for
    2093              :    unmergeable_svalue.  */
    2094              : 
    2095              : void
    2096            0 : unmergeable_svalue::
    2097              : add_dump_widget_children (text_art::tree_widget &w,
    2098              :                           symbolic::node_dump_state &nds) const
    2099              : {
    2100            0 :   svalue::add_dump_widget_children (w, nds);
    2101            0 :   w.add_child (m_arg->make_dump_widget (nds));
    2102            0 : }
    2103              : 
    2104              : void
    2105        82519 : unmergeable_svalue::accept_node_visitor (symbolic::node_visitor &v) const
    2106              : {
    2107        82519 :   if (v.visit_svalue (*this))
    2108        82519 :     m_arg->accept_node_visitor (v);
    2109        82519 : }
    2110              : 
    2111              : std::unique_ptr<json::object>
    2112            0 : unmergeable_svalue::to_json () const
    2113              : {
    2114            0 :   auto obj = svalue::make_json_obj ("unmergeable_svalue");
    2115            0 :   obj->set ("arg", m_arg->to_json ());
    2116            0 :   return obj;
    2117              : }
    2118              : 
    2119              : std::unique_ptr<diagnostics::markup::node>
    2120            0 : unmergeable_svalue::
    2121              : make_markup_node (symbolic::markup_context &markup_ctxt) const
    2122              : {
    2123            0 :   if (markup_ctxt.m_user_facing)
    2124            0 :     return m_arg->make_markup_node (markup_ctxt);
    2125              :   else
    2126            0 :     return diagnostics::markup::make_text_node ("unmergeable_svalue");
    2127              : }
    2128              : 
    2129              : /* Implementation of svalue::accept vfunc for unmergeable_svalue.  */
    2130              : 
    2131              : void
    2132            0 : unmergeable_svalue::accept (visitor *v) const
    2133              : {
    2134            0 :   m_arg->accept (v);
    2135            0 :   v->visit_unmergeable_svalue (this);
    2136            0 : }
    2137              : 
    2138              : /* Implementation of svalue::implicitly_live_p vfunc for unmergeable_svalue.  */
    2139              : 
    2140              : bool
    2141          793 : unmergeable_svalue::
    2142              : implicitly_live_p (symbolic::liveness_context &liveness_ctxt) const
    2143              : {
    2144          793 :   return liveness_ctxt.node_live_p (*get_arg ());
    2145              : }
    2146              : 
    2147              : /* class asm_output_svalue : public svalue.  */
    2148              : 
    2149              : bool
    2150         1025 : asm_output_svalue::key_t::operator< (const key_t &other) const
    2151              : {
    2152         1025 :   if (int c = cmp_types (m_type, other.m_type))
    2153           36 :     return c < 0;
    2154          989 :   if (int c = strcmp (m_asm_string, other.m_asm_string))
    2155           99 :     return c < 0;
    2156          890 :   if (int c = (int)m_output_idx - (int)other.m_output_idx)
    2157          191 :     return c < 0;
    2158          699 :   if (int c = (int)m_num_inputs - (int)other.m_num_inputs)
    2159            0 :     return c < 0;
    2160         1267 :   for (unsigned i = 0; i < m_num_inputs; i++)
    2161         1035 :     if (int c = symbolic::node::cmp_ids (m_input_arr[i], other.m_input_arr[i]))
    2162          467 :       return c < 0;
    2163              :   return false;
    2164              : }
    2165              : 
    2166              : /* Implementation of svalue::dump_to_pp vfunc for asm_output_svalue.  */
    2167              : 
    2168              : void
    2169            6 : asm_output_svalue::dump_to_pp (pretty_printer *pp, bool simple) const
    2170              : {
    2171            6 :   if (simple)
    2172              :     {
    2173            6 :       pp_printf (pp, "ASM_OUTPUT(%qs, %%%i, {",
    2174              :                  get_asm_string (),
    2175              :                  get_output_idx ());
    2176           18 :       for (unsigned i = 0; i < m_num_inputs; i++)
    2177              :         {
    2178            6 :           if (i > 0)
    2179            0 :             pp_string (pp, ", ");
    2180            6 :           dump_input (pp, 0, m_input_arr[i], simple);
    2181              :         }
    2182            6 :       pp_string (pp, "})");
    2183              :     }
    2184              :   else
    2185              :     {
    2186            0 :       pp_printf (pp, "asm_output_svalue (%qs, %%%i, {",
    2187              :                  get_asm_string (),
    2188              :                  get_output_idx ());
    2189            0 :       for (unsigned i = 0; i < m_num_inputs; i++)
    2190              :         {
    2191            0 :           if (i > 0)
    2192            0 :             pp_string (pp, ", ");
    2193            0 :           dump_input (pp, 0, m_input_arr[i], simple);
    2194              :         }
    2195            0 :       pp_string (pp, "})");
    2196              :     }
    2197            6 : }
    2198              : 
    2199              : /* Implementation of svalue::print_svalue_for_dump_widget_label vfunc for
    2200              :    asm_output_svalue.  */
    2201              : 
    2202              : void
    2203            0 : asm_output_svalue::print_svalue_for_dump_widget_label (pretty_printer *pp) const
    2204              : {
    2205            0 :   pp_printf (pp, "asm_output_svalue(%qs, %%%i)",
    2206              :              get_asm_string (),
    2207              :              get_output_idx ());
    2208            0 : }
    2209              : 
    2210              : /* Implementation of svalue::add_dump_widget_children vfunc for
    2211              :    asm_output_svalue.  */
    2212              : 
    2213              : void
    2214            0 : asm_output_svalue::
    2215              : add_dump_widget_children (text_art::tree_widget &w,
    2216              :                           symbolic::node_dump_state &nds) const
    2217              : {
    2218            0 :   svalue::add_dump_widget_children (w, nds);
    2219            0 :   for (unsigned i = 0; i < m_num_inputs; i++)
    2220              :     {
    2221            0 :       pretty_printer pp;
    2222            0 :       pp_printf (&pp, "arg %i", i);
    2223            0 :       w.add_child (m_input_arr[i]->make_dump_widget (nds,
    2224              :                                                      pp_formatted_text (&pp)));
    2225            0 :     }
    2226            0 : }
    2227              : 
    2228              : void
    2229        56107 : asm_output_svalue::accept_node_visitor (symbolic::node_visitor &v) const
    2230              : {
    2231        56107 :   if (v.visit_svalue (*this))
    2232       155384 :     for (unsigned i = 0; i < m_num_inputs; i++)
    2233        99277 :       m_input_arr[i]->accept_node_visitor (v);
    2234        56107 : }
    2235              : 
    2236              : std::unique_ptr<json::object>
    2237            0 : asm_output_svalue::to_json () const
    2238              : {
    2239            0 :   auto obj = svalue::make_json_obj ("asm_output_svalue");
    2240            0 :   obj->set_string ("id_reg", get_asm_string ());
    2241            0 :   obj->set_integer ("output_idx", get_output_idx ());
    2242            0 :   auto arr = std::make_unique<json::array> ();
    2243            0 :   for (unsigned i = 0; i < m_num_inputs; i++)
    2244            0 :     arr->append (m_input_arr[i]->to_json ());
    2245            0 :   obj->set ("input_arr", std::move (arr));
    2246            0 :   return obj;
    2247            0 : }
    2248              : 
    2249              : std::unique_ptr<diagnostics::markup::node>
    2250            0 : asm_output_svalue::
    2251              : make_markup_node (symbolic::markup_context &) const
    2252              : {
    2253            0 :   return diagnostics::markup::make_text_node ("asm_output_svalue");
    2254              : }
    2255              : 
    2256              : /* Subroutine of asm_output_svalue::dump_to_pp.  */
    2257              : 
    2258              : void
    2259            6 : asm_output_svalue::dump_input (pretty_printer *pp,
    2260              :                                unsigned input_idx,
    2261              :                                const svalue *sval,
    2262              :                                bool simple) const
    2263              : {
    2264            6 :   pp_printf (pp, "%%%i: ", input_idx_to_asm_idx (input_idx));
    2265            6 :   sval->dump_to_pp (pp, simple);
    2266            6 : }
    2267              : 
    2268              : /* Convert INPUT_IDX from an index into the array of inputs
    2269              :    into the index of all operands for the asm stmt.  */
    2270              : 
    2271              : unsigned
    2272            6 : asm_output_svalue::input_idx_to_asm_idx (unsigned input_idx) const
    2273              : {
    2274            6 :   return input_idx + m_num_outputs;
    2275              : }
    2276              : 
    2277              : /* Implementation of svalue::accept vfunc for asm_output_svalue.  */
    2278              : 
    2279              : void
    2280            0 : asm_output_svalue::accept (visitor *v) const
    2281              : {
    2282            0 :   for (unsigned i = 0; i < m_num_inputs; i++)
    2283            0 :     m_input_arr[i]->accept (v);
    2284            0 :   v->visit_asm_output_svalue (this);
    2285            0 : }
    2286              : 
    2287              : /* class const_fn_result_svalue : public svalue.  */
    2288              : 
    2289              : bool
    2290         1885 : const_fn_result_svalue::key_t::operator< (const key_t &other) const
    2291              : {
    2292         1885 :   if (int c = cmp_types (m_type, other.m_type))
    2293           14 :     return c < 0;
    2294         1871 :   if (int c = DECL_UID (m_fndecl) - DECL_UID (other.m_fndecl))
    2295          373 :     return c < 0;
    2296         1498 :   if (int c = (int)m_num_inputs - (int)other.m_num_inputs)
    2297           52 :     return c < 0;
    2298         2377 :   for (unsigned i = 0; i < m_num_inputs; i++)
    2299         1415 :     if (int c = symbolic::node::cmp_ids (m_input_arr[i], other.m_input_arr[i]))
    2300          484 :       return c < 0;
    2301              :   return false;
    2302              : }
    2303              : 
    2304              : /* Implementation of svalue::dump_to_pp vfunc for const_fn_result_svalue.  */
    2305              : 
    2306              : void
    2307          697 : const_fn_result_svalue::dump_to_pp (pretty_printer *pp, bool simple) const
    2308              : {
    2309          697 :   if (simple)
    2310              :     {
    2311          697 :       pp_printf (pp, "CONST_FN_RESULT(%qD, {", m_fndecl);
    2312         1414 :       for (unsigned i = 0; i < m_num_inputs; i++)
    2313              :         {
    2314           20 :           if (i > 0)
    2315            0 :             pp_string (pp, ", ");
    2316           20 :           dump_input (pp, i, m_input_arr[i], simple);
    2317              :         }
    2318          697 :       pp_string (pp, "})");
    2319              :     }
    2320              :   else
    2321              :     {
    2322            0 :       pp_printf (pp, "CONST_FN_RESULT(%qD, {", m_fndecl);
    2323            0 :       for (unsigned i = 0; i < m_num_inputs; i++)
    2324              :         {
    2325            0 :           if (i > 0)
    2326            0 :             pp_string (pp, ", ");
    2327            0 :           dump_input (pp, i, m_input_arr[i], simple);
    2328              :         }
    2329            0 :       pp_string (pp, "})");
    2330              :     }
    2331          697 : }
    2332              : 
    2333              : /* Implementation of svalue::print_svalue_for_dump_widget_label vfunc for
    2334              :    const_fn_result_svalue.  */
    2335              : 
    2336              : void
    2337          818 : const_fn_result_svalue::print_svalue_for_dump_widget_label (pretty_printer *pp) const
    2338              : {
    2339          818 :   pp_printf (pp, "const_fn_result_svalue: %qD", m_fndecl);
    2340          818 : }
    2341              : 
    2342              : /* Implementation of svalue::add_dump_widget_children vfunc for
    2343              :    const_fn_result_svalue.  */
    2344              : 
    2345              : void
    2346          698 : const_fn_result_svalue::
    2347              : add_dump_widget_children (text_art::tree_widget &w,
    2348              :                           symbolic::node_dump_state &nds) const
    2349              : {
    2350          698 :   svalue::add_dump_widget_children (w, nds);
    2351         1396 :   for (unsigned i = 0; i < m_num_inputs; i++)
    2352              :     {
    2353            0 :       pretty_printer pp;
    2354            0 :       pp_printf (&pp, "arg %i", i);
    2355            0 :       w.add_child (m_input_arr[i]->make_dump_widget (nds,
    2356              :                                                      pp_formatted_text (&pp)));
    2357            0 :     }
    2358          698 : }
    2359              : 
    2360              : void
    2361        77649 : const_fn_result_svalue::accept_node_visitor (symbolic::node_visitor &v) const
    2362              : {
    2363        77649 :   if (v.visit_svalue (*this))
    2364       139452 :     for (unsigned i = 0; i < m_num_inputs; i++)
    2365        61803 :       m_input_arr[i]->accept_node_visitor (v);
    2366        77649 : }
    2367              : 
    2368              : std::unique_ptr<json::object>
    2369            0 : const_fn_result_svalue::to_json () const
    2370              : {
    2371            0 :   auto obj = svalue::make_json_obj ("const_fn_result_svalue");
    2372            0 :   obj->set ("fn_decl", tree_to_json (m_fndecl));
    2373            0 :   auto arr = std::make_unique<json::array> ();
    2374            0 :   for (unsigned i = 0; i < m_num_inputs; i++)
    2375            0 :     arr->append (m_input_arr[i]->to_json ());
    2376            0 :   obj->set ("input_arr", std::move (arr));
    2377            0 :   return obj;
    2378            0 : }
    2379              : 
    2380              : std::unique_ptr<diagnostics::markup::node>
    2381            0 : const_fn_result_svalue::
    2382              : make_markup_node (symbolic::markup_context &) const
    2383              : {
    2384            0 :   return diagnostics::markup::make_text_node ("const_fn_result_svalue");
    2385              : }
    2386              : 
    2387              : /* Subroutine of const_fn_result_svalue::dump_to_pp.  */
    2388              : 
    2389              : void
    2390           20 : const_fn_result_svalue::dump_input (pretty_printer *pp,
    2391              :                                     unsigned input_idx,
    2392              :                                     const svalue *sval,
    2393              :                                     bool simple) const
    2394              : {
    2395           20 :   pp_printf (pp, "arg%i: ", input_idx);
    2396           20 :   sval->dump_to_pp (pp, simple);
    2397           20 : }
    2398              : 
    2399              : /* Implementation of svalue::accept vfunc for const_fn_result_svalue.  */
    2400              : 
    2401              : void
    2402            0 : const_fn_result_svalue::accept (visitor *v) const
    2403              : {
    2404            0 :   for (unsigned i = 0; i < m_num_inputs; i++)
    2405            0 :     m_input_arr[i]->accept (v);
    2406            0 :   v->visit_const_fn_result_svalue (this);
    2407            0 : }
    2408              : 
    2409              : } // namespace ana
    2410              : 
    2411              : #endif /* #if ENABLE_ANALYZER */
        

Generated by: LCOV version 2.5.0-beta

LCOV profile is generated on x86_64 machine using following configure options: configure --disable-bootstrap --enable-coverage=opt --enable-languages=c,c++,fortran,go,jit,lto,rust,m2 --enable-host-shared. GCC test suite is run with the built compiler.