openmp: Fix ICE on requires clause with atomic_default_mem_order (

When working on error directive, I've noticed the C FE ICEs on
  #pragma omp requires atomic_default_mem_order (
where it tries to peek 2nd token after the CPP_PRAGMA_EOL (or CPP_EOF)
in there in order to improve error-recovery on say
atomic_default_mem_order (acquire)
or
atomic_default_mem_order (seqcst)
etc.  The C++ FE didn't ICE, but it is better to follow the same thing there.

2021-08-19  Jakub Jelinek  <jakub@redhat.com>

gcc/c/
	* c-parser.c (c_parser_omp_requires): Don't call
	c_parser_peek_2nd_token and optionally consume token if current
	token is CPP_EOF, CPP_PRAGMA_EOL or CPP_CLOSE_PAREN.
gcc/cp/
	* parser.c (cp_parser_omp_requires): Don't call cp_lexer_nth_token_is
	and optionally consume token if current token is CPP_EOF,
	CPP_PRAGMA_EOL or CPP_CLOSE_PAREN.
gcc/testsuite/
	* c-c++-common/gomp/requires-3.c: Add testcase for
	atomic_default_mem_order ( at the end of line without corresponding ).
This commit is contained in:
Jakub Jelinek 2021-08-19 10:38:19 +02:00
parent cb23be4fa5
commit c04d766942
3 changed files with 26 additions and 6 deletions

View File

@ -21710,9 +21710,18 @@ c_parser_omp_requires (c_parser *parser)
error_at (c_parser_peek_token (parser)->location,
"expected %<seq_cst%>, %<relaxed%> or "
"%<acq_rel%>");
if (c_parser_peek_2nd_token (parser)->type
== CPP_CLOSE_PAREN)
c_parser_consume_token (parser);
switch (c_parser_peek_token (parser)->type)
{
case CPP_EOF:
case CPP_PRAGMA_EOL:
case CPP_CLOSE_PAREN:
break;
default:
if (c_parser_peek_2nd_token (parser)->type
== CPP_CLOSE_PAREN)
c_parser_consume_token (parser);
break;
}
}
else
c_parser_consume_token (parser);

View File

@ -45479,9 +45479,18 @@ cp_parser_omp_requires (cp_parser *parser, cp_token *pragma_tok)
error_at (cp_lexer_peek_token (parser->lexer)->location,
"expected %<seq_cst%>, %<relaxed%> or "
"%<acq_rel%>");
if (cp_lexer_nth_token_is (parser->lexer, 2,
CPP_CLOSE_PAREN))
cp_lexer_consume_token (parser->lexer);
switch (cp_lexer_peek_token (parser->lexer)->type)
{
case CPP_EOF:
case CPP_PRAGMA_EOL:
case CPP_CLOSE_PAREN:
break;
default:
if (cp_lexer_nth_token_is (parser->lexer, 2,
CPP_CLOSE_PAREN))
cp_lexer_consume_token (parser->lexer);
break;
}
}
else
cp_lexer_consume_token (parser->lexer);

View File

@ -1,3 +1,5 @@
#pragma omp requires atomic_default_mem_order(acquire) /* { dg-error "expected 'seq_cst', 'relaxed' or 'acq_rel'" } */
#pragma omp requires atomic_default_mem_order(release) /* { dg-error "expected 'seq_cst', 'relaxed' or 'acq_rel'" } */
#pragma omp requires atomic_default_mem_order(foobar) /* { dg-error "expected 'seq_cst', 'relaxed' or 'acq_rel'" } */
#pragma omp requires atomic_default_mem_order ( /* { dg-error "expected 'seq_cst', 'relaxed' or 'acq_rel'" } */
/* { dg-error "expected '\\\)' before end of line" "" { target *-*-* } .-1 } */