Commit c01bd174 by Joseph Myers Committed by Joseph Myers

Expand C2x attribute parsing support and factor out from TM attributes.

There is one place in the C parser that already handles a subset of
the C2x [[]] attribute syntax: c_parser_transaction_attributes.

This patch factors C2x attribute parsing out of there, extending it to
cover the full C2x attribute syntax (although currently only called
from that one place in the parser - so this is another piece of
preparation for supporting C2x attributes in the places where C2x says
they are valid, not the patch that actually enables such support).
The new C2X attribute parsing code uses the same representation for
scoped attributes as C++ does, so requiring parse_tm_stmt_attr to
handle the scoped attributes representation (C++ currently
special-cases TM attributes "to avoid the pedwarn in C++98 mode"; in C
I'm using an argument to c_parser_std_attribute_specifier to disable
the pedwarn_c11 call in the TM case).

Parsing of arguments to known attributes is shared by GNU and C2x
attributes.  C2x specifies that unknown attributes are ignored (GCC
practice in such a case is to warn along with ignoring the attribute)
and gives a very general balanced-token-sequence syntax for arguments
to unknown attributes (known ones each have their own syntax which is
a subset of balanced-token-sequence), so support is added for parsing
and ignoring such balanced-token-sequences as arguments of unknown
attributes.

Some limited tests are added of different attribute usages in the TM
attribute case.  The cases that become valid in the TM case include
extra commas inside [[]], and an explicit "gnu" namespace, as the
extra commas have no semantic effect for C2x attributes, while
accepting the "gnu" namespace seems appropriate because the attribute
in question is accepted inside __attribute__ (()), which is considered
equivalent to the "gnu" namespace inside [[]].

Bootstrapped with no regressions on x86_64-pc-linux-gnu.

gcc/c:
	* c-parser.c (c_parser_attribute_arguments): New function.
	Factored out of c_parser_gnu_attribute.
	(c_parser_gnu_attribute): Use c_parser_attribute_arguments.
	(c_parser_balanced_token_sequence, c_parser_std_attribute)
	(c_parser_std_attribute_specifier): New functions.
	(c_parser_transaction_attributes): Use
	c_parser_std_attribute_specifier.

gcc/c-family:
	* c-attribs.c (parse_tm_stmt_attr): Handle scoped attributes.

gcc/testsuite:
	* gcc.dg/tm/attrs-1.c: New test.
	* gcc.dg/tm/props-5.c: New test.  Based on props-4.c.

From-SVN: r277935
parent dc4b5796
2019-11-07 Joseph Myers <joseph@codesourcery.com>
* c-attribs.c (parse_tm_stmt_attr): Handle scoped attributes.
2019-11-05 Jason Merrill <jason@redhat.com> 2019-11-05 Jason Merrill <jason@redhat.com>
* c-opts.c (c_common_post_options): -fconcepts-ts implies * c-opts.c (c_common_post_options): -fconcepts-ts implies
......
...@@ -3227,10 +3227,12 @@ parse_tm_stmt_attr (tree attrs, int allowed) ...@@ -3227,10 +3227,12 @@ parse_tm_stmt_attr (tree attrs, int allowed)
for ( ; attrs ; attrs = TREE_CHAIN (attrs)) for ( ; attrs ; attrs = TREE_CHAIN (attrs))
{ {
tree a = TREE_PURPOSE (attrs); tree a = get_attribute_name (attrs);
tree ns = get_attribute_namespace (attrs);
int m = 0; int m = 0;
if (is_attribute_p ("outer", a)) if (is_attribute_p ("outer", a)
&& (ns == NULL_TREE || strcmp (IDENTIFIER_POINTER (ns), "gnu") == 0))
m = TM_STMT_ATTR_OUTER; m = TM_STMT_ATTR_OUTER;
if ((m & allowed) == 0) if ((m & allowed) == 0)
......
2019-11-07 Joseph Myers <joseph@codesourcery.com> 2019-11-07 Joseph Myers <joseph@codesourcery.com>
* c-parser.c (c_parser_attribute_arguments): New function.
Factored out of c_parser_gnu_attribute.
(c_parser_gnu_attribute): Use c_parser_attribute_arguments.
(c_parser_balanced_token_sequence, c_parser_std_attribute)
(c_parser_std_attribute_specifier): New functions.
(c_parser_transaction_attributes): Use
c_parser_std_attribute_specifier.
2019-11-07 Joseph Myers <joseph@codesourcery.com>
* c-parser.c (c_parser): Remove lex_untranslated_string. Add * c-parser.c (c_parser): Remove lex_untranslated_string. Add
lex_joined_string and translate_strings_p. lex_joined_string and translate_strings_p.
(c_lex_one_token): Pass 0 or C_LEX_STRING_NO_JOIN to (c_lex_one_token): Pass 0 or C_LEX_STRING_NO_JOIN to
......
2019-11-07 Joseph Myers <joseph@codesourcery.com>
* gcc.dg/tm/attrs-1.c: New test.
* gcc.dg/tm/props-5.c: New test. Based on props-4.c.
2019-11-08 Jakub Jelinek <jakub@redhat.com> 2019-11-08 Jakub Jelinek <jakub@redhat.com>
* g++.dg/cpp2a/spaceship-scalar1-neg.C: Change dg-do from run to * g++.dg/cpp2a/spaceship-scalar1-neg.C: Change dg-do from run to
......
/* Test various erroneous or ignored uses of C2X attribute syntax. */
/* { dg-do compile } */
/* { dg-options "-fgnu-tm" } */
void
f1 (void)
{
__transaction_atomic [[outer()]] {} /* { dg-error "does not take any arguments" } */
}
void
f2 (void)
{
__transaction_atomic [[not_a_tm_attribute]] {} /* { dg-warning "attribute directive ignored" } */
}
void
f3 (void)
{
__transaction_atomic [[unknown_attribute(args of *unknown* attributes need only (be {balanced[(({{[[]]}}))]}!), as per standard C)]] {} /* { dg-warning "attribute directive ignored" } */
}
void
f4 (void)
{
__transaction_atomic [[gnu::const]] {} /* { dg-warning "attribute directive ignored" } */
}
void
f5 (void)
{
__transaction_atomic [[bad_namespace::outer]] {} /* { dg-warning "attribute directive ignored" } */
}
void
f6 (void)
{
__transaction_atomic [[outer, outer]] {} /* { dg-warning "attribute duplicated" } */
}
/* This is a copy of props-4.c but with variations in the attribute
syntax. */
/* { dg-do compile } */
/* { dg-options "-fgnu-tm -fdump-tree-tmedge -fdump-tree-tmmark" } */
int a, b;
void __attribute((transaction_may_cancel_outer,noinline)) cancel1()
{
__transaction_cancel [[,,,outer,,]];
}
void
foo(void)
{
__transaction_atomic [[__gnu__::__outer__]] {
a = 2;
__transaction_atomic {
b = 2;
cancel1();
}
}
}
/* { dg-final { scan-tree-dump-times " instrumentedCode" 1 "tmedge" } } */
/* { dg-final { scan-tree-dump-times "hasNoAbort" 0 "tmedge" } } */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment