}
/* 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. */
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
/* 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. */
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
|| !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;
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);
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
&& 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
}
/* 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)))
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;
}
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;
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);
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, a component reference,
+ or a 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;
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;
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. */
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
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. */