1 /* PR tree-optimization/86428 - strlen of const array initialized with
2 a string of the same length not folded
3 { dg-do compile }
4 { dg-options "-O0 -Wall -fdump-tree-gimple" } */
5
6 #include "strlenopt.h"
7
8 const char a1[1] = "\0";
9 const char a2[2] = "1\0";
10 const char a3[3] = "12\0";
11 const char a8[8] = "1234567\0";
12 const char a9[9] = "12345678\0";
13
14 const char ax[9] = "12345678\0\0\0\0"; /* { dg-warning "initializer-string for array of chars is too long" } */
15 const char ay[9] = "\00012345678\0\0\0\0"; /* { dg-warning "initializer-string for array of chars is too long" } */
16
17
len1(void)18 int len1 (void)
19 {
20 size_t len0 = strlen (a1);
21 return len0;
22 }
23
len(void)24 int len (void)
25 {
26 size_t len = strlen (a2) + strlen (a3) + strlen (a8) + strlen (a9);
27 return len;
28 }
29
lenx(void)30 int lenx (void)
31 {
32 size_t lenx = strlen (ax);
33 return lenx;
34 }
35
leny(void)36 int leny (void)
37 {
38 size_t leny = strlen (ay);
39 return leny;
40 }
41
cmp88(void)42 int cmp88 (void)
43 {
44 int cmp88 = memcmp (a8, "1234567\0", sizeof a8);
45 return cmp88;
46 }
47
48 /* { dg-final { scan-tree-dump-times "strlen" 0 "gimple" } }
49 { dg-final { scan-tree-dump-times "len0 = 0;" 1 "gimple" } }
50 { dg-final { scan-tree-dump-times "len = 18;" 1 "gimple" } }
51 { dg-final { scan-tree-dump-times "lenx = 8;" 1 "gimple" } }
52 { dg-final { scan-tree-dump-times "leny = 0;" 1 "gimple" } }
53 { dg-final { scan-tree-dump-times "cmp88 = 0;" 1 "gimple" } } */
54