1 /* PR tree-optimization/83456 - -Wrestrict false positive on a non-overlapping
2 memcpy in an inline function
3 Verify that calls to built-in functions are diagnosed when the pointer
4 arguments to their restrict-qualified parameters are the same (the absence
5 of the false positives reported in PR 83456 is tested in Wrestrict-12.c.
7 { dg-options "-O2 -Wall -Wrestrict -Wno-stringop-truncation" } */
9 typedef __SIZE_TYPE__
size_t;
11 extern void* memcpy (void* restrict
, const void* restrict
, size_t);
12 extern void* mempcpy (void* restrict
, const void* restrict
, size_t);
13 extern char* stpncpy (char* restrict
, const char* restrict
, size_t);
14 extern char* stpcpy (char* restrict
, const char* restrict
);
15 extern char* strncat (char* restrict
, const char* restrict
, size_t);
16 extern char* strcat (char* restrict
, const char* restrict
);
17 extern char* strncpy (char* restrict
, const char* restrict
, size_t);
18 extern char* strcpy (char* restrict
, const char* restrict
);
28 void test_memcpy (char *p
, struct S
*q
, size_t n
)
30 /* The behavior of memcpy() is undefined only when when copying takes
31 place between overlapping objects. Since a call with a size of zero
32 does nothing, it should not be diagnosed. */
36 memcpy (p
, p
, 1); /* { dg-warning "\\\[-Wrestrict]" } */
39 memcpy (p
, p
, n
); /* { dg-warning "\\\[-Wrestrict]" } */
42 memcpy (q
->a
, q
->a
, 0);
45 memcpy (q
->p
, q
->p
, 1); /* { dg-warning "\\\[-Wrestrict]" } */
48 memcpy (&q
->a
[0], q
->a
, n
); /* { dg-warning "\\\[-Wrestrict]" "bug ????" { xfail *-*-* } } */
51 memcpy (q
, q
->a
, n
); /* { dg-warning "\\\[-Wrestrict]" "bug ????" { xfail *-*-* } } */
55 void test_mempcpy (char *p
, struct S
*q
, size_t n
)
60 mempcpy (p
, p
, 1); /* { dg-warning "\\\[-Wrestrict]" } */
63 mempcpy (p
, p
, n
); /* { dg-warning "\\\[-Wrestrict]" } */
66 mempcpy (q
->a
, q
->a
, 0);
69 mempcpy (q
->p
, q
->p
, 1); /* { dg-warning "\\\[-Wrestrict]" } */
72 mempcpy (&q
->a
[0], q
->a
, n
); /* { dg-warning "\\\[-Wrestrict]" "bug ????" { xfail *-*-* } } */
75 mempcpy (q
, q
->a
, n
); /* { dg-warning "\\\[-Wrestrict]" "bug ????" { xfail *-*-* } } */
79 void test_strncat (char *p
, struct S
*q
, size_t n
)
84 strncat (p
, p
, 1); /* { dg-warning "\\\[-Wrestrict]" } */
87 strncat (p
, p
, n
); /* { dg-warning "\\\[-Wrestrict]" } */
90 strncat (q
->a
, q
->a
, n
); /* { dg-warning "\\\[-Wrestrict]" } */
93 strncat (&q
->a
[0], &q
->a
[0], n
);/* { dg-warning "\\\[-Wrestrict]" } */
96 strncat (q
->a
, &q
->a
[0], n
); /* { dg-warning "\\\[-Wrestrict]" } */
99 strncat (q
->p
, &q
->p
[0], n
); /* { dg-warning "\\\[-Wrestrict]" } */
103 void test_strcat (char *p
, struct S
*q
, size_t n
)
105 strcat (p
, p
); /* { dg-warning "\\\[-Wrestrict]" } */
108 strcat (p
, p
); /* { dg-warning "\\\[-Wrestrict]" } */
111 strcat (p
, p
); /* { dg-warning "\\\[-Wrestrict]" } */
114 strcat (q
->a
, q
->a
); /* { dg-warning "\\\[-Wrestrict]" } */
117 strcat (&q
->a
[0], &q
->a
[0]); /* { dg-warning "\\\[-Wrestrict]" } */
120 strcat (q
->a
, &q
->a
[0]); /* { dg-warning "\\\[-Wrestrict]" } */
123 strcat (q
->p
, &q
->p
[0]); /* { dg-warning "\\\[-Wrestrict]" } */
127 void test_stpncpy (char *p
, struct S
*q
, size_t n
)
129 stpncpy (p
, p
, 0); /* { dg-warning "\\\[-Wrestrict]" } */
132 stpncpy (p
, p
, 1); /* { dg-warning "\\\[-Wrestrict]" } */
135 stpncpy (p
, p
, n
); /* { dg-warning "\\\[-Wrestrict]" } */
138 stpncpy (q
->a
, q
->a
, n
); /* { dg-warning "\\\[-Wrestrict]" } */
141 stpncpy (&q
->a
[0], &q
->a
[0], n
);/* { dg-warning "\\\[-Wrestrict]" } */
144 stpncpy (q
->a
, &q
->a
[0], n
); /* { dg-warning "\\\[-Wrestrict]" } */
147 stpncpy (q
->p
, &q
->p
[0], n
); /* { dg-warning "\\\[-Wrestrict]" } */
151 void test_stpcpy (char *p
, struct S
*q
, size_t n
)
153 stpcpy (p
, p
); /* { dg-warning "\\\[-Wrestrict]" } */
156 stpcpy (p
, p
); /* { dg-warning "\\\[-Wrestrict]" } */
159 stpcpy (p
, p
); /* { dg-warning "\\\[-Wrestrict]" } */
162 stpcpy (q
->a
, q
->a
); /* { dg-warning "\\\[-Wrestrict]" } */
165 stpcpy (&q
->a
[0], &q
->a
[0]); /* { dg-warning "\\\[-Wrestrict]" } */
168 stpcpy (q
->a
, &q
->a
[0]); /* { dg-warning "\\\[-Wrestrict]" } */
171 stpcpy (q
->p
, &q
->p
[0]); /* { dg-warning "\\\[-Wrestrict]" } */
175 void test_strncpy (char *p
, struct S
*q
, size_t n
)
180 strncpy (p
, p
, 1); /* { dg-warning "\\\[-Wrestrict]" } */
183 strncpy (p
, p
, n
); /* { dg-warning "\\\[-Wrestrict]" } */
186 strncpy (q
->a
, q
->a
, n
); /* { dg-warning "\\\[-Wrestrict]" } */
189 strncpy (&q
->a
[0], &q
->a
[0], n
);/* { dg-warning "\\\[-Wrestrict]" } */
192 strncpy (q
->a
, &q
->a
[0], n
); /* { dg-warning "\\\[-Wrestrict]" } */
195 strncpy (q
->p
, &q
->p
[0], n
); /* { dg-warning "\\\[-Wrestrict]" } */
199 void test_strcpy (char *p
, struct S
*q
, size_t n
)
201 strcpy (p
, p
); /* { dg-warning "\\\[-Wrestrict]" } */
204 strcpy (p
, p
); /* { dg-warning "\\\[-Wrestrict]" } */
207 strcpy (p
, p
); /* { dg-warning "\\\[-Wrestrict]" } */
210 strcpy (q
->a
, q
->a
); /* { dg-warning "\\\[-Wrestrict]" } */
213 strcpy (&q
->a
[0], &q
->a
[0]); /* { dg-warning "\\\[-Wrestrict]" } */
216 strcpy (q
->a
, &q
->a
[0]); /* { dg-warning "\\\[-Wrestrict]" } */
219 strcpy (q
->p
, &q
->p
[0]); /* { dg-warning "\\\[-Wrestrict]" } */