xref: /llvm-project/compiler-rt/test/ubsan/TestCases/TypeCheck/vptr-virtual-base.cpp (revision e9e1892b838d50729871f9b2160d4a11fb4972fb)
1 // RUN: %clangxx -frtti -fsanitize=null,vptr -fno-sanitize-recover=vptr -g %s -O3 -o %t
2 // RUN: not %run %t 2>&1 | FileCheck %s
3 
4 // REQUIRES: shared_cxxabi
5 // REQUIRES: cxxabi
6 // UNSUPPORTED: target={{.*windows-msvc.*}}
7 // Nested crash reported
8 // UNSUPPORTED: target={{.*freebsd.*}}
9 // FIXME: Itanium demangling isn't done for the type names on MinGW targets.
10 // XFAIL: target={{.*windows-gnu.*}}
11 
fS12 struct S { virtual int f() { return 0; } };
13 struct T : virtual S {};
14 
fFoo15 struct Foo { virtual int f() { return 0; } };
16 
main(int argc,char ** argv)17 int main(int argc, char **argv) {
18   Foo foo;
19   T *t = (T*)&foo;
20   S *s = t;
21   // CHECK: vptr-virtual-base.cpp:[[@LINE-1]]:10: runtime error: cast to virtual base of address [[PTR:0x[0-9a-f]*]] which does not point to an object of type 'T'
22   // CHECK-NEXT: [[PTR]]: note: object is of type 'Foo'
23   return s->f();
24 }
25