Require target lra in gcc.dg/pr108095.c
[official-gcc.git] / gcc / testsuite / gcc.dg / strlenopt-53.c
blob489c22b69372cd5695f8552715a296a274f4cf2e
1 /* PR tree-optimization/86415 - strlen() not folded for substrings
2 within constant arrays
3 { dg-do compile }
4 { dg-options "-O2 -Wall -fdump-tree-gimple -fdump-tree-ccp" } */
6 #include "strlenopt.h"
8 #define CONCAT(x, y) x ## y
9 #define CAT(x, y) CONCAT (x, y)
10 #define FAILNAME(name) CAT (call_ ## name ##_on_line_, __LINE__)
12 #define FAIL(name) do { \
13 extern void FAILNAME (name) (void); \
14 FAILNAME (name)(); \
15 } while (0)
17 /* Macro to emit a call to funcation 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 ELIM(expr) \
23 if (!(expr)) FAIL (in_true_branch_not_eliminated); else (void)0
25 #define T(s, n) ELIM (strlen (s) == n)
27 /* 11111
28 0 1 23 4 567 8 901234 */
29 #define STR "1\00012\000123\0001234\0"
31 const char a[] = STR;
32 const char b[20] = STR;
34 void test_literal (void)
36 /* Verify that strlen() of substrings within a string literal are
37 correctly folded. */
38 T (STR, 1); T (STR + 1, 0); T (STR + 2, 2); T (STR + 3, 1);
39 T (STR + 4, 0); T (STR + 5, 3); T (STR + 6, 2); T (STR + 7, 1);
40 T (STR + 8, 0); T (STR + 9, 4); T (STR + 10, 3); T (STR + 11, 2);
41 T (STR + 12, 1); T (STR + 13, 0); T (STR + 14, 0);
43 T (&(STR[0]), 1); T (&(STR[ 1]), 0); T (&(STR[ 2]), 2);
44 T (&(STR[ 3]), 1); T (&(STR[ 4]), 0); T (&(STR[ 5]), 3);
45 T (&(STR[ 6]), 2); T (&(STR[ 7]), 1); T (&(STR[ 8]), 0);
46 T (&(STR[ 9]), 4); T (&(STR[10]), 3); T (&(STR[11]), 2);
47 T (&(STR[12]), 1); T (&(STR[13]), 0); T (&(STR[14]), 0);
49 T (&(STR[0]) + 1, 0); T (&(STR[ 1]) + 1, 2); T (&(STR[ 2]) + 1, 1);
50 T (&(STR[ 3]) + 1, 0); T (&(STR[ 4]) + 1, 3); T (&(STR[ 5]) + 1, 2);
51 T (&(STR[ 6]) + 1, 1); T (&(STR[ 7]) + 1, 0); T (&(STR[ 8]) + 1, 4);
52 T (&(STR[ 9]) + 1, 3); T (&(STR[10]) + 1, 2); T (&(STR[11]) + 1, 1);
53 T (&(STR[12]) + 1, 0); T (&(STR[13]) + 1, 0); T (&(STR[13]) - 13, 1);
54 T (&(STR[13]) - 12, 0); T (&(STR[13]) - 11, 2); T (&(STR[13]) - 10, 1);
57 void test_array (void)
59 /* Verify that strlen() of substrings within a fully initialized
60 array are correctly folded. */
61 T (a, 1); T (a + 1, 0); T (a + 2, 2); T (a + 3, 1);
62 T (a + 4, 0); T (a + 5, 3); T (a + 6, 2); T (a + 7, 1);
63 T (a + 8, 0); T (a + 9, 4); T (a + 10, 3); T (a + 11, 2);
64 T (a + 12, 1); T (a + 13, 0); T (a + 14, 0);
66 /* Verify that strlen() of substrings within a partially initialized
67 array are also correctly folded, including those referring to
68 the empty substrings in the implicitly initialized elements. */
69 T (b, 1); T (b + 1, 0); T (b + 2, 2); T (b + 3, 1);
70 T (b + 4, 0); T (b + 5, 3); T (b + 6, 2); T (b + 7, 1);
71 T (b + 8, 0); T (b + 9, 4); T (b + 10, 3); T (b + 11, 2);
72 T (b + 12, 1); T (b + 13, 0); T (b + 14, 0); T (b + 15, 0);
73 T (b + 16, 0); T (b + 17, 0); T (b + 18, 0); T (b + 19, 0);
76 void test_array_ref_plus (void)
78 /* Verify that strlen() of substrings within a fully initialized
79 array referred to by array indices with offsets are correctly
80 folded. */
81 T (&a[ 0], 1); T (&a[ 0] + 1, 0);
82 T (&a[ 1], 0); T (&a[ 1] + 1, 2);
83 T (&a[ 2], 2); T (&a[ 2] + 1, 1); T (&a[ 2] + 2, 0);
84 T (&a[ 3], 1); T (&a[ 3] + 1, 0);
85 T (&a[ 4], 0); T (&a[ 4] + 1, 3);
86 T (&a[ 5], 3); T (&a[ 5] + 1, 2);
87 T (&a[ 5] + 2, 1); T (&a[ 5] + 3, 0); T (&a[ 5] + 4, 4);
88 T (&a[ 6], 2); T (&a[ 6] + 1, 1); T (&a[ 6] + 2, 0);
89 T (&a[ 7], 1); T (&a[ 7] + 1, 0);
90 T (&a[ 8], 0); T (&a[ 8] + 1, 4);
91 T (&a[ 9], 4); T (&a[ 9] + 1, 3); T (&a[ 9] + 2, 2);
92 T (&a[ 9] + 3, 1); T (&a[ 9] + 4, 0); T (&a[ 9] + 5, 0);
93 T (&a[10], 3); T (&a[10] + 1, 2); T (&a[10] + 2, 1);
94 T (&a[10] + 3, 0); T (&a[10] + 4, 0);
95 T (&a[11], 2); T (&a[11] + 1, 1); T (&a[11] + 2, 0);
96 T (&a[12], 1); T (&a[12] + 1, 0); T (&a[12] + 2, 0);
97 T (&a[13], 0); T (&a[13] + 1, 0);
98 T (&a[14], 0);
101 void test_array_ref (void)
103 T (&a[ 0], 1); T (&a[ 1], 0); T (&a[ 2], 2); T (&a[ 3], 1);
104 T (&a[ 4], 0); T (&a[ 5], 3); T (&a[ 6], 2); T (&a[ 7], 1);
105 T (&a[ 8], 0); T (&a[ 9], 4); T (&a[10], 3); T (&a[11], 2);
106 T (&a[12], 1); T (&a[13], 0); T (&a[14], 0);
108 T (&b[ 0], 1); T (&b[ 1], 0); T (&b[ 2], 2); T (&b[ 3], 1);
109 T (&b[ 4], 0); T (&b[ 5], 3); T (&b[ 6], 2); T (&b[ 7], 1);
110 T (&b[ 8], 0); T (&b[ 9], 4); T (&b[10], 3); T (&b[11], 2);
111 T (&b[12], 1); T (&b[13], 0); T (&b[14], 0); T (&b[15], 0);
112 T (&b[16], 0); T (&b[17], 0); T (&b[18], 0); T (&b[19], 0);
115 /* { dg-final { scan-tree-dump-times "strlen1" 0 "gimple" } }
116 { dg-final { scan-tree-dump-times "call_in_true_branch_not_eliminated" 0 "ccp1" } } */