* config.gcc: Remove MASK_JUMP_IN_DELAY from target_cpu_default2.
[official-gcc.git] / gcc / testsuite / c-c++-common / Wsizeof-pointer-memaccess1.c
blob8e829d61ae0b784fee319753bd916c4a3b2dbdff
1 /* Test -Wsizeof-pointer-memaccess warnings. */
2 /* { dg-do compile } */
3 /* { dg-options "-Wall -Wno-sizeof-array-argument" } */
5 typedef __SIZE_TYPE__ size_t;
6 #ifdef __cplusplus
7 extern "C" {
8 #endif
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);
12 #ifdef __cplusplus
14 #endif
16 struct A { short a, b; int c, d; long e, f; };
17 typedef struct A TA;
18 typedef struct A *PA;
19 typedef TA *PTA;
20 struct B {};
21 typedef struct B TB;
22 typedef struct B *PB;
23 typedef TB *PTB;
24 typedef int X[3][3][3];
26 void foo (void **);
28 void
29 f1 (void *x)
31 struct A a, *pa1 = &a;
32 TA *pa2 = &a;
33 PA pa3 = &a;
34 PTA pa4 = &a;
35 void *arr[100];
36 int i = 0;
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));
65 foo (arr);
68 void
69 f2 (void *x)
71 struct B b, *pb1 = &b;
72 TB *pb2 = &b;
73 PB pb3 = &b;
74 PTB pb4 = &b;
75 void *arr[100];
76 int i = 0;
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));
105 foo (arr);
108 void
109 f3 (void *x, char *y, int z, X w)
111 unsigned char *y1 = (unsigned char *) __builtin_alloca (z + 16);
112 char buf1[7];
113 signed char buf2[z + 32];
114 long buf3[17];
115 int *buf4[9];
116 signed char *y2 = buf2;
117 char c;
118 void *arr[100];
119 int i = 0;
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));
144 foo (arr);
147 void
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);