An iterator whose trip count isn't known at compile time already hits
a sorry diagnostic in build_omp_iterators_loops. But elems remained NULL_TREE
which segfaulted a few lines below.

Fix by unsetting OMP_CLAUSE_ITERATORS.

gcc/ChangeLog:

        * gimplify.cc (build_omp_iterators_loops): Clear
        OMP_CLAUSE_ITERATORS after sorry.

gcc/testsuite/ChangeLog:

        * c-c++-common/gomp/target-update-iterators-5.c: New test.
---
 gcc/gimplify.cc                               |  2 ++
 .../gomp/target-update-iterators-5.c          | 20 +++++++++++++++++++
 2 files changed, 22 insertions(+)
 create mode 100644 gcc/testsuite/c-c++-common/gomp/target-update-iterators-5.c

diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc
index 0f8bf533ba7..abc1a01179e 100644
--- a/gcc/gimplify.cc
+++ b/gcc/gimplify.cc
@@ -10154,6 +10154,8 @@ build_omp_iterators_loops (tree *list_p, gimple_seq 
*loops_seq_p)
        {
          /* Handle dynamic sizes.  */
          sorry ("dynamic iterator sizes not implemented yet");
+         OMP_CLAUSE_ITERATORS (c) = NULL_TREE;
+         continue;
        }
 
       /* BEFORE LOOP:  */
diff --git a/gcc/testsuite/c-c++-common/gomp/target-update-iterators-5.c 
b/gcc/testsuite/c-c++-common/gomp/target-update-iterators-5.c
new file mode 100644
index 00000000000..e69edf52cdd
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/gomp/target-update-iterators-5.c
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-options "-fopenmp" } */
+
+/* Check that an iterator whose trip count is not known at compile time does 
not
+   ICE.  */
+
+void f (int n, int *arr)
+{
+  #pragma omp target update to(iterator(i=0:n): arr[i]) /* { dg-message 
"sorry, unimplemented: dynamic iterator sizes not implemented yet" } */
+}
+
+void f1 (int s, int *arr)
+{
+  #pragma omp target update to(iterator(i=0:9:s): arr[i]) /* { dg-message 
"sorry, unimplemented: dynamic iterator sizes not implemented yet" } */
+}
+
+void f2 (int n, int *arr)
+{
+  #pragma omp target update from(iterator(i=0:n): arr[i]) /* { dg-message 
"sorry, unimplemented: dynamic iterator sizes not implemented yet" } */
+}
-- 
2.55.0

Reply via email to