]>
Commit | Line | Data |
---|---|---|
f0500db3 MS |
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" } */ | |
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 | { | |
d9da496a | 60 | *(AC2*)a1 = Ac2; // { dg-warning "writing 2 bytes into a region of size 1" "pr101475" { target { vect_slp_v2qi_store_unalign } } } |
3c8d8c0b | 61 | // After vectorization, below codes are optimized to |
62 | // MEM <vector(4) char> [(char *)&a2] = { 0, 1, 2, 3 }; | |
63 | // MEM <vector(4) char> [(char *)&a3] = { 0, 1, 2, 3 }; | |
64 | // MEM <vector(8) char> [(char *)&a4] = { 0, 1, 2, 3, 4, 5, 6, 7 }; | |
65 | // MEM <vector(8) char> [(char *)&a7] = { 0, 1, 2, 3, 4, 5, 6, 7 }; | |
66 | // MEM <vector(16) char> [(char *)&a15] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15 }; | |
67 | // and warning should be expected, refer to PR102722. | |
2e560abf | 68 | *(AC4*)a2 = Ac4; // { dg-warning "writing 4 bytes into a region of size 2" "pr101475" { xfail { ! { vect_slp_v4qi_store_unalign_1 } } } } |
69 | *(AC4*)a3 = Ac4; // { dg-warning "writing 4 bytes into a region of size 3" "pr101475" { xfail { ! { vect_slp_v4qi_store_unalign_1 } } } } | |
70 | *(AC8*)a4 = Ac8; // { dg-warning "writing 8 bytes into a region of size 4" "pr101475" { xfail { ! { vect_slp_v8qi_store_unalign_1 } } } } | |
71 | *(AC8*)a7 = Ac8; // { dg-warning "writing 8 bytes into a region of size 7" "pr101475" { xfail { ! { vect_slp_v8qi_store_unalign_1 } } } } | |
72 | *(AC16*)a15 = Ac16; // { dg-warning "writing 16 bytes into a region of size 15" "pr101475" { xfail { ! { vect_slp_v16qi_store_unalign_1 } } } } | |
f0500db3 MS |
73 | } |
74 | ||
75 | void warn_aggr_decl (void) | |
76 | { | |
77 | *(AC2*)a1 = ac2; // { dg-warning "writing 2 bytes into a region of size 1" } | |
78 | *(AC4*)a2 = ac4; // { dg-warning "writing 4 bytes into a region of size 2" } | |
79 | *(AC4*)a3 = ac4; // { dg-warning "writing 4 bytes into a region of size 3" } | |
80 | *(AC8*)a4 = ac8; // { dg-warning "writing 8 bytes into a region of size 4" } | |
81 | *(AC8*)a7 = ac8; // { dg-warning "writing 8 bytes into a region of size 7" } | |
82 | *(AC16*)a15 = ac16; // { dg-warning "writing 16 bytes into a region of size 15" } | |
83 | } | |
84 | ||
85 | void warn_aggr_parm (AC2 pc2, AC4 pc4, AC8 pc8, AC16 pc16) | |
86 | { | |
87 | *(AC2*)a1 = pc2; // { dg-warning "writing 2 bytes into a region of size 1" } | |
88 | *(AC4*)a2 = pc4; // { dg-warning "writing 4 bytes into a region of size 2" } | |
89 | *(AC4*)a3 = pc4; // { dg-warning "writing 4 bytes into a region of size 3" } | |
90 | *(AC8*)a4 = pc8; // { dg-warning "writing 8 bytes into a region of size 4" } | |
91 | *(AC8*)a7 = pc8; // { dg-warning "writing 8 bytes into a region of size 7" } | |
92 | *(AC16*)a15 = pc16; // { dg-warning "writing 16 bytes into a region of size 15" } | |
93 | } | |
94 | ||
95 | void warn_aggr_func (void) | |
96 | { | |
97 | *(AC2*)a1 = fac2 (); // { dg-warning "writing 2 bytes into a region of size 1" } | |
98 | *(AC4*)a2 = fac4 (); // { dg-warning "writing 4 bytes into a region of size 2" } | |
99 | *(AC4*)a3 = fac4 (); // { dg-warning "writing 4 bytes into a region of size 3" } | |
100 | *(AC8*)a4 = fac8 (); // { dg-warning "writing 8 bytes into a region of size 4" } | |
101 | *(AC8*)a7 = fac8 (); // { dg-warning "writing 8 bytes into a region of size 7" } | |
102 | *(AC16*)a15 = fac16 ();// { dg-warning "writing 16 bytes into a region of size 15" } | |
103 | ||
104 | extern AC2 fac2_x (); | |
105 | ||
106 | *(AC2*)a1 = fac2_x (); // { dg-warning "writing 2 bytes into a region of size 1" } | |
107 | ||
108 | extern AC2 fac2_p (char*); | |
109 | ||
110 | *(AC2*)a1 = fac2_p (0); // { dg-warning "writing 2 bytes into a region of size 1" } | |
111 | } |