Don't create location wrapper nodes within OpenACC clauses
authorThomas Schwinge <thomas@codesourcery.com>
Wed, 25 Nov 2020 19:36:55 +0000 (20:36 +0100)
committerThomas Schwinge <thomas@codesourcery.com>
Thu, 26 Nov 2020 09:02:38 +0000 (10:02 +0100)
This fixes a GCC 11, 10, 9 regression introduced by commit
dfd7fdca2ac17d8b823a16700525824ca312ade0 (Subversion r267272) "C++: more
location wrapper nodes (PR c++/43064, PR c++/43486)".  But: this isn't
intending to blame David, because back then, the problem hasn't been visible in
the testsuite (or else I'm sure would've been addressed right away) because of
our all dear friend: missing testsuite coverage.  Thus, for GCC 8, I'm likewise
enhancing the testsuite, without the C++ front end code changes.

I actually had presumed that there may be an issue for OpenACC:
<http://mid.mail-archive.com/874lb9qr2u.fsf@euler.schwinge.homeip.net>, so here
we are, two years (and many "wasted" hours...) later...

gcc/cp/
* parser.c (cp_parser_omp_var_list_no_open): Assert that array
section's 'low_bound', 'length' are not location wrapper nodes.
(cp_parser_oacc_all_clauses, cp_parser_oacc_cache): Instantiate
'auto_suppress_location_wrappers'.
gcc/testsuite/
* c-c++-common/goacc/cache-3-1.c: New.
* c-c++-common/goacc/cache-3-2.c: Likewise.
* c-c++-common/goacc/data-clause-1.c: Likewise.
* c-c++-common/goacc/data-clause-2.c: Likewise.
* c-c++-common/gomp/map-1.c: Adjust.
* c-c++-common/gomp/map-2.c: Likewise.
* g++.dg/goacc/cache-3-1.C: New.
* g++.dg/goacc/cache-3-2.C: Likewise.
* g++.dg/goacc/data-clause-1.C: Likewise.
* g++.dg/goacc/data-clause-2.C: Likewise.
* g++.dg/gomp/map-1.C: Adjust.
* g++.dg/gomp/map-2.C: Likewise.

Reported-by: Sandra Loosemore <sandra@codesourcery.com>
13 files changed:
gcc/cp/parser.c
gcc/testsuite/c-c++-common/goacc/cache-3-1.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/goacc/cache-3-2.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/goacc/data-clause-1.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/goacc/data-clause-2.c [new file with mode: 0644]
gcc/testsuite/c-c++-common/gomp/map-1.c
gcc/testsuite/c-c++-common/gomp/map-2.c
gcc/testsuite/g++.dg/goacc/cache-3-1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/goacc/cache-3-2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/goacc/data-clause-1.C [new file with mode: 0644]
gcc/testsuite/g++.dg/goacc/data-clause-2.C [new file with mode: 0644]
gcc/testsuite/g++.dg/gomp/map-1.C
gcc/testsuite/g++.dg/gomp/map-2.C

index d11900a..63a2c96 100644 (file)
@@ -34837,7 +34837,11 @@ cp_parser_omp_var_list_no_open (cp_parser *parser, enum omp_clause_code kind,
                  parser->colon_corrects_to_scope_p = false;
                  cp_lexer_consume_token (parser->lexer);
                  if (!cp_lexer_next_token_is (parser->lexer, CPP_COLON))
-                   low_bound = cp_parser_expression (parser);
+                   {
+                     low_bound = cp_parser_expression (parser);
+                     /* Later handling is not prepared to see through these.  */
+                     gcc_checking_assert (!location_wrapper_p (low_bound));
+                   }
                  if (!colon)
                    parser->colon_corrects_to_scope_p
                      = saved_colon_corrects_to_scope_p;
@@ -34857,7 +34861,11 @@ cp_parser_omp_var_list_no_open (cp_parser *parser, enum omp_clause_code kind,
                        cp_parser_commit_to_tentative_parse (parser);
                      if (!cp_lexer_next_token_is (parser->lexer,
                                                   CPP_CLOSE_SQUARE))
-                       length = cp_parser_expression (parser);
+                       {
+                         length = cp_parser_expression (parser);
+                         /* Later handling is not prepared to see through these.  */
+                         gcc_checking_assert (!location_wrapper_p (length));
+                       }
                    }
                  /* Look for the closing `]'.  */
                  if (!cp_parser_require (parser, CPP_CLOSE_SQUARE,
@@ -37521,6 +37529,9 @@ cp_parser_oacc_all_clauses (cp_parser *parser, omp_clause_mask mask,
   tree clauses = NULL;
   bool first = true;
 
+  /* Don't create location wrapper nodes within OpenACC clauses.  */
+  auto_suppress_location_wrappers sentinel;
+
   while (cp_lexer_next_token_is_not (parser->lexer, CPP_PRAGMA_EOL))
     {
       location_t here;
@@ -41444,6 +41455,10 @@ check_clauses:
 static tree
 cp_parser_oacc_cache (cp_parser *parser, cp_token *pragma_tok)
 {
+  /* Don't create location wrapper nodes within 'OMP_CLAUSE__CACHE_'
+     clauses.  */
+  auto_suppress_location_wrappers sentinel;
+
   tree stmt, clauses;
 
   clauses = cp_parser_omp_var_list (parser, OMP_CLAUSE__CACHE_, NULL_TREE);
diff --git a/gcc/testsuite/c-c++-common/goacc/cache-3-1.c b/gcc/testsuite/c-c++-common/goacc/cache-3-1.c
new file mode 100644 (file)
index 0000000..5318a57
--- /dev/null
@@ -0,0 +1,116 @@
+/* Test 'cache' directive diagnostics.  */
+
+/* See also corresponding C++ variant: '../../g++.dg/goacc/cache-3-1.C'.  */
+
+/* See also corresponding C/C++ data clause variant: 'data-clause-1.c'.  */
+
+/* { dg-additional-options "-fopenmp" } for '#pragma omp threadprivate'.  */
+
+/* The current implementation doesn't restrict where a 'cache' directive may
+   appear, so we don't make any special arrangements.  */
+
+extern int a[][10], a2[][10];
+int b[10], c[10][2], d[10], e[10], f[10];
+int b2[10], c2[10][2], d2[10], e2[10], f2[10];
+int k[10], l[10], m[10], n[10], o;
+int *p;
+int **q;
+int r[4][4][4][4][4];
+extern struct s s1;
+extern struct s s2[1]; /* { dg-error "array type has incomplete element type" "" { target c } } */
+int t[10];
+#pragma omp threadprivate (t)
+#pragma acc routine
+void bar (int *);
+
+void
+foo (int g[3][10], int h[4][8], int i[2][10], int j[][9],
+     int g2[3][10], int h2[4][8], int i2[2][10], int j2[][9])
+{
+  #pragma acc cache(bar[2:5]) /* { dg-error "is not a variable" } */
+    ;
+  #pragma acc cache(t[2:5]) /* { dg-error "is threadprivate variable" } */
+    ;
+  #pragma acc cache(k[0.5:]) /* { dg-error "low bound \[^\n\r]* of array section does not have integral type" } */
+    ;
+  #pragma acc cache(l[:7.5f]) /* { dg-error "length \[^\n\r]* of array section does not have integral type" } */
+    ;
+  #pragma acc cache(m[p:]) /* { dg-error "low bound \[^\n\r]* of array section does not have integral type" } */
+    ;
+  #pragma acc cache(n[:p]) /* { dg-error "length \[^\n\r]* of array section does not have integral type" } */
+    ;
+  #pragma acc cache(o[2:5]) /* { dg-error "does not have pointer or array type" } */
+    ;
+  #pragma acc cache(s1) /* { dg-error "expected '\\\['" } */
+    ;
+  #pragma acc cache(s2) /* { dg-error "expected '\\\['" } */
+    ;
+  #pragma acc cache(a[:][:]) /* { dg-error "array type length expression must be specified" } */
+    bar (&a[0][0]); /* { dg-bogus "referenced in target region does not have a mappable type" } */
+  #pragma acc cache(b[-1:]) /* { dg-error "negative low bound in array section" } */
+    bar (b);
+  #pragma acc cache(c[:-3][:]) /* { dg-error "negative length in array section" } */
+    bar (&c[0][0]);
+  #pragma acc cache(d[11:]) /* { dg-error "low bound \[^\n\r]* above array section size" } */
+    bar (d);
+  #pragma acc cache(e[:11]) /* { dg-error "length \[^\n\r]* above array section size" } */
+    bar (e);
+  #pragma acc cache(f[1:10]) /* { dg-error "high bound \[^\n\r]* above array section size" } */
+    bar (f);
+  #pragma acc cache(g[:][0:10]) /* { dg-error "for array function parameter length expression must be specified" } */
+    bar (&g[0][0]);
+  #pragma acc cache(h[2:1][-1:]) /* { dg-error "negative low bound in array section" } */
+    bar (&h[0][0]);
+  #pragma acc cache(h[:1][:-3]) /* { dg-error "negative length in array section" } */
+    bar (&h[0][0]);
+  #pragma acc cache(i[:1][11:]) /* { dg-error "low bound \[^\n\r]* above array section size" } */
+    bar (&i[0][0]);
+  #pragma acc cache(j[3:1][:10]) /* { dg-error "length \[^\n\r]* above array section size" } */
+    bar (&j[0][0]);
+  #pragma acc cache(j[30:1][5:5]) /* { dg-error "high bound \[^\n\r]* above array section size" } */
+    bar (&j[0][0]);
+  #pragma acc cache(a2[:1][2:4])
+    bar (&a2[0][0]);
+  #pragma acc cache(a2[3:5][:])
+    bar (&a2[0][0]);
+  #pragma acc cache(a2[3:5][:10])
+    bar (&a2[0][0]);
+  #pragma acc cache(b2[0:])
+    bar (b2);
+  #pragma acc cache(c2[:3][:])
+    bar (&c2[0][0]);
+  #pragma acc cache(d2[9:])
+    bar (d2);
+  #pragma acc cache(e2[:10])
+    bar (e2);
+  #pragma acc cache(f2[1:9])
+    bar (f2);
+  #pragma acc cache(g2[:1][2:4])
+    bar (&g2[0][0]);
+  #pragma acc cache(h2[2:2][0:])
+    bar (&h2[0][0]);
+  #pragma acc cache(h2[:1][:3])
+    bar (&h2[0][0]);
+  #pragma acc cache(i2[:1][9:])
+    bar (&i2[0][0]);
+  #pragma acc cache(j2[3:4][:9])
+    bar (&j2[0][0]);
+  #pragma acc cache(j2[30:1][5:4])
+    bar (&j2[0][0]);
+  #pragma acc cache(q[1:2])
+    ;
+  #pragma acc cache(q[3:5][:10]) /* { dg-error "array section is not contiguous" } */
+    ;
+  #pragma acc cache(r[3:][2:1][1:2])
+    ;
+  #pragma acc cache(r[3:][2:1][1:2][:][0:4])
+    ;
+  #pragma acc cache(r[3:][2:1][1:2][1:][0:4]) /* { dg-error "array section is not contiguous" } */
+    ;
+  #pragma acc cache(r[3:][2:1][1:2][:3][0:4]) /* { dg-error "array section is not contiguous" } */
+    ;
+  #pragma acc cache(r[3:][2:1][1:2][:][1:]) /* { dg-error "array section is not contiguous" } */
+    ;
+  #pragma acc cache(r[3:][2:1][1:2][:][:3]) /* { dg-error "array section is not contiguous" } */
+    ;
+}
diff --git a/gcc/testsuite/c-c++-common/goacc/cache-3-2.c b/gcc/testsuite/c-c++-common/goacc/cache-3-2.c
new file mode 100644 (file)
index 0000000..ea5222e
--- /dev/null
@@ -0,0 +1,50 @@
+/* Test 'cache' directive diagnostics.  */
+
+/* See also corresponding C++ variant: '../../g++.dg/goacc/cache-3-2.C'.  */
+
+/* See also corresponding C/C++ data clause variant: 'data-clause-2.c'.  */
+
+/* The current implementation doesn't restrict where a 'cache' directive may
+   appear, so we don't make any special arrangements.  */
+
+void
+foo (int *p, int (*q)[10], int r[10], int s[10][10])
+{
+  int a[10], b[10][10];
+  #pragma acc cache (p[-1:2])
+  ;
+  #pragma acc cache (q[-1:2][0:10])
+  ;
+  #pragma acc cache (q[-1:2][-2:10]) /* { dg-error "negative low bound in array section in" } */
+  ;
+  #pragma acc cache (r[-1:2])
+  ;
+  #pragma acc cache (s[-1:2][:])
+  ;
+  #pragma acc cache (s[-1:2][-2:10]) /* { dg-error "negative low bound in array section in" } */
+  ;
+  #pragma acc cache (a[-1:2])   /* { dg-error "negative low bound in array section in" } */
+  ;
+  #pragma acc cache (b[-1:2][0:])       /* { dg-error "negative low bound in array section in" } */
+  ;
+  #pragma acc cache (b[1:2][-2:10]) /* { dg-error "negative low bound in array section in" } */
+  ;
+  #pragma acc cache (p[2:-3])   /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma acc cache (q[2:-3][:])        /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma acc cache (q[2:3][0:-1])      /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma acc cache (r[2:-5])   /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma acc cache (s[2:-5][:])        /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma acc cache (s[2:5][0:-4])      /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma acc cache (a[2:-5])   /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma acc cache (b[2:-5][0:10]) /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma acc cache (b[2:5][0:-4]) /* { dg-error "negative length in array section in" } */
+  ;
+}
diff --git a/gcc/testsuite/c-c++-common/goacc/data-clause-1.c b/gcc/testsuite/c-c++-common/goacc/data-clause-1.c
new file mode 100644 (file)
index 0000000..9952ac4
--- /dev/null
@@ -0,0 +1,115 @@
+/* Test data clause diagnostics.  */
+
+/* See also corresponding OpenACC C++ variant: '../../g++.dg/goacc/data-clause-1.C'.  */
+
+/* See also corresponding OpenACC 'cache' directive variant: 'cache-3-1.c'.  */
+
+/* See also corresponding OpenMP variant: '../gomp/map-1.c'.  */
+
+/* { dg-additional-options "-fopenmp" } for '#pragma omp threadprivate'.  */
+
+extern int a[][10], a2[][10];
+int b[10], c[10][2], d[10], e[10], f[10];
+int b2[10], c2[10][2], d2[10], e2[10], f2[10];
+int k[10], l[10], m[10], n[10], o;
+int *p;
+int **q;
+int r[4][4][4][4][4];
+extern struct s s1;
+extern struct s s2[1]; /* { dg-error "array type has incomplete element type" "" { target c } } */
+int t[10];
+#pragma omp threadprivate (t)
+#pragma acc routine
+void bar (int *);
+
+void
+foo (int g[3][10], int h[4][8], int i[2][10], int j[][9],
+     int g2[3][10], int h2[4][8], int i2[2][10], int j2[][9])
+{
+  #pragma acc parallel copyin(bar[2:5]) /* { dg-error "is not a variable" } */
+    ;
+  #pragma acc parallel copyout(t[2:5]) /* { dg-error "is threadprivate variable" } */
+    ;
+  #pragma acc parallel copy(k[0.5:]) /* { dg-error "low bound \[^\n\r]* of array section does not have integral type" } */
+    ;
+  #pragma acc parallel copyout(l[:7.5f]) /* { dg-error "length \[^\n\r]* of array section does not have integral type" } */
+    ;
+  #pragma acc parallel copyin(m[p:]) /* { dg-error "low bound \[^\n\r]* of array section does not have integral type" } */
+    ;
+  #pragma acc parallel copy(n[:p]) /* { dg-error "length \[^\n\r]* of array section does not have integral type" } */
+    ;
+  #pragma acc parallel copyin(o[2:5]) /* { dg-error "does not have pointer or array type" } */
+    ;
+  #pragma acc parallel create(s1) /* { dg-error "'s1' does not have a mappable type in 'map' clause" } */
+    ;
+  #pragma acc parallel create(s2) /* { dg-error "'s2' does not have a mappable type in 'map' clause" } */
+    ;
+  #pragma acc parallel copyin(a[:][:]) /* { dg-error "array type length expression must be specified" } */
+    bar (&a[0][0]); /* { dg-error "referenced in target region does not have a mappable type" } */
+  #pragma acc parallel copy(b[-1:]) /* { dg-error "negative low bound in array section" } */
+    bar (b);
+  #pragma acc parallel copy(c[:-3][:]) /* { dg-error "negative length in array section" } */
+    bar (&c[0][0]);
+  #pragma acc parallel copyout(d[11:]) /* { dg-error "low bound \[^\n\r]* above array section size" } */
+    bar (d);
+  #pragma acc parallel copyin(e[:11]) /* { dg-error "length \[^\n\r]* above array section size" } */
+    bar (e);
+  #pragma acc parallel copyin(f[1:10]) /* { dg-error "high bound \[^\n\r]* above array section size" } */
+    bar (f);
+  #pragma acc parallel copyout(g[:][0:10]) /* { dg-error "for array function parameter length expression must be specified" } */
+    bar (&g[0][0]);
+  #pragma acc parallel copyout(h[2:1][-1:]) /* { dg-error "negative low bound in array section" } */
+    bar (&h[0][0]);
+  #pragma acc parallel copy(h[:1][:-3]) /* { dg-error "negative length in array section" } */
+    bar (&h[0][0]);
+  #pragma acc parallel copy(i[:1][11:]) /* { dg-error "low bound \[^\n\r]* above array section size" } */
+    bar (&i[0][0]);
+  #pragma acc parallel copyout(j[3:1][:10]) /* { dg-error "length \[^\n\r]* above array section size" } */
+    bar (&j[0][0]);
+  #pragma acc parallel copyin(j[30:1][5:5]) /* { dg-error "high bound \[^\n\r]* above array section size" } */
+    bar (&j[0][0]);
+  #pragma acc parallel copyin(a2[:1][2:4])
+    bar (&a2[0][0]);
+  #pragma acc parallel copy(a2[3:5][:])
+    bar (&a2[0][0]);
+  #pragma acc parallel copyin(a2[3:5][:10])
+    bar (&a2[0][0]);
+  #pragma acc parallel copy(b2[0:])
+    bar (b2);
+  #pragma acc parallel copy(c2[:3][:])
+    bar (&c2[0][0]);
+  #pragma acc parallel copyout(d2[9:])
+    bar (d2);
+  #pragma acc parallel copyin(e2[:10])
+    bar (e2);
+  #pragma acc parallel copyin(f2[1:9])
+    bar (f2);
+  #pragma acc parallel copy(g2[:1][2:4])
+    bar (&g2[0][0]);
+  #pragma acc parallel copyout(h2[2:2][0:])
+    bar (&h2[0][0]);
+  #pragma acc parallel copy(h2[:1][:3])
+    bar (&h2[0][0]);
+  #pragma acc parallel copyin(i2[:1][9:])
+    bar (&i2[0][0]);
+  #pragma acc parallel copyout(j2[3:4][:9])
+    bar (&j2[0][0]);
+  #pragma acc parallel copyin(j2[30:1][5:4])
+    bar (&j2[0][0]);
+  #pragma acc parallel copy(q[1:2])
+    ;
+  #pragma acc parallel copy(q[3:5][:10]) /* { dg-error "array section is not contiguous" } */
+    ;
+  #pragma acc parallel copy(r[3:][2:1][1:2])
+    ;
+  #pragma acc parallel copy(r[3:][2:1][1:2][:][0:4])
+    ;
+  #pragma acc parallel copy(r[3:][2:1][1:2][1:][0:4]) /* { dg-error "array section is not contiguous" } */
+    ;
+  #pragma acc parallel copy(r[3:][2:1][1:2][:3][0:4]) /* { dg-error "array section is not contiguous" } */
+    ;
+  #pragma acc parallel copy(r[3:][2:1][1:2][:][1:]) /* { dg-error "array section is not contiguous" } */
+    ;
+  #pragma acc parallel copy(r[3:][2:1][1:2][:][:3]) /* { dg-error "array section is not contiguous" } */
+    ;
+}
diff --git a/gcc/testsuite/c-c++-common/goacc/data-clause-2.c b/gcc/testsuite/c-c++-common/goacc/data-clause-2.c
new file mode 100644 (file)
index 0000000..d4603b0
--- /dev/null
@@ -0,0 +1,49 @@
+/* Test data clause diagnostics.  */
+
+/* See also corresponding OpenACC C++ variant: '../../g++.dg/goacc/data-clause-2.C'.  */
+
+/* See also corresponding OpenACC 'cache' directive variant: 'cache-3-2.c'.  */
+
+/* See also corresponding OpenMP variant: '../gomp/map-2.c'.  */
+
+void
+foo (int *p, int (*q)[10], int r[10], int s[10][10])
+{
+  int a[10], b[10][10];
+  #pragma acc parallel copy (p[-1:2])
+  ;
+  #pragma acc parallel copy (q[-1:2][0:10])
+  ;
+  #pragma acc parallel copy (q[-1:2][-2:10]) /* { dg-error "negative low bound in array section in" } */
+  ;
+  #pragma acc parallel copy (r[-1:2])
+  ;
+  #pragma acc parallel copy (s[-1:2][:])
+  ;
+  #pragma acc parallel copy (s[-1:2][-2:10]) /* { dg-error "negative low bound in array section in" } */
+  ;
+  #pragma acc parallel copy (a[-1:2])   /* { dg-error "negative low bound in array section in" } */
+  ;
+  #pragma acc parallel copy (b[-1:2][0:])       /* { dg-error "negative low bound in array section in" } */
+  ;
+  #pragma acc parallel copy (b[1:2][-2:10]) /* { dg-error "negative low bound in array section in" } */
+  ;
+  #pragma acc parallel copy (p[2:-3])   /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma acc parallel copy (q[2:-3][:])        /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma acc parallel copy (q[2:3][0:-1])      /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma acc parallel copy (r[2:-5])   /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma acc parallel copy (s[2:-5][:])        /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma acc parallel copy (s[2:5][0:-4])      /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma acc parallel copy (a[2:-5])   /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma acc parallel copy (b[2:-5][0:10]) /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma acc parallel copy (b[2:5][0:-4]) /* { dg-error "negative length in array section in" } */
+  ;
+}
index 31100b0..ed88944 100644 (file)
@@ -1,6 +1,8 @@
 /* Test 'map' clause diagnostics.  */
 
-/* See also corresponding C++ variant: '../../g++.dg/gomp/map-1.C'.  */
+/* See also corresponding OpenMP C++ variant: '../../g++.dg/gomp/map-1.C'.  */
+
+/* See also corresponding OpenACC variant: '../goacc/data-clause-1.c'.  */
 
 extern int a[][10], a2[][10];
 int b[10], c[10][2], d[10], e[10], f[10];
index cd69f6b..01fb4be 100644 (file)
@@ -1,6 +1,8 @@
 /* Test 'map' clause diagnostics.  */
 
-/* See also corresponding C++ variant: '../../g++.dg/gomp/map-2.C'.  */
+/* See also corresponding OpenMP C++ variant: '../../g++.dg/gomp/map-2.C'.  */
+
+/* See also corresponding OpenACC variant: '../goacc/data-clause-2.c'.  */
 
 void
 foo (int *p, int (*q)[10], int r[10], int s[10][10])
diff --git a/gcc/testsuite/g++.dg/goacc/cache-3-1.C b/gcc/testsuite/g++.dg/goacc/cache-3-1.C
new file mode 100644 (file)
index 0000000..ceafb38
--- /dev/null
@@ -0,0 +1,123 @@
+/* Test 'cache' directive diagnostics.  */
+
+/* See also corresponding C/C++ variant: '../../c-c++-common/goacc/cache-3-1.c'.  */
+
+/* See also corresponding C++ data clause variant: 'data-clause-1.C'.  */
+
+/* { dg-additional-options "-fopenmp" } for '#pragma omp threadprivate'.  */
+
+/* The current implementation doesn't restrict where a 'cache' directive may
+   appear, so we don't make any special arrangements.  */
+
+extern int a[][10], a2[][10];
+int b[10], c[10][2], d[10], e[10], f[10];
+int b2[10], c2[10][2], d2[10], e2[10], f2[10];
+int k[10], l[10], m[10], n[10], o;
+int *p;
+int **q;
+int r[4][4][4][4][4];
+extern struct s s1;
+extern struct s s2[1]; /* { dg-error "array type has incomplete element type" "" { target c } } */
+int t[10];
+#pragma omp threadprivate (t)
+#pragma acc routine
+void bar (int *);
+
+template <int N>
+void
+foo (int g[3][10], int h[4][8], int i[2][10], int j[][9],
+     int g2[3][10], int h2[4][8], int i2[2][10], int j2[][9])
+{
+  #pragma acc cache(bar[2:5]) /* { dg-error "is not a variable" } */
+    ;
+  #pragma acc cache(t[2:5]) /* { dg-error "is threadprivate variable" } */
+    ;
+  #pragma acc cache(k[0.5:]) /* { dg-error "low bound \[^\n\r]* of array section does not have integral type" } */
+    ;
+  #pragma acc cache(l[:7.5f]) /* { dg-error "length \[^\n\r]* of array section does not have integral type" } */
+    ;
+  #pragma acc cache(m[p:]) /* { dg-error "low bound \[^\n\r]* of array section does not have integral type" } */
+    ;
+  #pragma acc cache(n[:p]) /* { dg-error "length \[^\n\r]* of array section does not have integral type" } */
+    ;
+  #pragma acc cache(o[2:5]) /* { dg-error "does not have pointer or array type" } */
+    ;
+  #pragma acc cache(s1) /* { dg-error "expected '\\\['" } */
+    ;
+  #pragma acc cache(s2) /* { dg-error "expected '\\\['" } */
+    ;
+  #pragma acc cache(a[:][:]) /* { dg-error "array type length expression must be specified" } */
+    bar (&a[0][0]);
+  #pragma acc cache(b[-1:]) /* { dg-error "negative low bound in array section" } */
+    bar (b);
+  #pragma acc cache(c[:-3][:]) /* { dg-error "negative length in array section" } */
+    bar (&c[0][0]);
+  #pragma acc cache(d[11:]) /* { dg-error "low bound \[^\n\r]* above array section size" } */
+    bar (d);
+  #pragma acc cache(e[:11]) /* { dg-error "length \[^\n\r]* above array section size" } */
+    bar (e);
+  #pragma acc cache(f[1:10]) /* { dg-error "high bound \[^\n\r]* above array section size" } */
+    bar (f);
+  #pragma acc cache(g[:][0:10]) /* { dg-error "for array function parameter length expression must be specified" } */
+    bar (&g[0][0]);
+  #pragma acc cache(h[2:1][-1:]) /* { dg-error "negative low bound in array section" } */
+    bar (&h[0][0]);
+  #pragma acc cache(h[:1][:-3]) /* { dg-error "negative length in array section" } */
+    bar (&h[0][0]);
+  #pragma acc cache(i[:1][11:]) /* { dg-error "low bound \[^\n\r]* above array section size" } */
+    bar (&i[0][0]);
+  #pragma acc cache(j[3:1][:10]) /* { dg-error "length \[^\n\r]* above array section size" } */
+    bar (&j[0][0]);
+  #pragma acc cache(j[30:1][5:5]) /* { dg-error "high bound \[^\n\r]* above array section size" } */
+    bar (&j[0][0]);
+  #pragma acc cache(a2[:1][2:4])
+    bar (&a2[0][0]);
+  #pragma acc cache(a2[3:5][:])
+    bar (&a2[0][0]);
+  #pragma acc cache(a2[3:5][:10])
+    bar (&a2[0][0]);
+  #pragma acc cache(b2[0:])
+    bar (b2);
+  #pragma acc cache(c2[:3][:])
+    bar (&c2[0][0]);
+  #pragma acc cache(d2[9:])
+    bar (d2);
+  #pragma acc cache(e2[:10])
+    bar (e2);
+  #pragma acc cache(f2[1:9])
+    bar (f2);
+  #pragma acc cache(g2[:1][2:4])
+    bar (&g2[0][0]);
+  #pragma acc cache(h2[2:2][0:])
+    bar (&h2[0][0]);
+  #pragma acc cache(h2[:1][:3])
+    bar (&h2[0][0]);
+  #pragma acc cache(i2[:1][9:])
+    bar (&i2[0][0]);
+  #pragma acc cache(j2[3:4][:9])
+    bar (&j2[0][0]);
+  #pragma acc cache(j2[30:1][5:4])
+    bar (&j2[0][0]);
+  #pragma acc cache(q[1:2])
+    ;
+  #pragma acc cache(q[3:5][:10]) /* { dg-error "array section is not contiguous" } */
+    ;
+  #pragma acc cache(r[3:][2:1][1:2])
+    ;
+  #pragma acc cache(r[3:][2:1][1:2][:][0:4])
+    ;
+  #pragma acc cache(r[3:][2:1][1:2][1:][0:4]) /* { dg-error "array section is not contiguous" } */
+    ;
+  #pragma acc cache(r[3:][2:1][1:2][:3][0:4]) /* { dg-error "array section is not contiguous" } */
+    ;
+  #pragma acc cache(r[3:][2:1][1:2][:][1:]) /* { dg-error "array section is not contiguous" } */
+    ;
+  #pragma acc cache(r[3:][2:1][1:2][:][:3]) /* { dg-error "array section is not contiguous" } */
+    ;
+}
+
+static void
+instantiate ()
+{
+  &foo<0>;
+}
diff --git a/gcc/testsuite/g++.dg/goacc/cache-3-2.C b/gcc/testsuite/g++.dg/goacc/cache-3-2.C
new file mode 100644 (file)
index 0000000..5561e17
--- /dev/null
@@ -0,0 +1,57 @@
+/* Test 'cache' directive diagnostics.  */
+
+/* See also corresponding C/C++ variant: '../../c-c++-common/goacc/cache-3-2.c'.  */
+
+/* See also corresponding C++ data clause variant: 'data-clause-2.C'.  */
+
+/* The current implementation doesn't restrict where a 'cache' directive may
+   appear, so we don't make any special arrangements.  */
+
+template <int N>
+void
+foo (int *p, int (*q)[10], int r[10], int s[10][10])
+{
+  int a[10], b[10][10];
+  #pragma acc cache (p[-1:2])
+  ;
+  #pragma acc cache (q[-1:2][0:10])
+  ;
+  #pragma acc cache (q[-1:2][-2:10]) /* { dg-error "negative low bound in array section in" } */
+  ;
+  #pragma acc cache (r[-1:2])
+  ;
+  #pragma acc cache (s[-1:2][:])
+  ;
+  #pragma acc cache (s[-1:2][-2:10]) /* { dg-error "negative low bound in array section in" } */
+  ;
+  #pragma acc cache (a[-1:2])   /* { dg-error "negative low bound in array section in" } */
+  ;
+  #pragma acc cache (b[-1:2][0:])       /* { dg-error "negative low bound in array section in" } */
+  ;
+  #pragma acc cache (b[1:2][-2:10]) /* { dg-error "negative low bound in array section in" } */
+  ;
+  #pragma acc cache (p[2:-3])   /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma acc cache (q[2:-3][:])        /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma acc cache (q[2:3][0:-1])      /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma acc cache (r[2:-5])   /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma acc cache (s[2:-5][:])        /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma acc cache (s[2:5][0:-4])      /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma acc cache (a[2:-5])   /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma acc cache (b[2:-5][0:10]) /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma acc cache (b[2:5][0:-4]) /* { dg-error "negative length in array section in" } */
+  ;
+}
+
+static void
+instantiate ()
+{
+  &foo<0>;
+}
diff --git a/gcc/testsuite/g++.dg/goacc/data-clause-1.C b/gcc/testsuite/g++.dg/goacc/data-clause-1.C
new file mode 100644 (file)
index 0000000..07ef6ae
--- /dev/null
@@ -0,0 +1,122 @@
+/* Test data clause diagnostics.  */
+
+/* See also corresponding OpenACC C/C++ variant: '../../c-c++-common/goacc/data-clause-1.c'.  */
+
+/* See also corresponding OpenACC 'cache' directive variant: 'cache-3-1.C'.  */
+
+/* See also corresponding OpenMP variant: '../gomp/map-1.C'.  */
+
+/* { dg-additional-options "-fopenmp" } for '#pragma omp threadprivate'.  */
+
+extern int a[][10], a2[][10];
+int b[10], c[10][2], d[10], e[10], f[10];
+int b2[10], c2[10][2], d2[10], e2[10], f2[10];
+int k[10], l[10], m[10], n[10], o;
+int *p;
+int **q;
+int r[4][4][4][4][4];
+extern struct s s1;
+extern struct s s2[1]; /* { dg-error "array type has incomplete element type" "" { target c } } */
+int t[10];
+#pragma omp threadprivate (t)
+#pragma acc routine
+void bar (int *);
+
+template <int N>
+void
+foo (int g[3][10], int h[4][8], int i[2][10], int j[][9],
+     int g2[3][10], int h2[4][8], int i2[2][10], int j2[][9])
+{
+  #pragma acc parallel copyin(bar[2:5]) /* { dg-error "is not a variable" } */
+    ;
+  #pragma acc parallel copyout(t[2:5]) /* { dg-error "is threadprivate variable" } */
+    ;
+  #pragma acc parallel copy(k[0.5:]) /* { dg-error "low bound \[^\n\r]* of array section does not have integral type" } */
+    ;
+  #pragma acc parallel copyout(l[:7.5f]) /* { dg-error "length \[^\n\r]* of array section does not have integral type" } */
+    ;
+  #pragma acc parallel copyin(m[p:]) /* { dg-error "low bound \[^\n\r]* of array section does not have integral type" } */
+    ;
+  #pragma acc parallel copy(n[:p]) /* { dg-error "length \[^\n\r]* of array section does not have integral type" } */
+    ;
+  #pragma acc parallel copyin(o[2:5]) /* { dg-error "does not have pointer or array type" } */
+    ;
+  #pragma acc parallel create(s1) /* { dg-error "'s1' does not have a mappable type in 'map' clause" } */
+    ;
+  #pragma acc parallel create(s2) /* { dg-error "'s2' does not have a mappable type in 'map' clause" } */
+    ;
+  #pragma acc parallel copyin(a[:][:]) /* { dg-error "array type length expression must be specified" } */
+    bar (&a[0][0]); /* { dg-error "referenced in target region does not have a mappable type" "PR97996" { xfail *-*-* } } */
+  #pragma acc parallel copy(b[-1:]) /* { dg-error "negative low bound in array section" } */
+    bar (b);
+  #pragma acc parallel copy(c[:-3][:]) /* { dg-error "negative length in array section" } */
+    bar (&c[0][0]);
+  #pragma acc parallel copyout(d[11:]) /* { dg-error "low bound \[^\n\r]* above array section size" } */
+    bar (d);
+  #pragma acc parallel copyin(e[:11]) /* { dg-error "length \[^\n\r]* above array section size" } */
+    bar (e);
+  #pragma acc parallel copyin(f[1:10]) /* { dg-error "high bound \[^\n\r]* above array section size" } */
+    bar (f);
+  #pragma acc parallel copyout(g[:][0:10]) /* { dg-error "for array function parameter length expression must be specified" } */
+    bar (&g[0][0]);
+  #pragma acc parallel copyout(h[2:1][-1:]) /* { dg-error "negative low bound in array section" } */
+    bar (&h[0][0]);
+  #pragma acc parallel copy(h[:1][:-3]) /* { dg-error "negative length in array section" } */
+    bar (&h[0][0]);
+  #pragma acc parallel copy(i[:1][11:]) /* { dg-error "low bound \[^\n\r]* above array section size" } */
+    bar (&i[0][0]);
+  #pragma acc parallel copyout(j[3:1][:10]) /* { dg-error "length \[^\n\r]* above array section size" } */
+    bar (&j[0][0]);
+  #pragma acc parallel copyin(j[30:1][5:5]) /* { dg-error "high bound \[^\n\r]* above array section size" } */
+    bar (&j[0][0]);
+  #pragma acc parallel copyin(a2[:1][2:4])
+    bar (&a2[0][0]);
+  #pragma acc parallel copy(a2[3:5][:])
+    bar (&a2[0][0]);
+  #pragma acc parallel copyin(a2[3:5][:10])
+    bar (&a2[0][0]);
+  #pragma acc parallel copy(b2[0:])
+    bar (b2);
+  #pragma acc parallel copy(c2[:3][:])
+    bar (&c2[0][0]);
+  #pragma acc parallel copyout(d2[9:])
+    bar (d2);
+  #pragma acc parallel copyin(e2[:10])
+    bar (e2);
+  #pragma acc parallel copyin(f2[1:9])
+    bar (f2);
+  #pragma acc parallel copy(g2[:1][2:4])
+    bar (&g2[0][0]);
+  #pragma acc parallel copyout(h2[2:2][0:])
+    bar (&h2[0][0]);
+  #pragma acc parallel copy(h2[:1][:3])
+    bar (&h2[0][0]);
+  #pragma acc parallel copyin(i2[:1][9:])
+    bar (&i2[0][0]);
+  #pragma acc parallel copyout(j2[3:4][:9])
+    bar (&j2[0][0]);
+  #pragma acc parallel copyin(j2[30:1][5:4])
+    bar (&j2[0][0]);
+  #pragma acc parallel copy(q[1:2])
+    ;
+  #pragma acc parallel copy(q[3:5][:10]) /* { dg-error "array section is not contiguous" } */
+    ;
+  #pragma acc parallel copy(r[3:][2:1][1:2])
+    ;
+  #pragma acc parallel copy(r[3:][2:1][1:2][:][0:4])
+    ;
+  #pragma acc parallel copy(r[3:][2:1][1:2][1:][0:4]) /* { dg-error "array section is not contiguous" } */
+    ;
+  #pragma acc parallel copy(r[3:][2:1][1:2][:3][0:4]) /* { dg-error "array section is not contiguous" } */
+    ;
+  #pragma acc parallel copy(r[3:][2:1][1:2][:][1:]) /* { dg-error "array section is not contiguous" } */
+    ;
+  #pragma acc parallel copy(r[3:][2:1][1:2][:][:3]) /* { dg-error "array section is not contiguous" } */
+    ;
+}
+
+static void
+instantiate ()
+{
+  &foo<0>;
+}
diff --git a/gcc/testsuite/g++.dg/goacc/data-clause-2.C b/gcc/testsuite/g++.dg/goacc/data-clause-2.C
new file mode 100644 (file)
index 0000000..57d1823
--- /dev/null
@@ -0,0 +1,56 @@
+/* Test data clause diagnostics.  */
+
+/* See also corresponding OpenACC C/C++ variant: '../../c-c++-common/goacc/data-clause-2.c'.  */
+
+/* See also corresponding OpenACC 'cache' directive variant: 'cache-3-2.C'.  */
+
+/* See also corresponding OpenMP variant: '../gomp/map-2.C'.  */
+
+template <int N>
+void
+foo (int *p, int (*q)[10], int r[10], int s[10][10])
+{
+  int a[10], b[10][10];
+  #pragma acc parallel copy (p[-1:2])
+  ;
+  #pragma acc parallel copy (q[-1:2][0:10])
+  ;
+  #pragma acc parallel copy (q[-1:2][-2:10]) /* { dg-error "negative low bound in array section in" } */
+  ;
+  #pragma acc parallel copy (r[-1:2])
+  ;
+  #pragma acc parallel copy (s[-1:2][:])
+  ;
+  #pragma acc parallel copy (s[-1:2][-2:10]) /* { dg-error "negative low bound in array section in" } */
+  ;
+  #pragma acc parallel copy (a[-1:2])   /* { dg-error "negative low bound in array section in" } */
+  ;
+  #pragma acc parallel copy (b[-1:2][0:])       /* { dg-error "negative low bound in array section in" } */
+  ;
+  #pragma acc parallel copy (b[1:2][-2:10]) /* { dg-error "negative low bound in array section in" } */
+  ;
+  #pragma acc parallel copy (p[2:-3])   /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma acc parallel copy (q[2:-3][:])        /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma acc parallel copy (q[2:3][0:-1])      /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma acc parallel copy (r[2:-5])   /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma acc parallel copy (s[2:-5][:])        /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma acc parallel copy (s[2:5][0:-4])      /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma acc parallel copy (a[2:-5])   /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma acc parallel copy (b[2:-5][0:10]) /* { dg-error "negative length in array section in" } */
+  ;
+  #pragma acc parallel copy (b[2:5][0:-4]) /* { dg-error "negative length in array section in" } */
+  ;
+}
+
+static void
+instantiate ()
+{
+  &foo<0>;
+}
index 11275ef..27dc7a5 100644 (file)
@@ -1,6 +1,8 @@
 /* Test 'map' clause diagnostics.  */
 
-/* See also corresponding C/C++ variant: '../../c-c++-common/gomp/map-1.c'.  */
+/* See also corresponding OpenMP C/C++ variant: '../../c-c++-common/gomp/map-1.c'.  */
+
+/* See also corresponding OpenACC variant: '../goacc/data-clause-1.C'.  */
 
 extern int a[][10], a2[][10];
 int b[10], c[10][2], d[10], e[10], f[10];
@@ -41,7 +43,7 @@ foo (int g[3][10], int h[4][8], int i[2][10], int j[][9],
   #pragma omp target map(alloc: s2) /* { dg-error "'s2' does not have a mappable type in 'map' clause" } */
     ;
   #pragma omp target map(to: a[:][:]) /* { dg-error "array type length expression must be specified" } */
-    bar (&a[0][0]); /* { dg-error "referenced in target region does not have a mappable type" "TODO" { xfail *-*-* } } */
+    bar (&a[0][0]); /* { dg-error "referenced in target region does not have a mappable type" "PR97996" { xfail *-*-* } } */
   #pragma omp target map(tofrom: b[-1:]) /* { dg-error "negative low bound in array section" } */
     bar (b);
   #pragma omp target map(tofrom: c[:-3][:]) /* { dg-error "negative length in array section" } */
index 10eaaa9..bbe2606 100644 (file)
@@ -1,6 +1,8 @@
 /* Test 'map' clause diagnostics.  */
 
-/* See also corresponding C/C++ variant: '../../c-c++-common/gomp/map-2.c'.  */
+/* See also corresponding OpenMP C/C++ variant: '../../c-c++-common/gomp/map-2.c'.  */
+
+/* See also corresponding OpenACC variant: '../goacc/data-clause-2.C'.  */
 
 template <int N>
 void