1 /* Test -Wsizeof-pointer-memaccess warnings. */
2 /* { dg-do compile } */
3 /* { dg-options "-Wall -Wno-sizeof-array-argument" } */
5 typedef __SIZE_TYPE__
size_t;
9 extern int snprintf (char *, size_t, const char *, ...);
10 extern int vsnprintf (char *, size_t, const char *, __builtin_va_list
);
11 extern void *memchr (const void *, int, size_t);
16 struct A
{ short a
, b
; int c
, d
; long e
, f
; };
24 typedef int X
[3][3][3];
31 struct A a
, *pa1
= &a
;
37 arr
[i
++] = memchr (&a
, 0, sizeof (&a
)); /* { dg-warning "call is the same expression as the source; did you mean to remove the addressof" } */
38 arr
[i
++] = memchr (pa1
, 0, sizeof (pa1
)); /* { dg-warning "call is the same expression as the source; did you mean to dereference it" } */
39 arr
[i
++] = memchr (pa2
, 0, sizeof pa2
); /* { dg-warning "call is the same expression as the source; did you mean to dereference it" } */
40 arr
[i
++] = memchr (pa3
, 0, sizeof (pa3
)); /* { dg-warning "call is the same expression as the source; did you mean to dereference it" } */
41 arr
[i
++] = memchr (pa4
, 0, sizeof pa4
); /* { dg-warning "call is the same expression as the source; did you mean to dereference it" } */
42 arr
[i
++] = memchr (pa1
, 0, sizeof (struct A
*)); /* { dg-warning "call is the same pointer type \[^\n\r\]* as the source; expected \[^\n\r\]* or an explicit length" } */
43 arr
[i
++] = memchr (pa2
, 0, sizeof (PTA
)); /* { dg-warning "call is the same pointer type \[^\n\r\]* as the source; expected \[^\n\r\]* or an explicit length" } */
44 arr
[i
++] = memchr (pa3
, 0, sizeof (PA
)); /* { dg-warning "call is the same pointer type \[^\n\r\]* as the source; expected \[^\n\r\]* or an explicit length" } */
45 arr
[i
++] = memchr (pa4
, 0, sizeof (__typeof (pa4
))); /* { dg-warning "call is the same pointer type \[^\n\r\]* as the source; expected \[^\n\r\]* or an explicit length" } */
47 /* These are correct, no warning. */
48 arr
[i
++] = memchr (&a
, 0, sizeof a
);
49 arr
[i
++] = memchr (&a
, 0, sizeof (a
));
50 arr
[i
++] = memchr (&a
, 0, sizeof (struct A
));
51 arr
[i
++] = memchr (&a
, 0, sizeof (const struct A
));
52 arr
[i
++] = memchr (&a
, 0, sizeof (volatile struct A
));
53 arr
[i
++] = memchr (&a
, 0, sizeof (volatile const struct A
));
54 arr
[i
++] = memchr (&a
, 0, sizeof (TA
));
55 arr
[i
++] = memchr (&a
, 0, sizeof (__typeof (*&a
)));
56 arr
[i
++] = memchr (pa1
, 0, sizeof (*pa1
));
57 arr
[i
++] = memchr (pa2
, 0, sizeof (*pa3
));
58 arr
[i
++] = memchr (pa3
, 0, sizeof (__typeof (*pa3
)));
59 /* These are probably broken, but obfuscated, no warning. */
60 arr
[i
++] = memchr ((void *) &a
, 0, sizeof (&a
));
61 arr
[i
++] = memchr ((char *) &a
, 0, sizeof (&a
));
62 arr
[i
++] = memchr (&a
, 0, sizeof (&a
) + 0);
63 arr
[i
++] = memchr (&a
, 0, 0 + sizeof (&a
));
71 struct B b
, *pb1
= &b
;
77 arr
[i
++] = memchr (&b
, 0, sizeof (&b
)); /* { dg-warning "call is the same expression as the source; did you mean to remove the addressof" } */
78 arr
[i
++] = memchr (pb1
, 0, sizeof (pb1
)); /* { dg-warning "call is the same expression as the source; did you mean to dereference it" } */
79 arr
[i
++] = memchr (pb2
, 0, sizeof pb2
); /* { dg-warning "call is the same expression as the source; did you mean to dereference it" } */
80 arr
[i
++] = memchr (pb3
, 0, sizeof (pb3
)); /* { dg-warning "call is the same expression as the source; did you mean to dereference it" } */
81 arr
[i
++] = memchr (pb4
, 0, sizeof pb4
); /* { dg-warning "call is the same expression as the source; did you mean to dereference it" } */
82 arr
[i
++] = memchr (pb1
, 0, sizeof (struct B
*)); /* { dg-warning "call is the same pointer type \[^\n\r\]* as the source; expected \[^\n\r\]* or an explicit length" } */
83 arr
[i
++] = memchr (pb2
, 0, sizeof (PTB
)); /* { dg-warning "call is the same pointer type \[^\n\r\]* as the source; expected \[^\n\r\]* or an explicit length" } */
84 arr
[i
++] = memchr (pb3
, 0, sizeof (PB
)); /* { dg-warning "call is the same pointer type \[^\n\r\]* as the source; expected \[^\n\r\]* or an explicit length" } */
85 arr
[i
++] = memchr (pb4
, 0, sizeof (__typeof (pb4
))); /* { dg-warning "call is the same pointer type \[^\n\r\]* as the source; expected \[^\n\r\]* or an explicit length" } */
87 /* These are correct, no warning. */
88 arr
[i
++] = memchr (&b
, 0, sizeof b
);
89 arr
[i
++] = memchr (&b
, 0, sizeof (b
));
90 arr
[i
++] = memchr (&b
, 0, sizeof (struct B
));
91 arr
[i
++] = memchr (&b
, 0, sizeof (const struct B
));
92 arr
[i
++] = memchr (&b
, 0, sizeof (volatile struct B
));
93 arr
[i
++] = memchr (&b
, 0, sizeof (volatile const struct B
));
94 arr
[i
++] = memchr (&b
, 0, sizeof (TB
));
95 arr
[i
++] = memchr (&b
, 0, sizeof (__typeof (*&b
)));
96 arr
[i
++] = memchr (pb1
, 0, sizeof (*pb1
));
97 arr
[i
++] = memchr (pb2
, 0, sizeof (*pb3
));
98 arr
[i
++] = memchr (pb3
, 0, sizeof (__typeof (*pb3
)));
99 /* These are probably broken, but obfuscated, no warning. */
100 arr
[i
++] = memchr ((void *) &b
, 0, sizeof (&b
));
101 arr
[i
++] = memchr ((char *) &b
, 0, sizeof (&b
));
102 arr
[i
++] = memchr (&b
, 0, sizeof (&b
) + 0);
103 arr
[i
++] = memchr (&b
, 0, 0 + sizeof (&b
));
109 f3 (void *x
, char *y
, int z
, X w
)
111 unsigned char *y1
= (unsigned char *) __builtin_alloca (z
+ 16);
113 signed char buf2
[z
+ 32];
116 signed char *y2
= buf2
;
120 arr
[i
++] = memchr (y
, 0, sizeof (y
)); /* { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" } */
121 arr
[i
++] = memchr (y1
, 0, sizeof (y1
)); /* { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" } */
122 arr
[i
++] = memchr (y2
, 0, sizeof (y2
)); /* { dg-warning "call is the same expression as the source; did you mean to provide an explicit length" } */
123 arr
[i
++] = memchr (&c
, 0, sizeof (&c
)); /* { dg-warning "call is the same expression as the source; did you mean to remove the addressof" } */
124 arr
[i
++] = memchr (w
, 0, sizeof w
); /* { dg-warning "call is the same expression as the source; did you mean to dereference it" } */
126 /* These are correct, no warning. */
127 arr
[i
++] = memchr (y
, 0, sizeof (*y
));
128 arr
[i
++] = memchr (y1
, 0, sizeof (*y2
));
129 arr
[i
++] = memchr (buf1
, 0, sizeof buf1
);
130 arr
[i
++] = memchr (buf3
, 0, sizeof (buf3
));
131 arr
[i
++] = memchr (&buf3
[0], 0, sizeof (buf3
));
132 arr
[i
++] = memchr (&buf4
[0], 0, sizeof (buf4
));
133 arr
[i
++] = memchr (w
, 0, sizeof (X
));
134 /* These are probably broken, but obfuscated, no warning. */
135 arr
[i
++] = memchr ((void *) y
, 0, sizeof (y
));
136 arr
[i
++] = memchr ((char *) y1
, 0, sizeof (y2
));
137 arr
[i
++] = memchr (y
, 0, sizeof (y
) + 0);
138 arr
[i
++] = memchr (y1
, 0, 0 + sizeof (y2
));
139 arr
[i
++] = memchr ((void *) &c
, 0, sizeof (&c
));
140 arr
[i
++] = memchr ((signed char *) &c
, 0, sizeof (&c
));
141 arr
[i
++] = memchr (&c
, 0, sizeof (&c
) + 0);
142 arr
[i
++] = memchr (&c
, 0, 0 + sizeof (&c
));
148 f4 (char x
[64], char *y
, __builtin_va_list ap
)
150 char buf
[128], *p
= buf
;
151 snprintf (x
, sizeof (x
), "%s", y
); /* { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } */
152 vsnprintf (x
, sizeof (x
), "%s", ap
); /* { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } */
153 snprintf (p
, sizeof (p
), "%s", y
); /* { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } */
154 vsnprintf (p
, sizeof (p
), "%s", ap
); /* { dg-warning "call is the same expression as the destination; did you mean to provide an explicit length" } */
156 /* These are correct, no warning. */
157 snprintf (buf
, sizeof (buf
), "%s", y
);
158 vsnprintf (buf
, sizeof (buf
), "%s", ap
);
159 snprintf (p
, sizeof (buf
), "%s", y
);
160 vsnprintf (p
, sizeof (buf
), "%s", ap
);