Fix ICE in substring-handling building 502.gcc_r (PR 87562)
[official-gcc.git] / gcc / testsuite / gcc.dg / Wstringop-overflow-2.c
blob6e3e2ca0825b2bf496fc365bd6dcc2949154b5b7
1 /* PR tree-optimization/83508 - c-c++-common/Wrestrict.c fails since r255836
2 Test to verify that only one of -Wrestrict and -Wstringop-overflow is
3 issued for a problem where either would be appropriate.
4 { dg-do compile }
5 { dg-options "-O2 -Wrestrict -Wstringop-overflow" } */
7 #define DIFF_MAX __PTRDIFF_MAX__
9 typedef __PTRDIFF_TYPE__ ptrdiff_t;
10 typedef __SIZE_TYPE__ size_t;
12 void sink (void*);
14 void f (ptrdiff_t i, size_t n)
16 if (i < DIFF_MAX - 2 || DIFF_MAX - 1 > i)
17 i = DIFF_MAX - 2;
19 if (n < 4 || 5 < n)
20 n = 4;
22 char a[8] = "012";
24 /* The following could very well be diagnosed by -Wstringop-overflow
25 instead but there's no way to verify that only one of the two
26 warnings is issued and the choice of -Wrestrict simply reflects
27 the fact that -Wrestrict runs before -Wstringop-overflow. */
28 __builtin_strncpy (a + i, a, n); /* { dg-warning "\\\[-Wrestrict]" } */
29 sink (a);