File: dtor-vtable-multiple-inheritance.cpp

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (79 lines) | stat: -rw-r--r-- 2,148 bytes parent folder | download | duplicates (19)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// RUN: %clangxx_msan %s -O0 -fsanitize-memory-use-after-dtor -o %t && %run %t
// RUN: %clangxx_msan %s -O1 -fsanitize-memory-use-after-dtor -o %t && %run %t
// RUN: %clangxx_msan %s -O2 -fsanitize-memory-use-after-dtor -o %t && %run %t
// RUN: %clangxx_msan %s -DCVPTR=1 -O2 -fsanitize-memory-use-after-dtor -fsanitize-memory-track-origins -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=CVPTR
// RUN: %clangxx_msan %s -DEAVPTR=1 -O2 -fsanitize-memory-use-after-dtor -fsanitize-memory-track-origins -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=EAVPTR
// RUN: %clangxx_msan %s -DEDVPTR=1 -O2 -fsanitize-memory-use-after-dtor -fsanitize-memory-track-origins -o %t && not %run %t 2>&1 | FileCheck %s --check-prefixes=EDVPTR

// Expected to quit due to invalid access when invoking
// function using vtable.

class A {
 public:
  int x;
  virtual ~A() {
    // Should succeed
    this->A_Foo();
  }
  virtual void A_Foo() {}
};

class B : public virtual A {
 public:
  int y;
  virtual ~B() {}
  virtual void A_Foo() {}
};

class C : public B {
 public:
   int z;
};

class D {
 public:
  int w;
  ~D() {}
  virtual void D_Foo() {}
};

class E : public virtual A, public virtual D {
 public:
  int u;
  ~E() {}
  void A_Foo() {}
};

int main() {
  // Simple linear inheritance
  C *c = new C();
  c->~C();
  // This fails
#ifdef CVPTR
  c->A_Foo();
// CVPTR: Virtual table ptr was destroyed
// CVPTR: {{#0 0x.* in __sanitizer_dtor_callback_vptr}}
// CVPTR: {{#1 0x.* in ~C .*cpp:}}[[@LINE-28]]:
// CVPTR: {{#2 0x.* in main .*cpp:}}[[@LINE-7]]:
#endif

  // Multiple inheritance, so has multiple vtables
  E *e = new E();
  e->~E();
  // Both of these fail
#ifdef EAVPTR
  e->A_Foo();
// EAVPTR: Virtual table ptr was destroyed
// EAVPTR: {{#0 0x.* in __sanitizer_dtor_callback_vptr}}
// EAVPTR: {{#1 0x.* in ~E .*cpp:}}[[@LINE-25]]:
// EAVPTR: {{#2 0x.* in main .*cpp:}}[[@LINE-7]]:
#endif

#ifdef EDVPTR
  e->D_Foo();
// EDVPTR: Virtual table ptr was destroyed
// EDVPTR: {{#0 0x.* in __sanitizer_dtor_callback_vptr}}
// EDVPTR: {{#1 0x.* in ~E .*cpp:}}[[@LINE-33]]:
// EDVPTR: {{#2 0x.* in main .*cpp:}}[[@LINE-15]]:
#endif
}