40 lines · cpp
1// RUN: %clang_cl_asan %Od %p/dll_host.cpp %Fe%t2// RUN: %clang_cl_asan %LD %Od %s %Fe%t.dll3// RUN: %run %t %t.dll | FileCheck %s4 5#include <malloc.h>6#include <stdio.h>7 8#ifdef __MINGW32__9// FIXME: remove after mingw-w64 adds this declaration.10extern "C" size_t __cdecl _aligned_msize(void *_Memory, size_t _Alignment, size_t _Offset);11#endif12 13#define CHECK_ALIGNED(ptr,alignment) \14 do { \15 if (((uintptr_t)(ptr) % (alignment)) != 0) \16 return __LINE__; \17 } \18 while(0)19 20extern "C" __declspec(dllexport)21int 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("All ok\n");37// CHECK: All ok38 return 0;39}40