1f4a2713aSLionel Sambuc // RUN: %clang_cc1 -fborland-extensions -fsyntax-only -verify %s 2f4a2713aSLionel Sambuc 3f4a2713aSLionel Sambuc #define JOIN2(x,y) x ## y 4f4a2713aSLionel Sambuc #define JOIN(x,y) JOIN2(x,y) 5f4a2713aSLionel Sambuc #define TEST2(name) JOIN(name,__LINE__) 6f4a2713aSLionel Sambuc #define TEST TEST2(test) 7f4a2713aSLionel Sambuc typedef int DWORD; 8f4a2713aSLionel Sambuc 9f4a2713aSLionel Sambuc #pragma sysheader begin 10f4a2713aSLionel Sambuc 11f4a2713aSLionel Sambuc struct EXCEPTION_INFO{}; 12f4a2713aSLionel Sambuc 13f4a2713aSLionel Sambuc int __exception_code(); 14f4a2713aSLionel Sambuc struct EXCEPTION_INFO* __exception_info(); 15f4a2713aSLionel Sambuc void __abnormal_termination(); 16f4a2713aSLionel Sambuc 17f4a2713aSLionel Sambuc #define GetExceptionCode __exception_code 18f4a2713aSLionel Sambuc #define GetExceptionInformation __exception_info 19f4a2713aSLionel Sambuc #define AbnormalTermination __abnormal_termination 20f4a2713aSLionel Sambuc 21f4a2713aSLionel Sambuc #pragma sysheader end 22f4a2713aSLionel Sambuc 23f4a2713aSLionel Sambuc DWORD FilterExpression(int); // expected-note{{declared here}} 24f4a2713aSLionel Sambuc DWORD FilterExceptionInformation(struct EXCEPTION_INFO*); 25f4a2713aSLionel Sambuc 26f4a2713aSLionel Sambuc const char * NotFilterExpression(); 27f4a2713aSLionel Sambuc TEST()28f4a2713aSLionel Sambucvoid TEST() { 29f4a2713aSLionel Sambuc __try { 30f4a2713aSLionel Sambuc __try { 31f4a2713aSLionel Sambuc __try { 32f4a2713aSLionel Sambuc } 33f4a2713aSLionel Sambuc __finally{ 34f4a2713aSLionel Sambuc } 35f4a2713aSLionel Sambuc } 36f4a2713aSLionel Sambuc __finally{ 37f4a2713aSLionel Sambuc } 38f4a2713aSLionel Sambuc } 39f4a2713aSLionel Sambuc __finally{ 40f4a2713aSLionel Sambuc } 41f4a2713aSLionel Sambuc } 42f4a2713aSLionel Sambuc TEST()43f4a2713aSLionel Sambucvoid TEST() { 44f4a2713aSLionel Sambuc __try { 45f4a2713aSLionel Sambuc 46f4a2713aSLionel Sambuc } 47f4a2713aSLionel Sambuc } // expected-error{{expected '__except' or '__finally' block}} 48f4a2713aSLionel Sambuc TEST()49f4a2713aSLionel Sambucvoid TEST() { 50f4a2713aSLionel Sambuc __except ( FilterExpression() ) { // expected-warning{{implicit declaration of function '__except' is invalid in C99}} \ 51f4a2713aSLionel Sambuc // expected-error{{too few arguments to function call, expected 1, have 0}} 52f4a2713aSLionel Sambuc 53f4a2713aSLionel Sambuc } 54f4a2713aSLionel Sambuc } 55f4a2713aSLionel Sambuc TEST()56f4a2713aSLionel Sambucvoid TEST() { 57f4a2713aSLionel Sambuc __finally { } // expected-error{{}} 58f4a2713aSLionel Sambuc } 59f4a2713aSLionel Sambuc TEST()60f4a2713aSLionel Sambucvoid TEST() { 61f4a2713aSLionel Sambuc __try{ 62f4a2713aSLionel Sambuc int try_scope = 0; 63f4a2713aSLionel Sambuc } // TODO: expected expression is an extra error 64f4a2713aSLionel Sambuc __except( try_scope ? 1 : -1 ) // expected-error{{undeclared identifier 'try_scope'}} expected-error{{expected expression}} 65f4a2713aSLionel Sambuc {} 66f4a2713aSLionel Sambuc } 67f4a2713aSLionel Sambuc TEST()68f4a2713aSLionel Sambucvoid TEST() { 69f4a2713aSLionel Sambuc __try { 70f4a2713aSLionel Sambuc 71f4a2713aSLionel Sambuc } 72f4a2713aSLionel Sambuc // TODO: Why are there two errors? 73f4a2713aSLionel Sambuc __except( ) { // expected-error{{expected expression}} expected-error{{expected expression}} 74f4a2713aSLionel Sambuc } 75f4a2713aSLionel Sambuc } 76f4a2713aSLionel Sambuc TEST()77f4a2713aSLionel Sambucvoid TEST() { 78f4a2713aSLionel Sambuc __try { 79f4a2713aSLionel Sambuc 80f4a2713aSLionel Sambuc } 81f4a2713aSLionel Sambuc __except ( FilterExpression(GetExceptionCode()) ) { 82f4a2713aSLionel Sambuc 83f4a2713aSLionel Sambuc } 84f4a2713aSLionel Sambuc 85f4a2713aSLionel Sambuc __try { 86f4a2713aSLionel Sambuc 87f4a2713aSLionel Sambuc } 88f4a2713aSLionel Sambuc __except( FilterExpression(__exception_code()) ) { 89f4a2713aSLionel Sambuc 90f4a2713aSLionel Sambuc } 91f4a2713aSLionel Sambuc 92f4a2713aSLionel Sambuc __try { 93f4a2713aSLionel Sambuc 94f4a2713aSLionel Sambuc } 95f4a2713aSLionel Sambuc __except( FilterExceptionInformation(__exception_info()) ) { 96f4a2713aSLionel Sambuc 97f4a2713aSLionel Sambuc } 98f4a2713aSLionel Sambuc 99f4a2713aSLionel Sambuc __try { 100f4a2713aSLionel Sambuc 101f4a2713aSLionel Sambuc } 102f4a2713aSLionel Sambuc __except(FilterExceptionInformation( GetExceptionInformation() ) ) { 103f4a2713aSLionel Sambuc 104f4a2713aSLionel Sambuc } 105f4a2713aSLionel Sambuc } 106f4a2713aSLionel Sambuc TEST()107f4a2713aSLionel Sambucvoid TEST() { 108f4a2713aSLionel Sambuc __try { 109f4a2713aSLionel Sambuc 110f4a2713aSLionel Sambuc } 111f4a2713aSLionel Sambuc __except ( NotFilterExpression() ) { // expected-error{{filter expression type should be an integral value not 'const char *'}} 112f4a2713aSLionel Sambuc 113f4a2713aSLionel Sambuc } 114f4a2713aSLionel Sambuc } 115f4a2713aSLionel Sambuc TEST()116f4a2713aSLionel Sambucvoid TEST() { 117f4a2713aSLionel Sambuc int function_scope = 0; 118f4a2713aSLionel Sambuc __try { 119f4a2713aSLionel Sambuc int try_scope = 0; 120f4a2713aSLionel Sambuc } 121f4a2713aSLionel Sambuc __except ( FilterExpression(GetExceptionCode()) ) { 122f4a2713aSLionel Sambuc (void)function_scope; 123f4a2713aSLionel Sambuc (void)try_scope; // expected-error{{undeclared identifier}} 124f4a2713aSLionel Sambuc } 125f4a2713aSLionel Sambuc } 126f4a2713aSLionel Sambuc TEST()127f4a2713aSLionel Sambucvoid TEST() { 128f4a2713aSLionel Sambuc int function_scope = 0; 129f4a2713aSLionel Sambuc __try { 130f4a2713aSLionel Sambuc int try_scope = 0; 131f4a2713aSLionel Sambuc } 132f4a2713aSLionel Sambuc __finally { 133f4a2713aSLionel Sambuc (void)function_scope; 134f4a2713aSLionel Sambuc (void)try_scope; // expected-error{{undeclared identifier}} 135f4a2713aSLionel Sambuc } 136f4a2713aSLionel Sambuc } 137f4a2713aSLionel Sambuc TEST()138f4a2713aSLionel Sambucvoid TEST() { 139f4a2713aSLionel Sambuc int function_scope = 0; 140f4a2713aSLionel Sambuc __try { 141f4a2713aSLionel Sambuc 142f4a2713aSLionel Sambuc } 143f4a2713aSLionel Sambuc __except( function_scope ? 1 : -1 ) {} 144f4a2713aSLionel Sambuc } 145f4a2713aSLionel Sambuc TEST()146f4a2713aSLionel Sambucvoid TEST() { 147f4a2713aSLionel Sambuc __try { 148f4a2713aSLionel Sambuc (void)AbnormalTermination; // expected-error{{only allowed in __finally block}} 149f4a2713aSLionel Sambuc (void)__abnormal_termination; // expected-error{{only allowed in __finally block}} 150f4a2713aSLionel Sambuc } 151f4a2713aSLionel Sambuc __except( 1 ) { 152f4a2713aSLionel Sambuc (void)AbnormalTermination; // expected-error{{only allowed in __finally block}} 153f4a2713aSLionel Sambuc (void)__abnormal_termination; // expected-error{{only allowed in __finally block}} 154f4a2713aSLionel Sambuc } 155f4a2713aSLionel Sambuc 156f4a2713aSLionel Sambuc __try { 157f4a2713aSLionel Sambuc } 158f4a2713aSLionel Sambuc __finally { 159f4a2713aSLionel Sambuc AbnormalTermination(); 160f4a2713aSLionel Sambuc __abnormal_termination(); 161f4a2713aSLionel Sambuc } 162f4a2713aSLionel Sambuc } 163f4a2713aSLionel Sambuc TEST()164f4a2713aSLionel Sambucvoid TEST() { 165f4a2713aSLionel Sambuc (void)__exception_code; // expected-error{{only allowed in __except block}} 166f4a2713aSLionel Sambuc (void)__exception_info; // expected-error{{only allowed in __except filter expression}} 167f4a2713aSLionel Sambuc (void)__abnormal_termination; // expected-error{{only allowed in __finally block}} 168f4a2713aSLionel Sambuc 169f4a2713aSLionel Sambuc (void)GetExceptionCode(); // expected-error{{only allowed in __except block}} 170f4a2713aSLionel Sambuc (void)GetExceptionInformation(); // expected-error{{only allowed in __except filter expression}} 171f4a2713aSLionel Sambuc (void)AbnormalTermination(); // expected-error{{only allowed in __finally block}} 172f4a2713aSLionel Sambuc } 173*0a6a1f1dSLionel Sambuc test_seh_leave_stmt()174*0a6a1f1dSLionel Sambucvoid test_seh_leave_stmt() { 175*0a6a1f1dSLionel Sambuc __leave; // expected-error{{'__leave' statement not in __try block}} 176*0a6a1f1dSLionel Sambuc 177*0a6a1f1dSLionel Sambuc __try { 178*0a6a1f1dSLionel Sambuc __leave; 179*0a6a1f1dSLionel Sambuc __leave 4; // expected-error{{expected ';' after __leave statement}} 180*0a6a1f1dSLionel Sambuc } __except(1) { 181*0a6a1f1dSLionel Sambuc __leave; // expected-error{{'__leave' statement not in __try block}} 182*0a6a1f1dSLionel Sambuc } 183*0a6a1f1dSLionel Sambuc 184*0a6a1f1dSLionel Sambuc __try { 185*0a6a1f1dSLionel Sambuc __leave; 186*0a6a1f1dSLionel Sambuc } __finally { 187*0a6a1f1dSLionel Sambuc __leave; // expected-error{{'__leave' statement not in __try block}} 188*0a6a1f1dSLionel Sambuc } 189*0a6a1f1dSLionel Sambuc __leave; // expected-error{{'__leave' statement not in __try block}} 190*0a6a1f1dSLionel Sambuc } 191*0a6a1f1dSLionel Sambuc 192