1 // Hammer the CFG with large numbers of overlapping variable scopes, which
2 // implicit destructors triggered at each edge.
3 
4 #define EXPAND_BASIC_STRUCT(i) struct X##i { X##i(int); ~X##i(); };
5 #define EXPAND_NORET_STRUCT(i) struct X##i { X##i(int); ~X##i() __attribute__((noreturn)); };
6 EXPAND_BASIC_STRUCT(0000); EXPAND_NORET_STRUCT(0001);
7 EXPAND_BASIC_STRUCT(0010); EXPAND_BASIC_STRUCT(0011);
8 EXPAND_BASIC_STRUCT(0100); EXPAND_NORET_STRUCT(0101);
9 EXPAND_NORET_STRUCT(0110); EXPAND_BASIC_STRUCT(0111);
10 EXPAND_BASIC_STRUCT(1000); EXPAND_NORET_STRUCT(1001);
11 EXPAND_BASIC_STRUCT(1010); EXPAND_BASIC_STRUCT(1011);
12 EXPAND_NORET_STRUCT(1100); EXPAND_NORET_STRUCT(1101);
13 EXPAND_BASIC_STRUCT(1110); EXPAND_BASIC_STRUCT(1111);
14 
15 #define EXPAND_2_VARS(c, i, x)  const X##i var_##c##_##i##0(x), &var_##c##_##i##1 = X##i(x)
16 #define EXPAND_4_VARS(c, i, x)  EXPAND_2_VARS(c, i##0, x);  EXPAND_2_VARS(c, i##1, x)
17 #define EXPAND_8_VARS(c, i, x)  EXPAND_4_VARS(c, i##0, x);  EXPAND_4_VARS(c, i##1, x)
18 #define EXPAND_16_VARS(c, i, x) EXPAND_8_VARS(c, i##0, x);  EXPAND_8_VARS(c, i##1, x)
19 #define EXPAND_32_VARS(c, x)    EXPAND_16_VARS(c, 0, x);    EXPAND_16_VARS(c, 1, x)
20 
21 #define EXPAND_2_INNER_CASES(i, x, y)    INNER_CASE(i, x, y);             INNER_CASE(i + 1, x, y);
22 #define EXPAND_4_INNER_CASES(i, x, y)    EXPAND_2_INNER_CASES(i, x, y)    EXPAND_2_INNER_CASES(i + 2, x, y)
23 #define EXPAND_8_INNER_CASES(i, x, y)    EXPAND_4_INNER_CASES(i, x, y)    EXPAND_4_INNER_CASES(i + 4, x, y)
24 #define EXPAND_16_INNER_CASES(i, x, y)   EXPAND_8_INNER_CASES(i, x, y)    EXPAND_8_INNER_CASES(i + 8, x, y)
25 #define EXPAND_32_INNER_CASES(i, x, y)   EXPAND_16_INNER_CASES(i, x, y)   EXPAND_16_INNER_CASES(i + 16, x, y)
26 
27 #define EXPAND_2_OUTER_CASES(i, x, y)    OUTER_CASE(i, x, y);             OUTER_CASE(i + 1, x, y);
28 #define EXPAND_4_OUTER_CASES(i, x, y)    EXPAND_2_OUTER_CASES(i, x, y)    EXPAND_2_OUTER_CASES(i + 2, x, y)
29 #define EXPAND_8_OUTER_CASES(i, x, y)    EXPAND_4_OUTER_CASES(i, x, y)    EXPAND_4_OUTER_CASES(i + 4, x, y)
30 #define EXPAND_16_OUTER_CASES(i, x, y)   EXPAND_8_OUTER_CASES(i, x, y)    EXPAND_8_OUTER_CASES(i + 8, x, y)
31 #define EXPAND_32_OUTER_CASES(i, x, y)   EXPAND_16_OUTER_CASES(i, x, y)   EXPAND_16_OUTER_CASES(i + 16, x, y)
32 
33 unsigned cfg_nested_vars(int x) {
34   int y = 0;
35   while (x > 0) {
36     EXPAND_32_VARS(a, x);
37     switch (x) {
38 #define INNER_CASE(i, x, y) \
39           case i: { \
40             int case_var = 3*x + i; \
41             EXPAND_32_VARS(c, case_var); \
42             y += case_var - 1; \
43             break; \
44           }
45 #define OUTER_CASE(i, x, y) \
46       case i: { \
47         int case_var = y >> 8; \
48         EXPAND_32_VARS(b, y); \
49         switch (case_var) { \
50           EXPAND_32_INNER_CASES(0, x, y); \
51         } \
52         break; \
53       }
54 EXPAND_32_OUTER_CASES(0, x, y);
55     }
56     --x;
57   }
58   return y;
59 }
60