Files
clang-p2996/compiler-rt/test/tsan/static_init6.cc
Dan Liew fe7250c2fa Fix another case where libstdc++ is being inappropriately requested (see
r328775) for all platforms.

Given that this is the second occurance of this problem it seemed worth
fixing this problem in a more generic way. r328775 has been reverted and
now a substitution `%linux_static_libstdcplusplus` has been provided.
This substitution expands to Clang driver arguments to use a static
libstdc++ on Linux and on all other platforms it expands to nothing.

The `asan/TestCases/throw_invoke_test.cc` and
`test/tsan/static_init6.cc` test cases now use this substitution.

rdar://problem/39948818

Differential Revision: https://reviews.llvm.org/D46401

llvm-svn: 332254
2018-05-14 15:48:49 +00:00

44 lines
832 B
C++

// RUN: %clangxx_tsan %linux_static_libstdcplusplus -O1 %s -o %t && %run %t 2>&1 \
// RUN: | FileCheck %s
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
#include <sched.h>
struct Cache {
int x;
explicit Cache(int x)
: x(x) {
}
};
void *AsyncInit(void *p) {
return new Cache((int)(long)p);
}
Cache *CreateCache() {
pthread_t t;
pthread_create(&t, 0, AsyncInit, (void*)(long)rand());
void *res;
pthread_join(t, &res);
return (Cache*)res;
}
void *Thread1(void *x) {
static Cache *c = CreateCache();
if (c->x >= RAND_MAX)
exit(1);
return 0;
}
int main() {
pthread_t t[2];
pthread_create(&t[0], 0, Thread1, 0);
pthread_create(&t[1], 0, Thread1, 0);
pthread_join(t[0], 0);
pthread_join(t[1], 0);
fprintf(stderr, "PASS\n");
}
// CHECK-NOT: WARNING: ThreadSanitizer: data race