1 
2 // RUN: %clang_cl -LD %s -Fe%t.dll -DHEAP_LIBRARY -MD
3 // RUN: %clang_cl %s %t.lib -Fe%t -fsanitize=address -MT
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 
13 std::unique_ptr<int> __declspec(dllexport) myglobal(new int(42));
DllMain(PVOID h,DWORD reason,PVOID reserved)14 BOOL WINAPI DllMain(PVOID h, DWORD reason, PVOID reserved) {
15   return TRUE;
16 }
17 
18 #else
19 
20 #include <memory>
21 extern std::unique_ptr<int> __declspec(dllimport) myglobal;
main(int argc,char ** argv)22 int main(int argc, char **argv) {
23   printf("myglobal: %d\n", *myglobal);
24   return 0;
25 }
26 
27 #endif
28 
29 // CHECK: myglobal: 42
30 // CHECK-NOT: ERROR: AddressSanitizer: attempting free on address which was not malloc()-ed
31