aboutsummaryrefslogtreecommitdiff
path: root/gcc/c/c-parser.c
diff options
context:
space:
mode:
authorJoseph Myers <joseph@codesourcery.com>2019-11-25 13:42:49 +0000
committerJoseph Myers <jsm28@gcc.gnu.org>2019-11-25 13:42:49 +0000
commit1723e1bedb9545c45619c4023729755243524584 (patch)
tree3338a8b65ec9bfb47d4bf0a79a04d572e4162ea0 /gcc/c/c-parser.c
parent6cebc6cbbb801183090dbb2752aa6b698331a31c (diff)
downloadgcc-1723e1bedb9545c45619c4023729755243524584.zip
gcc-1723e1bedb9545c45619c4023729755243524584.tar.gz
gcc-1723e1bedb9545c45619c4023729755243524584.tar.bz2
Properly handle C2x attributes on types.
attribs.c has code to ignore all scoped attributes appertaining to types except when they are part of the definition of that type. I think the premise of that code is incorrect, and its presence is a bug; such attributes are clearly valid in both C and C++, which explicitly specify that attributes in certain syntactic positions appertain to a particular type, only for that use of that type and not for other uses of the same type specifiers without that attribute specified, and while the standard attributes in C2x aren't relevant in such contexts, some gnu:: attributes certainly are. Where some attributes are invalid on some types in such contexts, that's a matter for the individual attribute handlers to diagnose (or the front end if the requirements on a standard attribute in the standard are more strict than those of a handler shared with a GNU attribute). Thus, this patch removes the bogus code to allow such attributes to be used. Doing so (and adding tests for attributes in such positions) shows up that the logic in the C front end for creating the c_declarator structures for such attributes put them in the wrong place relative to the structures for function and array types, and the logic for postfix attributes on a list of declaration specifiers failed to handle some cases, so those bugs are also fixed in this patch. Bootstrapped with no regressions for x86_64-pc-linux-gnu. gcc: * attribs.c (decl_attributes): Do not ignore C++11 attributes on types. gcc/c: * c-tree.h (struct c_declarator): Use a structure for id member. * c-decl.c (grokdeclarator): Extract attributes from cdk_id declarators at the start, not when handling individual declarators later. Use u.id.id instead of u.id. (grokfield): Use u.id.id instead of u.id. (build_id_declarator): Set u.id.id and u.id.attrs. (finish_declspecs): Handle postfix attributes in case of typedef name or typeof used. * c-parser.c (c_parser_direct_declarator) (c_parser_direct_declarator_inner): Place declarator for attributes inside that for function or array, not outside. Set u.id.attrs for identifiers. (c_parser_parameter_declaration): Use u.id.id instead of u.id. * gimple-parser.c (c_parser_gimple_declaration): Use u.id.id instead of u.id. gcc/testsuite: * gcc.dg/gnu2x-attrs-1.c: Do not expect message about attributes appertaining to types. * gcc.dg/gnu2x-attrs-2.c: New test. * g++.dg/cpp0x/gen-attrs-1.C, g++.dg/cpp0x/gen-attrs-22.C, g++.dg/cpp0x/gen-attrs-4.C, g++.dg/cpp0x/lambda/lambda-attr1.C: Update expected diagnostics. From-SVN: r278683
Diffstat (limited to 'gcc/c/c-parser.c')
-rw-r--r--gcc/c/c-parser.c17
1 files changed, 6 insertions, 11 deletions
diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index 03194b4..5aa42e2 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -3857,11 +3857,7 @@ c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
inner->id_loc = c_parser_peek_token (parser)->location;
c_parser_consume_token (parser);
if (c_parser_nth_token_starts_std_attributes (parser, 1))
- {
- tree std_attrs = c_parser_std_attribute_specifier_sequence (parser);
- if (std_attrs)
- inner = build_attrs_declarator (std_attrs, inner);
- }
+ inner->u.id.attrs = c_parser_std_attribute_specifier_sequence (parser);
return c_parser_direct_declarator_inner (parser, *seen_id, inner);
}
@@ -3898,9 +3894,7 @@ c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
return NULL;
else
{
- inner
- = build_function_declarator (args,
- build_id_declarator (NULL_TREE));
+ inner = build_id_declarator (NULL_TREE);
if (!(args->types
&& args->types != error_mark_node
&& TREE_CODE (TREE_VALUE (args->types)) == IDENTIFIER_NODE)
@@ -3911,6 +3905,7 @@ c_parser_direct_declarator (c_parser *parser, bool type_seen_p, c_dtr_syn kind,
if (std_attrs)
inner = build_attrs_declarator (std_attrs, inner);
}
+ inner = build_function_declarator (args, inner);
return c_parser_direct_declarator_inner (parser, *seen_id,
inner);
}
@@ -4028,7 +4023,6 @@ c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
static_seen, star_seen);
if (declarator == NULL)
return NULL;
- inner = set_array_declarator_inner (declarator, inner);
if (c_parser_nth_token_starts_std_attributes (parser, 1))
{
tree std_attrs
@@ -4036,6 +4030,7 @@ c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
if (std_attrs)
inner = build_attrs_declarator (std_attrs, inner);
}
+ inner = set_array_declarator_inner (declarator, inner);
return c_parser_direct_declarator_inner (parser, id_present, inner);
}
else if (c_parser_next_token_is (parser, CPP_OPEN_PAREN))
@@ -4052,7 +4047,6 @@ c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
return NULL;
else
{
- inner = build_function_declarator (args, inner);
if (!(args->types
&& args->types != error_mark_node
&& TREE_CODE (TREE_VALUE (args->types)) == IDENTIFIER_NODE)
@@ -4063,6 +4057,7 @@ c_parser_direct_declarator_inner (c_parser *parser, bool id_present,
if (std_attrs)
inner = build_attrs_declarator (std_attrs, inner);
}
+ inner = build_function_declarator (args, inner);
return c_parser_direct_declarator_inner (parser, id_present, inner);
}
}
@@ -4352,7 +4347,7 @@ c_parser_parameter_declaration (c_parser *parser, tree attrs,
c_declarator *id_declarator = declarator;
while (id_declarator && id_declarator->kind != cdk_id)
id_declarator = id_declarator->declarator;
- location_t caret_loc = (id_declarator->u.id
+ location_t caret_loc = (id_declarator->u.id.id
? id_declarator->id_loc
: start_loc);
location_t param_loc = make_location (caret_loc, start_loc, end_loc);