| 1 |
/* { dg-skip-if "requires hosted libstdc++ for stdlib malloc" { ! hostedlib } } */ |
| 2 |
|
| 3 |
/* Verify that we emit sane paths for state machine errors. */ |
| 4 |
|
| 5 |
#include <stdlib.h> |
| 6 |
|
| 7 |
int *test_4 (void) |
| 8 |
{ |
| 9 |
int *ptr = (int *)malloc (sizeof (int)); /* { dg-line malloc } */ |
| 10 |
if (ptr) /* { dg-line cond } */ |
| 11 |
*ptr = 42; |
| 12 |
else |
| 13 |
*ptr = 43; /* { dg-line on_null_ptr } */ |
| 14 |
return ptr; |
| 15 |
|
| 16 |
/* { dg-warning "dereference of NULL 'ptr'" "warning" { target *-*-* } on_null_ptr } */ |
| 17 |
/* { dg-message "\\(1\\) allocated here" "event 1" { target *-*-* } malloc } */ |
| 18 |
/* { dg-message "\\(2\\) assuming 'ptr' is NULL" "event 2" { target *-*-* } cond } */ |
| 19 |
/* { dg-message "\\(3\\) following 'false' branch \\(when 'ptr' is NULL\\)\\.\\.\\." "event 3" { target *-*-* } cond } */ |
| 20 |
/* { dg-message "\\(4\\) \\.\\.\\.to here" "event 4" { target *-*-* } on_null_ptr } */ |
| 21 |
/* { dg-message "\\(5\\) dereference of NULL 'ptr'" "event 5" { target *-*-* } on_null_ptr } */ |
| 22 |
} |