annotate gcc/testsuite/gcc.dg/strlenopt-50.c @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
131
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
1 /* PR tree-optimization/86415 - strlen() not folded for substrings
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
2 within constant arrays
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
3 { dg-do compile }
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
4 { dg-options "-O2 -Wall -fdump-tree-gimple -fdump-tree-ccp" } */
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
5
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
6 #include "strlenopt.h"
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
7
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
8 #define CONCAT(x, y) x ## y
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
9 #define CAT(x, y) CONCAT (x, y)
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
10 #define FAILNAME(name) CAT (call_ ## name ##_on_line_, __LINE__)
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
11
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
12 #define FAIL(name) do { \
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
13 extern void FAILNAME (name) (void); \
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
14 FAILNAME (name)(); \
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
15 } while (0)
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
16
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
17 /* Macro to emit a call to funcation named
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
18 call_in_true_branch_not_eliminated_on_line_NNN()
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
19 for each call that's expected to be eliminated. The dg-final
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
20 scan-tree-dump-time directive at the bottom of the test verifies
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
21 that no such call appears in output. */
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
22 #define ELIM(expr) \
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
23 if (!(expr)) FAIL (in_true_branch_not_eliminated); else (void)0
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
24
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
25 #define T(s, n) ELIM (strlen (s) == n)
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
26
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
27 /* 11111
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
28 0 1 23 4 567 8 901234 */
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
29 #define STR "1\00012\000123\0001234\0"
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
30
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
31 const char a[] = STR;
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
32 const char b[20] = STR;
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
33
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
34 void test_literal (void)
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
35 {
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
36 /* Verify that strlen() of substrings within a string literal are
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
37 correctly folded. */
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
38 T (STR, 1); T (STR + 1, 0); T (STR + 2, 2); T (STR + 3, 1);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
39 T (STR + 4, 0); T (STR + 5, 3); T (STR + 6, 2); T (STR + 7, 1);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
40 T (STR + 8, 0); T (STR + 9, 4); T (STR + 10, 3); T (STR + 11, 2);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
41 T (STR + 12, 1); T (STR + 13, 0); T (STR + 14, 0);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
42
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
43 T (&(STR[0]), 1); T (&(STR[ 1]), 0); T (&(STR[ 2]), 2);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
44 T (&(STR[ 3]), 1); T (&(STR[ 4]), 0); T (&(STR[ 5]), 3);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
45 T (&(STR[ 6]), 2); T (&(STR[ 7]), 1); T (&(STR[ 8]), 0);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
46 T (&(STR[ 9]), 4); T (&(STR[10]), 3); T (&(STR[11]), 2);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
47 T (&(STR[12]), 1); T (&(STR[13]), 0); T (&(STR[14]), 0);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
48
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
49 T (&(STR[0]) + 1, 0); T (&(STR[ 1]) + 1, 2); T (&(STR[ 2]) + 1, 1);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
50 T (&(STR[ 3]) + 1, 0); T (&(STR[ 4]) + 1, 3); T (&(STR[ 5]) + 1, 2);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
51 T (&(STR[ 6]) + 1, 1); T (&(STR[ 7]) + 1, 0); T (&(STR[ 8]) + 1, 4);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
52 T (&(STR[ 9]) + 1, 3); T (&(STR[10]) + 1, 2); T (&(STR[11]) + 1, 1);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
53 T (&(STR[12]) + 1, 0); T (&(STR[13]) + 1, 0); T (&(STR[13]) - 13, 1);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
54 T (&(STR[13]) - 12, 0); T (&(STR[13]) - 11, 2); T (&(STR[13]) - 10, 1);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
55 }
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
56
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
57 void test_array (void)
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
58 {
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
59 /* Verify that strlen() of substrings within a fully initialized
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
60 array are correctly folded. */
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
61 T (a, 1); T (a + 1, 0); T (a + 2, 2); T (a + 3, 1);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
62 T (a + 4, 0); T (a + 5, 3); T (a + 6, 2); T (a + 7, 1);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
63 T (a + 8, 0); T (a + 9, 4); T (a + 10, 3); T (a + 11, 2);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
64 T (a + 12, 1); T (a + 13, 0); T (a + 14, 0);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
65
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
66 /* Verify that strlen() of substrings within a partially initialized
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
67 array are also correctly folded, including those referring to
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
68 the empty substrings in the implicitly initialized elements. */
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
69 T (b, 1); T (b + 1, 0); T (b + 2, 2); T (b + 3, 1);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
70 T (b + 4, 0); T (b + 5, 3); T (b + 6, 2); T (b + 7, 1);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
71 T (b + 8, 0); T (b + 9, 4); T (b + 10, 3); T (b + 11, 2);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
72 T (b + 12, 1); T (b + 13, 0); T (b + 14, 0); T (b + 15, 0);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
73 T (b + 16, 0); T (b + 17, 0); T (b + 18, 0); T (b + 19, 0);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
74 }
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
75
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
76 void test_array_ref_plus (void)
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
77 {
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
78 /* Verify that strlen() of substrings within a fully initialized
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
79 array referred to by array indices with offsets are correctly
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
80 folded. */
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
81 T (&a[ 0], 1); T (&a[ 0] + 1, 0);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
82 T (&a[ 1], 0); T (&a[ 1] + 1, 2);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
83 T (&a[ 2], 2); T (&a[ 2] + 1, 1); T (&a[ 2] + 2, 0);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
84 T (&a[ 3], 1); T (&a[ 3] + 1, 0);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
85 T (&a[ 4], 0); T (&a[ 4] + 1, 3);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
86 T (&a[ 5], 3); T (&a[ 5] + 1, 2);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
87 T (&a[ 5] + 2, 1); T (&a[ 5] + 3, 0); T (&a[ 5] + 4, 4);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
88 T (&a[ 6], 2); T (&a[ 6] + 1, 1); T (&a[ 6] + 2, 0);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
89 T (&a[ 7], 1); T (&a[ 7] + 1, 0);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
90 T (&a[ 8], 0); T (&a[ 8] + 1, 4);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
91 T (&a[ 9], 4); T (&a[ 9] + 1, 3); T (&a[ 9] + 2, 2);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
92 T (&a[ 9] + 3, 1); T (&a[ 9] + 4, 0); T (&a[ 9] + 5, 0);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
93 T (&a[10], 3); T (&a[10] + 1, 2); T (&a[10] + 2, 1);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
94 T (&a[10] + 3, 0); T (&a[10] + 4, 0);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
95 T (&a[11], 2); T (&a[11] + 1, 1); T (&a[11] + 2, 0);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
96 T (&a[12], 1); T (&a[12] + 1, 0); T (&a[12] + 2, 0);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
97 T (&a[13], 0); T (&a[13] + 1, 0);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
98 T (&a[14], 0);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
99 }
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
100
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
101 void test_array_ref (void)
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
102 {
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
103 T (&a[ 0], 1); T (&a[ 1], 0); T (&a[ 2], 2); T (&a[ 3], 1);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
104 T (&a[ 4], 0); T (&a[ 5], 3); T (&a[ 6], 2); T (&a[ 7], 1);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
105 T (&a[ 8], 0); T (&a[ 9], 4); T (&a[10], 3); T (&a[11], 2);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
106 T (&a[12], 1); T (&a[13], 0); T (&a[14], 0);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
107
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
108 T (&b[ 0], 1); T (&b[ 1], 0); T (&b[ 2], 2); T (&b[ 3], 1);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
109 T (&b[ 4], 0); T (&b[ 5], 3); T (&b[ 6], 2); T (&b[ 7], 1);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
110 T (&b[ 8], 0); T (&b[ 9], 4); T (&b[10], 3); T (&b[11], 2);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
111 T (&b[12], 1); T (&b[13], 0); T (&b[14], 0); T (&b[15], 0);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
112 T (&b[16], 0); T (&b[17], 0); T (&b[18], 0); T (&b[19], 0);
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
113 }
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
114
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
115 /* { dg-final { scan-tree-dump-times "strlen" 0 "gimple" } }
84e7813d76e9 gcc-8.2
mir3636
parents:
diff changeset
116 { dg-final { scan-tree-dump-times "call_in_true_branch_not_eliminated" 0 "ccp1" } } */