| 1 |
/* PR middle-end/63272 - GCC should warn when using pointer to dead scoped |
| 2 |
variable within the same function |
| 3 |
Exercise -Wdangling-pointer with inlining. |
| 4 |
{ dg-do compile } |
| 5 |
{ dg-options "-O1 -Wall" } */ |
| 6 |
|
| 7 |
void* sink (void*, ...); |
| 8 |
|
| 9 |
extern int *eip; // { dg-message "'eip' declared here" } |
| 10 |
|
| 11 |
static inline void store (int **p, int *q) |
| 12 |
{ |
| 13 |
*p = q; // { dg-warning "storing the address of local variable 'auto_x' in 'eip'" } |
| 14 |
} |
| 15 |
|
| 16 |
void nowarn_inlined_store_extern (void) |
| 17 |
{ |
| 18 |
extern int extern_x; |
| 19 |
store (&eip, &extern_x); |
| 20 |
} |
| 21 |
|
| 22 |
void nowarn_inlined_store_static (void) |
| 23 |
{ |
| 24 |
static int static_x; |
| 25 |
store (&eip, &static_x); |
| 26 |
} |
| 27 |
|
| 28 |
void warn_inlined_store_auto (void) |
| 29 |
{ |
| 30 |
int auto_x; // { dg-message "'auto_x' declared here" } |
| 31 |
store (&eip, &auto_x); |
| 32 |
} |