xref: /llvm-project/compiler-rt/test/asan/TestCases/Windows/dll_allocators_sanity.cpp (revision 5ad8bbee238f9655c55f048b6ae8c9b40b4c87e5)
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 
8 extern "C" __declspec(dllexport)
test_function()9 int test_function() {
10   int *p = (int*)malloc(1024 * sizeof(int));
11   p[512] = 0;
12   free(p);
13 
14   p = (int*)malloc(128);
15   p = (int*)realloc(p, 2048 * sizeof(int));
16   p[1024] = 0;
17   free(p);
18 
19   p = (int*)calloc(16, 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(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("All ok\n");
36 // CHECK: All ok
37 
38   return 0;
39 }
40