LCOV - code coverage report
Current view: top level - gcc/analyzer - svalue.h (source / functions) Coverage Total Hit
Test: gcc.info Lines: 92.3 % 194 179
Test Date: 2026-11-14 16:39:50 Functions: 87.3 % 55 48
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              : #ifndef GCC_ANALYZER_SVALUE_H
      22              : #define GCC_ANALYZER_SVALUE_H
      23              : 
      24              : #include "analyzer/symbolic-nodes.h"
      25              : #include "analyzer/store.h"
      26              : #include "analyzer/program-point.h"
      27              : #include "analyzer/symbolic-pointers.h"
      28              : 
      29              : using namespace ana;
      30              : 
      31              : namespace ana {
      32              : 
      33              : /* An enum for discriminating between the different concrete subclasses
      34              :    of svalue.  */
      35              : 
      36              : enum svalue_kind
      37              : {
      38              :   SK_POINTER,
      39              :   SK_CONSTANT,
      40              :   SK_UNKNOWN,
      41              :   SK_POISONED,
      42              :   SK_SETJMP,
      43              :   SK_INITIAL,
      44              :   SK_UNARYOP,
      45              :   SK_BINOP,
      46              :   SK_BIT_VECTOR,
      47              :   SK_UNMERGEABLE,
      48              :   SK_PLACEHOLDER,
      49              :   SK_WIDENING,
      50              :   SK_ASM_OUTPUT,
      51              :   SK_CONST_FN_RESULT
      52              : };
      53              : 
      54              : /* svalue and its subclasses.
      55              : 
      56              :    The class hierarchy looks like this (using indentation to show
      57              :    inheritance, and with svalue_kinds shown for the concrete subclasses):
      58              : 
      59              :    svalue
      60              :      pointer_svalue (SK_POINTER): a symbolic::pointer with a type
      61              :      constant_svalue (SK_CONSTANT): a constant
      62              :      unknown_svalue (SK_UNKNOWN): an unknowable value
      63              :      poisoned_svalue (SK_POISONED): a unusable value (undefined)
      64              :      setjmp_svalue (SK_SETJMP): a setjmp/longjmp buffer
      65              :      initial_svalue (SK_INITIAL): the initial value of a region
      66              :      unaryop_svalue (SK_UNARYOP): unary operation on another svalue
      67              :      binop_svalue (SK_BINOP): binary operation on two svalues
      68              :      svalue_from_bit_vector (SK_BIT_VECTOR): the interpretation of a symbolic bit_vector as a type
      69              :      unmergeable_svalue (SK_UNMERGEABLE): a value that is so interesting
      70              :        from a control-flow perspective that it can inhibit state-merging
      71              :      placeholder_svalue (SK_PLACEHOLDER): for use in selftests.
      72              :      widening_svalue (SK_WIDENING): a merger of two svalues (possibly
      73              :        in an iteration).
      74              :      asm_output_svalue (SK_ASM_OUTPUT): an output from a deterministic
      75              :        asm stmt.
      76              :      const_fn_result_svalue (SK_CONST_FN_RESULT): the return value from
      77              :        a function with __attribute((const)) for given inputs.  */
      78              : 
      79              : /* An abstract base class representing a value held by a region of memory.  */
      80              : 
      81              : class svalue : public symbolic::value_node
      82              : {
      83              : public:
      84           76 :   virtual ~svalue () {}
      85              : 
      86     21329536 :   tree get_type () const { return m_type; }
      87              : 
      88              :   const svalue *
      89     20207719 :   dyn_cast_svalue () const final override { return this; }
      90              : 
      91              :   virtual enum svalue_kind get_kind () const = 0;
      92              : 
      93              :   void print (const region_model &model,
      94              :               pretty_printer *pp) const;
      95              : 
      96              :   virtual void dump_to_pp (pretty_printer *pp, bool simple) const = 0;
      97              :   void dump () const;
      98              :   void dump (bool simple) const;
      99              : 
     100              :   void
     101              :   print_dump_widget_label (pretty_printer *pp) const final override;
     102              : 
     103              :   virtual void
     104              :   print_svalue_for_dump_widget_label (pretty_printer *pp) const = 0;
     105              : 
     106              :   void
     107              :   add_dump_widget_children (text_art::tree_widget &w,
     108              :                             symbolic::node_dump_state &nds) const override;
     109              : 
     110              :   const char *
     111        31745 :   get_any_dump_color () const override { return "svalue"; }
     112              : 
     113              :   label_text get_desc (bool simple=true) const;
     114              : 
     115              :   virtual const pointer_svalue *
     116     20482231 :   dyn_cast_pointer_svalue () const { return nullptr; }
     117              :   virtual const constant_svalue *
     118      5367540 :   dyn_cast_constant_svalue () const { return nullptr; }
     119              :   virtual const poisoned_svalue *
     120       274256 :   dyn_cast_poisoned_svalue () const { return nullptr; }
     121              :   virtual const setjmp_svalue *
     122           38 :   dyn_cast_setjmp_svalue () const { return nullptr; }
     123              :   virtual const initial_svalue *
     124      1589011 :   dyn_cast_initial_svalue () const { return nullptr; }
     125              :   virtual const unaryop_svalue *
     126     11680244 :   dyn_cast_unaryop_svalue () const { return nullptr; }
     127              :   virtual const binop_svalue *
     128       513503 :   dyn_cast_binop_svalue () const { return nullptr; }
     129              :   virtual const svalue_from_bit_vector *
     130     20080944 :   dyn_cast_svalue_from_bit_vector () const { return nullptr; }
     131              :   virtual const unmergeable_svalue *
     132     10563447 :   dyn_cast_unmergeable_svalue () const { return nullptr; }
     133              :   virtual const widening_svalue *
     134       210406 :   dyn_cast_widening_svalue () const { return nullptr; }
     135              :   virtual const asm_output_svalue *
     136            0 :   dyn_cast_asm_output_svalue () const { return nullptr; }
     137              :   virtual const const_fn_result_svalue *
     138            0 :   dyn_cast_const_fn_result_svalue () const { return nullptr; }
     139              : 
     140              :   iter_result
     141              :   for_each_svalue (iter_result (*cb) (const svalue &sval,
     142              :                                       void *user_data),
     143              :                    void *user_data) const final override;
     144              : 
     145              :   bool
     146              :   has_concrete_size_p (concrete_bit_size *out,
     147              :                        symbolic::scalar_manager<concrete_bit_size> &bit_mgr) const;
     148              : 
     149              :   tree maybe_get_constant () const;
     150              :   const symbolic::pointer *maybe_get_symbolic_pointer () const;
     151              :   const svalue *maybe_undo_cast () const;
     152              :   const svalue *unwrap_any_unmergeable () const;
     153              : 
     154              :   const svalue *can_merge_p (const svalue *other,
     155              :                               region_model_manager *mgr,
     156              :                               model_merger *merger) const;
     157              : 
     158              :   virtual void accept (visitor *v) const  = 0;
     159              : 
     160              :   static int cmp_ptr (const svalue *, const svalue *);
     161              :   static int cmp_ptr_ptr (const void *, const void *);
     162              : 
     163              :   virtual bool all_zeroes_p () const;
     164              : 
     165              :   /* Can this svalue be involved in constraints and sm-state?
     166              :      Most can, but UNKNOWN and POISONED svalues are singletons
     167              :      per-type and thus it's meaningless for them to "have state".  */
     168      1617465 :   virtual bool can_have_associated_state_p () const { return true; }
     169              : 
     170              :   const region *maybe_get_deref_base_region () const;
     171              : 
     172              :   bool maybe_print_for_user (pretty_printer *pp,
     173              :                              const region_model &model,
     174              :                              const svalue *outer_sval = nullptr) const;
     175              : 
     176              :   tree maybe_get_type_from_typeinfo () const;
     177              : 
     178              :   /* If we can get a value_range for this svalue, write it to OUT
     179              :      and return true.  Otherwise return false.  */
     180              :   bool
     181       298009 :   maybe_get_value_range (value_range &out) const
     182              :   {
     183       298009 :     if (maybe_get_value_range_1 (out))
     184              :       {
     185       194693 :         gcc_assert (!out.undefined_p ());
     186              :         return true;
     187              :       }
     188              :     return false;
     189              :   }
     190              : 
     191              :   virtual bool conjured_p () const;
     192              : 
     193              :   bool derived_from_initial_value_p () const;
     194              : 
     195              :  protected:
     196      1313732 :   svalue (complexity c, symbolic::node::id_t id, tree type)
     197        75508 :   : value_node (c, id), m_type (type)
     198              :   {}
     199              : 
     200              :   void print_svalue_node_label (pretty_printer *pp) const;
     201              : 
     202              :   std::unique_ptr<json::object>
     203              :   make_json_obj (const char *type_name) const;
     204              : 
     205              :  private:
     206              :   virtual bool
     207              :   maybe_get_value_range_1 (value_range &out) const;
     208              : 
     209              :   tree m_type;
     210              : };
     211              : 
     212              : /* Concrete subclass of svalue representing a symbolic::pointer with a type.
     213              : 
     214              :    Consolidation/canonicalization:
     215              :    - the pointer must not be a zero-offset pointer to *SYMBOLIC_REGION (PTR);
     216              :      we fold such cases to PTR (perhaps with a cast).  */
     217              : 
     218              : class pointer_svalue : public svalue
     219              : {
     220              : public:
     221              :   /* A support class for uniquifying instances of pointer_svalue.  */
     222              :   struct key_t
     223              :   {
     224      2718409 :     key_t (tree type, symbolic::pointer ptr)
     225      2718409 :     : m_type (type), m_ptr (ptr)
     226              :     {}
     227              : 
     228              :     bool operator< (const key_t &other) const;
     229              :     bool operator== (const key_t &other) const
     230              :     {
     231              :       return (m_type == other.m_type && m_ptr == other.m_ptr);
     232              :     }
     233              : 
     234              :     complexity
     235              :     get_complexity () const;
     236              : 
     237              :     tree m_type;
     238              :     symbolic::pointer m_ptr;
     239              :   };
     240              : 
     241        44256 :   pointer_svalue (symbolic::node::id_t id, key_t k)
     242              :   : svalue (k.get_complexity (), id, k.m_type),
     243        44256 :     m_ptr (k.m_ptr)
     244              :   {
     245        44256 :   }
     246              : 
     247      3037569 :   enum svalue_kind get_kind () const final override { return SK_POINTER; }
     248              :   const pointer_svalue *
     249      5838025 :   dyn_cast_pointer_svalue () const final override { return this; }
     250              : 
     251              :   void dump_to_pp (pretty_printer *pp, bool simple) const final override;
     252              : 
     253              :   void
     254              :   print_svalue_for_dump_widget_label (pretty_printer *pp) const final override;
     255              :   void
     256              :   add_dump_widget_children (text_art::tree_widget &w,
     257              :                             symbolic::node_dump_state &nds) const final override;
     258              :   void
     259              :   accept_node_visitor (symbolic::node_visitor &v) const final override;
     260              : 
     261              :   std::unique_ptr<json::object>
     262              :   to_json () const final override;
     263              : 
     264              :   std::unique_ptr<diagnostics::markup::node>
     265              :   make_markup_node (symbolic::markup_context &markup_ctxt) const final override;
     266              : 
     267              :   void accept (visitor *v) const final override;
     268              :   bool implicitly_live_p (symbolic::liveness_context &) const final override;
     269              : 
     270              :   const symbolic::pointer &
     271      5824903 :   get_symbolic_pointer () const { return m_ptr; }
     272              : 
     273              :   const region &
     274       229444 :   get_base_region () const { return m_ptr.get_base_region (); }
     275              : 
     276              :   const symbolic_byte_offset &
     277         1368 :   get_byte_offset () const { return m_ptr.get_byte_offset (); }
     278              : 
     279              :   bool
     280              :   zero_offset_p () const { return m_ptr.zero_offset_p (); }
     281              : 
     282        12177 :   bool non_null_p () const { return m_ptr.non_null_p (); }
     283              : 
     284              :  private:
     285              :   symbolic::pointer m_ptr;
     286              : };
     287              : 
     288              : } // namespace ana
     289              : 
     290              : template <>
     291              : template <>
     292              : inline bool
     293         8932 : is_a_helper <const pointer_svalue *>::test (const svalue *sval)
     294              : {
     295         8932 :   return sval->get_kind () == SK_POINTER;
     296              : }
     297              : 
     298              : namespace ana {
     299              : 
     300              : /* Concrete subclass of svalue representing a specific constant value.
     301              :    The type will either be the same as that of the underlying tree constant,
     302              :    or NULL_TREE indicating the constant is intended to be "typeless".  */
     303              : 
     304              : class constant_svalue : public svalue
     305              : {
     306              : public:
     307              :   /* A support class for uniquifying instances of constant_svalue.  */
     308              :   struct key_t
     309              :   {
     310      2642353 :     key_t (tree type, tree cst)
     311      2642353 :     : m_type (type), m_cst (cst)
     312              :     {}
     313              : 
     314              :     bool
     315              :     operator< (const key_t &other) const;
     316              :     bool operator== (const key_t &other) const
     317              :     {
     318              :       return (m_type == other.m_type && m_cst == other.m_cst);
     319              :     }
     320              : 
     321              :     tree m_type;
     322              :     tree m_cst;
     323              :   };
     324              : 
     325      1168695 :   constant_svalue (symbolic::node::id_t id, tree type, tree cst_expr)
     326      1168695 :   : svalue (complexity (1, 1), id, type),
     327      1168695 :     m_cst_expr (cst_expr)
     328              :   {
     329      1168695 :     gcc_assert (cst_expr);
     330      1168695 :     gcc_assert (CONSTANT_CLASS_P (cst_expr));
     331      1168695 :     gcc_assert (type == TREE_TYPE (cst_expr) || type == NULL_TREE);
     332      1168695 :   }
     333              : 
     334      6822437 :   enum svalue_kind get_kind () const final override { return SK_CONSTANT; }
     335              :   const constant_svalue *
     336      2850305 :   dyn_cast_constant_svalue () const final override { return this; }
     337              : 
     338              :   void dump_to_pp (pretty_printer *pp, bool simple) const final override;
     339              : 
     340              :   void
     341              :   print_svalue_for_dump_widget_label (pretty_printer *pp) const final override;
     342              : 
     343              :   void
     344              :   accept_node_visitor (symbolic::node_visitor &v) const final override;
     345              : 
     346              :   std::unique_ptr<json::object>
     347              :   to_json () const final override;
     348              : 
     349              :   std::unique_ptr<diagnostics::markup::node>
     350              :   make_markup_node (symbolic::markup_context &markup_ctxt) const final override;
     351              : 
     352              :   void accept (visitor *v) const final override;
     353              :   bool implicitly_live_p (symbolic::liveness_context &) const final override;
     354              : 
     355      3480599 :   tree get_constant () const { return m_cst_expr; }
     356              :   static tristate eval_condition (const constant_svalue *lhs,
     357              :                                   enum tree_code op,
     358              :                                   const constant_svalue *rhs);
     359              : 
     360              :   bool all_zeroes_p () const final override;
     361              : 
     362              :   bool maybe_get_value_range_1 (value_range &out) const final override;
     363              : 
     364              :  private:
     365              :   tree m_cst_expr;
     366              : };
     367              : 
     368              : } // namespace ana
     369              : 
     370              : template <>
     371              : template <>
     372              : inline bool
     373       672861 : is_a_helper <const constant_svalue *>::test (const svalue *sval)
     374              : {
     375       672861 :   return sval->get_kind () == SK_CONSTANT;
     376              : }
     377              : 
     378              : namespace ana {
     379              : 
     380              : /* Concrete subclass of svalue representing an unknowable value, the bottom
     381              :    value when thinking of svalues as a lattice.
     382              :    This is a singleton (w.r.t. its manager): there is a single unknown_svalue
     383              :    per type.  Self-comparisons of such instances yield "unknown".  */
     384              : 
     385              : class unknown_svalue : public svalue
     386              : {
     387              : public:
     388         8284 :   unknown_svalue (symbolic::node::id_t id, tree type)
     389         8284 :   : svalue (complexity (1, 1), id, type)
     390              :   {}
     391              : 
     392       575713 :   enum svalue_kind get_kind () const final override { return SK_UNKNOWN; }
     393              : 
     394              :   void dump_to_pp (pretty_printer *pp, bool simple) const final override;
     395              : 
     396              :   void
     397              :   print_svalue_for_dump_widget_label (pretty_printer *pp) const final override;
     398              : 
     399              :   void
     400              :   accept_node_visitor (symbolic::node_visitor &v) const final override;
     401              : 
     402              :   std::unique_ptr<json::object>
     403              :   to_json () const final override;
     404              : 
     405              :   std::unique_ptr<diagnostics::markup::node>
     406              :   make_markup_node (symbolic::markup_context &markup_ctxt) const final override;
     407              : 
     408              :   void accept (visitor *v) const final override;
     409              : 
     410              :   bool maybe_get_value_range_1 (value_range &out) const final override;
     411              : 
     412              :   /* Unknown values are singletons per-type, so can't have state.  */
     413        33716 :   bool can_have_associated_state_p () const final override { return false; }
     414              : };
     415              : 
     416              : // TODO: can this be eliminated? (in favor of poisoned_bit_vector)
     417              : /* Concrete subclass of svalue representing a value that should not
     418              :    be used (e.g. uninitialized memory, freed memory).  */
     419              : 
     420              : class poisoned_svalue : public svalue
     421              : {
     422              : public:
     423              :   /* A support class for uniquifying instances of poisoned_svalue.  */
     424              :   struct key_t
     425              :   {
     426            6 :     key_t (enum poison_kind kind, tree type)
     427            6 :     : m_kind (kind), m_type (type)
     428              :     {}
     429              : 
     430              :     bool
     431           10 :     operator< (const key_t &other) const
     432              :     {
     433           10 :       if (m_kind < other.m_kind)
     434              :         return true;
     435           10 :       return cmp_types (m_type, other.m_type) < 0;
     436              :     }
     437              : 
     438              :     bool
     439              :     operator== (const key_t &other) const
     440              :     {
     441              :       return (m_kind == other.m_kind && m_type == other.m_type);
     442              :     }
     443              : 
     444              :     enum poison_kind m_kind;
     445              :     tree m_type;
     446              :   };
     447              : 
     448            1 :   poisoned_svalue (enum poison_kind kind, symbolic::node::id_t id, tree type)
     449            1 :   : svalue (complexity (1, 1), id, type), m_kind (kind) {}
     450              : 
     451            0 :   enum svalue_kind get_kind () const final override { return SK_POISONED; }
     452              :   const poisoned_svalue *
     453            0 :   dyn_cast_poisoned_svalue () const final override { return this; }
     454              : 
     455              :   void dump_to_pp (pretty_printer *pp, bool simple) const final override;
     456              : 
     457              :   void
     458              :   print_svalue_for_dump_widget_label (pretty_printer *pp) const final override;
     459              : 
     460              :   void
     461              :   accept_node_visitor (symbolic::node_visitor &v) const final override;
     462              : 
     463              :   std::unique_ptr<json::object>
     464              :   to_json () const final override;
     465              : 
     466              :   std::unique_ptr<diagnostics::markup::node>
     467              :   make_markup_node (symbolic::markup_context &markup_ctxt) const final override;
     468              : 
     469              :   void accept (visitor *v) const final override;
     470              : 
     471            0 :   enum poison_kind get_poison_kind () const { return m_kind; }
     472              : 
     473              :   /* Poisoned svalues are singletons per-type, so can't have state.  */
     474            0 :   bool can_have_associated_state_p () const final override { return false; }
     475              : 
     476              :  private:
     477              :   enum poison_kind m_kind;
     478              : };
     479              : 
     480              : } // namespace ana
     481              : 
     482              : template <>
     483              : template <>
     484              : inline bool
     485            0 : is_a_helper <const poisoned_svalue *>::test (const svalue *sval)
     486              : {
     487            0 :   return sval->get_kind () == SK_POISONED;
     488              : }
     489              : 
     490              : namespace ana {
     491              : 
     492              : /* A bundle of information recording a setjmp/sigsetjmp call, corresponding
     493              :    roughly to a jmp_buf.  */
     494              : 
     495              : struct setjmp_record
     496              : {
     497           34 :   setjmp_record (const exploded_node *enode,
     498              :                  const superedge *sedge,
     499              :                  const gcall &setjmp_call)
     500           34 :   : m_enode (enode), m_sedge (sedge), m_setjmp_call (&setjmp_call)
     501              :   {
     502              :   }
     503              : 
     504              :   bool operator== (const setjmp_record &other) const
     505              :   {
     506              :     return (m_enode == other.m_enode
     507              :             && m_sedge == other.m_sedge
     508              :             && m_setjmp_call == other.m_setjmp_call);
     509              :   }
     510              : 
     511              :   static int cmp (const setjmp_record &rec1, const setjmp_record &rec2);
     512              : 
     513              :   const exploded_node *m_enode;
     514              :   const superedge *m_sedge;
     515              :   const gcall *m_setjmp_call;
     516              :   // non-null, but we can't use a reference since we're putting these in a std::map
     517              : };
     518              : 
     519              : /* Concrete subclass of svalue representing buffers for setjmp/sigsetjmp,
     520              :    so that longjmp/siglongjmp can potentially "return" to an entirely
     521              :    different function.  */
     522              : 
     523              : class setjmp_svalue : public svalue
     524              : {
     525              : public:
     526              :   /* A support class for uniquifying instances of poisoned_svalue.  */
     527              :   struct key_t
     528              :   {
     529           34 :     key_t (const setjmp_record &record, tree type)
     530           34 :     : m_record (record), m_type (type)
     531              :     {}
     532              : 
     533              :     bool operator< (const key_t &other) const;
     534              :     bool operator== (const key_t &other) const
     535              :     {
     536              :       return (m_record == other.m_record && m_type == other.m_type);
     537              :     }
     538              : 
     539              :     setjmp_record m_record;
     540              :     tree m_type;
     541              :   };
     542              : 
     543           34 :   setjmp_svalue (const setjmp_record &setjmp_record,
     544              :                  symbolic::node::id_t id,
     545              :                  tree type)
     546           34 :   : svalue (complexity (1, 1), id, type), m_setjmp_record (setjmp_record)
     547              :   {}
     548              : 
     549         2583 :   enum svalue_kind get_kind () const final override { return SK_SETJMP; }
     550              :   const setjmp_svalue *
     551           25 :   dyn_cast_setjmp_svalue () const final override { return this; }
     552              : 
     553              :   void dump_to_pp (pretty_printer *pp, bool simple) const final override;
     554              : 
     555              :   void
     556              :   print_svalue_for_dump_widget_label (pretty_printer *pp) const final override;
     557              :   void
     558              :   add_dump_widget_children (text_art::tree_widget &w,
     559              :                             symbolic::node_dump_state &nds) const final override;
     560              :   void
     561              :   accept_node_visitor (symbolic::node_visitor &v) const final override;
     562              : 
     563              :   std::unique_ptr<json::object>
     564              :   to_json () const final override;
     565              : 
     566              :   std::unique_ptr<diagnostics::markup::node>
     567              :   make_markup_node (symbolic::markup_context &markup_ctxt) const final override;
     568              : 
     569              :   void accept (visitor *v) const final override;
     570              : 
     571              :   int get_enode_index () const;
     572              : 
     573              :   const setjmp_record &get_setjmp_record () const { return m_setjmp_record; }
     574              : 
     575              :  private:
     576              :   setjmp_record m_setjmp_record;
     577              : };
     578              : 
     579              : } // namespace ana
     580              : 
     581              : template <>
     582              : template <>
     583              : inline bool
     584              : is_a_helper <const setjmp_svalue *>::test (const svalue *sval)
     585              : {
     586              :   return sval->get_kind () == SK_SETJMP;
     587              : }
     588              : 
     589              : namespace ana {
     590              : 
     591              : /* Concrete subclass of svalue representing the initial value of a
     592              :    specific base region.
     593              : 
     594              :    This represents the initial value at the start of the analysis path,
     595              :    as opposed to the first time the region is accessed during the path.
     596              :    Hence as soon as we have a call to an unknown function, all previously
     597              :    unmodelled globals become implicitly "unknown" rathen than "initial".
     598              : 
     599              :   Consolidation/canonicalization:
     600              :   - the region must be a "base region".  */
     601              : 
     602              : class initial_svalue : public svalue
     603              : {
     604              : public:
     605              :   initial_svalue (symbolic::node::id_t id, tree type, const region *reg);
     606              : 
     607      5356663 :   enum svalue_kind get_kind () const final override { return SK_INITIAL; }
     608              :   const initial_svalue *
     609       217262 :   dyn_cast_initial_svalue () const final override { return this; }
     610              : 
     611              :   void dump_to_pp (pretty_printer *pp, bool simple) const final override;
     612              : 
     613              :   void
     614              :   print_svalue_for_dump_widget_label (pretty_printer *pp) const final override;
     615              :   void
     616              :   add_dump_widget_children (text_art::tree_widget &w,
     617              :                             symbolic::node_dump_state &nds) const final override;
     618              :   void
     619              :   accept_node_visitor (symbolic::node_visitor &v) const final override;
     620              : 
     621              :   std::unique_ptr<json::object>
     622              :   to_json () const final override;
     623              : 
     624              :   std::unique_ptr<diagnostics::markup::node>
     625              :   make_markup_node (symbolic::markup_context &markup_ctxt) const final override;
     626              : 
     627              :   void accept (visitor *v) const final override;
     628              :   bool implicitly_live_p (symbolic::liveness_context &) const final override;
     629              : 
     630              :   bool initial_value_of_param_p () const;
     631              : 
     632      1075694 :   const region *get_region () const { return m_reg; }
     633              : 
     634              :  private:
     635              :   const region *m_reg;
     636              : };
     637              : 
     638              : } // namespace ana
     639              : 
     640              : template <>
     641              : template <>
     642              : inline bool
     643       897201 : is_a_helper <const initial_svalue *>::test (const svalue *sval)
     644              : {
     645       897201 :   return sval->get_kind () == SK_INITIAL;
     646              : }
     647              : 
     648              : namespace ana {
     649              : 
     650              : /* Concrete subclass of svalue representing a unary operation on
     651              :    another svalues (e.g. a cast).
     652              : 
     653              :    Consolidation/canonicalization:
     654              :    - arg->can_have_associated_state_p () must be true.  In particular,
     655              :      the arg cannot be SK_UNKNOWN (this will get folded to unknown).  */
     656              : 
     657              : class unaryop_svalue : public svalue
     658              : {
     659              : public:
     660              :   /* A support class for uniquifying instances of unaryop_svalue.  */
     661              :   struct key_t
     662              :   {
     663        96120 :     key_t (tree type, enum tree_code op, const svalue *arg)
     664        96120 :     : m_type (type), m_op (op), m_arg (arg)
     665              :     {}
     666              : 
     667              :     bool operator< (const key_t &other) const;
     668              :     bool operator== (const key_t &other) const
     669              :     {
     670              :       return (m_type == other.m_type
     671              :               && m_op == other.m_op
     672              :               && m_arg == other.m_arg);
     673              :     }
     674              : 
     675              :     tree m_type;
     676              :     enum tree_code m_op;
     677              :     const svalue *m_arg;
     678              :   };
     679              : 
     680         9076 :   unaryop_svalue (symbolic::node::id_t id, tree type, enum tree_code op,
     681              :                   const svalue *arg)
     682         9076 :   : svalue (complexity (arg), id, type), m_op (op), m_arg (arg)
     683              :   {
     684         9076 :     gcc_assert (arg->can_have_associated_state_p ());
     685         9076 :   }
     686              : 
     687      2493406 :   enum svalue_kind get_kind () const final override { return SK_UNARYOP; }
     688              :   const unaryop_svalue *
     689      2176895 :   dyn_cast_unaryop_svalue () const final override { return this; }
     690              : 
     691              :   void dump_to_pp (pretty_printer *pp, bool simple) const final override;
     692              : 
     693              :   void
     694              :   print_svalue_for_dump_widget_label (pretty_printer *pp) const final override;
     695              :   void
     696              :   add_dump_widget_children (text_art::tree_widget &w,
     697              :                             symbolic::node_dump_state &nds) const final override;
     698              :   void
     699              :   accept_node_visitor (symbolic::node_visitor &v) const final override;
     700              : 
     701              :   std::unique_ptr<json::object>
     702              :   to_json () const final override;
     703              : 
     704              :   std::unique_ptr<diagnostics::markup::node>
     705              :   make_markup_node (symbolic::markup_context &markup_ctxt) const final override;
     706              : 
     707              :   void accept (visitor *v) const final override;
     708              :   bool implicitly_live_p (symbolic::liveness_context &) const final override;
     709              : 
     710      4458173 :   enum tree_code get_op () const { return m_op; }
     711      2378487 :   const svalue *get_arg () const { return m_arg; }
     712              : 
     713              :   bool maybe_get_value_range_1 (value_range &out) const final override;
     714              : 
     715              :  private:
     716              :   enum tree_code m_op;
     717              :   const svalue *m_arg;
     718              : };
     719              : 
     720              : } // namespace ana
     721              : 
     722              : template <>
     723              : template <>
     724              : inline bool
     725       384888 : is_a_helper <const unaryop_svalue *>::test (const svalue *sval)
     726              : {
     727       384888 :   return sval->get_kind () == SK_UNARYOP;
     728              : }
     729              : 
     730              : namespace ana {
     731              : 
     732              : /* Concrete subclass of svalue representing a binary operation of
     733              :    two svalues.
     734              : 
     735              :   Consolidation/canonicalization:
     736              :    - can_have_associated_state_p () must be true for both arguments.
     737              :      In particular, they cannot be SK_UNKNOWN (this will get folded
     738              :      to unknown).  */
     739              : 
     740              : class binop_svalue : public svalue
     741              : {
     742              : public:
     743              :   /* A support class for uniquifying instances of binop_svalue.  */
     744              :   struct key_t
     745              :   {
     746        49916 :     key_t (tree type, enum tree_code op,
     747              :            const svalue *arg0, const svalue *arg1)
     748        49916 :     : m_type (type), m_op (op), m_arg0 (arg0), m_arg1 (arg1)
     749              :     {}
     750              : 
     751              :     bool operator< (const key_t &other) const;
     752              :     bool operator== (const key_t &other) const
     753              :     {
     754              :       return (m_type == other.m_type
     755              :               && m_op == other.m_op
     756              :               && m_arg0 == other.m_arg0
     757              :               && m_arg1 == other.m_arg1);
     758              :     }
     759              : 
     760              :     tree m_type;
     761              :     enum tree_code m_op;
     762              :     const svalue *m_arg0;
     763              :     const svalue *m_arg1;
     764              :   };
     765              : 
     766        13888 :   binop_svalue (symbolic::node::id_t id, tree type, enum tree_code op,
     767              :                 const svalue *arg0, const svalue *arg1)
     768              :   : svalue (complexity::from_pair (arg0->get_complexity (),
     769              :                                     arg1->get_complexity ()),
     770              :             id,
     771              :             type),
     772        13888 :     m_op (op), m_arg0 (arg0), m_arg1 (arg1)
     773              :   {
     774        13888 :     gcc_assert (arg0->can_have_associated_state_p ());
     775        13888 :     gcc_assert (arg1->can_have_associated_state_p ());
     776        13888 :   }
     777              : 
     778      3941302 :   enum svalue_kind get_kind () const final override { return SK_BINOP; }
     779        73927 :   const binop_svalue *dyn_cast_binop_svalue () const final override
     780              :   {
     781        73927 :     return this;
     782              :   }
     783              : 
     784              :   void dump_to_pp (pretty_printer *pp, bool simple) const final override;
     785              : 
     786              :   void
     787              :   print_svalue_for_dump_widget_label (pretty_printer *pp) const final override;
     788              :   void
     789              :   add_dump_widget_children (text_art::tree_widget &w,
     790              :                             symbolic::node_dump_state &nds) const final override;
     791              :   void
     792              :   accept_node_visitor (symbolic::node_visitor &v) const final override;
     793              : 
     794              :   std::unique_ptr<json::object>
     795              :   to_json () const final override;
     796              : 
     797              :   std::unique_ptr<diagnostics::markup::node>
     798              :   make_markup_node (symbolic::markup_context &markup_ctxt) const final override;
     799              : 
     800              :   void accept (visitor *v) const final override;
     801              :   bool implicitly_live_p (symbolic::liveness_context &) const final override;
     802              : 
     803              :   bool maybe_get_value_range_1 (value_range &out) const final override;
     804              : 
     805      3448846 :   enum tree_code get_op () const { return m_op; }
     806       630440 :   const svalue *get_arg0 () const { return m_arg0; }
     807       619026 :   const svalue *get_arg1 () const { return m_arg1; }
     808              : 
     809              :  private:
     810              :   enum tree_code m_op;
     811              :   const svalue *m_arg0;
     812              :   const svalue *m_arg1;
     813              : };
     814              : 
     815              : } // namespace ana
     816              : 
     817              : template <>
     818              : template <>
     819              : inline bool
     820       159529 : is_a_helper <const binop_svalue *>::test (const svalue *sval)
     821              : {
     822       159529 :   return sval->get_kind () == SK_BINOP;
     823              : }
     824              : 
     825              : namespace ana {
     826              : 
     827              : /* Concrete svalue subclass: interpreting a collection of bits as a
     828              :    symbolic value of a particular type.
     829              : 
     830              :    Consolidation/canonicalization:
     831              :    - all qualifiers (except address spaces) are stripped from the type
     832              :      of the pointee
     833              :    - no nesting: the underlying bit vector can't be a bit_vector_from_svalue
     834              :      (we fold away such cases).  */
     835              : 
     836              : class svalue_from_bit_vector : public svalue
     837              : {
     838              : public:
     839              :   struct key_t
     840              :   {
     841       906542 :     key_t (tree type,
     842              :            const symbolic::bit_vector *bv)
     843       906542 :     : m_type (type),
     844       906542 :       m_bv (bv)
     845              :     {
     846              :     }
     847              : 
     848              :     bool operator< (const key_t &other) const;
     849              :     bool operator== (const key_t &other) const
     850              :     {
     851              :       return (m_type == other.m_type
     852              :               && m_bv == other.m_bv);
     853              :     }
     854              : 
     855              :     /* Use m_bv to mark empty/deleted.  */
     856              :     void mark_deleted () { m_bv = reinterpret_cast<const symbolic::bit_vector *> (1); }
     857              :     void mark_empty () { m_bv = nullptr; }
     858              :     bool is_deleted () const
     859              :     {
     860              :       return m_bv == reinterpret_cast<const symbolic::bit_vector *> (1);
     861              :     }
     862              :     bool is_empty () const { return m_bv == nullptr; }
     863              : 
     864              :     tree m_type;
     865              :     const symbolic::bit_vector *m_bv;
     866              :   };
     867              : 
     868              :   svalue_from_bit_vector (symbolic::node::id_t id,
     869              :                           tree type,
     870              :                           const symbolic::bit_vector &bv);
     871              : 
     872      2394594 :   enum svalue_kind get_kind () const final override
     873              :   {
     874      2394594 :     return SK_BIT_VECTOR;
     875              :   }
     876              :   const svalue_from_bit_vector *
     877      2290480 :   dyn_cast_svalue_from_bit_vector () const final override
     878              :   {
     879      2290480 :     return this;
     880              :   }
     881              : 
     882              :   void dump_to_pp (pretty_printer *pp, bool simple) const final override;
     883              : 
     884              :   void
     885              :   print_svalue_for_dump_widget_label (pretty_printer *pp) const final override;
     886              :   void
     887              :   add_dump_widget_children (text_art::tree_widget &w,
     888              :                             symbolic::node_dump_state &nds) const final override;
     889              :   void
     890              :   accept_node_visitor (symbolic::node_visitor &v) const final override;
     891              : 
     892              :   std::unique_ptr<json::object>
     893              :   to_json () const final override;
     894              : 
     895              :   std::unique_ptr<diagnostics::markup::node>
     896              :   make_markup_node (symbolic::markup_context &markup_ctxt) const final override;
     897              : 
     898              :   void accept (visitor *v) const final override;
     899              : 
     900      2393340 :   const symbolic::bit_vector &get_bit_vector () const { return m_bv; }
     901              : 
     902              :   bool all_zeroes_p () const final override;
     903              : 
     904              :   bool implicitly_live_p (symbolic::liveness_context &) const final override;
     905              : 
     906              :   bool
     907              :   maybe_get_value_range_1 (value_range &out) const final override;
     908              : 
     909              :   bool
     910              :   conjured_p () const final override;
     911              : 
     912              :  private:
     913              :   const symbolic::bit_vector &m_bv;
     914              : };
     915              : 
     916              : } // namespace ana
     917              : 
     918              : template <>
     919              : template <>
     920              : inline bool
     921        80103 : is_a_helper <const svalue_from_bit_vector *>::test (const svalue *sval)
     922              : {
     923        80103 :   return sval->get_kind () == SK_BIT_VECTOR;
     924              : }
     925              : 
     926              : namespace ana {
     927              : 
     928              : /* Concrete subclass of svalue: decorate another svalue,
     929              :    so that the resulting svalue can be identified as being
     930              :    "interesting to control flow".
     931              :    For example, consider the return value from setjmp.  We
     932              :    don't want to merge states in which the result is 0 with
     933              :    those in which the result is non-zero.  By using an
     934              :    unmergeable_svalue for the result, we can inhibit such merges
     935              :    and have separate exploded nodes for those states, keeping
     936              :    the first and second returns from setjmp distinct in the exploded
     937              :    graph.
     938              : 
     939              :   Consolidation/canonicalization:
     940              :   - no nesting: the underlying arg is not itself unmergeable (we fold
     941              :     away nesting).  */
     942              : 
     943              : class unmergeable_svalue : public svalue
     944              : {
     945              : public:
     946          299 :   unmergeable_svalue (symbolic::node::id_t id, const svalue *arg)
     947          299 :   : svalue (complexity (arg), id, arg->get_type ()), m_arg (arg)
     948              :   {
     949          299 :   }
     950              : 
     951        56176 :   enum svalue_kind get_kind () const final override { return SK_UNMERGEABLE; }
     952              :   const unmergeable_svalue *
     953        13492 :   dyn_cast_unmergeable_svalue () const final override { return this; }
     954              : 
     955              :   void dump_to_pp (pretty_printer *pp, bool simple) const final override;
     956              : 
     957              :   void
     958              :   print_svalue_for_dump_widget_label (pretty_printer *pp) const final override;
     959              :   void
     960              :   add_dump_widget_children (text_art::tree_widget &w,
     961              :                             symbolic::node_dump_state &nds) const final override;
     962              :   void
     963              :   accept_node_visitor (symbolic::node_visitor &v) const final override;
     964              : 
     965              :   std::unique_ptr<json::object>
     966              :   to_json () const final override;
     967              : 
     968              :   std::unique_ptr<diagnostics::markup::node>
     969              :   make_markup_node (symbolic::markup_context &markup_ctxt) const final override;
     970              : 
     971              :   void accept (visitor *v) const final override;
     972              :   bool implicitly_live_p (symbolic::liveness_context &) const final override;
     973              : 
     974        14285 :   const svalue *get_arg () const { return m_arg; }
     975              : 
     976              :  private:
     977              :   const svalue *m_arg;
     978              : };
     979              : 
     980              : } // namespace ana
     981              : 
     982              : template <>
     983              : template <>
     984              : inline bool
     985            0 : is_a_helper <const unmergeable_svalue *>::test (const svalue *sval)
     986              : {
     987            0 :   return sval->get_kind () == SK_UNMERGEABLE;
     988              : }
     989              : 
     990              : namespace ana {
     991              : 
     992              : /* Concrete subclass of svalue for use in selftests, where
     993              :    we want a specific but unknown svalue.
     994              :    Unlike other svalue subclasses these aren't managed by
     995              :    region_model_manager.  */
     996              : 
     997           76 : class placeholder_svalue : public svalue
     998              : {
     999              : public:
    1000         5718 :   placeholder_svalue (symbolic::node::id_t id, tree type, const char *name)
    1001         5718 :   : svalue (complexity (1, 1), id, type), m_name (name)
    1002              :   {
    1003              :   }
    1004              : 
    1005        18753 :   enum svalue_kind get_kind () const final override { return SK_PLACEHOLDER; }
    1006              : 
    1007              :   void dump_to_pp (pretty_printer *pp, bool simple) const final override;
    1008              : 
    1009              :   void
    1010              :   print_svalue_for_dump_widget_label (pretty_printer *pp) const final override;
    1011              : 
    1012              :   void
    1013              :   accept_node_visitor (symbolic::node_visitor &v) const final override;
    1014              : 
    1015              :   std::unique_ptr<json::object>
    1016              :   to_json () const final override;
    1017              : 
    1018              :   std::unique_ptr<diagnostics::markup::node>
    1019              :   make_markup_node (symbolic::markup_context &markup_ctxt) const final override;
    1020              : 
    1021              :   void accept (visitor *v) const final override;
    1022              : 
    1023              :   const char *get_name () const { return m_name; }
    1024              : 
    1025              :  private:
    1026              :   const char *m_name;
    1027              : };
    1028              : 
    1029              : } // namespace ana
    1030              : 
    1031              : template <>
    1032              : template <>
    1033              : inline bool
    1034              : is_a_helper <const placeholder_svalue *>::test (const svalue *sval)
    1035              : {
    1036              :   return sval->get_kind () == SK_PLACEHOLDER;
    1037              : }
    1038              : 
    1039              : namespace ana {
    1040              : 
    1041              : /* Concrete subclass of svalue representing a "widening" seen when merging
    1042              :    states, widening from a base value to {base value, iter value} and thus
    1043              :    representing a possible fixed point in an iteration from the base to
    1044              :    +ve infinity, or -ve infinity, and thus useful for representing a value
    1045              :    within a loop.
    1046              :    TODO: We also need to capture the program_point at which the merger happens,
    1047              :    so that distinguish between different iterators, and thus handle
    1048              :    nested loops.  (currently we capture the function_point instead, for
    1049              :    redundant historical reasons).
    1050              : 
    1051              :    Consolidation/canonicalization:
    1052              :    - the underlying args must not themselves be SK_WIDENING.  */
    1053              : 
    1054              : class widening_svalue : public svalue
    1055              : {
    1056              : public:
    1057              :   /* A support class for uniquifying instances of widening_svalue.  */
    1058              :   struct key_t
    1059              :   {
    1060         2731 :     key_t (tree type, const supernode *snode,
    1061              :            const svalue *base_sval, const svalue *iter_sval)
    1062         2731 :     : m_type (type), m_snode (snode),
    1063         2731 :       m_base_sval (base_sval), m_iter_sval (iter_sval)
    1064              :     {}
    1065              : 
    1066              :     bool operator< (const key_t &other) const;
    1067              :     bool operator== (const key_t &other) const
    1068              :     {
    1069              :       return (m_type == other.m_type
    1070              :               && m_snode == other.m_snode
    1071              :               && m_base_sval == other.m_base_sval
    1072              :               && m_iter_sval == other.m_iter_sval);
    1073              :     }
    1074              : 
    1075              :     tree m_type;
    1076              :     const supernode *m_snode;
    1077              :     const svalue *m_base_sval;
    1078              :     const svalue *m_iter_sval;
    1079              :   };
    1080              : 
    1081              :   enum direction_t
    1082              :     {
    1083              :      DIR_ASCENDING,
    1084              :      DIR_DESCENDING,
    1085              :      DIR_UNKNOWN
    1086              :     };
    1087              : 
    1088         1686 :   widening_svalue (symbolic::node::id_t id, tree type, const supernode *snode,
    1089              :                    const svalue *base_sval, const svalue *iter_sval)
    1090              :   : svalue (complexity::from_pair (base_sval->get_complexity (),
    1091              :                                    iter_sval->get_complexity ()),
    1092              :             id,
    1093              :             type),
    1094         1686 :     m_snode (snode),
    1095         1686 :     m_base_sval (base_sval), m_iter_sval (iter_sval)
    1096              :   {
    1097         1686 :     gcc_assert (base_sval->can_have_associated_state_p ());
    1098         1686 :     gcc_assert (iter_sval->can_have_associated_state_p ());
    1099         1686 :   }
    1100              : 
    1101       688161 :   enum svalue_kind get_kind () const final override { return SK_WIDENING; }
    1102        16287 :   const widening_svalue *dyn_cast_widening_svalue () const final override
    1103              :   {
    1104        16287 :     return this;
    1105              :   }
    1106              : 
    1107              :   void dump_to_pp (pretty_printer *pp, bool simple) const final override;
    1108              : 
    1109              :   void
    1110              :   print_svalue_for_dump_widget_label (pretty_printer *pp) const final override;
    1111              :   void
    1112              :   add_dump_widget_children (text_art::tree_widget &w,
    1113              :                             symbolic::node_dump_state &nds) const final override;
    1114              :   void
    1115              :   accept_node_visitor (symbolic::node_visitor &v) const final override;
    1116              : 
    1117              :   std::unique_ptr<json::object>
    1118              :   to_json () const final override;
    1119              : 
    1120              :   std::unique_ptr<diagnostics::markup::node>
    1121              :   make_markup_node (symbolic::markup_context &markup_ctxt) const final override;
    1122              : 
    1123              :   void accept (visitor *v) const final override;
    1124              : 
    1125          114 :   const supernode *get_snode () const { return m_snode; }
    1126         8642 :   const svalue *get_base_svalue () const { return m_base_sval; }
    1127         2773 :   const svalue *get_iter_svalue () const { return m_iter_sval; }
    1128              : 
    1129              :   enum direction_t get_direction () const;
    1130              : 
    1131              :   tristate eval_condition_without_cm (enum tree_code op,
    1132              :                                       tree rhs_cst) const;
    1133              : 
    1134              :  private:
    1135              :   const supernode *m_snode;
    1136              :   const svalue *m_base_sval;
    1137              :   const svalue *m_iter_sval;
    1138              : };
    1139              : 
    1140              : } // namespace ana
    1141              : 
    1142              : template <>
    1143              : template <>
    1144              : inline bool
    1145          114 : is_a_helper <const widening_svalue *>::test (const svalue *sval)
    1146              : {
    1147          114 :   return sval->get_kind () == SK_WIDENING;
    1148              : }
    1149              : 
    1150              : namespace ana {
    1151              : 
    1152              : /* An output from a deterministic asm stmt, where we want to identify a
    1153              :    particular unknown value, rather than resorting to the unknown_value
    1154              :    singleton.
    1155              : 
    1156              :    Comparisons of variables that share the same asm_output_svalue are known
    1157              :    to be equal, even if we don't know what the value is.
    1158              : 
    1159              :    Consolidation/canonicalization:
    1160              :    - none of the inputs may be unknown (we fold away such cases).  */
    1161              : 
    1162              : class asm_output_svalue : public svalue
    1163              : {
    1164              : public:
    1165              :   /* Imposing an upper limit and using a (small) array allows key_t
    1166              :      to avoid memory management.  */
    1167              :   static const unsigned MAX_INPUTS = 2;
    1168              : 
    1169              :   /* A support class for uniquifying instances of asm_output_svalue.  */
    1170              :   struct key_t
    1171              :   {
    1172          289 :     key_t (tree type,
    1173              :            const char *asm_string,
    1174              :            unsigned output_idx,
    1175              :            const vec<const svalue *> &inputs)
    1176          289 :     : m_type (type), m_asm_string (asm_string), m_output_idx (output_idx),
    1177          289 :       m_num_inputs (inputs.length ())
    1178              :     {
    1179          289 :       gcc_assert (inputs.length () <= MAX_INPUTS);
    1180          750 :       for (unsigned i = 0; i < m_num_inputs; i++)
    1181          461 :         m_input_arr[i] = inputs[i];
    1182          289 :     }
    1183              : 
    1184              :     bool operator< (const key_t &other) const;
    1185              :     bool operator== (const key_t &other) const
    1186              :     {
    1187              :       if (!(m_type == other.m_type
    1188              :             && 0 == (strcmp (m_asm_string, other.m_asm_string))
    1189              :             && m_output_idx == other.m_output_idx
    1190              :             && m_num_inputs == other.m_num_inputs))
    1191              :         return false;
    1192              :       for (unsigned i = 0; i < m_num_inputs; i++)
    1193              :         if (m_input_arr[i] != other.m_input_arr[i])
    1194              :           return false;
    1195              :       return true;
    1196              :     }
    1197              : 
    1198              :     tree m_type;
    1199              :     const char *m_asm_string;
    1200              :     unsigned m_output_idx;
    1201              :     unsigned m_num_inputs;
    1202              :     const svalue *m_input_arr[MAX_INPUTS];
    1203              :   };
    1204              : 
    1205          173 :   asm_output_svalue (symbolic::node::id_t id,
    1206              :                      tree type,
    1207              :                      const char *asm_string,
    1208              :                      unsigned output_idx,
    1209              :                      unsigned num_outputs,
    1210              :                      const vec<const svalue *> &inputs)
    1211              :   : svalue (complexity::from_vec_svalue (inputs), id, type),
    1212          173 :     m_asm_string (asm_string),
    1213          173 :     m_output_idx (output_idx),
    1214          173 :     m_num_outputs (num_outputs),
    1215          173 :     m_num_inputs (inputs.length ())
    1216              :   {
    1217          173 :     gcc_assert (inputs.length () <= MAX_INPUTS);
    1218          430 :     for (unsigned i = 0; i < m_num_inputs; i++)
    1219          257 :       m_input_arr[i] = inputs[i];
    1220          173 :   }
    1221              : 
    1222        23094 :   enum svalue_kind get_kind () const final override { return SK_ASM_OUTPUT; }
    1223              :   const asm_output_svalue *
    1224            0 :   dyn_cast_asm_output_svalue () const final override
    1225              :   {
    1226            0 :     return this;
    1227              :   }
    1228              : 
    1229              :   void dump_to_pp (pretty_printer *pp, bool simple) const final override;
    1230              : 
    1231              :   void
    1232              :   print_svalue_for_dump_widget_label (pretty_printer *pp) const final override;
    1233              :   void
    1234              :   add_dump_widget_children (text_art::tree_widget &w,
    1235              :                             symbolic::node_dump_state &nds) const final override;
    1236              :   void
    1237              :   accept_node_visitor (symbolic::node_visitor &v) const final override;
    1238              : 
    1239              :   std::unique_ptr<json::object>
    1240              :   to_json () const final override;
    1241              : 
    1242              :   std::unique_ptr<diagnostics::markup::node>
    1243              :   make_markup_node (symbolic::markup_context &markup_ctxt) const final override;
    1244              : 
    1245              :   void accept (visitor *v) const final override;
    1246              : 
    1247            8 :   const char *get_asm_string () const { return m_asm_string; }
    1248           14 :   unsigned get_output_idx () const { return m_output_idx; }
    1249            8 :   unsigned get_num_outputs () const { return m_num_outputs; }
    1250            8 :   unsigned get_num_inputs () const { return m_num_inputs; }
    1251            0 :   const svalue *get_input (unsigned idx) const { return m_input_arr[idx]; }
    1252              : 
    1253              :  private:
    1254              :   void dump_input (pretty_printer *pp,
    1255              :                    unsigned input_idx,
    1256              :                    const svalue *sval,
    1257              :                    bool simple) const;
    1258              :   unsigned input_idx_to_asm_idx (unsigned input_idx) const;
    1259              : 
    1260              :   const char *m_asm_string;
    1261              :   unsigned m_output_idx;
    1262              : 
    1263              :   /* We capture this so that we can offset the input indices
    1264              :      to match the %0, %1, %2 in the asm_string when dumping.  */
    1265              :   unsigned m_num_outputs;
    1266              : 
    1267              :   unsigned m_num_inputs;
    1268              :   const svalue *m_input_arr[MAX_INPUTS];
    1269              : };
    1270              : 
    1271              : } // namespace ana
    1272              : 
    1273              : template <>
    1274              : template <>
    1275              : inline bool
    1276            8 : is_a_helper <const asm_output_svalue *>::test (const svalue *sval)
    1277              : {
    1278            8 :   return sval->get_kind () == SK_ASM_OUTPUT;
    1279              : }
    1280              : 
    1281              : namespace ana {
    1282              : 
    1283              : /* The return value from a function with __attribute((const)) for given
    1284              :    inputs, provided that we don't have too many inputs, and all of them
    1285              :    are deterministic.
    1286              : 
    1287              :    Comparisons of variables that share the same const_fn_result_svalue are known
    1288              :    to be equal, even if we don't know what the value is.
    1289              : 
    1290              :    Consolidation/canonicalization:
    1291              :    - TODO.  */
    1292              : 
    1293              : class const_fn_result_svalue : public svalue
    1294              : {
    1295              : public:
    1296              :   /* Imposing an upper limit and using a (small) array allows key_t
    1297              :      to avoid memory management.  */
    1298              :   static const unsigned MAX_INPUTS = 2;
    1299              : 
    1300              :   /* A support class for uniquifying instances of const_fn_result_svalue.  */
    1301              :   struct key_t
    1302              :   {
    1303          632 :     key_t (tree type,
    1304              :            tree fndecl,
    1305              :            const vec<const svalue *> &inputs)
    1306          632 :     : m_type (type), m_fndecl (fndecl),
    1307          632 :       m_num_inputs (inputs.length ())
    1308              :     {
    1309          632 :       gcc_assert (inputs.length () <= MAX_INPUTS);
    1310         1182 :       for (unsigned i = 0; i < m_num_inputs; i++)
    1311          550 :         m_input_arr[i] = inputs[i];
    1312          632 :     }
    1313              : 
    1314              :     bool operator< (const key_t &other) const;
    1315              :     bool operator== (const key_t &other) const
    1316              :     {
    1317              :       if (!(m_type == other.m_type
    1318              :             && m_fndecl == other.m_fndecl
    1319              :             && m_num_inputs == other.m_num_inputs))
    1320              :         return false;
    1321              :       for (unsigned i = 0; i < m_num_inputs; i++)
    1322              :         if (m_input_arr[i] != other.m_input_arr[i])
    1323              :           return false;
    1324              :       return true;
    1325              :     }
    1326              : 
    1327              :     tree m_type;
    1328              :     tree m_fndecl;
    1329              :     unsigned m_num_inputs;
    1330              :     const svalue *m_input_arr[MAX_INPUTS];
    1331              :   };
    1332              : 
    1333          151 :   const_fn_result_svalue (symbolic::node::id_t id,
    1334              :                           tree type,
    1335              :                           tree fndecl,
    1336              :                           const vec<const svalue *> &inputs)
    1337              :   : svalue (complexity::from_vec_svalue (inputs), id, type),
    1338          151 :     m_fndecl (fndecl),
    1339          151 :     m_num_inputs (inputs.length ())
    1340              :   {
    1341          151 :     gcc_assert (inputs.length () <= MAX_INPUTS);
    1342          303 :     for (unsigned i = 0; i < m_num_inputs; i++)
    1343          152 :       m_input_arr[i] = inputs[i];
    1344          151 :   }
    1345              : 
    1346        39100 :   enum svalue_kind get_kind () const final override
    1347              :   {
    1348        39100 :     return SK_CONST_FN_RESULT;
    1349              :   }
    1350              :   const const_fn_result_svalue *
    1351            0 :   dyn_cast_const_fn_result_svalue () const final override
    1352              :   {
    1353            0 :     return this;
    1354              :   }
    1355              : 
    1356              :   void dump_to_pp (pretty_printer *pp, bool simple) const final override;
    1357              : 
    1358              :   void
    1359              :   print_svalue_for_dump_widget_label (pretty_printer *pp) const final override;
    1360              :   void
    1361              :   add_dump_widget_children (text_art::tree_widget &w,
    1362              :                             symbolic::node_dump_state &nds) const final override;
    1363              :   void
    1364              :   accept_node_visitor (symbolic::node_visitor &v) const final override;
    1365              : 
    1366              :   std::unique_ptr<json::object>
    1367              :   to_json () const final override;
    1368              : 
    1369              :   std::unique_ptr<diagnostics::markup::node>
    1370              :   make_markup_node (symbolic::markup_context &markup_ctxt) const final override;
    1371              : 
    1372              :   void accept (visitor *v) const final override;
    1373              : 
    1374            2 :   tree get_fndecl () const { return m_fndecl; }
    1375            2 :   unsigned get_num_inputs () const { return m_num_inputs; }
    1376            2 :   const svalue *get_input (unsigned idx) const { return m_input_arr[idx]; }
    1377              : 
    1378              :  private:
    1379              :   void dump_input (pretty_printer *pp,
    1380              :                    unsigned input_idx,
    1381              :                    const svalue *sval,
    1382              :                    bool simple) const;
    1383              : 
    1384              :   tree m_fndecl;
    1385              :   unsigned m_num_inputs;
    1386              :   const svalue *m_input_arr[MAX_INPUTS];
    1387              : };
    1388              : 
    1389              : } // namespace ana
    1390              : 
    1391              : template <>
    1392              : template <>
    1393              : inline bool
    1394            2 : is_a_helper <const const_fn_result_svalue *>::test (const svalue *sval)
    1395              : {
    1396            2 :   return sval->get_kind () == SK_CONST_FN_RESULT;
    1397              : }
    1398              : 
    1399              : #endif /* GCC_ANALYZER_SVALUE_H */
        

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.