summaryrefslogtreecommitdiff
path: root/test/asan/TestCases/pass-object-byval.cc
diff options
context:
space:
mode:
authorMatt Morehouse <mascasa@google.com>2017-07-28 19:52:31 +0000
committerMatt Morehouse <mascasa@google.com>2017-07-28 19:52:31 +0000
commit7810a905a4c21031e7a5e8b8a8fde70ec40b5fa5 (patch)
treeced5e564f4c8d496da0e9161fd398101e041b323 /test/asan/TestCases/pass-object-byval.cc
parentb340d2cc8cfa5f26019be4e14a03873d41341e32 (diff)
Add end-to-end tests for overflows of byval arguments.
Summary: Included is one test for passing structs by value and one test for passing C++ objects by value. Reviewers: eugenis, vitalybuka Reviewed By: eugenis Subscribers: srhines, kubamracek, llvm-commits Differential Revision: https://reviews.llvm.org/D34827 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@309424 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/asan/TestCases/pass-object-byval.cc')
-rw-r--r--test/asan/TestCases/pass-object-byval.cc36
1 files changed, 36 insertions, 0 deletions
diff --git a/test/asan/TestCases/pass-object-byval.cc b/test/asan/TestCases/pass-object-byval.cc
new file mode 100644
index 000000000..189fcbeb2
--- /dev/null
+++ b/test/asan/TestCases/pass-object-byval.cc
@@ -0,0 +1,36 @@
+// Verify that objects passed by value get red zones and that the copy
+// constructor is called.
+// RUN: %clangxx_asan -O0 %s -o %t
+// RUN: not %run %t 2>&1 | FileCheck %s --implicit-check-not \
+// RUN: Assertion{{.*}}failed
+#include <cassert>
+
+class A {
+ public:
+ A() : me(this) {}
+ A(const A &other) : me(this) {
+ for (int i = 0; i < 8; ++i) a[i] = other.a[i];
+ }
+
+ int a[8];
+ A *me;
+};
+
+int bar(A *a) {
+ int *volatile ptr = &a->a[0];
+ return *(ptr - 1);
+}
+
+void foo(A a) {
+ assert(a.me == &a);
+ bar(&a);
+}
+
+int main() {
+ A a;
+ foo(a);
+}
+
+// CHECK: ERROR: AddressSanitizer: stack-buffer-overflow
+// CHECK: READ of size 4 at
+// CHECK: is located in stack of thread