xref: /llvm-project/bolt/test/runtime/X86/Inputs/exception4.cpp (revision 0224bdce9263b74806b94426b33e97e030ab7a79)
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 
never_throws()19 void never_throws() throw () {
20   printf("this statement is cold and should be outlined\n");
21 }
22 
main(int argc,char ** argv)23 int main(int argc, char **argv)
24 {
25   for (unsigned i = 0; i < 1000; ++i) {
26     try {
27       if (argc == 2) {
28         never_throws(); // should be cold
29       }
30       try {
31         if (argc == 2) {
32           never_throws(); // should be cold
33         }
34         throw ExcA();
35       } catch (ExcA) {
36         printf("catch 2\n");
37         throw new int();
38       }
39     } catch (...) {
40       printf("catch 1\n");
41     }
42 
43     try {
44       try {
45         foo(argc);
46       } catch (ExcC) {
47         printf("caught ExcC\n");
48       }
49     } catch (ExcG) {
50       printf("caught ExcG\n");
51     }
52   }
53 
54   return 0;
55 }
56