Hi Tobias, Arsen,
this patch fixes a ICE when invalid iterator maps are encountered.
Should've been a setting of 'remove = true' instead of returning
error_mark_node.
Tested on x86_64-linux + nvptx offloading without regressions.
Okay for mainline?
This patch was assisted-by Opus 5.5
Thanks,
Chung-Lin
gcc/c/ChangeLog:
* c-typeck.cc (c_finish_omp_clauses): Adjust to set 'remove = true'
upon error.
gcc/cp/ChangeLog:
* semantics.cc (finish_omp_clauses): Adjust to set 'remove = true' upon
error.
gcc/testsuite/ChangeLog
* c-c++-common/gomp/target-map-iterators-7.c: New test.
diff --git a/gcc/c/c-typeck.cc b/gcc/c/c-typeck.cc
index d7a77ea9a02..6cfc4eb67e3 100644
--- a/gcc/c/c-typeck.cc
+++ b/gcc/c/c-typeck.cc
@@ -17699,7 +17699,7 @@ c_finish_omp_clauses (tree clauses, enum
c_omp_region_type ort)
if (OMP_CLAUSE_ITERATORS (c)
&& c_omp_finish_iterators (OMP_CLAUSE_ITERATORS (c)))
{
- t = error_mark_node;
+ remove = true;
break;
}
/* FALLTHRU */
diff --git a/gcc/cp/semantics.cc b/gcc/cp/semantics.cc
index d900cf42ca6..45a0fa3180d 100644
--- a/gcc/cp/semantics.cc
+++ b/gcc/cp/semantics.cc
@@ -9519,7 +9519,7 @@ finish_omp_clauses (tree clauses, enum c_omp_region_type
ort)
if (OMP_CLAUSE_ITERATORS (c)
&& cp_omp_finish_iterators (OMP_CLAUSE_ITERATORS (c)))
{
- t = error_mark_node;
+ remove = true;
break;
}
/* FALLTHRU */
diff --git a/gcc/testsuite/c-c++-common/gomp/target-map-iterators-7.c
b/gcc/testsuite/c-c++-common/gomp/target-map-iterators-7.c
new file mode 100644
index 00000000000..e102a6add43
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/gomp/target-map-iterators-7.c
@@ -0,0 +1,78 @@
+/* { dg-do compile } */
+
+/* Invalid iterators in map, to and from clauses: the same checks as for
+ depend in depend-iterator-2.c. After the error, the clause used to be
+ kept and crashed the compiler in compute_omp_iterator_count. */
+
+#define N 8
+#define K 3
+
+void
+f1 (int **x)
+{
+ #pragma omp target enter data map(iterator(const int i=0:N), to: x[i][:K])
/* { dg-error "const qualified" } */
+ /* { dg-error "must contain at least one 'map' clause" "" { target *-*-* }
.-1 } */
+}
+
+void
+f2 (int **x)
+{
+ #pragma omp target enter data map(iterator(float i=0:N), to: x[i][:K]) /* {
dg-error "iterator 'i' has neither integral nor pointer type" } */
+ /* { dg-error "array subscript is not an integer|invalid types" "" { target
*-*-* } .-1 } */
+ /* { dg-error "must contain at least one 'map' clause" "" { target *-*-* }
.-2 } */
+}
+
+void
+f3 (int **x)
+{
+ #pragma omp target enter data map(iterator(i=0:N, j=i:N), to: x[j][:K]) /* {
dg-error "begin expression refers to outer iterator 'i'" } */
+ /* { dg-error "must contain at least one 'map' clause" "" { target *-*-* }
.-1 } */
+}
+
+void
+f4 (int **x)
+{
+ #pragma omp target enter data map(iterator(i=0:N, j=0:i), to: x[j][:K]) /* {
dg-error "end expression refers to outer iterator 'i'" } */
+ /* { dg-error "must contain at least one 'map' clause" "" { target *-*-* }
.-1 } */
+}
+
+void
+f5 (int **x)
+{
+ #pragma omp target enter data map(iterator(i=0:N, j=0:N:i), to: x[j][:K]) /*
{ dg-error "step expression refers to outer iterator 'i'" } */
+ /* { dg-error "must contain at least one 'map' clause" "" { target *-*-* }
.-1 } */
+}
+
+void
+f6 (int **x)
+{
+ #pragma omp target enter data map(iterator(i=0:N, i=0:N), to: x[i][:K]) /* {
dg-error "redeclaration of" } */
+}
+
+void
+f7 (int **x)
+{
+ #pragma omp target enter data map(iterator(i=0:N:0), to: x[i][:K]) /* {
dg-error "iterator 'i' has zero step" } */
+ /* { dg-error "must contain at least one 'map' clause" "" { target *-*-* }
.-1 } */
+}
+
+void
+f8 (int **x)
+{
+ #pragma omp target update to(iterator(const int i=0:N): x[i][:K]) /* {
dg-error "const qualified" } */
+ /* { dg-error "must contain at least one 'from' or 'to' clauses" "" { target
*-*-* } .-1 } */
+}
+
+void
+f9 (int **x)
+{
+ #pragma omp target update from(iterator(i=0:N:0): x[i][:K]) /* { dg-error
"iterator 'i' has zero step" } */
+ /* { dg-error "must contain at least one 'from' or 'to' clauses" "" { target
*-*-* } .-1 } */
+}
+
+void
+f10 (int **x)
+{
+ #pragma omp target map(iterator(i=0:N, j=i:N), to: x[j][:K]) /* { dg-error
"begin expression refers to outer iterator 'i'" } */
+ ;
+}