1// RUN: %clang_cl_asan %Od %s %Fe%t
2// RUN: not %run %t 2>&1 | FileCheck %s
3
4#include <malloc.h>
5
6int main() {
7 char *buffer = (char*)realloc(ptr: 0, size: 32),
8 *stale = buffer;
9 buffer = (char*)realloc(ptr: buffer, size: 64);
10 // The 'stale' may now point to a free'd memory.
11 stale[0] = 42;
12 // CHECK: AddressSanitizer: heap-use-after-free on address [[ADDR:0x[0-9a-f]+]]
13 // CHECK: WRITE of size 1 at [[ADDR]] thread T0
14 // CHECK-NEXT: {{#0 .* main .*use_after_realloc.cpp}}:[[@LINE-3]]
15 // CHECK: [[ADDR]] is located 0 bytes inside of 32-byte region
16 // CHECK: freed by thread T0 here:
17 // CHECK-NEXT: {{#0 .* realloc }}
18 // CHECK: {{ #[1-2] .* main .*use_after_realloc.cpp}}:[[@LINE-9]]
19 // CHECK: previously allocated by thread T0 here:
20 // CHECK-NEXT: {{#0 .* realloc }}
21 // CHECK: {{ #[1-2] .* main .*use_after_realloc.cpp}}:[[@LINE-14]]
22 free(ptr: buffer);
23}
24

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