1 /* PR tree-optimization/91294 - strlen result of a conditional with
4 { dg-options "-O2 -Wall" } */
8 #define NOIPA __attribute__ ((noclone, noinline, noipa))
10 #define assert(expr) \
13 : (__builtin_printf ("line %i %s: assertion failed: %s\n", \
14 __LINE__, __func__, #expr), \
19 const char s
[] = "1234567";
23 NOIPA
void lower_bound_assign_into_empty (void)
28 assert (strlen (a
) == 3);
31 NOIPA
void lower_bound_assign_into_longest (void)
36 assert (strlen (a
) == 31);
40 NOIPA
void lower_bound_assign_into_empty_idx_3 (int idx
)
46 assert (strlen (a
) == 4);
49 NOIPA
void lower_bound_assign_into_longest_idx_2 (int idx
)
55 assert (strlen (a
) == 2);
59 NOIPA
void lower_bound_memcpy_into_empty (void)
62 assert (strlen (a
) == 3);
65 NOIPA
void lower_bound_memcpy_into_longest (void)
68 assert (strlen (a
) == 31);
72 NOIPA
void lower_bound_memcpy_memcpy_into_empty (void)
75 memcpy (a
+ 2, "345", 3);
76 assert (strlen (a
) == 5);
79 NOIPA
void lower_bound_memcpy_memcpy_into_longest (void)
82 memcpy (a
+ 2, "345", 3);
83 assert (strlen (a
) == 31);
87 NOIPA
void memove_forward_strlen (void)
91 memmove (a
, a
+ 1, sizeof a
- 1);
93 assert (strlen (a
) == 5);
96 NOIPA
void memove_backward_into_empty_strlen (void)
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 */
122 memmove (b
, a
, sizeof a
);
124 assert (strlen (a
) == 6);
125 assert (strlen (b
) == 6);
126 assert (strcmp (a
, b
) == 0);
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 ();