[committed] openmp: Fix ICE on requires clause with atomic_default_mem_order (

Jakub Jelinek jakub@redhat.com
Thu Aug 19 08:44:54 GMT 2021


Hi!

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.

Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk.

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

--- gcc/c/c-parser.c.jj	2021-08-18 11:10:34.922869013 +0200
+++ gcc/c/c-parser.c	2021-08-18 18:51:19.692144764 +0200
@@ -21710,9 +21714,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);
--- gcc/cp/parser.c.jj	2021-08-18 21:37:03.225488478 +0200
+++ gcc/cp/parser.c	2021-08-18 21:39:34.343353030 +0200
@@ -45479,9 +45479,18 @@ cp_parser_omp_requires (cp_parser *parse
 		      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);
--- gcc/testsuite/c-c++-common/gomp/requires-3.c.jj	2020-01-12 11:54:37.016404311 +0100
+++ gcc/testsuite/c-c++-common/gomp/requires-3.c	2021-08-18 18:44:27.700851769 +0200
@@ -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 } */


	Jakub



More information about the Gcc-patches mailing list