1// RUN: %clangxx -frtti -fsanitize=null,vptr -g %s -O3 -o %t
2// RUN: %run %t 2>&1 | FileCheck %s
3
4// REQUIRES: cxxabi
5// UNSUPPORTED: target={{.*windows-msvc.*}}
6
7#include <string.h>
8
9class Base {
10public:
11 int i;
12 virtual void print() {}
13};
14
15class Derived : public Base {
16public:
17 void print() {}
18};
19
20int main() {
21 char *c = new char[sizeof(Derived)];
22 memset(s: (void *)c, c: 0xFF, n: sizeof(Derived));
23 Derived *list = (Derived *)c;
24
25// CHECK: PR33221.cpp:[[@LINE+2]]:19: runtime error: member access within address {{.*}} which does not point to an object of type 'Base'
26// CHECK-NEXT: invalid vptr
27 int foo = list->i;
28 return 0;
29}
30

source code of compiler-rt/test/ubsan/TestCases/TypeCheck/PR33221.cpp