]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
analyzer: add region_model_manager::get_or_create_int_cst
authorDavid Malcolm <dmalcolm@redhat.com>
Fri, 18 Jun 2021 15:19:30 +0000 (11:19 -0400)
committerDavid Malcolm <dmalcolm@redhat.com>
Fri, 18 Jun 2021 15:19:30 +0000 (11:19 -0400)
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>
gcc/analyzer/region-model-manager.cc
gcc/analyzer/region-model.cc
gcc/analyzer/region-model.h
gcc/analyzer/store.cc

index 621eff0e13953085fbafc0212fd02c48892994eb..1ee6663f05e76bbfe5ae6f9219f939113dee0c2c 100644 (file)
@@ -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
index e02a89765f0c79104e8aadb6f6332c9a8df336a2..462fe6d8b3c32abf1ecfc16defb79bf9c98514ec 100644 (file)
@@ -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
index 7b12d35ab597a4480122df9e9aa68f47c3785809..a4b584d186e258e46c3c563a7264d6f3ef9598dd 100644 (file)
@@ -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);
index d75fb2c4c7a27582c2fd20f0d58d734fb668d442..b643b63186353773eb4b7ffc753d9039c63312c9 100644 (file)
@@ -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,