public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* PR c/65586: Skipping omp pragmas with -fopenmp-simd
@ 2015-03-27  9:58 Tobias Burnus
  2015-03-27 10:06 ` Jakub Jelinek
  0 siblings, 1 reply; 2+ messages in thread
From: Tobias Burnus @ 2015-03-27  9:58 UTC (permalink / raw)
  To: gcc-patches

[-- Attachment #1: Type: text/plain, Size: 230 bytes --]

For -fopenmp-simd, GCC did not properly jump passed the clauses of
ignored directives. It worked, for "for simd" directives and for
those without clauses.

Bootstrapped and regtested on x86-64-gnu-linux.
OK for the trunk?

Tobias

[-- Attachment #2: openmp-simd.diff --]
[-- Type: text/x-diff, Size: 6722 bytes --]

2015-03-28  Tobias Burnus  <burnus@net-b.de>

	PR c/65586
gcc/c/
	* c-parser.c (c_parser_skip_to_pragma_eol): Optionally, don't
	error out.
	(c_parser_omp_for, c_parser_omp_parallel, c_parser_omp_distribute,
	c_parser_omp_teams, c_parser_omp_target, c_parser_omp_declare):
	Update calls to not error for skipped omp pragmas with -fopenmp-simd.

gcc/cp/
	* parser.c (cp_parser_omp_for, cp_parser_omp_parallel,
	cp_parser_omp_distribute, cp_parser_omp_teams, cp_parser_omp_target,
	cp_parser_omp_declare): Don't show error for skipped omp pragmas with
	-fopenmp-simd.

gcc/testsuite/
	* g++.dg/gomp/openmp-simd-3.C: New.
	* gcc.dg/gomp/openmp-simd-3.c: New.

diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index 5cc3892..18faa6e 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -991,24 +991,26 @@ c_parser_skip_to_end_of_parameter (c_parser *parser)
    end of line marker.  */
 
 static void
-c_parser_skip_to_pragma_eol (c_parser *parser)
+c_parser_skip_to_pragma_eol (c_parser *parser, bool error_if_not_eol = true)
 {
   gcc_assert (parser->in_pragma);
   parser->in_pragma = false;
 
-  if (!c_parser_require (parser, CPP_PRAGMA_EOL, "expected end of line"))
-    while (true)
-      {
-	c_token *token = c_parser_peek_token (parser);
-	if (token->type == CPP_EOF)
+  if (error_if_not_eol && c_parser_peek_token (parser)->type != CPP_PRAGMA_EOL)
+    c_parser_error (parser, "expected end of line");
+
+  while (true)
+    {
+      c_token *token = c_parser_peek_token (parser);
+      if (token->type == CPP_EOF)
+	break;
+      if (token->type == CPP_PRAGMA_EOL)
+	{
+	  c_parser_consume_token (parser);
 	  break;
-	if (token->type == CPP_PRAGMA_EOL)
-	  {
-	    c_parser_consume_token (parser);
-	    break;
-	  }
-	c_parser_consume_token (parser);
-      }
+	}
+      c_parser_consume_token (parser);
+    }
 
   parser->error = false;
 }
@@ -13223,7 +13225,7 @@ c_parser_omp_for (location_t loc, c_parser *parser,
     }
   if (!flag_openmp)  /* flag_openmp_simd  */
     {
-      c_parser_skip_to_pragma_eol (parser);
+      c_parser_skip_to_pragma_eol (parser, false);
       return NULL_TREE;
     }
 
@@ -13448,7 +13450,7 @@ c_parser_omp_parallel (location_t loc, c_parser *parser,
     }
   else if (!flag_openmp)  /* flag_openmp_simd  */
     {
-      c_parser_skip_to_pragma_eol (parser);
+      c_parser_skip_to_pragma_eol (parser, false);
       return NULL_TREE;
     }
   else if (c_parser_next_token_is (parser, CPP_NAME))
@@ -13708,7 +13710,7 @@ c_parser_omp_distribute (location_t loc, c_parser *parser,
     }
   if (!flag_openmp)  /* flag_openmp_simd  */
     {
-      c_parser_skip_to_pragma_eol (parser);
+      c_parser_skip_to_pragma_eol (parser, false);
       return NULL_TREE;
     }
 
@@ -13776,7 +13778,7 @@ c_parser_omp_teams (location_t loc, c_parser *parser,
     }
   if (!flag_openmp)  /* flag_openmp_simd  */
     {
-      c_parser_skip_to_pragma_eol (parser);
+      c_parser_skip_to_pragma_eol (parser, false);
       return NULL_TREE;
     }
 
@@ -13921,7 +13923,7 @@ c_parser_omp_target (c_parser *parser, enum pragma_context context)
 	}
       else if (!flag_openmp)  /* flag_openmp_simd  */
 	{
-	  c_parser_skip_to_pragma_eol (parser);
+	  c_parser_skip_to_pragma_eol (parser, false);
 	  return false;
 	}
       else if (strcmp (p, "data") == 0)
@@ -14604,7 +14606,7 @@ c_parser_omp_declare (c_parser *parser, enum pragma_context context)
 	}
       if (!flag_openmp)  /* flag_openmp_simd  */
 	{
-	  c_parser_skip_to_pragma_eol (parser);
+	  c_parser_skip_to_pragma_eol (parser, false);
 	  return;
 	}
       if (strcmp (p, "target") == 0)
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index a18f38c..4d6b479 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -30768,7 +30768,7 @@ cp_parser_omp_for (cp_parser *parser, cp_token *pragma_tok,
     }
   if (!flag_openmp)  /* flag_openmp_simd  */
     {
-      cp_parser_require_pragma_eol (parser, pragma_tok);
+      cp_parser_skip_to_pragma_eol (parser, pragma_tok);
       return NULL_TREE;
     }
 
@@ -30979,7 +30979,7 @@ cp_parser_omp_parallel (cp_parser *parser, cp_token *pragma_tok,
     }
   else if (!flag_openmp)  /* flag_openmp_simd  */
     {
-      cp_parser_require_pragma_eol (parser, pragma_tok);
+      cp_parser_skip_to_pragma_eol (parser, pragma_tok);
       return NULL_TREE;
     }
   else if (cp_lexer_next_token_is (parser->lexer, CPP_NAME))
@@ -31242,7 +31242,7 @@ cp_parser_omp_distribute (cp_parser *parser, cp_token *pragma_tok,
     }
   if (!flag_openmp)  /* flag_openmp_simd  */
     {
-      cp_parser_require_pragma_eol (parser, pragma_tok);
+      cp_parser_skip_to_pragma_eol (parser, pragma_tok);
       return NULL_TREE;
     }
 
@@ -31321,7 +31321,7 @@ cp_parser_omp_teams (cp_parser *parser, cp_token *pragma_tok,
     }
   if (!flag_openmp)  /* flag_openmp_simd  */
     {
-      cp_parser_require_pragma_eol (parser, pragma_tok);
+      cp_parser_skip_to_pragma_eol (parser, pragma_tok);
       return NULL_TREE;
     }
 
@@ -31466,7 +31466,7 @@ cp_parser_omp_target (cp_parser *parser, cp_token *pragma_tok,
 	}
       else if (!flag_openmp)  /* flag_openmp_simd  */
 	{
-	  cp_parser_require_pragma_eol (parser, pragma_tok);
+	  cp_parser_skip_to_pragma_eol (parser, pragma_tok);
 	  return false;
 	}
       else if (strcmp (p, "data") == 0)
@@ -32442,7 +32442,7 @@ cp_parser_omp_declare (cp_parser *parser, cp_token *pragma_tok,
 	}
       if (!flag_openmp)  /* flag_openmp_simd  */
 	{
-	  cp_parser_require_pragma_eol (parser, pragma_tok);
+	  cp_parser_skip_to_pragma_eol (parser, pragma_tok);
 	  return;
 	}
       if (strcmp (p, "target") == 0)
diff --git a/gcc/testsuite/g++.dg/gomp/openmp-simd-3.C b/gcc/testsuite/g++.dg/gomp/openmp-simd-3.C
new file mode 100644
index 0000000..eba9de2
--- /dev/null
+++ b/gcc/testsuite/g++.dg/gomp/openmp-simd-3.C
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-fopenmp-simd -fdump-tree-original" } */
+
+/* PR c/65586 */
+
+void foo() { }
+
+int main() {
+#pragma omp for collapse(1)
+  for (int i = 1; i <= 151; i+=31)
+     foo();
+}
+
+/* { dg-final { scan-tree-dump-not "omp" "original" } } */
+/* { dg-final { cleanup-tree-dump "original" } } */
diff --git a/gcc/testsuite/gcc.dg/gomp/openmp-simd-3.c b/gcc/testsuite/gcc.dg/gomp/openmp-simd-3.c
new file mode 100644
index 0000000..eba9de2
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/gomp/openmp-simd-3.c
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-fopenmp-simd -fdump-tree-original" } */
+
+/* PR c/65586 */
+
+void foo() { }
+
+int main() {
+#pragma omp for collapse(1)
+  for (int i = 1; i <= 151; i+=31)
+     foo();
+}
+
+/* { dg-final { scan-tree-dump-not "omp" "original" } } */
+/* { dg-final { cleanup-tree-dump "original" } } */

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: PR c/65586: Skipping omp pragmas with -fopenmp-simd
  2015-03-27  9:58 PR c/65586: Skipping omp pragmas with -fopenmp-simd Tobias Burnus
@ 2015-03-27 10:06 ` Jakub Jelinek
  0 siblings, 0 replies; 2+ messages in thread
From: Jakub Jelinek @ 2015-03-27 10:06 UTC (permalink / raw)
  To: Tobias Burnus; +Cc: gcc-patches

On Fri, Mar 27, 2015 at 10:58:14AM +0100, Tobias Burnus wrote:
> For -fopenmp-simd, GCC did not properly jump passed the clauses of
> ignored directives. It worked, for "for simd" directives and for
> those without clauses.
> 
> Bootstrapped and regtested on x86-64-gnu-linux.
> OK for the trunk?
> 
> Tobias

> +  while (true)
> +    {
> +      c_token *token = c_parser_peek_token (parser);
> +      if (token->type == CPP_EOF)
> +	break;
> +      if (token->type == CPP_PRAGMA_EOL)
> +	{
> +	  c_parser_consume_token (parser);
>  	  break;
> -	if (token->type == CPP_PRAGMA_EOL)
> -	  {
> -	    c_parser_consume_token (parser);
> -	    break;
> -	  }
> -	c_parser_consume_token (parser);
> -      }
> +	}
> +      c_parser_consume_token (parser);
> +    }

Can't you use

  cpp_ttype token_type;
  do
    {
      c_token *token = c_parser_peek_token (parser);
      token_type = token->type;
      if (token_type == CPP_EOF)
	break;
      c_parser_consume_token (parser);
    }
  while (token_type != CPP_PRAGMA_EOL);

instead?

Ok either way.

	Jakub

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-03-27 10:06 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-03-27  9:58 PR c/65586: Skipping omp pragmas with -fopenmp-simd Tobias Burnus
2015-03-27 10:06 ` Jakub Jelinek

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