[testsuite] Require c99_runtime for pr79800.c
[official-gcc.git] / libgomp / testsuite / libgomp.c++ / pr27337.C
blob6db2465ec3ad5c5c2251a5bd86c4263032851d0c
1 // PR middle-end/27337
2 // { dg-do run }
4 #include <omp.h>
6 extern "C" void abort (void);
8 struct S
10   S ();
11   ~S ();
12   S (const S &);
13   int i;
16 int n[3];
18 S::S () : i(18)
20   if (omp_get_thread_num () != 0)
21 #pragma omp atomic
22     n[0]++;
25 S::~S ()
27   if (omp_get_thread_num () != 0)
28 #pragma omp atomic
29     n[1]++;
32 S::S (const S &x)
34   if (x.i != 18)
35     abort ();
36   i = 118;
37   if (omp_get_thread_num () != 0)
38 #pragma omp atomic
39     n[2]++;
43 foo ()
45   int i;
46   S ret;
48 #pragma omp parallel for firstprivate (ret) lastprivate (ret) \
49                          schedule (static, 1) num_threads (4)
50   for (i = 0; i < 4; i++)
51     ret.i += omp_get_thread_num ();
53   return ret;
57 bar ()
59   int i;
60   S ret;
62 #pragma omp parallel for num_threads (4)
63   for (i = 0; i < 4; i++)
64 #pragma omp atomic
65     ret.i += omp_get_thread_num () + 1;
67   return ret;
70 S x;
72 int
73 main (void)
75   omp_set_dynamic (false);
76   x = foo ();
77   if (n[0] != 0 || n[1] != 3 || n[2] != 3)
78     abort ();
79   if (x.i != 118 + 3)
80     abort ();
81   x = bar ();
82   if (n[0] != 0 || n[1] != 3 || n[2] != 3)
83     abort ();
84   if (x.i != 18 + 0 + 1 + 2 + 3 + 4)
85     abort ();
86   return 0;