aboutsummaryrefslogtreecommitdiff
path: root/gcc/c-family/c-attribs.cc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/c-family/c-attribs.cc')
-rw-r--r--gcc/c-family/c-attribs.cc47
1 files changed, 47 insertions, 0 deletions
diff --git a/gcc/c-family/c-attribs.cc b/gcc/c-family/c-attribs.cc
index 671ea38..92ac93b 100644
--- a/gcc/c-family/c-attribs.cc
+++ b/gcc/c-family/c-attribs.cc
@@ -101,6 +101,8 @@ static tree handle_special_var_sec_attribute (tree *, tree, tree, int, bool *);
static tree handle_aligned_attribute (tree *, tree, tree, int, bool *);
static tree handle_warn_if_not_aligned_attribute (tree *, tree, tree,
int, bool *);
+static tree handle_strict_flex_array_attribute (tree *, tree, tree,
+ int, bool *);
static tree handle_weak_attribute (tree *, tree, tree, int, bool *) ;
static tree handle_noplt_attribute (tree *, tree, tree, int, bool *) ;
static tree handle_alias_ifunc_attribute (bool, tree *, tree, tree, bool *);
@@ -369,6 +371,8 @@ const struct attribute_spec c_common_attribute_table[] =
attr_aligned_exclusions },
{ "warn_if_not_aligned", 0, 1, false, false, false, false,
handle_warn_if_not_aligned_attribute, NULL },
+ { "strict_flex_array", 1, 1, true, false, false, false,
+ handle_strict_flex_array_attribute, NULL },
{ "weak", 0, 0, true, false, false, false,
handle_weak_attribute, NULL },
{ "noplt", 0, 0, true, false, false, false,
@@ -2508,6 +2512,49 @@ handle_warn_if_not_aligned_attribute (tree *node, tree name,
no_add_attrs, true);
}
+/* Handle a "strict_flex_array" attribute; arguments as in
+ struct attribute_spec.handler. */
+
+static tree
+handle_strict_flex_array_attribute (tree *node, tree name,
+ tree args, int ARG_UNUSED (flags),
+ bool *no_add_attrs)
+{
+ tree decl = *node;
+ tree argval = TREE_VALUE (args);
+
+ /* This attribute only applies to field decls of a structure. */
+ if (TREE_CODE (decl) != FIELD_DECL)
+ {
+ error_at (DECL_SOURCE_LOCATION (decl),
+ "%qE attribute may not be specified for %q+D", name, decl);
+ *no_add_attrs = true;
+ }
+ /* This attribute only applies to field with array type. */
+ else if (TREE_CODE (TREE_TYPE (decl)) != ARRAY_TYPE)
+ {
+ error_at (DECL_SOURCE_LOCATION (decl),
+ "%qE attribute may not be specified for a non-array field",
+ name);
+ *no_add_attrs = true;
+ }
+ else if (TREE_CODE (argval) != INTEGER_CST)
+ {
+ error_at (DECL_SOURCE_LOCATION (decl),
+ "%qE attribute argument not an integer", name);
+ *no_add_attrs = true;
+ }
+ else if (!tree_fits_uhwi_p (argval) || tree_to_uhwi (argval) > 3)
+ {
+ error_at (DECL_SOURCE_LOCATION (decl),
+ "%qE attribute argument %qE is not an integer constant"
+ " between 0 and 3", name, argval);
+ *no_add_attrs = true;
+ }
+
+ return NULL_TREE;
+}
+
/* Handle a "weak" attribute; arguments as in
struct attribute_spec.handler. */