1 // Copyright (c) Microsoft. All rights reserved. 2 // Licensed under the MIT license. See LICENSE file in the project root for 3 // full license information. 4 5 // Write to volatiles in the catch to try and verify that we have 6 // a correct catch frame prolog and epilog. 7 8 #include <stdio.h> 9 #include <malloc.h> 10 11 __declspec(align(64)) struct X 12 { 13 X() : x(3) { } 14 ~X() { } 15 volatile int x; 16 }; 17 18 void t(char * c) 19 { 20 c[4] = 'a'; 21 throw 123; 22 } 23 24 bool f() 25 { 26 char * buf = (char *) _alloca(10); 27 X x; 28 volatile bool caught = false; 29 30 try 31 { 32 t(buf); 33 } 34 catch(int) 35 { 36 caught = true; 37 x.x = 2; 38 } 39 40 return caught; 41 } 42 43 int main() 44 { 45 bool result = false; 46 47 __try { 48 result = f(); 49 } 50 __except(1) 51 { 52 printf("ERROR - Unexpectedly caught an exception\n"); 53 } 54 55 printf(result ? "passed\n" : "failed\n"); 56 return result ? 0 : -1; 57 } 58