44 lines · cpp
1// RUN: %clangxx_tsan -O0 %s -o %t2// RUN: %run %t 2>&1 | FileCheck %s3 4#include <stdio.h>5#include <stdlib.h>6 7extern "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 11long global_var;12 13int main() {14 long stack_var;15 void *heap_var = malloc(10);16 17 fprintf(stderr, "stack_var = %p\n", &stack_var);18 fprintf(stderr, "global_var = %p\n", &global_var);19 fprintf(stderr, "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(&stack_var, name, 128, &start, &size);29 fprintf(stderr, "type: %s\n", type);30 // CHECK: type: stack31 32 type = __tsan_locate_address(&global_var, name, 128, &start, &size);33 fprintf(stderr, "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(heap_var, name, 128, &start, &size);38 fprintf(stderr, "type: %s, start = %p, size = %zu\n", type, start, size);39 // CHECK: type: heap, start = [[HEAP_VAR]], size = 1040 41 free(heap_var);42 return 0;43}44