diff options
author | Vedant Kumar <vsk@apple.com> | 2017-06-01 16:44:11 +0000 |
---|---|---|
committer | Vedant Kumar <vsk@apple.com> | 2017-06-01 16:44:11 +0000 |
commit | bfeededd7ee43fe38262619ec200687875ae82a1 (patch) | |
tree | 60c4422bef86e5e631303be46506937600d2768f /test/ubsan | |
parent | 27c8277872fdff5466439844251c9c52ec37dadb (diff) |
Bug 33221 [UBSAN] segfault with -fsanitize=undefined
There is can be a situation when vptr is not initializing
by constructor of the object, and has a junk data which should
be properly checked, because c++ standard says:
"if default constructor is not specified
16 (7.3) no initialization is performed."
Patch by Denis Khalikov!
Differential Revision: https://reviews.llvm.org/D33712
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@304437 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/ubsan')
-rw-r--r-- | test/ubsan/TestCases/TypeCheck/PR33221.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/test/ubsan/TestCases/TypeCheck/PR33221.cpp b/test/ubsan/TestCases/TypeCheck/PR33221.cpp new file mode 100644 index 000000000..17e35a6d9 --- /dev/null +++ b/test/ubsan/TestCases/TypeCheck/PR33221.cpp @@ -0,0 +1,24 @@ +// RUN: %clangxx -frtti -fsanitize=undefined -g %s -O3 -o %t +// RUN: %run %t 2>&1 | FileCheck %s + +// REQUIRES: cxxabi + +class Base { +public: + int i; + virtual void print() {} +}; + +class Derived : public Base { +public: + void print() {} +}; + +int main() { + Derived *list = (Derived *)new char[sizeof(Derived)]; + +// CHECK: PR33221.cpp:[[@LINE+2]]:19: runtime error: member access within address {{.*}} which does not point to an object of type 'Base' +// CHECK-NEXT: object has invalid vptr + int foo = list->i; + return 0; +} |