Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / memprof / TestCases / free_hook_realloc.cpp
blob85e29a372fdff8db84e9575193213821b433aa9d
1 // Check that free hook doesn't conflict with Realloc.
2 // RUN: %clangxx_memprof -O2 %s -o %t && %run %t 2>&1 | FileCheck %s
4 #include <sanitizer/allocator_interface.h>
5 #include <stdlib.h>
6 #include <unistd.h>
8 static void *glob_ptr;
10 // (Speculative fix if memprof is enabled on Apple platforms)
11 // Required for dyld macOS 12.0+
12 #if (__APPLE__)
13 __attribute__((weak))
14 #endif
15 extern "C" void
16 __sanitizer_free_hook(const volatile void *ptr) {
17 if (ptr == glob_ptr) {
18 *(int *)ptr = 0;
19 write(1, "FreeHook\n", sizeof("FreeHook\n"));
23 int main() {
24 int *x = (int *)malloc(100);
25 x[0] = 42;
26 glob_ptr = x;
27 int *y = (int *)realloc(x, 200);
28 // Verify that free hook was called and didn't spoil the memory.
29 if (y[0] != 42) {
30 _exit(1);
32 write(1, "Passed\n", sizeof("Passed\n"));
33 free(y);
34 // CHECK: FreeHook
35 // CHECK: Passed
36 return 0;