Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 1 | // RUN: %clang_cl_asan -O0 %p/dll_host.cc -Fe%t |
| 2 | // RUN: %clang_cl_asan -LD -O0 %s -Fe%t.dll |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 3 | // RUN: %env_asan_opts=detect_stack_use_after_return=1 not %run %t %t.dll 2>&1 | FileCheck %s |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 4 | |
| 5 | #include <malloc.h> |
| 6 | |
| 7 | char *x; |
| 8 | |
| 9 | void foo() { |
| 10 | char stack_buffer[42]; |
| 11 | x = &stack_buffer[13]; |
| 12 | } |
| 13 | |
| 14 | extern "C" __declspec(dllexport) |
| 15 | int test_function() { |
| 16 | foo(); |
| 17 | *x = 42; |
| 18 | // CHECK: AddressSanitizer: stack-use-after-return |
| 19 | // CHECK: WRITE of size 1 at [[ADDR:.*]] thread T0 |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 20 | // CHECK-NEXT: test_function{{.*}}dll_stack_use_after_return.cc:[[@LINE-3]] |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 21 | // CHECK-NEXT: main |
| 22 | // |
| 23 | // CHECK: Address [[ADDR]] is located in stack of thread T0 at offset [[OFFSET:.*]] in frame |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 24 | // CHECK-NEXT: #0 {{.*}} foo{{.*}}dll_stack_use_after_return.cc |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 25 | // CHECK: 'stack_buffer' <== Memory access at offset [[OFFSET]] is inside this variable |
| 26 | return 0; |
| 27 | } |
| 28 | |