1 // RUN: %clang_cc1 -verify -fopenmp %s
2 
3 // RUN: %clang_cc1 -verify -fopenmp-simd %s
4 
5 int foo();
6 
7 template<typename T, int N>
tmain(int argc,char ** argv)8 int tmain(int argc, char **argv) { // expected-note {{declared here}}
9   #pragma omp critical
10   ;
11   #pragma omp critical untied // expected-error {{unexpected OpenMP clause 'untied' in directive '#pragma omp critical'}}
12   #pragma omp critical unknown // expected-warning {{extra tokens at the end of '#pragma omp critical' are ignored}}
13   #pragma omp critical ( // expected-error {{expected identifier}} expected-error {{expected ')'}} expected-note {{to match this '('}}
14   #pragma omp critical ( + // expected-error {{expected identifier}} expected-error {{expected ')'}} expected-note {{to match this '('}}
15   #pragma omp critical (name2 // expected-error {{expected ')'}} expected-note {{to match this '('}}
16   #pragma omp critical (name1)
17   foo();
18   {
19     #pragma omp critical
20   } // expected-error {{expected statement}}
21   #pragma omp critical (name2) // expected-note {{previous 'critical' region starts here}}
22   #pragma omp critical
23   for (int i = 0; i < 10; ++i) {
24     foo();
25     #pragma omp parallel
26     #pragma omp for
27     for (int j = 0; j < 10; j++) {
28       foo();
29       #pragma omp critical(name2) // expected-error {{cannot nest 'critical' regions having the same name 'name2'}}
30       foo();
31     }
32   }
33   #pragma omp critical (name2)
34   #pragma omp critical
35   for (int i = 0; i < 10; ++i) {
36     foo();
37     #pragma omp parallel
38     #pragma omp for
39     for (int j = 0; j < 10; j++) {
40       #pragma omp critical
41       foo();
42     }
43   }
44   #pragma omp critical (name2)
45   #pragma omp critical
46   for (int i = 0; i < 10; ++i) {
47     foo();
48     #pragma omp parallel
49     #pragma omp for
50     for (int j = 0; j < 10; j++) {
51       #pragma omp critical (nam)
52       foo();
53     }
54   }
55 
56   #pragma omp critical (name2) hint // expected-error {{expected '(' after 'hint'}}
57   foo();
58   #pragma omp critical (name2) hint( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
59   foo();
60   #pragma omp critical (name2) hint(+ // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
61   foo();
62   #pragma omp critical (name2) hint(argc) // expected-error {{expression is not an integral constant expression}} expected-note {{read of non-const variable 'argc' is not allowed in a constant expression}}
63   foo();
64   #pragma omp critical (name) hint(N) // expected-error {{argument to 'hint' clause must be a strictly positive integer value}} expected-error {{constructs with the same name must have a 'hint' clause with the same value}} expected-note {{'hint' clause with value '4'}}
65   foo();
66   #pragma omp critical hint(N) // expected-error {{the name of the construct must be specified in presence of 'hint' clause}}
67   foo();
68   return 0;
69 }
70 
main(int argc,char ** argv)71 int main(int argc, char **argv) { // expected-note {{declared here}}
72   #pragma omp critical
73   ;
74   #pragma omp critical untied // expected-error {{unexpected OpenMP clause 'untied' in directive '#pragma omp critical'}}
75   #pragma omp critical unknown // expected-warning {{extra tokens at the end of '#pragma omp critical' are ignored}}
76   #pragma omp critical ( // expected-error {{expected identifier}} expected-error {{expected ')'}} expected-note {{to match this '('}}
77   #pragma omp critical ( + // expected-error {{expected identifier}} expected-error {{expected ')'}} expected-note {{to match this '('}}
78   #pragma omp critical (name2 // expected-error {{expected ')'}} expected-note {{to match this '('}}
79   #pragma omp critical (name1)
80   foo();
81   {
82     #pragma omp critical
83   } // expected-error {{expected statement}}
84   #pragma omp critical (name2) // expected-note {{previous 'critical' region starts here}}
85   #pragma omp critical
86   for (int i = 0; i < 10; ++i) {
87     foo();
88     #pragma omp parallel
89     #pragma omp for
90     for (int j = 0; j < 10; j++) {
91       foo();
92       #pragma omp critical(name2) // expected-error {{cannot nest 'critical' regions having the same name 'name2'}}
93       foo();
94     }
95   }
96   #pragma omp critical (name2)
97   #pragma omp critical
98   for (int i = 0; i < 10; ++i) {
99     foo();
100     #pragma omp parallel
101     #pragma omp for
102     for (int j = 0; j < 10; j++) {
103       #pragma omp critical
104       foo();
105     }
106   }
107   #pragma omp critical (name2)
108   #pragma omp critical
109   for (int i = 0; i < 10; ++i) {
110     foo();
111     #pragma omp parallel
112     #pragma omp for
113     for (int j = 0; j < 10; j++) {
114       #pragma omp critical (nam)
115       foo();
116     }
117   }
118 
119   #pragma omp critical (name2) hint // expected-error {{expected '(' after 'hint'}}
120   foo();
121   #pragma omp critical (name2) hint( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
122   foo();
123   #pragma omp critical (name2) hint(+ // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
124   foo();
125   #pragma omp critical (name2) hint(argc) // expected-error {{expression is not an integral constant expression}} expected-note {{read of non-const variable 'argc' is not allowed in a constant expression}}
126   foo();
127   #pragma omp critical (name) hint(23) // expected-note {{previous 'hint' clause with value '23'}}
128   foo();
129   #pragma omp critical hint(-5) // expected-error {{argument to 'hint' clause must be a strictly positive integer value}}
130   foo();
131   #pragma omp critical hint(1) // expected-error {{the name of the construct must be specified in presence of 'hint' clause}}
132   foo();
133   return tmain<int, 4>(argc, argv) + tmain<float, -5>(argc, argv); // expected-note {{in instantiation of function template specialization 'tmain<float, -5>' requested here}} expected-note {{in instantiation of function template specialization 'tmain<int, 4>' requested here}}
134 }
135 
foo()136 int foo() {
137   L1:
138     foo();
139   #pragma omp critical
140   {
141     foo();
142     goto L1; // expected-error {{use of undeclared label 'L1'}}
143   }
144   goto L2; // expected-error {{use of undeclared label 'L2'}}
145   #pragma omp critical
146   {
147     L2:
148     foo();
149   }
150 
151   return 0;
152  }
153