]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Interaction of dynamic/multidimensional arrays with attach/detach.
authorJulian Brown <julian@codesourcery.com>
Tue, 5 Feb 2019 21:43:21 +0000 (13:43 -0800)
committerThomas Schwinge <thomas@codesourcery.com>
Tue, 3 Mar 2020 11:12:53 +0000 (12:12 +0100)
gcc/
* omp-low.c (scan_sharing_clauses): Disallow dynamic (multidimensional)
arrays within structs.

gcc/testsuite/
* c-c++-common/goacc/deep-copy-multidim.c: Add test.

(cherry picked from openacc-gcc-9-branch commit
857f3bc94d843467db9857b82512a1a5a470b1ef)

gcc/ChangeLog.omp
gcc/omp-low.c
gcc/testsuite/ChangeLog.omp
gcc/testsuite/c-c++-common/goacc/deep-copy-multidim.c [new file with mode: 0644]

index fbe1afe552cabad5f3a5d836d28feefb1ea297a5..3095c0c79f9993c24a79e51796acfaa2a3082c66 100644 (file)
@@ -1,3 +1,8 @@
+2019-02-05  Julian Brown  <julian@codesourcery.com>
+
+       * omp-low.c (scan_sharing_clauses): Disallow dynamic (multidimensional)
+       arrays within structs.
+
 2018-10-16  Chung-Lin Tang  <cltang@codesourcery.com>
 
        * tree-pretty-print.c (dump_omp_clauses): Add cases for printing
index d69d9dc9c119f494ffe29ed379d14d6c6fd3f328..a6bf2200f37801359006230159f43e275be7e6b8 100644 (file)
@@ -1468,7 +1468,15 @@ scan_sharing_clauses (tree clauses, omp_context *ctx)
                  t = TREE_TYPE (t);
                }
 
-             install_var_field (da_decl, by_ref, 3, ctx);
+             if (DECL_P (decl))
+               install_var_field (da_decl, by_ref, 3, ctx);
+             else
+               {
+                 error_at (OMP_CLAUSE_LOCATION (c),
+                           "dynamic arrays cannot be used within structs");
+                 break;
+               }
+
              tree new_var = install_var_local (da_decl, ctx);
 
              bool existed = ctx->dynamic_arrays->put (new_var, da_dimensions);
index 33af5c50689fcff19b3338ed2bf74aa5d17bdc78..7e5117da871f494d1dc23d30f25a0d9f9a15dcf5 100644 (file)
@@ -1,3 +1,7 @@
+2019-02-05  Julian Brown  <julian@codesourcery.com>
+
+       * c-c++-common/goacc/deep-copy-multidim.c: Add test.
+
 2019-01-31  Julian Brown  <julian@codesourcery.com>
 
        * c-c++-common/goacc/deep-copy-arrayofstruct.c: New test.
diff --git a/gcc/testsuite/c-c++-common/goacc/deep-copy-multidim.c b/gcc/testsuite/c-c++-common/goacc/deep-copy-multidim.c
new file mode 100644 (file)
index 0000000..1696f0c
--- /dev/null
@@ -0,0 +1,32 @@
+/* { dg-do compile } */
+
+#include <stdlib.h>
+#include <assert.h>
+
+struct dc
+{
+  int a;
+  int **b;
+};
+
+int
+main ()
+{
+  int n = 100, i, j;
+  struct dc v = { .a = 3 };
+
+  v.b = (int **) malloc (sizeof (int *) * n);
+  for (i = 0; i < n; i++)
+    v.b[i] = (int *) malloc (sizeof (int) * n);
+
+#pragma acc parallel loop copy(v.a, v.b[:n][:n]) /* { dg-error "dynamic arrays cannot be used within structs" } */
+  for (i = 0; i < n; i++)
+    for (j = 0; j < n; j++)
+      v.b[i][j] = v.a + i + j;
+
+  for (i = 0; i < n; i++)
+    for (j = 0; j < n; j++)
+      assert (v.b[i][j] == v.a + i + j);
+
+  return 0;
+}