| 1 |
/* { dg-do compile } */ |
| 2 |
/* { dg-options "-fanalyzer" } */ |
| 3 |
/* { dg-require-effective-target analyzer } */ |
| 4 |
|
| 5 |
#include "../analyzer/analyzer-decls.h" |
| 6 |
|
| 7 |
/* Basic example of known fn behavior. */ |
| 8 |
|
| 9 |
extern int returns_42 (void); |
| 10 |
|
| 11 |
void test_1 (void) |
| 12 |
{ |
| 13 |
int val = returns_42 (); |
| 14 |
__analyzer_eval (val == 42); /* { dg-warning "TRUE" } */ |
| 15 |
} |
| 16 |
|
| 17 |
/* Example of bifurcation, with a copy that can fail. */ |
| 18 |
|
| 19 |
extern int |
| 20 |
attempt_to_copy (void *to, const void *from, int sz); |
| 21 |
|
| 22 |
void test_copy_success (void *to, const void *from, int sz) |
| 23 |
{ |
| 24 |
if (!attempt_to_copy (to, from, sz)) |
| 25 |
{ |
| 26 |
/* Success */ |
| 27 |
} |
| 28 |
} |
| 29 |
|
| 30 |
void test_copy_failure (void *to, const void *from, int sz) |
| 31 |
{ |
| 32 |
if (attempt_to_copy (to, from, sz)) /* { dg-message "when 'attempt_to_copy' fails" } */ |
| 33 |
__analyzer_dump_path (); /* { dg-message "path" } */ |
| 34 |
} |
| 35 |
|
| 36 |
struct coord |
| 37 |
{ |
| 38 |
int x; |
| 39 |
int y; |
| 40 |
int z; |
| 41 |
}; |
| 42 |
|
| 43 |
void test_copy_2 (void) |
| 44 |
{ |
| 45 |
struct coord to = {1, 2, 3}; |
| 46 |
struct coord from = {4, 5, 6}; |
| 47 |
if (attempt_to_copy (&to, &from, sizeof (struct coord))) |
| 48 |
{ |
| 49 |
/* Failure. */ |
| 50 |
__analyzer_eval (to.x == 1); /* { dg-warning "TRUE" } */ |
| 51 |
__analyzer_eval (to.y == 2); /* { dg-warning "TRUE" } */ |
| 52 |
__analyzer_eval (to.z == 3); /* { dg-warning "TRUE" } */ |
| 53 |
} |
| 54 |
else |
| 55 |
{ |
| 56 |
/* Success. */ |
| 57 |
__analyzer_eval (to.x == 4); /* { dg-warning "TRUE" } */ |
| 58 |
__analyzer_eval (to.y == 5); /* { dg-warning "TRUE" } */ |
| 59 |
__analyzer_eval (to.z == 6); /* { dg-warning "TRUE" } */ |
| 60 |
} |
| 61 |
} |