aboutsummaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/gomp/target-this-4.C
blob: 3b2d5811350bfe1efb36e1f3f75e9b10c13b2565 (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// We use 'auto' without a function return type, so specify dialect here
// { dg-additional-options "-std=c++14 -fdump-tree-gimple" }
#include <cstdlib>
#include <cstring>

struct T
{
  int *ptr;
  int ptr_len;

  int *&refptr;
  int refptr_len;

  auto set_ptr_func (int n)
  {
    auto fn = [=](void) -> bool
      {
	bool mapped;
	#pragma omp target map(from:mapped)
	{
	  if (ptr)
	    for (int i = 0; i < ptr_len; i++)
	      ptr[i] = n;
	  mapped = (ptr != NULL);
	}
	return mapped;
      };
    return fn;
  }

  auto set_refptr_func (int n)
  {
    auto fn = [=](void) -> bool
      {
	bool mapped;
	#pragma omp target map(from:mapped)
	{
	  if (refptr)
	    for (int i = 0; i < refptr_len; i++)
	      refptr[i] = n;
	  mapped = (refptr != NULL);
	}
	return mapped;
      };
    return fn;
  }
};

int main (void)
{
  #define N 10
  int *ptr1 = new int[N];
  int *ptr2 = new int[N];

  memset (ptr1, 0, sizeof (int) * N);
  memset (ptr2, 0, sizeof (int) * N);

  T a = { ptr1, N, ptr2, N };

  auto p1 = a.set_ptr_func (1);
  auto r2 = a.set_refptr_func (2);

  if (p1 ())
    abort ();
  if (r2 ())
    abort ();

  if (a.ptr != ptr1)
    abort ();
  if (a.refptr != ptr2)
    abort ();

  for (int i = 0; i < N; i++)
    if (ptr1[i] != 0)
      abort ();

  for (int i = 0; i < N; i++)
    if (ptr2[i] != 0)
      abort ();

  #pragma omp target data map(ptr1[:N], ptr2[:N])
  {
    if (!p1 ())
      abort ();
    if (!r2 ())
      abort ();
  }

  if (a.ptr != ptr1)
    abort ();
  if (a.refptr != ptr2)
    abort ();

  for (int i = 0; i < N; i++)
    if (ptr1[i] != 1)
      abort ();

  for (int i = 0; i < N; i++)
    if (ptr2[i] != 2)
      abort ();

  return 0;
}

/* { dg-final { scan-tree-dump {#pragma omp target num_teams.* map\(to:\*__closure \[len: [0-9]+\]\) map\(firstprivate:__closure \[pointer assign, bias: 0\]\) map\(struct:\*__closure \[len: 1\]\) map\(alloc:__closure->__this \[len: [0-9]+\]\) map\(tofrom:\*_[0-9]+ \[len: [0-9]+\]\) map\(always_pointer:__closure->__this \[pointer assign, bias: 0\]\) map\(attach_zero_length_array_section:_[0-9]+->ptr \[bias: 0\]\) map\(from:mapped \[len: 1\]\) map\(alloc:\*_[0-9]+ \[len: 0\]\) firstprivate\(n\) map\(alloc:MEM.* \[len: 0\]\) map\(firstprivate:this \[pointer assign, bias: 0\]\)} "gimple" } } */

/* { dg-final { scan-tree-dump {#pragma omp target num_teams.* map\(to:\*__closure \[len: [0-9]+\]\) map\(firstprivate:__closure \[pointer assign, bias: 0\]\) map\(struct:\*__closure \[len: 1\]\) map\(alloc:__closure->__this \[len: [0-9]+\]\) map\(tofrom:\*_[0-9]+ \[len: [0-9]+\]\) map\(always_pointer:__closure->__this \[pointer assign, bias: 0\]\) map\(alloc:\*_[0-9]+ \[pointer assign, zero-length array section, bias: 0\]\) map\(attach:_[0-9]+->refptr \[bias: 0\]\) map\(from:mapped \[len: [0-9]+\]\) map\(alloc:\*_[0-9]+ \[len: 0\]\) firstprivate\(n\) map\(alloc:MEM.* \[len: 0\]\) map\(firstprivate:this \[pointer assign, bias: 0\]\)} "gimple" } } */