1 // RUN: %clang_cc1 -fsyntax-only -fopenmp -verify %s
2 
3 void foo();
4 
5 // expected-error@+1 {{unexpected OpenMP directive '#pragma omp single'}}
6 #pragma omp single
7 
8 // expected-error@+1 {{unexpected OpenMP directive '#pragma omp single'}}
9 #pragma omp single foo
10 
11 void test_no_clause() {
12   int i;
13 #pragma omp single
14   foo();
15 
16 #pragma omp single
17   ++i;
18 }
19 
20 void test_branch_protected_scope() {
21   int i = 0;
22 L1:
23   ++i;
24 
25   int x[24];
26 
27 #pragma omp parallel
28 #pragma omp single
29   {
30     if (i == 5)
31       goto L1; // expected-error {{use of undeclared label 'L1'}}
32     else if (i == 6)
33       return; // expected-error {{cannot return from OpenMP region}}
34     else if (i == 7)
35       goto L2;
36     else if (i == 8) {
37     L2:
38       x[i]++;
39     }
40   }
41 
42   if (x[0] == 0)
43     goto L2; // expected-error {{use of undeclared label 'L2'}}
44   else if (x[1] == 1)
45     goto L1;
46 }
47 
48 void test_invalid_clause() {
49   int i;
50 #pragma omp parallel
51 // expected-warning@+1 {{extra tokens at the end of '#pragma omp single' are ignored}}
52 #pragma omp single foo bar
53   foo();
54 }
55 
56 void test_non_identifiers() {
57   int i, x;
58 
59 #pragma omp parallel
60 // expected-warning@+1 {{extra tokens at the end of '#pragma omp single' are ignored}}
61 #pragma omp single;
62   foo();
63 #pragma omp parallel
64 // expected-error@+2 {{unexpected OpenMP clause 'linear' in directive '#pragma omp single'}}
65 // expected-warning@+1 {{extra tokens at the end of '#pragma omp single' are ignored}}
66 #pragma omp single linear(x);
67   foo();
68 
69 #pragma omp parallel
70 // expected-warning@+1 {{extra tokens at the end of '#pragma omp single' are ignored}}
71 #pragma omp single private(x);
72   foo();
73 
74 #pragma omp parallel
75 // expected-warning@+1 {{extra tokens at the end of '#pragma omp single' are ignored}}
76 #pragma omp single, private(x);
77   foo();
78 }
79 
80 void test_private() {
81   int i;
82 #pragma omp parallel
83 // expected-error@+2 {{expected expression}}
84 // expected-error@+1 {{expected ')'}} expected-note@+1 {{to match this '('}}
85 #pragma omp single private(
86   foo();
87 #pragma omp parallel
88 // expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}}
89 // expected-error@+1 2 {{expected expression}}
90 #pragma omp single private(,
91   foo();
92 #pragma omp parallel
93 // expected-error@+1 2 {{expected expression}}
94 #pragma omp single private(, )
95   foo();
96 #pragma omp parallel
97 // expected-error@+1 {{expected expression}}
98 #pragma omp single private()
99   foo();
100 #pragma omp parallel
101 // expected-error@+1 {{expected expression}}
102 #pragma omp single private(int)
103   foo();
104 #pragma omp parallel
105 // expected-error@+1 {{expected variable name}}
106 #pragma omp single private(0)
107   foo();
108 
109   int x, y, z;
110 #pragma omp parallel
111 #pragma omp single private(x)
112   foo();
113 #pragma omp parallel
114 #pragma omp single private(x, y)
115   foo();
116 #pragma omp parallel
117 #pragma omp single private(x, y, z)
118   foo();
119 }
120 
121 void test_firstprivate() {
122   int i;
123 #pragma omp parallel
124 // expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}}
125 // expected-error@+1 {{expected expression}}
126 #pragma omp single firstprivate(
127   foo();
128 
129 #pragma omp parallel
130 // expected-error@+2 {{expected ')'}} expected-note@+2 {{to match this '('}}
131 // expected-error@+1 2 {{expected expression}}
132 #pragma omp single firstprivate(,
133   foo();
134 #pragma omp parallel
135 // expected-error@+1 2 {{expected expression}}
136 #pragma omp single firstprivate(, )
137   foo();
138 #pragma omp parallel
139 // expected-error@+1 {{expected expression}}
140 #pragma omp single firstprivate()
141   foo();
142 #pragma omp parallel
143 // expected-error@+1 {{expected expression}}
144 #pragma omp single firstprivate(int)
145   foo();
146 #pragma omp parallel
147 // expected-error@+1 {{expected variable name}}
148 #pragma omp single firstprivate(0)
149   foo();
150 }
151 
152 void test_nowait() {
153 #pragma omp single nowait nowait // expected-error {{directive '#pragma omp single' cannot contain more than one 'nowait' clause}}
154   for (int i = 0; i < 16; ++i)
155     ;
156 }
157