Matt Morehouse | 74ddba0 | 2017-07-28 19:52:31 +0000 | [diff] [blame] | 1 | // Verify that objects passed by value get red zones and that the copy |
| 2 | // constructor is called. |
| 3 | // RUN: %clangxx_asan -O0 %s -o %t |
| 4 | // RUN: not %run %t 2>&1 | FileCheck %s --implicit-check-not \ |
| 5 | // RUN: Assertion{{.*}}failed |
Reid Kleckner | 3bcad2b | 2017-07-28 21:43:23 +0000 | [diff] [blame] | 6 | |
| 7 | // ASan instrumentation can't insert red-zones around inalloca parameters. |
Petr Hosek | eb46c95 | 2018-08-09 02:16:18 +0000 | [diff] [blame] | 8 | // XFAIL: windows-msvc && asan-32-bits |
Reid Kleckner | 3bcad2b | 2017-07-28 21:43:23 +0000 | [diff] [blame] | 9 | |
Matt Morehouse | 74ddba0 | 2017-07-28 19:52:31 +0000 | [diff] [blame] | 10 | #include <cassert> |
| 11 | |
| 12 | class A { |
| 13 | public: |
| 14 | A() : me(this) {} |
| 15 | A(const A &other) : me(this) { |
| 16 | for (int i = 0; i < 8; ++i) a[i] = other.a[i]; |
| 17 | } |
| 18 | |
| 19 | int a[8]; |
| 20 | A *me; |
| 21 | }; |
| 22 | |
| 23 | int bar(A *a) { |
| 24 | int *volatile ptr = &a->a[0]; |
| 25 | return *(ptr - 1); |
| 26 | } |
| 27 | |
| 28 | void foo(A a) { |
| 29 | assert(a.me == &a); |
| 30 | bar(&a); |
| 31 | } |
| 32 | |
| 33 | int main() { |
| 34 | A a; |
| 35 | foo(a); |
| 36 | } |
| 37 | |
| 38 | // CHECK: ERROR: AddressSanitizer: stack-buffer-overflow |
| 39 | // CHECK: READ of size 4 at |
| 40 | // CHECK: is located in stack of thread |