| 1 |
/* { dg-skip-if "requires hosted libstdc++ for stdlib malloc" { ! hostedlib } } */ |
| 2 |
|
| 3 |
#include <stdlib.h> |
| 4 |
|
| 5 |
extern void foo (void); |
| 6 |
extern void bar (void); |
| 7 |
|
| 8 |
void test_1 (int flag, int n); |
| 9 |
|
| 10 |
void caller_1_of_test_1 (int n) |
| 11 |
{ |
| 12 |
test_1 (1, n); /* { dg-bogus "test_1" } */ |
| 13 |
test_1 (0, n); /* { dg-bogus "test_1" } */ |
| 14 |
} |
| 15 |
|
| 16 |
void __attribute__((noinline)) |
| 17 |
test_1 (int flag, int n) |
| 18 |
{ |
| 19 |
int *ptr = (int *)malloc (sizeof (int)); |
| 20 |
|
| 21 |
if (flag) |
| 22 |
{ |
| 23 |
int i; |
| 24 |
for (i = 0; i < n; i++) |
| 25 |
foo (); |
| 26 |
} |
| 27 |
else |
| 28 |
bar (); |
| 29 |
|
| 30 |
free (ptr); |
| 31 |
free (ptr); /* { dg-warning "double-'free'" } */ |
| 32 |
/* FIXME: we get duplicates intraprocedurally, as there are two paths |
| 33 |
through the function. |
| 34 |
The calls in test_2 also generate additional duplicates. |
| 35 |
How to verify lack of duplicates? |
| 36 |
Putting a bogus on the interprocedual one detects that, at least. */ |
| 37 |
|
| 38 |
if (flag) |
| 39 |
foo (); |
| 40 |
else |
| 41 |
bar (); |
| 42 |
} |
| 43 |
|
| 44 |
void caller_2_of_test_1 (int n) |
| 45 |
{ |
| 46 |
test_1 (1, n); /* { dg-bogus "test_1" } */ |
| 47 |
test_1 (0, n); /* { dg-bogus "test_1" } */ |
| 48 |
} |