aboutsummaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.c++/target-19.C
blob: afa6e68d5cce5c83c00df95edb0fba7285503ba7 (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
extern "C" void abort ();
struct S { char a[64]; int (&r)[2]; char b[64]; };

__attribute__((noinline, noclone)) void
foo (S s, int (&t)[3], int z)
{
  int err, sep = 1;
  // Test that implicit mapping of reference to array does NOT
  // behave like zero length array sections.  s.r can't be used
  // implicitly, as that means implicit mapping of the whole s
  // and trying to dereference the references in there is unspecified.
  #pragma omp target map(from: err) map(to: sep)
  {
    err = t[0] != 1 || t[1] != 2 || t[2] != 3;
    sep = 0;
  }
  if (err) abort ();
  // But explicit zero length array section mapping does.
  #pragma omp target map(from: err) map(tofrom: s.r[:0], t[:0])
  {
    if (sep)
      err = s.r != (int *) 0 || t != (int *) 0;
    else
      err = t[0] != 1 || t[1] != 2 || t[2] != 3 || s.r[0] != 6 || s.r[1] != 7;
  }
  if (err) abort ();
  // Similarly zero length array section, but unknown at compile time.
  #pragma omp target map(from: err) map(tofrom: s.r[:z], t[:z])
  {
    if (sep)
      err = s.r != (int *) 0 || t != (int *) 0;
    else
      err = t[0] != 1 || t[1] != 2 || t[2] != 3 || s.r[0] != 6 || s.r[1] != 7;
  }
  if (err) abort ();
  #pragma omp target enter data map (to: s.r, t)
  // But when already mapped, it binds to existing mappings.
  #pragma omp target map(from: err) map(tofrom: s.r[:0], t[:0])
  {
    err = t[0] != 1 || t[1] != 2 || t[2] != 3 || s.r[0] != 6 || s.r[1] != 7;
    sep = 0;
  }
  if (err) abort ();
  #pragma omp target map(from: err) map(tofrom: s.r[:z], t[:z])
  {
    err = t[0] != 1 || t[1] != 2 || t[2] != 3 || s.r[0] != 6 || s.r[1] != 7;
    sep = 0;
  }
  if (err) abort ();
}

int
main ()
{
  int t[3] = { 1, 2, 3 };
  int r[2] = { 6, 7 };
  S s = { {}, r, {} };
  foo (s, t, 0);
}