}
}
-/* Get the LEVEL of the strict_flex_array for the ARRAY_FIELD based on the
- values of attribute strict_flex_array and the flag_strict_flex_arrays. */
-unsigned int
-strict_flex_array_level_of (tree array_field)
-{
- gcc_assert (TREE_CODE (array_field) == FIELD_DECL);
- unsigned int strict_flex_array_level = flag_strict_flex_arrays;
-
- tree attr_strict_flex_array
- = lookup_attribute ("strict_flex_array", DECL_ATTRIBUTES (array_field));
- /* If there is a strict_flex_array attribute attached to the field,
- override the flag_strict_flex_arrays. */
- if (attr_strict_flex_array)
- {
- /* Get the value of the level first from the attribute. */
- unsigned HOST_WIDE_INT attr_strict_flex_array_level = 0;
- gcc_assert (TREE_VALUE (attr_strict_flex_array) != NULL_TREE);
- attr_strict_flex_array = TREE_VALUE (attr_strict_flex_array);
- gcc_assert (TREE_VALUE (attr_strict_flex_array) != NULL_TREE);
- attr_strict_flex_array = TREE_VALUE (attr_strict_flex_array);
- gcc_assert (tree_fits_uhwi_p (attr_strict_flex_array));
- attr_strict_flex_array_level = tree_to_uhwi (attr_strict_flex_array);
-
- /* The attribute has higher priority than flag_struct_flex_array. */
- strict_flex_array_level = attr_strict_flex_array_level;
- }
- return strict_flex_array_level;
-}
-
-
/* Return the access specification for a function parameter PARM
or null if the current function has no such specification. */
extern attr_access *get_parm_access (rdwr_map &, tree,
tree = current_function_decl);
-extern unsigned int strict_flex_array_level_of (tree);
-
#endif // GCC_ATTRIBS_H
}
}
+/* Get the LEVEL of the strict_flex_array for the ARRAY_FIELD based on the
+ values of attribute strict_flex_array and the flag_strict_flex_arrays. */
+static unsigned int
+strict_flex_array_level_of (tree array_field)
+{
+ gcc_assert (TREE_CODE (array_field) == FIELD_DECL);
+ unsigned int strict_flex_array_level = flag_strict_flex_arrays;
+
+ tree attr_strict_flex_array
+ = lookup_attribute ("strict_flex_array", DECL_ATTRIBUTES (array_field));
+ /* If there is a strict_flex_array attribute attached to the field,
+ override the flag_strict_flex_arrays. */
+ if (attr_strict_flex_array)
+ {
+ /* Get the value of the level first from the attribute. */
+ unsigned HOST_WIDE_INT attr_strict_flex_array_level = 0;
+ gcc_assert (TREE_VALUE (attr_strict_flex_array) != NULL_TREE);
+ attr_strict_flex_array = TREE_VALUE (attr_strict_flex_array);
+ gcc_assert (TREE_VALUE (attr_strict_flex_array) != NULL_TREE);
+ attr_strict_flex_array = TREE_VALUE (attr_strict_flex_array);
+ gcc_assert (tree_fits_uhwi_p (attr_strict_flex_array));
+ attr_strict_flex_array_level = tree_to_uhwi (attr_strict_flex_array);
+
+ /* The attribute has higher priority than flag_struct_flex_array. */
+ strict_flex_array_level = attr_strict_flex_array_level;
+ }
+ return strict_flex_array_level;
+}
/* Determine whether the FIELD_DECL X is a flexible array member according to
the following info:
/* Set to the type of the special array member for a COMPONENT_REF. */
special_array_member sam{ };
-
+ tree afield_decl = NULL_TREE;
tree arg = TREE_OPERAND (ref, 0);
- const bool compref = TREE_CODE (arg) == COMPONENT_REF;
- unsigned int strict_flex_array_level = flag_strict_flex_arrays;
- if (compref)
+ if (TREE_CODE (arg) == COMPONENT_REF)
{
/* Try to determine special array member type for this COMPONENT_REF. */
sam = component_ref_sam_type (arg);
- /* Get the level of strict_flex_array for this array field. */
- tree afield_decl = TREE_OPERAND (arg, 1);
- strict_flex_array_level = strict_flex_array_level_of (afield_decl);
+ afield_decl = TREE_OPERAND (arg, 1);
}
get_up_bounds_for_array_ref (ref, &decl, &up_bound, &up_bound_p1);
/* issue warnings for -Wstrict-flex-arrays according to the level of
flag_strict_flex_arrays. */
- if (out_of_bound && warn_strict_flex_arrays)
- switch (strict_flex_array_level)
- {
- case 3:
- /* Issue additional warnings for trailing arrays [0]. */
- if (sam == special_array_member::trail_0)
+ if ((out_of_bound && warn_strict_flex_arrays)
+ && (((sam == special_array_member::trail_0)
+ || (sam == special_array_member::trail_1)
+ || (sam == special_array_member::trail_n))
+ && DECL_NOT_FLEXARRAY (afield_decl)))
warned = warning_at (location, OPT_Wstrict_flex_arrays,
"trailing array %qT should not be used as "
- "a flexible array member for level 3",
+ "a flexible array member",
artype);
- /* FALLTHROUGH. */
- case 2:
- /* Issue additional warnings for trailing arrays [1]. */
- if (sam == special_array_member::trail_1)
- warned = warning_at (location, OPT_Wstrict_flex_arrays,
- "trailing array %qT should not be used as "
- "a flexible array member for level 2 and "
- "above", artype);
- /* FALLTHROUGH. */
- case 1:
- /* Issue warnings for trailing arrays [n]. */
- if (sam == special_array_member::trail_n)
- warned = warning_at (location, OPT_Wstrict_flex_arrays,
- "trailing array %qT should not be used as "
- "a flexible array member for level 1 and "
- "above", artype);
- break;
- case 0:
- /* Do nothing. */
- break;
- default:
- gcc_unreachable ();
- }
/* Avoid more warnings when checking more significant subscripts
of the same expression. */
struct trailing_array_4 *trailing_flex)
{
normal->c[5] = 5; /*{ dg-warning "array subscript 5 is above array bounds of" } */
- /*{ dg-warning "should not be used as a flexible array member for level 1 and above" "" { target *-*-* } .-1 } */
+ /*{ dg-warning "should not be used as a flexible array member" "" { target *-*-* } .-1 } */
trailing_1->c[2] = 2; /* { dg-bogus "array subscript " } */
trailing_0->c[1] = 1; /* { dg-bogus "array subscript " } */
trailing_flex->c[10] = 10; /* { dg-bogus "array subscript " } */
struct trailing_array_4 *trailing_flex)
{
normal->c[5] = 5; /*{ dg-warning "array subscript 5 is above array bounds of" } */
- /*{ dg-warning "should not be used as a flexible array member for level 1 and above" "" { target *-*-* } .-1 } */
+ /*{ dg-warning "should not be used as a flexible array member" "" { target *-*-* } .-1 } */
trailing_1->c[2] = 2; /* { dg-warning "array subscript 2 is above array bounds of" } */
- /* { dg-warning "should not be used as a flexible array member for level 2 and above" "" { target *-*-* } .-1 } */
+ /* { dg-warning "should not be used as a flexible array member" "" { target *-*-* } .-1 } */
trailing_0->c[1] = 1; /* { dg-bogus "array subscript " } */
trailing_flex->c[10] = 10; /* { dg-bogus "array subscript " } */
struct trailing_array_4 *trailing_flex)
{
normal->c[5] = 5; /*{ dg-warning "array subscript 5 is above array bounds of" } */
- /*{ dg-warning "should not be used as a flexible array member for level 1 and above" "" { target *-*-* } .-1 } */
+ /*{ dg-warning "should not be used as a flexible array member" "" { target *-*-* } .-1 } */
trailing_1->c[2] = 2; /*{ dg-warning "array subscript 2 is above array bounds of" } */
- /* { dg-warning "should not be used as a flexible array member for level 2 and above" "" { target *-*-* } .-1 } */
+ /* { dg-warning "should not be used as a flexible array member" "" { target *-*-* } .-1 } */
trailing_0->c[1] = 1; /*{ dg-warning "array subscript 1 is outside array bounds of" } */
- /* { dg-warning "should not be used as a flexible array member for level 3" "" { target *-*-* } .-1 } */
+ /* { dg-warning "should not be used as a flexible array member" "" { target *-*-* } .-1 } */
trailing_flex->c[10] = 10; /* { dg-bogus "array subscript" } */
}
struct trailing_array_4 *trailing_flex)
{
normal->c[5] = 5; /*{ dg-warning "array subscript 5 is above array bounds of" } */
- /*{ dg-warning "should not be used as a flexible array member for level 1 and above" "" { target *-*-* } .-1 } */
+ /*{ dg-warning "should not be used as a flexible array member" "" { target *-*-* } .-1 } */
trailing_1->c[2] = 2; /* { dg-bogus "array subscript " } */
trailing_0->c[1] = 1; /* { dg-bogus "array subscript " } */
trailing_flex->c[10] = 10; /* { dg-bogus "array subscript " } */
struct trailing_array_4 *trailing_flex)
{
normal->c[5] = 5; /*{ dg-warning "array subscript 5 is above array bounds of" } */
- /*{ dg-warning "should not be used as a flexible array member for level 1 and above" "" { target *-*-* } .-1 } */
+ /*{ dg-warning "should not be used as a flexible array member" "" { target *-*-* } .-1 } */
trailing_1->c[2] = 2; /*{ dg-warning "array subscript 2 is above array bounds of" } */
- /* { dg-warning "should not be used as a flexible array member for level 2 and above" "" { target *-*-* } .-1 } */
+ /* { dg-warning "should not be used as a flexible array member" "" { target *-*-* } .-1 } */
trailing_0->c[1] = 1; /* { dg-bogus "array subscript " } */
trailing_flex->c[10] = 10; /* { dg-bogus "array subscript " } */
struct trailing_array_4 *trailing_flex)
{
normal->c[5] = 5; /*{ dg-warning "array subscript 5 is above array bounds of" } */
- /*{ dg-warning "should not be used as a flexible array member for level 1 and above" "" { target *-*-* } .-1 } */
+ /*{ dg-warning "should not be used as a flexible array member" "" { target *-*-* } .-1 } */
trailing_1->c[2] = 2; /*{ dg-warning "array subscript 2 is above array bounds of" } */
- /* { dg-warning "should not be used as a flexible array member for level 2 and above" "" { target *-*-* } .-1 } */
+ /* { dg-warning "should not be used as a flexible array member" "" { target *-*-* } .-1 } */
trailing_0->c[1] = 1; /*{ dg-warning "array subscript 1 is outside array bounds of" } */
- /* { dg-warning "should not be used as a flexible array member for level 3" "" { target *-*-* } .-1 } */
+ /* { dg-warning "should not be used as a flexible array member" "" { target *-*-* } .-1 } */
trailing_flex->c[10] = 10; /* { dg-bogus "array subscript " } */
}
struct trailing_array_3 *trailing_0,
struct trailing_array_4 *trailing_flex)
{
- normal->c[5] = 5; /*{ dg-warning "should not be used as a flexible array member for level 1 and above" } */
- trailing_1->c[2] = 2; /* { dg-warning "should not be used as a flexible array member for level 2 and above" } */
- trailing_0->c[1] = 1; /* { dg-bogus "should not be used as a flexible array member for level 2 and above" } */
- trailing_flex->c[10] = 10; /* { dg-bogus "should not be used as a flexible array member for level 2 and above" } */
+ normal->c[5] = 5; /*{ dg-warning "should not be used as a flexible array member" } */
+ trailing_1->c[2] = 2; /* { dg-warning "should not be used as a flexible array member" } */
+ trailing_0->c[1] = 1; /* { dg-bogus "should not be used as a flexible array member" } */
+ trailing_flex->c[10] = 10; /* { dg-bogus "should not be used as a flexible array member" } */
}
struct trailing_array_3 *trailing_0,
struct trailing_array_4 *trailing_flex)
{
- normal->c[5] = 5; /*{ dg-warning "should not be used as a flexible array member for level 1 and above" } */
- trailing_1->c[2] = 2; /* { dg-warning "should not be used as a flexible array member for level 2 and above" } */
- trailing_0->c[1] = 1; /* { dg-warning "should not be used as a flexible array member for level 3" } */
- trailing_flex->c[10] = 10; /* { dg-bogus "should not be used as a flexible array member for level 3" } */
+ normal->c[5] = 5; /*{ dg-warning "should not be used as a flexible array member" } */
+ trailing_1->c[2] = 2; /* { dg-warning "should not be used as a flexible array member" } */
+ trailing_0->c[1] = 1; /* { dg-warning "should not be used as a flexible array member" } */
+ trailing_flex->c[10] = 10; /* { dg-bogus "should not be used as a flexible array member" } */
}
struct trailing_array_3 *trailing_0,
struct trailing_array_4 *trailing_flex)
{
- normal->c[5] = 5; /*{ dg-warning "should not be used as a flexible array member for level 1 and above" } */
- trailing_1->c[2] = 2; /* { dg-bogus "should not be used as a flexible array member for level 1 and above" } */
- trailing_0->c[1] = 1; /* { dg-bogus "should not be used as a flexible array member for level 1 and above" } */
- trailing_flex->c[10] = 10; /* { dg-bogus "should not be used as a flexible array member for level 1 and above" } */
+ normal->c[5] = 5; /*{ dg-warning "should not be used as a flexible array member" } */
+ trailing_1->c[2] = 2; /* { dg-bogus "should not be used as a flexible array member" } */
+ trailing_0->c[1] = 1; /* { dg-bogus "should not be used as a flexible array member" } */
+ trailing_flex->c[10] = 10; /* { dg-bogus "should not be used as a flexible array member" } */
}
|| *sam == special_array_member::trail_n)
return memsize;
- /* flag_strict_flex_arrays will control how to treat
- the trailing arrays as flexiable array members. */
-
tree afield_decl = TREE_OPERAND (ref, 1);
- unsigned int strict_flex_array_level
- = strict_flex_array_level_of (afield_decl);
-
- switch (strict_flex_array_level)
- {
- case 3:
- /* Treaing 0-length trailing arrays as normal array. */
- if (*sam == special_array_member::trail_0)
- return size_zero_node;
- /* FALLTHROUGH. */
- case 2:
- /* Treating 1-element trailing arrays as normal array. */
- if (*sam == special_array_member::trail_1)
- return memsize;
- /* FALLTHROUGH. */
- case 1:
- /* Treating 2-or-more elements trailing arrays as normal
- array. */
- if (*sam == special_array_member::trail_n)
- return memsize;
- /* FALLTHROUGH. */
- case 0:
- break;
- default:
- gcc_unreachable ();
- }
+ gcc_assert (TREE_CODE (afield_decl) == FIELD_DECL);
+ /* if the trailing array is a not a flexible array member, treat it as
+ a normal array. */
+ if (DECL_NOT_FLEXARRAY (afield_decl)
+ && *sam != special_array_member::int_0)
+ return memsize;
- if (*sam == special_array_member::int_0)
+ if (*sam == special_array_member::int_0)
memsize = NULL_TREE;
/* For a reference to a flexible array member of a union