1 /* PR tree-optimization/78450 - strlen(s) return value can be assumed
2 to be less than the size of s
4 { dg-options "-O2 -fdump-tree-optimized" } */
8 extern char a7
[7], a6
[6], a5
[5], a4
[4], a3
[3], a2
[2], a1
[1];
9 extern char a0
[0]; /* Intentionally not tested here. */
10 extern char ax
[]; /* Same. */
13 char a7
[7], a6
[6], a5
[5], a4
[4], a3
[3], a2
[2], a1
[1];
14 char a0
[0]; /* Not tested here. */
17 struct NestedMemArrays
{
18 struct { char a7
[7]; } ma7
;
19 struct { char a6
[6]; } ma6
;
20 struct { char a5
[5]; } ma5
;
21 struct { char a4
[4]; } ma4
;
22 struct { char a3
[3]; } ma3
;
23 struct { char a2
[2]; } ma2
;
24 struct { char a1
[1]; } ma1
;
25 struct { char a0
[0]; } ma0
;
29 extern void failure_on_line (int);
31 #define TEST_FAIL(line) \
33 failure_on_line (line); \
37 if (!(expr)) TEST_FAIL (__LINE__); else (void)0
40 void test_array (void)
42 T (strlen (a7
) < sizeof a7
);
43 T (strlen (a6
) < sizeof a6
);
44 T (strlen (a5
) < sizeof a5
);
45 T (strlen (a4
) < sizeof a4
);
46 T (strlen (a3
) < sizeof a3
);
48 /* The following two calls are folded too early which defeats
49 the strlen() optimization.
51 T (strlen (a1) == 0); */
54 void test_memarray (struct MemArrays
*ma
)
56 T (strlen (ma
->a7
) < sizeof ma
->a7
);
57 T (strlen (ma
->a6
) < sizeof ma
->a6
);
58 T (strlen (ma
->a5
) < sizeof ma
->a5
);
59 T (strlen (ma
->a4
) < sizeof ma
->a4
);
60 T (strlen (ma
->a3
) < sizeof ma
->a3
);
62 /* The following two calls are folded too early which defeats
63 the strlen() optimization.
64 T (strlen (ma->a2) == 1);
65 T (strlen (ma->a1) == 0); */
68 /* Verify that the range of strlen(A) of a last struct member is
69 set even when the array is the sole member of a struct as long
70 as the struct itself is a member of another struct. The converse
71 is tested in stlenopt-37.c. */
72 void test_nested_memarray (struct NestedMemArrays
*ma
)
74 T (strlen (ma
->ma7
.a7
) < sizeof ma
->ma7
.a7
);
75 T (strlen (ma
->ma6
.a6
) < sizeof ma
->ma6
.a6
);
76 T (strlen (ma
->ma5
.a5
) < sizeof ma
->ma5
.a5
);
77 T (strlen (ma
->ma4
.a4
) < sizeof ma
->ma4
.a4
);
78 T (strlen (ma
->ma3
.a3
) < sizeof ma
->ma3
.a3
);
80 /* The following two calls are folded too early which defeats
81 the strlen() optimization.
82 T (strlen (ma->ma2.a2) == 1);
83 T (strlen (ma->ma1.a1) == 0); */
86 /* { dg-final { scan-tree-dump-not "failure_on_line" "optimized" } } */