summaryrefslogtreecommitdiff
path: root/test/asan/TestCases/Windows/wrong_downcast_on_heap.cc
diff options
context:
space:
mode:
authorTimur Iskhodzhanov <timurrrr@google.com>2014-05-15 11:14:00 +0000
committerTimur Iskhodzhanov <timurrrr@google.com>2014-05-15 11:14:00 +0000
commit0241a7c5bae364ded44f4f33803d199eade8dd4e (patch)
treec38f4b31c9fcdb18e0a1836616964064df6672e4 /test/asan/TestCases/Windows/wrong_downcast_on_heap.cc
parentd4f5c5a234747c1801fed48aa1f8b242ab7e306a (diff)
[ASan/Win tests] Add tests for downcast-related overflows, as well as CRT initiazliers
git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@208865 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/asan/TestCases/Windows/wrong_downcast_on_heap.cc')
-rw-r--r--test/asan/TestCases/Windows/wrong_downcast_on_heap.cc27
1 files changed, 27 insertions, 0 deletions
diff --git a/test/asan/TestCases/Windows/wrong_downcast_on_heap.cc b/test/asan/TestCases/Windows/wrong_downcast_on_heap.cc
new file mode 100644
index 000000000..3fab7c9c2
--- /dev/null
+++ b/test/asan/TestCases/Windows/wrong_downcast_on_heap.cc
@@ -0,0 +1,27 @@
+// RUN: %clangxx_asan -O0 %s -Fe%t
+// FIXME: 'cat' is needed due to PR19744.
+// RUN: not %run %t 2>&1 | cat | FileCheck %s
+
+class Parent {
+ public:
+ int field;
+};
+
+class Child : public Parent {
+ public:
+ int extra_field;
+};
+
+int main(void) {
+ Parent *p = new Parent;
+ Child *c = (Child*)p; // Intentional error here!
+ c->extra_field = 42;
+// CHECK: AddressSanitizer: heap-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
+// CHECK: WRITE of size 4 at [[ADDR]] thread T0
+// CHECK: {{#0 0x[0-9a-f]* in main .*wrong_downcast_on_heap.cc}}:[[@LINE-3]]
+// CHECK: [[ADDR]] is located 0 bytes to the right of 4-byte region
+// CHECK: allocated by thread T0 here:
+// CHECK: #0 {{.*}} operator new
+ return 0;
+}
+