summaryrefslogtreecommitdiff
path: root/libgomp/testsuite/libgomp.c++/task-5.C
blob: c882bfe1517251e260a850d810cf28a46b9265d1 (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
// { dg-do run }

extern "C" void abort ();

struct A
{
  A ();
  ~A ();
  A (const A &);
  unsigned long l;
};

int e;

A::A ()
{
  l = 17;
}

A::~A ()
{
  if (l > 130)
    #pragma omp atomic
      e++;
}

A::A (const A &r)
{
  l = r.l + 64;
}

void
check (int i, A &a, int j, A &b)
{
  if (i != 6 || a.l != 21 + 64 || j != 0 || b.l != 23 + 64)
    #pragma omp atomic
      e++;
}

A b;
int j;

void
foo (int i)
{
  A a;
  a.l = 21;
  #pragma omp task firstprivate (j, b)
    check (i, a, j, b);
}

void
bar (int i, A a)
{
  a.l = 21;
  #pragma omp task firstprivate (j, b)
    check (i, a, j, b);
}

A
baz ()
{
  A a, c;
  a.l = 21;
  c.l = 23;
  #pragma omp task firstprivate (a, c)
    check (6, a, 0, c);
  return a;
}

int
main ()
{
  b.l = 23;
  foo (6);
  bar (6, A ());
  baz ();
  #pragma omp parallel num_threads (4)
    {
      #pragma omp single
	for (int i = 0; i < 64; i++)
	  {
	    foo (6);
	    bar (6, A ());
	    baz ();
	  }
    }
  if (e)
    abort ();
}