@@ -10696,6 +10696,7 @@ omp_accumulate_sibling_list (enum omp_region_type region_type,
poly_int64 cbitpos;
tree ocd = OMP_CLAUSE_DECL (grp_end);
bool openmp = !(region_type & ORT_ACC);
+ bool target = (region_type & ORT_TARGET) != 0;
tree *continue_at = NULL;
while (TREE_CODE (ocd) == ARRAY_REF)
@@ -10800,9 +10801,9 @@ omp_accumulate_sibling_list (enum omp_region_type region_type,
}
/* For OpenMP semantics, we don't want to implicitly allocate
- space for the pointer here. A FRAGILE_P node is only being
- created so that omp-low.cc is able to rewrite the struct
- properly.
+ space for the pointer here for non-compute regions (e.g. "enter
+ data"). A FRAGILE_P node is only being created so that
+ omp-low.cc is able to rewrite the struct properly.
For references (to pointers), we want to actually allocate the
space for the reference itself in the sorted list following the
struct node.
@@ -10810,6 +10811,7 @@ omp_accumulate_sibling_list (enum omp_region_type region_type,
mapping of the attachment point, but not otherwise. */
if (*fragile_p
|| (openmp
+ && !target
&& attach_detach
&& TREE_CODE (TREE_TYPE (ocd)) == POINTER_TYPE
&& !OMP_CLAUSE_ATTACHMENT_MAPPING_ERASED (grp_end)))
@@ -11122,6 +11124,7 @@ omp_accumulate_sibling_list (enum omp_region_type region_type,
if (*fragile_p
|| (openmp
+ && !target
&& attach_detach
&& TREE_CODE (TREE_TYPE (ocd)) == POINTER_TYPE
&& !OMP_CLAUSE_ATTACHMENT_MAPPING_ERASED (grp_end)))
@@ -49,4 +49,5 @@ main (void)
/* { dg-final { scan-tree-dump {#pragma omp target num_teams.* map\(tofrom:a \[len: [0-9]+\]\[implicit\]\)} "gimple" } } */
-/* { dg-final { scan-tree-dump {#pragma omp target num_teams.* map\(struct:a \[len: 1\]\) map\(alloc:a\.ptr \[len: 0\]\) map\(tofrom:\*_[0-9]+ \[len: [0-9]+\]\) map\(attach:a\.ptr \[bias: 0\]\)} "gimple" } } */
+/* { dg-final { scan-tree-dump {#pragma omp target num_teams.* map\(struct:a \[len: 1\]\) map\(alloc:a\.ptr \[len: [0-9]+\]\) map\(tofrom:\*_[0-9]+ \[len: [0-9]+\]\) map\(attach:a\.ptr \[bias: 0\]\)} "gimple" } } */
+/* { dg-final { scan-tree-dump-not {map\(struct:a \[len: 1\]\) map\(alloc:a\.ptr \[len: 0\]\)} "gimple" } } */
@@ -42,5 +42,7 @@ main (void)
#pragma omp target exit data map(from:a.ptr, a.ptr[:N])
+ free (a.ptr);
+
return 0;
}
new file mode 100644
@@ -0,0 +1,50 @@
+#include <stdlib.h>
+
+#define N 10
+
+struct S
+{
+ int a, b;
+ int *ptr;
+ int c, d;
+};
+
+int
+main (void)
+{
+ struct S a;
+ a.ptr = (int *) malloc (sizeof (int) * N);
+
+ for (int i = 0; i < N; i++)
+ a.ptr[i] = 0;
+
+ #pragma omp target enter data map(to: a.ptr)
+ #pragma omp target enter data map(to: a.ptr[:N])
+
+ #pragma omp target
+ for (int i = 0; i < N; i++)
+ a.ptr[i] += 1;
+
+ #pragma omp target update from(a.ptr[:N])
+
+ for (int i = 0; i < N; i++)
+ if (a.ptr[i] != 1)
+ abort ();
+
+ #pragma omp target map(a.ptr[:N])
+ for (int i = 0; i < N; i++)
+ a.ptr[i] += 1;
+
+ #pragma omp target update from(a.ptr[:N])
+
+ for (int i = 0; i < N; i++)
+ if (a.ptr[i] != 2)
+ abort ();
+
+ #pragma omp target exit data map(release: a.ptr[:N])
+ #pragma omp target exit data map(release: a.ptr)
+
+ free (a.ptr);
+
+ return 0;
+}
new file mode 100644
@@ -0,0 +1,36 @@
+#include <stdlib.h>
+
+#define N 10
+
+struct S
+{
+ int a, b;
+ int *ptr;
+ int c, d;
+};
+
+int
+main (void)
+{
+ struct S a;
+ a.ptr = (int *) malloc (sizeof (int) * N);
+
+ for (int i = 0; i < N; i++)
+ a.ptr[i] = 0;
+
+ #pragma omp target enter data map(to: a.ptr[:N])
+
+ #pragma omp target map(a, a.ptr[:0])
+ for (int i = 0; i < N; i++)
+ a.ptr[i] += 1;
+
+ #pragma omp target exit data map(from: a.ptr[:N])
+
+ for (int i = 0; i < N; i++)
+ if (a.ptr[i] != 1)
+ abort ();
+
+ free (a.ptr);
+
+ return 0;
+}
@@ -21,8 +21,7 @@ main ()
s.v.b = a + 16;
s.w = c + 3;
int err = 0;
- #pragma omp target map (to: s.w, s.v.b, s.u, s.s) \
- map (to:s.v.b[0:z + 7], s.u[z + 1:z + 4]) \
+ #pragma omp target map (to:s.v.b[0:z + 7], s.u[z + 1:z + 4]) \
map (tofrom:s.s[3:3]) \
map (from: s.w[z:4], err) private (i)
{