Debian Codegraph @

compiler-rt/test/ubsan/TestCases/TypeCheck/PR33221.cpp

raw
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
9 class Base {
10 public:
11 int i;
12 virtual void print() {}
13 };
14
15 class Derived : public Base {
16 public:
17 void print() {}
18 };
19
20 int main() {
21 char *c = new char[sizeof(Derived)];
22 memset((void *)c, 0xFF, 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 }