Skip analyzer strndup test on hppa*-*-hpux*
[official-gcc.git] / gcc / testsuite / gcc.dg / strlenopt-63.c
blobf77db6bbe7ab4b3036d05a40b0b7c0c9854af0ab
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" } */
8 #include "strlenopt.h"
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 ()))
17 typedef char A5[5];
19 A5 a5[5];
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)
32 strcpy (*p[0], "");
33 A (strlen (*p[0]) == 0);
36 __attribute__ ((noclone, noinline, noipa))
37 void deref_idx_1 (void)
39 strcpy (*p[1], "1");
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)
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);
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)
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);
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);
143 int main (void)
145 deref_deref ();
147 deref_idx_0 ();
148 deref_idx_1 ();
149 deref_idx_2 ();
150 deref_idx_3 ();
151 deref_idx_4 ();
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 ();