diff mbox series

Fix PR85782: C++ ICE with continue statements inside acc loops

Message ID 089cec5d-9cec-d507-10b0-9ffd73963d6d@codesourcery.com
State New
Headers show
Series Fix PR85782: C++ ICE with continue statements inside acc loops | expand

Commit Message

Cesar Philippidis May 15, 2018, 2:11 p.m. UTC
This patch resolves the issue in PR85782, which involves a C++ ICE
caused by OpenACC loops which contain continue statements. The problem
is that genericize_continue_stmt expects a continue label for the loop,
but that wasn't getting set up acc loops. This patch fixes that by
calling genericize_omp_for_stmt for OACC_LOOP statements, because
OACC_LOOP and OMP_FOR statements are almost identical at this point of
parsing.

I regression tested it on x86_64-linux with nvptx offloading.

Is this ok for trunk and the stable branches?  The patch for the stable
branches is slightly different, because cp_genericize_r uses if
statements to check for statement types instead of a huge switch statement.

Cesar

Comments

Cesar Philippidis May 18, 2018, 3:30 p.m. UTC | #1
Ping.

For reference, I've attached the patch for gcc7.

Cesar

On 05/15/2018 07:11 AM, Cesar Philippidis wrote:
> This patch resolves the issue in PR85782, which involves a C++ ICE
> caused by OpenACC loops which contain continue statements. The problem
> is that genericize_continue_stmt expects a continue label for the loop,
> but that wasn't getting set up acc loops. This patch fixes that by
> calling genericize_omp_for_stmt for OACC_LOOP statements, because
> OACC_LOOP and OMP_FOR statements are almost identical at this point of
> parsing.
> 
> I regression tested it on x86_64-linux with nvptx offloading.
> 
> Is this ok for trunk and the stable branches?  The patch for the stable
> branches is slightly different, because cp_genericize_r uses if
> statements to check for statement types instead of a huge switch statement.
> 
> Cesar
> 
> 
> trunk-pr85782.diff
> 
> 
> 2018-05-15  Cesar Philippidis  <cesar@codesourcery.com>
> 
> 	PR c++/85782
> 
> 	gcc/cp/
> 	* cp-gimplify.c (cp_genericize_r): Call genericize_omp_for_stmt for
> 	OACC_LOOPs.
> 
> 	gcc/testsuite/
> 	* c-c++-common/goacc/pr85782.c: New test.
> 
> 	libgomp/
> 	* testsuite/libgomp.oacc-c-c++-common/pr85782.c: New test.
> 
> 
> diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c
> index eda5f05..55aef86 100644
> --- a/gcc/cp/cp-gimplify.c
> +++ b/gcc/cp/cp-gimplify.c
> @@ -1463,6 +1463,7 @@ cp_genericize_r (tree *stmt_p, int *walk_subtrees, void *data)
>      case OMP_FOR:
>      case OMP_SIMD:
>      case OMP_DISTRIBUTE:
> +    case OACC_LOOP:
>        genericize_omp_for_stmt (stmt_p, walk_subtrees, data);
>        break;
>  
> diff --git a/gcc/testsuite/c-c++-common/goacc/pr85782.c b/gcc/testsuite/c-c++-common/goacc/pr85782.c
> new file mode 100644
> index 0000000..f213a24
> --- /dev/null
> +++ b/gcc/testsuite/c-c++-common/goacc/pr85782.c
> @@ -0,0 +1,11 @@
> +/* PR c++/85782 */
> +
> +void
> +foo ()
> +{
> +  int i;
> +  
> +  #pragma acc parallel loop
> +  for (i = 0; i < 100; i++)
> +    continue;
> +}
> diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/pr85782.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/pr85782.c
> new file mode 100644
> index 0000000..6f84dfc
> --- /dev/null
> +++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/pr85782.c
> @@ -0,0 +1,32 @@
> +/* PR c++/85782 */
> +
> +#include <assert.h>
> +
> +#define N 100
> +
> +int
> +main ()
> +{
> +  int i, a[N];
> +
> +  for (i = 0; i < N; i++)
> +    a[i] = i+1;
> +
> +  #pragma acc parallel loop copy(a)
> +  for (i = 0; i < N; i++)
> +    {
> +      if (i % 2)
> +	continue;
> +      a[i] = 0;
> +    }
> +
> +  for (i = 0; i < N; i++)
> +    {
> +      if (i % 2)
> +	assert (a[i] == i+1);
> +      else
> +	assert (a[i] == 0);
> +    }
> +
> +    return 0;
> +}
>
2018-05-18  Cesar Philippidis  <cesar@codesourcery.com>

	PR c++/85782

	gcc/cp/
	* cp-gimplify.c (cp_genericize_r): Call genericize_omp_for_stmt for
	OACC_LOOPs.

	gcc/testsuite/
	* c-c++-common/goacc/pr85782.c: New test.

	libgomp/
	* testsuite/libgomp.oacc-c-c++-common/pr85782.c: New test.


diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c
index 00214e9..4fbb8b5 100644
--- a/gcc/cp/cp-gimplify.c
+++ b/gcc/cp/cp-gimplify.c
@@ -1473,7 +1473,8 @@ cp_genericize_r (tree *stmt_p, int *walk_subtrees, void *data)
     genericize_break_stmt (stmt_p);
   else if (TREE_CODE (stmt) == OMP_FOR
 	   || TREE_CODE (stmt) == OMP_SIMD
-	   || TREE_CODE (stmt) == OMP_DISTRIBUTE)
+	   || TREE_CODE (stmt) == OMP_DISTRIBUTE
+	   || TREE_CODE (stmt) == OACC_LOOP)
     genericize_omp_for_stmt (stmt_p, walk_subtrees, data);
   else if (TREE_CODE (stmt) == PTRMEM_CST)
     {
diff --git a/gcc/testsuite/c-c++-common/goacc/pr85782.c b/gcc/testsuite/c-c++-common/goacc/pr85782.c
new file mode 100644
index 0000000..f213a24
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/goacc/pr85782.c
@@ -0,0 +1,11 @@
+/* PR c++/85782 */
+
+void
+foo ()
+{
+  int i;
+  
+  #pragma acc parallel loop
+  for (i = 0; i < 100; i++)
+    continue;
+}
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/pr85782.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/pr85782.c
new file mode 100644
index 0000000..6f84dfc
--- /dev/null
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/pr85782.c
@@ -0,0 +1,32 @@
+/* PR c++/85782 */
+
+#include <assert.h>
+
+#define N 100
+
+int
+main ()
+{
+  int i, a[N];
+
+  for (i = 0; i < N; i++)
+    a[i] = i+1;
+
+  #pragma acc parallel loop copy(a)
+  for (i = 0; i < N; i++)
+    {
+      if (i % 2)
+	continue;
+      a[i] = 0;
+    }
+
+  for (i = 0; i < N; i++)
+    {
+      if (i % 2)
+	assert (a[i] == i+1);
+      else
+	assert (a[i] == 0);
+    }
+
+    return 0;
+}
Jakub Jelinek May 18, 2018, 3:34 p.m. UTC | #2
On Fri, May 18, 2018 at 08:30:44AM -0700, Cesar Philippidis wrote:
> Ping.

Ok.

> For reference, I've attached the patch for gcc7.

	Jakub
diff mbox series

Patch

2018-05-15  Cesar Philippidis  <cesar@codesourcery.com>

	PR c++/85782

	gcc/cp/
	* cp-gimplify.c (cp_genericize_r): Call genericize_omp_for_stmt for
	OACC_LOOPs.

	gcc/testsuite/
	* c-c++-common/goacc/pr85782.c: New test.

	libgomp/
	* testsuite/libgomp.oacc-c-c++-common/pr85782.c: New test.


diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c
index eda5f05..55aef86 100644
--- a/gcc/cp/cp-gimplify.c
+++ b/gcc/cp/cp-gimplify.c
@@ -1463,6 +1463,7 @@  cp_genericize_r (tree *stmt_p, int *walk_subtrees, void *data)
     case OMP_FOR:
     case OMP_SIMD:
     case OMP_DISTRIBUTE:
+    case OACC_LOOP:
       genericize_omp_for_stmt (stmt_p, walk_subtrees, data);
       break;
 
diff --git a/gcc/testsuite/c-c++-common/goacc/pr85782.c b/gcc/testsuite/c-c++-common/goacc/pr85782.c
new file mode 100644
index 0000000..f213a24
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/goacc/pr85782.c
@@ -0,0 +1,11 @@ 
+/* PR c++/85782 */
+
+void
+foo ()
+{
+  int i;
+  
+  #pragma acc parallel loop
+  for (i = 0; i < 100; i++)
+    continue;
+}
diff --git a/libgomp/testsuite/libgomp.oacc-c-c++-common/pr85782.c b/libgomp/testsuite/libgomp.oacc-c-c++-common/pr85782.c
new file mode 100644
index 0000000..6f84dfc
--- /dev/null
+++ b/libgomp/testsuite/libgomp.oacc-c-c++-common/pr85782.c
@@ -0,0 +1,32 @@ 
+/* PR c++/85782 */
+
+#include <assert.h>
+
+#define N 100
+
+int
+main ()
+{
+  int i, a[N];
+
+  for (i = 0; i < N; i++)
+    a[i] = i+1;
+
+  #pragma acc parallel loop copy(a)
+  for (i = 0; i < N; i++)
+    {
+      if (i % 2)
+	continue;
+      a[i] = 0;
+    }
+
+  for (i = 0; i < N; i++)
+    {
+      if (i % 2)
+	assert (a[i] == i+1);
+      else
+	assert (a[i] == 0);
+    }
+
+    return 0;
+}