| 1 |
/* PR middle-end/99502 - missing -Warray-bounds on partial out of bounds |
| 2 |
access in C++ |
| 3 |
{ dg-do compile } |
| 4 |
{ dg-options "-O2 -Wall" } */ |
| 5 |
|
| 6 |
typedef __INT8_TYPE__ int8_t; |
| 7 |
typedef __INT16_TYPE__ int16_t; |
| 8 |
typedef __INT32_TYPE__ int32_t; |
| 9 |
|
| 10 |
struct POD32 |
| 11 |
{ |
| 12 |
int32_t i32; |
| 13 |
}; |
| 14 |
|
| 15 |
int8_t a16[2]; |
| 16 |
int8_t apod32[sizeof (POD32)]; |
| 17 |
|
| 18 |
void nowarn_pod32_assign () |
| 19 |
{ |
| 20 |
POD32 *p = (POD32*)apod32; |
| 21 |
*p = POD32 (); |
| 22 |
} |
| 23 |
|
| 24 |
void nowarn_pod32_assign_member () |
| 25 |
{ |
| 26 |
POD32 *p = (POD32*)apod32; |
| 27 |
p->i32 = __LINE__; |
| 28 |
} |
| 29 |
|
| 30 |
|
| 31 |
void warn_pod32_assign () |
| 32 |
{ |
| 33 |
POD32 *p = (POD32*)a16; |
| 34 |
*p = POD32 (); // { dg-warning "-Warray-bounds" } |
| 35 |
} |
| 36 |
|
| 37 |
void warn_pod32_assign_member () |
| 38 |
{ |
| 39 |
POD32 *p = (POD32*)a16; |
| 40 |
p->i32 = __LINE__; // { dg-warning "-Warray-bounds" } |
| 41 |
} |
| 42 |
|
| 43 |
|
| 44 |
struct BV32 // { dg-warning "-Warray-bounds" "due to pr99525" } |
| 45 |
{ |
| 46 |
int32_t i32; |
| 47 |
|
| 48 |
virtual ~BV32 (); |
| 49 |
}; |
| 50 |
|
| 51 |
int8_t abv32[sizeof (BV32)]; |
| 52 |
|
| 53 |
void nowarn_bv32_assign () |
| 54 |
{ |
| 55 |
BV32 *p = (BV32*)abv32; |
| 56 |
*p = BV32 (); |
| 57 |
} |
| 58 |
|
| 59 |
void nowarn_bv32_assign_member () |
| 60 |
{ |
| 61 |
BV32 *p = (BV32*)abv32; |
| 62 |
p->i32 = __LINE__; |
| 63 |
} |
| 64 |
|
| 65 |
void warn_bv32_assign () |
| 66 |
{ |
| 67 |
BV32 *p = (BV32*)a16; |
| 68 |
*p = BV32 (); // { dg-warning "-Warray-bounds" "pr99525" { xfail *-*-* } } |
| 69 |
} |
| 70 |
|
| 71 |
void warn_bv32_assign_member () |
| 72 |
{ |
| 73 |
BV32 *p = (BV32*)a16; |
| 74 |
p->i32 = __LINE__; // { dg-warning "-Warray-bounds" } |
| 75 |
} |
| 76 |
|
| 77 |
|
| 78 |
struct DV32: virtual BV32 { }; |
| 79 |
|
| 80 |
int8_t adv32[sizeof (DV32)]; |
| 81 |
int8_t adv32_m1[sizeof adv32 - 1]; |
| 82 |
|
| 83 |
void nowarn_dv32_assign () |
| 84 |
{ |
| 85 |
DV32 *p = (DV32*)adv32; |
| 86 |
*p = DV32 (); |
| 87 |
} |
| 88 |
|
| 89 |
void nowarn_dv32_assign_member () |
| 90 |
{ |
| 91 |
DV32 *p = (DV32*)adv32; |
| 92 |
p->i32 = __LINE__; |
| 93 |
} |
| 94 |
|
| 95 |
void warn_dv32_assign () |
| 96 |
{ |
| 97 |
DV32 *p = (DV32*)adv32_m1; |
| 98 |
*p = DV32 (); // { dg-warning "-Warray-bounds" "pr?????" { xfail *-*-* } } |
| 99 |
} |
| 100 |
|
| 101 |
void warn_dv32_assign_member () |
| 102 |
{ |
| 103 |
DV32 *p = (DV32*)adv32_m1; |
| 104 |
p->i32 = __LINE__; // { dg-warning "-Warray-bounds" "pr?????" { xfail *-*-* } } |
| 105 |
} |