Pirama Arumuga Nainar | 7c91505 | 2015-04-08 08:58:29 -0700 | [diff] [blame] | 1 | // RUN: %clang_cl_asan -LD -O0 -DDLL %s -Fe%t.dll |
| 2 | // RUN: %clang_cl_asan -O0 -DEXE %s %t.lib -Fe%te.exe |
Pirama Arumuga Nainar | cdce50b | 2015-07-01 12:26:56 -0700 | [diff] [blame] | 3 | // RUN: env ASAN_OPTIONS=$ASAN_OPTIONS:report_globals=2 %run %te.exe 2>&1 | FileCheck %s |
Pirama Arumuga Nainar | 7c91505 | 2015-04-08 08:58:29 -0700 | [diff] [blame] | 4 | |
| 5 | // FIXME: Currently, the MT runtime build crashes on startup due to dbghelp.dll |
| 6 | // initialization failure. |
| 7 | // REQUIRES: asan-dynamic-runtime |
| 8 | |
| 9 | #include <windows.h> |
| 10 | #include <stdio.h> |
| 11 | |
| 12 | extern "C" { |
| 13 | #if defined(EXE) |
| 14 | __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 | // This global is registered at startup. |
| 26 | int x[42]; |
| 27 | |
| 28 | __declspec(dllexport) int foo_from_dll() { |
| 29 | return x[2]; |
| 30 | } |
| 31 | |
| 32 | BOOL WINAPI DllMain(HMODULE, DWORD reason, LPVOID) { |
| 33 | printf("in DLL(reason=%d)\n", (int)reason); |
| 34 | fflush(0); |
| 35 | return TRUE; |
| 36 | } |
| 37 | #else |
| 38 | # error oops! |
| 39 | #endif |
| 40 | } |