]>
git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/gcc.dg/strlenopt-69.c
1 /* PR tree-optimization/90879 - fold zero-equality of strcmp between
2 a longer string and a smaller array
4 { dg-options "-O2 -Wall -Wno-string-compare -fdump-tree-optimized -ftrack-macro-expansion=0" } */
11 : (__builtin_printf ("assertion failed on line %i: %s\n", \
15 void clobber (void*, ...);
17 struct S
{ char a4
[4], c
; };
22 /* Verify that comparison of string literals with arrays with unknown
23 content but size that prevents them from comparing equal is folded
26 void test_array_lit (void)
28 A (strcmp (a4
, "1234")); clobber (a4
);
29 A (strcmp (a4
, "12345")); clobber (a4
);
30 A (strcmp (a4
, "123456")); clobber (a4
);
31 A (strcmp ("1234", a4
)); clobber (a4
);
32 A (strcmp ("12345", a4
)); clobber (a4
);
33 A (strcmp ("123456", a4
)); clobber (a4
);
36 void test_memarray_lit (struct S
*p
)
38 A (strcmp (p
->a4
, "1234"));
39 A (strcmp (p
->a4
, "12345"));
40 A (strcmp (p
->a4
, "123456"));
42 A (strcmp ("1234", p
->a4
));
43 A (strcmp ("12345", p
->a4
));
44 A (strcmp ("123456", p
->a4
));
47 /* Verify that the equality of empty strings is folded. */
49 void test_empty_string (void)
51 A (0 == strcmp ("", ""));
54 A (0 == strcmp (a4
, ""));
55 A (0 == strcmp ("", a4
));
56 A (0 == strcmp (a4
, a4
));
59 A (0 == strcmp (a4
, s
));
63 A (0 == strcmp (a4
+ 1, b4
+ 1));
67 A (0 == strcmp (&a4
[2], &b4
[2]));
70 /* The following isn't handled yet due to PR 92155. */
73 memset (a4
, 0, sizeof a4
);
74 memset (b4
, 0, sizeof b4
);
75 A (0 == strcmp (a4
, b4
));
79 /* Verify that comparison of dynamically created strings with unknown
82 void test_array_copy (void)
90 A (strcmp (a4
, s
)); clobber (a4
);
93 A (strcmp (a4
, s
)); clobber (a4
);
96 A (strcmp (s
, a4
)); clobber (a4
);
99 A (strcmp (s
, a4
)); clobber (a4
);
101 strcpy (s
, "123456");
102 A (strcmp (s
, a4
)); clobber (a4
);
106 void test_array_bounded (void)
108 A (strncmp (a4
, "12345", 5)); clobber (a4
);
109 A (strncmp ("54321", a4
, 5)); clobber (a4
);
111 A (strncmp (a4
, "123456", 5)); clobber (a4
);
112 A (strncmp ("654321", a4
, 5)); clobber (a4
);
115 void test_array_copy_bounded (void)
119 A (strncmp (a4
, s
, 5)); clobber (a4
);
121 A (strncmp (s
, a4
, 5)); clobber (a4
);
123 strcpy (s
, "123456");
124 A (strncmp (a4
, s
, 5)); clobber (a4
);
125 strcpy (s
, "654321");
126 A (strncmp (s
, a4
, 5)); clobber (a4
);
129 /* { dg-final { scan-tree-dump-not "abort|strcmp|strncmp" "optimized" } } */