Debian Codegraph @

gcc/testsuite/gcc.dg/strlenopt-83.c

raw
1 /* PR tree-optimization/83821 - local aggregate initialization defeats
2 strlen optimization
3 { dg-do compile }
4 { dg-options "-O2 -Wall -fdump-tree-optimized" } */
5
6 #include "strlenopt.h"
7 char *p_p2, *p_p5, *p_p9, *p_p14;
8
9 unsigned n0, n1, n2, n3, n4;
10
11
12 static inline __attribute__ ((always_inline)) void
13 elim_strlen_of_consecutive_strcpy (char *p)
14 {
15 p_p2 = p + 2;
16 __builtin_strcpy (p_p2, "12");
17
18 p_p5 = p_p2 + 3;
19 __builtin_strcpy (p_p5, "124");
20
21 p_p9 = p_p5 + 4;
22 __builtin_strcpy (p_p9, "1245");
23
24 p_p14 = p_p9 + 5;
25
26 n0 = __builtin_strlen (p);
27 n1 = __builtin_strlen (p_p2);
28 n2 = __builtin_strlen (p_p5);
29 n3 = __builtin_strlen (p_p9);
30
31 /* The following isn't handled yet:
32 n4 = __builtin_strlen (p_p14); */
33
34 if (n0 || n1 != 2 || n2 != 3 || n3 != 4)
35 __builtin_abort ();
36 }
37
38
39 void elim_strlen_of_consecutive_strcpy_in_alloca (unsigned n)
40 {
41 /* Only known sizes are handled so far. */
42 n = 14;
43
44 char *p = __builtin_alloca (n);
45
46 *p = '\0';
47
48 elim_strlen_of_consecutive_strcpy (p);
49 }
50
51
52 void elim_strlen_of_consecutive_strcpy_in_vla (unsigned n)
53 {
54 /* Only known sizes are handled so far. */
55 n = 14;
56
57 char vla[n];
58
59 *vla = '\0';
60
61 elim_strlen_of_consecutive_strcpy (vla);
62 }
63
64 void elim_strlen_of_consecutive_strcpy_in_malloc (unsigned n)
65 {
66 char *p = __builtin_malloc (n);
67
68 *p = '\0';
69
70 elim_strlen_of_consecutive_strcpy (p);
71 }
72
73
74 void elim_strlen_of_consecutive_strcpy_in_calloc (unsigned n)
75 {
76 char *p = __builtin_calloc (n, 1);
77
78 /* Do not store into *P to verify that strlen knows it's zero. */
79
80 elim_strlen_of_consecutive_strcpy (p);
81 }
82
83 /* { dg-final { scan-tree-dump-not "abort" "optimized" } } */