xref: /llvm-project/bolt/test/runtime/X86/Inputs/exception3.cpp (revision a80e1e493f33ef99684ffea58548f28cf2786b73)
1 #include <stdio.h>
2 
3 class ExcA {};
4 class ExcB {};
5 class ExcC {};
6 class ExcD {};
7 class ExcE {};
8 class ExcF {};
9 class ExcG {};
10 
foo(int a)11 void foo(int a)
12 {
13   if (a > 1)
14     throw ExcG();
15   else
16     throw ExcC();
17 }
18 
main(int argc,char ** argv)19 int main(int argc, char **argv)
20 {
21   asm volatile ("nop;nop;nop;nop;nop");
22   try {
23     try {
24       asm volatile ("nop;nop;nop;nop;nop");
25       throw ExcA();
26     } catch (ExcA) {
27       asm volatile ("nop;nop;nop;nop;nop");
28       printf("catch 2\n");
29       throw new int();
30     }
31   } catch (...) {
32     asm volatile ("nop;nop;nop;nop;nop");
33     printf("catch 1\n");
34   }
35 
36   try {
37     asm volatile ("nop;nop;nop;nop;nop");
38     try {
39       asm volatile ("nop;nop;nop;nop;nop");
40       foo(argc);
41     } catch (ExcC) {
42       asm volatile ("nop;nop;nop;nop;nop");
43       printf("caught ExcC\n");
44     }
45   } catch (ExcG) {
46     asm volatile ("nop;nop;nop;nop;nop");
47     printf("caught ExcG\n");
48   }
49 
50   return 0;
51 }
52