1 | // RUN: %clang_cl_asan %Od %p/dll_host.cpp %Fe%t |
2 | // RUN: %clang_cl_asan %LD %Od %s %Fe%t.dll |
3 | // RUN: %run %t %t.dll | FileCheck %s |
4 | |
5 | #include <malloc.h> |
6 | #include <stdio.h> |
7 | |
8 | #ifdef __MINGW32__ |
9 | // FIXME: remove after mingw-w64 adds this declaration. |
10 | extern "C" size_t __cdecl _aligned_msize(void *_Memory, size_t _Alignment, size_t _Offset); |
11 | #endif |
12 | |
13 | #define CHECK_ALIGNED(ptr,alignment) \ |
14 | do { \ |
15 | if (((uintptr_t)(ptr) % (alignment)) != 0) \ |
16 | return __LINE__; \ |
17 | } \ |
18 | while(0) |
19 | |
20 | extern "C" __declspec(dllexport) |
21 | int test_function() { |
22 | int *p = (int*)_aligned_malloc(1024 * sizeof(int), 32); |
23 | CHECK_ALIGNED(p, 32); |
24 | p[512] = 0; |
25 | _aligned_free(p); |
26 | |
27 | p = (int*)_aligned_malloc(128, 128); |
28 | CHECK_ALIGNED(p, 128); |
29 | p = (int*)_aligned_realloc(p, 2048 * sizeof(int), 128); |
30 | CHECK_ALIGNED(p, 128); |
31 | p[1024] = 0; |
32 | if (_aligned_msize(p, 128, 0) != 2048 * sizeof(int)) |
33 | return __LINE__; |
34 | _aligned_free(p); |
35 | |
36 | printf(format: "All ok\n" ); |
37 | // CHECK: All ok |
38 | return 0; |
39 | } |
40 | |