summaryrefslogtreecommitdiff
path: root/test/ubsan/TestCases/TypeCheck/PR33221.cpp
blob: 65cbf5d000d9ec6581165a206225736af6aecc4f (plain)
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
// RUN: %clangxx -frtti -fsanitize=null,vptr -g %s -O3 -o %t
// RUN: %run %t 2>&1 | FileCheck %s

// REQUIRES: cxxabi
// UNSUPPORTED: win32

#include <string.h>

class Base {
public:
  int i;
  virtual void print() {}
};

class Derived : public Base {
public:
  void print() {}
};

int main() {
  char *c = new char[sizeof(Derived)];
  memset((void *)c, 0xFF, sizeof(Derived));
  Derived *list = (Derived *)c;

// CHECK: PR33221.cpp:[[@LINE+2]]:19: runtime error: member access within address {{.*}} which does not point to an object of type 'Base'
// CHECK-NEXT: invalid vptr
  int foo = list->i;
  return 0;
}