1 // Test that registers of running threads are included in the root set.
2 // RUN: %clangxx_lsan -pthread %s -o %t
3 // RUN: %env_lsan_opts="report_objects=1:use_stacks=0:use_registers=0" not %run %t 2>&1 | FileCheck %s
4 // RUN: %env_lsan_opts="report_objects=1:use_stacks=0:use_registers=1" %run %t 2>&1
5 // RUN: %env_lsan_opts="" %run %t 2>&1
7 #include "sanitizer_common/print_address.h"
14 extern "C" void *registers_thread_func(void *arg
) {
15 int *sync
= reinterpret_cast<int *>(arg
);
16 void *p
= malloc(1337);
17 print_address("Test alloc: ", 1, p
);
20 // To store the pointer, choose a register which is unlikely to be reused by
22 #if defined(__i386__) || defined(__i686__)
26 #elif defined(__x86_64__)
30 #elif defined(__mips__)
34 #elif defined(__arm__)
38 #elif defined(__aarch64__)
39 // x9-10 are used. x11-12 are probably used.
40 // So we pick x13 to be safe and x14 as a backup.
41 // (x13 known to be used on Ubuntu Focal)
46 #elif defined(__loongarch_lp64)
47 asm("move $s8, %0" : : "r"(p
));
48 #elif defined(__powerpc__)
52 #elif defined(__s390x__)
56 #elif defined(__riscv)
61 #error "Test is not supported on this architecture."
63 __sync_fetch_and_xor(sync
, 1);
71 int res
= pthread_create(&thread_id
, 0, registers_thread_func
, &sync
);
73 while (!__sync_fetch_and_xor(&sync
, 0))
77 // CHECK: Test alloc: [[ADDR:0x[0-9,a-f]+]]
78 // CHECK: LeakSanitizer: detected memory leaks
79 // CHECK: [[ADDR]] (1337 bytes)
80 // CHECK: SUMMARY: {{.*}}Sanitizer: