Debian Codegraph @

gcc/testsuite/g++.dg/tree-ssa/strlenopt-1.C

raw
1 /* PR tree-optimization/92765 - wrong code for strcmp of a union member
2 { dg-do run }
3 { dg-options "-O2 -Wall" } */
4
5 typedef __SIZE_TYPE__ size_t;
6
7 inline void* operator new (size_t, void *p)
8 {
9 return p;
10 }
11
12 struct A { char a2[2]; };
13 struct B { char a4[4]; };
14
15 __attribute__((noipa)) void
16 sink (void*) { }
17
18 __attribute__((noipa)) void
19 copy (char *d, const char *s)
20 {
21 while ((*d++ = *s++));
22 }
23
24 __attribute__((noipa)) void
25 store_and_compare (void *p)
26 {
27 A *a = new (p) A;
28 sink (a->a2);
29
30 B *b = new (p) B;
31 char *q = (char *) b->a4;
32 copy (q, "abc");
33
34 if (__builtin_strcmp (q, "abc"))
35 __builtin_abort ();
36 }
37
38 int main ()
39 {
40 char a [sizeof (A) > sizeof (B) ? sizeof (A) : sizeof (B)];
41 store_and_compare (a);
42 }