]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/testsuite/gcc.dg/strlenopt-63.c
Update copyright years.
[thirdparty/gcc.git] / gcc / testsuite / gcc.dg / strlenopt-63.c
CommitLineData
7802a8ec
MS
1/* PR tree-optimization/90662 - strlen of a string in a vla plus offset
2 not folded
3 Verify that strlen of pointers to char arrays are computed correctly
4 (whether folded or not).
5 { dg-do run }
6 { dg-options "-O2 -Wall" } */
7
8#include "strlenopt.h"
9
10#define A(expr) \
11 ((expr) \
12 ? (void)0 \
13 : (__builtin_printf ("assertion failed on line %i: %s\n", \
14 __LINE__, #expr), \
15 __builtin_abort ()))
16
17typedef char A5[5];
18
19A5 a5[5];
20A5* p[5] = { &a5[4], &a5[3], &a5[2], &a5[1], &a5[0] };
21
22__attribute__ ((noclone, noinline, noipa))
23void deref_deref (void)
24{
25 strcpy (**p, "12345");
26 A (strlen (**p) == 5);
27}
28
29__attribute__ ((noclone, noinline, noipa))
30void deref_idx_0 (void)
31{
32 strcpy (*p[0], "");
33 A (strlen (*p[0]) == 0);
34}
35
36__attribute__ ((noclone, noinline, noipa))
37void deref_idx_1 (void)
38{
39 strcpy (*p[1], "1");
40 A (strlen (*p[1]) == 1);
41 A (strlen (&(*p[1])[1]) == 0);
42
43 A (strlen (*p[0]) == 0);
44}
45
46__attribute__ ((noclone, noinline, noipa))
47void deref_idx_2 (void)
48{
49 strcpy (*p[2], "12");
50 A (strlen (*p[2]) == 2);
51 A (strlen (&(*p[2])[1]) == 1);
52 A (strlen (&(*p[2])[2]) == 0);
53
54 A (strlen (*p[1]) == 1);
55 A (strlen (*p[0]) == 0);
56}
57
58__attribute__ ((noclone, noinline, noipa))
59void deref_idx_3 (void)
60{
61 strcpy (*p[3], "123");
62 A (strlen (*p[3]) == 3);
63 A (strlen (&(*p[3])[1]) == 2);
64 A (strlen (&(*p[3])[2]) == 1);
65 A (strlen (&(*p[3])[3]) == 0);
66
67 A (strlen (*p[2]) == 2);
68 A (strlen (*p[1]) == 1);
69 A (strlen (*p[0]) == 0);
70}
71
72__attribute__ ((noclone, noinline, noipa))
73void deref_idx_4 (void)
74{
75 strcpy (*p[4], "1234");
76 A (strlen (*p[4]) == 4);
77 A (strlen (&(*p[4])[1]) == 3);
78 A (strlen (&(*p[4])[2]) == 2);
79 A (strlen (&(*p[4])[3]) == 1);
80 A (strlen (&(*p[4])[4]) == 0);
81
82 A (strlen (*p[3]) == 3);
83 A (strlen (*p[2]) == 2);
84 A (strlen (*p[1]) == 1);
85 A (strlen (*p[0]) == 0);
86}
87
88__attribute__ ((noclone, noinline, noipa))
89void deref_idx_4_x (void)
90{
91 strcpy (*p[4], "");
92 A (strlen (*p[4]) == 0);
93 A (strlen (*p[3]) == 3);
94 A (strlen (*p[2]) == 2);
95 A (strlen (*p[1]) == 1);
96 A (strlen (*p[0]) == 0);
97}
98
99__attribute__ ((noclone, noinline, noipa))
100void deref_idx_3_x (void)
101{
102 strcpy (&(*p[3])[0], "1");
103 A (strlen (*p[4]) == 0);
104 A (strlen (*p[3]) == 1);
105 A (strlen (*p[2]) == 2);
106 A (strlen (*p[1]) == 1);
107 A (strlen (*p[0]) == 0);
108}
109
110__attribute__ ((noclone, noinline, noipa))
111void deref_idx_2_x (void)
112{
113 strcpy (*p[2], "12");
114 A (strlen (*p[4]) == 0);
115 A (strlen (*p[3]) == 1);
116 A (strlen (*p[2]) == 2);
117 A (strlen (*p[1]) == 1);
118 A (strlen (*p[0]) == 0);
119}
120
121__attribute__ ((noclone, noinline, noipa))
122void deref_idx_1_x (void)
123{
124 strcpy (*p[1], "123");
125 A (strlen (*p[4]) == 0);
126 A (strlen (*p[3]) == 1);
127 A (strlen (*p[2]) == 2);
128 A (strlen (*p[1]) == 3);
129 A (strlen (*p[0]) == 0);
130}
131
132__attribute__ ((noclone, noinline, noipa))
133void deref_idx_0_x (void)
134{
135 strcpy (*p[0], "1234");
136 A (strlen (*p[4]) == 0);
137 A (strlen (*p[3]) == 1);
138 A (strlen (*p[2]) == 2);
139 A (strlen (*p[1]) == 3);
140 A (strlen (*p[0]) == 4);
141}
142
143int main (void)
144{
145 deref_deref ();
146
147 deref_idx_0 ();
148 deref_idx_1 ();
149 deref_idx_2 ();
150 deref_idx_3 ();
151 deref_idx_4 ();
152
153 deref_idx_4_x ();
154 deref_idx_3_x ();
155 deref_idx_2_x ();
156 deref_idx_1_x ();
157 deref_idx_0_x ();
158}