]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Change the name of array_at_struct_end_p to array_ref_flexible_size_p
authorQing Zhao <qing.zhao@oracle.com>
Wed, 9 Nov 2022 15:48:04 +0000 (15:48 +0000)
committerQing Zhao <qing.zhao@oracle.com>
Wed, 9 Nov 2022 15:48:04 +0000 (15:48 +0000)
The name of the utility routine "array_at_struct_end_p" is misleading
and should be changed to a new name that more accurately reflects its
real meaning.

The routine "array_at_struct_end_p" is used to check whether an array
reference is to an array whose actual size might be larger than its
upper bound implies, which includes 3 different cases:

   A. a ref to a flexible array member at the end of a structure;
   B. a ref to an array with a different type against the original decl;
   C. a ref to an array that was passed as a parameter;

The old name only reflects the above case A, therefore very confusing
when reading the corresponding gcc source code.

In this patch, A new name "array_ref_flexible_size_p" is used to replace
the old name.

All the references to the routine "array_at_struct_end_p" was replaced
with this new name, and the corresponding comments were updated to make
them clean and consistent.

gcc/ChangeLog:

* gimple-array-bounds.cc (trailing_array): Replace
array_at_struct_end_p with new name and update comments.
* gimple-fold.cc (get_range_strlen_tree): Likewise.
* gimple-ssa-warn-restrict.cc (builtin_memref::builtin_memref):
Likewise.
* graphite-sese-to-poly.cc (bounds_are_valid): Likewise.
* tree-if-conv.cc (idx_within_array_bound): Likewise.
* tree-object-size.cc (addr_object_size): Likewise.
* tree-ssa-alias.cc (component_ref_to_zero_sized_trailing_array_p):
Likewise.
(stmt_kills_ref_p): Likewise.
* tree-ssa-loop-niter.cc (idx_infer_loop_bounds): Likewise.
* tree-ssa-strlen.cc (maybe_set_strlen_range): Likewise.
* tree.cc (array_at_struct_end_p): Rename to ...
(array_ref_flexible_size_p): ... this.
(component_ref_size): Replace array_at_struct_end_p with new name.
* tree.h (array_at_struct_end_p): Rename to ...
(array_ref_flexible_size_p): ... this.

gcc/gimple-array-bounds.cc
gcc/gimple-fold.cc
gcc/gimple-ssa-warn-restrict.cc
gcc/graphite-sese-to-poly.cc
gcc/tree-if-conv.cc
gcc/tree-object-size.cc
gcc/tree-ssa-alias.cc
gcc/tree-ssa-loop-niter.cc
gcc/tree-ssa-strlen.cc
gcc/tree.cc
gcc/tree.h

index e190b93aa85310b47bcf6623593c5d3dbe7abbff..fbf448e045df4c208b7e118f7e08242576a80184 100644 (file)
@@ -129,7 +129,7 @@ get_ref_size (tree arg, tree *pref)
 }
 
 /* Return true if REF is (likely) an ARRAY_REF to a trailing array member
-   of a struct.  It refines array_at_struct_end_p by detecting a pointer
+   of a struct.  It refines array_ref_flexible_size_p by detecting a pointer
    to an array and an array parameter declared using the [N] syntax (as
    opposed to a pointer) and returning false.  Set *PREF to the decl or
    expression REF refers to.  */
@@ -167,7 +167,7 @@ trailing_array (tree arg, tree *pref)
        return false;
     }
 
-  return array_at_struct_end_p (arg);
+  return array_ref_flexible_size_p (arg);
 }
 
 /* Checks one ARRAY_REF in REF, located at LOCUS. Ignores flexible
index 410544c17bb12983c9c3745440df4329ad833a49..8d4079870be53cce902e8368cf973ab87e775d11 100644 (file)
@@ -1690,13 +1690,11 @@ get_range_strlen_tree (tree arg, bitmap visited, strlen_range_kind rkind,
          /* Handle a MEM_REF into a DECL accessing an array of integers,
             being conservative about references to extern structures with
             flexible array members that can be initialized to arbitrary
-            numbers of elements as an extension (static structs are okay).
-            FIXME: Make this less conservative -- see
-            component_ref_size in tree.cc.  */
+            numbers of elements as an extension (static structs are okay).  */
          tree ref = TREE_OPERAND (TREE_OPERAND (arg, 0), 0);
          if ((TREE_CODE (ref) == PARM_DECL || VAR_P (ref))
              && (decl_binds_to_current_def_p (ref)
-                 || !array_at_struct_end_p (arg)))
+                 || !array_ref_flexible_size_p (arg)))
            {
              /* Fail if the offset is out of bounds.  Such accesses
                 should be diagnosed at some point.  */
index b7ed15c8902cf80761eefe0f050ed575d6b95d83..832456ba6fce2f9e614e1bdf1c28612b6ddfe221 100644 (file)
@@ -296,8 +296,9 @@ builtin_memref::builtin_memref (pointer_query &ptrqry, gimple *stmt, tree expr,
   tree basetype = TREE_TYPE (base);
   if (TREE_CODE (basetype) == ARRAY_TYPE)
     {
-      if (ref && array_at_struct_end_p (ref))
-       ;   /* Use the maximum possible offset for last member arrays.  */
+      if (ref && array_ref_flexible_size_p (ref))
+       ;   /* Use the maximum possible offset for an array that might
+              have flexible size.  */
       else if (tree basesize = TYPE_SIZE_UNIT (basetype))
        if (TREE_CODE (basesize) == INTEGER_CST)
          /* Size could be non-constant for a variable-length type such
index 51ba3af204f2d3f7684a420552ad27bf9da2d736..7eb24c1c991b5e153f66a58509b2a9ec13d972d2 100644 (file)
@@ -536,9 +536,9 @@ bounds_are_valid (tree ref, tree low, tree high)
       || !tree_fits_shwi_p (high))
     return false;
 
-  /* 1-element arrays at end of structures may extend over
+  /* An array that has flexible size may extend over
      their declared size.  */
-  if (array_at_struct_end_p (ref)
+  if (array_ref_flexible_size_p (ref)
       && operand_equal_p (low, high, 0))
     return false;
 
index a83b013d2ad3d9066b1c2bc62282ec054483598f..34bb507ff3ba6a1b97a465d5f1a11ca5b4f90658 100644 (file)
@@ -763,10 +763,9 @@ idx_within_array_bound (tree ref, tree *idx, void *dta)
   if (TREE_CODE (ref) != ARRAY_REF)
     return false;
 
-  /* For arrays at the end of the structure, we are not guaranteed that they
-     do not really extend over their declared size.  However, for arrays of
-     size greater than one, this is unlikely to be intended.  */
-  if (array_at_struct_end_p (ref))
+  /* For arrays that might have flexible sizes, it is not guaranteed that they
+     do not extend over their declared size.  */
+  if (array_ref_flexible_size_p (ref))
     return false;
 
   ev = analyze_scalar_evolution (loop, *idx);
index 1f04cb80fd0a3dfea17687c8e0de1ae892955145..2e5d267d8ce23a03dfab12feaaf86455da14fbc0 100644 (file)
@@ -633,7 +633,7 @@ addr_object_size (struct object_size_info *osi, const_tree ptr,
                        v = NULL_TREE;
                        break;
                      }
-                   is_flexible_array_mem_ref = array_at_struct_end_p (v);
+                   is_flexible_array_mem_ref = array_ref_flexible_size_p (v);
                    while (v != pt_var && TREE_CODE (v) == COMPONENT_REF)
                      if (TREE_CODE (TREE_TYPE (TREE_OPERAND (v, 0)))
                          != UNION_TYPE
index b4c65da5718b61b6ee628765af7a1ac373508fad..d3a91b1f2385c9a7212df8e89cc0dc8200a3ebad 100644 (file)
@@ -1073,7 +1073,7 @@ component_ref_to_zero_sized_trailing_array_p (tree ref)
          && TREE_CODE (TREE_TYPE (TREE_OPERAND (ref, 1))) == ARRAY_TYPE
          && (!TYPE_SIZE (TREE_TYPE (TREE_OPERAND (ref, 1)))
              || integer_zerop (TYPE_SIZE (TREE_TYPE (TREE_OPERAND (ref, 1)))))
-         && array_at_struct_end_p (ref));
+         && array_ref_flexible_size_p (ref));
 }
 
 /* Worker for aliasing_component_refs_p. Most parameters match parameters of
@@ -3433,10 +3433,10 @@ stmt_kills_ref_p (gimple *stmt, ao_ref *ref)
            }
          /* Finally check if the lhs has the same address and size as the
             base candidate of the access.  Watch out if we have dropped
-            an array-ref that was at struct end, this means ref->ref may
-            be outside of the TYPE_SIZE of its base.  */
+            an array-ref that might have flexible size, this means ref->ref
+            may be outside of the TYPE_SIZE of its base.  */
          if ((! innermost_dropped_array_ref
-              || ! array_at_struct_end_p (innermost_dropped_array_ref))
+              || ! array_ref_flexible_size_p (innermost_dropped_array_ref))
              && (lhs == base
                  || (((TYPE_SIZE (TREE_TYPE (lhs))
                        == TYPE_SIZE (TREE_TYPE (base)))
index 4ffcef4f4ff2fe182fbe711553c8e4575560ab07..3fbbf4367ed1bda2bd38e0578c590cfdd2b9a351 100644 (file)
@@ -3716,18 +3716,17 @@ idx_infer_loop_bounds (tree base, tree *idx, void *dta)
   struct ilb_data *data = (struct ilb_data *) dta;
   tree ev, init, step;
   tree low, high, type, next;
-  bool sign, upper = true, at_end = false;
+  bool sign, upper = true, has_flexible_size = false;
   class loop *loop = data->loop;
 
   if (TREE_CODE (base) != ARRAY_REF)
     return true;
 
-  /* For arrays at the end of the structure, we are not guaranteed that they
-     do not really extend over their declared size.  However, for arrays of
-     size greater than one, this is unlikely to be intended.  */
-  if (array_at_struct_end_p (base))
+  /* For arrays that might have flexible sizes, it is not guaranteed that they
+     do not really extend over their declared size.  */ 
+  if (array_ref_flexible_size_p (base))
     {
-      at_end = true;
+      has_flexible_size = true;
       upper = false;
     }
 
@@ -3760,9 +3759,9 @@ idx_infer_loop_bounds (tree base, tree *idx, void *dta)
   sign = tree_int_cst_sign_bit (step);
   type = TREE_TYPE (step);
 
-  /* The array of length 1 at the end of a structure most likely extends
+  /* The array that might have flexible size most likely extends
      beyond its bounds.  */
-  if (at_end
+  if (has_flexible_size
       && operand_equal_p (low, high, 0))
     return true;
 
index 5afbae1b72e324b4c9102b877cd0ca5d1da3c971..b87c7c7ce1f73ad84cb5b2bf9745eafbca81f60f 100644 (file)
@@ -1987,7 +1987,7 @@ maybe_set_strlen_range (tree lhs, tree src, tree bound)
         suggests if it's treated as a poor-man's flexible array member.  */
       src = TREE_OPERAND (src, 0);
       if (TREE_CODE (src) != MEM_REF
-         && !array_at_struct_end_p (src))
+         && !array_ref_flexible_size_p (src))
        {
          tree type = TREE_TYPE (src);
          tree size = TYPE_SIZE_UNIT (type);
index 172098787dd924ec23101e7495cf0e67ca47d787..574bd2e65d976d9654894fa936c1f62890f296b1 100644 (file)
@@ -12727,8 +12727,8 @@ array_ref_up_bound (tree exp)
   return NULL_TREE;
 }
 
-/* Returns true if REF is an array reference, component reference,
-   or memory reference to an array whose actual size might be larger
+/* Returns true if REF is an array reference, component reference,
+   or memory reference to an array whose actual size might be larger
    than its upper bound implies, there are multiple cases:
    A. a ref to a flexible array member at the end of a structure;
    B. a ref to an array with a different type against the original decl;
@@ -12743,10 +12743,10 @@ array_ref_up_bound (tree exp)
    int test (uint8_t *p, uint32_t t[1][1], int n) {
    for (int i = 0; i < 4; i++, p++)
      t[i][0] = ...;
+*/
 
-   FIXME, the name of this routine need to be changed to be more accurate.  */
 bool
-array_at_struct_end_p (tree ref)
+array_ref_flexible_size_p (tree ref)
 {
   /* the TYPE for this array referece.  */
   tree atype = NULL_TREE;
@@ -12879,6 +12879,7 @@ array_at_struct_end_p (tree ref)
   return afield_decl ? !DECL_NOT_FLEXARRAY (afield_decl) : true;
 }
 
+
 /* Return a tree representing the offset, in bytes, of the field referenced
    by EXP.  This does not include any offset in DECL_FIELD_BIT_OFFSET.  */
 
@@ -12974,7 +12975,7 @@ component_ref_size (tree ref, special_array_member *sam /* = NULL */)
        return (tree_int_cst_equal (memsize, TYPE_SIZE_UNIT (memtype))
                ? memsize : NULL_TREE);
 
-      bool trailing = array_at_struct_end_p (ref);
+      bool trailing = array_ref_flexible_size_p (ref);
       bool zero_length = integer_zerop (memsize);
       if (!trailing && !zero_length)
        /* MEMBER is either an interior array or is an array with
index d6a5fdf6d81bf10044249c015083e6db8b35b519..a863d2e50e5ecafa3f5da4dda98d9637261d07a9 100644 (file)
@@ -5554,10 +5554,10 @@ extern tree array_ref_up_bound (tree);
    EXP, an ARRAY_REF or an ARRAY_RANGE_REF.  */
 extern tree array_ref_low_bound (tree);
 
-/* Returns true if REF is an array reference or a component reference
-   to an array at the end of a structure.  If this is the case, the array
-   may be allocated larger than its upper bound implies.  */
-extern bool array_at_struct_end_p (tree);
+/* Returns true if REF is an array reference, a component reference,
+   or a memory reference to an array whose actual size might be larger
+   than its upper bound implies.  */
+extern bool array_ref_flexible_size_p (tree);
 
 /* Return a tree representing the offset, in bytes, of the field referenced
    by EXP.  This does not include any offset in DECL_FIELD_BIT_OFFSET.  */