| 1 | // RUN: %clang_cl_asan %LD %Od -DDLL %s %Fe%t.dll \ |
| 2 | // RUN: %if target={{.*-windows-gnu}} %{ -Wl,--out-implib,%t.lib %} |
| 3 | // RUN: %clang_cl_asan %Od -DEXE %s %t.lib %Fe%te.exe |
| 4 | // RUN: %env_asan_opts=report_globals=2 %run %te.exe 2>&1 | FileCheck %s |
| 5 | |
| 6 | // FIXME: Currently, the MT runtime build crashes on startup due to dbghelp.dll |
| 7 | // initialization failure. |
| 8 | // REQUIRES: asan-dynamic-runtime |
| 9 | |
| 10 | #include <windows.h> |
| 11 | #include <stdio.h> |
| 12 | |
| 13 | #if defined(EXE) |
| 14 | extern "C" __declspec(dllimport) int foo_from_dll(); |
| 15 | |
| 16 | // CHECK: in DLL(reason=1) |
| 17 | int main(int argc, char **argv) { |
| 18 | foo_from_dll(); |
| 19 | // CHECK: hello! |
| 20 | printf("hello!\n" ); |
| 21 | fflush(0); |
| 22 | // CHECK: in DLL(reason=0) |
| 23 | } |
| 24 | #elif defined(DLL) |
| 25 | extern "C" { |
| 26 | // This global is registered at startup. |
| 27 | int x[42]; |
| 28 | |
| 29 | __declspec(dllexport) int foo_from_dll() { |
| 30 | return x[2]; |
| 31 | } |
| 32 | |
| 33 | BOOL WINAPI DllMain(HMODULE, DWORD reason, LPVOID) { |
| 34 | printf("in DLL(reason=%d)\n" , (int)reason); |
| 35 | fflush(0); |
| 36 | return TRUE; |
| 37 | } |
| 38 | } |
| 39 | #else |
| 40 | # error oops! |
| 41 | #endif |
| 42 | |