Debian Codegraph @

gcc/testsuite/g++.dg/ubsan/vptr-11.C

raw
1 // PR c++/70147
2 // { dg-do run }
3 // { dg-options "-fsanitize=vptr -fno-sanitize-recover=vptr" }
4
5 static int ac, ad, bc, bd, cc, cd, dc, dd;
6 struct A
7 {
8 A ()
9 {
10 ac++;
11 }
12 virtual void f ()
13 {
14 }
15 __attribute__ ((noinline)) ~ A ();
16 };
17
18 struct D
19 {
20 __attribute__ ((noinline)) D (int);
21 ~D ()
22 {
23 dd++;
24 }
25 };
26 struct B: virtual A, D
27 {
28 B ():D (1)
29 {
30 bc++;
31 }
32 virtual void f ()
33 {
34 }
35 ~B ()
36 {
37 bd++;
38 }
39 };
40
41 struct C: B, virtual A
42 {
43 C ()
44 {
45 cc++;
46 }
47 ~C ()
48 {
49 cd++;
50 }
51 };
52
53 D::D (int x)
54 {
55 if (x)
56 throw 1;
57 dc++;
58 }
59
60 __attribute__ ((noinline, noclone))
61 void foo (A * p)
62 {
63 p->f ();
64 }
65
66 A::~A ()
67 {
68 foo (this);
69 ad++;
70 }
71
72 int
73 main ()
74 {
75 try
76 {
77 C c;
78 }
79 catch ( ...)
80 {
81 }
82 if (ac != 1 || ad != 1 || bc || bd || cc || cd || dc || dd)
83 __builtin_abort ();
84 }