c++: Implement for namespace statics CWG 2867 - Order of initialization for structure...
[official-gcc.git] / gcc / testsuite / gcc.dg / Wreturn-local-addr-6.c
blob844660ff0152b47a095fb4ab8d59ccb169e276ac
1 /* PR c/71924 - missing -Wreturn-local-addr returning alloca result
2 { dg-do compile }
3 { dg-options "-O2 -Wall" }
4 { dg-require-effective-target alloca } */
6 typedef __SIZE_TYPE__ size_t;
8 void* memcpy (void*, const void*, size_t);
9 void* mempcpy (void*, const void*, size_t);
10 void* memmove (void*, const void*, size_t);
12 char* stpcpy (char*, const char*);
13 char* stpncpy (char*, const char*, size_t);
15 size_t strlen (const char*);
16 size_t strnlen (const char*, size_t);
18 char* strcat (char*, const char*);
19 char* strncat (char*, const char*, size_t);
21 char* strcpy (char*, const char*);
22 char* strncpy (char*, const char*, size_t);
24 char* strdup (const char*);
26 char* strchr (const char*, int);
27 char* strrchr (const char*, int);
28 char* strstr (const char*, const char*);
30 void sink (void*, ...);
33 void* return_memcpy (const void *s, unsigned n)
35 char a[n]; /* { dg-message "declared here" } */
36 void *p = memcpy (a, s, n);
37 sink (p);
38 return p; /* { dg-warning "\\\[-Wreturn-local-addr]" } */
41 void* return_memcpy_cst (const void *s, unsigned n)
43 char a[n]; /* { dg-message "declared here" } */
44 void *p = memcpy (a + 1, s, n);
45 sink (p);
46 return p; /* { dg-warning "\\\[-Wreturn-local-addr]" } */
49 void* return_memcpy_var (const void *s, unsigned n, int i)
51 char a[n]; /* { dg-message "declared here" } */
52 void *p = memcpy (a + i, s, n);
53 sink (p);
54 return p; /* { dg-warning "\\\[-Wreturn-local-addr]" } */
57 void* return_mempcpy (const void *s, unsigned n)
59 char a[n]; /* { dg-message "declared here" } */
60 void *p = mempcpy (a, s, n);
61 sink (p);
62 return p; /* { dg-warning "\\\[-Wreturn-local-addr]" } */
65 void* return_memmove_cst (unsigned n)
67 char a[n]; /* { dg-message "declared here" } */
68 sink (a);
69 void *p = memmove (a + 1, a, n);
70 sink (p);
71 return p; /* { dg-warning "\\\[-Wreturn-local-addr]" } */
74 void* return_memmove_var (unsigned n, int i)
76 char a[n]; /* { dg-message "declared here" } */
77 sink (a);
78 void *p = memmove (a + i, a, n);
79 sink (p);
80 return p; /* { dg-warning "\\\[-Wreturn-local-addr]" } */
83 char* return_stpcpy (unsigned n, const char *s)
85 char a[n]; /* { dg-message "declared here" } */
86 char *p = stpcpy (a, s);
87 sink (p);
88 return p; /* { dg-warning "\\\[-Wreturn-local-addr]" } */
91 char* return_stpncpy (unsigned n, const char *s)
93 char a[n]; /* { dg-message "declared here" } */
94 char *p = stpncpy (a, s, n);
95 sink (p);
96 return p; /* { dg-warning "\\\[-Wreturn-local-addr]" } */
99 char* return_strcat (unsigned n, const char *s)
101 char a[n]; /* { dg-message "declared here" } */
102 sink (a);
103 char *p = strcat (a, s);
104 sink (p);
105 return p; /* { dg-warning "\\\[-Wreturn-local-addr]" } */
108 char* return_strncat (unsigned n, const char *s)
110 char a[n]; /* { dg-message "declared here" } */
111 sink (a);
112 char *p = strncat (a, s, n);
113 sink (p);
114 return p; /* { dg-warning "\\\[-Wreturn-local-addr]" } */
117 char* return_strcpy (unsigned n, const char *s)
119 char a[n]; /* { dg-message "declared here" } */
120 char *p = strcpy (a, s);
121 sink (p);
122 return p; /* { dg-warning "\\\[-Wreturn-local-addr]" } */
125 char* return_strcpy_plus_strlen (unsigned n, const char *s)
127 char a[n]; /* { dg-message "declared here" } */
128 char *p = strcpy (a, s);
129 sink (p);
130 p += strlen (p);
131 return p; /* { dg-warning "\\\[-Wreturn-local-addr]" } */
134 char* return_strcpy_cst_plus_strlen (unsigned n, const char *s)
136 char a[n]; /* { dg-message "declared here" } */
137 sink (a);
138 char *p = strcpy (a + 1, s);
139 sink (p);
140 p += strlen (p);
141 return p; /* { dg-warning "\\\[-Wreturn-local-addr]" } */
144 char* return_strcpy_var_plus_strlen (unsigned n, const char *s, int i)
146 char a[n]; /* { dg-message "declared here" } */
147 sink (a);
148 char *p = strcpy (a + i, s);
149 sink (p);
150 p += strlen (p);
151 return p; /* { dg-warning "\\\[-Wreturn-local-addr]" } */
154 char* return_strncpy (unsigned n, const char *s)
156 char a[n]; /* { dg-message "declared here" } */
157 char *p = strncpy (a, s, n);
158 sink (p);
159 return p; /* { dg-warning "\\\[-Wreturn-local-addr]" } */
162 char* return_strncpy_plus_strnlen (unsigned n, const char *s)
164 char a[n]; /* { dg-message "declared here" } */
165 char *p = strncpy (a, s, n);
166 p += strnlen (p, n);
167 sink (p);
168 return p; /* { dg-warning "\\\[-Wreturn-local-addr]" } */
171 char* return_strdup (unsigned n)
173 char a[n];
174 sink (a);
175 char *p = strdup (a);
176 return p;
179 char* return_strchr (unsigned n, int c)
181 char a[n]; /* { dg-message "declared here" } */
182 sink (a);
183 char *p = strchr (a, c);
184 return p; /* { dg-warning "\\\[-Wreturn-local-addr]" } */
187 char* return_strstr (unsigned n, const char *s)
189 char a[n]; /* { dg-message "declared here" } */
190 sink (a);
191 char *p = strstr (a, s);
192 if (p)
193 p += strlen (p);
194 return p; /* { dg-warning "\\\[-Wreturn-local-addr]" } */
197 char* return_strrchr (unsigned n, int c)
199 char a[n]; /* { dg-message "declared here" } */
200 sink (a);
201 char *p = strrchr (a, c);
202 return p; /* { dg-warning "\\\[-Wreturn-local-addr]" } */