libcpp, c, middle-end: Optimize initializers using #embed in C
[official-gcc.git] / gcc / testsuite / gcc.dg / strcmpopt_10.c
blobd7f94ac4d528b32db9ab628f555252d0e4fbb820
1 /* Verify that strncmp equalities aren't eliminated when the trailing array
2 type referenced by a member pointer is smaller than the string in cases
3 when the pointer pointed to by the enclosing object references an object
4 sufficiently large to store a string of equal length.
5 { dg-do compile }
6 { dg-options "-O2 -Wall -Wextra -Wno-stringop-overread -fdump-tree-optimized" } */
8 void init (void*);
10 struct A1 { char i, a[1]; };
12 void f1_arr (void)
14 char a[9];
15 init (a);
17 struct A1 *p = (struct A1*)a;
19 if (__builtin_strncmp (p->a, "01234567", 8) == 0)
21 extern void array_test (void);
22 array_test ();
26 void f1_ptr (void)
28 void *p;
29 init (&p);
31 struct A1 *q = (struct A1*)p;
33 if (__builtin_strncmp (q->a, "0123456789", 10) == 0)
35 extern void pointer_test (void);
36 pointer_test ();
40 void f1_struct (void)
42 struct { char a[9]; } b;
43 init (&b);
45 struct A1 *p = (struct A1*)&b;
47 if (__builtin_strncmp (p->a, "01234567", 8) == 0)
49 extern void struct_test (void);
50 struct_test ();
54 void f1_memptr (void)
56 struct { void *p; } b;
57 init (&b);
59 struct A1 *p = (struct A1*)b.p;
61 if (__builtin_strncmp (p->a, "0123456789", 10) == 0)
63 extern void memptr_test (void);
64 memptr_test ();
69 struct A2 { char i, a[2]; };
71 void f2_arr (void)
73 char a[8];
74 init (a);
76 struct A2 *p = (struct A2*)a;
78 if (__builtin_strncmp (p->a, "0123456", 7) == 0)
80 extern void array_test (void);
81 array_test ();
85 void f2_ptr (void)
87 void *p;
88 init (&p);
90 struct A2 *q = (struct A2*)p;
92 if (__builtin_strncmp (q->a, "0123456789", 10) == 0)
94 extern void pointer_test (void);
95 pointer_test ();
99 void f2_struct (void)
101 struct { char a[8]; } b;
102 init (&b);
104 struct A2 *p = (struct A2*)&b;
106 if (__builtin_strncmp (p->a, "0123456", 7) == 0)
108 extern void struct_test (void);
109 struct_test ();
113 void f2_memptr (void)
115 struct { void *p; } b;
116 init (&b);
118 struct A2 *p = (struct A2*)b.p;
120 if (__builtin_strncmp (p->a, "0123456789", 10) == 0)
122 extern void memptr_test (void);
123 memptr_test ();
127 /* { dg-final { scan-tree-dump-times "array_test" 2 "optimized" } }
128 { dg-final { scan-tree-dump-times "pointer_test" 2 "optimized" } }
129 { dg-final { scan-tree-dump-times "struct_test" 2 "optimized" } }
130 { dg-final { scan-tree-dump-times "memptr_test" 2 "optimized" } } */