[ASan Win] Simplify and improve the way we forward ASan interface calls from DLLs
[blocksruntime.git] / test / asan / TestCases / Windows / dll_thread_stack_array_left_oob.cc
blobe777e1bd7c0e31beb163eec761731f5f4ce9e9c2
1 // RUN: %clangxx_asan -O0 %p/dll_host.cc -Fe%t
2 // RUN: %clangxx_asan -LD -O0 %s -Fe%t.dll
3 // FIXME: 'cat' is needed due to PR19744.
4 // RUN: not %run %t %t.dll 2>&1 | cat | FileCheck %s
6 #include <windows.h>
7 #include <malloc.h>
9 DWORD WINAPI thread_proc(void *context) {
10 int subscript = -1;
11 char stack_buffer[42];
12 stack_buffer[subscript] = 42;
13 // CHECK: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
14 // CHECK: WRITE of size 1 at [[ADDR]] thread T1
15 // CHECK-NEXT: thread_proc {{.*}}dll_thread_stack_array_left_oob.cc:[[@LINE-3]]
17 // CHECK: Address [[ADDR]] is located in stack of thread T1 at offset [[OFFSET:.*]] in frame
18 // CHECK-NEXT: thread_proc {{.*}}dll_thread_stack_array_left_oob.cc
20 // CHECK: 'stack_buffer' <== Memory access at offset [[OFFSET]] underflows this variable
22 return 0;
25 extern "C" __declspec(dllexport)
26 int test_function() {
27 HANDLE thr = CreateThread(NULL, 0, thread_proc, NULL, 0, NULL);
28 // CHECK-LABEL: Thread T1 created by T0 here:
29 // CHECK: test_function {{.*}}dll_thread_stack_array_left_oob.cc:[[@LINE-2]]
30 // CHECK-NEXT: main {{.*}}dll_host.cc
31 // CHECK-LABEL: SUMMARY
32 if (thr == 0)
33 return 1;
34 if (WAIT_OBJECT_0 != WaitForSingleObject(thr, INFINITE))
35 return 2;
36 return 0;