This patch teaches the c and c++ FEs how to update the list of clauses
after calling c_finish_omp_clauses when parsing combined loop
constructs. The problem here is, if an invalid clause isn't removed by
the FE, the gimplifier will ICE because the tree node representing the
clause contains incomplete fields. So updating the split clauses allows
the compiler to gracefully error.

Is this patch ok for trunk? It's specific to openacc.

Thanks,
Cesar
2016-03-09  Cesar Philippidis  <ce...@codesourcery.com>

	gcc/c/
	* c-parser.c (c_parser_oacc_loop): Update cclauses and clauses
	when calling c_finish_omp_clauses.

	gcc/cp/
	* parser.c (cp_parser_oacc_loop): Update cclauses and clauses
	when calling c_finish_omp_clauses.

	gcc/testsuite/
	* c-c++-common/goacc/combined-directives-2.c: New test.


diff --git a/gcc/c/c-parser.c b/gcc/c/c-parser.c
index a7d5827..60ec996 100644
--- a/gcc/c/c-parser.c
+++ b/gcc/c/c-parser.c
@@ -13789,9 +13789,9 @@ c_parser_oacc_loop (location_t loc, c_parser *parser, char *p_name,
     {
       clauses = c_oacc_split_loop_clauses (clauses, cclauses);
       if (*cclauses)
-	c_finish_omp_clauses (*cclauses, false);
+	*cclauses = c_finish_omp_clauses (*cclauses, false);
       if (clauses)
-	c_finish_omp_clauses (clauses, false);
+	clauses = c_finish_omp_clauses (clauses, false);
     }
 
   tree block = c_begin_compound_stmt (true);
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 726d5fc..6ae45b0 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -35346,9 +35346,9 @@ cp_parser_oacc_loop (cp_parser *parser, cp_token *pragma_tok, char *p_name,
     {
       clauses = c_oacc_split_loop_clauses (clauses, cclauses);
       if (*cclauses)
-	finish_omp_clauses (*cclauses, false);
+	*cclauses = finish_omp_clauses (*cclauses, false);
       if (clauses)
-	finish_omp_clauses (clauses, false);
+	clauses = finish_omp_clauses (clauses, false);
     }
 
   tree block = begin_omp_structured_block ();
diff --git a/gcc/testsuite/c-c++-common/goacc/combined-directives-2.c b/gcc/testsuite/c-c++-common/goacc/combined-directives-2.c
new file mode 100644
index 0000000..c51e2f9
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/goacc/combined-directives-2.c
@@ -0,0 +1,14 @@
+/* Ensure that bogus clauses aren't propagated in combined loop
+   constructs.  */
+
+int
+main ()
+{
+  int a, i;
+
+#pragma acc parallel loop vector copy(a[0:100]) reduction(+:a) /* { dg-error "'a' does not have pointer or array type" } */
+  for (i = 0; i < 100; i++)
+    a++;
+
+  return a;
+}

Reply via email to