1 /* PR tree-optimization/91294 - strlen result of a conditional with
4 { dg-options "-O2 -Wall" } */
8 #define NOIPA __attribute__ ((noclone, noinline, noipa))
12 const char s
[] = "1234567";
16 /* Exercise a memcpy overwriting a destination string of known length
17 with a source argument involving a conditional expression with strings
18 of unqual lengths, with the selected one being the longer of the two
19 and resulting in no change to the length of the overwritten destination
21 NOIPA
void test_memcpy_same_length ()
23 memcpy (a
, "123456789a", 11);
24 memcpy (a
+ 6, i
? "78\0" : "789\0", 4);
29 /* Same as above but with strcpy/strcat. */
31 NOIPA
void test_strcpy_strcat_same_length ()
33 strcpy (a
, "12345678");
35 memcpy (a
+ 6, i
? "78\0" : "789\0", 4);
40 /* Same as above but using a memcpy of a power-of-two size that gets
41 (on some targets) transformed into a single MEM_REF assignment. */
43 NOIPA
void test_assign_same_length ()
46 memcpy (a
+ 5, i
? "67\0" : "678\0", 4);
51 /* Same as above but resulting in increasing the length of the destination
54 NOIPA
void test_memcpy_lengthen ()
56 memcpy (a
, "123456789a", 11);
57 memcpy (a
+ 8, i
? "9a\0" : "9ab\0", 4);
62 NOIPA
void test_strcpy_strcat_lengthen ()
64 strcpy (a
, "12345678");
66 memcpy (a
+ 8, i
? "9a\0" : "9ab\0", 4);
71 NOIPA
void test_assign_lengthen ()
74 memcpy (a
+ 6, i
? "78\0" : "789\0", 4);
79 NOIPA
void test_memcpy_shorten ()
81 memcpy (a
, "123456789a", 11);
82 memcpy (a
+ 6, i
? "789\0" : "78\0", 4);
87 NOIPA
void test_strcpy_strcat_shorten ()
89 strcpy (a
, "12345678");
91 memcpy (a
+ 6, i
? "789\0" : "78\0", 4);
96 NOIPA
void test_assign_shorten ()
99 memcpy (a
+ 6, i
? "789\0" : "78\0", 4);
107 test_memcpy_same_length ();
108 test_strcpy_strcat_same_length ();
109 test_assign_same_length ();
111 test_memcpy_lengthen ();
112 test_strcpy_strcat_lengthen ();
113 test_assign_lengthen ();
115 test_memcpy_shorten ();
116 test_strcpy_strcat_shorten ();
117 test_assign_shorten ();