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
8extern "C" __declspec(dllexport)
9int test_function() {
10 int *p = (int*)malloc(size: 1024 * sizeof(int));
11 p[512] = 0;
12 free(ptr: p);
13
14 p = (int*)malloc(size: 128);
15 p = (int*)realloc(ptr: p, size: 2048 * sizeof(int));
16 p[1024] = 0;
17 free(ptr: p);
18
19 p = (int*)calloc(nmemb: 16, size: sizeof(int));
20 if (p[8] != 0)
21 return 1;
22 p[15]++;
23 if (16 * sizeof(int) != _msize(p))
24 return 2;
25 free(ptr: p);
26
27 p = new int;
28 *p = 42;
29 delete p;
30
31 p = new int[42];
32 p[15]++;
33 delete [] p;
34
35 printf(format: "All ok\n");
36// CHECK: All ok
37
38 return 0;
39}
40

source code of compiler-rt/test/asan/TestCases/Windows/dll_allocators_sanity.cpp