blob: 0e5de2018db0a0d8f215d9a1603d4e21e855daff [file] [log] [blame]
Stephen Hines0e2c34f2015-03-23 12:09:02 -07001// RUN: %clang_cc1 -fborland-extensions -DBORLAND -fsyntax-only -verify %s
2// RUN: %clang_cc1 -fms-extensions -fsyntax-only -verify %s
John Wiegley28bbe4b2011-04-28 01:08:34 +00003
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)
8typedef int DWORD;
9
10#pragma sysheader begin
11
12struct EXCEPTION_INFO{};
13
Stephen Hines0e2c34f2015-03-23 12:09:02 -070014unsigned long __exception_code();
15#ifdef BORLAND
John Wiegley28bbe4b2011-04-28 01:08:34 +000016struct EXCEPTION_INFO* __exception_info();
Stephen Hines0e2c34f2015-03-23 12:09:02 -070017#endif
18int __abnormal_termination();
John Wiegley28bbe4b2011-04-28 01:08:34 +000019
20#define GetExceptionCode __exception_code
21#define GetExceptionInformation __exception_info
22#define AbnormalTermination __abnormal_termination
23
24#pragma sysheader end
25
Douglas Gregor1aaa2492011-10-21 03:57:52 +000026DWORD FilterExpression(int); // expected-note{{declared here}}
John Wiegley28bbe4b2011-04-28 01:08:34 +000027DWORD FilterExceptionInformation(struct EXCEPTION_INFO*);
28
29const char * NotFilterExpression();
30
31void TEST() {
32 __try {
33 __try {
34 __try {
35 }
36 __finally{
37 }
38 }
39 __finally{
40 }
41 }
42 __finally{
43 }
44}
45
46void TEST() {
47 __try {
48
49 }
50} // expected-error{{expected '__except' or '__finally' block}}
51
52void TEST() {
Douglas Gregor1aaa2492011-10-21 03:57:52 +000053 __except ( FilterExpression() ) { // expected-warning{{implicit declaration of function '__except' is invalid in C99}} \
54 // expected-error{{too few arguments to function call, expected 1, have 0}}
John Wiegley28bbe4b2011-04-28 01:08:34 +000055
56 }
57}
58
59void TEST() {
60 __finally { } // expected-error{{}}
61}
62
63void TEST() {
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}}
68 {}
69}
70
71void TEST() {
72 __try {
73
74 }
75 // TODO: Why are there two errors?
76 __except( ) { // expected-error{{expected expression}} expected-error{{expected expression}}
77 }
78}
79
80void TEST() {
81 __try {
82
83 }
84 __except ( FilterExpression(GetExceptionCode()) ) {
85
86 }
87
88 __try {
89
90 }
91 __except( FilterExpression(__exception_code()) ) {
92
93 }
94
95 __try {
96
97 }
98 __except( FilterExceptionInformation(__exception_info()) ) {
99
100 }
101
102 __try {
103
104 }
105 __except(FilterExceptionInformation( GetExceptionInformation() ) ) {
106
107 }
108}
109
110void TEST() {
111 __try {
112
113 }
114 __except ( NotFilterExpression() ) { // expected-error{{filter expression type should be an integral value not 'const char *'}}
115
116 }
117}
118
119void TEST() {
120 int function_scope = 0;
121 __try {
122 int try_scope = 0;
123 }
124 __except ( FilterExpression(GetExceptionCode()) ) {
125 (void)function_scope;
126 (void)try_scope; // expected-error{{undeclared identifier}}
127 }
128}
129
130void TEST() {
131 int function_scope = 0;
132 __try {
133 int try_scope = 0;
134 }
135 __finally {
136 (void)function_scope;
137 (void)try_scope; // expected-error{{undeclared identifier}}
138 }
139}
140
141void TEST() {
142 int function_scope = 0;
143 __try {
144
145 }
146 __except( function_scope ? 1 : -1 ) {}
147}
148
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700149#ifdef BORLAND
John Wiegley28bbe4b2011-04-28 01:08:34 +0000150void TEST() {
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700151 (void)__abnormal_termination(); // expected-error{{only allowed in __finally block}}
152 (void)AbnormalTermination(); // expected-error{{only allowed in __finally block}}
153
John Wiegley28bbe4b2011-04-28 01:08:34 +0000154 __try {
155 (void)AbnormalTermination; // expected-error{{only allowed in __finally block}}
156 (void)__abnormal_termination; // expected-error{{only allowed in __finally block}}
157 }
158 __except( 1 ) {
159 (void)AbnormalTermination; // expected-error{{only allowed in __finally block}}
160 (void)__abnormal_termination; // expected-error{{only allowed in __finally block}}
161 }
162
163 __try {
164 }
165 __finally {
166 AbnormalTermination();
167 __abnormal_termination();
168 }
169}
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700170#endif
John Wiegley28bbe4b2011-04-28 01:08:34 +0000171
172void TEST() {
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700173 (void)__exception_info(); // expected-error{{only allowed in __except filter expression}}
John Wiegley28bbe4b2011-04-28 01:08:34 +0000174 (void)GetExceptionInformation(); // expected-error{{only allowed in __except filter expression}}
Stephen Hines0e2c34f2015-03-23 12:09:02 -0700175}
176
177void TEST() {
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}}
183}
184
185void TEST() {
186 __try {
187 } __except(1) {
188 GetExceptionCode(); // valid
189 GetExceptionInformation(); // expected-error{{only allowed in __except filter expression}}
190 }
John Wiegley28bbe4b2011-04-28 01:08:34 +0000191}
Stephen Hinesc568f1e2014-07-21 00:47:37 -0700192
193void test_seh_leave_stmt() {
194 __leave; // expected-error{{'__leave' statement not in __try block}}
195
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}}
201 }
202
203 __try {
204 __leave;
205 } __finally {
206 __leave; // expected-error{{'__leave' statement not in __try block}}
207 }
208 __leave; // expected-error{{'__leave' statement not in __try block}}
209}