diff options
author | Martin Uecker <uecker@tugraz.at> | 2024-10-22 23:25:00 +0200 |
---|---|---|
committer | Martin Uecker <uecker@gcc.gnu.org> | 2024-10-31 19:32:21 +0100 |
commit | 9eae9268e41463927c9383004e58708048ec379f (patch) | |
tree | 91a4264895e89e0f314347a362ffb85ee5095cb9 /gcc/c/c-parser.cc | |
parent | 241d419c46f381f9351b1957d7d34f177e0303ba (diff) | |
download | gcc-9eae9268e41463927c9383004e58708048ec379f.zip gcc-9eae9268e41463927c9383004e58708048ec379f.tar.gz gcc-9eae9268e41463927c9383004e58708048ec379f.tar.bz2 |
c: detect variably-modified types [PR117145,PR117245,PR100420]
This fixes two cases where variably-modified types were not recognized as
such. The first is when building composite types and the other when a type
is reconstructed for the 'vector' attribute. Construction of types in
the C FE is reorganized to use c_build_* functions which are responsible for
setting C_TYPE_VARIABLE_SIZE, C_TYPE_VARIABLY_MODIFIED and TYPE_TYPELESS_STORAGE
based on the properties of the type itself and these replace all other logic
elsewhere (e.g. in grokdeclarator). A new 'c_reconstruct_complex_type' based
on these functions is introduced which is called via a language hook when the
'vector' attribute is processed (as for C++).
One problem is are arrays of unspecified size 'T[*]' which were represented
identically to zero-sized arrays but with C_TYPE_VARIABLE_SIZE set. To avoid
having to create distinct type copies for this, the representation was changed
to make it a natural VLA by giving it an upper bound of '(0, 0)'. This also
then allows fixing of PR100420 where such arrays were printed as 'T[0]'.
Finally, a new function 'c_verify_type' checks consistency of properties
specific to C FE and is called when checking is on.
PR c/117145
PR c/117245
PR c/100420
gcc/c/ChangeLog:
* c-decl.cc (c_build_pointer_type): Move to c-typeck.cc
(grokdeclarator): Simplify logic.
(match_builtin_function_types): Adapt.
(push_decl): Adapt.
(implicitly_declare): Adapt.
(c_update_type_canonical): Adapt.
(c_make_fname_decl): Adapt.
(start_function): Adapt.
* c-objc-common.h: Add LANG_HOOKS_RECONSTRUCT_COMPLEX_TYPE.
* c-tree.h: Add prototypes.
* c-typeck.cc (c_verify_type): New function.
(c_set_type_bits). New function.
(c_build_pointer_type): Moved from c-decl.cc.
(c_build_pointer_type_for_mode): New function.
(c_build_function_type): New function.
(c_build_array_type): New function.
(c_build_type_attribute_variant): New function.
(c_reconstruct_complex_type): New function.
(c_build_functype_attribute_variant): Renamed.
(array_to_pointer_conversion): Simplify logic.
(composite_type_internal): Simplify logic..
(build_unary_op): Simplify logic..
(comptypes_verify): Add checking assertions.
(c_build_qualified_type): Add checking assertions.
(c_build_function_call_vec): Adapt.
(qualify_type): Adapt.
(build_functype_attribute_variant): Adapt.
(common_pointer_type): Adapt.
(c_common_type): Adapt.
(convert_for_assignment): Adapt.
(type_or_builtin_type): Adapt.
(build_access_with_size_for_counted_by): Adapt.
(build_conditional_expr): Adapt.
(build_modify_expr): Adapt.
(build_binary_op): Adapt.
(build_omp_array_section): Adapt.
(handle_omp_array_sections): Adapt.
(c_finish_omp_clauses): Adapt.
* c-parser.cc (c_parser_typeof_specifier): Adapt.
(c_parser_generic_selection): Adapt.
gcc/c-family/ChangeLog:
* c-pretty-print.cc (c_pretty_printer::direct_abstract_declarator):
Detect arrays of unspecified size.
gcc/testsuite/ChangeLog:
* gcc.dg/c23-tag-composite-11.c: New test.
* gcc.dg/Warray-parameter-4.c: Resolve xfails.
* gcc.dg/Wvla-parameter-2.c: Resolve xfails.
* gcc.dg/Wvla-parameter-3.c: Resolve xfails.
* gcc.dg/pr117145-1.c: New test.
* gcc.dg/pr117145-2.c: New test.
* gcc.dg/pr117245.c: New test.
Diffstat (limited to 'gcc/c/c-parser.cc')
-rw-r--r-- | gcc/c/c-parser.cc | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc index 90c3397..179c772 100644 --- a/gcc/c/c-parser.cc +++ b/gcc/c/c-parser.cc @@ -4417,7 +4417,7 @@ c_parser_typeof_specifier (c_parser *parser) else if (FUNCTION_POINTER_TYPE_P (ret.spec) && TYPE_QUALS (TREE_TYPE (ret.spec)) != TYPE_UNQUALIFIED) ret.spec - = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (ret.spec))); + = c_build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (ret.spec))); } } return ret; @@ -10700,7 +10700,7 @@ c_parser_generic_selection (c_parser *parser) if (FUNCTION_POINTER_TYPE_P (selector_type) && TYPE_QUALS (TREE_TYPE (selector_type)) != TYPE_UNQUALIFIED) selector_type - = build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type))); + = c_build_pointer_type (TYPE_MAIN_VARIANT (TREE_TYPE (selector_type))); } if (!c_parser_require (parser, CPP_COMMA, "expected %<,%>")) |