Skip analyzer strndup test on hppa*-*-hpux*
[official-gcc.git] / gcc / testsuite / gcc.dg / Wdangling-pointer.c
blob89e222038dbc9c4f90e7bb0d4f0b71680e476bd5
1 /* Exercise basic C-only cases of -Wdangling-pointer.
2 { dg-do compile }
3 { dg-options "-O0 -Wall" }
4 { dg-require-effective-target alloca } */
6 typedef __SIZE_TYPE__ size_t;
8 extern void* memchr (const void*, int, size_t);
9 extern char* strchr (const char*, int);
11 void sink (const void*, ...);
14 void nowarn_compound_literal (int i)
17 int *p = (int[]){ 1, 2, 3 };
18 sink (p);
21 int *q = (int[]){ 1, 2, 3 };
22 int *p = &q[1];
23 sink (p);
26 int *p = __builtin_memchr ((int[]){ 1, 2, 3 }, 2, 3 * sizeof *p);
27 sink (p);
30 int *p = __builtin_memchr ((int[]){ i, i + 1 }, 3, 2 * sizeof *p);
31 sink (p);
36 void warn_compound_literal (int i)
38 int *p;
40 p = (int[]){ 1, 2, 3 }; // { dg-message "unnamed temporary" },
42 sink (p); // { dg-warning "using dangling pointer 'p' to an unnamed temporary" }
45 int *q =
46 (int[]){ 1, 2, 3 }; // { dg-message "unnamed temporary" },
47 p = &q[1];
49 sink (p); // { dg-warning "using dangling pointer 'p' to an unnamed temporary" }
51 p = (int*)memchr (
52 (int[]){ 1, 2, 3 }, // { dg-message "unnamed temporary" }
53 2, 3 * sizeof *p);
55 sink (p); // { dg-warning "using dangling pointer 'p' to an unnamed temporary" }
58 p = (int*)memchr (
59 (int[]){ i, i + 1 },// { dg-message "unnamed temporary" }
60 3, 2 * sizeof *p);
62 sink (p); // { dg-warning "using dangling pointer 'p' to an unnamed temporary" }
66 void warn_store_compound_literal (int **p)
68 int *q = (int[]) { 1, 2, 3 };
69 p[0] = q; // { dg-warning "storing the address" }
72 void warn_store_vla (int n, int **p)
74 int a[n];
75 p[1] = &a[1]; // { dg-warning "-Wdangling-pointer" "pr??????" { xfail *-*-* } }