2018-01-22 Sebastian Perta <sebastian.perta@renesas.com>
[official-gcc.git] / libgomp / testsuite / libgomp.c++ / target-19.C
blobafa6e68d5cce5c83c00df95edb0fba7285503ba7
1 extern "C" void abort ();
2 struct S { char a[64]; int (&r)[2]; char b[64]; };
4 __attribute__((noinline, noclone)) void
5 foo (S s, int (&t)[3], int z)
7   int err, sep = 1;
8   // Test that implicit mapping of reference to array does NOT
9   // behave like zero length array sections.  s.r can't be used
10   // implicitly, as that means implicit mapping of the whole s
11   // and trying to dereference the references in there is unspecified.
12   #pragma omp target map(from: err) map(to: sep)
13   {
14     err = t[0] != 1 || t[1] != 2 || t[2] != 3;
15     sep = 0;
16   }
17   if (err) abort ();
18   // But explicit zero length array section mapping does.
19   #pragma omp target map(from: err) map(tofrom: s.r[:0], t[:0])
20   {
21     if (sep)
22       err = s.r != (int *) 0 || t != (int *) 0;
23     else
24       err = t[0] != 1 || t[1] != 2 || t[2] != 3 || s.r[0] != 6 || s.r[1] != 7;
25   }
26   if (err) abort ();
27   // Similarly zero length array section, but unknown at compile time.
28   #pragma omp target map(from: err) map(tofrom: s.r[:z], t[:z])
29   {
30     if (sep)
31       err = s.r != (int *) 0 || t != (int *) 0;
32     else
33       err = t[0] != 1 || t[1] != 2 || t[2] != 3 || s.r[0] != 6 || s.r[1] != 7;
34   }
35   if (err) abort ();
36   #pragma omp target enter data map (to: s.r, t)
37   // But when already mapped, it binds to existing mappings.
38   #pragma omp target map(from: err) map(tofrom: s.r[:0], t[:0])
39   {
40     err = t[0] != 1 || t[1] != 2 || t[2] != 3 || s.r[0] != 6 || s.r[1] != 7;
41     sep = 0;
42   }
43   if (err) abort ();
44   #pragma omp target map(from: err) map(tofrom: s.r[:z], t[:z])
45   {
46     err = t[0] != 1 || t[1] != 2 || t[2] != 3 || s.r[0] != 6 || s.r[1] != 7;
47     sep = 0;
48   }
49   if (err) abort ();
52 int
53 main ()
55   int t[3] = { 1, 2, 3 };
56   int r[2] = { 6, 7 };
57   S s = { {}, r, {} };
58   foo (s, t, 0);