1// RUN: %clang_cl_asan %Od %p/dll_host.cpp %Fe%t
2// RUN: %clang_cl_asan %LD %Od %s %Fe%t.dll
3// RUN: %env_asan_opts=detect_stack_use_after_return=1 not %run %t %t.dll 2>&1 | FileCheck %s
4// RUN: %clang_cl_asan %LD %Od %s %Fe%t.dll -fsanitize-address-use-after-return=always
5// RUN: not %run %t %t.dll 2>&1 | FileCheck %s
6
7#include <malloc.h>
8
9char *x;
10
11void foo() {
12 char stack_buffer[42];
13 x = &stack_buffer[13];
14}
15
16extern "C" __declspec(dllexport)
17int test_function() {
18 foo();
19 *x = 42;
20// CHECK: AddressSanitizer: stack-use-after-return
21// CHECK: WRITE of size 1 at [[ADDR:.*]] thread T0
22// CHECK-NEXT: test_function{{.*}}dll_stack_use_after_return.cpp:[[@LINE-3]]
23// CHECK-NEXT: main
24//
25// CHECK: Address [[ADDR]] is located in stack of thread T0 at offset [[OFFSET:.*]] in frame
26// CHECK-NEXT: #0 {{.*}} foo{{.*}}dll_stack_use_after_return.cpp
27// CHECK: 'stack_buffer'{{.*}} <== Memory access at offset [[OFFSET]] is inside this variable
28 return 0;
29}
30
31

source code of compiler-rt/test/asan/TestCases/Windows/dll_stack_use_after_return.cpp