aboutsummaryrefslogtreecommitdiff
path: root/gcc/c/c-parser.cc
diff options
context:
space:
mode:
authorMartin Uecker <uecker@tugraz.at>2023-04-13 19:37:12 +0200
committerMartin Uecker <uecker@tugraz.at>2023-05-23 22:04:49 +0200
commitf9b5be322358ee63798e02a9103b6bbe459e7aea (patch)
treee280f4418c443ba88255bfddf9624a08c1980c89 /gcc/c/c-parser.cc
parent8a20b4bc50bdc8d61610974d60d5851f3fd8b70f (diff)
downloadgcc-f9b5be322358ee63798e02a9103b6bbe459e7aea.zip
gcc-f9b5be322358ee63798e02a9103b6bbe459e7aea.tar.gz
gcc-f9b5be322358ee63798e02a9103b6bbe459e7aea.tar.bz2
Fix ICEs related to VM types in C 1/2 [PR70418, PR107557, PR108423]
Size expressions were sometimes lost and not gimplified correctly, leading to ICEs and incorrect evaluation order. Fix this by 1) not recursing into pointers when gimplifying parameters in the middle-end (the code is merged with gimplify_type_sizes), which is incorrect because it might access variables declared later for incomplete structs, and 2) tracking size expressions for struct/union members correctly, 3) emitting code to evaluate size expressions for missing cases (nested functions, empty declarations, and structs/unions). PR c/70418 PR c/106465 PR c/107557 PR c/108423 gcc/c/ * c-decl.cc (start_decl): Make sure size expression are evaluated only in correct context. (grokdeclarator): Size expression in fields may need a bind expression, make sure DECL_EXPR is always created. (grokfield, declspecs_add_type): Pass along size expressions. (finish_struct): Remove unneeded DECL_EXPR. (start_function): Evaluate size expressions for nested functions. * c-parser.cc (c_parser_struct_declarations, c_parser_struct_or_union_specifier): Pass along size expressions. (c_parser_declaration_or_fndef): Evaluate size expression. (c_parser_objc_at_property_declaration, c_parser_objc_class_instance_variables): Adapt. * c-tree.h (grokfield): Adapt declaration. gcc/testsuite/ * gcc.dg/nested-vla-1.c: New test. * gcc.dg/nested-vla-2.c: New test. * gcc.dg/nested-vla-3.c: New test. * gcc.dg/pr70418.c: New test. * gcc.dg/pr106465.c: New test. * gcc.dg/pr107557-1.c: New test. * gcc.dg/pr107557-2.c: New test. * gcc.dg/pr108423-1.c: New test. * gcc.dg/pr108423-2.c: New test. * gcc.dg/pr108423-3.c: New test. * gcc.dg/pr108423-4.c: New test. * gcc.dg/pr108423-5.c: New test. * gcc.dg/pr108423-6.c: New test. * gcc.dg/typename-vla-2.c: New test. * gcc.dg/typename-vla-3.c: New test. * gcc.dg/typename-vla-4.c: New test. * gcc.misc-tests/gcov-pr85350.c: Adapt.
Diffstat (limited to 'gcc/c/c-parser.cc')
-rw-r--r--gcc/c/c-parser.cc22
1 files changed, 13 insertions, 9 deletions
diff --git a/gcc/c/c-parser.cc b/gcc/c/c-parser.cc
index 11ac865..0ec7534 100644
--- a/gcc/c/c-parser.cc
+++ b/gcc/c/c-parser.cc
@@ -1541,7 +1541,7 @@ static void c_parser_static_assert_declaration_no_semi (c_parser *);
static void c_parser_static_assert_declaration (c_parser *);
static struct c_typespec c_parser_enum_specifier (c_parser *);
static struct c_typespec c_parser_struct_or_union_specifier (c_parser *);
-static tree c_parser_struct_declaration (c_parser *);
+static tree c_parser_struct_declaration (c_parser *, tree *);
static struct c_typespec c_parser_typeof_specifier (c_parser *);
static tree c_parser_alignas_specifier (c_parser *);
static struct c_declarator *c_parser_direct_declarator (c_parser *, bool,
@@ -2263,6 +2263,9 @@ c_parser_declaration_or_fndef (c_parser *parser, bool fndef_ok,
if (!handled_assume)
pedwarn (here, 0, "empty declaration");
}
+ /* We still have to evaluate size expressions. */
+ if (specs->expr)
+ add_stmt (fold_convert (void_type_node, specs->expr));
c_parser_consume_token (parser);
if (oacc_routine_data)
c_finish_oacc_routine (oacc_routine_data, NULL_TREE, false);
@@ -3782,6 +3785,7 @@ c_parser_struct_or_union_specifier (c_parser *parser)
so we'll be minimizing the number of node traversals required
by chainon. */
tree contents;
+ tree expr = NULL;
timevar_push (TV_PARSE_STRUCT);
contents = NULL_TREE;
c_parser_consume_token (parser);
@@ -3843,7 +3847,7 @@ c_parser_struct_or_union_specifier (c_parser *parser)
}
/* Parse some comma-separated declarations, but not the
trailing semicolon if any. */
- decls = c_parser_struct_declaration (parser);
+ decls = c_parser_struct_declaration (parser, &expr);
contents = chainon (decls, contents);
/* If no semicolon follows, either we have a parse error or
are at the end of the struct or union and should
@@ -3874,7 +3878,7 @@ c_parser_struct_or_union_specifier (c_parser *parser)
chainon (attrs, postfix_attrs)),
struct_info);
ret.kind = ctsk_tagdef;
- ret.expr = NULL_TREE;
+ ret.expr = expr;
ret.expr_const_operands = true;
ret.has_enum_type_specifier = false;
timevar_pop (TV_PARSE_STRUCT);
@@ -3936,7 +3940,7 @@ c_parser_struct_or_union_specifier (c_parser *parser)
expressions will be diagnosed as non-constant. */
static tree
-c_parser_struct_declaration (c_parser *parser)
+c_parser_struct_declaration (c_parser *parser, tree *expr)
{
struct c_declspecs *specs;
tree prefix_attrs;
@@ -3949,7 +3953,7 @@ c_parser_struct_declaration (c_parser *parser)
tree decl;
ext = disable_extension_diagnostics ();
c_parser_consume_token (parser);
- decl = c_parser_struct_declaration (parser);
+ decl = c_parser_struct_declaration (parser, expr);
restore_extension_diagnostics (ext);
return decl;
}
@@ -3995,7 +3999,7 @@ c_parser_struct_declaration (c_parser *parser)
ret = grokfield (c_parser_peek_token (parser)->location,
build_id_declarator (NULL_TREE), specs,
- NULL_TREE, &attrs);
+ NULL_TREE, &attrs, expr);
if (ret)
decl_attributes (&ret, attrs, 0);
}
@@ -4056,7 +4060,7 @@ c_parser_struct_declaration (c_parser *parser)
if (c_parser_next_token_is_keyword (parser, RID_ATTRIBUTE))
postfix_attrs = c_parser_gnu_attributes (parser);
d = grokfield (c_parser_peek_token (parser)->location,
- declarator, specs, width, &all_prefix_attrs);
+ declarator, specs, width, &all_prefix_attrs, expr);
decl_attributes (&d, chainon (postfix_attrs,
all_prefix_attrs), 0);
DECL_CHAIN (d) = decls;
@@ -11732,7 +11736,7 @@ c_parser_objc_class_instance_variables (c_parser *parser)
}
/* Parse some comma-separated declarations. */
- decls = c_parser_struct_declaration (parser);
+ decls = c_parser_struct_declaration (parser, NULL);
if (decls == NULL)
{
/* There is a syntax error. We want to skip the offending
@@ -12871,7 +12875,7 @@ c_parser_objc_at_property_declaration (c_parser *parser)
/* 'properties' is the list of properties that we read. Usually a
single one, but maybe more (eg, in "@property int a, b, c;" there
are three). */
- tree properties = c_parser_struct_declaration (parser);
+ tree properties = c_parser_struct_declaration (parser, NULL);
if (properties == error_mark_node)
c_parser_skip_until_found (parser, CPP_SEMICOLON, NULL);