[PR,c++/70565] ICE at gimplify.c:8832 (cilkplus array extension)
diff mbox

Message ID dbd22047-4d42-741b-ed4b-e27128d3a2d6@redhat.com
State New
Headers show

Commit Message

Aldy Hernandez Jan. 17, 2017, 10:43 a.m. UTC
The problem at hand can be seen in this simple testcase:

int array[999];
void foo()
{
   _Cilk_for (int i=0; i < 999; ++i)
     array[:] = 0;
}

The issue here is that the _Cilk_for degrades into an OMP PARALLEL, and 
we fail to expand the array extension in the body of the OMP PARALLEL.

This is probably an obvious patch, but just in case... OK for trunk?

Aldy
commit d92a180d74fc6b20f140928eadccc406fba25edc
Author: Aldy Hernandez <aldyh@redhat.com>
Date:   Mon Jan 16 11:28:35 2017 -0500

            PR c++/70565
            * cp/cp-array-notation.c (expand_array_notation_exprs): Handle
            OMP_PARALLEL.

Comments

Jakub Jelinek Jan. 17, 2017, 10:59 a.m. UTC | #1
On Tue, Jan 17, 2017 at 05:43:34AM -0500, Aldy Hernandez wrote:
> The problem at hand can be seen in this simple testcase:
> 
> int array[999];
> void foo()
> {
>   _Cilk_for (int i=0; i < 999; ++i)
>     array[:] = 0;
> }
> 
> The issue here is that the _Cilk_for degrades into an OMP PARALLEL, and we
> fail to expand the array extension in the body of the OMP PARALLEL.
> 
> This is probably an obvious patch, but just in case... OK for trunk?

See comments in PR71473, this is sufficient for this exact case, but
there are lots of other tree codes the C++ expand_array_notation_exprs
doesn't handle.  Consider:
int array[999];
void foo ()
{
  #pragma omp task
  for (int i=0; i < 999; ++i)
    array[:] = 0;
}
and many others.  Also it would be nice to include some testcase
(the above one is weird, you are 999 times clearing the whole array,
and due to the _Cilk_for it is even racy).  Perhaps turn that into
int array[1024];
void foo()
{
  _Cilk_for (int i = 0; i < 512; ++i)
    array[2 * i : 2] = 0;
}
or something similar.

So, if you'd be willing to rewrite the routine into cp_walk_tree with a
callback similarly to how the C FE does this, it would be appreciated.
Otherwise we'll need to keep up endlessly catching up both the current
tree codes that are mishandled as well as any future tree codes.

> commit d92a180d74fc6b20f140928eadccc406fba25edc
> Author: Aldy Hernandez <aldyh@redhat.com>
> Date:   Mon Jan 16 11:28:35 2017 -0500
> 
>             PR c++/70565
>             * cp/cp-array-notation.c (expand_array_notation_exprs): Handle
>             OMP_PARALLEL.

No cp/ prefix in cp/ChangeLog.

	Jakub

Patch
diff mbox

diff --git a/gcc/cp/cp-array-notation.c b/gcc/cp/cp-array-notation.c
index a0c54fd..36d6624 100644
--- a/gcc/cp/cp-array-notation.c
+++ b/gcc/cp/cp-array-notation.c
@@ -1198,6 +1198,10 @@  expand_array_notation_exprs (tree t)
       }
 
     case OMP_PARALLEL:
+      OMP_PARALLEL_BODY (t)
+	= expand_array_notation_exprs (OMP_PARALLEL_BODY (t));
+      return t;
+
     case OMP_TASK:
     case OMP_FOR:
     case OMP_SINGLE:
diff --git a/gcc/testsuite/g++.dg/cilk-plus/pr70565.C b/gcc/testsuite/g++.dg/cilk-plus/pr70565.C
new file mode 100644
index 0000000..781ce2c
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cilk-plus/pr70565.C
@@ -0,0 +1,9 @@ 
+// { dg-do compile } */
+// { dg-options "-fcilkplus" }
+
+int array[999];
+void foo()
+{
+  _Cilk_for (int i=0; i < 999; ++i)
+    array[:] = 0;
+}