1*404b540aSrobert /* { dg-do run } */
2*404b540aSrobert
3*404b540aSrobert int x, *p = &x;
4*404b540aSrobert extern void abort (void);
5*404b540aSrobert void
f1(int * q)6*404b540aSrobert f1 (int *q)
7*404b540aSrobert {
8*404b540aSrobert *q = 1;
9*404b540aSrobert #pragma omp flush
10*404b540aSrobert /* x, p, and *q are flushed */
11*404b540aSrobert /* because they are shared and accessible */
12*404b540aSrobert /* q is not flushed because it is not shared. */
13*404b540aSrobert }
14*404b540aSrobert
15*404b540aSrobert void
f2(int * q)16*404b540aSrobert f2 (int *q)
17*404b540aSrobert {
18*404b540aSrobert #pragma omp barrier
19*404b540aSrobert *q = 2;
20*404b540aSrobert #pragma omp barrier
21*404b540aSrobert /* a barrier implies a flush */
22*404b540aSrobert /* x, p, and *q are flushed */
23*404b540aSrobert /* because they are shared and accessible */
24*404b540aSrobert /* q is not flushed because it is not shared. */
25*404b540aSrobert }
26*404b540aSrobert
27*404b540aSrobert int
g(int n)28*404b540aSrobert g (int n)
29*404b540aSrobert {
30*404b540aSrobert int i = 1, j, sum = 0;
31*404b540aSrobert *p = 1;
32*404b540aSrobert #pragma omp parallel reduction(+: sum) num_threads(2)
33*404b540aSrobert {
34*404b540aSrobert f1 (&j);
35*404b540aSrobert /* i, n and sum were not flushed */
36*404b540aSrobert /* because they were not accessible in f1 */
37*404b540aSrobert /* j was flushed because it was accessible */
38*404b540aSrobert sum += j;
39*404b540aSrobert f2 (&j);
40*404b540aSrobert /* i, n, and sum were not flushed */
41*404b540aSrobert /* because they were not accessible in f2 */
42*404b540aSrobert /* j was flushed because it was accessible */
43*404b540aSrobert sum += i + j + *p + n;
44*404b540aSrobert }
45*404b540aSrobert return sum;
46*404b540aSrobert }
47*404b540aSrobert
48*404b540aSrobert int
main()49*404b540aSrobert main ()
50*404b540aSrobert {
51*404b540aSrobert int result = g (10);
52*404b540aSrobert if (result != 30)
53*404b540aSrobert abort ();
54*404b540aSrobert return 0;
55*404b540aSrobert }
56