| 1 |
/* PR tree-optimization/111009 */ |
| 2 |
/* { dg-do run } */ |
| 3 |
/* { dg-options "-O3 -fno-strict-overflow" } */ |
| 4 |
|
| 5 |
struct dso { |
| 6 |
struct dso * next; |
| 7 |
int maj; |
| 8 |
}; |
| 9 |
|
| 10 |
__attribute__((noipa)) static void __dso_id__cmp_(void) {} |
| 11 |
|
| 12 |
__attribute__((noipa)) |
| 13 |
static int bug(struct dso * d, struct dso *dso) |
| 14 |
{ |
| 15 |
struct dso **p = &d; |
| 16 |
struct dso *curr = 0; |
| 17 |
|
| 18 |
while (*p) { |
| 19 |
curr = *p; |
| 20 |
// prevent null deref below |
| 21 |
if (!dso) return 1; |
| 22 |
if (dso == curr) return 1; |
| 23 |
|
| 24 |
int *a = &dso->maj; |
| 25 |
// null deref |
| 26 |
if (!(a && *a)) __dso_id__cmp_(); |
| 27 |
|
| 28 |
p = &curr->next; |
| 29 |
} |
| 30 |
return 0; |
| 31 |
} |
| 32 |
|
| 33 |
__attribute__((noipa)) |
| 34 |
int main(void) { |
| 35 |
struct dso d = { 0, 0, }; |
| 36 |
bug(&d, 0); |
| 37 |
} |
| 38 |
|