aboutsummaryrefslogtreecommitdiffstats
path: root/gcc-4.2.1-5666.3/libgomp/testsuite/libgomp.c++/pr27337.C
blob: 6db2465ec3ad5c5c2251a5bd86c4263032851d0c (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
// PR middle-end/27337
// { dg-do run }

#include <omp.h>

extern "C" void abort (void);

struct S
{
  S ();
  ~S ();
  S (const S &);
  int i;
};

int n[3];

S::S () : i(18)
{
  if (omp_get_thread_num () != 0)
#pragma omp atomic
    n[0]++;
}

S::~S ()
{
  if (omp_get_thread_num () != 0)
#pragma omp atomic
    n[1]++;
}

S::S (const S &x)
{
  if (x.i != 18)
    abort ();
  i = 118;
  if (omp_get_thread_num () != 0)
#pragma omp atomic
    n[2]++;
}

S
foo ()
{
  int i;
  S ret;

#pragma omp parallel for firstprivate (ret) lastprivate (ret) \
			 schedule (static, 1) num_threads (4)
  for (i = 0; i < 4; i++)
    ret.i += omp_get_thread_num ();

  return ret;
}

S
bar ()
{
  int i;
  S ret;

#pragma omp parallel for num_threads (4)
  for (i = 0; i < 4; i++)
#pragma omp atomic
    ret.i += omp_get_thread_num () + 1;

  return ret;
}

S x;

int
main (void)
{
  omp_set_dynamic (false);
  x = foo ();
  if (n[0] != 0 || n[1] != 3 || n[2] != 3)
    abort ();
  if (x.i != 118 + 3)
    abort ();
  x = bar ();
  if (n[0] != 0 || n[1] != 3 || n[2] != 3)
    abort ();
  if (x.i != 18 + 0 + 1 + 2 + 3 + 4)
    abort ();
  return 0;
}