RISC-V: Add naked function support.
[official-gcc.git] / libvtv / testsuite / libvtv.cc / virtfunc-test.cc
bloba33b045e75ff4bc3752c34b6860d20ee95da3fba
1 // { dg-do run }
3 /* This test script is part of GDB, the GNU debugger.
5 Copyright (C) 1993-2018 Free Software Foundation, Inc.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 // Pls try the following program on virtual functions and try to do print on
22 // most of the code in main(). Almost none of them works !
25 // The inheritance structure is:
27 // V : VA VB
28 // A : (V)
29 // B : A
30 // D : AD (V)
31 // C : (V)
32 // E : B (V) D C
35 class VA
37 public:
38 int va;
41 class VB
43 public:
44 int vb;
45 int fvb();
46 virtual int vvb();
49 class V : public VA, public VB
51 public:
52 int f();
53 virtual int vv();
54 int w;
57 class A : virtual public V
59 public:
60 virtual int f();
61 private:
62 int a;
65 class B : public A
67 public:
68 int f();
69 private:
70 int b;
73 class C : public virtual V
75 public:
76 int c;
79 class AD
81 public:
82 virtual int vg() = 0;
85 class D : public AD, virtual public V
87 public:
88 static void s();
89 virtual int vg();
90 virtual int vd();
91 int fd();
92 int d;
95 class E : public B, virtual public V, public D, public C
97 public:
98 int f();
99 int vg();
100 int vv();
101 int e;
104 D dd;
105 D* ppd = &dd;
106 AD* pAd = &dd;
108 A a;
109 B b;
110 C c;
111 D d;
112 E e;
113 V v;
114 VB vb;
117 A* pAa = &a;
118 A* pAe = &e;
120 B* pBe = &e;
122 D* pDd = &d;
123 D* pDe = &e;
125 V* pVa = &a;
126 V* pVv = &v;
127 V* pVe = &e;
128 V* pVd = &d;
130 AD* pADe = &e;
132 E* pEe = &e;
134 VB* pVB = &vb;
136 void init()
138 a.vb = 1;
139 b.vb = 2;
140 c.vb = 3;
141 d.vb = 4;
142 e.vb = 5;
143 v.vb = 6;
144 vb.vb = 7;
146 d.d = 1;
147 e.d = 2;
150 extern "C" int printf(const char *, ...);
152 int all_count = 0;
153 int failed_count = 0;
155 #define TEST(EXPR, EXPECTED) \
156 ret = EXPR; \
157 if (ret != EXPECTED) {\
158 printf("Failed %s is %d, should be %d!\n", #EXPR, ret, EXPECTED); \
159 failed_count++; } \
160 all_count++;
162 int ret;
164 void test_calls()
166 TEST(pAe->f(), 20);
167 TEST(pAa->f(), 1);
169 TEST(pDe->vg(), 202);
170 TEST(pADe->vg(), 202);
171 TEST(pDd->vg(), 101);
173 TEST(pEe->vvb(), 411);
175 TEST(pVB->vvb(), 407);
177 TEST(pBe->vvb(), 411);
178 TEST(pDe->vvb(), 411);
180 TEST(pEe->vd(), 282);
181 TEST(pEe->fvb(), 311);
183 TEST(pEe->D::vg(), 102);
184 printf("Did %d tests, of which %d failed.\n", all_count, failed_count);
186 #ifdef usestubs
187 extern "C" {
188 void set_debug_traps();
189 void breakpoint();
191 #endif
193 int main()
195 #ifdef usestubs
196 set_debug_traps();
197 breakpoint();
198 #endif
199 init();
201 e.w = 7;
202 e.vb = 11;
204 test_calls();
205 return 0;
209 int A::f() {return 1;}
210 int B::f() {return 2;}
211 void D::s() {}
212 int E::f() {return 20;}
213 int D::vg() {return 100+d;}
214 int E::vg() {return 200+d;}
215 int V::f() {return 600+w;}
216 int V::vv() {return 400+w;}
217 int E::vv() {return 450+w;}
218 int D::fd() {return 250+d;}
219 int D::vd() {return 280+d;}
220 int VB::fvb() {return 300+vb;}
221 int VB::vvb() {return 400+vb;}