Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame^] | 1 | // RUN: %clang_cc1 -fborland-extensions -DBORLAND -fsyntax-only -verify %s |
| 2 | // RUN: %clang_cc1 -fms-extensions -fsyntax-only -verify %s |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 3 | |
| 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; |
| 9 | |
| 10 | #pragma sysheader begin |
| 11 | |
| 12 | struct EXCEPTION_INFO{}; |
| 13 | |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame^] | 14 | unsigned long __exception_code(); |
| 15 | #ifdef BORLAND |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 16 | struct EXCEPTION_INFO* __exception_info(); |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame^] | 17 | #endif |
| 18 | int __abnormal_termination(); |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 19 | |
| 20 | #define GetExceptionCode __exception_code |
| 21 | #define GetExceptionInformation __exception_info |
| 22 | #define AbnormalTermination __abnormal_termination |
| 23 | |
| 24 | #pragma sysheader end |
| 25 | |
Douglas Gregor | 1aaa249 | 2011-10-21 03:57:52 +0000 | [diff] [blame] | 26 | DWORD FilterExpression(int); // expected-note{{declared here}} |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 27 | DWORD FilterExceptionInformation(struct EXCEPTION_INFO*); |
| 28 | |
| 29 | const char * NotFilterExpression(); |
| 30 | |
| 31 | void TEST() { |
| 32 | __try { |
| 33 | __try { |
| 34 | __try { |
| 35 | } |
| 36 | __finally{ |
| 37 | } |
| 38 | } |
| 39 | __finally{ |
| 40 | } |
| 41 | } |
| 42 | __finally{ |
| 43 | } |
| 44 | } |
| 45 | |
| 46 | void TEST() { |
| 47 | __try { |
| 48 | |
| 49 | } |
| 50 | } // expected-error{{expected '__except' or '__finally' block}} |
| 51 | |
| 52 | void TEST() { |
Douglas Gregor | 1aaa249 | 2011-10-21 03:57:52 +0000 | [diff] [blame] | 53 | __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 Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 55 | |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | void TEST() { |
| 60 | __finally { } // expected-error{{}} |
| 61 | } |
| 62 | |
| 63 | void 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 | |
| 71 | void 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 | |
| 80 | void 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 | |
| 110 | void 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 | |
| 119 | void 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 | |
| 130 | void 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 | |
| 141 | void TEST() { |
| 142 | int function_scope = 0; |
| 143 | __try { |
| 144 | |
| 145 | } |
| 146 | __except( function_scope ? 1 : -1 ) {} |
| 147 | } |
| 148 | |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame^] | 149 | #ifdef BORLAND |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 150 | void TEST() { |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame^] | 151 | (void)__abnormal_termination(); // expected-error{{only allowed in __finally block}} |
| 152 | (void)AbnormalTermination(); // expected-error{{only allowed in __finally block}} |
| 153 | |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 154 | __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 Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame^] | 170 | #endif |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 171 | |
| 172 | void TEST() { |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame^] | 173 | (void)__exception_info(); // expected-error{{only allowed in __except filter expression}} |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 174 | (void)GetExceptionInformation(); // expected-error{{only allowed in __except filter expression}} |
Stephen Hines | 0e2c34f | 2015-03-23 12:09:02 -0700 | [diff] [blame^] | 175 | } |
| 176 | |
| 177 | void 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 | |
| 185 | void TEST() { |
| 186 | __try { |
| 187 | } __except(1) { |
| 188 | GetExceptionCode(); // valid |
| 189 | GetExceptionInformation(); // expected-error{{only allowed in __except filter expression}} |
| 190 | } |
John Wiegley | 28bbe4b | 2011-04-28 01:08:34 +0000 | [diff] [blame] | 191 | } |
Stephen Hines | c568f1e | 2014-07-21 00:47:37 -0700 | [diff] [blame] | 192 | |
| 193 | void 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 | } |