1 /* PR middle-end/10138 - warn for uninitialized arrays passed as const*
3 Verify that passing pointers to uninitialized objects to const
4 arguments to built-ins is diagnosed where expected.
6 { dg-options "-O -Wall -ftrivial-auto-var-init=zero" }
7 { dg-require-effective-target alloca } */
9 typedef __SIZE_TYPE__
size_t;
11 void* alloca (size_t);
12 void* malloc (size_t);
13 void* realloc (void*, size_t);
15 void* memcpy (void*, const void*, size_t);
16 char* strcpy (char*, const char*);
17 size_t strlen (const char*);
21 void nowarn_array_memcpy (void *d
, unsigned n
)
25 memcpy (d
, a
, n
/* Non-constant to avoid folding into MEM_REF. */);
28 void nowarn_array_plus_cst_memcpy (void *d
, unsigned n
)
35 void nowarn_array_plus_var_memcpy (void *d
, unsigned n
, int i
)
42 void nowarn_array_assign_memcpy (char *d
, unsigned n
)
49 void nowarn_array_init_memcpy (char *d
, unsigned n
)
55 void nowarn_array_compound_memcpy (void *d
, unsigned n
)
57 memcpy (d
, (int[2]){ 0 }, n
);
60 void nowarn_struct_assign_memcpy (void *d
, unsigned n
)
62 struct S
{ int a
, b
, c
, d
; } s
;
69 void nowarn_array_init_strcpy (char *d
[], unsigned n
)
84 void nowarn_array_assign_strcpy (char *d
[], unsigned n
)
98 void warn_array_plus_cst_strcpy (char *d
, unsigned n
)
106 strcpy (d
, a
+ 4); // { dg-warning "\\\[-Wuninitialized" }
107 strcpy (d
, a
+ 5); // { dg-warning "\\\[-Wuninitialized" }
108 strcpy (d
, a
+ 6); // { dg-warning "\\\[-Wuninitialized" }
109 strcpy (d
, a
+ 7); // { dg-warning "\\\[-Wuninitialized" }
112 void nowarn_array_plus_var_strcpy (char *d
, int i
)
124 size_t nowarn_array_assign_strlen (const char *s
)
141 size_t warn_array_plus_cst_strlen (const char *s
)
149 return strlen (a
+ 4); // { dg-warning "\\\[-Wuninitialized" }
152 size_t nowarn_array_plus_var_strlen (const char *s
, int i
)
160 return strlen (a
+ i
);
164 size_t nowarn_alloca_assign_strlen (int i
)
166 char *p
= (char*)alloca (8);
171 size_t nowarn_alloca_escape_strlen (int i
)
173 char *p
= (char*)alloca (8);
178 size_t warn_alloca_strlen (void)
180 char *p
= (char*)alloca (8);
181 return strlen (p
); // { dg-warning "\\\[-Wuninitialized" }
185 size_t nowarn_malloc_assign_strlen (int i
)
187 char *p
= (char*)malloc (8);
192 size_t nowarn_malloc_escape_strlen (int i
)
194 char *p
= (char*)malloc (8);
199 size_t warn_malloc_strlen (void)
201 char *p
= (char*)malloc (8);
202 return strlen (p
); // { dg-warning "\\\[-Wuninitialized" }
206 size_t nowarn_realloc_strlen (void *p
)
208 char *q
= (char*)realloc (p
, 8);
213 size_t nowarn_vla_assign_strlen (int n
, int i
)
220 size_t nowarn_vla_strcpy_strlen (int n
, const char *s
, int i
)
224 return strlen (vla
+ i
);
227 size_t nowarn_vla_escape_strlen (int n
, int i
)
234 size_t warn_vla_strlen (unsigned n
)
237 return strlen (vla
); // { dg-warning "\\\[-Wuninitialized" }