16a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines// RUN: %clang_cl_asan -O0 %p/dll_host.cc -Fe%t
26a211c5814e25d6745a5058cc0e499e5235d3821Stephen Hines// RUN: %clang_cl_asan -LD -O0 %s -Fe%t.dll
32d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines// RUN: %run %t %t.dll | FileCheck %s
42d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines
52d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines#include <malloc.h>
62d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines#include <stdio.h>
72d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines
82d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines#define CHECK_ALIGNED(ptr,alignment) \
92d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines  do { \
102d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines    if (((uintptr_t)(ptr) % (alignment)) != 0) \
112d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines      return __LINE__; \
122d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines    } \
132d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines  while(0)
142d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines
152d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hinesextern "C" __declspec(dllexport)
162d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hinesint test_function() {
172d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines  int *p = (int*)_aligned_malloc(1024 * sizeof(int), 32);
182d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines  CHECK_ALIGNED(p, 32);
192d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines  p[512] = 0;
202d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines  _aligned_free(p);
212d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines
222d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines  p = (int*)_aligned_malloc(128, 128);
232d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines  CHECK_ALIGNED(p, 128);
242d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines  p = (int*)_aligned_realloc(p, 2048 * sizeof(int), 128);
252d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines  CHECK_ALIGNED(p, 128);
262d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines  p[1024] = 0;
272d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines  if (_aligned_msize(p, 128, 0) != 2048 * sizeof(int))
282d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines    return __LINE__;
292d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines  _aligned_free(p);
302d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines
312d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines  printf("All ok\n");
322d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines// CHECK: All ok
332d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines  return 0;
342d1fdb26e458c4ddc04155c1d421bced3ba90cd0Stephen Hines}
35