1 /* PR 96903 - bogus warning on memcpy at negative offset from array end
3 { dg-options "-O2 -Wall -Wno-array-bounds -ftrack-macro-expansion=0" } */
7 #define INT_MAX __INT_MAX__
8 #define INT_MIN -(INT_MAX - 1)
9 #define UINT_MAX (2U * INT_MAX + 1)
11 typedef __SIZE_TYPE__
size_t;
13 void* memset (void *, int, size_t);
15 void sink (void*, ...);
18 struct S
{ char a11
[11], b
; };
21 #define T2(dst, off1, off2, n) do { \
23 char *_p1 = _p0 + (off1); \
24 char *_p2 = _p1 + (off2); \
26 sink (dst, _p0, _p1, _p2); \
29 #define T1(dst, off, n) T2 (dst, off, 0, n)
32 void nowarn_memset_array_cst (void)
54 void nowarn_memset_array_rng_int (void)
58 int i11
= SR (11, INT_MAX
);
59 int i10
= SR (10, INT_MAX
);
60 int i9
= SR ( 9, INT_MAX
);
61 int i3
= SR ( 3, INT_MAX
);
62 int i2
= SR ( 2, INT_MAX
);
63 int i1
= SR ( 1, INT_MAX
);
64 int i0
= SR ( 0, INT_MAX
);
66 int m11
= SR (INT_MIN
, -11);
67 int m10
= SR (INT_MIN
, -10);
68 int m9
= SR (INT_MIN
, -9);
69 int m3
= SR (INT_MIN
, -3);
70 int m2
= SR (INT_MIN
, -2);
71 int m1
= SR (INT_MIN
, -1);
72 int m0
= SR (INT_MIN
, -0);
92 void nowarn_memset_array_rng (void)
96 T2 (p
, SR (-11, -10), SR ( -2, -1), UR (11, 12));
97 T2 (p
, SR (-10, -9), SR ( -1, 0), UR (11, 13));
98 T2 (p
, SR ( -9, -8), SR ( -2, -1), UR (11, 14));
99 T2 (p
, SR ( -8, -7), SR ( -3, -2), UR (11, 15));
100 T2 (p
, SR ( -7, -6), SR ( -4, -3), UR (11, 16));
101 T2 (p
, SR ( -6, -5), SR ( -5, -4), UR (11, 17));
102 T2 (p
, SR ( -5, -4), SR ( -6, -5), UR (11, 18));
103 T2 (p
, SR ( -4, -3), SR ( -7, -6), UR (11, 19));
104 T2 (p
, SR ( -3, -2), SR ( -8, -7), UR (11, INT_MAX
));
105 T2 (p
, SR ( -2, -1), SR ( -9, -8), UR (11, UINT_MAX
));
106 T2 (p
, SR ( -1, 0), SR (-10, -9), UR (11, DIFF_MAX
));
107 T2 (p
, SR ( 0, 1), SR (-11, -10), UR (11, SIZE_MAX
));
109 T2 (p
, SR (DIFF_MIN
, -10), SR (DIFF_MIN
, -1), UR (10, 12));
111 T2 (p
, SR (-11, -10), SR ( -3, -1), UR (10, 12))
112 T2 (p
, SR (-11, -10), SR ( -3, -1), UR (10, 12))
116 void warn_memset_array_rng (void)
119 size_t n11_12
= UR (11, 12);
120 size_t n10_12
= UR (10, 12);
122 T2 (p
, SR (-11, -10), SR ( -3, -2), n11_12
); // { dg-warning "writing between 11 and 12 bytes into a region of size 0" }
123 T2 (p
, SR (-11, -10), SR ( -3, -2), n10_12
); // { dg-warning "writing between 10 and 12 bytes into a region of size 0" }
127 void nowarn_memset_anti_range (void)
129 size_t n11
= UR (11, SIZE_MAX
);
133 T1 (p
, (int)SAR (INT_MIN
, -12), n11
);
134 T1 (p
, (int)SAR ( -13, -13), n11
);
135 T1 (p
, (int)SAR ( -13, -12), n11
);
136 T1 (p
, (int)SAR ( -10, 1), n11
);
137 T1 (p
, (int)SAR ( -10, 11), n11
);
138 T1 (p
, (int)SAR ( -10, INT_MAX
), n11
);
139 T1 (p
, (int)SAR ( -1, -1), n11
);
140 T1 (p
, (int)SAR ( -1, 0), n11
);
141 T1 (p
, (int)SAR ( -1, 11), n11
);
142 T1 (p
, (int)SAR ( -1, INT_MAX
), n11
);
144 T1 (p
, SAR (DIFF_MIN
, -12), n11
);
145 T1 (p
, SAR ( -13, -13), n11
);
146 T1 (p
, SAR ( -13, -12), n11
);
147 T1 (p
, SAR ( -10, 1), n11
); // { dg-bogus "-Wstringop-overflow" }
148 T1 (p
, SAR ( -10, 11), n11
); // { dg-bogus "-Wstringop-overflow" }
149 T1 (p
, SAR ( -10, DIFF_MAX
), n11
);
150 T1 (p
, SAR ( -1, -1), n11
); // { dg-bogus "-Wstringop-overflow" }
151 T1 (p
, SAR ( -1, 0), n11
); // { dg-bogus "-Wstringop-overflow" }
152 T1 (p
, SAR ( -1, 11), n11
); // { dg-bogus "-Wstringop-overflow" }
153 T1 (p
, SAR ( -1, DIFF_MAX
), n11
);
156 void warn_memset_reversed_range (void)
158 size_t n11
= UR (11, SIZE_MAX
);
162 /* Since the offset is excessive, either starting before &a11[0]
163 ot just past &a[11], the region size in the warning should
164 probably be zero, but accept other sizes too.
166 The problem isn't detected anymore because the offset is in
167 the anti-range ~[INT_MIN, -11] which isn't handled. */
168 T1 (p
, SAR (INT_MIN
, -11), n11
); // { dg-warning "writing 11 or more bytes into a region of size \\d+" "" { xfail *-*-* } }
170 /* The following are represented as ordinary ranges with reversed bounds
171 and those are handled. */
172 T1 (p
, SAR (INT_MIN
, 11), n11
); // { dg-warning "writing 11 or more bytes into a region of size 0" }
173 T1 (p
, SAR (INT_MIN
, 1), n11
); // { dg-warning "writing 11 or more bytes into a region of size 0" }
174 T1 (p
, SAR (INT_MIN
, 0), n11
); // { dg-warning "writing 11 or more bytes into a region of size 0" }
175 /* Also represented as a true anti-range. */
176 T1 (p
, SAR ( -12, -11), n11
); // { dg-warning "writing 11 or more bytes into a region of size \\d+" "" { xfail *-*-* } }
177 T1 (p
, SAR ( -12, -1), n11
); // { dg-warning "writing 11 or more bytes into a region of size 0" }
178 T1 (p
, SAR ( -11, 0), n11
); // { dg-warning "writing 11 or more bytes into a region of size 0" }
179 T1 (p
, SAR ( -11, 11), n11
); // { dg-warning "writing 11 or more bytes into a region of size 0" }