annotate libcxxabi/test/dynamic_cast.pass.cpp @ 221:79ff65ed7e25

LLVM12 Original
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 15 Jun 2021 19:15:29 +0900
parents 1d019706d866
children 5f17cb93ff66
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
150
anatofuz
parents:
diff changeset
1 //===------------------------- dynamic_cast.pass.cpp ----------------------===//
anatofuz
parents:
diff changeset
2 //
anatofuz
parents:
diff changeset
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
anatofuz
parents:
diff changeset
4 // See https://llvm.org/LICENSE.txt for license information.
anatofuz
parents:
diff changeset
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
anatofuz
parents:
diff changeset
6 //
anatofuz
parents:
diff changeset
7 //===----------------------------------------------------------------------===//
anatofuz
parents:
diff changeset
8
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
9 // XFAIL: gcc-7, gcc-8, gcc-9
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
10
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
11 // PR33425 and PR33487 are not fixed until the dylib shipped with macOS 10.15
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
12 // XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.14
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
13
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
14 // PR33439 isn't fixed until the dylib shipped with macOS 10.14
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
15 // XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.13
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
16 // XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.12
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
17 // XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.11
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
18 // XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.10
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
19 // XFAIL: use_system_cxx_lib && x86_64-apple-macosx10.9
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
20
150
anatofuz
parents:
diff changeset
21 #include <cassert>
anatofuz
parents:
diff changeset
22
anatofuz
parents:
diff changeset
23 // This test explicitly tests dynamic cast with types that have inaccessible
anatofuz
parents:
diff changeset
24 // bases.
anatofuz
parents:
diff changeset
25 #if defined(__clang__)
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
26 # pragma clang diagnostic ignored "-Winaccessible-base"
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
27 #elif defined(__GNUC__) && (__GNUC__ >= 10)
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
28 # pragma GCC diagnostic ignored "-Winaccessible-base"
150
anatofuz
parents:
diff changeset
29 #endif
anatofuz
parents:
diff changeset
30
anatofuz
parents:
diff changeset
31 typedef char Pad1[43981];
anatofuz
parents:
diff changeset
32 typedef char Pad2[34981];
anatofuz
parents:
diff changeset
33 typedef char Pad3[93481];
anatofuz
parents:
diff changeset
34 typedef char Pad4[13489];
anatofuz
parents:
diff changeset
35 typedef char Pad5[81349];
anatofuz
parents:
diff changeset
36 typedef char Pad6[34819];
anatofuz
parents:
diff changeset
37 typedef char Pad7[3489];
anatofuz
parents:
diff changeset
38
anatofuz
parents:
diff changeset
39 namespace t1
anatofuz
parents:
diff changeset
40 {
anatofuz
parents:
diff changeset
41
anatofuz
parents:
diff changeset
42 // PR33425
anatofuz
parents:
diff changeset
43 struct C3 { virtual ~C3() {} Pad1 _; };
anatofuz
parents:
diff changeset
44 struct C5 : protected virtual C3 { Pad2 _; };
anatofuz
parents:
diff changeset
45 struct C6 : virtual C5 { Pad3 _; };
anatofuz
parents:
diff changeset
46 struct C7 : virtual C3 { Pad4 _; };
anatofuz
parents:
diff changeset
47 struct C9 : C6, C7 { Pad5 _; };
anatofuz
parents:
diff changeset
48
anatofuz
parents:
diff changeset
49 C9 c9;
anatofuz
parents:
diff changeset
50 C3 *c3 = &c9;
anatofuz
parents:
diff changeset
51
anatofuz
parents:
diff changeset
52 void test()
anatofuz
parents:
diff changeset
53 {
anatofuz
parents:
diff changeset
54 assert(dynamic_cast<C3*>(c3) == static_cast<C3*>(&c9));
anatofuz
parents:
diff changeset
55 assert(dynamic_cast<C5*>(c3) == static_cast<C5*>(&c9));
anatofuz
parents:
diff changeset
56 assert(dynamic_cast<C6*>(c3) == static_cast<C6*>(&c9));
anatofuz
parents:
diff changeset
57 assert(dynamic_cast<C7*>(c3) == static_cast<C7*>(&c9));
anatofuz
parents:
diff changeset
58 assert(dynamic_cast<C9*>(c3) == static_cast<C9*>(&c9));
anatofuz
parents:
diff changeset
59 }
anatofuz
parents:
diff changeset
60
anatofuz
parents:
diff changeset
61 } // t1
anatofuz
parents:
diff changeset
62
anatofuz
parents:
diff changeset
63 namespace t2
anatofuz
parents:
diff changeset
64 {
anatofuz
parents:
diff changeset
65
anatofuz
parents:
diff changeset
66 // PR33425
anatofuz
parents:
diff changeset
67 struct Src { virtual ~Src() {} Pad1 _; };
anatofuz
parents:
diff changeset
68 struct Mask : protected virtual Src { Pad2 _; };
anatofuz
parents:
diff changeset
69 struct Dest : Mask { Pad3 _; };
anatofuz
parents:
diff changeset
70 struct Root : Dest, virtual Src { Pad4 _; };
anatofuz
parents:
diff changeset
71
anatofuz
parents:
diff changeset
72 Root root;
anatofuz
parents:
diff changeset
73 Src *src = &root;
anatofuz
parents:
diff changeset
74
anatofuz
parents:
diff changeset
75 void test()
anatofuz
parents:
diff changeset
76 {
anatofuz
parents:
diff changeset
77 assert(dynamic_cast<Src*>(src) == static_cast<Src*>(&root));
anatofuz
parents:
diff changeset
78 assert(dynamic_cast<Mask*>(src) == static_cast<Mask*>(&root));
anatofuz
parents:
diff changeset
79 assert(dynamic_cast<Dest*>(src) == static_cast<Dest*>(&root));
anatofuz
parents:
diff changeset
80 assert(dynamic_cast<Root*>(src) == static_cast<Root*>(&root));
anatofuz
parents:
diff changeset
81 }
anatofuz
parents:
diff changeset
82
anatofuz
parents:
diff changeset
83 } // t2
anatofuz
parents:
diff changeset
84
anatofuz
parents:
diff changeset
85 namespace t3
anatofuz
parents:
diff changeset
86 {
anatofuz
parents:
diff changeset
87
anatofuz
parents:
diff changeset
88 // PR33487
anatofuz
parents:
diff changeset
89 struct Class1 { virtual ~Class1() {} Pad1 _; };
anatofuz
parents:
diff changeset
90 struct Shared : virtual Class1 { Pad2 _; };
anatofuz
parents:
diff changeset
91 struct Class6 : virtual Shared { Pad3 _; };
anatofuz
parents:
diff changeset
92 struct Left : Class6 { Pad4 _; };
anatofuz
parents:
diff changeset
93 struct Right : Class6 { Pad5 _; };
anatofuz
parents:
diff changeset
94 struct Main : Left, Right { Pad6 _; };
anatofuz
parents:
diff changeset
95
anatofuz
parents:
diff changeset
96 Main m;
anatofuz
parents:
diff changeset
97 Class1 *c1 = &m;
anatofuz
parents:
diff changeset
98
anatofuz
parents:
diff changeset
99 void test()
anatofuz
parents:
diff changeset
100 {
anatofuz
parents:
diff changeset
101 assert(dynamic_cast<Class1*>(c1) == static_cast<Class1*>(&m));
anatofuz
parents:
diff changeset
102 assert(dynamic_cast<Shared*>(c1) == static_cast<Shared*>(&m));
anatofuz
parents:
diff changeset
103 assert(dynamic_cast<Class6*>(c1) == 0);
anatofuz
parents:
diff changeset
104 assert(dynamic_cast<Left*>(c1) == static_cast<Left*>(&m));
anatofuz
parents:
diff changeset
105 assert(dynamic_cast<Right*>(c1) == static_cast<Right*>(&m));
anatofuz
parents:
diff changeset
106 assert(dynamic_cast<Main*>(c1) == static_cast<Main*>(&m));
anatofuz
parents:
diff changeset
107 }
anatofuz
parents:
diff changeset
108
anatofuz
parents:
diff changeset
109 } // t3
anatofuz
parents:
diff changeset
110
anatofuz
parents:
diff changeset
111 namespace t4
anatofuz
parents:
diff changeset
112 {
anatofuz
parents:
diff changeset
113
anatofuz
parents:
diff changeset
114 // PR33439
anatofuz
parents:
diff changeset
115 struct C2 { virtual ~C2() {} Pad1 _; };
anatofuz
parents:
diff changeset
116 struct C3 { virtual ~C3() {} Pad2 _; };
anatofuz
parents:
diff changeset
117 struct C4 : C3 { Pad3 _; };
anatofuz
parents:
diff changeset
118 struct C8 : C2, virtual C4 { Pad4 _; };
anatofuz
parents:
diff changeset
119 struct C9 : C4, C8 { Pad5 _; };
anatofuz
parents:
diff changeset
120
anatofuz
parents:
diff changeset
121 C9 c9;
anatofuz
parents:
diff changeset
122 C2 *c2 = &c9;
anatofuz
parents:
diff changeset
123
anatofuz
parents:
diff changeset
124 void test()
anatofuz
parents:
diff changeset
125 {
anatofuz
parents:
diff changeset
126 assert(dynamic_cast<C2*>(c2) == static_cast<C2*>(&c9));
anatofuz
parents:
diff changeset
127 assert(dynamic_cast<C3*>(c2) == 0);
anatofuz
parents:
diff changeset
128 assert(dynamic_cast<C4*>(c2) == 0);
anatofuz
parents:
diff changeset
129 assert(dynamic_cast<C8*>(c2) == static_cast<C8*>(&c9));
anatofuz
parents:
diff changeset
130 assert(dynamic_cast<C9*>(c2) == static_cast<C9*>(&c9));
anatofuz
parents:
diff changeset
131 }
anatofuz
parents:
diff changeset
132
anatofuz
parents:
diff changeset
133 } // t4
anatofuz
parents:
diff changeset
134
anatofuz
parents:
diff changeset
135 namespace t5
anatofuz
parents:
diff changeset
136 {
anatofuz
parents:
diff changeset
137
anatofuz
parents:
diff changeset
138 // PR33439
anatofuz
parents:
diff changeset
139 struct Dummy { virtual ~Dummy() {} Pad1 _; };
anatofuz
parents:
diff changeset
140 struct Src { virtual ~Src() {} Pad2 _; };
anatofuz
parents:
diff changeset
141 struct Dest : Dummy { Pad3 _; };
anatofuz
parents:
diff changeset
142 struct A1 : Dest { Pad4 _; };
anatofuz
parents:
diff changeset
143 struct A2 : Dest { Pad5 _; };
anatofuz
parents:
diff changeset
144 struct Root : Src, A1, A2 { Pad6 _; };
anatofuz
parents:
diff changeset
145
anatofuz
parents:
diff changeset
146 Root root;
anatofuz
parents:
diff changeset
147 Src *src = &root;
anatofuz
parents:
diff changeset
148
anatofuz
parents:
diff changeset
149 void test()
anatofuz
parents:
diff changeset
150 {
anatofuz
parents:
diff changeset
151 assert(dynamic_cast<Dummy*>(src) == 0);
anatofuz
parents:
diff changeset
152 assert(dynamic_cast<Src*>(src) == static_cast<Src*>(&root));
anatofuz
parents:
diff changeset
153 assert(dynamic_cast<Dest*>(src) == 0);
anatofuz
parents:
diff changeset
154 assert(dynamic_cast<A1*>(src) == static_cast<A1*>(&root));
anatofuz
parents:
diff changeset
155 assert(dynamic_cast<A2*>(src) == static_cast<A2*>(&root));
anatofuz
parents:
diff changeset
156 }
anatofuz
parents:
diff changeset
157
anatofuz
parents:
diff changeset
158 } // t5
anatofuz
parents:
diff changeset
159
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
160 int main(int, char**)
150
anatofuz
parents:
diff changeset
161 {
anatofuz
parents:
diff changeset
162 t1::test();
anatofuz
parents:
diff changeset
163 t2::test();
anatofuz
parents:
diff changeset
164 t3::test();
anatofuz
parents:
diff changeset
165 t4::test();
anatofuz
parents:
diff changeset
166 t5::test();
221
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
167
79ff65ed7e25 LLVM12 Original
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents: 150
diff changeset
168 return 0;
150
anatofuz
parents:
diff changeset
169 }