Stephen Hines | 6a211c5 | 2014-07-21 00:49:56 -0700 | [diff] [blame] | 1 | // RUN: %clang_cl_asan -O0 %s -Fe%t |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 2 | // RUN: not %run %t 2>&1 | FileCheck %s |
| 3 | |
| 4 | #include <windows.h> |
| 5 | |
| 6 | typedef 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 | |
| 13 | void 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]] |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 17 | // CHECK: {{#0 .* make_access.*bitfield_uaf.cc}}:[[@LINE-3]] |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 18 | // CHECK: {{#1 .* main}} |
| 19 | } |
| 20 | |
| 21 | int 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 .* main .*bitfield_uaf.cc}}:[[@LINE-4]] |
| 28 | // CHECK-LABEL: previously allocated by thread T0 here: |
| 29 | // CHECK: {{#0 .* malloc }} |
| 30 | // CHECK: {{#1 .* main .*bitfield_uaf.cc}}:[[@LINE-8]] |
| 31 | make_access(s); |
| 32 | return 0; |
| 33 | } |
| 34 | |