1// RUN: %clang_cl_asan %Od %s %Fe%t
2// RUN: not %run %t 2>&1 | FileCheck %s
3
4#include <windows.h>
5
6typedef struct _S {
7 unsigned int bf1:1;
8 unsigned int bf2:2;
9 unsigned int bf3:3;
10 unsigned int bf4:4;
11} S;
12
13void make_access(S *s) {
14 s->bf2 = 2;
15// CHECK: AddressSanitizer: heap-use-after-free on address [[ADDR:0x[0-9a-f]+]]
16// CHECK: READ of size {{[124]}} at [[ADDR]]
17// CHECK: {{#0 .* make_access.*bitfield_uaf.cpp}}:[[@LINE-3]]
18// CHECK: {{#1 .* main}}
19}
20
21int main(void) {
22 S *s = (S*)malloc(sizeof(S));
23 free(s);
24 // CHECK: [[ADDR]] is located 0 bytes inside of 4-byte region
25 // CHECK-LABEL: freed by thread T0 here:
26 // CHECK: {{#0 .* free }}
27 // CHECK: {{ #[1-2] .* main .*bitfield_uaf.cpp}}:[[@LINE-4]]
28 // CHECK-LABEL: previously allocated by thread T0 here:
29 // CHECK: {{#0 .* malloc }}
30 // CHECK: {{ #[1-2] .* main .*bitfield_uaf.cpp}}:[[@LINE-8]]
31 make_access(s);
32 return 0;
33}
34
35

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