| 1 |
/* { dg-do run { target c++11 } } */ |
| 2 |
/* { dg-options "-O1 -fipa-cp -fipa-cp-clone" } */ |
| 3 |
|
| 4 |
struct R {} RGood; |
| 5 |
struct L {} LBad; |
| 6 |
|
| 7 |
volatile int vi; |
| 8 |
static void __attribute__((noipa)) L_run(void) { vi = 0; __builtin_abort (); } |
| 9 |
static void callback_fn_L(void) { vi = 1; L_run(); } |
| 10 |
static void callback_fn_R(void) { vi = 2; } |
| 11 |
|
| 12 |
struct function_ref { |
| 13 |
void (*callback)(void) = nullptr; |
| 14 |
|
| 15 |
function_ref(L * pl) { callback = callback_fn_L; } |
| 16 |
function_ref(R * pr) { callback = callback_fn_R; } |
| 17 |
}; |
| 18 |
|
| 19 |
// allow one level of recursion to call callback twice |
| 20 |
static int is_recur(void) { |
| 21 |
static int n = 0; |
| 22 |
switch (n++) { |
| 23 |
case 0: return 1; |
| 24 |
default: return 0; |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
static void do3(volatile int * punused, function_ref Expired) { |
| 29 |
Expired.callback(); |
| 30 |
|
| 31 |
if (is_recur()) |
| 32 |
do3(punused, Expired); |
| 33 |
} |
| 34 |
|
| 35 |
static void do1(function_ref Expired) { |
| 36 |
volatile int unused = 42; |
| 37 |
|
| 38 |
do3(&unused, Expired); |
| 39 |
} |
| 40 |
|
| 41 |
int main(int, const char **) { do1(&RGood); return 0; } |
| 42 |
|
| 43 |
void seemingly_unused_foo(void) { do1(&LBad); } |
| 44 |
|
| 45 |
void (*fnptr)(void) = seemingly_unused_foo; |