[clang] Implement lifetime analysis for lifetime_capture_by(X) (#115921)
[llvm-project.git] / clang / test / Sema / __try.c
blob9bfd914c013c15ebb21c74583214c988a89462b2
1 // RUN: %clang_cc1 -triple x86_64-windows -fborland-extensions -DBORLAND -fsyntax-only -verify -fblocks %s
2 // RUN: %clang_cc1 -triple x86_64-windows -fms-extensions -fsyntax-only -verify -fblocks %s
4 #define JOIN2(x,y) x ## y
5 #define JOIN(x,y) JOIN2(x,y)
6 #define TEST2(name) JOIN(name,__LINE__)
7 #define TEST TEST2(test)
8 typedef int DWORD;
10 #pragma sysheader begin
12 struct EXCEPTION_INFO{};
14 unsigned long __exception_code(void);
15 #ifdef BORLAND
16 struct EXCEPTION_INFO* __exception_info(void);
17 #endif
18 int __abnormal_termination(void);
20 #define GetExceptionCode __exception_code
21 #define GetExceptionInformation __exception_info
22 #define AbnormalTermination __abnormal_termination
24 #pragma sysheader end
26 DWORD FilterExpression(int); // expected-note{{declared here}}
27 DWORD FilterExceptionInformation(struct EXCEPTION_INFO*);
29 const char * NotFilterExpression(void);
31 void TEST(void) {
32 __try {
33 __try {
34 __try {
36 __finally{
39 __finally{
42 __finally{
46 void TEST(void) {
47 __try {
50 } // expected-error{{expected '__except' or '__finally' block}}
52 void TEST(void) {
53 __except (FilterExpression()) { // expected-error{{call to undeclared function '__except'; ISO C99 and later do not support implicit function declarations}} \
54 // expected-error{{too few arguments to function call, expected 1, have 0}} \
55 // expected-error{{expected ';' after expression}}
59 void TEST(void) {
60 __finally { } // expected-error{{}}
63 void TEST(void) {
64 __try{
65 int try_scope = 0;
66 } // TODO: expected expression is an extra error
67 __except( try_scope ? 1 : -1 ) // expected-error{{undeclared identifier 'try_scope'}} expected-error{{expected expression}}
71 void TEST(void) {
72 __try {
75 // TODO: Why are there two errors?
76 __except( ) { // expected-error{{expected expression}} expected-error{{expected expression}}
80 void TEST(void) {
81 __try {
84 __except ( FilterExpression(GetExceptionCode()) ) {
88 __try {
91 __except( FilterExpression(__exception_code()) ) {
95 __try {
98 __except( FilterExceptionInformation(__exception_info()) ) {
102 __try {
105 __except(FilterExceptionInformation( GetExceptionInformation() ) ) {
110 void TEST(void) {
111 __try {
114 __except ( NotFilterExpression() ) { // expected-error{{filter expression has non-integral type 'const char *'}}
119 void TEST(void) {
120 int function_scope = 0;
121 __try {
122 int try_scope = 0;
124 __except ( FilterExpression(GetExceptionCode()) ) {
125 (void)function_scope;
126 (void)try_scope; // expected-error{{undeclared identifier}}
130 void TEST(void) {
131 int function_scope = 0;
132 __try {
133 int try_scope = 0;
135 __finally {
136 (void)function_scope;
137 (void)try_scope; // expected-error{{undeclared identifier}}
141 void TEST(void) {
142 int function_scope = 0;
143 __try {
146 __except( function_scope ? 1 : -1 ) {}
149 #ifdef BORLAND
150 void TEST(void) {
151 (void)__abnormal_termination(); // expected-error{{only allowed in __finally block}}
152 (void)AbnormalTermination(); // expected-error{{only allowed in __finally block}}
154 __try {
155 (void)AbnormalTermination; // expected-error{{only allowed in __finally block}}
156 (void)__abnormal_termination; // expected-error{{only allowed in __finally block}}
158 __except( 1 ) {
159 (void)AbnormalTermination; // expected-error{{only allowed in __finally block}}
160 (void)__abnormal_termination; // expected-error{{only allowed in __finally block}}
163 __try {
165 __finally {
166 AbnormalTermination();
167 __abnormal_termination();
170 #endif
172 void TEST(void) {
173 (void)__exception_info(); // expected-error{{only allowed in __except filter expression}}
174 (void)GetExceptionInformation(); // expected-error{{only allowed in __except filter expression}}
177 void TEST(void) {
178 #ifndef BORLAND
179 (void)__exception_code; // expected-error{{builtin functions must be directly called}}
180 #endif
181 (void)__exception_code(); // expected-error{{only allowed in __except block or filter expression}}
182 (void)GetExceptionCode(); // expected-error{{only allowed in __except block or filter expression}}
185 void TEST(void) {
186 __try {
187 } __except(1) {
188 GetExceptionCode(); // valid
189 GetExceptionInformation(); // expected-error{{only allowed in __except filter expression}}
193 void test_seh_leave_stmt(void) {
194 __leave; // expected-error{{'__leave' statement not in __try block}}
196 __try {
197 __leave;
198 __leave 4; // expected-error{{expected ';' after __leave statement}}
199 } __except(1) {
200 __leave; // expected-error{{'__leave' statement not in __try block}}
203 __try {
204 __leave;
205 } __finally {
206 __leave; // expected-error{{'__leave' statement not in __try block}}
208 __leave; // expected-error{{'__leave' statement not in __try block}}
211 void test_jump_out_of___finally(void) {
212 while(1) {
213 __try {
214 } __finally {
215 continue; // expected-warning{{jump out of __finally block has undefined behavior}}
218 __try {
219 } __finally {
220 while (1) {
221 continue;
225 // Check that a deep __finally containing a block with a shallow continue
226 // doesn't trigger the warning.
227 while(1) {{{{
228 __try {
229 } __finally {
231 while(1)
232 continue;
233 }();
235 }}}}
237 while(1) {
238 __try {
239 } __finally {
240 break; // expected-warning{{jump out of __finally block has undefined behavior}}
243 switch(1) {
244 case 1:
245 __try {
246 } __finally {
247 break; // expected-warning{{jump out of __finally block has undefined behavior}}
250 __try {
251 } __finally {
252 while (1) {
253 break;
257 __try {
258 __try {
259 } __finally {
260 __leave; // expected-warning{{jump out of __finally block has undefined behavior}}
262 } __finally {
264 __try {
265 } __finally {
266 __try {
267 __leave;
268 } __finally {
272 __try {
273 } __finally {
274 return; // expected-warning{{jump out of __finally block has undefined behavior}}
277 __try {
278 } __finally {
280 return;
281 }();
285 void test_typo_in_except(void) {
286 __try {
287 } __except(undeclared_identifier) { // expected-error {{use of undeclared identifier 'undeclared_identifier'}} expected-error {{expected expression}}