Skip analyzer strndup test on hppa*-*-hpux*
[official-gcc.git] / gcc / testsuite / gcc.dg / strlenopt-76.c
blob30ccd166a1153b1917949ed5f9935015b315eab2
1 /* PR tree-optimization/91294 - strlen result of a conditional with
2 an offset
3 { dg-do run }
4 { dg-options "-O2 -Wall" } */
6 #include "strlenopt.h"
8 #define NOIPA __attribute__ ((noclone, noinline, noipa))
10 #define assert(expr) \
11 ((expr) \
12 ? (void)0 \
13 : (__builtin_printf ("line %i %s: assertion failed: %s\n", \
14 __LINE__, __func__, #expr), \
15 __builtin_abort ()))
17 int i = 0;
19 const char s[] = "1234567";
21 char a[32];
23 NOIPA void lower_bound_assign_into_empty (void)
25 a[0] = '1';
26 a[1] = '2';
27 a[2] = '3';
28 assert (strlen (a) == 3);
31 NOIPA void lower_bound_assign_into_longest (void)
33 a[0] = '1';
34 a[1] = '2';
35 a[2] = '3';
36 assert (strlen (a) == 31);
40 NOIPA void lower_bound_assign_into_empty_idx_3 (int idx)
42 a[0] = '1';
43 a[1] = '2';
44 a[2] = '3';
45 a[idx] = 'x';
46 assert (strlen (a) == 4);
49 NOIPA void lower_bound_assign_into_longest_idx_2 (int idx)
51 a[0] = '1';
52 a[1] = '2';
53 a[2] = '3';
54 a[idx] = '\0';
55 assert (strlen (a) == 2);
59 NOIPA void lower_bound_memcpy_into_empty (void)
61 memcpy (a, "123", 3);
62 assert (strlen (a) == 3);
65 NOIPA void lower_bound_memcpy_into_longest (void)
67 memcpy (a, "123", 3);
68 assert (strlen (a) == 31);
72 NOIPA void lower_bound_memcpy_memcpy_into_empty (void)
74 memcpy (a, "123", 3);
75 memcpy (a + 2, "345", 3);
76 assert (strlen (a) == 5);
79 NOIPA void lower_bound_memcpy_memcpy_into_longest (void)
81 memcpy (a, "123", 3);
82 memcpy (a + 2, "345", 3);
83 assert (strlen (a) == 31);
87 NOIPA void memove_forward_strlen (void)
89 char a[] = "123456";
91 memmove (a, a + 1, sizeof a - 1);
93 assert (strlen (a) == 5);
96 NOIPA void memove_backward_into_empty_strlen (void)
98 strcpy (a, "123456");
100 memmove (a + 1, a, 6);
102 assert (strlen (a) == 7);
105 NOIPA void memove_backward_into_longest_strlen (void)
107 memcpy (a, "123456", 6);
109 memmove (a + 1, a, 6);
111 assert (strlen (a) == 31);
114 NOIPA void memove_strcmp (void)
116 /* Test derived from libstdc++-v3's
117 20_util/specialized_algorithms/memory_management_tools/1.cc */
119 char a[] = "123456";
120 char b[] = "000000";
122 memmove (b, a, sizeof a);
124 assert (strlen (a) == 6);
125 assert (strlen (b) == 6);
126 assert (strcmp (a, b) == 0);
130 int main (void)
132 memset (a, '\0', sizeof a);
133 lower_bound_assign_into_empty ();
135 memset (a, 'x', sizeof a - 1);
136 a[sizeof a - 1] = '\0';
137 lower_bound_assign_into_longest ();
139 memset (a, '\0', sizeof a);
140 lower_bound_assign_into_empty_idx_3 (3);
142 memset (a, 'x', sizeof a - 1);
143 a[sizeof a - 1] = '\0';
144 lower_bound_assign_into_longest_idx_2 (2);
146 memset (a, '\0', sizeof a);
147 lower_bound_memcpy_into_empty ();
149 memset (a, 'x', sizeof a - 1);
150 a[sizeof a - 1] = '\0';
151 lower_bound_memcpy_into_longest ();
153 memset (a, 'x', sizeof a - 1);
154 a[sizeof a - 1] = '\0';
155 lower_bound_memcpy_into_longest ();
157 memset (a, '\0', sizeof a);
158 lower_bound_memcpy_memcpy_into_empty ();
160 memset (a, 'x', sizeof a - 1);
161 a[sizeof a - 1] = '\0';
162 lower_bound_memcpy_memcpy_into_longest ();
164 memove_forward_strlen ();
166 memset (a, '\0', sizeof a);
167 memove_backward_into_empty_strlen ();
169 memset (a, 'x', sizeof a - 1);
170 a[sizeof a - 1] = '\0';
171 memove_backward_into_longest_strlen ();
173 memove_strcmp ();