comparison gcc/testsuite/c-c++-common/Wrestrict-2.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents
children 1830386684a0
comparison
equal deleted inserted replaced
111:04ced10e8804 131:84e7813d76e9
1 /* PR 35503 - Warn about restricted pointers
2 Test to exercise that -Wrestrict warnings are issued for memory and
3 sring functions when they are declared in system headers (i.e., not
4 just when they are explicitly declared in the source file.)
5 Also verify that the warnings are issued even for calls where the
6 source of the aliasing violation is in a different function than
7 the restricted call.
8 { dg-do compile }
9 { dg-options "-O2 -Wrestrict" } */
10
11 #include <string.h>
12
13 static void wrap_memcpy (void *d, const void *s, size_t n)
14 {
15 memcpy (d, s, n); /* { dg-warning "accessing 2 bytes at offsets 0 and 1 overlaps 1 byte at offset 1" "memcpy" } */
16 }
17
18 void call_memcpy (char *d)
19 {
20 const void *s = d + 1;
21 wrap_memcpy (d, s, 2);
22 }
23
24
25 static void wrap_strcat (char *d, const char *s)
26 {
27 strcat (d, s); /* { dg-warning "source argument is the same as destination" "strcat" } */
28 }
29
30 void call_strcat (char *d)
31 {
32 const char *s = d;
33 wrap_strcat (d, s);
34 }
35
36
37 static void wrap_strcpy (char *d, const char *s)
38 {
39 strcpy (d, s); /* { dg-warning "source argument is the same as destination" "strcpy" } */
40 }
41
42 void call_strcpy (char *d)
43 {
44 const char *s = d;
45 wrap_strcpy (d, s);
46 }
47
48
49 static void wrap_strncat (char *d, const char *s, size_t n)
50 {
51 strncat (d, s, n); /* { dg-warning "source argument is the same as destination" "strncat" } */
52 }
53
54 void call_strncat (char *d, size_t n)
55 {
56 const char *s = d;
57 wrap_strncat (d, s, n);
58 }
59
60
61 static void wrap_strncpy (char *d, const char *s, size_t n)
62 {
63 strncpy (d, s, n); /* { dg-warning "source argument is the same as destination" "strncpy" } */
64 }
65
66 void call_strncpy (char *d, size_t n)
67 {
68 const char *s = d;
69 wrap_strncpy (d, s, n);
70 }