| 1 |
/* { dg-skip-if "" { *-*-* } { "-fno-fat-lto-objects" } { "" } } */ |
| 2 |
/* { dg-additional-options "-fsanitize=bounds" } */ |
| 3 |
|
| 4 |
#include <stdlib.h> |
| 5 |
#include "../analyzer-decls.h" |
| 6 |
|
| 7 |
int test_1 (int *arr, int i, int n) |
| 8 |
{ |
| 9 |
if (i >= n) |
| 10 |
return 0; |
| 11 |
return arr[i]; |
| 12 |
} |
| 13 |
|
| 14 |
int test_2 (int *arr, int i, int n) |
| 15 |
{ |
| 16 |
if (i >= n) |
| 17 |
return 0; |
| 18 |
if (arr[i]) |
| 19 |
__analyzer_eval (arr[i]); /* { dg-warning "TRUE" } */ |
| 20 |
else |
| 21 |
__analyzer_eval (arr[i]); /* { dg-warning "FALSE" } */ |
| 22 |
return 1; |
| 23 |
} |
| 24 |
|
| 25 |
int test_3 (int arr[], int i, int n) |
| 26 |
{ |
| 27 |
if (i >= n) |
| 28 |
return 0; |
| 29 |
if (arr[i]) |
| 30 |
__analyzer_eval (arr[i]); /* { dg-warning "TRUE" } */ |
| 31 |
else |
| 32 |
__analyzer_eval (arr[i]); /* { dg-warning "FALSE" } */ |
| 33 |
return 1; |
| 34 |
} |
| 35 |
|
| 36 |
void test_4 (int i, int n) |
| 37 |
{ |
| 38 |
int arr[n]; |
| 39 |
arr[i] = 42; |
| 40 |
__analyzer_eval (arr[i] == 42); /* { dg-warning "TRUE" } */ |
| 41 |
} |
| 42 |
|
| 43 |
void test_5 (int i, int n) |
| 44 |
{ |
| 45 |
int *arr = malloc (sizeof(int) * n); |
| 46 |
if (arr) |
| 47 |
{ |
| 48 |
arr[i] = 42; |
| 49 |
__analyzer_eval (arr[i] == 42); /* { dg-warning "TRUE" } */ |
| 50 |
} |
| 51 |
free (arr); |
| 52 |
} |
| 53 |
|
| 54 |
int global; |
| 55 |
|
| 56 |
void test_6 (int i, int n) |
| 57 |
{ |
| 58 |
int arr[n]; |
| 59 |
int saved = global; |
| 60 |
arr[i] = 42; |
| 61 |
__analyzer_eval (saved == global); /* { dg-warning "TRUE" } */ |
| 62 |
} |