aboutsummaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.c/target-map-zero-sized-2.c
blob: 3220828efd05f7477f1846086e2e62c5fefd23b5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
int
main ()
{
  int i, n;
  int data[] = {1,2};
  struct S { int **ptrset; };

// -----------------------------------

/* The produced mapping for sptr1->ptrset[i][:n]

   GOMP_MAP_STRUCT (size = 1)
      GOMP_MAP_ZERO_LEN_ARRAY_SECTION
   GOMP_MAP_ZERO_LEN_ARRAY_SECTION
      GOMP_MAP_ATTACH
   GOMP_MAP_ATTACH -> attaching to 2nd GOMP_MAP_ZERO_LEN_ARRAY_SECTION

which get split into 3 separate map_vars call; in particular,
the latter is separate and points to an unmpapped variable.

Thus, it failed with:
   libgomp: pointer target not mapped for attach  */

  struct S s1, *sptr1;
  s1.ptrset = (int **) __builtin_malloc (sizeof(void*) * 3);
  s1.ptrset[0] = data;
  s1.ptrset[1] = data;
  s1.ptrset[2] = data;
  sptr1 = &s1;

  i = 1;
  n = 0;
  #pragma omp target enter data map(sptr1[:1], sptr1->ptrset[:3])
  #pragma omp target enter data map(sptr1->ptrset[i][:n])

  #pragma omp target exit data map(sptr1->ptrset[i][:n])
  #pragma omp target exit data map(sptr1[:1], sptr1->ptrset[:3])

  __builtin_free (s1.ptrset);

// -----------------------------------

/* The produced mapping for sptr2->ptrset[i][:n] is similar:

   GOMP_MAP_STRUCT (size = 1)
      GOMP_MAP_ZERO_LEN_ARRAY_SECTION
   GOMP_MAP_TO  ! this one has now a finite size
      GOMP_MAP_ATTACH
   GOMP_MAP_ATTACH -> attach to the GOMP_MAP_TO

As the latter GOMP_MAP_ATTACH has now a pointer target,
the attachment worked.  */

  struct S s2, *sptr2;
  s2.ptrset = (int **) __builtin_malloc (sizeof(void*) * 3);
  s2.ptrset[0] = data;
  s2.ptrset[1] = data;
  s2.ptrset[2] = data;
  sptr2 = &s2;

  i = 1;
  n = 2;
  #pragma omp target enter data map(sptr2[:1], sptr2->ptrset[:3])
  #pragma omp target enter data map(sptr2->ptrset[i][:n])

  #pragma omp target
    if (sptr2->ptrset[1][0] != 1 || sptr2->ptrset[1][1] != 2)
      __builtin_abort ();

  #pragma omp target exit data map(sptr2->ptrset[i][:n])
  #pragma omp target exit data map(sptr2[:1], sptr2->ptrset[:3])

  __builtin_free (s2.ptrset);
}