1 // RUN: %clang_cl_asan -O0 %p/dll_host.cc -Fe%t
2 // RUN: %clang_cl_asan -LD -O0 %s -Fe%t.dll
3 // RUN: %run %t %t.dll | FileCheck %s
4 
5 #include <malloc.h>
6 #include <stdio.h>
7 
8 #define CHECK_ALIGNED(ptr,alignment) \
9   do { \
10     if (((uintptr_t)(ptr) % (alignment)) != 0) \
11       return __LINE__; \
12     } \
13   while(0)
14 
15 extern "C" __declspec(dllexport)
test_function()16 int test_function() {
17   int *p = (int*)_aligned_malloc(1024 * sizeof(int), 32);
18   CHECK_ALIGNED(p, 32);
19   p[512] = 0;
20   _aligned_free(p);
21 
22   p = (int*)_aligned_malloc(128, 128);
23   CHECK_ALIGNED(p, 128);
24   p = (int*)_aligned_realloc(p, 2048 * sizeof(int), 128);
25   CHECK_ALIGNED(p, 128);
26   p[1024] = 0;
27   if (_aligned_msize(p, 128, 0) != 2048 * sizeof(int))
28     return __LINE__;
29   _aligned_free(p);
30 
31   printf("All ok\n");
32 // CHECK: All ok
33   return 0;
34 }
35