xref: /llvm-project/clang/test/OpenMP/parallel_sections_if_messages.cpp (revision 655cb4a2d702b70899f3ad384d047537e02698d8)
1 // RUN: %clang_cc1 -verify -fopenmp -fopenmp-version=45 -ferror-limit 100 %s -Wuninitialized
2 
3 // RUN: %clang_cc1 -verify -fopenmp-simd -fopenmp-version=45 -ferror-limit 100 %s -Wuninitialized
4 
5 void foo() {
6 }
7 
8 bool foobool(int argc) {
9   return argc;
10 }
11 
12 void xxx(int argc) {
13   int cond; // expected-note {{initialize the variable 'cond' to silence this warning}}
14 #pragma omp parallel sections if(cond) // expected-warning {{variable 'cond' is uninitialized when used here}}
15   {
16     ;
17   }
18 }
19 
20 struct S1; // expected-note {{declared here}}
21 
22 template <class T, class S> // expected-note {{declared here}}
23 int tmain(T argc, S **argv) {
24   T z;
25   #pragma omp parallel sections if // expected-error {{expected '(' after 'if'}}
26   {
27     foo();
28   }
29   #pragma omp parallel sections if ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
30   {
31     foo();
32   }
33   #pragma omp parallel sections if () // expected-error {{expected expression}}
34   {
35     foo();
36   }
37   #pragma omp parallel sections if (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
38   {
39     foo();
40   }
41   #pragma omp parallel sections if (argc)) // expected-warning {{extra tokens at the end of '#pragma omp parallel sections' are ignored}}
42   {
43     foo();
44   }
45   #pragma omp parallel sections if (argc > 0 ? argv[1] : argv[2])
46   {
47     foo();
48   }
49   #pragma omp parallel sections if (foobool(argc)), if (true) // expected-error {{directive '#pragma omp parallel sections' cannot contain more than one 'if' clause}}
50   {
51     foo();
52   }
53   #pragma omp parallel sections if (S) // expected-error {{'S' does not refer to a value}}
54   {
55     foo();
56   }
57   #pragma omp parallel sections if (argv[1]=2) // expected-error {{expected ')'}} expected-note {{to match this '('}}
58   {
59     foo();
60   }
61   #pragma omp parallel sections if (argc argc) // expected-error {{expected ')'}} expected-note {{to match this '('}}
62   {
63     foo();
64   }
65   #pragma omp parallel sections if(argc + z)
66   {
67     foo();
68   }
69   #pragma omp parallel sections if(parallel : // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
70   {
71     foo();
72   }
73   #pragma omp parallel sections if(parallel : argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
74   {
75     foo();
76   }
77   #pragma omp parallel sections if(parallel : argc)
78   {
79     foo();
80   }
81   #pragma omp parallel sections if(parallel : argc) if (for:argc) // expected-error {{directive name modifier 'for' is not allowed for '#pragma omp parallel sections'}}
82   {
83     foo();
84   }
85   #pragma omp parallel sections if(parallel : argc) if (parallel:argc) // expected-error {{directive '#pragma omp parallel sections' cannot contain more than one 'if' clause with 'parallel' name modifier}}
86   {
87     foo();
88   }
89   #pragma omp parallel sections if(parallel : argc) if (argc) // expected-error {{no more 'if' clause is allowed}} expected-note {{previous clause with directive name modifier specified here}}
90   {
91     foo();
92   }
93 
94   return 0;
95 }
96 
97 int main(int argc, char **argv) {
98   int z;
99   #pragma omp parallel sections if // expected-error {{expected '(' after 'if'}}
100   {
101     foo();
102   }
103   #pragma omp parallel sections if ( // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
104   {
105     foo();
106   }
107   #pragma omp parallel sections if () // expected-error {{expected expression}}
108   {
109     foo();
110   }
111   #pragma omp parallel sections if (argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
112   {
113     foo();
114   }
115   #pragma omp parallel sections if (argc)) // expected-warning {{extra tokens at the end of '#pragma omp parallel sections' are ignored}}
116   {
117     foo();
118   }
119   #pragma omp parallel sections if (argc > 0 ? argv[1] : argv[2] + z)
120   {
121     foo();
122   }
123   #pragma omp parallel sections if (foobool(argc)), if (true) // expected-error {{directive '#pragma omp parallel sections' cannot contain more than one 'if' clause}}
124   {
125     foo();
126   }
127   #pragma omp parallel sections if (S1) // expected-error {{'S1' does not refer to a value}}
128   {
129     foo();
130   }
131   #pragma omp parallel sections if (argv[1]=2) // expected-error {{expected ')'}} expected-note {{to match this '('}}
132   {
133     foo();
134   }
135   #pragma omp parallel sections if (argc argc) // expected-error {{expected ')'}} expected-note {{to match this '('}}
136   {
137     foo();
138   }
139   #pragma omp parallel sections if (1 0) // expected-error {{expected ')'}} expected-note {{to match this '('}}
140   {
141     foo();
142   }
143   #pragma omp parallel sections if(if(tmain(argc, argv) // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
144   {
145     foo();
146   }
147   #pragma omp parallel sections if(parallel : // expected-error {{expected expression}} expected-error {{expected ')'}} expected-note {{to match this '('}}
148   {
149     foo();
150   }
151   #pragma omp parallel sections if(parallel : argc // expected-error {{expected ')'}} expected-note {{to match this '('}}
152   {
153     foo();
154   }
155   #pragma omp parallel sections if(parallel : argc)
156   {
157     foo();
158   }
159   #pragma omp parallel sections if(parallel : argc) if (for:argc) // expected-error {{directive name modifier 'for' is not allowed for '#pragma omp parallel sections'}}
160   {
161     foo();
162   }
163   #pragma omp parallel sections if(parallel : argc) if (parallel:argc) // expected-error {{directive '#pragma omp parallel sections' cannot contain more than one 'if' clause with 'parallel' name modifier}}
164   {
165     foo();
166   }
167   #pragma omp parallel sections if(parallel : argc) if (argc) // expected-error {{no more 'if' clause is allowed}} expected-note {{previous clause with directive name modifier specified here}}
168   {
169     foo();
170   }
171 
172   return tmain(argc, argv);
173 }
174