* tree-loop-distribution.c (INCLUDE_ALGORITHM): New header file.
[official-gcc.git] / gcc / testsuite / gcc.dg / builtin-stpncpy.c
blobe4290d5635ce7b86dc2ba4d2fead3b96a8da2261
1 /* PR tree-optimization/80669 - Bad -Wstringop-overflow warnings for stpncpy
2 { dg-do compile }
3 { dg-options "-O2 -Wall" } */
5 #define SIZE_MAX __SIZE_MAX__
7 typedef __SIZE_TYPE__ size_t;
9 void sink (char*);
11 #define stpncpy (d, s, n) sink (__builtin_stpncpy (d, s, n))
13 size_t value (void);
15 size_t range (size_t min, size_t max)
17 size_t val = value ();
18 return val < min || max < val ? min : val;
21 /* Verify that no warning is issued for stpncpy with constant size. */
22 void test_cst (char *d)
24 __builtin_stpncpy (d, "123", 0);
25 __builtin_stpncpy (d, "123", 1);
26 __builtin_stpncpy (d, "123", 2);
27 __builtin_stpncpy (d, "123", 3);
28 __builtin_stpncpy (d, "123", 4);
29 __builtin_stpncpy (d, "123", 5);
30 __builtin_stpncpy (d, "123", 999);
32 size_t n = SIZE_MAX / 2;
34 __builtin_stpncpy (d, "123", n);
36 __builtin_stpncpy (d, "123", n + 1); /* { dg-warning "specified size \[0-9\]+ exceeds maximum object size \[0-9\]+" } */
40 /* Verify that no warning is issued for stpncpy with size in some range. */
41 void test_rng (char *d)
43 #define R(min, max) range (min, max)
45 __builtin_stpncpy (d, "123", R (0, 1));
46 __builtin_stpncpy (d, "123", R (0, 2));
47 __builtin_stpncpy (d, "123", R (0, 3));
48 __builtin_stpncpy (d, "123", R (0, 4));
49 __builtin_stpncpy (d, "123", R (0, 5));
51 __builtin_stpncpy (d, "123", R (1, 2));
52 __builtin_stpncpy (d, "123", R (1, 3));
53 __builtin_stpncpy (d, "123", R (1, 4));
54 __builtin_stpncpy (d, "123", R (1, 5));
56 __builtin_stpncpy (d, "123", R (2, 3));
57 __builtin_stpncpy (d, "123", R (2, 4));
58 __builtin_stpncpy (d, "123", R (2, 5));
60 __builtin_stpncpy (d, "123", R (3, 4));
61 __builtin_stpncpy (d, "123", R (3, 5));
63 __builtin_stpncpy (d, "123", R (4, 5));
65 __builtin_stpncpy (d, "123", R (5, 6));
67 __builtin_stpncpy (d, "123", R (12345, 23456));
69 size_t n = SIZE_MAX / 2;
71 __builtin_stpncpy (d, "123", R (n - 1, n + 1));
73 __builtin_stpncpy (d, "123", R (n + 1, n + 2)); /* { dg-warning "specified size between \[0-9\]+ and \[0-9\]+ exceeds maximum object size \[0-9\]+" } */