[LVI] Add trunc to i1 handling. (#124480)
[llvm-project.git] / compiler-rt / test / asan / TestCases / Windows / free_hook_realloc.cpp
blob297218bf8e99f1fa31f65c9096077ad1eca962bf
1 // Check that free hook doesn't conflict with Realloc.
2 // RUN: %clangxx_asan -O2 %s -o %t
3 // RUN: %run %t 2>&1 | FileCheck %s
5 // FIXME: merge this with the common free_hook_realloc test when we can run
6 // common tests on Windows.
8 #include <stdlib.h>
9 #include <io.h>
10 #include <sanitizer/allocator_interface.h>
12 static void *glob_ptr;
14 extern "C" {
15 void __sanitizer_free_hook(const volatile void *ptr) {
16 if (ptr == glob_ptr) {
17 *(int*)ptr = 0;
18 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;