Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / msan / dtls_test.c
blob3c384256147a0a9ed5e73d1c278f13248f33d36d
1 /* RUN: %clang_msan -g %s -o %t
2 RUN: %clang_msan -g %s -DBUILD_SO -fPIC -o %t-so.so -shared
3 RUN: %run %t 2>&1
5 Regression test for a bug in msan/glibc integration,
6 see https://sourceware.org/bugzilla/show_bug.cgi?id=16291
7 and https://github.com/google/sanitizers/issues/547
9 XFAIL: target={{.*freebsd.*}}
10 UNSUPPORTED: target=powerpc{{.*}}
12 // Reports use-of-uninitialized-value, not analyzed
13 XFAIL: target={{.*netbsd.*}}
17 #ifndef BUILD_SO
18 #include <assert.h>
19 #include <dlfcn.h>
20 #include <stdio.h>
21 #include <stdlib.h>
22 #include <pthread.h>
24 typedef long *(* get_t)();
25 get_t GetTls;
26 void *Thread1(void *unused) {
27 long uninitialized;
28 long *x = GetTls();
29 if (*x)
30 fprintf(stderr, "bar\n");
31 *x = uninitialized;
32 fprintf(stderr, "stack: %p dtls: %p\n", &x, x);
33 return 0;
36 void *Thread2(void *unused) {
37 long *x = GetTls();
38 fprintf(stderr, "stack: %p dtls: %p\n", &x, x);
39 if (*x)
40 fprintf(stderr, "foo\n"); // False negative here.
41 return 0;
44 int main(int argc, char *argv[]) {
45 char path[4096];
46 snprintf(path, sizeof(path), "%s-so.so", argv[0]);
47 int i;
49 void *handle = dlopen(path, RTLD_LAZY);
50 if (!handle) fprintf(stderr, "%s\n", dlerror());
51 assert(handle != 0);
52 GetTls = (get_t)dlsym(handle, "GetTls");
53 assert(dlerror() == 0);
55 pthread_t t;
56 pthread_create(&t, 0, Thread1, 0);
57 pthread_join(t, 0);
58 pthread_create(&t, 0, Thread2, 0);
59 pthread_join(t, 0);
60 return 0;
62 #else // BUILD_SO
63 __thread long huge_thread_local_array[1 << 17];
64 long *GetTls() {
65 return &huge_thread_local_array[0];
67 #endif