Require target lra in gcc.dg/pr108095.c
[official-gcc.git] / gcc / testsuite / gcc.dg / strlenopt-91.c
bloba30556128edb7b696b1d9f04b4c652fa72b519a6
1 /* PR tree-optimization/92412 - excessive errno aliasing assumption defeats
2 optimization
3 { dg-do compile }
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) \
22 return; \
24 void *q = alloc; \
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) \
30 __builtin_abort (); \
32 sink (p, q); \
33 } while (0)
36 void alloca_test_local (unsigned n)
38 char loca[] = "123";
39 T (loca, alloca (n));
42 void alloca_test_extern_const (unsigned n)
44 T (exta, alloca (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)
56 char loca[] = "123";
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)
74 char loca[] = "123";
75 T (loca, malloc (n));
78 void malloc_test_extern_const (unsigned n)
80 T (exta, malloc (n));
83 void malloc_test_static (unsigned n)
85 T (stata, malloc (n));
89 #undef T
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) \
94 return; \
96 char vla[n]; \
97 char *q = vla; \
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 (); \
105 sink (p, vla); \
106 } while (0)
109 void vla_test_local (unsigned n)
111 char loca[] = "123";
112 T (loca, n);
115 void vla_test_extern_const (unsigned n)
117 T (exta, n);
120 void vla_test_static (unsigned n)
122 T (stata, n);
125 /* { dg-final { scan-tree-dump-not "abort" "optimized" } } */