diff options
author | Martin Uecker <uecker@tugraz.at> | 2023-02-15 10:54:00 +0100 |
---|---|---|
committer | Martin Uecker <uecker@tugraz.at> | 2023-02-18 10:39:01 +0100 |
commit | 47821ba07a19b672d3cba351a03af2b122e02213 (patch) | |
tree | 51bd978038361d057159355eacc58f4561f4e852 /gcc/c/c-parser.cc | |
parent | 3057d7928c0dbc78dbf748c9621ccd102e06beee (diff) | |
download | gcc-47821ba07a19b672d3cba351a03af2b122e02213.zip gcc-47821ba07a19b672d3cba351a03af2b122e02213.tar.gz gcc-47821ba07a19b672d3cba351a03af2b122e02213.tar.bz2 |
C: Detect all variably modified types [PR108375]
Some variably modified types were not detected correctly.
Define C_TYPE_VARIABLY_MODIFIED via TYPE_LANG_FLAG 6 in the CFE.
This flag records whether a type is variably modified and is
set for all such types including arrays with variably modified
element type or structures and unions with variably modified
members. This is then used to detect such types in the C FE
and middle-end (via the existing language hook).
gcc/c/ChangeLog:
PR c/108375
* c-decl.cc (decl_jump_unsafe): Use c_type_variably_modified_p.
(diagnose_mismatched_decl): Dito.
(warn_about_goto): Dito:
(c_check_switch_jump_warnings): Dito.
(finish_decl): Dito.
(finish_struct): Dito.
(grokdeclarator): Set C_TYPE_VARIABLY_MODIFIED.
(finish_struct): Set C_TYPE_VARIABLY_MODIFIED.
* c-objc-common.cc (c_var_mod_p): New function.
(c_var_unspec_p): Remove.
* c-objc-common.h: Set lang hook.
* c-parser.cc (c_parser_declararion_or_fndef): Use c_type_variably_modified_p.
(c_parser_typeof_specifier): Dito.
(c_parser_has_attribute_expression): Dito.
(c_parser_generic_selection): Dito.
* c-tree.h: Define C_TYPE_VARIABLY_MODIFIED and define c_var_mode_p.
* c-typeck.cc: Remove c_vla_mod_p and use C_TYPE_VARIABLY_MODIFIED.
gcc/testsuite/ChangeLog:
PR c/108375
* gcc.dg/pr108375-1.c: New test.
* gcc.dg/pr108375-2.c: New test.
Diffstat (limited to 'gcc/c/c-parser.cc')
-rw-r--r-- | gcc/c/c-parser.cc | 13 |
1 files changed, 6 insertions, 7 deletions
diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc index 4342788..21bc316 100644 --- a/gcc/c/c-parser.cc +++ b/gcc/c/c-parser.cc @@ -2494,8 +2494,7 @@ c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok, init = convert_lvalue_to_rvalue (init_loc, init, true, true, true); tree init_type = TREE_TYPE (init.value); - bool vm_type = variably_modified_type_p (init_type, - NULL_TREE); + bool vm_type = c_type_variably_modified_p (init_type); if (vm_type) init.value = save_expr (init.value); finish_init (); @@ -4143,7 +4142,7 @@ c_parser_typeof_specifier (c_parser *parser) if (type != NULL) { ret.spec = groktypename (type, &ret.expr, &ret.expr_const_operands); - pop_maybe_used (variably_modified_type_p (ret.spec, NULL_TREE)); + pop_maybe_used (c_type_variably_modified_p (ret.spec)); } } else @@ -4158,7 +4157,7 @@ c_parser_typeof_specifier (c_parser *parser) error_at (here, "%<typeof%> applied to a bit-field"); mark_exp_read (expr.value); ret.spec = TREE_TYPE (expr.value); - was_vm = variably_modified_type_p (ret.spec, NULL_TREE); + was_vm = c_type_variably_modified_p (ret.spec); /* This is returned with the type so that when the type is evaluated, this can be evaluated. */ if (was_vm) @@ -9058,7 +9057,7 @@ c_parser_has_attribute_expression (c_parser *parser) if (tname) { oper = groktypename (tname, NULL, NULL); - pop_maybe_used (variably_modified_type_p (oper, NULL_TREE)); + pop_maybe_used (c_type_variably_modified_p (oper)); } } else @@ -9071,7 +9070,7 @@ c_parser_has_attribute_expression (c_parser *parser) mark_exp_read (cexpr.value); oper = cexpr.value; tree etype = TREE_TYPE (oper); - bool was_vm = variably_modified_type_p (etype, NULL_TREE); + bool was_vm = c_type_variably_modified_p (etype); /* This is returned with the type so that when the type is evaluated, this can be evaluated. */ if (was_vm) @@ -9320,7 +9319,7 @@ c_parser_generic_selection (c_parser *parser) error_at (assoc.type_location, "%<_Generic%> association has incomplete type"); - if (variably_modified_type_p (assoc.type, NULL_TREE)) + if (c_type_variably_modified_p (assoc.type)) error_at (assoc.type_location, "%<_Generic%> association has " "variable length type"); |