1 /* PR tree-optimization/90662 - strlen of a string in a vla plus offset
3 Verify that strlen of pointers to char arrays are computed correctly
4 (whether folded or not).
6 { dg-options "-O2 -Wall" } */
13 : (__builtin_printf ("assertion failed on line %i: %s\n", \
20 A5
* p
[5] = { &a5
[4], &a5
[3], &a5
[2], &a5
[1], &a5
[0] };
22 __attribute__ ((noclone
, noinline
, noipa
))
23 void deref_deref (void)
25 strcpy (**p
, "12345");
26 A (strlen (**p
) == 5);
29 __attribute__ ((noclone
, noinline
, noipa
))
30 void deref_idx_0 (void)
33 A (strlen (*p
[0]) == 0);
36 __attribute__ ((noclone
, noinline
, noipa
))
37 void deref_idx_1 (void)
40 A (strlen (*p
[1]) == 1);
41 A (strlen (&(*p
[1])[1]) == 0);
43 A (strlen (*p
[0]) == 0);
46 __attribute__ ((noclone
, noinline
, noipa
))
47 void deref_idx_2 (void)
50 A (strlen (*p
[2]) == 2);
51 A (strlen (&(*p
[2])[1]) == 1);
52 A (strlen (&(*p
[2])[2]) == 0);
54 A (strlen (*p
[1]) == 1);
55 A (strlen (*p
[0]) == 0);
58 __attribute__ ((noclone
, noinline
, noipa
))
59 void deref_idx_3 (void)
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);
67 A (strlen (*p
[2]) == 2);
68 A (strlen (*p
[1]) == 1);
69 A (strlen (*p
[0]) == 0);
72 __attribute__ ((noclone
, noinline
, noipa
))
73 void deref_idx_4 (void)
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);
82 A (strlen (*p
[3]) == 3);
83 A (strlen (*p
[2]) == 2);
84 A (strlen (*p
[1]) == 1);
85 A (strlen (*p
[0]) == 0);
88 __attribute__ ((noclone
, noinline
, noipa
))
89 void deref_idx_4_x (void)
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);
99 __attribute__ ((noclone
, noinline
, noipa
))
100 void deref_idx_3_x (void)
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);
110 __attribute__ ((noclone
, noinline
, noipa
))
111 void deref_idx_2_x (void)
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);
121 __attribute__ ((noclone
, noinline
, noipa
))
122 void deref_idx_1_x (void)
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);
132 __attribute__ ((noclone
, noinline
, noipa
))
133 void deref_idx_0_x (void)
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);