1 | // RUN: %clangxx_tsan -O0 %s -o %t |
2 | // RUN: %run %t 2>&1 | FileCheck %s |
3 | |
4 | #include <stdio.h> |
5 | #include <stdlib.h> |
6 | |
7 | extern "C" const char * |
8 | __tsan_locate_address(void *addr, char *name, size_t name_size, |
9 | void **region_address_ptr, size_t *region_size_ptr); |
10 | |
11 | long global_var; |
12 | |
13 | int main() { |
14 | long stack_var; |
15 | void *heap_var = malloc(size: 10); |
16 | |
17 | fprintf(stderr, format: "stack_var = %p\n" , &stack_var); |
18 | fprintf(stderr, format: "global_var = %p\n" , &global_var); |
19 | fprintf(stderr, format: "heap_var = %p\n" , heap_var); |
20 | // CHECK: stack_var = [[STACK_VAR:0x[0-9a-f]+]] |
21 | // CHECK: global_var = [[GLOBAL_VAR:0x[0-9a-f]+]] |
22 | // CHECK: heap_var = [[HEAP_VAR:0x[0-9a-f]+]] |
23 | |
24 | const char *type; |
25 | char name[128]; |
26 | void *start; |
27 | size_t size; |
28 | type = __tsan_locate_address(addr: &stack_var, name, name_size: 128, region_address_ptr: &start, region_size_ptr: &size); |
29 | fprintf(stderr, format: "type: %s\n" , type); |
30 | // CHECK: type: stack |
31 | |
32 | type = __tsan_locate_address(addr: &global_var, name, name_size: 128, region_address_ptr: &start, region_size_ptr: &size); |
33 | fprintf(stderr, format: "type: %s, name = %s, start = %p, size = %zu\n" , type, name, |
34 | start, size); |
35 | // CHECK: type: global, name = global_var, start = [[GLOBAL_VAR]], size = {{8|0}} |
36 | |
37 | type = __tsan_locate_address(addr: heap_var, name, name_size: 128, region_address_ptr: &start, region_size_ptr: &size); |
38 | fprintf(stderr, format: "type: %s, start = %p, size = %zu\n" , type, start, size); |
39 | // CHECK: type: heap, start = [[HEAP_VAR]], size = 10 |
40 | |
41 | free(ptr: heap_var); |
42 | return 0; |
43 | } |
44 | |