]>
git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/gcc.dg/strlenopt-69.c
46ceb9ddb054dc5f891cc64afc0e34ff9c37a4b1
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]));
71 memset (a4
, 0, sizeof a4
);
72 memset (b4
, 0, sizeof b4
);
73 A (0 == strcmp (a4
, b4
));
76 /* Verify that comparison of dynamically created strings with unknown
79 void test_array_copy (void)
87 A (strcmp (a4
, s
)); clobber (a4
);
90 A (strcmp (a4
, s
)); clobber (a4
);
93 A (strcmp (s
, a4
)); clobber (a4
);
96 A (strcmp (s
, a4
)); clobber (a4
);
99 A (strcmp (s
, a4
)); clobber (a4
);
103 void test_array_bounded (void)
105 A (strncmp (a4
, "12345", 5)); clobber (a4
);
106 A (strncmp ("54321", a4
, 5)); clobber (a4
);
108 A (strncmp (a4
, "123456", 5)); clobber (a4
);
109 A (strncmp ("654321", a4
, 5)); clobber (a4
);
112 void test_array_copy_bounded (void)
116 A (strncmp (a4
, s
, 5)); clobber (a4
);
118 A (strncmp (s
, a4
, 5)); clobber (a4
);
120 strcpy (s
, "123456");
121 A (strncmp (a4
, s
, 5)); clobber (a4
);
122 strcpy (s
, "654321");
123 A (strncmp (s
, a4
, 5)); clobber (a4
);
126 /* { dg-final { scan-tree-dump-not "abort|strcmp|strncmp" "optimized" } } */