[PATCH] D34827: Add end-to-end tests for overflows of byval arguments.
Matt Morehouse via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 29 11:50:39 PDT 2017
morehouse created this revision.
Herald added a subscriber: kubamracek.
Included is one test for passing structs by values and one test for passing C++
objects by value.
https://reviews.llvm.org/D34827
Files:
test/asan/TestCases/pass-object-byval.cc
test/asan/TestCases/pass-struct-byval.cc
Index: test/asan/TestCases/pass-struct-byval.cc
===================================================================
--- /dev/null
+++ test/asan/TestCases/pass-struct-byval.cc
@@ -0,0 +1,23 @@
+// RUN: %clangxx_asan -O0 %s -o %t
+// RUN: not %run %t 2>&1 | FileCheck %s
+
+struct A {
+ int a[8];
+};
+
+int bar(A *a) {
+ int *ptr = &a->a[0];
+ return *((int *) (ptr - 1));
+}
+
+void foo(A a) {
+ bar(&a);
+}
+
+int main() {
+ foo(A());
+}
+
+// CHECK: ERROR: AddressSanitizer: stack-buffer-underflow
+// CHECK: READ of size 4 at
+// CHECK: is located in stack of thread
Index: test/asan/TestCases/pass-object-byval.cc
===================================================================
--- /dev/null
+++ test/asan/TestCases/pass-object-byval.cc
@@ -0,0 +1,40 @@
+// Verify that objects passed by value get red zones.
+// RUN: %clangxx_asan -O0 %s -o %t
+// RUN: not %run %t 2>&1 | FileCheck --check-prefix=CHECK-REDZONE %s
+//
+// Verify that objects are passed via pointer-to-copy and not via byval args.
+// Otherwise we would have issues with the self-referential pointer "me" in
+// class A below when ASan does a memcpy on the byval arg.
+// RUN: %clangxx_asan %s -emit-llvm -S -o %t.ll
+// RUN: cat %t.ll | FileCheck --check-prefix=CHECK-BYVAL %s
+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 *ptr = &a->a[0];
+ return *((int *) (ptr - 1));
+}
+
+void foo(A a) {
+ bar(&a);
+}
+
+int main() {
+ A a;
+ foo(a);
+}
+
+// CHECK-REDZONE: ERROR: AddressSanitizer: stack-buffer-overflow
+// CHECK-REDZONE: READ of size 4 at
+// CHECK-REDZONE: is located in stack of thread
+
+// CHECK-BYVAL: define void @_Z3foo1A(%class.A* %a)
+
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34827.104714.patch
Type: text/x-patch
Size: 1781 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170629/dabfed5d/attachment.bin>
More information about the llvm-commits
mailing list