aboutsummaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.c-c++-common/target-has-device-addr-1.c
blob: fcc5c9e85534fb9d26b70c434acd52827c202529 (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
/* Testing the 'has_device_addr' clause on the target construct with
   enclosing 'target data' construct. */

#define N 40

int
main ()
{
  int x = 24;

  #pragma omp target data map(x) use_device_addr(x)
    #pragma omp target has_device_addr(x)
      x = 42;
  if (x != 42)
    __builtin_abort ();

  int y[N];

  for (int i = 0; i < N; i++)
    y[i] = 42;
  #pragma omp target data map(y) use_device_addr(y)
    #pragma omp target has_device_addr(y)
      for (int i = 0; i < N; i++)
	y[i] = i;
  for (int i = 0; i < N; i++)
    if (y[i] != i)
      __builtin_abort ();

  #pragma omp target data map(y[:N]) use_device_addr(y)
    #pragma omp target has_device_addr(y[:N])
      for (int i = 0; i < N; i++)
	y[i] = i + 2;
  for (int i = 0; i < N; i++)
    if (y[i] != i + 2)
      __builtin_abort ();

  #pragma omp target data map(y[:N]) use_device_addr(y)
    #pragma omp target has_device_addr(y[24])
	y[24] = 42;
  if (y[24] != 42)
    __builtin_abort ();

  #pragma omp target data map(y[:N]) use_device_addr(y)
    #pragma omp target has_device_addr(y[24:])
      for (int i = 24; i < N; i++)
	y[i] = i + 3;
  for (int i = 24; i < N; i++)
    if (y[i] != i + 3)
      __builtin_abort ();

  #pragma omp target data map(y[:N]) use_device_addr(y)
    #pragma omp target has_device_addr(y[12:24])
      for (int i = 12; i < 24; i++)
	y[i] = i + 4;
  for (int i = 12; i < 24; i++)
    if (y[i] != i + 4)
      __builtin_abort ();

  int u[0];
  #pragma omp target data map(u) use_device_addr(u)
    #pragma omp target has_device_addr(u)
  ;

  struct S { int m; } s;
  s.m = 42;
  #pragma omp target data map (s) use_device_addr (s)
    #pragma omp target has_device_addr (s)
      ++s.m;
  if (s.m != 43)
    __builtin_abort ();

  return 0;
}