public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-1647] analyzer: add region_model_manager::get_or_create_int_cst
@ 2021-06-18 15:20 David Malcolm
  0 siblings, 0 replies; only message in thread
From: David Malcolm @ 2021-06-18 15:20 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:1aff29d42601927a416a484d6c0fa37a25faae79

commit r12-1647-g1aff29d42601927a416a484d6c0fa37a25faae79
Author: David Malcolm <dmalcolm@redhat.com>
Date:   Fri Jun 18 11:19:30 2021 -0400

    analyzer: add region_model_manager::get_or_create_int_cst
    
    gcc/analyzer/ChangeLog:
            * region-model-manager.cc
            (region_model_manager::get_or_create_int_cst): New.
            (region_model_manager::maybe_undo_optimize_bit_field_compare): Use
            it to simplify away a local tree.
            * region-model.cc (region_model::on_setjmp): Likewise.
            (region_model::on_longjmp): Likewise.
            * region-model.h (region_model_manager::get_or_create_int_cst):
            New decl.
            * store.cc (binding_cluster::zero_fill_region): Use it to simplify
            away a local tree.
    
    Signed-off-by: David Malcolm <dmalcolm@redhat.com>

Diff:
---
 gcc/analyzer/region-model-manager.cc | 14 ++++++++++++--
 gcc/analyzer/region-model.cc         | 11 +++++------
 gcc/analyzer/region-model.h          |  1 +
 gcc/analyzer/store.cc                |  4 ++--
 4 files changed, 20 insertions(+), 10 deletions(-)

diff --git a/gcc/analyzer/region-model-manager.cc b/gcc/analyzer/region-model-manager.cc
index 621eff0e139..1ee6663f05e 100644
--- a/gcc/analyzer/region-model-manager.cc
+++ b/gcc/analyzer/region-model-manager.cc
@@ -210,6 +210,17 @@ region_model_manager::get_or_create_constant_svalue (tree cst_expr)
   return cst_sval;
 }
 
+/* Return the svalue * for a constant_svalue for the INTEGER_CST
+   for VAL of type TYPE, creating it if necessary.  */
+
+const svalue *
+region_model_manager::get_or_create_int_cst (tree type, poly_int64 val)
+{
+  gcc_assert (type);
+  tree tree_cst = build_int_cst (type, val);
+  return get_or_create_constant_svalue (tree_cst);
+}
+
 /* Return the svalue * for a unknown_svalue for TYPE (which can be NULL),
    creating it if necessary.
    The unknown_svalue instances are reused, based on pointer equality
@@ -475,8 +486,7 @@ maybe_undo_optimize_bit_field_compare (tree type,
      shift it by the correct number of bits.  */
   const svalue *lhs = get_or_create_cast (type, sval);
   HOST_WIDE_INT bit_offset = bits.get_start_bit_offset ().to_shwi ();
-  tree shift_amt = build_int_cst (type, bit_offset);
-  const svalue *shift_sval = get_or_create_constant_svalue (shift_amt);
+  const svalue *shift_sval = get_or_create_int_cst (type, bit_offset);
   const svalue *shifted_sval = get_or_create_binop (type, LSHIFT_EXPR,
 						    lhs, shift_sval);
   /* Reapply the mask (needed for negative
diff --git a/gcc/analyzer/region-model.cc b/gcc/analyzer/region-model.cc
index e02a89765f0..462fe6d8b3c 100644
--- a/gcc/analyzer/region-model.cc
+++ b/gcc/analyzer/region-model.cc
@@ -1259,8 +1259,8 @@ region_model::on_setjmp (const gcall *call, const exploded_node *enode,
   /* Direct calls to setjmp return 0.  */
   if (tree lhs = gimple_call_lhs (call))
     {
-      tree zero = build_int_cst (TREE_TYPE (lhs), 0);
-      const svalue *new_sval = m_mgr->get_or_create_constant_svalue (zero);
+      const svalue *new_sval
+	= m_mgr->get_or_create_int_cst (TREE_TYPE (lhs), 0);
       const region *lhs_reg = get_lvalue (lhs, ctxt);
       set_value (lhs_reg, new_sval, ctxt);
     }
@@ -1291,15 +1291,14 @@ region_model::on_longjmp (const gcall *longjmp_call, const gcall *setjmp_call,
   if (tree lhs = gimple_call_lhs (setjmp_call))
     {
       /* Passing 0 as the val to longjmp leads to setjmp returning 1.  */
-      tree t_zero = build_int_cst (TREE_TYPE (fake_retval), 0);
-      const svalue *zero_sval = m_mgr->get_or_create_constant_svalue (t_zero);
+      const svalue *zero_sval
+	= m_mgr->get_or_create_int_cst (TREE_TYPE (fake_retval), 0);
       tristate eq_zero = eval_condition (fake_retval_sval, EQ_EXPR, zero_sval);
       /* If we have 0, use 1.  */
       if (eq_zero.is_true ())
 	{
-	  tree t_one = build_int_cst (TREE_TYPE (fake_retval), 1);
 	  const svalue *one_sval
-	    = m_mgr->get_or_create_constant_svalue (t_one);
+	    = m_mgr->get_or_create_int_cst (TREE_TYPE (fake_retval), 1);
 	  fake_retval_sval = one_sval;
 	}
       else
diff --git a/gcc/analyzer/region-model.h b/gcc/analyzer/region-model.h
index 7b12d35ab59..a4b584d186e 100644
--- a/gcc/analyzer/region-model.h
+++ b/gcc/analyzer/region-model.h
@@ -238,6 +238,7 @@ public:
 
   /* svalue consolidation.  */
   const svalue *get_or_create_constant_svalue (tree cst_expr);
+  const svalue *get_or_create_int_cst (tree type, poly_int64);
   const svalue *get_or_create_unknown_svalue (tree type);
   const svalue *get_or_create_setjmp_svalue (const setjmp_record &r,
 					     tree type);
diff --git a/gcc/analyzer/store.cc b/gcc/analyzer/store.cc
index d75fb2c4c7a..b643b631863 100644
--- a/gcc/analyzer/store.cc
+++ b/gcc/analyzer/store.cc
@@ -1043,8 +1043,8 @@ binding_cluster::zero_fill_region (store_manager *mgr, const region *reg)
 
   /* Add a default binding to zero.  */
   region_model_manager *sval_mgr = mgr->get_svalue_manager ();
-  tree cst_zero = build_int_cst (integer_type_node, 0);
-  const svalue *cst_sval = sval_mgr->get_or_create_constant_svalue (cst_zero);
+  const svalue *cst_sval
+    = sval_mgr->get_or_create_int_cst (integer_type_node, 0);
   const svalue *bound_sval = cst_sval;
   if (reg->get_type ())
     bound_sval = sval_mgr->get_or_create_unaryop (reg->get_type (), NOP_EXPR,


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2021-06-18 15:20 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-18 15:20 [gcc r12-1647] analyzer: add region_model_manager::get_or_create_int_cst David Malcolm

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).