diff options
author | Qing Zhao <qing.zhao@oracle.com> | 2023-06-29 17:07:08 +0000 |
---|---|---|
committer | Qing Zhao <qing.zhao@oracle.com> | 2023-06-29 17:13:09 +0000 |
commit | 3967da96556163d78cbeafe342c16b820aa85799 (patch) | |
tree | fb68c4f2731df7d84d6b05e1a826f6a5d09d2654 /gcc/c | |
parent | 6a1cf0d0d9cbf79f30aa5d76bca19615f12ea57f (diff) | |
download | gcc-3967da96556163d78cbeafe342c16b820aa85799.zip gcc-3967da96556163d78cbeafe342c16b820aa85799.tar.gz gcc-3967da96556163d78cbeafe342c16b820aa85799.tar.bz2 |
Introduce IR bit TYPE_INCLUDES_FLEXARRAY for the GCC extension
on a structure with a C99 flexible array member being nested in
another structure
GCC extension accepts the case when a struct with a flexible array member
is embedded into another struct or union (possibly recursively) as the last
field.
This patch is to introduce the IR bit TYPE_INCLUDES_FLEXARRAY (reuse the
existing IR bit TYPE_NO_NAMED_ARGS_SATDARG_P), set it correctly in C FE,
stream it correctly in Middle-end, and print it during IR dumping.
gcc/c/ChangeLog:
* c-decl.cc (finish_struct): Set TYPE_INCLUDES_FLEXARRAY for
struct/union type.
gcc/lto/ChangeLog:
* lto-common.cc (compare_tree_sccs_1): Compare bit
TYPE_NO_NAMED_ARGS_STDARG_P or TYPE_INCLUDES_FLEXARRAY properly
for its corresponding type.
gcc/ChangeLog:
* print-tree.cc (print_node): Print new bit type_include_flexarray.
* tree-core.h (struct tree_type_common): Use bit no_named_args_stdarg_p
as type_include_flexarray for RECORD_TYPE or UNION_TYPE.
* tree-streamer-in.cc (unpack_ts_type_common_value_fields): Stream
in bit no_named_args_stdarg_p properly for its corresponding type.
* tree-streamer-out.cc (pack_ts_type_common_value_fields): Stream
out bit no_named_args_stdarg_p properly for its corresponding type.
* tree.h (TYPE_INCLUDES_FLEXARRAY): New macro TYPE_INCLUDES_FLEXARRAY.
Diffstat (limited to 'gcc/c')
-rw-r--r-- | gcc/c/c-decl.cc | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc index 1af51c4..e14f514 100644 --- a/gcc/c/c-decl.cc +++ b/gcc/c/c-decl.cc @@ -9267,6 +9267,17 @@ finish_struct (location_t loc, tree t, tree fieldlist, tree attributes, /* Set DECL_NOT_FLEXARRAY flag for FIELD_DECL x. */ DECL_NOT_FLEXARRAY (x) = !is_flexible_array_member_p (is_last_field, x); + /* Set TYPE_INCLUDES_FLEXARRAY for the context of x, t. + when x is an array and is the last field. */ + if (TREE_CODE (TREE_TYPE (x)) == ARRAY_TYPE) + TYPE_INCLUDES_FLEXARRAY (t) + = is_last_field && flexible_array_member_type_p (TREE_TYPE (x)); + /* Recursively set TYPE_INCLUDES_FLEXARRAY for the context of x, t + when x is an union or record and is the last field. */ + else if (RECORD_OR_UNION_TYPE_P (TREE_TYPE (x))) + TYPE_INCLUDES_FLEXARRAY (t) + = is_last_field && TYPE_INCLUDES_FLEXARRAY (TREE_TYPE (x)); + if (DECL_NAME (x) || RECORD_OR_UNION_TYPE_P (TREE_TYPE (x))) saw_named_field = true; |