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