diff options
Diffstat (limited to 'gcc/tree.c')
-rw-r--r-- | gcc/tree.c | 35 |
1 files changed, 35 insertions, 0 deletions
@@ -15003,6 +15003,41 @@ default_is_empty_record (const_tree type) return default_is_empty_type (TYPE_MAIN_VARIANT (type)); } +/* Determine whether TYPE is a structure with a flexible array member, + or a union containing such a structure (possibly recursively). */ + +bool +flexible_array_type_p (const_tree type) +{ + tree x, last; + switch (TREE_CODE (type)) + { + case RECORD_TYPE: + last = NULL_TREE; + for (x = TYPE_FIELDS (type); x != NULL_TREE; x = DECL_CHAIN (x)) + if (TREE_CODE (x) == FIELD_DECL) + last = x; + if (last == NULL_TREE) + return false; + if (TREE_CODE (TREE_TYPE (last)) == ARRAY_TYPE + && TYPE_SIZE (TREE_TYPE (last)) == NULL_TREE + && TYPE_DOMAIN (TREE_TYPE (last)) != NULL_TREE + && TYPE_MAX_VALUE (TYPE_DOMAIN (TREE_TYPE (last))) == NULL_TREE) + return true; + return false; + case UNION_TYPE: + for (x = TYPE_FIELDS (type); x != NULL_TREE; x = DECL_CHAIN (x)) + { + if (TREE_CODE (x) == FIELD_DECL + && flexible_array_type_p (TREE_TYPE (x))) + return true; + } + return false; + default: + return false; + } +} + /* Like int_size_in_bytes, but handle empty records specially. */ HOST_WIDE_INT |