]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
range-ops: use const/static where possible
authorDavid Malcolm <dmalcolm@redhat.com>
Wed, 6 May 2026 14:22:57 +0000 (10:22 -0400)
committerDavid Malcolm <dmalcolm@redhat.com>
Wed, 6 May 2026 14:22:57 +0000 (10:22 -0400)
No functional change intended.

gcc/ChangeLog:
* range-op-float.cc (fop_unordered): Make static and const.
(fop_ordered): Likewise.
(fop_unordered_lt): Likewise.
(fop_unordered_le): Likewise.
(fop_unordered_gt): Likewise.
(fop_unordered_ge): Likewise.
(fop_unordered_equal): Likewise.
(fop_ltgt): Likewise.
(fop_div): Likewise.
* range-op-ptr.cc (op_pointer_plus): Likewise.
(op_pointer_diff): Likewise.
* range-op.cc (op_equal): Likewise.
(op_not_equal): Likewise.
(op_lt): Likewise.
(op_le): Likewise.
(op_gt): Likewise.
(op_ge): Likewise.
(op_ident): Likewise.
(op_cst): Likewise.
(op_cast): Likewise.
(op_view): Likewise.
(op_plus): Likewise.
(op_abs): Likewise.
(op_minus): Likewise.
(op_negate): Likewise.
(op_mult): Likewise.
(op_addr): Likewise.
(op_bitwise_not): Likewise.
(op_bitwise_xor): Likewise.
(op_bitwise_and): Likewise.
(op_bitwise_or): Likewise.
(op_min): Likewise.
(op_max): Likewise.
(operator_table): Make static.  Fix typo in comment.
(range_op_handler::range_op_handler): Fix typo in leading comment.
(range_op_handler::range_op): Make returned ptr const.  Use
nullptr.
(RO_III): Make static.
(RO_IFI): Likewise.
(RO_IFF): Likewise.
(RO_FFF): Likewise.
(RO_FIF): Likewise.
(RO_FII): Likewise.
(RO_PPP): Likewise.
(RO_PPI): Likewise.
(RO_IPP): Likewise.
(RO_IPI): Likewise.
(RO_PIP): Likewise.
(RO_PII): Likewise.
(op_trunc_div): Make const.
(op_floor_div): Likewise.
(op_round_div): Likewise.
(op_ceil_div): Likewise.
* range-op.h (range_op_handler::range_op): Make returned ptr
const.
(range_op_handler::m_operator): Make const.
(range_op_table::operator[]): Make const.  Make returned ptr
const.
(range_op_table::set): Make range_operator const.
(range_op_table::m_range_tree): Make ptrs const.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
gcc/range-op-float.cc
gcc/range-op-ptr.cc
gcc/range-op.cc
gcc/range-op.h

index 9e825f6b3eff010851435275ef27bb1c924d3f95..5d1273732b979fa2c79423083deb0bfe75d170af 100644 (file)
@@ -1356,7 +1356,8 @@ public:
   {
     return op1_range (r, type, lhs, op1, rel.swap_op1_op2 ());
   }
-} fop_unordered;
+};
+static const foperator_unordered fop_unordered;
 
 bool
 foperator_unordered::fold_range (irange &r, tree type,
@@ -1430,7 +1431,8 @@ public:
   {
     return op1_range (r, type, lhs, op1, rel.swap_op1_op2 ());
   }
-} fop_ordered;
+};
+static const foperator_ordered fop_ordered;
 
 bool
 foperator_ordered::fold_range (irange &r, tree type,
@@ -1652,7 +1654,8 @@ public:
                  const irange &lhs,
                  const frange &op1,
                  relation_trio trio) const final override;
-} fop_unordered_lt;
+};
+static const foperator_unordered_lt fop_unordered_lt;
 
 bool
 foperator_unordered_lt::op1_range (frange &r, tree type,
@@ -1762,7 +1765,8 @@ public:
   bool op2_range (frange &r, tree type,
                  const irange &lhs, const frange &op1,
                  relation_trio = TRIO_VARYING) const final override;
-} fop_unordered_le;
+};
+static const foperator_unordered_le fop_unordered_le;
 
 bool
 foperator_unordered_le::op1_range (frange &r, tree type,
@@ -1870,7 +1874,8 @@ public:
   bool op2_range (frange &r, tree type,
                  const irange &lhs, const frange &op1,
                  relation_trio = TRIO_VARYING) const final override;
-} fop_unordered_gt;
+};
+static const foperator_unordered_gt fop_unordered_gt;
 
 bool
 foperator_unordered_gt::op1_range (frange &r,
@@ -1982,7 +1987,8 @@ public:
   bool op2_range (frange &r, tree type,
                  const irange &lhs, const frange &op1,
                  relation_trio = TRIO_VARYING) const final override;
-} fop_unordered_ge;
+};
+static const foperator_unordered_ge fop_unordered_ge;
 
 bool
 foperator_unordered_ge::op1_range (frange &r,
@@ -2096,7 +2102,8 @@ public:
   {
     return op1_range (r, type, lhs, op1, rel.swap_op1_op2 ());
   }
-} fop_unordered_equal;
+};
+static const foperator_unordered_equal fop_unordered_equal;
 
 bool
 foperator_unordered_equal::op1_range (frange &r, tree type,
@@ -2178,7 +2185,8 @@ public:
   {
     return op1_range (r, type, lhs, op1, rel.swap_op1_op2 ());
   }
-} fop_ltgt;
+};
+static const foperator_ltgt fop_ltgt;
 
 bool
 foperator_ltgt::op1_range (frange &r, tree type,
@@ -2900,7 +2908,8 @@ private:
     gcc_checking_assert (!real_isnan (&ub));
     r.set (type, lb, ub, nan_state (maybe_nan));
   }
-} fop_div;
+};
+static const foperator_div fop_div;
 
 bool
 operator_cast::fold_range (frange &r, tree type, const frange &op1,
index ce23db08827defdd30e36d09504e8bc37d59265a..6461530a9a3127ae1bdde1388fb355c907536459 100644 (file)
@@ -318,7 +318,8 @@ public:
                                          relation_kind) const final override;
   void update_bitmask (prange &r, const prange &lh, const irange &rh) const
     { update_known_bitmask (r, POINTER_PLUS_EXPR, lh, rh); }
-} op_pointer_plus;
+};
+static const pointer_plus_operator op_pointer_plus;
 
 bool
 pointer_plus_operator::fold_range (prange &r, tree type,
@@ -475,7 +476,8 @@ class operator_pointer_diff : public range_operator
   void update_bitmask (irange &r,
                       const prange &lh, const prange &rh) const final override
   { update_known_bitmask (r, POINTER_DIFF_EXPR, lh, rh); }
-} op_pointer_diff;
+};
+static const operator_pointer_diff op_pointer_diff;
 
 bool
 operator_pointer_diff::fold_range (irange &r, tree type,
index 49738c792cf2d17020933f31ff0c656071b2706e..40c62c3a2d6f685ae035199ee550eee0e34bfeeb 100644 (file)
@@ -51,31 +51,31 @@ along with GCC; see the file COPYING3.  If not see
 
 // Instantiate the operators which apply to multiple types here.
 
-operator_equal op_equal;
-operator_not_equal op_not_equal;
-operator_lt op_lt;
-operator_le op_le;
-operator_gt op_gt;
-operator_ge op_ge;
-operator_identity op_ident;
-operator_cst op_cst;
-operator_cast op_cast;
-operator_view op_view;
-operator_plus op_plus;
-operator_abs op_abs;
-operator_minus op_minus;
-operator_negate op_negate;
-operator_mult op_mult;
-operator_addr_expr op_addr;
-operator_bitwise_not op_bitwise_not;
-operator_bitwise_xor op_bitwise_xor;
-operator_bitwise_and op_bitwise_and;
-operator_bitwise_or op_bitwise_or;
-operator_min op_min;
-operator_max op_max;
-
-// Instantaite a range operator table.
-range_op_table operator_table;
+static const operator_equal op_equal;
+static const operator_not_equal op_not_equal;
+static const operator_lt op_lt;
+static const operator_le op_le;
+static const operator_gt op_gt;
+static const operator_ge op_ge;
+static const operator_identity op_ident;
+static const operator_cst op_cst;
+static const operator_cast op_cast;
+static const operator_view op_view;
+static const operator_plus op_plus;
+static const operator_abs op_abs;
+static const operator_minus op_minus;
+static const operator_negate op_negate;
+static const operator_mult op_mult;
+static const operator_addr_expr op_addr;
+static const operator_bitwise_not op_bitwise_not;
+static const operator_bitwise_xor op_bitwise_xor;
+static const operator_bitwise_and op_bitwise_and;
+static const operator_bitwise_or op_bitwise_or;
+static const operator_min op_min;
+static const operator_max op_max;
+
+// Instantiate a range operator table.
+static range_op_table operator_table;
 
 // Invoke the initialization routines for each class of range.
 
@@ -126,7 +126,7 @@ range_op_handler::range_op_handler ()
   m_operator = &default_operator;
 }
 
-// Create a range_op_handler for CODE.  Use a default operatoer if CODE
+// Create a range_op_handler for CODE.  Use a default operator if CODE
 // does not have an entry.
 
 range_op_handler::range_op_handler (unsigned code)
@@ -144,15 +144,15 @@ range_op_handler::operator bool () const
 }
 
 // Return a pointer to the range operator assocaited with this handler.
-// If it is a default operator, return NULL.
+// If it is a default operator, return nullptr.
 // This is the equivalent of indexing the range table.
 
-range_operator *
+const range_operator *
 range_op_handler::range_op () const
 {
   if (m_operator != &default_operator)
     return m_operator;
-  return NULL;
+  return nullptr;
 }
 
 // Create a dispatch pattern for value range discriminators LHS, OP1, and OP2.
@@ -171,18 +171,18 @@ dispatch_trio (unsigned lhs, unsigned op1, unsigned op2)
 // Reminder, single operand instructions use the LHS type for op2, even if
 // unused.  So FLOAT = INT would be RO_FIF.
 
-const unsigned RO_III =        dispatch_trio (VR_IRANGE, VR_IRANGE, VR_IRANGE);
-const unsigned RO_IFI = dispatch_trio (VR_IRANGE, VR_FRANGE, VR_IRANGE);
-const unsigned RO_IFF = dispatch_trio (VR_IRANGE, VR_FRANGE, VR_FRANGE);
-const unsigned RO_FFF = dispatch_trio (VR_FRANGE, VR_FRANGE, VR_FRANGE);
-const unsigned RO_FIF = dispatch_trio (VR_FRANGE, VR_IRANGE, VR_FRANGE);
-const unsigned RO_FII = dispatch_trio (VR_FRANGE, VR_IRANGE, VR_IRANGE);
-const unsigned RO_PPP = dispatch_trio (VR_PRANGE, VR_PRANGE, VR_PRANGE);
-const unsigned RO_PPI = dispatch_trio (VR_PRANGE, VR_PRANGE, VR_IRANGE);
-const unsigned RO_IPP = dispatch_trio (VR_IRANGE, VR_PRANGE, VR_PRANGE);
-const unsigned RO_IPI = dispatch_trio (VR_IRANGE, VR_PRANGE, VR_IRANGE);
-const unsigned RO_PIP = dispatch_trio (VR_PRANGE, VR_IRANGE, VR_PRANGE);
-const unsigned RO_PII = dispatch_trio (VR_PRANGE, VR_IRANGE, VR_IRANGE);
+static const unsigned RO_III = dispatch_trio (VR_IRANGE, VR_IRANGE, VR_IRANGE);
+static const unsigned RO_IFI = dispatch_trio (VR_IRANGE, VR_FRANGE, VR_IRANGE);
+static const unsigned RO_IFF = dispatch_trio (VR_IRANGE, VR_FRANGE, VR_FRANGE);
+static const unsigned RO_FFF = dispatch_trio (VR_FRANGE, VR_FRANGE, VR_FRANGE);
+static const unsigned RO_FIF = dispatch_trio (VR_FRANGE, VR_IRANGE, VR_FRANGE);
+static const unsigned RO_FII = dispatch_trio (VR_FRANGE, VR_IRANGE, VR_IRANGE);
+static const unsigned RO_PPP = dispatch_trio (VR_PRANGE, VR_PRANGE, VR_PRANGE);
+static const unsigned RO_PPI = dispatch_trio (VR_PRANGE, VR_PRANGE, VR_IRANGE);
+static const unsigned RO_IPP = dispatch_trio (VR_IRANGE, VR_PRANGE, VR_PRANGE);
+static const unsigned RO_IPI = dispatch_trio (VR_IRANGE, VR_PRANGE, VR_IRANGE);
+static const unsigned RO_PIP = dispatch_trio (VR_PRANGE, VR_IRANGE, VR_PRANGE);
+static const unsigned RO_PII = dispatch_trio (VR_PRANGE, VR_IRANGE, VR_IRANGE);
 
 // Return a dispatch value for parameter types LHS, OP1 and OP2.
 
@@ -2497,10 +2497,10 @@ protected:
   tree_code m_code;
 };
 
-static operator_div op_trunc_div (TRUNC_DIV_EXPR);
-static operator_div op_floor_div (FLOOR_DIV_EXPR);
-static operator_div op_round_div (ROUND_DIV_EXPR);
-static operator_div op_ceil_div (CEIL_DIV_EXPR);
+static const operator_div op_trunc_div (TRUNC_DIV_EXPR);
+static const operator_div op_floor_div (FLOOR_DIV_EXPR);
+static const operator_div op_round_div (ROUND_DIV_EXPR);
+static const operator_div op_ceil_div (CEIL_DIV_EXPR);
 
 // Set OP2 to non-zero if the LHS isn't UNDEFINED.
 bool
index 1fd84ca07131660277f64af0100567959ccd68c8..36e99a6f91289aa97fd16b34dfe5e10f45405bb3 100644 (file)
@@ -304,7 +304,7 @@ public:
   range_op_handler ();
   range_op_handler (unsigned);
   operator bool () const;
-  range_operator *range_op () const;
+  const range_operator *range_op () const;
 
   bool fold_range (vrange &r, tree type,
                   const vrange &lh,
@@ -338,7 +338,7 @@ protected:
   void discriminator_fail (const vrange &,
                           const vrange &,
                           const vrange &) const;
-  range_operator *m_operator;
+  const range_operator *m_operator;
 };
 
 // Cast the range in R to TYPE if R supports TYPE.
@@ -404,19 +404,19 @@ class range_op_table
 {
 public:
   range_op_table ();
-  inline range_operator *operator[] (unsigned code)
+  inline const range_operator *operator[] (unsigned code) const
     {
       gcc_checking_assert (code < RANGE_OP_TABLE_SIZE);
       return m_range_tree[code];
     }
 protected:
-  inline void set (unsigned code, range_operator &op)
+  inline void set (unsigned code, const range_operator &op)
     {
       gcc_checking_assert (code < RANGE_OP_TABLE_SIZE);
       gcc_checking_assert (m_range_tree[code] == NULL);
       m_range_tree[code] = &op;
     }
-  range_operator *m_range_tree[RANGE_OP_TABLE_SIZE];
+  const range_operator *m_range_tree[RANGE_OP_TABLE_SIZE];
   void initialize_integral_ops ();
   void initialize_pointer_ops ();
   void initialize_float_ops ();