public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
From: Sandra Loosemore <sloosemore@baylibre.com>
To: Jakub Jelinek <jakub@redhat.com>
Cc: gcc-patches@gcc.gnu.org, tburnus@baylibre.com
Subject: Re: [PATCH v3 04/12] OpenMP: C front end support for metadirectives
Date: Sat, 31 Aug 2024 16:33:27 -0600	[thread overview]
Message-ID: <2658f77b-628b-44e9-aedd-40c9a3f3b82e@baylibre.com> (raw)
In-Reply-To: <Zr8qYE2SpLN/8DbU@tucnak>

On 8/16/24 04:30, Jakub Jelinek wrote:
> On Sat, Jul 20, 2024 at 02:42:23PM -0600, Sandra Loosemore wrote:
>> --- a/gcc/c/c-parser.cc
>> +++ b/gcc/c/c-parser.cc
>> @@ -263,9 +263,24 @@ struct GTY(()) c_parser {
>>        otherwise NULL.  */
>>     vec<c_token, va_gc> *in_omp_attribute_pragma;
>>   
>> +  /* When in_omp_attribute_pragma is non-null, these fields save the values
>> +     of the tokens and tokens_avail fields, so that they can be restored
>> +     after parsing the attribute.  Note that parsing the body of a
>> +     metadirective uses its own save/restore mechanism as those can be
>> +     nested with or without the attribute pragmas in the body.  */
>> +    c_token * GTY((skip)) save_tokens;
>> +    unsigned int save_tokens_avail;
> 
> The indentation of the above 2 is wrong.
> Plus if those members are for metadirective parsing, their names are too
> generic.

They are not for metadirective parsing, they are to generalize the 
state-saving for OpenMP attribute-syntax directives that are converted 
to pragmas.  It's related to this patch hunk:

@@ -6846,7 +6884,6 @@ c_parser_handle_statement_omp_attributes (c_parser 
*parser
, tree &attrs,
      return false;

    unsigned int tokens_avail = parser->tokens_avail;
-  gcc_assert (parser->tokens == &parser->tokens_buf[0]);

    tokens++;
    vec<c_token, va_gc> *toks = NULL;

and the multiple instances like this:

@@ -1307,8 +1322,10 @@ c_parser_skip_until_found (c_parser *parser,
           c_token *token = c_parser_peek_token (parser);
           if (token->type == CPP_EOF)
             {
-             parser->tokens = &parser->tokens_buf[0];
-             parser->tokens_avail = token->flags;
+             parser->tokens = parser->save_tokens;
+             parser->save_tokens = NULL;
+             parser->tokens_avail = parser->save_tokens_avail;
+             parser->save_tokens_avail = 0;
               parser->in_omp_attribute_pragma = NULL;
             }
         }

where there presently is a hard-wired assumption that omp attribute 
pragma parsing is the *only* thing that messes with what parser->tokens 
points to.  Metadirectives need to maintain a separate token stream too, 
and attribute-syntax pragma directives can appear inside a 
metadirective, so fixing this somehow is necessary.  Due to the control 
flow of parsing the attribute-syntax pragmas it's not possible to save 
the state it needs in local variables on the stack, so hanging it off 
the parser object is about the only choice.

> But more importantly, for something parsed really rarely, wouldn't it be
> better to just add a single pointer to a new structure that contains
> all you need for metadirective parsing?

Do you want me to create separate new data structures for both the 
attribute-syntax pragma parsing, and the metadirective-specific bits? 
And maybe submit the attribute-syntax pragma parsing state changes as 
its own patch separate from the metadirective pieces?

-Sandra

  reply	other threads:[~2024-08-31 22:33 UTC|newest]

Thread overview: 42+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-20 20:42 [PATCH v3 00/12] Metadirective support + "declare variant" improvements Sandra Loosemore
2024-07-20 20:42 ` [PATCH v3 01/12] OpenMP: metadirective tree data structures and front-end interfaces Sandra Loosemore
2024-07-25 14:00   ` Tobias Burnus
2024-07-25 19:13     ` Sandra Loosemore
2024-08-09 16:42   ` Jakub Jelinek
2024-08-19 19:12     ` Sandra Loosemore
2024-07-20 20:42 ` [PATCH v3 02/12] OpenMP: middle-end support for metadirectives Sandra Loosemore
2024-08-09 17:12   ` Jakub Jelinek
2024-08-10  7:18     ` Jakub Jelinek
2024-08-10  8:02       ` Jakub Jelinek
2024-08-21  0:36         ` Sandra Loosemore
2024-07-20 20:42 ` [PATCH v3 03/12] libgomp: runtime support for target_device selector Sandra Loosemore
2024-08-14 10:25   ` Jakub Jelinek
2024-08-14 11:01     ` Jakub Jelinek
2024-09-09 10:46     ` Tobias Burnus
2024-09-22  1:00       ` Sandra Loosemore
2024-09-22  5:37         ` Tobias Burnus
2024-07-20 20:42 ` [PATCH v3 04/12] OpenMP: C front end support for metadirectives Sandra Loosemore
2024-08-16 10:30   ` Jakub Jelinek
2024-08-31 22:33     ` Sandra Loosemore [this message]
2024-07-20 20:42 ` [PATCH v3 05/12] OpenMP: C++ front-end " Sandra Loosemore
2024-08-16 11:15   ` Jakub Jelinek
2024-07-20 20:42 ` [PATCH v3 06/12] OpenMP: common c/c++ testcases " Sandra Loosemore
2024-08-16 11:29   ` Jakub Jelinek
2024-07-20 20:42 ` [PATCH v3 07/12] OpenMP: Fortran front-end support " Sandra Loosemore
2024-08-16 12:25   ` Jakub Jelinek
2024-07-20 20:42 ` [PATCH v3 08/12] OpenMP: Reject other properties with kind(any) Sandra Loosemore
2024-08-16 12:58   ` Jakub Jelinek
2024-09-08 15:15     ` Sandra Loosemore
2024-09-09 11:01       ` Jakub Jelinek
2024-09-09 20:55         ` Sandra Loosemore
2024-09-09 21:10           ` Jakub Jelinek
2024-09-18 20:50           ` Sandra Loosemore
2024-09-20  7:41             ` Jakub Jelinek
2024-09-22  2:08               ` Sandra Loosemore
2024-09-22  4:52                 ` Jakub Jelinek
2024-09-22 14:45                   ` Sandra Loosemore
2024-09-23  7:23                     ` Jakub Jelinek
2024-07-20 20:42 ` [PATCH v3 09/12] OpenMP: Extend dynamic selector support to declare variant Sandra Loosemore
2024-07-20 20:42 ` [PATCH v3 10/12] OpenMP: Remove dead code from declare variant reimplementation Sandra Loosemore
2024-07-20 20:42 ` [PATCH v3 11/12] OpenMP: Update "declare target"/OpenMP context interaction Sandra Loosemore
2024-07-20 20:42 ` [PATCH v3 12/12] OpenMP: Update documentation of metadirective implementation status Sandra Loosemore

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2658f77b-628b-44e9-aedd-40c9a3f3b82e@baylibre.com \
    --to=sloosemore@baylibre.com \
    --cc=gcc-patches@gcc.gnu.org \
    --cc=jakub@redhat.com \
    --cc=tburnus@baylibre.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).