| 1 |
/* Verify that -Wuninitialized warnings about accesses to objects via |
| 2 |
pointers and offsets mention valid expressions. |
| 3 |
{ dg-do compile } |
| 4 |
{ dg-options "-O2 -Wall" } */ |
| 5 |
|
| 6 |
typedef __INT16_TYPE__ int16_t; |
| 7 |
typedef __INT32_TYPE__ int32_t; |
| 8 |
|
| 9 |
void sink (int); |
| 10 |
|
| 11 |
/* Verify properly aligned accesses at offsets that are multiples of |
| 12 |
the access size. */ |
| 13 |
|
| 14 |
void test_aligned (void) |
| 15 |
{ |
| 16 |
char *p1 = (char*)__builtin_malloc (32); |
| 17 |
p1 += sizeof (int32_t); |
| 18 |
|
| 19 |
int16_t *p2 = (int16_t*)p1; |
| 20 |
sink (p2[1]); // { dg-warning "'\\(\\(int16_t\\*\\)p1\\)\\\[3]' is used uninitialized" } |
| 21 |
|
| 22 |
int32_t *p4 = (int32_t*)p1; |
| 23 |
sink (p4[1]); // { dg-warning "'\\(\\(int32_t\\*\\)p1\\)\\\[2]' is used uninitialized" } |
| 24 |
} |
| 25 |
|
| 26 |
|
| 27 |
/* Verify misaligned accesses at offsets that aren't multiples of |
| 28 |
the access size. */ |
| 29 |
|
| 30 |
void test_misaligned (void) |
| 31 |
{ |
| 32 |
char *p1 = (char*)__builtin_malloc (32); |
| 33 |
p1 += 1; |
| 34 |
|
| 35 |
int16_t *p2 = (int16_t*)p1; |
| 36 |
sink (p2[1]); // { dg-warning "'\\(\\(int16_t\\*\\)\\(p1 \\+ 1\\)\\)\\\[1]' is used uninitialized" } |
| 37 |
|
| 38 |
int32_t *p4 = (int32_t*)p1; |
| 39 |
sink (p4[1]); // { dg-warning "'\\(\\(int32_t\\*\\)\\(p1 \\+ 1\\)\\)\\\[1]' is used uninitialized" } |
| 40 |
} |