1 /* Verify warnings and notes for MAX_EXPRs involving either pointers
2    to distinct objects or one to a known object and the other to
3    an unknown one.  Unlike for the same object, for unrelated objects
4    the expected warnings and notes are the same as for MIN_EXPR: when
5    the order of the objects in the address space cannot be determined
6    the larger of them is assumed to be used.  (This is different for
7    distinct struct members where the order is given.)
8    The relational expressions are strictly invalid but that should be
9    diagnosed by a separate warning.
10    { dg-do compile }
11    { dg-options "-O2 -Wno-array-bounds" } */
12 
13 #define MAX(p, q) ((p) > (q) ? (p) : (q))
14 
15 /* Verify that even for MAX_EXPR and like for MIN_EXPR, the note points
16    to the larger of the two objects and mentions the offset into it
17    (although the offset might be better included in the warning).  */
18 extern char a3[3];
19 extern char a5[5];  // { dg-message "at offset \[^a-zA-Z\n\r\]*5\[^a-zA-Z0-9\]* into destination object 'a5' of size 5" "note" }
20 
max_a3_a5(int i)21 void max_a3_a5 (int i)
22 {
23   char *p = a3 + i;
24   char *q = a5 + i;
25 
26   /* The relational expression below is invalid and should be diagnosed
27      by its own warning independently of -Wstringop-overflow.  */
28   char *d = MAX (p, q);
29 
30   d[2] = 0;         // { dg-warning "writing 4 bytes into a region of size 3" "pr102706" { target { vect_slp_v4qi_store_unalign } } }
31   d[3] = 0;
32   d[4] = 0;
33   d[5] = 0;         // { dg-warning "writing 1 byte into a region of size 0" "pr102706" { xfail { vect_slp_v4qi_store_unalign } } }
34 }
35 
36 
37 // Same as above but with the larger array as the first MAX_EXPR operand.
38 extern char b4[4];
39 extern char b6[6];  // { dg-message "at offset \[^a-zA-Z\n\r\]*6\[^a-zA-Z0-9\]* into destination object 'b6' of size 6" "note" }
40 
max_b6_b4(int i)41 void max_b6_b4 (int i)
42 {
43   char *p = b6 + i;
44   char *q = b4 + i;
45   char *d = MAX (p, q);
46 
47   d[3] = 0;         // { dg-warning "writing 4 bytes into a region of size 3" "pr102706" { target { vect_slp_v4qi_store_unalign } } }
48   d[4] = 0;
49   d[5] = 0;
50   d[6] = 0;         // { dg-warning "writing 1 byte into a region of size 0" "pr102706" { xfail { vect_slp_v4qi_store_unalign } } }
51 }
52 
53 
54 /* Same as above but with the first MAX_EXPR operand pointing to an unknown
55    object.  */
56 extern char c7[7];  // { dg-message "at offset 7 into destination object 'c7' of size 7" "note" }
57 
max_p_c7(char * p,int i)58 void max_p_c7 (char *p, int i)
59 {
60   char *q = c7 + i;
61   char *d = MAX (p, q);
62 
63   d[6] = 0;
64   d[7] = 0;         // { dg-warning "writing 1 byte into a region of size 0" }
65 }
66 
67 
68 /* Same as above but with the second MIN_EXPR operand pointing to an unknown
69    object.  */
70 extern char d8[8];  // { dg-message "at offset 8 into destination object 'd8' of size 8" "note" }
71 
max_d8_p(char * q,int i)72 void max_d8_p (char *q, int i)
73 {
74   char *p = d8 + i;
75   char *d = MAX (p, q);
76 
77   d[7] = 0;
78   d[8] = 0;         // { dg-warning "writing 1 byte into a region of size 0" }
79 }
80 
81 
82 struct A3_5
83 {
84   char a3[3];  // { dg-message "at offset 3 into destination object 'a3' of size 3" "pr??????" { xfail *-*-* } }
85   // refer to pr102697 for xfail
86   char a5[5];  // { dg-message "at offset 5 into destination object 'a5' of size 5" "note" { xfail { vect_slp_v4qi_store_unalign } } }
87 };
88 
max_A3_A5(int i,struct A3_5 * pa3_5)89 void max_A3_A5 (int i, struct A3_5 *pa3_5)
90 {
91   char *p = pa3_5->a3 + i;
92   char *q = pa3_5->a5 + i;
93 
94   char *d = MAX (p, q);
95 
96   d[2] = 0;
97   d[3] = 0;         // { dg-warning "writing 1 byte into a region of size 0" "pr??????" { xfail *-*-* } }
98   d[4] = 0;
99   d[5] = 0;         // { dg-warning "writing 1 byte into a region of size 0" "pr102697" { xfail { vect_slp_v4qi_store_unalign } } }
100 }
101 
102 
103 struct B4_B6
104 {
105   char b4[4];
106   // refer to pr102697 for xfail
107   char b6[6];       // { dg-message "at offset \[^a-zA-Z\n\r\]*6\[^a-zA-Z0-9\]* into destination object 'b6' of size 6" "note" { xfail { vect_slp_v4qi_store_unalign } } }
108 };
109 
max_B6_B4(int i,struct B4_B6 * pb4_b6)110 void max_B6_B4 (int i, struct B4_B6 *pb4_b6)
111 {
112   char *p = pb4_b6->b6 + i;
113   char *q = pb4_b6->b4 + i;
114   char *d = MAX (p, q);
115 
116   d[3] = 0;
117   d[4] = 0;
118   d[5] = 0;
119   d[6] = 0;         // { dg-warning "writing 1 byte into a region of size 0" "pr102697" { xfail { vect_slp_v4qi_store_unalign } } }
120 }
121 
122 
123 struct C7
124 {
125   char c7[7];       // { dg-message "at offset 7 into destination object 'c7' of size 7" "note" }
126 };
127 
max_p_C7(char * p,int i,struct C7 * pc7)128 void max_p_C7 (char *p, int i, struct C7 *pc7)
129 {
130   char *q = pc7->c7 + i;
131   char *d = MAX (p, q);
132 
133   d[6] = 0;
134   d[7] = 0;         // { dg-warning "writing 1 byte into a region of size 0" }
135 }
136 
137 
138 struct D8
139 {
140   char d8[8];       // { dg-message "at offset 8 into destination object 'd8' of size 8" "note" }
141 };
142 
max_D8_p(char * q,int i,struct D8 * pd8)143 void max_D8_p (char *q, int i, struct D8 *pd8)
144 {
145   char *p = pd8->d8 + i;
146   char *d = MAX (p, q);
147 
148   d[7] = 0;
149   d[8] = 0;         // { dg-warning "writing 1 byte into a region of size 0" }
150 }
151