blob: 982fb899ec5bc893e832692c5a0f9b15b2572722 [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"
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -08003// RUN: %clang_lsan %s -o %t
Stephen Hines2d1fdb22014-05-28 23:58:16 -07004// 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) {
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080016 __lsan_disable();
Stephen Hines2d1fdb22014-05-28 23:58:16 -070017 void *p = malloc(1337);
18 // Break optimization.
19 fprintf(stderr, "Test alloc: %p.\n", p);
20 pthread_setspecific(key, 0);
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -080021 __lsan_enable();
Stephen Hines2d1fdb22014-05-28 23:58:16 -070022}
23
24void *thread_func(void *arg) {
25 int res = pthread_setspecific(key, (void*)1);
26 assert(res == 0);
27 return 0;
28}
29
30int main() {
31 int res = pthread_key_create(&key, &key_destructor);
32 assert(res == 0);
33 pthread_t thread_id;
34 res = pthread_create(&thread_id, 0, thread_func, 0);
35 assert(res == 0);
36 res = pthread_join(thread_id, 0);
37 assert(res == 0);
38 return 0;
39}