| 1 |
/* PR tree-optimization/97027 - missing warning on buffer overflow storing |
| 2 |
a larger scalar into a smaller array |
| 3 |
Verify overflow by aggregate stores. |
| 4 |
{ dg-do compile } |
| 5 |
{ dg-options "-O2 -fno-tree-vectorize" } */ |
| 6 |
|
| 7 |
#define A(N) (A ## N) |
| 8 |
#define Ac1 (AC1){ 0 } |
| 9 |
#define Ac2 (AC2){ 0, 1 } |
| 10 |
#define Ac4 (AC4){ 0, 1, 2, 3 } |
| 11 |
#define Ac8 (AC8){ 0, 1, 2, 3, 4, 5, 6, 7 } |
| 12 |
#define Ac16 (AC16){ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 } |
| 13 |
|
| 14 |
typedef struct AC1 { char a[1]; } AC1; |
| 15 |
typedef struct AC2 { char a[2]; } AC2; |
| 16 |
typedef struct AC3 { char a[3]; } AC3; |
| 17 |
typedef struct AC4 { char a[4]; } AC4; |
| 18 |
typedef struct AC5 { char a[5]; } AC5; |
| 19 |
typedef struct AC8 { char a[8]; } AC8; |
| 20 |
typedef struct AC16 { char a[16]; } AC16; |
| 21 |
|
| 22 |
extern char a1[1], a2[2], a3[3], a4[4], a5[5], a6[6], a7[7], a8[8], a15[15]; |
| 23 |
|
| 24 |
extern AC1 ac1; |
| 25 |
extern AC2 ac2; |
| 26 |
extern AC4 ac4; |
| 27 |
extern AC8 ac8; |
| 28 |
extern AC16 ac16; |
| 29 |
|
| 30 |
extern AC1 fac1 (void); |
| 31 |
extern AC2 fac2 (void); |
| 32 |
extern AC4 fac4 (void); |
| 33 |
extern AC8 fac8 (void); |
| 34 |
extern AC16 fac16 (void); |
| 35 |
|
| 36 |
void nowarn (void) |
| 37 |
{ |
| 38 |
*(AC1*)a1 = Ac1; |
| 39 |
*(AC2*)a2 = Ac2; |
| 40 |
*(AC4*)a4 = Ac4; |
| 41 |
*(AC4*)a5 = Ac4; |
| 42 |
*(AC4*)a6 = Ac4; |
| 43 |
*(AC4*)a7 = Ac4; |
| 44 |
*(AC8*)a8 = Ac8; |
| 45 |
*(AC8*)a15 = Ac8; |
| 46 |
} |
| 47 |
|
| 48 |
void warn_comp_lit_zero (void) |
| 49 |
{ |
| 50 |
*(AC2*)a1 = (AC2){ }; // { dg-warning "writing 2 bytes into a region of size 1" } |
| 51 |
*(AC4*)a2 = (AC4){ }; // { dg-warning "writing 4 bytes into a region of size 2" } |
| 52 |
*(AC4*)a3 = (AC4){ }; // { dg-warning "writing 4 bytes into a region of size 3" } |
| 53 |
*(AC8*)a4 = (AC8){ }; // { dg-warning "writing 8 bytes into a region of size 4" } |
| 54 |
*(AC8*)a7 = (AC8){ }; // { dg-warning "writing 8 bytes into a region of size 7" } |
| 55 |
*(AC16*)a15 = (AC16){ };// { dg-warning "writing 16 bytes into a region of size 15" } |
| 56 |
} |
| 57 |
|
| 58 |
void warn_comp_lit (void) |
| 59 |
{ |
| 60 |
/* Ideally only one warning would be issued for each of the stores |
| 61 |
mentioning the size of the rest of the source being assigned to |
| 62 |
the destination that doesn't fit. But without vectorization |
| 63 |
the assignment is a series of one-character stores, except in |
| 64 |
the first instance multiple warnings end up being issued for |
| 65 |
each assignment, each saying "writing 1 byte into a region of |
| 66 |
size 0". That's suboptimal and should be improved. See also |
| 67 |
PR 92110. */ |
| 68 |
*(AC2*)a1 = Ac2; // { dg-warning "writing (2 bytes|1 byte) into a region of size (1|0)" "pr101475" } |
| 69 |
*(AC4*)a2 = Ac4; // { dg-warning "writing (4 bytes|1 byte) into a region of size (2|0)" "pr101475" } |
| 70 |
*(AC4*)a3 = Ac4; // { dg-warning "writing (4 bytes|1 byte) into a region of size (3|0)" "pr101475" } |
| 71 |
*(AC8*)a4 = Ac8; // { dg-warning "writing (8 bytes|1 byte) into a region of size (4|0)" "pr101475" } |
| 72 |
*(AC8*)a7 = Ac8; // { dg-warning "writing (8 bytes|1 byte) into a region of size (7|0)" "pr101475" } |
| 73 |
*(AC16*)a15 = Ac16; // { dg-warning "writing (16 bytes|1 byte) into a region of size (15|0)" "pr101475" } |
| 74 |
} |
| 75 |
|
| 76 |
void warn_aggr_decl (void) |
| 77 |
{ |
| 78 |
*(AC2*)a1 = ac2; // { dg-warning "writing 2 bytes into a region of size 1" } |
| 79 |
*(AC4*)a2 = ac4; // { dg-warning "writing 4 bytes into a region of size 2" } |
| 80 |
*(AC4*)a3 = ac4; // { dg-warning "writing 4 bytes into a region of size 3" } |
| 81 |
*(AC8*)a4 = ac8; // { dg-warning "writing 8 bytes into a region of size 4" } |
| 82 |
*(AC8*)a7 = ac8; // { dg-warning "writing 8 bytes into a region of size 7" } |
| 83 |
*(AC16*)a15 = ac16; // { dg-warning "writing 16 bytes into a region of size 15" } |
| 84 |
} |
| 85 |
|
| 86 |
void warn_aggr_parm (AC2 pc2, AC4 pc4, AC8 pc8, AC16 pc16) |
| 87 |
{ |
| 88 |
*(AC2*)a1 = pc2; // { dg-warning "writing 2 bytes into a region of size 1" } |
| 89 |
*(AC4*)a2 = pc4; // { dg-warning "writing 4 bytes into a region of size 2" } |
| 90 |
*(AC4*)a3 = pc4; // { dg-warning "writing 4 bytes into a region of size 3" } |
| 91 |
*(AC8*)a4 = pc8; // { dg-warning "writing 8 bytes into a region of size 4" } |
| 92 |
*(AC8*)a7 = pc8; // { dg-warning "writing 8 bytes into a region of size 7" } |
| 93 |
*(AC16*)a15 = pc16; // { dg-warning "writing 16 bytes into a region of size 15" } |
| 94 |
} |
| 95 |
|
| 96 |
void warn_aggr_func (void) |
| 97 |
{ |
| 98 |
*(AC2*)a1 = fac2 (); // { dg-warning "writing 2 bytes into a region of size 1" } |
| 99 |
*(AC4*)a2 = fac4 (); // { dg-warning "writing 4 bytes into a region of size 2" } |
| 100 |
*(AC4*)a3 = fac4 (); // { dg-warning "writing 4 bytes into a region of size 3" } |
| 101 |
*(AC8*)a4 = fac8 (); // { dg-warning "writing 8 bytes into a region of size 4" } |
| 102 |
*(AC8*)a7 = fac8 (); // { dg-warning "writing 8 bytes into a region of size 7" } |
| 103 |
*(AC16*)a15 = fac16 ();// { dg-warning "writing 16 bytes into a region of size 15" } |
| 104 |
|
| 105 |
extern AC2 fac2_x (); |
| 106 |
|
| 107 |
*(AC2*)a1 = fac2_x (); // { dg-warning "writing 2 bytes into a region of size 1" } |
| 108 |
|
| 109 |
extern AC2 fac2_p (char*); |
| 110 |
|
| 111 |
*(AC2*)a1 = fac2_p (0); // { dg-warning "writing 2 bytes into a region of size 1" } |
| 112 |
} |