1 /* PR tree-optimization/91315 - missing strlen lower bound of a string
2 known to be at least N characters
4 { dg-options "-O2 -Wall -fdump-tree-optimized" } */
8 #define CAT(x, y) x ## y
9 #define CONCAT(x, y) CAT (x, y)
10 #define FAILNAME(name) CONCAT (call_ ## name ##_on_line_, __LINE__)
12 #define FAIL(name) do { \
13 extern void FAILNAME (name) (void); \
17 /* Macro to emit a call to function named
18 call_in_true_branch_not_eliminated_on_line_NNN()
19 for each call that's expected to be eliminated. The dg-final
20 scan-tree-dump-time directive at the bottom of the test verifies
21 that no such call appears in output. */
22 #define ASSERT_ELIM(expr) \
23 if (!!(expr)) FAIL (in_true_branch_not_eliminated); else (void)0
27 void lower_bound_assign_1 (void)
30 ASSERT_ELIM (strlen (a
) < 1);
33 void lower_bound_assign_2 (void)
37 ASSERT_ELIM (strlen (a
) < 2);
40 void lower_bound_assign_3 (void)
45 ASSERT_ELIM (strlen (a
) < 3);
48 void lower_bound_memcpy (void)
51 ASSERT_ELIM (strlen (a
) < 3);
54 void lower_bound_memcpy_memcpy_2 (void)
57 memcpy (a
+ 2, "345", 3);
58 ASSERT_ELIM (strlen (a
) < 5);
61 void lower_bound_memcpy_memcpy_3 (void)
64 memcpy (a
+ 3, "456", 3);
65 ASSERT_ELIM (strlen (a
) < 6);
68 /* FIXME: Not optimized yet.
69 void lower_bound_stpcpy_stpcpy_assign (void)
71 *stpcpy (strcpy (a, "123"), "4567") = '8';
72 ASSERT_ELIM (strlen (a) < 8);
76 void lower_bound_strcpy_strcat_assign (void)
81 ASSERT_ELIM (strlen (a
) < 6);
84 /* { dg-final { scan-tree-dump-times "call_in_true_branch_not_eliminated_" 0 "optimized" } } */