| 1 |
/* { dg-do run } */ |
| 2 |
/* { dg-options "" } */ |
| 3 |
/* Verify cleanup execution on non-trivial exit from a block. */ |
| 4 |
|
| 5 |
extern void exit(int); |
| 6 |
extern void abort(void); |
| 7 |
|
| 8 |
static int counter; |
| 9 |
|
| 10 |
static void |
| 11 |
handler(int *p) |
| 12 |
{ |
| 13 |
counter += *p; |
| 14 |
} |
| 15 |
|
| 16 |
static void __attribute__((noinline)) |
| 17 |
bar(void) |
| 18 |
{ |
| 19 |
} |
| 20 |
|
| 21 |
static void doit(int n, int n2) |
| 22 |
{ |
| 23 |
int i; |
| 24 |
for (i = 0; i < n; ++i) |
| 25 |
{ |
| 26 |
int dummy __attribute__((cleanup (handler))) = i; |
| 27 |
if (i == n2) |
| 28 |
break; |
| 29 |
bar(); |
| 30 |
} |
| 31 |
} |
| 32 |
|
| 33 |
int main() |
| 34 |
{ |
| 35 |
doit (10, 6); |
| 36 |
if (counter != 0 + 1 + 2 + 3 + 4 + 5 + 6) |
| 37 |
abort (); |
| 38 |
return 0; |
| 39 |
} |