1 /* PR tree-optimization/83444
2 { dg-do compile { target i?86-*-* x86_64-*-* } }
3 { dg-options "-O2 -fdump-tree-optimized" } */
4
5 #include "strlenopt.h"
6
7 #define STR "1234567"
8
9 const char str[] = STR;
10
11 char dst[10];
12
13 void copy_from_global_str (void)
14 {
15 strcpy (dst, str);
16
17 if (strlen (dst) != sizeof str - 1)
18 abort ();
19 }
20
21 void copy_from_local_str (void)
22 {
23 const char s[] = STR;
24
25 strcpy (dst, s);
26
27 if (strlen (dst) != sizeof s - 1)
28 abort ();
29 }
30
31 void copy_from_local_memstr (void)
32 {
33 struct {
34 char s[sizeof STR];
35 } x = { STR };
36
37 strcpy (dst, x.s);
38
39 if (strlen (dst) != sizeof x.s - 1)
40 abort ();
41 }
42
43 void copy_to_local_str (void)
44 {
45 char d[sizeof STR];
46
47 strcpy (d, str);
48
49 if (strlen (d) != sizeof str - 1)
50 abort ();
51 }
52
53 void copy_to_local_memstr (void)
54 {
55 struct {
56 char d[sizeof STR];
57 } x;
58
59 strcpy (x.d, str);
60
61 if (strlen (x.d) != sizeof str- 1)
62 abort ();
63 }
64
65 /* Verify that all calls to strlen have been eliminated.
66 { dg-final { scan-tree-dump-not "(abort|strlen) \\(\\)" "optimized" } } */