xref: /llvm-project/bolt/test/runtime/Inputs/exceptions_split.cpp (revision 777e268b8168b326db54ecacb62733ee926bb781)
1 // Test that we can have a statement that throws in hot cold
2 // and a landing pad in cold code.
3 //
4 // Record performance data with no args. Run test with 2 args.
5 
6 #include <stdint.h>
7 #include <stdio.h>
8 
foo()9 int foo() { return 0; }
10 
bar(int a)11 void bar(int a) {
12   if (a > 2 && a % 2)
13     throw new int();
14 }
15 
filter_only()16 void filter_only() { foo(); }
17 
main(int argc,char ** argv)18 int main(int argc, char **argv) {
19   unsigned r = 0;
20 
21   uint64_t limit = (argc >= 2 ? 10 : 5000);
22   for (uint64_t i = 0; i < limit; ++i) {
23     i += foo();
24     try {
25       bar(argc);
26       try {
27         if (argc >= 2)
28           throw new int();
29       } catch (...) {
30         printf("catch 2\n");
31         throw new int();
32       }
33     } catch (...) {
34       printf("catch 1\n");
35     }
36   }
37 
38   return 0;
39 }
40