OSDN Git Service

8c4c93eb6670465071503a49b0cbb5c3a0759208
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / g++.old-deja / g++.abi / vtable2.C
1 // Origin: Mark Mitchell <mark@codesourcery.com>
2
3 #if defined (__GXX_ABI_VERSION) && __GXX_ABI_VERSION >= 100
4
5 #include <stddef.h>
6
7 struct S0
8 {
9   virtual void s0 ();
10 };
11
12 struct S1 : virtual public S0
13 {
14   virtual void s1 ();
15 };
16
17 struct S2 : virtual public S1
18 {
19   virtual void s1 ();
20   virtual void s0 ();
21 };
22
23 struct S3
24 {
25   virtual void s3 ();
26 };
27
28 struct S4 : public S3, virtual public S2
29 {
30   virtual void s1 ();
31 };
32
33 void S0::s0 ()
34 {
35 }
36
37 void S1::s1 ()
38 {
39 }
40
41 void S2::s1 ()
42 {
43 }
44
45 void S2::s0 ()
46 {
47 }
48
49 void S3::s3 ()
50 {
51 }
52
53 void S4::s1 ()
54 {
55 }
56
57 /* The vtables should look like:
58
59    S0 primary vtable
60    
61      S0 offset to top
62      S0 RTTI
63      S0::s0
64
65    =================
66
67    S1 primary vtable
68
69      S0::s0 vcall offset
70      S0 vbase offset
71      S1 offset to top
72      S1 RTTI
73      S0::s0
74      S1::s1
75
76    =================
77
78    S2 primary vtable
79    
80      S2::s1 vcall offset
81      S1 vbase offset
82      S2::s0 vcall offset
83      S0 vbase offset
84      S2 offset to top
85      S2 RTTI
86      S2::s0
87      S2::s1
88
89    =================
90
91    S3 primary vtable
92
93      S3 offset to top
94      S3 RTTI
95      S3::s3
96
97    =================
98
99    S4 primary vtable
100
101      vbase offset for S0
102      vbase offset for S1
103      vbase offset for S2
104      S4 offset to top
105      S4 RTTI
106      S3::s3
107      S4::s1
108
109    S2-in-S4 secondary vtable
110
111      S1 vbase offset
112      S4::s1 vcall offset
113      S0 vbase offset
114      S2:s0 vcall offset
115      S2 offset to top
116      S4 RTTI
117      S2::s0
118      S4::s1
119
120 */
121
122 // These are tricks to allow us to get raw function pointers for
123 // member functions.
124 extern "C" {
125 void s3__2S3 ();
126 void s1__2S4 ();
127 }
128
129 int main ()
130 {
131   S4 s4;
132   ptrdiff_t **vptr;
133   ptrdiff_t *vtbl;
134
135   // Set vtbl to point at the beginning of S4's primary vtable.
136   vptr = (ptrdiff_t **) &s4;
137   vtbl = *vptr;
138   vtbl -= 5;
139
140   if (*vtbl++ != ((char*) (S0*) &s4) - (char*) &s4)
141     return 1;
142   if (*vtbl++ != ((char*) (S1*) &s4) - (char*) &s4)
143     return 2;
144   if (*vtbl++ != ((char*) (S2*) &s4) - (char*) &s4)
145     return 3;
146   if (*vtbl++ != 0)
147     return 4;
148   // Skip the RTTI entry.
149   vtbl++;
150   if (*vtbl++ != (ptrdiff_t) &s3__2S3)
151     return 5;
152   if (*vtbl++ != (ptrdiff_t) &s1__2S4)
153     return 6;
154   // The S1 vbase offset.
155   if (*vtbl++ != 0)
156     return 7;
157   // The S4::s1 vcall offset is negative; once you convert to S2, you
158   // have to convert to S4 to find the final overrider.
159   if (*vtbl++ != ((char*) &s4 - (char*) (S2*) &s4))
160     return 8;
161   if (*vtbl++ != 0)
162     return 9;
163   if (*vtbl++ != 0)
164     return 10;
165   // Now we're at the S2 offset to top entry.
166   if (*vtbl++ != ((char*) &s4 - (char*) (S2*) &s4))
167     return 11;
168   // Skip the RTTI entry.
169   vtbl++;
170   // Skip the remaining virtual functions -- they are thunks.
171   vtbl++;
172   vtbl++;
173 }
174
175 #else /* !(defined (__GXX_ABI_VERSION) && __GXX_ABI_VERSION >= 100) */
176
177 int main ()
178 {
179 }
180
181 #endif /* !(defined (__GXX_ABI_VERSION) && __GXX_ABI_VERSION >= 100) */