blob: a0012c74dd962a37802b060ad71a607288aa2005 [file] [log] [blame]
Stephen Hines2d1fdb22014-05-28 23:58:16 -07001// Regression test. Disabler should not depend on TSD validity.
2// RUN: LSAN_BASE="report_objects=1:use_registers=0:use_stacks=0:use_globals=0:use_tls=1"
3// RUN: %clangxx_lsan %s -o %t
4// RUN: LSAN_OPTIONS=$LSAN_BASE %run %t
5
6#include <assert.h>
7#include <pthread.h>
8#include <stdio.h>
9#include <stdlib.h>
10
11#include "sanitizer/lsan_interface.h"
12
13pthread_key_t key;
14
15void key_destructor(void *arg) {
16 __lsan::ScopedDisabler d;
17 void *p = malloc(1337);
18 // Break optimization.
19 fprintf(stderr, "Test alloc: %p.\n", p);
20 pthread_setspecific(key, 0);
21}
22
23void *thread_func(void *arg) {
24 int res = pthread_setspecific(key, (void*)1);
25 assert(res == 0);
26 return 0;
27}
28
29int main() {
30 int res = pthread_key_create(&key, &key_destructor);
31 assert(res == 0);
32 pthread_t thread_id;
33 res = pthread_create(&thread_id, 0, thread_func, 0);
34 assert(res == 0);
35 res = pthread_join(thread_id, 0);
36 assert(res == 0);
37 return 0;
38}