1// Test that stacks of non-main threads are included in the root set. 2// RUN: LSAN_BASE="report_objects=1:use_registers=0" 3// RUN: %clangxx_lsan -pthread %s -o %t 4// RUN: LSAN_OPTIONS=$LSAN_BASE:"use_stacks=0" not %run %t 2>&1 | FileCheck %s 5// RUN: LSAN_OPTIONS=$LSAN_BASE:"use_stacks=1" %run %t 2>&1 6// RUN: LSAN_OPTIONS="" %run %t 2>&1 7 8#include <assert.h> 9#include <pthread.h> 10#include <stdio.h> 11#include <stdlib.h> 12 13extern "C" 14void *stacks_thread_func(void *arg) { 15 int *sync = reinterpret_cast<int *>(arg); 16 void *p = malloc(1337); 17 fprintf(stderr, "Test alloc: %p.\n", p); 18 fflush(stderr); 19 __sync_fetch_and_xor(sync, 1); 20 while (true) 21 pthread_yield(); 22} 23 24int main() { 25 int sync = 0; 26 pthread_t thread_id; 27 int res = pthread_create(&thread_id, 0, stacks_thread_func, &sync); 28 assert(res == 0); 29 while (!__sync_fetch_and_xor(&sync, 0)) 30 pthread_yield(); 31 return 0; 32} 33// CHECK: Test alloc: [[ADDR:.*]]. 34// CHECK: LeakSanitizer: detected memory leaks 35// CHECK: [[ADDR]] (1337 bytes) 36// CHECK: SUMMARY: {{(Leak|Address)}}Sanitizer: 37