comparison gcc/testsuite/g++.dg/init/array51.C @ 145:1830386684a0

gcc-9.2.0
author anatofuz
date Thu, 13 Feb 2020 11:34:05 +0900
parents
children
comparison
equal deleted inserted replaced
131:84e7813d76e9 145:1830386684a0
1 // PR c++/89833
2 // Anal test to verify that arrays of null pointer to members are
3 // treated as null regardless of the form of their initialization,
4 // and have all bits set in their representation.
5 // { dg-do run { target c++11 } }
6 // { dg-options "-O2 -Wall" }
7
8 #define NOIPA __attribute__ ((noipa))
9
10 struct A { int i; };
11
12 typedef int A::*pam_t;
13
14 pam_t apam__[2] = { };
15 pam_t apam0_[2] = { 0 };
16 pam_t apam00[2] = { 0, 0 };
17
18 struct B { pam_t a[2]; };
19
20 NOIPA B f__ () { return B{ }; }
21 NOIPA B f0_ () { return B{ 0 }; }
22 NOIPA B f00 () { return B{ 0, 0 }; }
23
24 const B c__{ };
25 const B c0_{ 0 };
26 const B c00{ 0, 0 };
27
28 B b__{ };
29 B b0_{ 0 };
30 B b00{ 0, 0 };
31
32 #define assert(expr) \
33 (expr) ? (void)0 : __builtin_abort ()
34
35 signed char allones[2 * sizeof (pam_t)];
36
37 #define assert_rep(mp, n) \
38 assert (!test_allones (mp, n))
39
40 NOIPA void init_allones ()
41 {
42 __builtin_memset (allones, -1, sizeof allones);
43 }
44
45 NOIPA int test_allones (const pam_t *p, unsigned n)
46 {
47 return __builtin_memcmp (allones, p, sizeof *p * n);
48 }
49
50 int main ()
51 {
52 init_allones ();
53
54 assert (apam__[0] == nullptr && apam__[1] == nullptr);
55 assert (apam0_[0] == nullptr && apam0_[1] == nullptr);
56 assert (apam00[0] == nullptr && apam00[1] == nullptr);
57
58 assert (f__ ().a[0] == nullptr && f__ ().a[1] == nullptr);
59 assert (f0_ ().a[0] == nullptr && f0_ ().a[1] == nullptr);
60 assert (f00 ().a[0] == nullptr && f00 ().a[1] == nullptr);
61
62 assert (b__.a[0] == nullptr && b__.a[1] == nullptr);
63 assert (b0_.a[0] == nullptr && b0_.a[1] == nullptr);
64 assert (b00.a[0] == nullptr && b00.a[1] == nullptr);
65
66 assert (c__.a[0] == nullptr && c__.a[1] == nullptr);
67 assert (c0_.a[0] == nullptr && c0_.a[1] == nullptr);
68 assert (c00.a[0] == nullptr && c00.a[1] == nullptr);
69
70 assert_rep (apam__, 2);
71 assert_rep (apam0_, 2);
72 assert_rep (apam00, 2);
73
74 assert_rep (f__ ().a, 2);
75 assert_rep (f0_ ().a, 2);
76 assert_rep (f0_ ().a, 2);
77 assert_rep (f00 ().a, 2);
78
79 assert_rep (b__.a, 2);
80 assert_rep (b0_.a, 2);
81 assert_rep (b00.a, 2);
82
83 assert_rep (c__.a, 2);
84 assert_rep (c0_.a, 2);
85 assert_rep (c00.a, 2);
86 }