1 /* PR tree-optimization/92412 - excessive errno aliasing assumption defeats
4 { dg-options "-O2 -Wall -fdump-tree-optimized" }
5 { dg-require-effective-target alloca } */
7 typedef __SIZE_TYPE__
size_t;
9 extern void* alloca (size_t);
10 extern void* calloc (size_t, size_t);
11 extern void* malloc (size_t);
13 extern const char exta
[4];
14 static char stata
[] = "123";
16 void sink (const void*, ...);
18 #define T(ptr, alloc) do { \
19 const char *p = ptr; \
20 if (p[0] != '1' || p[1] != '2' || p[2] != '3' || p[3] != '\0' \
21 || __builtin_strlen (p) != 3) \
25 __builtin_strcpy (q, p); \
27 if (p[0] != '1' || p[1] != '2' || p[2] != '3' || p[3] != '\0' \
28 || __builtin_strlen (p) != 3 \
29 || __builtin_strlen (q) != 3) \
36 void alloca_test_local (unsigned n
)
42 void alloca_test_extern_const (unsigned n
)
47 void alloca_test_static (unsigned n
)
49 T (stata
, alloca (n
));
53 // Verify fix for PR tree-optimization/92412.
54 void calloc_test_local (unsigned m
, unsigned n
)
57 T (loca
, calloc (m
, n
));
60 void calloc_test_extern_const (unsigned m
, unsigned n
)
62 T (exta
, calloc (m
, n
));
65 void calloc_test_static (unsigned m
, unsigned n
)
67 T (stata
, calloc (m
, n
));
71 // Verify fix for PR tree-optimization/92412.
72 void malloc_test_local (unsigned n
)
78 void malloc_test_extern_const (unsigned n
)
83 void malloc_test_static (unsigned n
)
85 T (stata
, malloc (n
));
90 #define T(ptr, n) do { \
91 const char *p = ptr; \
92 if (p[0] != '1' || p[1] != '2' || p[2] != '3' || p[3] != '\0' \
93 || __builtin_strlen (p) != 3) \
98 __builtin_strcpy (q, p); \
100 if (p[0] != '1' || p[1] != '2' || p[2] != '3' || p[3] != '\0' \
101 || __builtin_strlen (p) != 3 \
102 || __builtin_strlen (q) != 3) \
103 __builtin_abort (); \
109 void vla_test_local (unsigned n
)
115 void vla_test_extern_const (unsigned n
)
120 void vla_test_static (unsigned n
)
125 /* { dg-final { scan-tree-dump-not "abort" "optimized" } } */