xref: /llvm-project/compiler-rt/test/gwp_asan/repeated_alloc.cpp (revision c17ac8432e62efcbbcaa5519739b403275c553ff)
121184ec5SMitch Phillips // REQUIRES: gwp_asan
221184ec5SMitch Phillips // This test ensures that normal allocation/memory access/deallocation works
321184ec5SMitch Phillips // as expected and we didn't accidentally break the supporting allocator.
421184ec5SMitch Phillips 
521184ec5SMitch Phillips // RUN: %clangxx_gwp_asan %s -o %t
6*c17ac843SMitch Phillips // RUN: %env_scudo_options=GWP_ASAN_MaxSimultaneousAllocations=1 %run %t
7*c17ac843SMitch Phillips // RUN: %env_scudo_options=GWP_ASAN_MaxSimultaneousAllocations=2 %run %t
8*c17ac843SMitch Phillips // RUN: %env_scudo_options=GWP_ASAN_MaxSimultaneousAllocations=11 %run %t
9*c17ac843SMitch Phillips // RUN: %env_scudo_options=GWP_ASAN_MaxSimultaneousAllocations=12 %run %t
10*c17ac843SMitch Phillips // RUN: %env_scudo_options=GWP_ASAN_MaxSimultaneousAllocations=13 %run %t
1121184ec5SMitch Phillips 
1221184ec5SMitch Phillips #include <cstdlib>
1321184ec5SMitch Phillips 
main()1421184ec5SMitch Phillips int main() {
1521184ec5SMitch Phillips   void* Pointers[16];
1621184ec5SMitch Phillips   for (unsigned i = 0; i < 16; ++i) {
1721184ec5SMitch Phillips     char *Ptr = reinterpret_cast<char*>(malloc(1 << i));
1821184ec5SMitch Phillips     Pointers[i] = Ptr;
1921184ec5SMitch Phillips     *Ptr = 0;
2021184ec5SMitch Phillips     Ptr[(1 << i) - 1] = 0;
2121184ec5SMitch Phillips   }
2221184ec5SMitch Phillips 
2321184ec5SMitch Phillips   for (unsigned i = 0; i < 16; ++i) {
2421184ec5SMitch Phillips     free(Pointers[i]);
2521184ec5SMitch Phillips   }
2621184ec5SMitch Phillips 
2721184ec5SMitch Phillips   return 0;
2821184ec5SMitch Phillips }
29