1// RUN: %clang_cl %LD %s %Fe%t.dll -DHEAP_LIBRARY %MD \
2// RUN: %if target={{.*-windows-gnu}} %{ -Wl,--out-implib,%t.lib %}
3// RUN: %clang_cl_asan %s %t.lib %Fe%t
4// RUN: %run %t 2>&1 | FileCheck %s
5
6// Check that ASan does not fail when releasing allocations that occurred within
7// an uninstrumented DLL.
8
9#ifdef HEAP_LIBRARY
10#include <memory>
11#include <windows.h>
12
13std::unique_ptr<int> __declspec(dllexport) myglobal(new int(42));
14BOOL WINAPI DllMain(PVOID h, DWORD reason, PVOID reserved) {
15 return TRUE;
16}
17
18#else
19
20#include <cstdio>
21#include <memory>
22extern std::unique_ptr<int> __declspec(dllimport) myglobal;
23int main(int argc, char **argv) {
24 printf("myglobal: %d\n", *myglobal);
25 return 0;
26}
27
28#endif
29
30// CHECK: myglobal: 42
31// CHECK-NOT: ERROR: AddressSanitizer: attempting free on address which was not malloc()-ed
32

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