PR tree-optimization/85753 - missing -Wrestrict on memcpy into a member array
[official-gcc.git] / gcc / testsuite / gcc.dg / Wrestrict-10.c
blobc412e42bacc932ae8bd9a4690ebc29d4074f86e7
1 /* PR tree-optimization/84526 - ICE in generic_overlap
2 { dg-do compile }
3 { dg-options "-O2 -Wrestrict" } */
5 typedef __SIZE_TYPE__ size_t;
7 extern void* memcpy (void* restrict, const void* restrict, size_t);
8 extern char* strcat (char* restrict, const char* restrict);
9 extern char* strcpy (char* restrict, const char* restrict);
10 extern char* strncat (char* restrict, const char* restrict, size_t);
11 extern char* strncpy (char* restrict, const char* restrict, size_t);
13 struct
15 char a[1];
16 } b;
18 int i;
19 size_t n;
21 void __attribute__ ((noclone, noinline))
22 test_arr_memcpy_1 (void)
24 memcpy (&b.a[i], b.a, n);
27 void __attribute__ ((noclone, noinline))
28 test_arr_memcpy_2 (void)
30 memcpy (b.a, &b.a[i], n);
33 void __attribute__ ((noclone, noinline))
34 test_arr_strcat_1 (void)
36 strcat (&b.a[i], b.a); /* { dg-warning "\\\[-Wrestrict" } */
39 void __attribute__ ((noclone, noinline))
40 test_arr_strcat_2 (void)
42 /* This probably deserves a warning. */
43 strcpy (b.a, &b.a[i]);
46 void __attribute__ ((noclone, noinline))
47 test_arr_strncat_1 (void)
49 strncat (&b.a[i], b.a, n); /* { dg-warning "\\\[-Wrestrict" } */
52 void __attribute__ ((noclone, noinline))
53 test_arr_strncat_2 (void)
55 strncat (b.a, &b.a[i], n); /* { dg-warning "\\\[-Wrestrict" } */
58 void __attribute__ ((noclone, noinline))
59 test_arr_strcpy_1 (void)
61 strcpy (&b.a[i], b.a); /* { dg-warning "\\\[-Wrestrict" } */
64 void __attribute__ ((noclone, noinline))
65 test_arr_strcpy_2 (void)
67 strcpy (b.a, &b.a[i]);
71 struct S {
72 int a;
73 char b[10];
74 } d;
76 void __attribute__ ((noclone, noinline))
77 test_obj_memcpy_1 (void)
79 memcpy (d.b, (char *) &d, n);
82 void __attribute__ ((noclone, noinline))
83 test_obj_memcpy_2 (void)
85 memcpy ((char *) &d, d.b, n);
88 void __attribute__ ((noclone, noinline))
89 test_obj_strcpy_1 (void)
91 strcpy (d.b, (char *) &d);
94 void __attribute__ ((noclone, noinline))
95 test_obj_strcpy_2 (void)
97 strcpy ((char *) &d, d.b);
100 void __attribute__ ((noclone, noinline))
101 test_obj_strncat_1 (void)
103 strncat (d.b, (char *) &d, n); /* { dg-warning "\\\[-Wrestrict" } */
106 void __attribute__ ((noclone, noinline))
107 test_obj_strncat_2 (void)
109 strncat ((char *) &d, d.b, n); /* { dg-warning "\\\[-Wrestrict" } */
112 void __attribute__ ((noclone, noinline))
113 test_obj_strncpy_1 (void)
115 strncpy (d.b, (char *) &d, n);
118 void test_obj_strncpy_2 (void)
120 strncpy ((char *) &d, d.b, n);