Imported Upstream version 6.10.0.49

Former-commit-id: 1d6753294b2993e1fbf92de9366bb9544db4189b
This commit is contained in:
Xamarin Public Jenkins (auto-signing)
2020-01-16 16:38:04 +00:00
parent d94e79959b
commit 468663ddbb
48518 changed files with 2789335 additions and 61176 deletions

View File

@@ -0,0 +1,17 @@
// Test that verifies TSan runtime doesn't contain compiler-emitted
// memcpy/memmove calls. It builds the binary with TSan and passes it to
// check_memcpy.sh script.
// RUN: %clangxx_tsan -O1 %s -o %t
// RUN: llvm-objdump -d %t | FileCheck %s
// REQUIRES: compiler-rt-optimized
int main() {
return 0;
}
// CHECK-NOT: callq {{.*<(__interceptor_)?mem(cpy|set)>}}
// tail calls:
// CHECK-NOT: jmpq {{.*<(__interceptor_)?mem(cpy|set)>}}

View File

@@ -0,0 +1,60 @@
// RUN: %clang_tsan -fno-sanitize=thread -shared -fPIC -O1 -DBUILD_SO=1 %s -o \
// RUN: %t.so && \
// RUN: %clang_tsan -O1 %s %t.so -o %t && %run %t 2>&1 | FileCheck %s
// RUN: llvm-objdump -t %t | FileCheck %s --check-prefix=CHECK-DUMP
// CHECK-DUMP: {{[.]preinit_array.*__local_tsan_preinit}}
// SANITIZER_CAN_USE_PREINIT_ARRAY is undefined on android.
// UNSUPPORTED: android
// Test checks if __tsan_init is called from .preinit_array.
// Without initialization from .preinit_array, __tsan_init will be called from
// constructors of the binary which are called after constructors of shared
// library.
#include <stdio.h>
#if BUILD_SO
// "volatile" is needed to avoid compiler optimize-out constructors.
volatile int counter = 0;
volatile int lib_constructor_call = 0;
volatile int tsan_init_call = 0;
__attribute__ ((constructor))
void LibConstructor() {
lib_constructor_call = ++counter;
};
#else // BUILD_SO
extern int counter;
extern int lib_constructor_call;
extern int tsan_init_call;
volatile int bin_constructor_call = 0;
__attribute__ ((constructor))
void BinConstructor() {
bin_constructor_call = ++counter;
};
namespace __tsan {
void OnInitialize() {
tsan_init_call = ++counter;
}
}
int main() {
// CHECK: TSAN_INIT 1
// CHECK: LIB_CONSTRUCTOR 2
// CHECK: BIN_CONSTRUCTOR 3
printf("TSAN_INIT %d\n", tsan_init_call);
printf("LIB_CONSTRUCTOR %d\n", lib_constructor_call);
printf("BIN_CONSTRUCTOR %d\n", bin_constructor_call);
return 0;
}
#endif // BUILD_SO

View File

@@ -0,0 +1,52 @@
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t 2>&1 | FileCheck %s
#include "../test.h"
#include <memory.h>
// A reproducer for a known issue.
// See reference to double_race.cc in tsan_rtl_report.cc for an explanation.
char buf[16];
volatile int nreport;
void __sanitizer_report_error_summary(const char *summary) {
nreport++;
}
const int kEventPCBits = 61;
extern "C" bool __tsan_symbolize_external(unsigned long pc, char *func_buf,
unsigned long func_siz,
char *file_buf,
unsigned long file_siz, int *line,
int *col) {
if (pc >> kEventPCBits) {
printf("bad PC passed to __tsan_symbolize_external: %lx\n", pc);
_exit(1);
}
return true;
}
void *Thread(void *arg) {
barrier_wait(&barrier);
memset(buf, 2, sizeof(buf));
return 0;
}
int main() {
barrier_init(&barrier, 2);
pthread_t t;
pthread_create(&t, 0, Thread, 0);
memset(buf, 1, sizeof(buf));
barrier_wait(&barrier);
pthread_join(t, 0);
return 0;
}
// CHECK: WARNING: ThreadSanitizer: data race
// CHECK: Write of size 8 at {{.*}} by thread T1:
// CHECK: #0 memset
// CHECK: #1 Thread
// CHECK-NOT: bad PC passed to __tsan_symbolize_external
// CHECK: WARNING: ThreadSanitizer: data race
// CHECK: Write of size 8 at {{.*}} by thread T1:
// CHECK: #0 Thread

View File

@@ -0,0 +1,9 @@
def getRoot(config):
if not config.parent:
return config
return getRoot(config.parent)
root = getRoot(config)
if root.host_os not in ['Linux']:
config.unsupported = True

View File

@@ -0,0 +1,36 @@
// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
pthread_mutex_t m;
void *thr(void *p) {
pthread_mutex_lock(&m);
return 0;
}
int main() {
pthread_mutexattr_t a;
pthread_mutexattr_init(&a);
pthread_mutexattr_setrobust(&a, PTHREAD_MUTEX_ROBUST);
pthread_mutex_init(&m, &a);
pthread_t th;
pthread_create(&th, 0, thr, 0);
sleep(1);
if (pthread_mutex_lock(&m) != EOWNERDEAD) {
fprintf(stderr, "not EOWNERDEAD\n");
exit(1);
}
pthread_join(th, 0);
fprintf(stderr, "DONE\n");
}
// This is a correct code, and tsan must not bark.
// CHECK-NOT: WARNING: ThreadSanitizer
// CHECK-NOT: EOWNERDEAD
// CHECK: DONE
// CHECK-NOT: WARNING: ThreadSanitizer

View File

@@ -0,0 +1,41 @@
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
#include <pthread.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <errno.h>
pthread_mutex_t m;
int x;
void *thr(void *p) {
pthread_mutex_lock(&m);
x = 42;
return 0;
}
int main() {
pthread_mutexattr_t a;
pthread_mutexattr_init(&a);
pthread_mutexattr_setrobust(&a, PTHREAD_MUTEX_ROBUST);
pthread_mutex_init(&m, &a);
pthread_t th;
pthread_create(&th, 0, thr, 0);
sleep(1);
if (pthread_mutex_trylock(&m) != EOWNERDEAD) {
fprintf(stderr, "not EOWNERDEAD\n");
exit(1);
}
x = 43;
pthread_join(th, 0);
fprintf(stderr, "DONE\n");
}
// This is a false positive, tsan must not bark at the data race.
// But currently it does.
// CHECK-NOT: WARNING: ThreadSanitizer WARNING: double lock of mutex
// CHECK: WARNING: ThreadSanitizer: data race
// CHECK-NOT: EOWNERDEAD
// CHECK: DONE
// CHECK-NOT: WARNING: ThreadSanitizer

View File

@@ -0,0 +1,6 @@
// RUN: %clang_tsan %s -pie -fPIE -o %t && %run setarch x86_64 -R %t
// REQUIRES: x86_64-target-arch
int main() {
return 0;
}

View File

@@ -0,0 +1,34 @@
// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
#include <stdio.h>
#include <stdlib.h>
// Defined by tsan.
extern "C" FILE *__interceptor_fopen(const char *file, const char *mode);
extern "C" int __interceptor_fileno(FILE *f);
extern "C" FILE *fopen(const char *file, const char *mode) {
static int first = 0;
if (__sync_lock_test_and_set(&first, 1) == 0)
printf("user fopen\n");
return __interceptor_fopen(file, mode);
}
extern "C" int fileno(FILE *f) {
static int first = 0;
if (__sync_lock_test_and_set(&first, 1) == 0)
printf("user fileno\n");
return 1;
}
int main() {
FILE *f = fopen("/dev/zero", "r");
if (f) {
char buf;
fread(&buf, 1, 1, f);
fclose(f);
}
}
// CHECK: user fopen
// CHECK-NOT: ThreadSanitizer

View File

@@ -0,0 +1,35 @@
// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
// UNSUPPORTED: powerpc64le
// FIXME: Remove the test or find how to fix this.
// On some distributions, probably with newer glibc, tsan initialization calls
// dlsym which then calls malloc and crashes because of tsan is not initialized.
// UNSUPPORTED: linux
#include <stdio.h>
// Defined by tsan.
extern "C" void *__interceptor_malloc(unsigned long size);
extern "C" void __interceptor_free(void *p);
extern "C" void *malloc(unsigned long size) {
static int first = 0;
if (__sync_lock_test_and_set(&first, 1) == 0)
fprintf(stderr, "user malloc\n");
return __interceptor_malloc(size);
}
extern "C" void free(void *p) {
__interceptor_free(p);
}
int main() {
volatile char *p = (char*)malloc(10);
p[0] = 0;
free((void*)p);
}
// CHECK: user malloc
// CHECK-NOT: ThreadSanitizer