1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313
|
/* PR middle-end/10138 - warn for uninitialized arrays passed as const*
arguments
{ dg-do compile }
{ dg-options "-O -Wall" }
{ dg-require-effective-target alloca } */
typedef __SIZE_TYPE__ size_t;
void* alloca (size_t);
void* malloc (size_t);
void* realloc (void*, size_t);
void fpi (int*);
void fpci (const int*);
void fpcv (const void*);
void nowarn_scalar_fpi (void)
{
int x;
fpi (&x);
}
void nowarn_scalar_plus_cst_fpi (void)
{
int x;
// This deserves a warning other than -Wuninitialized.
fpi (&x + 1);
}
void nowarn_scalar_plus_var_fpi (int i)
{
int x;
// Same as above, this deserves a warning other than -Wuninitialized.
fpi (&x + i);
}
void nowarn_array_assign_fpci (void)
{
int a[2];
a[0] = 0;
fpci (a);
}
void nowarn_array_assign_plus_cst_fpci (void)
{
int a[4];
a[1] = 0;
a[2] = 1;
fpci (a + 1);
}
void nowarn_array_init_fpci (void)
{
int a[4] = { 0 };
fpci (a);
}
void nowarn_array_compound_fpi (void)
{
fpi ((int[2]){ 1 });
}
void nowarn_array_compound_fpci (void)
{
fpci ((int[3]){ 1 });
}
void warn_array_fpci (void)
{
int a[4]; // { dg-message "declared here" }"
fpci (a); // { dg-warning "\\\[-Wmaybe-uninitialized" }
}
void warn_array_plus_cst_fpci (void)
{
int a[4];
fpci (a + 1); // { dg-warning "\\\[-Wmaybe-uninitialized" }
}
void warn_array_plus_var_fpci (int i)
{
int a[4];
fpci (a + i); // { dg-warning "\\\[-Wmaybe-uninitialized" }
}
void nowarn_array_end_fpci (void)
{
int a[4];
/* This should be diagnosed by a warning other than -Wuninitialized
because the just-past-the-end pointer cannot be dereferenced and
the function doesn't take any other pointer to tell where the start
of the array is. -Wuninitialized isn't appropriate because there
is nothing to initialize at that offset. */
fpci (a + 4);
}
void warn_matrix_fpcv (void)
{
int a[2][2];
fpci (a[1]); // { dg-warning "\\\[-Wmaybe-uninitialized" }
}
void warn_scalar_fpcv (void)
{
int i;
fpci (&i); // { dg-warning "\\\[-Wmaybe-uninitialized" }
}
void warn_scalar_plus_cst_fpcv (void)
{
int x;
/* Same as above, this deserves a warning other than -Wuninitialized
for passing the function a past-the-end pointer with no other
argument. */
fpci (&x + 1);
}
void warn_scalar_plus_var_fpcv (int i)
{
int x;
fpci (&x + i); // { dg-warning "\\\[-Wmaybe-uninitialized" }
}
void nowarn_struct_assign_fpci (void)
{
struct { int a, b; } s;
s.a = 0;
fpci (&s.a);
}
void warn_struct_assign_fpci (void)
{
struct { int a, b; } s;
s.a = 0;
fpci (&s.b); // { dg-warning "\\\[-Wmaybe-uninitialized" }
}
void nowarn_struct_init_fpci (void)
{
struct { int a, b; } s = { 0 };
fpci (&s.a);
fpci (&s.b);
}
void nowarn_struct_compound_fpci (void)
{
struct S { int a, b; };
fpci (&(struct S){ }.a);
fpci (&(struct S){ }.b);
}
/* Verify that passing a just-past-the-end pointer to a const pointer
argument to a function that takes another argument is not diagnosed
since the two arguments together could outline a range. */
void nowarn_fp_p (void)
{
extern void fpi_pci (int*, const int*);
{
int i;
fpi_pci (&i, &i + 1);
}
{
int j;
fpi_pci (&j + 1, &j + 1);
}
extern void fpc_pcc (char*, const char*);
{
char a[2];
fpc_pcc (a, a + 2);
}
{
char a[3];
fpc_pcc (a, a + 3);
}
extern void fpcc_pcc (const char*, const char*);
{
char a[4];
fpcc_pcc (a + 4, a + 4);
}
}
/* Verify passing addresses of empty uninitialized objects doesn't
trigger a warning. */
void nowarn_fpcEmpty (void)
{
struct Empty { };
extern void fpcEmpty (const struct Empty*);
/* Since Empty has no members warning for it isn't really necessary.
See also PR 38908. */
struct Empty s;
fpcEmpty (&s);
}
/* Verify passing addresses of uninitialized objects to functions
declared without a proptotype doesn't trigger a warning. */
void nowarn_noproto (void)
{
extern void fnoproto ();
int i, a[2];
fnoproto (&i, a, a + 2);
}
/* Verify passing addresses of uninitialized objects to variadic
functions doesn't trigger a warning. */
void nowarn_vararg (void)
{
extern void fvararg (int, ...);
int i, a[2];
fvararg (0, &i, a, a + 2);
}
void nowarn_alloca_assign_fpci (unsigned n)
{
int *p = (int*)alloca (n);
p[0] = 0;
fpci (p);
}
void nowarn_alloca_assign_plus_cst_fpci (unsigned n)
{
int *p = (int*)alloca (n);
p[1] = 0;
p[2] = 1;
fpci (p + 1);
}
void warn_alloca_fpci (unsigned n)
{
int *p = (int*)alloca (n);
fpci (p); // { dg-warning "\\\[-Wmaybe-uninitialized" }
}
void warn_alloca_assign_plus_cst_fpci (unsigned n)
{
int *p = (int*)alloca (n);
p[1] = 0;
p[2] = 1;
fpci (p + 3); // { dg-warning "\\\[-Wmaybe-uninitialized" }
}
void nowarn_vla_assign_fpci (unsigned n)
{
int a[n];
a[0] = 0;
fpci (a);
}
void nowarn_vla_assign_plus_cst_fpci (unsigned n)
{
int vla[n];
vla[1] = 0;
vla[2] = 1;
fpci (vla + 1);
}
void warn_vla_fpci (unsigned n)
{
int vla[n]; // { dg-message "declared here" "pr?????" { xfail *-*-* } }"
fpci (vla); // { dg-warning "\\\[-Wmaybe-uninitialized" }
}
void warn_vla_assign_plus_cst_fpci (unsigned n)
{
int vla[n]; // { dg-message "declared here" "pr?????" { xfail *-*-* } }"
vla[1] = 0;
vla[2] = 1;
fpci (vla + 3); // { dg-warning "\\\[-Wmaybe-uninitialized" }
}
void nowarn_malloc_assign_fpci (unsigned n)
{
int *p = (int*)malloc (n);
p[0] = 0;
fpci (p);
}
void nowarn_malloc_assign_plus_cst_fpci (unsigned n)
{
int *p = (int*)malloc (n);
p[1] = 0;
p[2] = 1;
fpci (p + 1);
}
void warn_malloc_fpci (unsigned n)
{
int *p = (int*)malloc (n);
fpci (p); // { dg-warning "\\\[-Wmaybe-uninitialized" }
}
void warn_malloc_assign_plus_cst_fpci (unsigned n)
{
int *p = (int*)malloc (n); // { dg-message "allocated here" "pr?????" { xfail *-*-* } }"
p[1] = 0;
p[2] = 1;
fpci (p + 3); // { dg-warning "\\\[-Wmaybe-uninitialized" }
}
|