Debian Codegraph @

gcc/testsuite/g++.dg/torture/builtin-clear-padding-2.C

raw
1 /* PR libstdc++/88101 */
2 /* { dg-do run } */
3
4 #include <new>
5
6 struct S { char a; short b; char c; long long d; char e; decltype (nullptr) f; char g; };
7 alignas (S) unsigned char buf1[sizeof (S)];
8 alignas (S) unsigned char buf2[sizeof (S)];
9
10 template <int N>
11 void
12 foo ()
13 {
14 __builtin_clear_padding ((S *) buf2);
15 }
16
17 void
18 bar (S *s)
19 {
20 s->a = -1; s->b = -1; s->c = -1; s->d = -1; s->e = -1; s->g = -1;
21 }
22
23 int
24 main ()
25 {
26 S *s1 = new (buf1) S;
27 S *s2 = new (buf2) S;
28 __builtin_memset (s1, 0, sizeof (S));
29 __builtin_memset (s2, ~0, sizeof (S));
30 bar (s1);
31 bar (s2);
32 foo <0> ();
33 if (__builtin_memcmp (s1, s2, sizeof (S)) != 0)
34 __builtin_abort ();
35 }