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