Expand C2x attribute parsing support and factor out from TM attributes

Programming / Compilers / GCC - jsm28 [138bc75d-0d04-0410-961f-82ee72b054a4] - 7 November 2019 23:54 EST

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.

- 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.

- c-attribs.c (parse_tm_stmt_attr): Handle scoped attributes.

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

323d28cf2d8 Expand C2x attribute parsing support and factor out from TM attributes.
gcc/c-family/ChangeLog | 4 +
gcc/c-family/c-attribs.c | 6 +-
gcc/c/ChangeLog | 10 ++
gcc/c/c-parser.c | 347 +++++++++++++++++++++++++++++---------
gcc/testsuite/ChangeLog | 5 +
gcc/testsuite/gcc.dg/tm/attrs-1.c | 39 +++++
gcc/testsuite/gcc.dg/tm/props-5.c | 26 +++
7 files changed, 357 insertions(+), 80 deletions(-)

Upstream: gcc.gnu.org

  • Share