blob: e0eee4af76428b049bd844993fd9033e296556a5 [file] [log] [blame]
Stephen Hines86277eb2015-03-23 12:06:32 -07001// RUN: %clang_cl_asan -LD -O0 -DDLL %s -Fe%t.dll
2// RUN: %clang_cl_asan -O0 -DEXE %s -Fe%te.exe
Pirama Arumuga Nainarcdce50b2015-07-01 12:26:56 -07003// RUN: env ASAN_OPTIONS=%ASAN_OPTIONS%:report_globals=2 %run %te.exe %t.dll 2>&1 | FileCheck %s
Stephen Hines86277eb2015-03-23 12:06:32 -07004
5#include <windows.h>
6#include <stdio.h>
7#include <string.h>
8
9extern "C" {
10#if defined(EXE)
11int main(int argc, char **argv) {
12 if (argc != 2) {
13 printf("Usage: %s [client].dll\n", argv[0]);
14 return 101;
15 }
16 const char *dll_name = argv[1];
17
18// CHECK: time to load DLL
19 printf("time to load DLL\n");
20 fflush(0);
21
22// On DLL load, the "in DLL\n" string is registered:
23// CHECK: Added Global{{.*}} size=19
24// CHECK: in DLL(reason=1)
25 HMODULE dll = LoadLibrary(dll_name);
26 if (dll == NULL)
27 return 3;
28
29// CHECK: in DLL(reason=0)
30// CHECK-NEXT: Removed Global{{.*}} size=19
31 if (!FreeLibrary(dll))
32 return 4;
33
34// CHECK: bye!
35 printf("bye!\n");
36 fflush(0);
37}
38#elif defined(DLL)
39BOOL WINAPI DllMain(HMODULE, DWORD reason, LPVOID) {
40 printf("in DLL(reason=%d)\n", (int)reason);
41 fflush(0);
42 return TRUE;
43}
44#else
45# error oops!
46#endif
47}