Import Cobalt 24.master.0.1032339
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/CMakeLists.txt b/third_party/llvm-project/compiler-rt/test/tsan/CMakeLists.txt
index ba0fd9f..25e95aa 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/CMakeLists.txt
+++ b/third_party/llvm-project/compiler-rt/test/tsan/CMakeLists.txt
@@ -1,13 +1,14 @@
set(TSAN_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
set(TSAN_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS})
-if(${COMPILER_RT_DEFAULT_TARGET_ARCH} MATCHES "x86_64")
+if(${COMPILER_RT_DEFAULT_TARGET_ARCH} MATCHES "(x86_64|s390x)")
list(APPEND TSAN_TEST_DEPS GotsanRuntimeCheck)
endif()
if(NOT COMPILER_RT_STANDALONE_BUILD)
list(APPEND TSAN_TEST_DEPS tsan)
endif()
if(COMPILER_RT_LIBCXX_PATH AND
+ COMPILER_RT_LIBCXXABI_PATH AND
COMPILER_RT_TEST_COMPILER_ID STREQUAL "Clang"
AND NOT APPLE AND NOT ANDROID)
list(APPEND TSAN_TEST_DEPS libcxx_tsan)
@@ -16,7 +17,13 @@
set(TSAN_HAS_LIBCXX False)
endif()
+set(TSAN_DYNAMIC_TEST_DEPS ${TSAN_TEST_DEPS})
set(TSAN_TESTSUITES)
+set(TSAN_DYNAMIC_TESTSUITES)
+
+if (NOT DEFINED TSAN_TEST_DEFLAKE_THRESHOLD)
+ set(TSAN_TEST_DEFLAKE_THRESHOLD "10")
+endif()
set(TSAN_TEST_ARCH ${TSAN_SUPPORTED_ARCH})
if(APPLE)
@@ -25,18 +32,42 @@
foreach(arch ${TSAN_TEST_ARCH})
set(TSAN_TEST_APPLE_PLATFORM "osx")
+ set(TSAN_TEST_MIN_DEPLOYMENT_TARGET_FLAG "${DARWIN_osx_MIN_VER_FLAG}")
set(TSAN_TEST_TARGET_ARCH ${arch})
string(TOLOWER "-${arch}" TSAN_TEST_CONFIG_SUFFIX)
get_test_cc_for_arch(${arch} TSAN_TEST_TARGET_CC TSAN_TEST_TARGET_CFLAGS)
+ string(REPLACE ";" " " LIBDISPATCH_CFLAGS_STRING " ${COMPILER_RT_TEST_LIBDISPATCH_CFLAGS}")
+ string(APPEND TSAN_TEST_TARGET_CFLAGS ${LIBDISPATCH_CFLAGS_STRING})
+
+ if (COMPILER_RT_HAS_MSSE4_2_FLAG)
+ string(APPEND TSAN_TEST_TARGET_CFLAGS " -msse4.2 ")
+ endif()
+
string(TOUPPER ${arch} ARCH_UPPER_CASE)
set(CONFIG_NAME ${ARCH_UPPER_CASE}Config)
configure_lit_site_cfg(
- ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
- ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg)
+ ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
+ ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py
+ MAIN_CONFIG
+ ${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py
+ )
list(APPEND TSAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
+
+ if(COMPILER_RT_TSAN_HAS_STATIC_RUNTIME)
+ string(TOLOWER "-${arch}-${OS_NAME}-dynamic" TSAN_TEST_CONFIG_SUFFIX)
+ set(CONFIG_NAME ${ARCH_UPPER_CASE}${OS_NAME}DynamicConfig)
+ configure_lit_site_cfg(
+ ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
+ ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py
+ MAIN_CONFIG
+ ${CMAKE_CURRENT_SOURCE_DIR}/lit.cfg.py
+ )
+ list(APPEND TSAN_DYNAMIC_TESTSUITES
+ ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
+ endif()
endforeach()
# iOS and iOS simulator test suites
@@ -45,52 +76,68 @@
# variable to select which iOS device or simulator to use, e.g.:
# SANITIZER_IOSSIM_TEST_DEVICE_IDENTIFIER="iPhone 6"
if(APPLE)
- set(EXCLUDE_FROM_ALL ON)
-
set(TSAN_TEST_TARGET_CC ${COMPILER_RT_TEST_COMPILER})
-
- set(TSAN_TEST_APPLE_PLATFORM "iossim")
- set(arch "x86_64")
- set(TSAN_TEST_TARGET_ARCH ${arch})
- set(TSAN_TEST_TARGET_CFLAGS "-arch ${arch} -isysroot ${DARWIN_iossim_SYSROOT} ${COMPILER_RT_TEST_COMPILER_CFLAGS}")
- set(TSAN_TEST_CONFIG_SUFFIX "-${arch}-${TSAN_TEST_APPLE_PLATFORM}")
- string(TOUPPER ${arch} ARCH_UPPER_CASE)
- set(CONFIG_NAME "IOSSim${ARCH_UPPER_CASE}Config")
- configure_lit_site_cfg(
- ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
- ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg
+ set(TSAN_APPLE_PLATFORMS ${TSAN_SUPPORTED_OS})
+ foreach(platform ${TSAN_APPLE_PLATFORMS})
+ if ("${platform}" STREQUAL "osx")
+ # Skip macOS because it's handled by the code above that builds tests for the host machine.
+ continue()
+ endif()
+ list_intersect(
+ TSAN_TEST_${platform}_ARCHS
+ TSAN_SUPPORTED_ARCH
+ DARWIN_${platform}_ARCHS
)
- add_lit_testsuite(check-tsan-iossim-${arch} "ThreadSanitizer iOS Simulator ${arch} tests"
- ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/
- DEPENDS ${TSAN_TEST_DEPS})
-
- set(TSAN_TEST_APPLE_PLATFORM "ios")
- set(arch "arm64")
- set(TSAN_TEST_TARGET_ARCH ${arch})
- set(TSAN_TEST_TARGET_CFLAGS "-arch ${arch} -isysroot ${DARWIN_ios_SYSROOT} ${COMPILER_RT_TEST_COMPILER_CFLAGS}")
- set(TSAN_TEST_CONFIG_SUFFIX "-${arch}-${TSAN_TEST_APPLE_PLATFORM}")
- string(TOUPPER ${arch} ARCH_UPPER_CASE)
- set(CONFIG_NAME "IOS${ARCH_UPPER_CASE}Config")
- configure_lit_site_cfg(
- ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
- ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg
- )
- add_lit_testsuite(check-tsan-ios-${arch} "ThreadSanitizer iOS Simulator ${arch} tests"
- ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/
- DEPENDS ${TSAN_TEST_DEPS})
-
- set(EXCLUDE_FROM_ALL OFF)
+ foreach(arch ${TSAN_TEST_${platform}_ARCHS})
+ get_test_cflags_for_apple_platform(
+ "${platform}"
+ "${arch}"
+ TSAN_TEST_TARGET_CFLAGS
+ )
+ string(TOUPPER "${arch}" ARCH_UPPER_CASE)
+ get_capitalized_apple_platform("${platform}" PLATFORM_CAPITALIZED)
+ set(CONFIG_NAME "${PLATFORM_CAPITALIZED}${ARCH_UPPER_CASE}Config")
+ set(TSAN_TEST_CONFIG_SUFFIX "-${arch}-${platform}")
+ set(TSAN_TEST_APPLE_PLATFORM "${platform}")
+ set(TSAN_TEST_TARGET_ARCH "${arch}")
+ set(TSAN_TEST_MIN_DEPLOYMENT_TARGET_FLAG "${DARWIN_${platform}_MIN_VER_FLAG}")
+ configure_lit_site_cfg(
+ ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.py.in
+ ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg.py
+ )
+ add_lit_testsuite(check-tsan-${platform}-${arch} "ThreadSanitizer ${platform} ${arch} tests"
+ ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/
+ EXCLUDE_FROM_CHECK_ALL
+ DEPENDS ${TSAN_TEST_DEPS})
+ endforeach()
+ endforeach()
endif()
if(COMPILER_RT_INCLUDE_TESTS)
configure_lit_site_cfg(
- ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.in
- ${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg)
+ ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in
+ ${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg.py)
+ if(COMPILER_RT_TSAN_HAS_STATIC_RUNTIME)
+ configure_lit_site_cfg(
+ ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.py.in
+ ${CMAKE_CURRENT_BINARY_DIR}/Unit/dynamic/lit.site.cfg.py)
+ endif()
list(APPEND TSAN_TEST_DEPS TsanUnitTests)
list(APPEND TSAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit)
+ if(COMPILER_RT_TSAN_HAS_STATIC_RUNTIME)
+ list(APPEND TSAN_DYNAMIC_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit/dynamic)
+ endif()
endif()
add_lit_testsuite(check-tsan "Running ThreadSanitizer tests"
${TSAN_TESTSUITES}
DEPENDS ${TSAN_TEST_DEPS})
set_target_properties(check-tsan PROPERTIES FOLDER "Compiler-RT Tests")
+
+if(COMPILER_RT_TSAN_HAS_STATIC_RUNTIME)
+ add_lit_testsuite(check-tsan-dynamic "Running the ThreadSanitizer tests with dynamic runtime"
+ ${TSAN_DYNAMIC_TESTSUITES}
+ EXCLUDE_FROM_CHECK_ALL
+ DEPENDS ${TSAN_DYNAMIC_TEST_DEPS})
+ set_target_properties(check-tsan-dynamic PROPERTIES FOLDER "Compiler-RT Misc")
+endif()
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/debug_external.cc b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/debug_external.cpp
similarity index 90%
rename from third_party/llvm-project/compiler-rt/test/tsan/Darwin/debug_external.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/Darwin/debug_external.cpp
index 2418a27..6539a18 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/debug_external.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/debug_external.cpp
@@ -42,7 +42,13 @@
return 0;
}
-void __tsan_on_report(void *report) {
+// Required for dyld macOS 12.0+
+#if (__APPLE__)
+__attribute__((weak))
+#endif
+__attribute__((disable_sanitizer_instrumentation))
+extern "C" void
+__tsan_on_report(void *report) {
const char *type;
void *addr;
void *start;
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/dispatch_once_deadlock.mm b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/dispatch_once_deadlock.mm
deleted file mode 100644
index e109f64..0000000
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/dispatch_once_deadlock.mm
+++ /dev/null
@@ -1,41 +0,0 @@
-// Check that calling dispatch_once from a report callback works.
-
-// RUN: %clang_tsan %s -o %t -framework Foundation
-// RUN: not %run %t 2>&1 | FileCheck %s
-
-#import <Foundation/Foundation.h>
-#import <pthread.h>
-
-long g = 0;
-long h = 0;
-void f() {
- static dispatch_once_t onceToken;
- dispatch_once(&onceToken, ^{
- g++;
- });
- h++;
-}
-
-extern "C" void __tsan_on_report() {
- fprintf(stderr, "Report.\n");
- f();
-}
-
-int main() {
- fprintf(stderr, "Hello world.\n");
-
- f();
-
- pthread_mutex_t mutex = {0};
- pthread_mutex_lock(&mutex);
-
- fprintf(stderr, "g = %ld.\n", g);
- fprintf(stderr, "h = %ld.\n", h);
- fprintf(stderr, "Done.\n");
-}
-
-// CHECK: Hello world.
-// CHECK: Report.
-// CHECK: g = 1
-// CHECK: h = 2
-// CHECK: Done.
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/dlopen.cc b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/dlopen.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/Darwin/dlopen.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/Darwin/dlopen.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/dyld-insert-libraries.c b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/dyld-insert-libraries.c
new file mode 100644
index 0000000..2e28a23
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/dyld-insert-libraries.c
@@ -0,0 +1,112 @@
+// Test that dyld interposition works in the presence of DYLD_INSERT_LIBRARIES.
+// Additionally, the injected library also has a pthread introspection hook that
+// calls intercepted APIs before and after calling through to the TSan hook.
+// This mirrors what libBacktraceRecording.dylib (Xcode 'Queue Debugging'
+// feature) does.
+
+// RUN: %clang_tsan %s -o %t
+// RUN: %clang_tsan %s -o %t.dylib -fno-sanitize=thread -dynamiclib -DSHARED_LIB
+//
+// RUN: env DYLD_INSERT_LIBRARIES=%t.dylib %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
+//
+// XFAIL: ios
+
+#include <assert.h>
+#include <pthread.h>
+#include <stdio.h>
+#include <string.h>
+
+#if defined(SHARED_LIB)
+enum {
+ PTHREAD_INTROSPECTION_THREAD_CREATE = 1,
+ PTHREAD_INTROSPECTION_THREAD_START,
+ PTHREAD_INTROSPECTION_THREAD_TERMINATE,
+ PTHREAD_INTROSPECTION_THREAD_DESTROY,
+};
+typedef void (*pthread_introspection_hook_t)(unsigned int event,
+ pthread_t thread, void *addr,
+ size_t size);
+extern pthread_introspection_hook_t pthread_introspection_hook_install(
+ pthread_introspection_hook_t hook);
+
+static pthread_introspection_hook_t previous_pthread_hook;
+static void pthread_introspection_hook(unsigned int event, pthread_t thread, void *addr, size_t size) {
+ pthread_t self;
+ const unsigned k_max_thread_name_size = 64;
+ char name[k_max_thread_name_size];
+
+ // Use some intercepted APIs *before* TSan hook runs.
+ {
+ self = pthread_self();
+ pthread_getname_np(self, name, k_max_thread_name_size);
+ if (strlen(name) == 0) {
+ strlcpy(name, "n/a", 4);
+ }
+ }
+
+ // This calls through to the TSan-installed hook, because the injected library
+ // constructor (see __library_initializer() below) runs after the TSan
+ // initializer. It replaces and forward to the previously-installed TSan
+ // introspection hook (very similar to what libBacktraceRecording.dylib does).
+ assert(previous_pthread_hook);
+ previous_pthread_hook(event, thread, addr, size);
+
+ // Use some intercepted APIs *after* TSan hook runs.
+ {
+ assert(self == pthread_self());
+ char name2[k_max_thread_name_size];
+ pthread_getname_np(self, name2, k_max_thread_name_size);
+ if (strlen(name2) == 0) {
+ strlcpy(name2, "n/a", 4);
+ }
+ assert(strcmp(name, name2) == 0);
+ }
+
+ switch (event) {
+ case PTHREAD_INTROSPECTION_THREAD_CREATE:
+ fprintf(stderr, "THREAD_CREATE %p, self: %p, name: %s\n", thread, self, name);
+ break;
+ case PTHREAD_INTROSPECTION_THREAD_START:
+ fprintf(stderr, "THREAD_START %p, self: %p, name: %s\n", thread, self, name);
+ break;
+ case PTHREAD_INTROSPECTION_THREAD_TERMINATE:
+ fprintf(stderr, "THREAD_TERMINATE %p, self: %p, name: %s\n", thread, self, name);
+ break;
+ case PTHREAD_INTROSPECTION_THREAD_DESTROY:
+ fprintf(stderr, "THREAD_DESTROY %p, self: %p, name: %s\n", thread, self, name);
+ break;
+ }
+}
+
+__attribute__((constructor))
+static void __library_initializer(void) {
+ fprintf(stderr, "__library_initializer\n");
+ previous_pthread_hook = pthread_introspection_hook_install(pthread_introspection_hook);
+}
+
+#else // defined(SHARED_LIB)
+
+void *Thread(void *a) {
+ pthread_setname_np("child thread");
+ fprintf(stderr, "Hello from pthread\n");
+ return NULL;
+}
+
+int main() {
+ fprintf(stderr, "main\n");
+ pthread_t t;
+ pthread_create(&t, NULL, Thread, NULL);
+ pthread_join(t, NULL);
+ fprintf(stderr, "Done.\n");
+}
+#endif // defined(SHARED_LIB)
+
+// CHECK: __library_initializer
+// CHECK: main
+// Ignore TSan background thread.
+// CHECK: THREAD_CREATE
+// CHECK: THREAD_CREATE [[CHILD:0x[0-9a-f]+]]
+// CHECK: THREAD_START [[CHILD]], self: [[CHILD]], name: n/a
+// CHECK: Hello from pthread
+// CHECK: THREAD_TERMINATE [[CHILD]], self: [[CHILD]], name: child thread
+// CHECK: THREAD_DESTROY [[CHILD]]
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/dyld-library-path.c b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/dyld-library-path.c
new file mode 100644
index 0000000..729c45d
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/dyld-library-path.c
@@ -0,0 +1,22 @@
+// Test that dyld interposition works in the presence of DYLD_LIBRARY_PATH.
+
+// RUN: %clang_tsan %s -o %t
+// RUN: env DYLD_LIBRARY_PATH=/usr/lib/system/introspection/ %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
+
+#include <pthread.h>
+#include <stdio.h>
+
+void *Thread(void *a) {
+ fprintf(stderr, "Hello from pthread\n");
+ return NULL;
+}
+
+int main() {
+ pthread_t t;
+ pthread_create(&t, NULL, Thread, NULL);
+ pthread_join(t, NULL);
+ fprintf(stderr, "Done.\n");
+}
+
+// CHECK: Hello from pthread
+// CHECK: Done.
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/external-dups.cc b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/external-dups.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/Darwin/external-dups.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/Darwin/external-dups.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/external-ignore-noninstrumented.cc b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/external-ignore-noninstrumented.cpp
similarity index 78%
rename from third_party/llvm-project/compiler-rt/test/tsan/Darwin/external-ignore-noninstrumented.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/Darwin/external-ignore-noninstrumented.cpp
index d2acaf5..916b0b8 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/external-ignore-noninstrumented.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/external-ignore-noninstrumented.cpp
@@ -1,7 +1,7 @@
-// RUN: %clangxx_tsan -shared %p/external-lib.cc -fno-sanitize=thread -DUSE_TSAN_CALLBACKS \
+// RUN: %clangxx_tsan -shared %p/external-lib.cpp -fno-sanitize=thread -DUSE_TSAN_CALLBACKS \
// RUN: -o %t-lib.dylib -install_name @rpath/`basename %t-lib.dylib`
-// RUN: %clangxx_tsan -shared %p/external-noninstrumented-module.cc %t-lib.dylib -fno-sanitize=thread \
+// RUN: %clangxx_tsan -shared %p/external-noninstrumented-module.cpp %t-lib.dylib -fno-sanitize=thread \
// RUN: -o %t-module.dylib -install_name @rpath/`basename %t-module.dylib`
// RUN: %clangxx_tsan %s %t-module.dylib -o %t
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/external-lib.cc b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/external-lib.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/Darwin/external-lib.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/Darwin/external-lib.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/external-noninstrumented-module.cc b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/external-noninstrumented-module.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/Darwin/external-noninstrumented-module.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/Darwin/external-noninstrumented-module.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/external-swift-debugging.cc b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/external-swift-debugging.cpp
similarity index 94%
rename from third_party/llvm-project/compiler-rt/test/tsan/Darwin/external-swift-debugging.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/Darwin/external-swift-debugging.cpp
index 603734e..72335ed 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/external-swift-debugging.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/external-swift-debugging.cpp
@@ -45,8 +45,8 @@
fprintf(stderr, "Done.\n");
}
-extern "C"
-void __tsan_on_report(void *report) {
+extern "C" __attribute__((disable_sanitizer_instrumentation)) void
+__tsan_on_report(void *report) {
const char *description;
int count;
int stack_count, mop_count, loc_count, mutex_count, thread_count,
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/external-swift.cc b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/external-swift.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/Darwin/external-swift.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/Darwin/external-swift.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/external.cc b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/external.cpp
similarity index 93%
rename from third_party/llvm-project/compiler-rt/test/tsan/Darwin/external.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/Darwin/external.cpp
index e72281a..3869c7a 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/external.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/external.cpp
@@ -1,12 +1,12 @@
-// RUN: %clangxx_tsan %p/external-lib.cc -shared \
+// RUN: %clangxx_tsan %p/external-lib.cpp -shared \
// RUN: -o %t-lib-instrumented.dylib \
// RUN: -install_name @rpath/`basename %t-lib-instrumented.dylib`
-// RUN: %clangxx_tsan %p/external-lib.cc -shared -fno-sanitize=thread \
+// RUN: %clangxx_tsan %p/external-lib.cpp -shared -fno-sanitize=thread \
// RUN: -o %t-lib-noninstrumented.dylib \
// RUN: -install_name @rpath/`basename %t-lib-noninstrumented.dylib`
-// RUN: %clangxx_tsan %p/external-lib.cc -shared -fno-sanitize=thread -DUSE_TSAN_CALLBACKS \
+// RUN: %clangxx_tsan %p/external-lib.cpp -shared -fno-sanitize=thread -DUSE_TSAN_CALLBACKS \
// RUN: -o %t-lib-noninstrumented-callbacks.dylib \
// RUN: -install_name @rpath/`basename %t-lib-noninstrumented-callbacks.dylib`
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-after.mm b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-after.mm
deleted file mode 100644
index 4d66c50..0000000
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-after.mm
+++ /dev/null
@@ -1,41 +0,0 @@
-// RUN: %clang_tsan %s -o %t -framework Foundation
-// RUN: %run %t 2>&1 | FileCheck %s
-
-#import <Foundation/Foundation.h>
-
-long my_global;
-long my_global2;
-
-void callback(void *context) {
- my_global2 = 42;
-
- dispatch_async(dispatch_get_main_queue(), ^{
- CFRunLoopStop(CFRunLoopGetMain());
- });
-}
-
-int main(int argc, const char *argv[]) {
- fprintf(stderr, "start\n");
-
- my_global = 10;
- dispatch_queue_t q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10 * NSEC_PER_MSEC)), q, ^{
- my_global = 42;
-
- dispatch_async(dispatch_get_main_queue(), ^{
- CFRunLoopStop(CFRunLoopGetMain());
- });
- });
- CFRunLoopRun();
-
- my_global2 = 10;
- dispatch_after_f(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10 * NSEC_PER_MSEC)), q, NULL, &callback);
- CFRunLoopRun();
-
- fprintf(stderr, "done\n");
- return 0;
-}
-
-// CHECK: start
-// CHECK: done
-// CHECK-NOT: WARNING: ThreadSanitizer
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-apply.mm b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-apply.mm
deleted file mode 100644
index d9d2562..0000000
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-apply.mm
+++ /dev/null
@@ -1,48 +0,0 @@
-// RUN: %clang_tsan %s -o %t -framework Foundation
-// RUN: %run %t 2>&1 | FileCheck %s
-
-#import <Foundation/Foundation.h>
-
-#import "../test.h"
-
-long global;
-long array[2];
-
-void callback(void *context, size_t i) {
- long n = global;
- array[i] = n + i;
- barrier_wait(&barrier);
-}
-
-int main(int argc, const char *argv[]) {
- barrier_init(&barrier, 2);
- fprintf(stderr, "start\n");
-
- // Warm up GCD (workaround for macOS Sierra where dispatch_apply might run single-threaded).
- dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ });
-
- dispatch_queue_t q = dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT);
-
- global = 42;
-
- dispatch_apply(100, q, ^(size_t i) {
- long n = global;
- array[i] = n + i;
- barrier_wait(&barrier);
- });
-
- for (int i = 0; i < 100; i++) {
- fprintf(stderr, "array[%d] = %ld\n", i, array[i]);
- }
-
- global = 43;
-
- dispatch_apply_f(100, q, NULL, &callback);
-
- fprintf(stderr, "done\n");
- return 0;
-}
-
-// CHECK: start
-// CHECK: done
-// CHECK-NOT: WARNING: ThreadSanitizer
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-async-norace.mm b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-async-norace.mm
deleted file mode 100644
index 83f8c0d..0000000
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-async-norace.mm
+++ /dev/null
@@ -1,26 +0,0 @@
-// RUN: %clang_tsan %s -o %t -framework Foundation
-// RUN: %run %t 2>&1 | FileCheck %s
-
-#import <Foundation/Foundation.h>
-
-long global;
-
-int main() {
- NSLog(@"Hello world.");
-
- global = 42;
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- global = 43;
-
- dispatch_sync(dispatch_get_main_queue(), ^{
- CFRunLoopStop(CFRunLoopGetCurrent());
- });
- });
-
- CFRunLoopRun();
- NSLog(@"Done.");
-}
-
-// CHECK: Hello world.
-// CHECK: Done.
-// CHECK-NOT: WARNING: ThreadSanitizer
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-blocks.mm b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-blocks.mm
deleted file mode 100644
index 1aac7e1..0000000
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-blocks.mm
+++ /dev/null
@@ -1,34 +0,0 @@
-// RUN: %clangxx_tsan %s -o %t -framework Foundation
-// RUN: %run %t 2>&1 | FileCheck %s
-
-#import <Foundation/Foundation.h>
-
-int main() {
- fprintf(stderr, "start\n");
-
- dispatch_queue_t background_q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
- dispatch_queue_t main_q = dispatch_get_main_queue();
-
- dispatch_async(background_q, ^{
- __block long block_var = 0;
-
- dispatch_sync(main_q, ^{
- block_var = 42;
- });
-
- fprintf(stderr, "block_var = %ld\n", block_var);
-
- dispatch_sync(dispatch_get_main_queue(), ^{
- CFRunLoopStop(CFRunLoopGetCurrent());
- });
- });
-
- CFRunLoopRun();
- fprintf(stderr, "done\n");
-}
-
-// CHECK: start
-// CHECK: block_var = 42
-// CHECK: done
-// CHECK-NOT: WARNING: ThreadSanitizer
-// CHECK-NOT: CHECK failed
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-data.mm b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-data.mm
deleted file mode 100644
index d451cf5..0000000
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-data.mm
+++ /dev/null
@@ -1,36 +0,0 @@
-// RUN: %clang_tsan %s -o %t -framework Foundation
-// RUN: %run %t 2>&1 | FileCheck %s
-
-#import <Foundation/Foundation.h>
-
-long global;
-
-int main(int argc, const char *argv[]) {
- fprintf(stderr, "Hello world.\n");
-
- dispatch_queue_t q = dispatch_queue_create("my.queue", DISPATCH_QUEUE_SERIAL);
- dispatch_semaphore_t sem = dispatch_semaphore_create(0);
-
- global = 44;
- dispatch_data_t data = dispatch_data_create("buffer", 6, q, ^{
- fprintf(stderr, "Data destructor.\n");
- global++;
-
- dispatch_semaphore_signal(sem);
- });
- dispatch_release(data);
- data = nil;
-
- dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
-
- data = dispatch_data_create("buffer", 6, q, DISPATCH_DATA_DESTRUCTOR_DEFAULT);
- dispatch_release(data);
- data = nil;
-
- fprintf(stderr, "Done.\n");
-}
-
-// CHECK: Hello world.
-// CHECK: Data destructor.
-// CHECK-NOT: WARNING: ThreadSanitizer
-// CHECK: Done.
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-groups-destructor.mm b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-groups-destructor.mm
deleted file mode 100644
index 05c65c0..0000000
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-groups-destructor.mm
+++ /dev/null
@@ -1,43 +0,0 @@
-// RUN: %clangxx_tsan %s -o %t -framework Foundation
-// RUN: %run %t 2>&1 | FileCheck %s
-
-#import <Foundation/Foundation.h>
-
-#import <memory>
-#import <stdatomic.h>
-
-_Atomic(long) destructor_counter = 0;
-
-struct MyStruct {
- virtual ~MyStruct() {
- usleep(10000);
- atomic_fetch_add_explicit(&destructor_counter, 1, memory_order_relaxed);
- }
-};
-
-int main(int argc, const char *argv[]) {
- fprintf(stderr, "Hello world.\n");
-
- dispatch_queue_t q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
- dispatch_group_t g = dispatch_group_create();
-
- for (int i = 0; i < 100; i++) {
- std::shared_ptr<MyStruct> shared(new MyStruct());
-
- dispatch_group_async(g, q, ^{
- shared.get(); // just to make sure the object is captured by the block
- });
- }
-
- dispatch_group_wait(g, DISPATCH_TIME_FOREVER);
-
- if (destructor_counter != 100) {
- abort();
- }
-
- fprintf(stderr, "Done.\n");
-}
-
-// CHECK: Hello world.
-// CHECK-NOT: WARNING: ThreadSanitizer
-// CHECK: Done.
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-serial-queue-norace.mm b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-serial-queue-norace.mm
deleted file mode 100644
index 8754b61..0000000
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-serial-queue-norace.mm
+++ /dev/null
@@ -1,40 +0,0 @@
-// RUN: %clang_tsan %s -o %t -framework Foundation
-// RUN: %run %t 2>&1 | FileCheck %s
-
-#import <Foundation/Foundation.h>
-
-#import "../test.h"
-
-long global;
-
-int main() {
- NSLog(@"Hello world.");
- NSLog(@"addr=%p\n", &global);
-
- dispatch_queue_t q1 = dispatch_queue_create("my.queue1", DISPATCH_QUEUE_CONCURRENT);
- dispatch_queue_t q2 = dispatch_queue_create("my.queue2", DISPATCH_QUEUE_SERIAL);
-
- global = 42;
- for (int i = 0; i < 10; i++) {
- dispatch_async(q1, ^{
- for (int i = 0; i < 100; i++) {
- dispatch_sync(q2, ^{
- global++;
- });
- }
- });
- }
-
- dispatch_barrier_async(q1, ^{
- dispatch_sync(dispatch_get_main_queue(), ^{
- CFRunLoopStop(CFRunLoopGetCurrent());
- });
- });
-
- CFRunLoopRun();
- NSLog(@"Done.");
-}
-
-// CHECK: Hello world.
-// CHECK: Done.
-// CHECK-NOT: WARNING: ThreadSanitizer
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-source-registration.mm b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-source-registration.mm
deleted file mode 100644
index d6d339f..0000000
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-source-registration.mm
+++ /dev/null
@@ -1,33 +0,0 @@
-// RUN: %clang_tsan %s -o %t -framework Foundation
-// RUN: %run %t 2>&1 | FileCheck %s
-
-#import <Foundation/Foundation.h>
-
-long global;
-
-int main(int argc, const char *argv[]) {
- dispatch_queue_t queue =
- dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT);
-
- dispatch_source_t source =
- dispatch_source_create(DISPATCH_SOURCE_TYPE_SIGNAL, SIGHUP, 0, queue);
-
- global = 42;
-
- dispatch_source_set_registration_handler(source, ^{
- fprintf(stderr, "global = %ld\n", global);
-
- dispatch_sync(dispatch_get_main_queue(), ^{
- CFRunLoopStop(CFRunLoopGetCurrent());
- });
- });
-
- dispatch_resume(source);
-
- CFRunLoopRun();
-
- return 0;
-}
-
-// CHECK: global = 42
-// CHECK-NOT: WARNING: ThreadSanitizer
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-sync-block-copy.mm b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-sync-block-copy.mm
new file mode 100644
index 0000000..a5bdc72
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-sync-block-copy.mm
@@ -0,0 +1,38 @@
+// This test verifies that dispatch_sync() doesn't actually copy the block under TSan (without TSan, it doesn't).
+
+// RUN: %clang_tsan %s -o %t_no_tsan -framework Foundation -fno-sanitize=thread
+// RUN: %clang_tsan %s -o %t_with_tsan -framework Foundation
+
+// RUN: %run %t_no_tsan 2>&1 | FileCheck %s
+// RUN: %run %t_with_tsan 2>&1 | FileCheck %s
+
+#import <Foundation/Foundation.h>
+
+@interface MyClass : NSObject
+@end
+
+@implementation MyClass
+- (instancetype)retain {
+ // Copying the dispatch_sync'd block below will increment the retain count of
+ // this object. Abort if that happens.
+ abort();
+}
+@end
+
+int main(int argc, const char* argv[]) {
+ dispatch_queue_t q = dispatch_queue_create("my.queue", NULL);
+ id object = [[MyClass alloc] init];
+ void (^block)(void) = ^ {
+ NSLog(@"%@", object);
+ };
+ dispatch_sync(q, ^{
+ NSLog(@"%@", object);
+ });
+ dispatch_sync(q, block);
+ [object release];
+ NSLog(@"Done.");
+ return 0;
+}
+
+// CHECK: Done.
+// CHECK-NOT: WARNING: ThreadSanitizer
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-sync-norace.mm b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-sync-norace.mm
deleted file mode 100644
index 18bf973..0000000
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-sync-norace.mm
+++ /dev/null
@@ -1,32 +0,0 @@
-// RUN: %clang_tsan %s -o %t -framework Foundation
-// RUN: %run %t 2>&1 | FileCheck %s
-
-#import <Foundation/Foundation.h>
-
-long global;
-
-static const long nIter = 1000;
-
-int main() {
- NSLog(@"Hello world.");
-
- global = 42;
- for (int i = 0; i < nIter; i++) {
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- dispatch_sync(dispatch_get_main_queue(), ^{
- global = i;
-
- if (i == nIter - 1) {
- CFRunLoopStop(CFRunLoopGetCurrent());
- }
- });
- });
- }
-
- CFRunLoopRun();
- NSLog(@"Done.");
-}
-
-// CHECK: Hello world.
-// CHECK: Done.
-// CHECK-NOT: WARNING: ThreadSanitizer
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-target-queue-norace.mm b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-target-queue-norace.mm
deleted file mode 100644
index fbfa658..0000000
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-target-queue-norace.mm
+++ /dev/null
@@ -1,41 +0,0 @@
-// RUN: %clang_tsan %s -o %t -framework Foundation
-// RUN: %run %t 2>&1 | FileCheck %s
-
-#import <Foundation/Foundation.h>
-
-long global;
-
-int main(int argc, const char *argv[]) {
- dispatch_queue_t target_queue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL);
- dispatch_queue_t q1 = dispatch_queue_create(NULL, DISPATCH_QUEUE_CONCURRENT);
- dispatch_queue_t q2 = dispatch_queue_create(NULL, DISPATCH_QUEUE_CONCURRENT);
- dispatch_set_target_queue(q1, target_queue);
- dispatch_set_target_queue(q2, target_queue);
-
- for (int i = 0; i < 100000; i++) {
- dispatch_async(q1, ^{
- global++;
-
- if (global == 200000) {
- dispatch_sync(dispatch_get_main_queue(), ^{
- CFRunLoopStop(CFRunLoopGetCurrent());
- });
- }
- });
- dispatch_async(q2, ^{
- global++;
-
- if (global == 200000) {
- dispatch_sync(dispatch_get_main_queue(), ^{
- CFRunLoopStop(CFRunLoopGetCurrent());
- });
- }
- });
- }
-
- CFRunLoopRun();
- NSLog(@"Done.");
- return 0;
-}
-
-// CHECK-NOT: WARNING: ThreadSanitizer
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/ignore-noninstrumented.mm b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/ignore-noninstrumented.mm
index 668a76a..88d3926 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/ignore-noninstrumented.mm
+++ b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/ignore-noninstrumented.mm
@@ -1,4 +1,7 @@
-// Check that ignore_noninstrumented_modules=1 suppresses races from system libraries on OS X.
+// Check that ignore_noninstrumented_modules=1 suppresses reporting races from
+// system libraries on OS X. There are currently false positives coming from
+// libxpc, libdispatch, CoreFoundation and others, because these libraries use
+// TSan-invisible atomics as synchronization.
// RUN: %clang_tsan %s -o %t -framework Foundation
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/ignored-interceptors.mm b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/ignored-interceptors.mm
deleted file mode 100644
index b2e40f0..0000000
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/ignored-interceptors.mm
+++ /dev/null
@@ -1,55 +0,0 @@
-// Check that ignore_interceptors_accesses=1 suppresses reporting races from
-// system libraries on OS X. There are currently false positives coming from
-// libxpc, libdispatch, CoreFoundation and others, because these libraries use
-// TSan-invisible atomics as synchronization.
-
-// RUN: %clang_tsan %s -o %t -framework Foundation
-
-// Check that without the flag, there are false positives.
-// RUN: %env_tsan_opts=ignore_noninstrumented_modules=0 %deflake %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-RACE
-
-// With ignore_interceptors_accesses=1, no races are reported.
-// RUN: %env_tsan_opts=ignore_noninstrumented_modules=0:ignore_interceptors_accesses=1 %run %t 2>&1 | FileCheck %s
-
-// With ignore_interceptors_accesses=1, races in user's code are still reported.
-// RUN: %env_tsan_opts=ignore_noninstrumented_modules=0:ignore_interceptors_accesses=1 %deflake %run %t race 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-RACE
-
-#import <Foundation/Foundation.h>
-
-#import "../test.h"
-
-long global;
-
-void *Thread1(void *x) {
- barrier_wait(&barrier);
- global = 42;
- return NULL;
-}
-
-void *Thread2(void *x) {
- global = 43;
- barrier_wait(&barrier);
- return NULL;
-}
-
-int main(int argc, char *argv[]) {
- fprintf(stderr, "Hello world.\n");
-
- // NSUserDefaults uses XPC which triggers the false positive.
- NSDictionary *d = [[NSUserDefaults standardUserDefaults] dictionaryRepresentation];
-
- if (argc > 1 && strcmp(argv[1], "race") == 0) {
- barrier_init(&barrier, 2);
- pthread_t t[2];
- pthread_create(&t[0], NULL, Thread1, NULL);
- pthread_create(&t[1], NULL, Thread2, NULL);
- pthread_join(t[0], NULL);
- pthread_join(t[1], NULL);
- }
-
- fprintf(stderr, "Done.\n");
-}
-
-// CHECK: Hello world.
-// CHECK-RACE: SUMMARY: ThreadSanitizer: data race
-// CHECK: Done.
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/libcxx-shared-ptr-stress.mm b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/libcxx-shared-ptr-stress.mm
index e5cd7ed..5ce016ae 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/libcxx-shared-ptr-stress.mm
+++ b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/libcxx-shared-ptr-stress.mm
@@ -3,33 +3,35 @@
#import <Foundation/Foundation.h>
-#import <assert.h>
+#import <atomic>
+#import <cassert>
+#import <cstdio>
#import <memory>
-#import <stdatomic.h>
-_Atomic(long) shared_call_counter = 0;
-_Atomic(long) weak_call_counter = 0;
-_Atomic(long) destructor_counter = 0;
-_Atomic(long) weak_destroyed_counter = 0;
+std::atomic<long> shared_call_counter(0);
+std::atomic<long> weak_call_counter(0);
+std::atomic<long> destructor_counter(0);
+std::atomic<long> weak_destroyed_counter(0);
struct MyStruct {
- _Atomic(long) self_counter = 0;
+ std::atomic<long> self_counter;
+ MyStruct() : self_counter(0) { }
virtual void shared_call() {
- atomic_fetch_add_explicit(&self_counter, 1, memory_order_relaxed);
- atomic_fetch_add_explicit(&shared_call_counter, 1, memory_order_relaxed);
+ std::atomic_fetch_add_explicit(&self_counter, 1, std::memory_order_relaxed);
+ std::atomic_fetch_add_explicit(&shared_call_counter, 1, std::memory_order_relaxed);
}
virtual void weak_call() {
- atomic_fetch_add_explicit(&weak_call_counter, 1, memory_order_relaxed);
+ std::atomic_fetch_add_explicit(&weak_call_counter, 1, std::memory_order_relaxed);
}
virtual ~MyStruct() {
long n = self_counter;
assert(n == 1000);
- atomic_fetch_add_explicit(&destructor_counter, 1, memory_order_relaxed);
+ std::atomic_fetch_add_explicit(&destructor_counter, 1, std::memory_order_relaxed);
}
};
int main(int argc, const char *argv[]) {
- fprintf(stderr, "Hello world.\n");
+ std::fprintf(stderr, "Hello world.\n");
dispatch_queue_t q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
@@ -51,7 +53,7 @@
if (weak_copy) {
weak_copy->weak_call();
} else {
- atomic_fetch_add_explicit(&weak_destroyed_counter, 1, memory_order_relaxed);
+ std::atomic_fetch_add_explicit(&weak_destroyed_counter, 1, std::memory_order_relaxed);
break;
}
}
@@ -60,12 +62,12 @@
dispatch_group_wait(g, DISPATCH_TIME_FOREVER);
- fprintf(stderr, "shared_call_counter = %ld\n", shared_call_counter);
- fprintf(stderr, "weak_call_counter = %ld\n", weak_call_counter);
- fprintf(stderr, "destructor_counter = %ld\n", destructor_counter);
- fprintf(stderr, "weak_destroyed_counter = %ld\n", weak_destroyed_counter);
+ std::fprintf(stderr, "shared_call_counter = %ld\n", shared_call_counter.load());
+ std::fprintf(stderr, "weak_call_counter = %ld\n", weak_call_counter.load());
+ std::fprintf(stderr, "destructor_counter = %ld\n", destructor_counter.load());
+ std::fprintf(stderr, "weak_destroyed_counter = %ld\n", weak_destroyed_counter.load());
- fprintf(stderr, "Done.\n");
+ std::fprintf(stderr, "Done.\n");
}
// CHECK: Hello world.
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/lit.local.cfg b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/lit.local.cfg.py
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/Darwin/lit.local.cfg
rename to third_party/llvm-project/compiler-rt/test/tsan/Darwin/lit.local.cfg.py
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/mach_vm_allocate.c b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/mach_vm_allocate.c
new file mode 100644
index 0000000..b51ed78
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/mach_vm_allocate.c
@@ -0,0 +1,89 @@
+// Test that mach_vm_[de]allocate resets shadow memory status.
+//
+// RUN: %clang_tsan %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
+
+// <mach/mach_vm.h> is not provided by the simulator SDK.
+// UNSUPPORTED: iossim
+
+#include <mach/mach.h>
+#include <mach/mach_vm.h>
+#include <pthread.h>
+#include <assert.h>
+#include <stdio.h>
+
+#include "../test.h"
+
+const mach_vm_size_t alloc_size = sizeof(int);
+static int *global_ptr;
+
+static int *alloc() {
+ mach_vm_address_t addr;
+ kern_return_t kr =
+ mach_vm_allocate(mach_task_self(), &addr, alloc_size, VM_FLAGS_ANYWHERE);
+ assert(kr == KERN_SUCCESS);
+ return (int *)addr;
+}
+
+static void alloc_fixed(int *ptr) {
+ mach_vm_address_t addr = (mach_vm_address_t)ptr;
+ // Re-allocation via VM_FLAGS_FIXED sporadically fails.
+ kern_return_t kr =
+ mach_vm_allocate(mach_task_self(), &addr, alloc_size, VM_FLAGS_FIXED);
+ if (kr != KERN_SUCCESS)
+ global_ptr = NULL;
+}
+
+static void dealloc(int *ptr) {
+ kern_return_t kr =
+ mach_vm_deallocate(mach_task_self(), (mach_vm_address_t)ptr, alloc_size);
+ assert(kr == KERN_SUCCESS);
+}
+
+static void *Thread(void *arg) {
+ *global_ptr = 7; // Assignment 1
+
+ // We want to test that TSan does not report a race between the two
+ // assignments to *global_ptr when the underlying memory is re-allocated
+ // between assignments. The calls to the API itself are racy though, so ignore
+ // them.
+ AnnotateIgnoreWritesBegin(__FILE__, __LINE__);
+ dealloc(global_ptr);
+ alloc_fixed(global_ptr);
+ AnnotateIgnoreWritesEnd(__FILE__, __LINE__);
+
+ barrier_wait(&barrier);
+ return NULL;
+}
+
+static bool try_realloc_on_same_address() {
+ barrier_init(&barrier, 2);
+ global_ptr = alloc();
+ pthread_t t;
+ pthread_create(&t, NULL, Thread, NULL);
+
+ barrier_wait(&barrier);
+ if (global_ptr)
+ *global_ptr = 8; // Assignment 2
+
+ pthread_join(t, NULL);
+ dealloc(global_ptr);
+
+ return global_ptr != NULL;
+}
+
+int main(int argc, const char *argv[]) {
+ bool success;
+ for (int i = 0; i < 10; i++) {
+ success = try_realloc_on_same_address();
+ if (success) break;
+ }
+
+ if (!success)
+ fprintf(stderr, "Unable to set up testing condition; silently pass test\n");
+
+ printf("Done.\n");
+ return 0;
+}
+
+// CHECK: Done.
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/main_tid.mm b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/main_tid.mm
index 6dea58e..5f42c41 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/main_tid.mm
+++ b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/main_tid.mm
@@ -13,7 +13,13 @@
unsigned long trace_size);
}
-void __tsan_on_report(void *report) {
+// Required for dyld macOS 12.0+
+#if (__APPLE__)
+__attribute__((weak))
+#endif
+__attribute__((disable_sanitizer_instrumentation))
+extern "C" void
+__tsan_on_report(void *report) {
fprintf(stderr, "__tsan_on_report(%p)\n", report);
int tid;
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/malloc-stack-logging.cc b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/malloc-stack-logging.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/Darwin/malloc-stack-logging.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/Darwin/malloc-stack-logging.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/malloc_size.mm b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/malloc_size.mm
index 485d85b..bb222c1 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/malloc_size.mm
+++ b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/malloc_size.mm
@@ -1,4 +1,5 @@
// Test that malloc_zone_from_ptr returns a valid zone for a 0-sized allocation.
+// Test that malloc_size does not crash for an invalid pointer.
// RUN: %clang_tsan %s -o %t -framework Foundation
// RUN: %run %t 2>&1 | FileCheck %s
@@ -54,4 +55,13 @@
// CHECK: size = 0x0
describe_zone(p);
// CHECK: zone = no zone
+
+ p = (void *)0x42; // invalid pointer
+ s = malloc_size(p);
+ fprintf(stderr, "size = 0x%zx\n", s);
+ // CHECK: size = 0x0
+ describe_zone(p);
+ // CHECK: zone = no zone
+
+ return 0;
}
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/no_call_setenv_in_symbolize.cpp b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/no_call_setenv_in_symbolize.cpp
new file mode 100644
index 0000000..1e31693
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/no_call_setenv_in_symbolize.cpp
@@ -0,0 +1,43 @@
+// RUN: %clangxx_tsan -O1 %s -o %t
+// `handle_sigbus=0` is required because when the rdar://problem/58789439 bug was
+// present TSan's runtime could derefence bad memory leading to SIGBUS being raised.
+// If the signal was caught TSan would deadlock because it would try to run the
+// symbolizer again.
+// RUN: %env_tsan_opts=handle_sigbus=0,symbolize=1 %run %t 2>&1 | FileCheck %s
+// RUN: %env_tsan_opts=handle_sigbus=0,symbolize=1 __check_mach_ports_lookup=some_value %run %t 2>&1 | FileCheck %s
+#include <sanitizer/common_interface_defs.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+const char *kEnvName = "__UNLIKELY_ENV_VAR_NAME__";
+
+int main() {
+ if (getenv(kEnvName)) {
+ fprintf(stderr, "Env var %s should not be set\n", kEnvName);
+ abort();
+ }
+
+ // This will set an environment variable that isn't already in
+ // the environment array. This will cause Darwin's Libc to
+ // malloc() a new array.
+ if (setenv(kEnvName, "some_value", /*overwrite=*/1)) {
+ fprintf(stderr, "Failed to set %s \n", kEnvName);
+ abort();
+ }
+
+ // rdar://problem/58789439
+ // Now trigger symbolization. If symbolization tries to call
+ // to `setenv` that adds a new environment variable, then Darwin
+ // Libc will call `realloc()` and TSan's runtime will hit
+ // an assertion failure because TSan's runtime uses a different
+ // allocator during symbolization which leads to `realloc()` being
+ // called on a pointer that the allocator didn't allocate.
+ //
+ // CHECK: #{{[0-9]}} main {{.*}}no_call_setenv_in_symbolize.cpp:[[@LINE+1]]
+ __sanitizer_print_stack_trace();
+
+ // CHECK: DONE
+ fprintf(stderr, "DONE\n");
+
+ return 0;
+}
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/norace-objcxx-run-time.mm b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/norace-objcxx-run-time.mm
index ee76ec1..0cf729e 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/norace-objcxx-run-time.mm
+++ b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/norace-objcxx-run-time.mm
@@ -1,5 +1,5 @@
-// RUN: %clang_tsan %s -lc++ -fobjc-arc -lobjc -o %t -framework Foundation %darwin_min_target_with_full_runtime_arc_support
-// RUN: %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan %s -lc++ -fobjc-arc -lobjc -o %t -framework Foundation
+// RUN: %env_tsan_opts=ignore_interceptors_accesses=1 %run %t 2>&1 | FileCheck %s
// Check that we do not report races between:
// - Object retain and initialize
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/objc-synchronize-cycle-tagged.mm b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/objc-synchronize-cycle-tagged.mm
new file mode 100644
index 0000000..2358936
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/objc-synchronize-cycle-tagged.mm
@@ -0,0 +1,42 @@
+// RUN: %clangxx_tsan %s -o %t -framework Foundation -fobjc-arc
+// RUN: %run %t 6 2>&1 | FileCheck %s --check-prefix=SIX
+// RUN: not %run %t 7 2>&1 | FileCheck %s --check-prefix=SEVEN
+
+#import <Foundation/Foundation.h>
+
+static bool isTaggedPtr(id obj) {
+ uintptr_t ptr = (uintptr_t) obj;
+ return (ptr & 0x8000000000000001ull) != 0;
+}
+
+int main(int argc, char* argv[]) {
+ assert(argc == 2);
+ int arg = atoi(argv[1]);
+
+ @autoreleasepool {
+ NSObject* obj = [NSObject new];
+ NSObject* num1 = [NSNumber numberWithInt:7];
+ NSObject* num2 = [NSNumber numberWithInt:arg];
+
+ assert(!isTaggedPtr(obj));
+ assert(isTaggedPtr(num1) && isTaggedPtr(num2));
+
+ // obj -> num1 (includes num2)
+ @synchronized(obj) {
+ @synchronized(num1) {
+ }
+ }
+
+ // num2 -> obj1
+ @synchronized(num2) {
+ @synchronized(obj) {
+// SEVEN: ThreadSanitizer: lock-order-inversion (potential deadlock)
+ }
+ }
+ }
+
+ NSLog(@"PASS");
+// SIX-NOT: ThreadSanitizer
+// SIX: PASS
+ return 0;
+}
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/objc-synchronize-cycle.mm b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/objc-synchronize-cycle.mm
new file mode 100644
index 0000000..006716f
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/objc-synchronize-cycle.mm
@@ -0,0 +1,31 @@
+// RUN: %clangxx_tsan %s -o %t -framework Foundation -fobjc-arc
+// RUN: not %run %t 2>&1 | FileCheck %s
+// RUN: %env_tsan_opts=detect_deadlocks=1 not %run %t 2>&1 | FileCheck %s
+// RUN: %env_tsan_opts=detect_deadlocks=0 %run %t 2>&1 | FileCheck %s --check-prefix=DISABLED
+
+#import <Foundation/Foundation.h>
+
+int main() {
+ @autoreleasepool {
+ NSObject* obj1 = [NSObject new];
+ NSObject* obj2 = [NSObject new];
+
+ // obj1 -> obj2
+ @synchronized(obj1) {
+ @synchronized(obj2) {
+ }
+ }
+
+ // obj1 -> obj1
+ @synchronized(obj2) {
+ @synchronized(obj1) {
+// CHECK: ThreadSanitizer: lock-order-inversion (potential deadlock)
+ }
+ }
+ }
+
+ NSLog(@"PASS");
+// DISABLED-NOT: ThreadSanitizer
+// DISABLED: PASS
+ return 0;
+}
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/objc-synchronize-nested-recursive.mm b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/objc-synchronize-nested-recursive.mm
new file mode 100644
index 0000000..be48a0e
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/objc-synchronize-nested-recursive.mm
@@ -0,0 +1,35 @@
+// RUN: %clangxx_tsan %s -o %t -framework Foundation -fobjc-arc
+// RUN: %run %t 2>&1 | FileCheck %s
+
+#import <Foundation/Foundation.h>
+
+int main() {
+ @autoreleasepool {
+ NSObject* obj1 = [NSObject new];
+ NSObject* obj2 = [NSObject new];
+
+ @synchronized(obj1) {
+ @synchronized(obj1) {
+ NSLog(@"nested 1-1");
+// CHECK: nested 1-1
+ }
+ }
+
+ @synchronized(obj1) {
+ @synchronized(obj2) {
+ @synchronized(obj1) {
+ @synchronized(obj2) {
+ NSLog(@"nested 1-2-1-2");
+// CHECK: nested 1-2-1-2
+ }
+ }
+ }
+ }
+
+ }
+
+ NSLog(@"PASS");
+// CHECK-NOT: ThreadSanitizer
+// CHECK: PASS
+ return 0;
+}
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/objc-synchronize-tagged.mm b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/objc-synchronize-tagged.mm
index ab0af46..2b2c08b 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/objc-synchronize-tagged.mm
+++ b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/objc-synchronize-tagged.mm
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan %s -o %t -framework Foundation -fobjc-arc %darwin_min_target_with_full_runtime_arc_support
+// RUN: %clangxx_tsan %s -o %t -framework Foundation -fobjc-arc
// RUN: %run %t 2>&1 | FileCheck %s
#import <Foundation/Foundation.h>
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/objc-synchronize.mm b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/objc-synchronize.mm
index 0bf0637..85aaa24 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/objc-synchronize.mm
+++ b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/objc-synchronize.mm
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan %s -o %t -framework Foundation -fobjc-arc %darwin_min_target_with_full_runtime_arc_support
+// RUN: %clangxx_tsan %s -o %t -framework Foundation -fobjc-arc
// RUN: %run %t 2>&1 | FileCheck %s
#import <Foundation/Foundation.h>
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/os_unfair_lock.c b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/os_unfair_lock.c
new file mode 100644
index 0000000..320e7f5
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/os_unfair_lock.c
@@ -0,0 +1,28 @@
+// RUN: %clang_tsan %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
+
+#include <os/lock.h>
+#include <pthread.h>
+#include <stdio.h>
+
+long global_variable;
+os_unfair_lock lock = OS_UNFAIR_LOCK_INIT;
+
+void *Thread(void *a) {
+ os_unfair_lock_lock(&lock);
+ global_variable++;
+ os_unfair_lock_unlock(&lock);
+ return NULL;
+}
+
+int main() {
+ pthread_t t1, t2;
+ global_variable = 0;
+ pthread_create(&t1, NULL, Thread, NULL);
+ pthread_create(&t2, NULL, Thread, NULL);
+ pthread_join(t1, NULL);
+ pthread_join(t2, NULL);
+ fprintf(stderr, "global_variable = %ld\n", global_variable);
+}
+
+// CHECK: global_variable = 2
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/osspinlock-norace.cc b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/osspinlock-norace.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/Darwin/osspinlock-norace.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/Darwin/osspinlock-norace.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/realloc-zero.cc b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/realloc-zero.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/Darwin/realloc-zero.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/Darwin/realloc-zero.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/signals-blocked.cc b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/signals-blocked.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/Darwin/signals-blocked.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/Darwin/signals-blocked.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/symbolizer-atos.cc b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/symbolizer-atos.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/Darwin/symbolizer-atos.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/Darwin/symbolizer-atos.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/symbolizer-dladdr.cc b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/symbolizer-dladdr.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/Darwin/symbolizer-dladdr.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/Darwin/symbolizer-dladdr.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/variadic-open.cpp b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/variadic-open.cpp
new file mode 100644
index 0000000..cd76840
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/Darwin/variadic-open.cpp
@@ -0,0 +1,24 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %run %t %t.tmp 2>&1 | FileCheck %s
+#include <stdio.h>
+#include <assert.h>
+#include <fcntl.h>
+#include <unistd.h>
+#include <sys/stat.h>
+
+int main(int argc, char *argv[]) {
+ fprintf(stderr, "Hello world.\n");
+ assert(argv[1]);
+ unlink(argv[1]);
+ int fd = open(argv[1], O_RDWR | O_CREAT, 0600);
+ assert(fd != -1);
+ struct stat info;
+ int result = fstat(fd, &info);
+ fprintf(stderr, "permissions = 0%o\n", info.st_mode & ~S_IFMT);
+ assert(result == 0);
+ close(fd);
+ fprintf(stderr, "Done.\n");
+}
+
+// CHECK: Hello world.
+// CHECK: permissions = 0600
+// CHECK: Done.
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Linux/check_memcpy.c b/third_party/llvm-project/compiler-rt/test/tsan/Linux/check_memcpy.c
new file mode 100644
index 0000000..26f9961
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/Linux/check_memcpy.c
@@ -0,0 +1,20 @@
+// Test that verifies TSan runtime doesn't contain compiler-emitted
+// memcpy/memmove calls. It builds the binary with TSan and check's
+// its objdump.
+
+// This could fail if using a static libunwind because that static libunwind
+// could be uninstrumented and contain memcpy/memmove calls not intercepted by
+// tsan.
+// REQUIRES: shared_unwind
+
+// RUN: %clang_tsan -O1 %s -o %t
+// RUN: llvm-objdump -d -l %t | FileCheck %s
+
+int main() {
+ return 0;
+}
+
+// CHECK-NOT: callq {{.*<(__interceptor_)?mem(cpy|set)>}}
+// tail calls:
+// CHECK-NOT: jmpq {{.*<(__interceptor_)?mem(cpy|set)>}}
+
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Linux/check_memcpy.cc b/third_party/llvm-project/compiler-rt/test/tsan/Linux/check_memcpy.cc
deleted file mode 100644
index b81efa4..0000000
--- a/third_party/llvm-project/compiler-rt/test/tsan/Linux/check_memcpy.cc
+++ /dev/null
@@ -1,17 +0,0 @@
-// 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)>}}
-
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Linux/check_preinit.cc b/third_party/llvm-project/compiler-rt/test/tsan/Linux/check_preinit.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/Linux/check_preinit.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/Linux/check_preinit.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Linux/clockwait_double_lock.c b/third_party/llvm-project/compiler-rt/test/tsan/Linux/clockwait_double_lock.c
new file mode 100644
index 0000000..8b3edab
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/Linux/clockwait_double_lock.c
@@ -0,0 +1,32 @@
+// Regression test for https://github.com/google/sanitizers/issues/1259
+// RUN: %clang_tsan -O1 %s -o %t && %run %t
+// REQUIRES: glibc-2.30 || android-30
+
+#define _GNU_SOURCE
+#include <pthread.h>
+
+pthread_cond_t cv;
+pthread_mutex_t mtx;
+
+void *fn(void *vp) {
+ pthread_mutex_lock(&mtx);
+ pthread_cond_signal(&cv);
+ pthread_mutex_unlock(&mtx);
+ return NULL;
+}
+
+int main() {
+ pthread_mutex_lock(&mtx);
+
+ pthread_t tid;
+ pthread_create(&tid, NULL, fn, NULL);
+
+ struct timespec ts;
+ clock_gettime(CLOCK_MONOTONIC, &ts);
+ ts.tv_sec += 10;
+ pthread_cond_clockwait(&cv, &mtx, CLOCK_MONOTONIC, &ts);
+ pthread_mutex_unlock(&mtx);
+
+ pthread_join(tid, NULL);
+ return 0;
+}
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Linux/clone_deadlock.cpp b/third_party/llvm-project/compiler-rt/test/tsan/Linux/clone_deadlock.cpp
new file mode 100644
index 0000000..70846da
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/Linux/clone_deadlock.cpp
@@ -0,0 +1,40 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %env_tsan_opts=atexit_sleep_ms=0 %run %t 2>&1 | FileCheck %s
+#include "../test.h"
+#include <errno.h>
+#include <sched.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+long counter;
+
+static void *incrementer(void *arg) {
+ for (;;)
+ __sync_fetch_and_add(&counter, 1);
+ return 0;
+}
+
+static int cloned(void *arg) {
+ for (int i = 0; i < 1000; i++)
+ __sync_fetch_and_add(&counter, 1);
+ exit(0);
+ return 0;
+}
+
+int main() {
+ barrier_init(&barrier, 2);
+ pthread_t th;
+ pthread_create(&th, 0, incrementer, 0);
+ for (int i = 0; i < 100; i++) {
+ char stack[64 << 10] __attribute__((aligned(64)));
+ int pid = clone(cloned, stack + sizeof(stack), SIGCHLD, 0);
+ if (pid == -1) {
+ fprintf(stderr, "failed to clone: %d\n", errno);
+ exit(1);
+ }
+ while (wait(0) != pid) {
+ }
+ }
+ fprintf(stderr, "DONE\n");
+}
+
+// CHECK: DONE
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Linux/clone_setns.cpp b/third_party/llvm-project/compiler-rt/test/tsan/Linux/clone_setns.cpp
new file mode 100644
index 0000000..1bd812f
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/Linux/clone_setns.cpp
@@ -0,0 +1,53 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
+
+// The test models how sandbox2 unshares user namespace after clone:
+// https://github.com/google/sandboxed-api/blob/c95837a6c131fbdf820db352a97d54fcbcbde6c0/sandboxed_api/sandbox2/forkserver.cc#L249
+// which works only in sigle-threaded processes.
+
+#include "../test.h"
+#include <errno.h>
+#include <sched.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#ifdef __linux__
+# include <linux/version.h>
+#endif
+
+#if __PPC64__ && RHEL_MAJOR == 7 && RHEL_MINOR == 9
+# define PPC64_RHEL7_9 1
+#endif
+
+#ifndef PPC64_RHEL7_9
+static int cloned(void *arg) {
+ // Unshare can fail for other reasons, e.g. no permissions,
+ // so check only the error we are interested in:
+ // if the process is multi-threaded unshare must return EINVAL.
+ if (unshare(CLONE_NEWUSER) && errno == EINVAL) {
+ fprintf(stderr, "unshare failed: %d\n", errno);
+ exit(1);
+ }
+ exit(0);
+ return 0;
+}
+#endif
+
+int main() {
+#ifndef PPC64_RHEL7_9
+ char stack[64 << 10] __attribute__((aligned(64)));
+ int pid = clone(cloned, stack + sizeof(stack), SIGCHLD, 0);
+ if (pid == -1) {
+ fprintf(stderr, "failed to clone: %d\n", errno);
+ exit(1);
+ }
+ int status = 0;
+ while (wait(&status) != pid) {
+ }
+ if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
+ fprintf(stderr, "child failed: %d\n", status);
+ exit(1);
+ }
+#endif
+ fprintf(stderr, "DONE\n");
+}
+
+// CHECK: DONE
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Linux/dlopen_static_tls.cpp b/third_party/llvm-project/compiler-rt/test/tsan/Linux/dlopen_static_tls.cpp
new file mode 100644
index 0000000..c661293
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/Linux/dlopen_static_tls.cpp
@@ -0,0 +1,85 @@
+// RUN: %clangxx_tsan -O1 %s -DBUILD_SO -fPIC -shared -o %t-so.so
+// RUN: %clangxx_tsan -O1 %s %link_libcxx_tsan -o %t && %run %t 2>&1 | FileCheck %s
+
+// A test for loading a dynamic library with static TLS.
+// Such static TLS is a hack that allows a dynamic library to have faster TLS,
+// but it can be loaded only iff all threads happened to allocate some excess
+// of static TLS space for whatever reason. If it's not the case loading fails with:
+// dlopen: cannot load any more object with static TLS
+// We used to produce a false positive because dlopen will write into TLS
+// of all existing threads to initialize/zero TLS region for the loaded library.
+// And this appears to be racing with initialization of TLS in the thread
+// since we model a write into the whole static TLS region (we don't know what part
+// of it is currently unused):
+// WARNING: ThreadSanitizer: data race (pid=2317365)
+// Write of size 1 at 0x7f1fa9bfcdd7 by main thread:
+// #0 memset
+// #1 init_one_static_tls
+// #2 __pthread_init_static_tls
+// [[ this is where main calls dlopen ]]
+// #3 main
+// Previous write of size 8 at 0x7f1fa9bfcdd0 by thread T1:
+// #0 __tsan_tls_initialization
+
+// Failing on bots:
+// https://lab.llvm.org/buildbot#builders/184/builds/1580
+// https://lab.llvm.org/buildbot#builders/18/builds/3167
+// UNSUPPORTED: target={{(aarch64|powerpc64).*}}
+
+#ifdef BUILD_SO
+
+__attribute__((tls_model("initial-exec"))) __thread char x = 42;
+__attribute__((tls_model("initial-exec"))) __thread char y;
+
+extern "C" int sofunc() { return ++x + ++y; }
+
+#else // BUILD_SO
+
+# include "../test.h"
+# include <dlfcn.h>
+# include <string>
+
+__thread int x[1023];
+
+void *lib;
+void (*func)();
+int ready;
+
+void *thread(void *arg) {
+ barrier_wait(&barrier);
+ if (__atomic_load_n(&ready, __ATOMIC_ACQUIRE))
+ func();
+ barrier_wait(&barrier);
+ if (dlclose(lib)) {
+ printf("error in dlclose: %s\n", dlerror());
+ exit(1);
+ }
+ return 0;
+}
+
+int main(int argc, char *argv[]) {
+ barrier_init(&barrier, 2);
+ pthread_t th;
+ pthread_create(&th, 0, thread, 0);
+ lib = dlopen((std::string(argv[0]) + "-so.so").c_str(), RTLD_NOW);
+ if (lib == 0) {
+ printf("error in dlopen: %s\n", dlerror());
+ return 1;
+ }
+ func = (void (*)())dlsym(lib, "sofunc");
+ if (func == 0) {
+ printf("error in dlsym: %s\n", dlerror());
+ return 1;
+ }
+ __atomic_store_n(&ready, 1, __ATOMIC_RELEASE);
+ barrier_wait(&barrier);
+ func();
+ barrier_wait(&barrier);
+ pthread_join(th, 0);
+ fprintf(stderr, "DONE\n");
+ return 0;
+}
+
+#endif // BUILD_SO
+
+// CHECK: DONE
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Linux/double_race.cc b/third_party/llvm-project/compiler-rt/test/tsan/Linux/double_race.cc
deleted file mode 100644
index 2b4af35..0000000
--- a/third_party/llvm-project/compiler-rt/test/tsan/Linux/double_race.cc
+++ /dev/null
@@ -1,52 +0,0 @@
-// 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
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Linux/double_race.cpp b/third_party/llvm-project/compiler-rt/test/tsan/Linux/double_race.cpp
new file mode 100644
index 0000000..f02c3c2
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/Linux/double_race.cpp
@@ -0,0 +1,51 @@
+// 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.cpp in tsan_rtl_report.cpp for an explanation.
+
+long long buf[2];
+volatile int nreport;
+
+__attribute__((disable_sanitizer_instrumentation)) void
+__sanitizer_report_error_summary(const char *summary) {
+ nreport++;
+}
+
+const int kEventPCBits = 61;
+
+extern "C" __attribute__((disable_sanitizer_instrumentation)) 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: #{{[12]}} Thread
+// CHECK-NOT: bad PC passed to __tsan_symbolize_external
+// CHECK-NOT: __sanitizer_report_error_summary
+// CHECK-NOT: WARNING: ThreadSanitizer: data race
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Linux/epoll_norace.cpp b/third_party/llvm-project/compiler-rt/test/tsan/Linux/epoll_norace.cpp
new file mode 100644
index 0000000..1cef619
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/Linux/epoll_norace.cpp
@@ -0,0 +1,42 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
+
+// The test captures what some high-performance networking servers do.
+// One thread writes to an fd, and another just receives an epoll
+// notification about the write to synchronize with the first thread
+// w/o actually reading from the fd.
+
+#include "../test.h"
+#include <errno.h>
+#include <sys/epoll.h>
+#include <sys/eventfd.h>
+
+int main() {
+ int efd = epoll_create(1);
+ if (efd == -1)
+ exit(printf("epoll_create failed: %d\n", errno));
+ int fd = eventfd(0, 0);
+ if (fd == -1)
+ exit(printf("eventfd failed: %d\n", errno));
+ epoll_event event = {.events = EPOLLIN | EPOLLET};
+ if (epoll_ctl(efd, EPOLL_CTL_ADD, fd, &event))
+ exit(printf("epoll_ctl failed: %d\n", errno));
+ pthread_t th;
+ pthread_create(
+ &th, nullptr,
+ +[](void *arg) -> void * {
+ long long to_add = 1;
+ if (write((long)arg, &to_add, sizeof(to_add)) != sizeof(to_add))
+ exit(printf("write failed: %d\n", errno));
+ return nullptr;
+ },
+ (void *)(long)fd);
+ struct epoll_event events[1] = {};
+ if (epoll_wait(efd, events, 1, -1) != 1)
+ exit(printf("epoll_wait failed: %d\n", errno));
+ close(fd);
+ pthread_join(th, nullptr);
+ close(efd);
+ fprintf(stderr, "DONE\n");
+}
+
+// CHECK: DONE
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Linux/fork_deadlock.cpp b/third_party/llvm-project/compiler-rt/test/tsan/Linux/fork_deadlock.cpp
new file mode 100644
index 0000000..9525070
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/Linux/fork_deadlock.cpp
@@ -0,0 +1,66 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %env_tsan_opts=atexit_sleep_ms=0 %run %t 2>&1 | FileCheck %s
+
+// This test models what happens on Mac when fork
+// calls malloc/free inside of our atfork callbacks.
+// and ensures that we don't deadlock on malloc/free calls.
+
+#include "../test.h"
+#include "syscall.h"
+#include <errno.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+// disable_sanitizer_instrumentation on __tsan_test_only_on_fork is not
+// transitive, so we must apply it here as well.
+// Instrumenting alloc_free_blocks() will result in deadlocks in TSan.
+__attribute__((disable_sanitizer_instrumentation)) void alloc_free_blocks() {
+ // Allocate a bunch of blocks to drain local allocator cache
+ // and provoke it to lock allocator global mutexes.
+ const int kBlocks = 1000;
+ void *blocks[kBlocks];
+ for (int i = 0; i < kBlocks; i++) {
+ void *p = malloc(10);
+ *(volatile char *)p = 0;
+ blocks[i] = p;
+ }
+ for (int i = 0; i < kBlocks; i++)
+ free(blocks[i]);
+}
+
+__attribute__((disable_sanitizer_instrumentation)) extern "C" void
+__tsan_test_only_on_fork() {
+ const char *msg = "__tsan_test_only_on_fork\n";
+ write(2, msg, strlen(msg));
+ alloc_free_blocks();
+}
+
+static void *background(void *p) {
+ for (;;)
+ alloc_free_blocks();
+ return 0;
+}
+
+int main() {
+ pthread_t th;
+ pthread_create(&th, 0, background, 0);
+ pthread_detach(th);
+ for (int i = 0; i < 10; i++) {
+ int pid = myfork();
+ if (pid < 0) {
+ fprintf(stderr, "failed to fork (%d)\n", errno);
+ exit(1);
+ }
+ if (pid == 0) {
+ // child
+ exit(0);
+ }
+ // parent
+ while (wait(0) < 0) {
+ }
+ }
+ fprintf(stderr, "DONE\n");
+}
+
+// CHECK: __tsan_test_only_on_fork
+// CHECK: DONE
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Linux/fork_multithreaded4.cpp b/third_party/llvm-project/compiler-rt/test/tsan/Linux/fork_multithreaded4.cpp
new file mode 100644
index 0000000..927f5a6
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/Linux/fork_multithreaded4.cpp
@@ -0,0 +1,46 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
+
+// The test tries to provoke internal allocator to be locked during fork
+// and then force the child process to use the internal allocator.
+
+#include "../test.h"
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+static void *forker(void *arg) {
+ void *p = calloc(1, 16);
+ static_cast<volatile int *>(p)[0]++;
+ __atomic_fetch_add(static_cast<int *>(p), 1, __ATOMIC_SEQ_CST);
+ int pid = fork();
+ if (pid < 0) {
+ fprintf(stderr, "failed to fork (%d)\n", errno);
+ exit(1);
+ }
+ if (pid == 0) {
+ __atomic_fetch_add(&static_cast<int *>(p)[1], 1, __ATOMIC_SEQ_CST);
+ exit(0);
+ }
+ int status = 0;
+ while (waitpid(pid, &status, 0) != pid) {
+ }
+ if (!WIFEXITED(status) || WEXITSTATUS(status) != 0) {
+ fprintf(stderr, "subprocess failed (%d)\n", status);
+ exit(1);
+ }
+ free(p);
+ return 0;
+}
+
+int main() {
+ for (int i = 0; i < 10; i++) {
+ pthread_t threads[100];
+ for (auto &th : threads)
+ pthread_create(&th, 0, forker, 0);
+ for (auto th : threads)
+ pthread_join(th, 0);
+ }
+ fprintf(stderr, "DONE\n");
+}
+
+// CHECK: DONE
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Linux/fork_syscall.cpp b/third_party/llvm-project/compiler-rt/test/tsan/Linux/fork_syscall.cpp
new file mode 100644
index 0000000..5764cd1
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/Linux/fork_syscall.cpp
@@ -0,0 +1,38 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %env_tsan_opts=atexit_sleep_ms=50 %run %t 2>&1 | FileCheck %s
+#include "../test.h"
+#include "syscall.h"
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+int counter;
+
+static void *incrementer(void *p) {
+ for (;;)
+ __sync_fetch_and_add(&counter, 1);
+ return 0;
+}
+
+int main() {
+ pthread_t th1;
+ pthread_create(&th1, 0, incrementer, 0);
+ for (int i = 0; i < 10; i++) {
+ switch (myfork()) {
+ default: // parent
+ while (wait(0) < 0) {
+ }
+ fprintf(stderr, ".");
+ break;
+ case 0: // child
+ __sync_fetch_and_add(&counter, 1);
+ exit(0);
+ break;
+ case -1: // error
+ fprintf(stderr, "failed to fork (%d)\n", errno);
+ exit(1);
+ }
+ }
+ fprintf(stderr, "OK\n");
+}
+
+// CHECK: OK
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Linux/lit.local.cfg b/third_party/llvm-project/compiler-rt/test/tsan/Linux/lit.local.cfg.py
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/Linux/lit.local.cfg
rename to third_party/llvm-project/compiler-rt/test/tsan/Linux/lit.local.cfg.py
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Linux/mutex_robust.cc b/third_party/llvm-project/compiler-rt/test/tsan/Linux/mutex_robust.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/Linux/mutex_robust.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/Linux/mutex_robust.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Linux/mutex_robust2.cc b/third_party/llvm-project/compiler-rt/test/tsan/Linux/mutex_robust2.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/Linux/mutex_robust2.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/Linux/mutex_robust2.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Linux/pie_no_aslr.cc b/third_party/llvm-project/compiler-rt/test/tsan/Linux/pie_no_aslr.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/Linux/pie_no_aslr.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/Linux/pie_no_aslr.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Linux/sethostent.cpp b/third_party/llvm-project/compiler-rt/test/tsan/Linux/sethostent.cpp
new file mode 100644
index 0000000..6cb8c29
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/Linux/sethostent.cpp
@@ -0,0 +1,37 @@
+// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
+
+// Use of gethostent provokes caching of some resources inside of libc.
+// They are freed in __libc_thread_freeres very late in thread lifetime,
+// after our ThreadFinish. __libc_thread_freeres calls free which
+// previously crashed in malloc hooks.
+
+#include "../test.h"
+#include <netdb.h>
+
+long X;
+
+extern "C" void __sanitizer_malloc_hook(void *ptr, size_t size) {
+ __atomic_fetch_add(&X, 1, __ATOMIC_RELAXED);
+}
+
+extern "C" void __sanitizer_free_hook(void *ptr) {
+ __atomic_fetch_sub(&X, 1, __ATOMIC_RELAXED);
+}
+
+void *Thread(void *x) {
+ sethostent(1);
+ gethostbyname("llvm.org");
+ gethostent();
+ endhostent();
+ return NULL;
+}
+
+int main() {
+ pthread_t th;
+ pthread_create(&th, NULL, Thread, NULL);
+ pthread_join(th, NULL);
+ fprintf(stderr, "DONE\n");
+ return 0;
+}
+
+// CHECK: DONE
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Linux/syscall.cpp b/third_party/llvm-project/compiler-rt/test/tsan/Linux/syscall.cpp
new file mode 100644
index 0000000..6b46bda
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/Linux/syscall.cpp
@@ -0,0 +1,37 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t 2>&1 | FileCheck %s
+#include "syscall.h"
+#include "../test.h"
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+int pipefd[2];
+unsigned long long buf[2];
+
+static void *thr(void *p) {
+ barrier_wait(&barrier);
+ mywrite(pipefd[1], buf, sizeof(buf));
+ return 0;
+}
+
+int main() {
+ barrier_init(&barrier, 2);
+ if (mypipe(pipefd))
+ exit((perror("pipe"), 1));
+ mywrite(pipefd[1], buf, sizeof(buf));
+ pthread_t th;
+ pthread_create(&th, 0, thr, 0);
+ myread(pipefd[0], buf, sizeof(buf));
+ barrier_wait(&barrier);
+ pthread_join(th, 0);
+ fprintf(stderr, "DONE\n");
+}
+
+// CHECK: WARNING: ThreadSanitizer: data race
+// CHECK: Read of size 8
+// CHECK: #0 mywrite
+// CHECK: #1 thr
+// CHECK: Previous write of size 8
+// CHECK: #0 myread
+// CHECK: #1 main
+// CHECK: DONE
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Linux/syscall.h b/third_party/llvm-project/compiler-rt/test/tsan/Linux/syscall.h
new file mode 100644
index 0000000..2d0a854
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/Linux/syscall.h
@@ -0,0 +1,45 @@
+#include <fcntl.h>
+#include <sanitizer/linux_syscall_hooks.h>
+#include <signal.h>
+#include <sys/syscall.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+int myfork() {
+ __sanitizer_syscall_pre_fork();
+#ifdef SYS_fork
+ int res = syscall(SYS_fork);
+#else
+ int res = syscall(SYS_clone, SIGCHLD, 0);
+#endif
+ __sanitizer_syscall_post_fork(res);
+ return res;
+}
+
+int mypipe(int pipefd[2]) {
+ __sanitizer_syscall_pre_pipe(pipefd);
+ int res = syscall(SYS_pipe2, pipefd, 0);
+ __sanitizer_syscall_post_pipe(res, pipefd);
+ return res;
+}
+
+int myclose(int fd) {
+ __sanitizer_syscall_pre_close(fd);
+ int res = syscall(SYS_close, fd);
+ __sanitizer_syscall_post_close(res, fd);
+ return res;
+}
+
+ssize_t myread(int fd, void *buf, size_t count) {
+ __sanitizer_syscall_pre_read(fd, buf, count);
+ ssize_t res = syscall(SYS_read, fd, buf, count);
+ __sanitizer_syscall_post_read(res, fd, buf, count);
+ return res;
+}
+
+ssize_t mywrite(int fd, const void *buf, size_t count) {
+ __sanitizer_syscall_pre_write(fd, buf, count);
+ ssize_t res = syscall(SYS_write, fd, buf, count);
+ __sanitizer_syscall_post_write(res, fd, buf, count);
+ return res;
+}
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Linux/thread_timedjoin.c b/third_party/llvm-project/compiler-rt/test/tsan/Linux/thread_timedjoin.c
new file mode 100644
index 0000000..1d3f109
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/Linux/thread_timedjoin.c
@@ -0,0 +1,39 @@
+// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
+#define _GNU_SOURCE
+#include "../test.h"
+#include <errno.h>
+
+int var;
+
+void *Thread(void *x) {
+ barrier_wait(&barrier);
+ var = 1;
+ return 0;
+}
+
+static void check(int res, int expect) {
+ if (res != expect) {
+ fprintf(stderr, "Unexpected result of pthread_timedjoin_np: %d\n", res);
+ exit(1);
+ }
+}
+
+int main() {
+ barrier_init(&barrier, 2);
+ pthread_t t;
+ pthread_create(&t, 0, Thread, 0);
+ struct timespec ts;
+ clock_gettime(CLOCK_REALTIME, &ts);
+ check(pthread_timedjoin_np(t, 0, &ts), ETIMEDOUT);
+ barrier_wait(&barrier);
+ clock_gettime(CLOCK_REALTIME, &ts);
+ ts.tv_sec += 10000;
+ check(pthread_timedjoin_np(t, 0, &ts), 0);
+ var = 2;
+ fprintf(stderr, "PASS\n");
+ return 0;
+}
+
+// CHECK-NOT: WARNING: ThreadSanitizer: data race
+// CHECK-NOT: WARNING: ThreadSanitizer: thread leak
+// CHECK: PASS
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Linux/thread_tryjoin.c b/third_party/llvm-project/compiler-rt/test/tsan/Linux/thread_tryjoin.c
new file mode 100644
index 0000000..675e159
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/Linux/thread_tryjoin.c
@@ -0,0 +1,41 @@
+// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
+#define _GNU_SOURCE
+#include "../test.h"
+#include <errno.h>
+
+int var;
+
+void *Thread(void *x) {
+ barrier_wait(&barrier);
+ var = 1;
+ return 0;
+}
+
+static void check(int res) {
+ if (res != EBUSY) {
+ fprintf(stderr, "Unexpected result of pthread_tryjoin_np: %d\n", res);
+ exit(1);
+ }
+}
+
+int main() {
+ barrier_init(&barrier, 2);
+ pthread_t t;
+ pthread_create(&t, 0, Thread, 0);
+ check(pthread_tryjoin_np(t, 0));
+ barrier_wait(&barrier);
+ for (;;) {
+ int res = pthread_tryjoin_np(t, 0);
+ if (!res)
+ break;
+ check(res);
+ pthread_yield();
+ }
+ var = 2;
+ fprintf(stderr, "PASS\n");
+ return 0;
+}
+
+// CHECK-NOT: WARNING: ThreadSanitizer: data race
+// CHECK-NOT: WARNING: ThreadSanitizer: thread leak
+// CHECK: PASS
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Linux/user_fopen.cc b/third_party/llvm-project/compiler-rt/test/tsan/Linux/user_fopen.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/Linux/user_fopen.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/Linux/user_fopen.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Linux/user_malloc.cc b/third_party/llvm-project/compiler-rt/test/tsan/Linux/user_malloc.cpp
similarity index 62%
rename from third_party/llvm-project/compiler-rt/test/tsan/Linux/user_malloc.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/Linux/user_malloc.cpp
index b470e6c..fbe023d 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/Linux/user_malloc.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/Linux/user_malloc.cpp
@@ -1,18 +1,14 @@
-// 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
+// RUN: %clangxx_tsan -c -O1 -fno-sanitize=thread %s -o %t.o
+// RUN: %clangxx_tsan -O1 %s %t.o -o %t && %run %t 2>&1 | FileCheck %s
#include <stdio.h>
+#include <stdlib.h>
+
+#if !__has_feature(thread_sanitizer)
// 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)
@@ -24,12 +20,16 @@
__interceptor_free(p);
}
+#else
+
int main() {
volatile char *p = (char*)malloc(10);
p[0] = 0;
free((void*)p);
}
+#endif
+
// CHECK: user malloc
// CHECK-NOT: ThreadSanitizer
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Unit/lit.site.cfg.in b/third_party/llvm-project/compiler-rt/test/tsan/Unit/lit.site.cfg.py.in
similarity index 83%
rename from third_party/llvm-project/compiler-rt/test/tsan/Unit/lit.site.cfg.in
rename to third_party/llvm-project/compiler-rt/test/tsan/Unit/lit.site.cfg.py.in
index 40cf096..a9c6261 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/Unit/lit.site.cfg.in
+++ b/third_party/llvm-project/compiler-rt/test/tsan/Unit/lit.site.cfg.py.in
@@ -12,12 +12,14 @@
config.test_exec_root = "@COMPILER_RT_BINARY_DIR@/lib/tsan/tests"
config.test_source_root = config.test_exec_root
-if config.host_os == 'Darwin':
- config.parallelism_group = config.darwin_sanitizer_parallelism_group_func
+if not config.parallelism_group:
+ config.parallelism_group = 'shadow-memory'
+if config.host_os == 'Darwin':
# On Darwin, we default to ignore_noninstrumented_modules=1, which also
- # suppresses some races the tests are supposed to find. See tsan/lit.cfg.
+ # suppresses some races the tests are supposed to find. See tsan/lit.cfg.py.
if 'TSAN_OPTIONS' in config.environment:
config.environment['TSAN_OPTIONS'] += ':ignore_noninstrumented_modules=0'
else:
config.environment['TSAN_OPTIONS'] = 'ignore_noninstrumented_modules=0'
+ config.environment['TSAN_OPTIONS'] += ':ignore_interceptors_accesses=0'
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/aligned_vs_unaligned_race.cc b/third_party/llvm-project/compiler-rt/test/tsan/aligned_vs_unaligned_race.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/aligned_vs_unaligned_race.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/aligned_vs_unaligned_race.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/annotate_happens_before.cc b/third_party/llvm-project/compiler-rt/test/tsan/annotate_happens_before.cc
deleted file mode 100644
index 0116616..0000000
--- a/third_party/llvm-project/compiler-rt/test/tsan/annotate_happens_before.cc
+++ /dev/null
@@ -1,57 +0,0 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
-#include "test.h"
-
-/*
-Annotations usage example.
-
-Tsan does not see synchronization in barrier_wait.
-ANNOTATE_HAPPENS_BEFORE/AFTER communicate the synchronization to tsan
-and prevent the race report.
-
-If the compiler does not support __has_feature macro, then you can build with
-CFLAGS="-fsanitize=thread -DTHREAD_SANITIZER" and then use
-#ifdef THREAD_SANITIZER to enabled annotations.
-*/
-
-#if defined(__has_feature) && __has_feature(thread_sanitizer)
-# define ANNOTATE_HAPPENS_BEFORE(addr) \
- AnnotateHappensBefore(__FILE__, __LINE__, (void*)(addr))
-# define ANNOTATE_HAPPENS_AFTER(addr) \
- AnnotateHappensAfter(__FILE__, __LINE__, (void*)(addr))
-extern "C" void AnnotateHappensBefore(const char *f, int l, void *addr);
-extern "C" void AnnotateHappensAfter(const char *f, int l, void *addr);
-#else
-# define ANNOTATE_HAPPENS_BEFORE(addr)
-# define ANNOTATE_HAPPENS_AFTER(addr)
-#endif
-
-int Global;
-
-void *Thread1(void *x) {
- barrier_wait(&barrier);
- ANNOTATE_HAPPENS_AFTER(&barrier);
- Global++;
- return NULL;
-}
-
-void *Thread2(void *x) {
- Global--;
- ANNOTATE_HAPPENS_BEFORE(&barrier);
- barrier_wait(&barrier);
- return NULL;
-}
-
-int main() {
- barrier_init(&barrier, 2);
- pthread_t t[2];
- pthread_create(&t[0], NULL, Thread1, NULL);
- pthread_create(&t[1], NULL, Thread2, NULL);
- pthread_join(t[0], NULL);
- pthread_join(t[1], NULL);
- fprintf(stderr, "DONE\n");
- return 0;
-}
-
-// CHECK-NOT: WARNING: ThreadSanitizer: data race
-// CHECK: DONE
-
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/annotate_happens_before.cpp b/third_party/llvm-project/compiler-rt/test/tsan/annotate_happens_before.cpp
new file mode 100644
index 0000000..86a8669
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/annotate_happens_before.cpp
@@ -0,0 +1,41 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
+#include "test.h"
+
+/*
+Annotations usage example.
+
+Tsan does not see synchronization in barrier_wait.
+ANNOTATE_HAPPENS_BEFORE/AFTER communicate the synchronization to tsan
+and prevent the race report.
+*/
+
+int Global;
+
+void *Thread1(void *x) {
+ barrier_wait(&barrier);
+ ANNOTATE_HAPPENS_AFTER(&barrier);
+ Global++;
+ return NULL;
+}
+
+void *Thread2(void *x) {
+ Global--;
+ ANNOTATE_HAPPENS_BEFORE(&barrier);
+ barrier_wait(&barrier);
+ return NULL;
+}
+
+int main() {
+ barrier_init(&barrier, 2);
+ pthread_t t[2];
+ pthread_create(&t[0], NULL, Thread1, NULL);
+ pthread_create(&t[1], NULL, Thread2, NULL);
+ pthread_join(t[0], NULL);
+ pthread_join(t[1], NULL);
+ fprintf(stderr, "DONE\n");
+ return 0;
+}
+
+// CHECK-NOT: WARNING: ThreadSanitizer: data race
+// CHECK: DONE
+
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/atexit.cc b/third_party/llvm-project/compiler-rt/test/tsan/atexit.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/atexit.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/atexit.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/atexit2.cc b/third_party/llvm-project/compiler-rt/test/tsan/atexit2.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/atexit2.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/atexit2.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/atexit3.cc b/third_party/llvm-project/compiler-rt/test/tsan/atexit3.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/atexit3.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/atexit3.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/atexit4.cpp b/third_party/llvm-project/compiler-rt/test/tsan/atexit4.cpp
new file mode 100644
index 0000000..6126e8c
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/atexit4.cpp
@@ -0,0 +1,36 @@
+// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
+#include "test.h"
+
+void *thread(void *x) {
+ barrier_wait(&barrier);
+ *static_cast<int *>(x) = 2;
+ return nullptr;
+}
+
+static void race() {
+ int data = 0;
+ pthread_t t;
+ pthread_create(&t, nullptr, thread, &data);
+ data = 1;
+ barrier_wait(&barrier);
+ pthread_join(t, nullptr);
+}
+
+struct X {
+ __attribute__((noinline))
+ X() { atexit(race); }
+} x;
+
+int main() {
+ barrier_init(&barrier, 2);
+ fprintf(stderr, "DONE\n");
+}
+
+// CHECK: DONE
+// CHECK: WARNING: ThreadSanitizer: data race
+// CHECK: Write of size 4
+// CHECK: #0 thread
+// CHECK: Previous write of size 4
+// CHECK: #0 race
+// CHECK: #1 at_exit_callback_installed_at
+// CHECK: #2 X
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/atexit5.cpp b/third_party/llvm-project/compiler-rt/test/tsan/atexit5.cpp
new file mode 100644
index 0000000..e24f15d
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/atexit5.cpp
@@ -0,0 +1,27 @@
+// RUN: %clangxx_tsan -O1 -fno-inline-functions %s -o %t && %deflake %run %t | FileCheck %s
+#include "test.h"
+#include <memory>
+
+std::unique_ptr<long> global(new long(42));
+
+void *thread(void *x) {
+ *global = 43;
+ barrier_wait(&barrier);
+ return nullptr;
+}
+
+int main() {
+ barrier_init(&barrier, 2);
+ pthread_t th;
+ pthread_create(&th, nullptr, thread, nullptr);
+ pthread_detach(th);
+ barrier_wait(&barrier);
+ return 0;
+}
+
+// CHECK: WARNING: ThreadSanitizer: data race
+// CHECK: Write of size 8
+// The exact spelling and number of std frames is hard to guess.
+// CHECK: unique_ptr
+// CHECK: #{{[1-9]}} cxa_at_exit_callback_installed_at
+// CHECK: #{{[2-9]}} __cxx_global_var_init
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/atomic_free.cc b/third_party/llvm-project/compiler-rt/test/tsan/atomic_free.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/atomic_free.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/atomic_free.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/atomic_free2.cc b/third_party/llvm-project/compiler-rt/test/tsan/atomic_free2.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/atomic_free2.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/atomic_free2.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/atomic_free3.cc b/third_party/llvm-project/compiler-rt/test/tsan/atomic_free3.cpp
similarity index 89%
rename from third_party/llvm-project/compiler-rt/test/tsan/atomic_free3.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/atomic_free3.cpp
index f2875ae..3f0e198 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/atomic_free3.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/atomic_free3.cpp
@@ -24,5 +24,4 @@
// CHECK: #1 main
// CHECK: Previous atomic write
-// CHECK: #0 __tsan_atomic32_store
-// CHECK: #1 Thread
+// CHECK: #0 Thread
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/atomic_hle.cc b/third_party/llvm-project/compiler-rt/test/tsan/atomic_hle.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/atomic_hle.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/atomic_hle.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/atomic_norace.cc b/third_party/llvm-project/compiler-rt/test/tsan/atomic_norace.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/atomic_norace.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/atomic_norace.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/atomic_norace2.cpp b/third_party/llvm-project/compiler-rt/test/tsan/atomic_norace2.cpp
new file mode 100644
index 0000000..9f93a55
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/atomic_norace2.cpp
@@ -0,0 +1,48 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
+#include "test.h"
+
+const int kTestCount = 3;
+typedef long long T;
+T data[kTestCount];
+T atomics[kTestCount];
+
+void *Thread(void *p) {
+ for (int i = 0; i < kTestCount; i++) {
+ barrier_wait(&barrier);
+ while (__atomic_load_n(&atomics[i], __ATOMIC_ACQUIRE) == 0) {
+ }
+ data[i]++;
+ }
+ return 0;
+}
+
+int main() {
+ barrier_init(&barrier, 2);
+ pthread_t t;
+ pthread_create(&t, 0, Thread, 0);
+ for (int i = 0; i < kTestCount; i++) {
+ barrier_wait(&barrier);
+ // We want the release to happen while the other thread
+ // spins calling load-acquire. This can expose some
+ // interesting interleavings of release and acquire.
+ usleep(100 * 1000);
+ data[i] = 1;
+ switch (i) {
+ case 0:
+ __atomic_store_n(&atomics[i], 1, __ATOMIC_RELEASE);
+ break;
+ case 1:
+ __atomic_fetch_add(&atomics[1], 1, __ATOMIC_RELEASE);
+ break;
+ case 2:
+ T cmp = 0;
+ __atomic_compare_exchange_n(&atomics[2], &cmp, 1, false, __ATOMIC_RELEASE, __ATOMIC_RELAXED);
+ break;
+ }
+ }
+ pthread_join(t, 0);
+ fprintf(stderr, "DONE\n");
+}
+
+// CHECK-NOT: ThreadSanitizer: data race
+// CHECK: DONE
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/atomic_race.cc b/third_party/llvm-project/compiler-rt/test/tsan/atomic_race.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/atomic_race.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/atomic_race.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/atomic_stack.cc b/third_party/llvm-project/compiler-rt/test/tsan/atomic_stack.cpp
similarity index 89%
rename from third_party/llvm-project/compiler-rt/test/tsan/atomic_stack.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/atomic_stack.cpp
index 979eaea..d92bfdb 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/atomic_stack.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/atomic_stack.cpp
@@ -26,5 +26,4 @@
// CHECK: WARNING: ThreadSanitizer: data race
// CHECK: Atomic write of size 4
-// CHECK: #0 __tsan_atomic32_fetch_add
-// CHECK: #1 Thread1
+// CHECK: #0 Thread1
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/atomic_store.cc b/third_party/llvm-project/compiler-rt/test/tsan/atomic_store.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/atomic_store.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/atomic_store.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/barrier.cc b/third_party/llvm-project/compiler-rt/test/tsan/barrier.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/barrier.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/barrier.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/bench.h b/third_party/llvm-project/compiler-rt/test/tsan/bench.h
index 5ae0dd8..58a0a78 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/bench.h
+++ b/third_party/llvm-project/compiler-rt/test/tsan/bench.h
@@ -1,18 +1,12 @@
-#include <pthread.h>
-#include <stdlib.h>
-#include <stddef.h>
-#include <unistd.h>
-#include <stdio.h>
+#include "test.h"
#include <time.h>
int bench_nthread;
int bench_niter;
-int grow_clock_var;
-pthread_barrier_t glow_clock_barrier;
+int bench_mode;
void bench(); // defined by user
void start_thread_group(int nth, void(*f)(int tid));
-void grow_clock_worker(int tid);
int main(int argc, char **argv) {
bench_nthread = 2;
@@ -21,15 +15,8 @@
bench_niter = 100;
if (argc > 2)
bench_niter = atoi(argv[2]);
-
- // Grow thread's clock.
- int clock_size = 10;
- if (argc > 1)
- clock_size = 1000;
- pthread_barrier_init(&glow_clock_barrier, 0, clock_size);
- start_thread_group(clock_size, grow_clock_worker);
- pthread_barrier_destroy(&glow_clock_barrier);
- __atomic_load_n(&grow_clock_var, __ATOMIC_ACQUIRE);
+ if (argc > 3)
+ bench_mode = atoi(argv[3]);
timespec tp0;
clock_gettime(CLOCK_MONOTONIC, &tp0);
@@ -50,10 +37,3 @@
for (int i = 0; i < nth; i++)
pthread_join(th[i], 0);
}
-
-void grow_clock_worker(int tid) {
- int res = pthread_barrier_wait(&glow_clock_barrier);
- if (res == PTHREAD_BARRIER_SERIAL_THREAD)
- __atomic_store_n(&grow_clock_var, 0, __ATOMIC_RELEASE);
-}
-
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/bench_acquire_only.cc b/third_party/llvm-project/compiler-rt/test/tsan/bench_acquire_only.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/bench_acquire_only.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/bench_acquire_only.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/bench_acquire_release.cc b/third_party/llvm-project/compiler-rt/test/tsan/bench_acquire_release.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/bench_acquire_release.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/bench_acquire_release.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/bench_local_mutex.cc b/third_party/llvm-project/compiler-rt/test/tsan/bench_local_mutex.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/bench_local_mutex.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/bench_local_mutex.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/bench_malloc.cpp b/third_party/llvm-project/compiler-rt/test/tsan/bench_malloc.cpp
new file mode 100644
index 0000000..fb15ab2
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/bench_malloc.cpp
@@ -0,0 +1,22 @@
+// RUN: %clangxx_tsan %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s
+
+// bench.h needs pthread barriers which are not available on OS X
+// UNSUPPORTED: darwin
+
+#include "bench.h"
+
+void thread(int tid) {
+ void **blocks = new void *[bench_mode];
+ for (int i = 0; i < bench_niter; i++) {
+ for (int j = 0; j < bench_mode; j++)
+ blocks[j] = malloc(8);
+ for (int j = 0; j < bench_mode; j++)
+ free(blocks[j]);
+ }
+ delete[] blocks;
+}
+
+void bench() { start_thread_group(bench_nthread, thread); }
+
+// CHECK: DONE
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/bench_memory_access.cpp b/third_party/llvm-project/compiler-rt/test/tsan/bench_memory_access.cpp
new file mode 100644
index 0000000..899ce92
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/bench_memory_access.cpp
@@ -0,0 +1,107 @@
+// RUN: %clangxx_tsan %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s
+
+// bench.h needs pthread barriers which are not available on OS X
+// UNSUPPORTED: darwin
+
+#include "bench.h"
+#include <memory.h>
+
+void thread(int tid) {
+ volatile long x = 0;
+ switch (bench_mode) {
+ case 0:
+ for (int i = 0; i < bench_niter; i++)
+ *(volatile char *)&x = 1;
+ break;
+ case 1:
+ for (int i = 0; i < bench_niter; i++)
+ *(volatile short *)&x = 1;
+ break;
+ case 2:
+ for (int i = 0; i < bench_niter; i++)
+ *(volatile int *)&x = 1;
+ break;
+ case 3:
+ for (int i = 0; i < bench_niter; i++)
+ *(volatile long *)&x = 1;
+ break;
+ case 4:
+ for (int i = 0; i < bench_niter; i++)
+ *(volatile char *)&x;
+ break;
+ case 5:
+ for (int i = 0; i < bench_niter; i++)
+ *(volatile short *)&x;
+ break;
+ case 6:
+ for (int i = 0; i < bench_niter; i++)
+ *(volatile int *)&x;
+ break;
+ case 7:
+ for (int i = 0; i < bench_niter; i++)
+ *(volatile long *)&x;
+ case 8:
+ for (int i = 0; i < bench_niter / 10; i++) {
+ ((volatile long *)&x)[0];
+ ((volatile int *)&x)[0];
+ ((volatile short *)&x)[2];
+ ((volatile char *)&x)[6];
+ ((volatile char *)&x)[7];
+ ((volatile long *)&x)[0] = 1;
+ ((volatile int *)&x)[0] = 1;
+ ((volatile short *)&x)[2] = 1;
+ ((volatile char *)&x)[6] = 1;
+ ((volatile char *)&x)[7] = 1;
+ }
+ break;
+ case 9: {
+ volatile long size = sizeof(x);
+ for (int i = 0; i < bench_niter; i++)
+ memset((void *)&x, i, size);
+ break;
+ }
+ case 10: {
+ volatile long data[2] = {};
+ volatile long size = sizeof(data) - 2;
+ for (int i = 0; i < bench_niter; i++)
+ memset(((char *)data) + 1, i, size);
+ break;
+ }
+ case 11: {
+ volatile long data[2] = {};
+ for (int i = 0; i < bench_niter / 8 / 3; i++) {
+ for (int off = 0; off < 8; off++) {
+ __sanitizer_unaligned_store16(((char *)data) + off, i);
+ __sanitizer_unaligned_store32(((char *)data) + off, i);
+ __sanitizer_unaligned_store64(((char *)data) + off, i);
+ }
+ }
+ break;
+ }
+#if TSAN_VECTORIZE
+ case 12: {
+ // The compiler wants to optimize all this away.
+ // Use volatile to prevent optimization, but then use kBlock
+ // to avoid the additional non-vector load in the inner loop.
+ // Also use only even indexes to prevent compiler from
+ // inserting memset.
+ const int kBlock = 128;
+ __m128i data[kBlock * 2];
+ __m128i *volatile vptr = data;
+ for (int i = 0; i < bench_niter / kBlock; i++) {
+ __m128i *ptr = vptr;
+ for (int j = 0; j < kBlock; j++)
+ _mm_store_si128(&ptr[j * 2], _mm_setzero_si128());
+ }
+ break;
+ }
+#endif
+ }
+}
+
+void bench() {
+ start_thread_group(bench_nthread, thread);
+}
+
+// CHECK: DONE
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/bench_mutex.cc b/third_party/llvm-project/compiler-rt/test/tsan/bench_mutex.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/bench_mutex.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/bench_mutex.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/bench_release_only.cc b/third_party/llvm-project/compiler-rt/test/tsan/bench_release_only.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/bench_release_only.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/bench_release_only.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/bench_rwmutex.cc b/third_party/llvm-project/compiler-rt/test/tsan/bench_rwmutex.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/bench_rwmutex.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/bench_rwmutex.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/bench_shadow_flush.cc b/third_party/llvm-project/compiler-rt/test/tsan/bench_shadow_flush.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/bench_shadow_flush.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/bench_shadow_flush.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/bench_single_writer.cc b/third_party/llvm-project/compiler-rt/test/tsan/bench_single_writer.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/bench_single_writer.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/bench_single_writer.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/bench_ten_mutexes.cc b/third_party/llvm-project/compiler-rt/test/tsan/bench_ten_mutexes.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/bench_ten_mutexes.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/bench_ten_mutexes.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/bench_threads.cpp b/third_party/llvm-project/compiler-rt/test/tsan/bench_threads.cpp
new file mode 100644
index 0000000..1d0be21
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/bench_threads.cpp
@@ -0,0 +1,45 @@
+// RUN: %clangxx_tsan %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s
+
+// bench.h needs pthread barriers which are not available on OS X
+// UNSUPPORTED: darwin
+
+#include "bench.h"
+
+void *nop_thread(void *arg) {
+ pthread_setname_np(pthread_self(), "nop_thread");
+ return nullptr;
+}
+
+void thread(int tid) {
+ for (int i = 0; i < bench_niter; i++) {
+ pthread_t th;
+ pthread_create(&th, nullptr, nop_thread, nullptr);
+ pthread_join(th, nullptr);
+ }
+}
+
+void bench() {
+ // Benchmark thread creation/joining in presence of a large number
+ // of threads (both alive and already joined).
+ printf("starting transient threads...\n");
+ for (int i = 0; i < 200; i++) {
+ const int kBatch = 100;
+ pthread_t th[kBatch];
+ for (int j = 0; j < kBatch; j++)
+ pthread_create(&th[j], nullptr, nop_thread, nullptr);
+ for (int j = 0; j < kBatch; j++)
+ pthread_join(th[j], nullptr);
+ }
+ printf("starting persistent threads...\n");
+ const int kLiveThreads = 2000;
+ pthread_t th[kLiveThreads];
+ for (int j = 0; j < kLiveThreads; j++)
+ pthread_create(&th[j], nullptr, nop_thread, nullptr);
+ printf("starting benchmark threads...\n");
+ start_thread_group(bench_nthread, thread);
+ for (int j = 0; j < kLiveThreads; j++)
+ pthread_join(th[j], nullptr);
+}
+
+// CHECK: DONE
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/benign_race.cc b/third_party/llvm-project/compiler-rt/test/tsan/benign_race.cc
deleted file mode 100644
index 90722aa..0000000
--- a/third_party/llvm-project/compiler-rt/test/tsan/benign_race.cc
+++ /dev/null
@@ -1,39 +0,0 @@
-// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
-#include "test.h"
-
-int Global;
-int WTFGlobal;
-
-extern "C" {
-void AnnotateBenignRaceSized(const char *f, int l,
- void *mem, unsigned int size, const char *desc);
-void WTFAnnotateBenignRaceSized(const char *f, int l,
- void *mem, unsigned int size,
- const char *desc);
-}
-
-
-void *Thread(void *x) {
- Global = 42;
- WTFGlobal = 142;
- barrier_wait(&barrier);
- return 0;
-}
-
-int main() {
- barrier_init(&barrier, 2);
- AnnotateBenignRaceSized(__FILE__, __LINE__,
- &Global, sizeof(Global), "Race on Global");
- WTFAnnotateBenignRaceSized(__FILE__, __LINE__,
- &WTFGlobal, sizeof(WTFGlobal),
- "Race on WTFGlobal");
- pthread_t t;
- pthread_create(&t, 0, Thread, 0);
- barrier_wait(&barrier);
- Global = 43;
- WTFGlobal = 143;
- pthread_join(t, 0);
- fprintf(stderr, "OK\n");
-}
-
-// CHECK-NOT: WARNING: ThreadSanitizer: data race
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/benign_race.cpp b/third_party/llvm-project/compiler-rt/test/tsan/benign_race.cpp
new file mode 100644
index 0000000..53e820d
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/benign_race.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
+#include "test.h"
+
+int Global;
+int WTFGlobal;
+
+void *Thread(void *x) {
+ Global = 42;
+ WTFGlobal = 142;
+ barrier_wait(&barrier);
+ return 0;
+}
+
+int main() {
+ barrier_init(&barrier, 2);
+ ANNOTATE_BENIGN_RACE(Global);
+ WTF_ANNOTATE_BENIGN_RACE(WTFGlobal);
+ pthread_t t;
+ pthread_create(&t, 0, Thread, 0);
+ barrier_wait(&barrier);
+ Global = 43;
+ WTFGlobal = 143;
+ pthread_join(t, 0);
+ fprintf(stderr, "OK\n");
+}
+
+// CHECK-NOT: WARNING: ThreadSanitizer: data race
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/blacklist.cc b/third_party/llvm-project/compiler-rt/test/tsan/blacklist.cc
deleted file mode 100644
index c1bcca6..0000000
--- a/third_party/llvm-project/compiler-rt/test/tsan/blacklist.cc
+++ /dev/null
@@ -1,30 +0,0 @@
-// Test blacklist functionality for TSan.
-
-// RUN: echo "fun:*Blacklisted_Thread2*" > %t.blacklist
-// RUN: %clangxx_tsan -O1 %s -fsanitize-blacklist=%t.blacklist -o %t && %run %t 2>&1 | FileCheck %s
-#include <pthread.h>
-#include <stdio.h>
-
-int Global;
-
-void *Thread1(void *x) {
- Global++;
- return NULL;
-}
-
-void *Blacklisted_Thread2(void *x) {
- Global--;
- return NULL;
-}
-
-int main() {
- pthread_t t[2];
- pthread_create(&t[0], NULL, Thread1, NULL);
- pthread_create(&t[1], NULL, Blacklisted_Thread2, NULL);
- pthread_join(t[0], NULL);
- pthread_join(t[1], NULL);
- fprintf(stderr, "PASS\n");
- return 0;
-}
-
-// CHECK-NOT: ThreadSanitizer: data race
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/blacklist2.cc b/third_party/llvm-project/compiler-rt/test/tsan/blacklist2.cc
deleted file mode 100644
index bf6c4eb..0000000
--- a/third_party/llvm-project/compiler-rt/test/tsan/blacklist2.cc
+++ /dev/null
@@ -1,49 +0,0 @@
-// Test that blacklisted functions are still contained in the stack trace.
-
-// RUN: echo "fun:*Blacklisted_Thread2*" > %t.blacklist
-// RUN: echo "fun:*CallTouchGlobal*" >> %t.blacklist
-
-// RUN: %clangxx_tsan -O1 %s -fsanitize-blacklist=%t.blacklist -o %t
-// RUN: %deflake %run %t 2>&1 | FileCheck %s
-#include "test.h"
-
-int Global;
-
-void *Thread1(void *x) {
- barrier_wait(&barrier);
- // CHECK: ThreadSanitizer: data race
- // CHECK: Write of size 4
- // CHECK: #0 Thread1{{.*}}blacklist2.cc:[[@LINE+1]]
- Global++;
- return NULL;
-}
-
-void TouchGlobal() {
- // CHECK: Previous write of size 4
- // CHECK: #0 TouchGlobal{{.*}}blacklist2.cc:[[@LINE+1]]
- Global--;
-}
-
-void CallTouchGlobal() {
- // CHECK: #1 CallTouchGlobal{{.*}}blacklist2.cc:[[@LINE+1]]
- TouchGlobal();
-}
-
-void *Blacklisted_Thread2(void *x) {
- Global--;
- // CHECK: #2 Blacklisted_Thread2{{.*}}blacklist2.cc:[[@LINE+1]]
- CallTouchGlobal();
- barrier_wait(&barrier);
- return NULL;
-}
-
-int main() {
- barrier_init(&barrier, 2);
- pthread_t t[2];
- pthread_create(&t[0], NULL, Thread1, NULL);
- pthread_create(&t[1], NULL, Blacklisted_Thread2, NULL);
- pthread_join(t[0], NULL);
- pthread_join(t[1], NULL);
- fprintf(stderr, "PASS\n");
- return 0;
-}
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/compare_exchange.cpp b/third_party/llvm-project/compiler-rt/test/tsan/compare_exchange.cpp
new file mode 100644
index 0000000..a41fea4
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/compare_exchange.cpp
@@ -0,0 +1,106 @@
+// RUN: %clangxx_tsan -O1 %s %link_libcxx_tsan -o %t && %deflake %env_tsan_opts=atexit_sleep_ms=50 %run %t 2>&1 | FileCheck --check-prefix=CHECK-REPORT %s
+
+#include <atomic>
+#include <cassert>
+#include <stdio.h>
+#include <thread>
+
+#define NUM_ORDS 16
+#define NUM_THREADS NUM_ORDS * 2
+struct node {
+ int val;
+};
+std::atomic<node *> _nodes[NUM_THREADS] = {};
+
+void f1(int i) {
+ auto n = new node();
+ n->val = 42;
+ _nodes[i].store(n, std::memory_order_release);
+}
+
+template <int version>
+void f2(int i, std::memory_order mo, std::memory_order fmo) {
+ node *expected = nullptr;
+ while (expected == nullptr) {
+ _nodes[i].compare_exchange_weak(expected, nullptr, mo, fmo);
+ };
+
+ ++expected->val;
+ assert(expected->val == 43);
+}
+
+struct MemOrdSuccFail {
+ std::memory_order mo;
+ std::memory_order fmo;
+};
+
+MemOrdSuccFail OrdList[NUM_ORDS] = {
+ {std::memory_order_release, std::memory_order_relaxed},
+ {std::memory_order_release, std::memory_order_acquire},
+ {std::memory_order_release, std::memory_order_consume},
+ {std::memory_order_release, std::memory_order_seq_cst},
+
+ {std::memory_order_acq_rel, std::memory_order_relaxed},
+ {std::memory_order_acq_rel, std::memory_order_acquire},
+ {std::memory_order_acq_rel, std::memory_order_consume},
+ {std::memory_order_acq_rel, std::memory_order_seq_cst},
+
+ {std::memory_order_seq_cst, std::memory_order_relaxed},
+ {std::memory_order_seq_cst, std::memory_order_acquire},
+ {std::memory_order_seq_cst, std::memory_order_consume},
+ {std::memory_order_seq_cst, std::memory_order_seq_cst},
+
+ {std::memory_order_relaxed, std::memory_order_relaxed},
+ {std::memory_order_relaxed, std::memory_order_acquire},
+ {std::memory_order_relaxed, std::memory_order_consume},
+ {std::memory_order_relaxed, std::memory_order_seq_cst},
+};
+
+int main() {
+ std::thread threads[NUM_THREADS];
+ int ords = 0;
+
+ // Instantiate a new f2 for each MO so we can dedup reports and actually
+ // make sure relaxed FMO triggers a warning for every different MO.
+ for (unsigned t = 0; t < 8; t += 2) {
+ threads[t] = std::thread(f1, t);
+ threads[t + 1] = std::thread(f2<0>, t, OrdList[ords].mo, OrdList[ords].fmo);
+ threads[t].join();
+ threads[t + 1].join();
+ ords++;
+ }
+
+ for (unsigned t = 8; t < 16; t += 2) {
+ threads[t] = std::thread(f1, t);
+ threads[t + 1] = std::thread(f2<1>, t, OrdList[ords].mo, OrdList[ords].fmo);
+ threads[t].join();
+ threads[t + 1].join();
+ ords++;
+ }
+
+ for (unsigned t = 16; t < 24; t += 2) {
+ threads[t] = std::thread(f1, t);
+ threads[t + 1] = std::thread(f2<2>, t, OrdList[ords].mo, OrdList[ords].fmo);
+ threads[t].join();
+ threads[t + 1].join();
+ ords++;
+ }
+
+ for (unsigned t = 24; t < 32; t += 2) {
+ threads[t] = std::thread(f1, t);
+ threads[t + 1] = std::thread(f2<3>, t, OrdList[ords].mo, OrdList[ords].fmo);
+ threads[t].join();
+ threads[t + 1].join();
+ ords++;
+ }
+
+ fprintf(stderr, "DONE\n");
+ return 0;
+}
+
+// CHECK-REPORT: WARNING: ThreadSanitizer: data race
+// CHECK-REPORT: WARNING: ThreadSanitizer: data race
+// CHECK-REPORT: WARNING: ThreadSanitizer: data race
+// CHECK-REPORT: WARNING: ThreadSanitizer: data race
+// CHECK-REPORT: DONE
+// CHECK-REPORT: ThreadSanitizer: reported 4 warnings
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/cond_cancel.c b/third_party/llvm-project/compiler-rt/test/tsan/cond_cancel.c
index 5c49715..03070bf 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/cond_cancel.c
+++ b/third_party/llvm-project/compiler-rt/test/tsan/cond_cancel.c
@@ -3,12 +3,12 @@
// CHECK: OK
// This test is failing on powerpc64 (VMA=44). After calling pthread_cancel,
// the Thread-specific data destructors are not called, so the destructor
-// "thread_finalize" (defined in tsan_interceptors.cc) can not set the status
+// "thread_finalize" (defined in tsan_interceptors.cpp) can not set the status
// of the thread to "ThreadStatusFinished" failing a check in "SetJoined"
-// (defined in sanitizer_thread_registry.cc). It might seem a bug on glibc,
+// (defined in sanitizer_thread_registry.cpp). It might seem a bug on glibc,
// however the same version GLIBC-2.17 will not make fail the test on
// powerpc64 BE (VMA=46)
-// UNSUPPORTED: powerpc64-unknown-linux-gnu
+// UNSUPPORTED: target=powerpc64-unknown-linux-gnu{{.*}}
#include "test.h"
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/cond_destruction.cc b/third_party/llvm-project/compiler-rt/test/tsan/cond_destruction.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/cond_destruction.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/cond_destruction.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/cond_race.cc b/third_party/llvm-project/compiler-rt/test/tsan/cond_race.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/cond_race.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/cond_race.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/custom_mutex0.cc b/third_party/llvm-project/compiler-rt/test/tsan/custom_mutex0.cpp
similarity index 88%
rename from third_party/llvm-project/compiler-rt/test/tsan/custom_mutex0.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/custom_mutex0.cpp
index 8302fd8..da83048 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/custom_mutex0.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/custom_mutex0.cpp
@@ -1,7 +1,7 @@
// RUN: %clangxx_tsan -O1 --std=c++11 %s -o %t && %run %t 2>&1 | FileCheck %s
#include "custom_mutex.h"
-// Test that custom annoations provide normal mutex synchronization
+// Test that custom annotations provide normal mutex synchronization
// (no race reports for properly protected critical sections).
Mutex mu(true, 0);
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/custom_mutex1.cc b/third_party/llvm-project/compiler-rt/test/tsan/custom_mutex1.cpp
similarity index 93%
rename from third_party/llvm-project/compiler-rt/test/tsan/custom_mutex1.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/custom_mutex1.cpp
index 1c879f5..c9324e5 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/custom_mutex1.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/custom_mutex1.cpp
@@ -35,5 +35,5 @@
// CHECK: ThreadSanitizer: data race
// CHECK-NEXT: Write of size 8 at {{.*}} by main thread:
-// CHECK-NEXT: #0 main {{.*}}custom_mutex1.cc:29
+// CHECK-NEXT: #0 main {{.*}}custom_mutex1.cpp:29
// CHECK: DONE
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/custom_mutex2.cc b/third_party/llvm-project/compiler-rt/test/tsan/custom_mutex2.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/custom_mutex2.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/custom_mutex2.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/custom_mutex3.cc b/third_party/llvm-project/compiler-rt/test/tsan/custom_mutex3.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/custom_mutex3.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/custom_mutex3.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/custom_mutex4.cc b/third_party/llvm-project/compiler-rt/test/tsan/custom_mutex4.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/custom_mutex4.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/custom_mutex4.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/custom_mutex5.cc b/third_party/llvm-project/compiler-rt/test/tsan/custom_mutex5.cpp
similarity index 90%
rename from third_party/llvm-project/compiler-rt/test/tsan/custom_mutex5.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/custom_mutex5.cpp
index ad906e3..cb18b23 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/custom_mutex5.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/custom_mutex5.cpp
@@ -27,7 +27,7 @@
}
// CHECK: WARNING: ThreadSanitizer: destroy of a locked mutex
-// CHECK: main {{.*}}custom_mutex5.cc:14
+// CHECK: main {{.*}}custom_mutex5.cpp:14
// CHECK: WARNING: ThreadSanitizer: destroy of a locked mutex
-// CHECK: main {{.*}}custom_mutex5.cc:22
+// CHECK: main {{.*}}custom_mutex5.cpp:22
// CHECK: DONE
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/cxa_guard_acquire.cpp b/third_party/llvm-project/compiler-rt/test/tsan/cxa_guard_acquire.cpp
new file mode 100644
index 0000000..d483cd3
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/cxa_guard_acquire.cpp
@@ -0,0 +1,31 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
+
+#include <stdio.h>
+
+namespace __tsan {
+
+#if (__APPLE__)
+__attribute__((weak))
+#endif
+void OnPotentiallyBlockingRegionBegin() {
+ printf("Enter __cxa_guard_acquire\n");
+}
+
+#if (__APPLE__)
+__attribute__((weak))
+#endif
+void OnPotentiallyBlockingRegionEnd() { printf("Exit __cxa_guard_acquire\n"); }
+
+} // namespace __tsan
+
+int main(int argc, char **argv) {
+ // CHECK: Enter main
+ printf("Enter main\n");
+ // CHECK-NEXT: Enter __cxa_guard_acquire
+ // CHECK-NEXT: Exit __cxa_guard_acquire
+ static int s = argc;
+ (void)s;
+ // CHECK-NEXT: Exit main
+ printf("Exit main\n");
+ return 0;
+}
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/deadlock_detector_stress_test.cc b/third_party/llvm-project/compiler-rt/test/tsan/deadlock_detector_stress_test.cpp
similarity index 96%
rename from third_party/llvm-project/compiler-rt/test/tsan/deadlock_detector_stress_test.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/deadlock_detector_stress_test.cpp
index bbaaabb..f3d2fc7 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/deadlock_detector_stress_test.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/deadlock_detector_stress_test.cpp
@@ -1,12 +1,12 @@
// RUN: %clangxx_tsan %s -o %t -DLockType=PthreadMutex
-// RUN: %env_tsan_opts=detect_deadlocks=1 %deflake %run %t | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NOT-SECOND
-// RUN: %env_tsan_opts=detect_deadlocks=1:second_deadlock_stack=1 %deflake %run %t | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-SECOND
+// RUN: %deflake %run %t | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NOT-SECOND
+// RUN: %env_tsan_opts=second_deadlock_stack=1 %deflake %run %t | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-SECOND
// RUN: %clangxx_tsan %s -o %t -DLockType=PthreadSpinLock
-// RUN: %env_tsan_opts=detect_deadlocks=1 %deflake %run %t | FileCheck %s
+// RUN: %deflake %run %t | FileCheck %s
// RUN: %clangxx_tsan %s -o %t -DLockType=PthreadRWLock
-// RUN: %env_tsan_opts=detect_deadlocks=1 %deflake %run %t | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-RD
+// RUN: %deflake %run %t | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-RD
// RUN: %clangxx_tsan %s -o %t -DLockType=PthreadRecursiveMutex
-// RUN: %env_tsan_opts=detect_deadlocks=1 %deflake %run %t | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-REC
+// RUN: %deflake %run %t | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-REC
#include "test.h"
#undef NDEBUG
#include <assert.h>
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/debug_alloc_stack.cc b/third_party/llvm-project/compiler-rt/test/tsan/debug_alloc_stack.cpp
similarity index 98%
rename from third_party/llvm-project/compiler-rt/test/tsan/debug_alloc_stack.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/debug_alloc_stack.cpp
index ffe99e7..5deed49 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/debug_alloc_stack.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/debug_alloc_stack.cpp
@@ -49,7 +49,7 @@
void *trace[100];
size_t num_frames = 100;
int thread_id;
- uint64_t *thread_os_id;
+ uint64_t thread_os_id;
num_frames =
__tsan_get_alloc_stack(mem, trace, num_frames, &thread_id, &thread_os_id);
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/debug_locate.cc b/third_party/llvm-project/compiler-rt/test/tsan/debug_locate.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/debug_locate.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/debug_locate.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/debugging.cc b/third_party/llvm-project/compiler-rt/test/tsan/debugging.cpp
similarity index 95%
rename from third_party/llvm-project/compiler-rt/test/tsan/debugging.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/debugging.cpp
index d9c7c65..9d247a2 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/debugging.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/debugging.cpp
@@ -46,7 +46,13 @@
fprintf(stderr, "Done.\n");
}
-void __tsan_on_report(void *report) {
+// Required for dyld macOS 12.0+
+#if (__APPLE__)
+__attribute__((weak))
+#endif
+__attribute__((disable_sanitizer_instrumentation))
+extern "C" void
+__tsan_on_report(void *report) {
fprintf(stderr, "__tsan_on_report(%p)\n", report);
fprintf(stderr, "__tsan_get_current_report() = %p\n",
__tsan_get_current_report());
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/deep_stack1.cc b/third_party/llvm-project/compiler-rt/test/tsan/deep_stack1.cpp
similarity index 93%
rename from third_party/llvm-project/compiler-rt/test/tsan/deep_stack1.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/deep_stack1.cpp
index 44dd0c4..1e97358 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/deep_stack1.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/deep_stack1.cpp
@@ -53,5 +53,5 @@
// CHECK: WARNING: ThreadSanitizer: data race
// CHECK: #100 foo
-// We must output suffucuently large stack (at least 100 frames)
+// We must output sufficiently large stack (at least 100 frames)
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/deep_stack2.cpp b/third_party/llvm-project/compiler-rt/test/tsan/deep_stack2.cpp
new file mode 100644
index 0000000..1675686
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/deep_stack2.cpp
@@ -0,0 +1,42 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
+#include "test.h"
+
+volatile long X;
+volatile long Y;
+volatile int N1 = 2 << 10;
+volatile int N2 = 32 << 10;
+void (*volatile F)();
+void (*volatile G)();
+
+static void foo() {
+ if (--N1)
+ return F();
+ while (--N2)
+ G();
+}
+
+static void bar() { Y++; }
+
+void *Thread(void *p) {
+ F();
+ X = 43;
+ barrier_wait(&barrier);
+ return 0;
+}
+
+int main() {
+ barrier_init(&barrier, 2);
+ F = foo;
+ G = bar;
+ pthread_t t;
+ pthread_create(&t, 0, Thread, 0);
+ barrier_wait(&barrier);
+ X = 43;
+ pthread_join(t, 0);
+}
+
+// CHECK: WARNING: ThreadSanitizer: data race
+// CHECK: Write
+// CHECK: #0 main
+// CHECK: Previous write
+// CHECK: #0 Thread
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/default_options.cc b/third_party/llvm-project/compiler-rt/test/tsan/default_options.cpp
similarity index 92%
rename from third_party/llvm-project/compiler-rt/test/tsan/default_options.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/default_options.cpp
index 77bdcd5..3b447e7 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/default_options.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/default_options.cpp
@@ -2,6 +2,9 @@
#include <pthread.h>
#include <stdio.h>
+#if (__APPLE__)
+__attribute__((weak))
+#endif
extern "C" const char *__tsan_default_options() {
return "report_bugs=0";
}
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/deflake.bash b/third_party/llvm-project/compiler-rt/test/tsan/deflake.bash
index 9731fa5..5a88174 100755
--- a/third_party/llvm-project/compiler-rt/test/tsan/deflake.bash
+++ b/third_party/llvm-project/compiler-rt/test/tsan/deflake.bash
@@ -1,13 +1,22 @@
#!/usr/bin/env bash
# This script is used to deflake inherently flaky tsan tests.
# It is invoked from lit tests as:
-# %deflake mybinary
+# %deflake $THRESHOLD mybinary
# which is then substituted by lit to:
-# $(dirname %s)/deflake.bash mybinary
-# The script runs the target program up to 10 times,
+# $(dirname %s)/deflake.bash $THRESHOLD mybinary
+# - When TSAN_TEST_DEFLAKE_THRESHOLD is defined to a positive integer value,
+# THRESHOLD will be the defined value.
+# - When TSAN_TEST_DEFLAKE_THRESHOLD is not defined, THRESHOLD will be 10.
+# The script runs the target program up to $THRESHOLD times,
# until it fails (i.e. produces a race report).
-for i in $(seq 1 10); do
+THRESHOLD="${1}"
+shift
+
+# Early exit if $THRESHOLD is not a non-negative integer
+[[ "${THRESHOLD}" =~ ^[0-9]+$ ]] || exit 1
+
+while (( THRESHOLD-- )); do
OUT=`$@ 2>&1`
if [[ $? != 0 ]]; then
echo "$OUT"
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/dl_iterate_phdr.cc b/third_party/llvm-project/compiler-rt/test/tsan/dl_iterate_phdr.cpp
similarity index 93%
rename from third_party/llvm-project/compiler-rt/test/tsan/dl_iterate_phdr.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/dl_iterate_phdr.cpp
index 3c9821b..4a1fcc2 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/dl_iterate_phdr.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/dl_iterate_phdr.cpp
@@ -1,5 +1,5 @@
// RUN: %clangxx_tsan -O1 %s -DBUILD_SO -fPIC -shared -o %t-so.so
-// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s %link_libcxx_tsan -o %t && %run %t 2>&1 | FileCheck %s
// dl_iterate_phdr doesn't exist on OS X.
// UNSUPPORTED: darwin
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/dlclose.cc b/third_party/llvm-project/compiler-rt/test/tsan/dlclose.cpp
similarity index 91%
rename from third_party/llvm-project/compiler-rt/test/tsan/dlclose.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/dlclose.cpp
index d497fd7..6f0716d 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/dlclose.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/dlclose.cpp
@@ -1,5 +1,5 @@
// RUN: %clangxx_tsan -O1 %s -DBUILD_SO -fPIC -shared -o %t-so.so
-// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s %link_libcxx_tsan -o %t && %run %t 2>&1 | FileCheck %s
// Test case for
// https://github.com/google/sanitizers/issues/487
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/dtls.c b/third_party/llvm-project/compiler-rt/test/tsan/dtls.c
index 5169756..adcd11e 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/dtls.c
+++ b/third_party/llvm-project/compiler-rt/test/tsan/dtls.c
@@ -1,6 +1,8 @@
-// RUN: %clang_tsan %s -o %t
-// RUN: %clang_tsan %s -DBUILD_SO -fPIC -o %t-so.so -shared
+// RUN: %clang_tsan %darwin_min_target_with_tls_support %s -o %t
+// RUN: %clang_tsan %darwin_min_target_with_tls_support %s -DBUILD_SO -fPIC -o \
+// RUN: %t-so.so -shared
// RUN: %run %t 2>&1 | FileCheck %s
+// XFAIL: target={{.*netbsd.*}}
// Test that tsan cleans up dynamic TLS memory between reuse.
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/exceptions.cc b/third_party/llvm-project/compiler-rt/test/tsan/exceptions.cpp
similarity index 91%
rename from third_party/llvm-project/compiler-rt/test/tsan/exceptions.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/exceptions.cpp
index 193e115..386145d 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/exceptions.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/exceptions.cpp
@@ -11,7 +11,7 @@
__attribute__((noinline)) void callee_throws() {
try {
throws_int();
- } catch (int) { // NOLINT
+ } catch (int) {
fprintf(stderr, "callee_throws caught exception\n");
}
}
@@ -19,7 +19,7 @@
__attribute__((noinline)) void throws_catches_rethrows() {
try {
throws_int();
- } catch (int) { // NOLINT
+ } catch (int) {
fprintf(stderr, "throws_catches_rethrows caught exception\n");
throw;
}
@@ -28,7 +28,7 @@
__attribute__((noinline)) void callee_rethrows() {
try {
throws_catches_rethrows();
- } catch (int) { // NOLINT
+ } catch (int) {
fprintf(stderr, "callee_rethrows caught exception\n");
}
}
@@ -36,7 +36,7 @@
__attribute__((noinline)) void throws_and_catches() {
try {
throws_int();
- } catch (int) { // NOLINT
+ } catch (int) {
fprintf(stderr, "throws_and_catches caught exception\n");
}
}
@@ -45,10 +45,10 @@
try {
try {
throws_int();
- } catch (double) { // NOLINT
+ } catch (double) {
fprintf(stderr, "nested_try inner block caught exception\n");
}
- } catch (int) { // NOLINT
+ } catch (int) {
fprintf(stderr, "nested_try outer block caught exception\n");
}
}
@@ -57,10 +57,10 @@
try {
try {
throws_int();
- } catch (int) { // NOLINT
+ } catch (int) {
fprintf(stderr, "nested_try inner block caught exception\n");
}
- } catch (double) { // NOLINT
+ } catch (double) {
fprintf(stderr, "nested_try outer block caught exception\n");
}
}
@@ -83,7 +83,7 @@
__attribute__((noinline)) void cpp_object_with_destructor() {
try {
local_object_then_throw();
- } catch (int) { // NOLINT
+ } catch (int) {
fprintf(stderr, "cpp_object_with_destructor caught exception\n");
}
}
@@ -99,7 +99,7 @@
__attribute__((noinline)) void multiframe_unwind() {
try {
recursive_call(5);
- } catch (int) { // NOLINT
+ } catch (int) {
fprintf(stderr, "multiframe_unwind caught exception\n");
}
}
@@ -114,7 +114,7 @@
try {
longjmp(env, 42);
- } catch (int) { // NOLINT
+ } catch (int) {
fprintf(stderr, "longjmp_unwind caught exception\n");
}
}
@@ -137,7 +137,7 @@
try {
recursive_call_longjmp(env, 5);
- } catch (int) { // NOLINT
+ } catch (int) {
fprintf(stderr, "longjmp_unwind_multiple_frames caught exception\n");
}
}
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/fd_close_norace.cc b/third_party/llvm-project/compiler-rt/test/tsan/fd_close_norace.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/fd_close_norace.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/fd_close_norace.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/fd_close_norace2.cc b/third_party/llvm-project/compiler-rt/test/tsan/fd_close_norace2.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/fd_close_norace2.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/fd_close_norace2.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/fd_close_norace3.cpp b/third_party/llvm-project/compiler-rt/test/tsan/fd_close_norace3.cpp
new file mode 100644
index 0000000..eab8cd5
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/fd_close_norace3.cpp
@@ -0,0 +1,28 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %env_tsan_opts=flush_memory_ms=1 %run %t 2>&1 | FileCheck %s
+#include "test.h"
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+void *Thread(void *stop) {
+ while (!__atomic_load_n((int *)stop, __ATOMIC_RELAXED))
+ close(open("/dev/null", O_RDONLY));
+ return 0;
+}
+
+int main() {
+ int stop = 0;
+ const int kThreads = 10;
+ pthread_t th[kThreads];
+ for (int i = 0; i < kThreads; i++)
+ pthread_create(&th[i], 0, Thread, &stop);
+ sleep(5);
+ __atomic_store_n(&stop, 1, __ATOMIC_RELAXED);
+ for (int i = 0; i < kThreads; i++)
+ pthread_join(th[i], 0);
+ fprintf(stderr, "DONE\n");
+}
+
+// CHECK-NOT: WARNING: ThreadSanitizer: data race
+// CHECK: DONE
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/fd_close_race.cpp b/third_party/llvm-project/compiler-rt/test/tsan/fd_close_race.cpp
new file mode 100644
index 0000000..549f1dc
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/fd_close_race.cpp
@@ -0,0 +1,26 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
+#include "test.h"
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+void *Thread(void *arg) {
+ char buf;
+ read((long)arg, &buf, 1);
+ barrier_wait(&barrier);
+ return NULL;
+}
+
+int main() {
+ barrier_init(&barrier, 2);
+ int fd = open("/dev/random", O_RDONLY);
+ pthread_t t;
+ pthread_create(&t, NULL, Thread, (void *)(long)fd);
+ barrier_wait(&barrier);
+ close(fd);
+ pthread_join(t, NULL);
+ fprintf(stderr, "DONE\n");
+}
+
+// CHECK: WARNING: ThreadSanitizer: data race
+// CHECK: DONE
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/fd_dup_norace.cc b/third_party/llvm-project/compiler-rt/test/tsan/fd_dup_norace.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/fd_dup_norace.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/fd_dup_norace.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/fd_dup_norace2.cc b/third_party/llvm-project/compiler-rt/test/tsan/fd_dup_norace2.cpp
similarity index 95%
rename from third_party/llvm-project/compiler-rt/test/tsan/fd_dup_norace2.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/fd_dup_norace2.cpp
index 31aaed9..8ecde36 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/fd_dup_norace2.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/fd_dup_norace2.cpp
@@ -17,7 +17,7 @@
char buf;
int n = read(fd, &buf, 1);
if (n != 1) {
- // This read can "legitimately" fail regadless of the fact that glibc claims
+ // This read can "legitimately" fail regardless of the fact that glibc claims
// that "there is no instant in the middle of calling dup2 at which new is
// closed and not yet a duplicate of old". Strace of the failing runs
// looks as follows:
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/fd_dup_race.cc b/third_party/llvm-project/compiler-rt/test/tsan/fd_dup_race.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/fd_dup_race.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/fd_dup_race.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/fd_location.cc b/third_party/llvm-project/compiler-rt/test/tsan/fd_location.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/fd_location.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/fd_location.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/fd_location_closed.cpp b/third_party/llvm-project/compiler-rt/test/tsan/fd_location_closed.cpp
new file mode 100644
index 0000000..bde0487
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/fd_location_closed.cpp
@@ -0,0 +1,29 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
+#include "test.h"
+
+#include <fcntl.h>
+
+void *Thread(void *x) {
+ int fd = (long)x;
+ char buf;
+ read(fd, &buf, 1);
+ barrier_wait(&barrier);
+ close(fd);
+ return NULL;
+}
+
+int main() {
+ barrier_init(&barrier, 2);
+ int fd = open("/dev/random", O_RDONLY);
+ pthread_t t[2];
+ pthread_create(&t[0], NULL, Thread, (void *)(long)fd);
+ pthread_create(&t[1], NULL, Thread, (void *)(long)fd);
+
+ pthread_join(t[0], NULL);
+ pthread_join(t[1], NULL);
+}
+
+// CHECK: WARNING: ThreadSanitizer: data race
+// CHECK: Location is file descriptor {{[0-9]+}} {{(destroyed by thread|created by main)}}
+// CHECK: #0 {{close|open}}
+// CHECK: #1 {{Thread|main}}
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/fd_pipe_norace.cc b/third_party/llvm-project/compiler-rt/test/tsan/fd_pipe_norace.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/fd_pipe_norace.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/fd_pipe_norace.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/fd_pipe_race.cc b/third_party/llvm-project/compiler-rt/test/tsan/fd_pipe_race.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/fd_pipe_race.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/fd_pipe_race.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/fd_socket_connect_norace.cc b/third_party/llvm-project/compiler-rt/test/tsan/fd_socket_connect_norace.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/fd_socket_connect_norace.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/fd_socket_connect_norace.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/fd_socket_norace.cc b/third_party/llvm-project/compiler-rt/test/tsan/fd_socket_norace.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/fd_socket_norace.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/fd_socket_norace.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/fd_socketpair_norace.cc b/third_party/llvm-project/compiler-rt/test/tsan/fd_socketpair_norace.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/fd_socketpair_norace.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/fd_socketpair_norace.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/fd_stdout_race.cc b/third_party/llvm-project/compiler-rt/test/tsan/fd_stdout_race.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/fd_stdout_race.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/fd_stdout_race.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/fd_tid_recycled.cc b/third_party/llvm-project/compiler-rt/test/tsan/fd_tid_recycled.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/fd_tid_recycled.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/fd_tid_recycled.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/fiber_asm.cpp b/third_party/llvm-project/compiler-rt/test/tsan/fiber_asm.cpp
new file mode 100644
index 0000000..63b63d3
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/fiber_asm.cpp
@@ -0,0 +1,86 @@
+// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
+// REQUIRES: x86_64-target-arch
+// UNSUPPORTED: tvos, watchos
+#include "test.h"
+
+struct ucontext {
+ void *sp;
+ void *fiber;
+};
+
+extern "C" {
+ void ucontext_do_switch(void **save, void **load);
+ void ucontext_trampoline();
+}
+
+__asm__(".global " ASM_SYMBOL(ucontext_do_switch) "\n"
+ ASM_SYMBOL(ucontext_do_switch) ":\n\t"
+ "pushq %rbp\n\t"
+ "pushq %r15\n\t"
+ "pushq %r14\n\t"
+ "pushq %r13\n\t"
+ "pushq %r12\n\t"
+ "pushq %rbx\n\t"
+ "movq %rsp, (%rdi)\n\t"
+ "movq (%rsi), %rsp\n\t"
+ "popq %rbx\n\t"
+ "popq %r12\n\t"
+ "popq %r13\n\t"
+ "popq %r14\n\t"
+ "popq %r15\n\t"
+ "popq %rbp\n\t"
+ "retq");
+
+__asm__(".global " ASM_SYMBOL(ucontext_trampoline) "\n"
+ ASM_SYMBOL(ucontext_trampoline) ":\n\t"
+ ".cfi_startproc\n\t"
+ ".cfi_undefined rip\n\t"
+ "movq %r12, %rdi\n\t"
+ "jmpq *%rbx\n\t"
+ ".cfi_endproc");
+
+void ucontext_init(ucontext *context, void *stack, unsigned stack_sz,
+ void (*func)(void*), void *arg) {
+ void **sp = reinterpret_cast<void **>(static_cast<char *>(stack) + stack_sz);
+ *(--sp) = 0;
+ *(--sp) = reinterpret_cast<void *>(ucontext_trampoline);
+ *(--sp) = 0; // rbp
+ *(--sp) = 0; // r15
+ *(--sp) = 0; // r14
+ *(--sp) = 0; // r13
+ *(--sp) = arg; // r12
+ *(--sp) = reinterpret_cast<void *>(func); // rbx
+ context->sp = sp;
+ context->fiber = __tsan_create_fiber(0);
+}
+
+void ucontext_free(ucontext *context) {
+ __tsan_destroy_fiber(context->fiber);
+}
+
+__attribute__((no_sanitize_thread))
+void ucontext_switch(ucontext *save, ucontext *load) {
+ save->fiber = __tsan_get_current_fiber();
+ __tsan_switch_to_fiber(load->fiber, 0);
+ ucontext_do_switch(&save->sp, &load->sp);
+}
+
+char stack[64 * 1024] __attribute__((aligned(16)));
+
+ucontext uc, orig_uc;
+
+void func(void *arg) {
+ __asm__ __volatile__(".cfi_undefined rip");
+ ucontext_switch(&uc, &orig_uc);
+}
+
+int main() {
+ ucontext_init(&uc, stack, sizeof(stack), func, 0);
+ ucontext_switch(&orig_uc, &uc);
+ ucontext_free(&uc);
+ fprintf(stderr, "PASS\n");
+ return 0;
+}
+
+// CHECK-NOT: WARNING: ThreadSanitizer:
+// CHECK: PASS
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/fiber_cleanup.cpp b/third_party/llvm-project/compiler-rt/test/tsan/fiber_cleanup.cpp
new file mode 100644
index 0000000..b914b0b
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/fiber_cleanup.cpp
@@ -0,0 +1,71 @@
+// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
+// REQUIRES: linux
+#include "test.h"
+
+#include <pthread.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+long count_memory_mappings() {
+ pid_t my_pid = getpid();
+ char proc_file_name[128];
+ snprintf(proc_file_name, sizeof(proc_file_name), "/proc/%d/maps", my_pid);
+
+ FILE *proc_file = fopen(proc_file_name, "r");
+ long line_count = 0;
+ int c;
+ do {
+ c = fgetc(proc_file);
+ if (c == '\n') {
+ line_count++;
+ }
+ } while (c != EOF);
+ fclose(proc_file);
+
+ return line_count;
+}
+
+void fiber_iteration() {
+ void *orig_fiber = __tsan_get_current_fiber();
+ void *fiber = __tsan_create_fiber(0);
+
+ pthread_mutex_t mutex;
+ pthread_mutex_init(&mutex, NULL);
+
+ // Running some code on the fiber that triggers handling of pending signals.
+ __tsan_switch_to_fiber(fiber, 0);
+ pthread_mutex_lock(&mutex);
+ pthread_mutex_unlock(&mutex);
+ __tsan_switch_to_fiber(orig_fiber, 0);
+
+ // We expect the fiber to clean up all resources (here the sigcontext) when destroyed.
+ __tsan_destroy_fiber(fiber);
+}
+
+// Magic-Number for some warmup iterations,
+// as tsan maps some memory for the first runs.
+const size_t num_warmup = 100;
+
+int main() {
+ for (size_t i = 0; i < num_warmup; i++) {
+ fiber_iteration();
+ }
+
+ long memory_mappings_before = count_memory_mappings();
+ fiber_iteration();
+ fiber_iteration();
+ long memory_mappings_after = count_memory_mappings();
+
+ // Is there a better way to detect a resource leak in the
+ // ThreadState object? (i.e. a mmap not being freed)
+ if (memory_mappings_before == memory_mappings_after) {
+ fprintf(stderr, "PASS\n");
+ } else {
+ fprintf(stderr, "FAILED\n");
+ }
+
+ return 0;
+}
+
+// CHECK-NOT: WARNING: ThreadSanitizer:
+// CHECK: PASS
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/fiber_from_thread.cpp b/third_party/llvm-project/compiler-rt/test/tsan/fiber_from_thread.cpp
new file mode 100644
index 0000000..d27379e
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/fiber_from_thread.cpp
@@ -0,0 +1,49 @@
+// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
+// UNSUPPORTED: tvos, watchos
+// XFAIL: ios && !iossim
+#include "sanitizer_common/sanitizer_ucontext.h"
+#include "test.h"
+
+char stack[64 * 1024] __attribute__((aligned(16)));
+
+ucontext_t uc, orig_uc1, orig_uc2;
+void *fiber, *orig_fiber1, *orig_fiber2;
+
+int var;
+
+void *Thread(void *x) {
+ orig_fiber2 = __tsan_get_current_fiber();
+ swapcontext(&orig_uc2, &orig_uc1);
+ return 0;
+}
+
+void func() {
+ pthread_t t;
+ pthread_create(&t, 0, Thread, 0);
+ pthread_join(t, 0);
+ __tsan_switch_to_fiber(orig_fiber1, 0);
+ swapcontext(&uc, &orig_uc1);
+}
+
+int main() {
+ orig_fiber1 = __tsan_get_current_fiber();
+ fiber = __tsan_create_fiber(0);
+ getcontext(&uc);
+ uc.uc_stack.ss_sp = stack;
+ uc.uc_stack.ss_size = sizeof(stack);
+ uc.uc_link = 0;
+ makecontext(&uc, func, 0);
+ var = 1;
+ __tsan_switch_to_fiber(fiber, 0);
+ swapcontext(&orig_uc1, &uc);
+ var = 2;
+ __tsan_switch_to_fiber(orig_fiber2, 0);
+ swapcontext(&orig_uc1, &orig_uc2);
+ var = 3;
+ __tsan_destroy_fiber(fiber);
+ fprintf(stderr, "PASS\n");
+ return 0;
+}
+
+// CHECK-NOT: WARNING: ThreadSanitizer:
+// CHECK: PASS
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/fiber_longjmp.cpp b/third_party/llvm-project/compiler-rt/test/tsan/fiber_longjmp.cpp
new file mode 100644
index 0000000..e56fd21
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/fiber_longjmp.cpp
@@ -0,0 +1,81 @@
+// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
+// UNSUPPORTED: tvos, watchos
+// XFAIL: ios && !iossim
+#include "sanitizer_common/sanitizer_ucontext.h"
+#include "test.h"
+#include <setjmp.h>
+
+char stack[64 * 1024] __attribute__((aligned(16)));
+
+sigjmp_buf jmpbuf, orig_jmpbuf[2];
+void *fiber, *orig_fiber[2];
+
+const unsigned N = 1000;
+
+__attribute__((noinline))
+void switch0() {
+ if (!sigsetjmp(jmpbuf, 0)) {
+ __tsan_switch_to_fiber(orig_fiber[0], 0);
+ siglongjmp(orig_jmpbuf[0], 1);
+ }
+}
+
+void func() {
+ if (!sigsetjmp(jmpbuf, 0)) {
+ __tsan_switch_to_fiber(orig_fiber[0], 0);
+ siglongjmp(orig_jmpbuf[0], 1);
+ }
+ for (;;) {
+ switch0();
+ if (!sigsetjmp(jmpbuf, 0)) {
+ __tsan_switch_to_fiber(orig_fiber[1], 0);
+ siglongjmp(orig_jmpbuf[1], 1);
+ }
+ }
+}
+
+void *Thread(void *x) {
+ orig_fiber[1] = __tsan_get_current_fiber();
+ for (unsigned i = 0; i < N; i++) {
+ barrier_wait(&barrier);
+ if (!sigsetjmp(orig_jmpbuf[1], 0)) {
+ __tsan_switch_to_fiber(fiber, 0);
+ siglongjmp(jmpbuf, 1);
+ }
+ barrier_wait(&barrier);
+ }
+ return 0;
+}
+
+int main() {
+ fiber = __tsan_create_fiber(0);
+ barrier_init(&barrier, 2);
+ pthread_t t;
+ pthread_create(&t, 0, Thread, 0);
+ orig_fiber[0] = __tsan_get_current_fiber();
+ ucontext_t uc, orig_uc;
+ getcontext(&uc);
+ uc.uc_stack.ss_sp = stack;
+ uc.uc_stack.ss_size = sizeof(stack);
+ uc.uc_link = 0;
+ makecontext(&uc, func, 0);
+ if (!sigsetjmp(orig_jmpbuf[0], 0)) {
+ __tsan_switch_to_fiber(fiber, 0);
+ swapcontext(&orig_uc, &uc);
+ }
+ for (unsigned i = 0; i < N; i++) {
+ if (!sigsetjmp(orig_jmpbuf[0], 0)) {
+ __tsan_switch_to_fiber(fiber, 0);
+ siglongjmp(jmpbuf, 1);
+ }
+ barrier_wait(&barrier);
+ barrier_wait(&barrier);
+ }
+ pthread_join(t, 0);
+ __tsan_destroy_fiber(fiber);
+ fprintf(stderr, "PASS\n");
+ return 0;
+}
+
+// CHECK-NOT: WARNING: ThreadSanitizer:
+// CHECK: PASS
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/fiber_race.cpp b/third_party/llvm-project/compiler-rt/test/tsan/fiber_race.cpp
new file mode 100644
index 0000000..add6694
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/fiber_race.cpp
@@ -0,0 +1,37 @@
+// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t 2>&1 | FileCheck %s
+// UNSUPPORTED: tvos, watchos
+// XFAIL: ios && !iossim
+#include "sanitizer_common/sanitizer_ucontext.h"
+#include "test.h"
+
+char stack[64 * 1024] __attribute__((aligned(16)));
+
+ucontext_t uc, orig_uc;
+void *fiber, *orig_fiber;
+
+int var;
+
+void func() {
+ var = 1;
+ __tsan_switch_to_fiber(orig_fiber, __tsan_switch_to_fiber_no_sync);
+ swapcontext(&uc, &orig_uc);
+}
+
+int main() {
+ orig_fiber = __tsan_get_current_fiber();
+ fiber = __tsan_create_fiber(0);
+ getcontext(&uc);
+ uc.uc_stack.ss_sp = stack;
+ uc.uc_stack.ss_size = sizeof(stack);
+ uc.uc_link = 0;
+ makecontext(&uc, func, 0);
+ var = 2;
+ __tsan_switch_to_fiber(fiber, __tsan_switch_to_fiber_no_sync);
+ swapcontext(&orig_uc, &uc);
+ __tsan_destroy_fiber(fiber);
+ fprintf(stderr, "PASS\n");
+ return 0;
+}
+
+// CHECK: WARNING: ThreadSanitizer: data race
+// CHECK: PASS
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/fiber_simple.cpp b/third_party/llvm-project/compiler-rt/test/tsan/fiber_simple.cpp
new file mode 100644
index 0000000..8123eb8
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/fiber_simple.cpp
@@ -0,0 +1,37 @@
+// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
+// UNSUPPORTED: tvos, watchos
+// XFAIL: ios && !iossim
+#include "sanitizer_common/sanitizer_ucontext.h"
+#include "test.h"
+
+char stack[64 * 1024] __attribute__((aligned(16)));
+
+ucontext_t uc, orig_uc;
+void *fiber, *orig_fiber;
+
+int var;
+
+void func() {
+ var = 1;
+ __tsan_switch_to_fiber(orig_fiber, 0);
+ swapcontext(&uc, &orig_uc);
+}
+
+int main() {
+ orig_fiber = __tsan_get_current_fiber();
+ fiber = __tsan_create_fiber(0);
+ getcontext(&uc);
+ uc.uc_stack.ss_sp = stack;
+ uc.uc_stack.ss_size = sizeof(stack);
+ uc.uc_link = 0;
+ makecontext(&uc, func, 0);
+ var = 2;
+ __tsan_switch_to_fiber(fiber, 0);
+ swapcontext(&orig_uc, &uc);
+ __tsan_destroy_fiber(fiber);
+ fprintf(stderr, "PASS\n");
+ return 0;
+}
+
+// CHECK-NOT: WARNING: ThreadSanitizer:
+// CHECK: PASS
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/fiber_two_threads.cpp b/third_party/llvm-project/compiler-rt/test/tsan/fiber_two_threads.cpp
new file mode 100644
index 0000000..d2961b9
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/fiber_two_threads.cpp
@@ -0,0 +1,63 @@
+// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
+// UNSUPPORTED: tvos, watchos
+// XFAIL: ios && !iossim
+#include "sanitizer_common/sanitizer_ucontext.h"
+#include "test.h"
+
+char stack[64 * 1024] __attribute__((aligned(16)));
+
+ucontext_t uc, orig_uc[2];
+void *fiber, *orig_fiber[2];
+
+const unsigned N = 1000;
+
+__attribute__((noinline))
+void switch0() {
+ __tsan_switch_to_fiber(orig_fiber[0], 0);
+ swapcontext(&uc, &orig_uc[0]);
+}
+
+void func() {
+ for (;;) {
+ switch0();
+ __tsan_switch_to_fiber(orig_fiber[1], 0);
+ swapcontext(&uc, &orig_uc[1]);
+ }
+}
+
+void *Thread(void *x) {
+ orig_fiber[1] = __tsan_get_current_fiber();
+ for (unsigned i = 0; i < N; i++) {
+ barrier_wait(&barrier);
+ __tsan_switch_to_fiber(fiber, 0);
+ swapcontext(&orig_uc[1], &uc);
+ barrier_wait(&barrier);
+ }
+ return 0;
+}
+
+int main() {
+ fiber = __tsan_create_fiber(0);
+ barrier_init(&barrier, 2);
+ pthread_t t;
+ pthread_create(&t, 0, Thread, 0);
+ orig_fiber[0] = __tsan_get_current_fiber();
+ getcontext(&uc);
+ uc.uc_stack.ss_sp = stack;
+ uc.uc_stack.ss_size = sizeof(stack);
+ uc.uc_link = 0;
+ makecontext(&uc, func, 0);
+ for (unsigned i = 0; i < N; i++) {
+ __tsan_switch_to_fiber(fiber, 0);
+ swapcontext(&orig_uc[0], &uc);
+ barrier_wait(&barrier);
+ barrier_wait(&barrier);
+ }
+ pthread_join(t, 0);
+ __tsan_destroy_fiber(fiber);
+ fprintf(stderr, "PASS\n");
+ return 0;
+}
+
+// CHECK-NOT: WARNING: ThreadSanitizer:
+// CHECK: PASS
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/flush_memory.cpp b/third_party/llvm-project/compiler-rt/test/tsan/flush_memory.cpp
new file mode 100644
index 0000000..03caea9
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/flush_memory.cpp
@@ -0,0 +1,38 @@
+// RUN: %clangxx_tsan -O1 %s -o %t
+// RUN: %env_tsan_opts=flush_memory_ms=1:flush_symbolizer_ms=1:memory_limit_mb=1 not %run %t 2>&1 | FileCheck %s
+#include "test.h"
+
+long X, Y;
+
+void *Thread(void *arg) {
+ __atomic_fetch_add(&X, 1, __ATOMIC_SEQ_CST);
+ barrier_wait(&barrier);
+ barrier_wait(&barrier);
+ Y = 1;
+ return &Y;
+}
+
+int main() {
+ __tsan_flush_memory();
+ barrier_init(&barrier, 2);
+ __atomic_fetch_add(&X, 1, __ATOMIC_SEQ_CST);
+ pthread_t t;
+ pthread_create(&t, NULL, Thread, NULL);
+ barrier_wait(&barrier);
+ __tsan_flush_memory();
+ // Trigger a race to test flushing of the symbolizer cache.
+ Y = 2;
+ barrier_wait(&barrier);
+ pthread_join(t, NULL);
+ __atomic_fetch_add(&X, 1, __ATOMIC_SEQ_CST);
+ // Background runtime thread should do some flushes meanwhile.
+ sleep(2);
+ __tsan_flush_memory();
+ fprintf(stderr, "DONE\n");
+ // The race may not be detected since we are doing aggressive flushes
+ // (if the state flush happens between racing accesses, tsan won't
+ // detect the race). So return 1 to make the test deterministic.
+ return 1;
+}
+
+// CHECK: DONE
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/force_background_thread.cpp b/third_party/llvm-project/compiler-rt/test/tsan/force_background_thread.cpp
new file mode 100644
index 0000000..cf645cd
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/force_background_thread.cpp
@@ -0,0 +1,25 @@
+// RUN: %clangxx_tsan -O1 %s -o %t
+// RUN: %deflake %env_tsan_opts=force_background_thread=0:verbosity=1:memory_limit_mb=1000 %run %t 2>&1 | FileCheck %s --implicit-check-not "memory flush check"
+// RUN: %deflake %env_tsan_opts=force_background_thread=1:verbosity=1:memory_limit_mb=1000 %run %t 2>&1 | FileCheck %s --check-prefixes=CHECK,THREAD
+// RUN: %deflake %env_tsan_opts=force_background_thread=0:verbosity=1:memory_limit_mb=1000 %run %t 1 2>&1 | FileCheck %s --check-prefixes=CHECK,THREAD
+
+// Fails with: objc[99984]: task_restartable_ranges_register failed (result 0x2e: (os/kern) service not supported)
+// UNSUPPORTED: darwin
+
+#include "test.h"
+
+void *Thread(void *a) { return nullptr; }
+
+int main(int argc, char *argv[]) {
+ if (argc > 1) {
+ pthread_t t;
+ pthread_create(&t, nullptr, Thread, nullptr);
+ void *p;
+ pthread_join(t, &p);
+ }
+ sleep(3);
+ return 1;
+}
+
+// CHECK: Running under ThreadSanitizer
+// THREAD: ThreadSanitizer: memory flush check
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/fork_atexit.cc b/third_party/llvm-project/compiler-rt/test/tsan/fork_atexit.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/fork_atexit.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/fork_atexit.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/fork_deadlock.cc b/third_party/llvm-project/compiler-rt/test/tsan/fork_deadlock.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/fork_deadlock.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/fork_deadlock.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/fork_multithreaded.cc b/third_party/llvm-project/compiler-rt/test/tsan/fork_multithreaded.cc
deleted file mode 100644
index faf407b..0000000
--- a/third_party/llvm-project/compiler-rt/test/tsan/fork_multithreaded.cc
+++ /dev/null
@@ -1,44 +0,0 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s -check-prefix=CHECK-DIE
-// RUN: %clangxx_tsan -O1 %s -o %t && %env_tsan_opts=die_after_fork=0 %run %t 2>&1 | FileCheck %s -check-prefix=CHECK-NODIE
-#include "test.h"
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/wait.h>
-
-static void *sleeper(void *p) {
- sleep(1000); // not intended to exit during test
- return 0;
-}
-
-static void *nop(void *p) {
- return 0;
-}
-
-int main() {
- barrier_init(&barrier, 2);
- pthread_t th;
- pthread_create(&th, 0, sleeper, 0);
- switch (fork()) {
- default: // parent
- while (wait(0) < 0) {}
- break;
- case 0: // child
- {
- pthread_t th2;
- pthread_create(&th2, 0, nop, 0);
- exit(0);
- break;
- }
- case -1: // error
- fprintf(stderr, "failed to fork (%d)\n", errno);
- exit(1);
- }
- fprintf(stderr, "OK\n");
-}
-
-// CHECK-DIE: ThreadSanitizer: starting new threads after multi-threaded fork is not supported
-// CHECK-DIE: OK
-
-// CHECK-NODIE-NOT: ThreadSanitizer: starting new threads after multi-threaded fork is not supported
-// CHECK-NODIE: OK
-
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/fork_multithreaded.cpp b/third_party/llvm-project/compiler-rt/test/tsan/fork_multithreaded.cpp
new file mode 100644
index 0000000..1d3ff8d
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/fork_multithreaded.cpp
@@ -0,0 +1,66 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 66 2>&1 | FileCheck %s -check-prefix=CHECK-DIE
+// RUN: %clangxx_tsan -O1 %s -o %t && %env_tsan_opts=die_after_fork=0 %run %t 2>&1 | FileCheck %s -check-prefix=CHECK-NODIE
+#include "test.h"
+#include <errno.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+static void *sleeper(void *p) {
+ barrier_wait(&barrier);
+ return 0;
+}
+
+static void *nop(void *p) {
+ return 0;
+}
+
+int main(int argc, const char **argv) {
+ barrier_init(&barrier, 3);
+ const int kSleeperThreads = 2;
+ barrier_init(&barrier, kSleeperThreads + 1);
+ pthread_t th0[kSleeperThreads];
+ for (int i = 0; i < kSleeperThreads; i++)
+ pthread_create(&th0[i], 0, sleeper, 0);
+ const int kNopThreads = 5;
+ pthread_t th1[kNopThreads];
+ for (int i = 0; i < kNopThreads; i++)
+ pthread_create(&th1[i], 0, nop, 0);
+ for (int i = 0; i < kNopThreads; i++)
+ pthread_join(th1[i], 0);
+ int pid = fork();
+ if (pid < 0) {
+ fprintf(stderr, "failed to fork (%d)\n", errno);
+ exit(1);
+ }
+ if (pid == 0) {
+ // child
+ const int kChildThreads = 4;
+ pthread_t th2[kChildThreads];
+ for (int i = 0; i < kChildThreads; i++)
+ pthread_create(&th2[i], 0, nop, 0);
+ for (int i = 0; i < kChildThreads; i++)
+ pthread_join(th2[i], 0);
+ exit(0);
+ return 0;
+ }
+ // parent
+ int expect = argc > 1 ? atoi(argv[1]) : 0;
+ int status = 0;
+ while (waitpid(pid, &status, 0) != pid) {
+ }
+ if (!WIFEXITED(status) || WEXITSTATUS(status) != expect) {
+ fprintf(stderr, "subprocess exited with %d, expected %d\n", status, expect);
+ exit(1);
+ }
+ barrier_wait(&barrier);
+ for (int i = 0; i < kSleeperThreads; i++)
+ pthread_join(th0[i], 0);
+ fprintf(stderr, "OK\n");
+ return 0;
+}
+
+// CHECK-DIE: ThreadSanitizer: starting new threads after multi-threaded fork is not supported
+
+// CHECK-NODIE-NOT: ThreadSanitizer:
+// CHECK-NODIE: OK
+// CHECK-NODIE-NOT: ThreadSanitizer:
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/fork_multithreaded3.cc b/third_party/llvm-project/compiler-rt/test/tsan/fork_multithreaded3.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/fork_multithreaded3.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/fork_multithreaded3.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/free_race.c b/third_party/llvm-project/compiler-rt/test/tsan/free_race.c
index d508552..af86b44 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/free_race.c
+++ b/third_party/llvm-project/compiler-rt/test/tsan/free_race.c
@@ -15,7 +15,7 @@
return NULL;
}
-void *Thread2(void *x) {
+__attribute__((noinline)) void *Thread2(void *x) {
barrier_wait(&barrier);
pthread_mutex_lock(&mtx);
mem[0] = 42;
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/free_race2.c b/third_party/llvm-project/compiler-rt/test/tsan/free_race2.c
index de6b2ae..ddba22c 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/free_race2.c
+++ b/third_party/llvm-project/compiler-rt/test/tsan/free_race2.c
@@ -1,23 +1,34 @@
// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
+// RUN: %clang_tsan -O1 -DACCESS_OFFSET=4 %s -o %t && %deflake %run %t | FileCheck %s
#include <stdlib.h>
-void __attribute__((noinline)) foo(int *mem) {
+#ifndef ACCESS_OFFSET
+#define ACCESS_OFFSET 0
+#endif
+
+__attribute__((noinline)) void foo(void *mem) {
free(mem);
}
-void __attribute__((noinline)) bar(int *mem) {
- mem[0] = 42;
+__attribute__((noinline)) void baz(void *mem) {
+ free(mem);
+}
+
+__attribute__((noinline)) void bar(void *mem) {
+ *(long*)((char*)mem + ACCESS_OFFSET) = 42;
}
int main() {
- int *mem = (int*)malloc(100);
+ void *mem = malloc(100);
+ baz(mem);
+ mem = malloc(100);
foo(mem);
bar(mem);
return 0;
}
// CHECK: WARNING: ThreadSanitizer: heap-use-after-free
-// CHECK: Write of size 4 at {{.*}} by main thread:
+// CHECK: Write of size {{.*}} at {{.*}} by main thread:
// CHECK: #0 bar
// CHECK: #1 main
// CHECK: Previous write of size 8 at {{.*}} by main thread:
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/free_race3.c b/third_party/llvm-project/compiler-rt/test/tsan/free_race3.c
new file mode 100644
index 0000000..f38a98c
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/free_race3.c
@@ -0,0 +1,29 @@
+// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
+
+#include "test.h"
+
+int *mem;
+
+void *Thread(void *x) {
+ mem[0] = 42;
+ barrier_wait(&barrier);
+ return NULL;
+}
+
+int main() {
+ barrier_init(&barrier, 2);
+ mem = (int*)malloc(100);
+ pthread_t t;
+ pthread_create(&t, 0, Thread, 0);
+ barrier_wait(&barrier);
+ free(mem);
+ pthread_join(t, NULL);
+ return 0;
+}
+
+// CHECK: WARNING: ThreadSanitizer: data race
+// CHECK: Write of size 8 at {{.*}} by main thread{{.*}}:
+// CHECK: #0 free
+// CHECK: #{{(1|2)}} main
+// CHECK: Previous write of size 4 at {{.*}} by thread T1{{.*}}:
+// CHECK: #0 Thread
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/getline_nohang.cc b/third_party/llvm-project/compiler-rt/test/tsan/getline_nohang.cpp
similarity index 92%
rename from third_party/llvm-project/compiler-rt/test/tsan/getline_nohang.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/getline_nohang.cpp
index d103839..d1bb279 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/getline_nohang.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/getline_nohang.cpp
@@ -1,5 +1,8 @@
// RUN: %clangxx_tsan -O1 %s -o %t && %run %t
+// Data race randomly triggered.
+// UNSUPPORTED: target={{.*netbsd.*}}
+
// Make sure TSan doesn't deadlock on a file stream lock at program shutdown.
// See https://github.com/google/sanitizers/issues/454
#ifdef __FreeBSD__
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/global_race.cc b/third_party/llvm-project/compiler-rt/test/tsan/global_race.cpp
similarity index 65%
rename from third_party/llvm-project/compiler-rt/test/tsan/global_race.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/global_race.cpp
index 01df3b6..6695982 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/global_race.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/global_race.cpp
@@ -1,15 +1,15 @@
// RUN: rm -rf %t-dir
// RUN: mkdir %t-dir
-// RUN: %clangxx_tsan -O1 %s -o %t-dir/global_race.cc.exe && %deflake %run %t-dir/global_race.cc.exe 2>&1 \
+// RUN: %clangxx_tsan -O1 %s -o %t-dir/global_race.cpp.exe && %deflake %run %t-dir/global_race.cpp.exe 2>&1 \
// RUN: | FileCheck %s
// Also check that memory access instrumentation can be configured by either
// driver or legacy flags:
-// RUN: %clangxx_tsan -O1 %s -o %t-dir/global_race.cc.exe -fno-sanitize-thread-memory-access && not %deflake %run %t-dir/global_race.cc.exe 2>&1 \
+// RUN: %clangxx_tsan -O1 %s -o %t-dir/global_race.cpp.exe -fno-sanitize-thread-memory-access && not %deflake %run %t-dir/global_race.cpp.exe 2>&1 \
// RUN: | FileCheck --allow-empty --check-prefix=CHECK-MEMORY-ACCESS-OFF %s
-// RUN: %clangxx_tsan -O1 %s -o %t-dir/global_race.cc.exe -mllvm -tsan-instrument-memory-accesses=0 && not %deflake %run %t-dir/global_race.cc.exe 2>&1 \
+// RUN: %clangxx_tsan -O1 %s -o %t-dir/global_race.cpp.exe -mllvm -tsan-instrument-memory-accesses=0 && not %deflake %run %t-dir/global_race.cpp.exe 2>&1 \
// RUN: | FileCheck --allow-empty --check-prefix=CHECK-MEMORY-ACCESS-OFF %s
#include "test.h"
@@ -34,6 +34,6 @@
// CHECK: addr=[[ADDR:0x[0-9,a-f]+]]
// CHECK: WARNING: ThreadSanitizer: data race
-// CHECK: Location is global 'GlobalData' {{(of size 40 )?}}at [[ADDR]] (global_race.cc.exe+0x{{[0-9,a-f]+}})
+// CHECK: Location is global 'GlobalData' {{(of size 40 )?}}at [[ADDR]] (global_race.cpp.exe+0x{{[0-9,a-f]+}})
// CHECK-MEMORY-ACCESS-OFF-NOT: WARNING: ThreadSanitizer: data race
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/global_race2.cc b/third_party/llvm-project/compiler-rt/test/tsan/global_race2.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/global_race2.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/global_race2.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/global_race3.cc b/third_party/llvm-project/compiler-rt/test/tsan/global_race3.cpp
similarity index 89%
rename from third_party/llvm-project/compiler-rt/test/tsan/global_race3.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/global_race3.cpp
index e0d59d2..9d82dae 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/global_race3.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/global_race3.cpp
@@ -2,10 +2,10 @@
#include "test.h"
namespace XXX {
- struct YYY {
- static int ZZZ[10];
- };
- int YYY::ZZZ[10];
+struct YYY {
+ static int ZZZ[10];
+};
+int YYY::ZZZ[10];
}
void *Thread(void *a) {
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/halt_on_error.cc b/third_party/llvm-project/compiler-rt/test/tsan/halt_on_error.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/halt_on_error.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/halt_on_error.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/heap_race.cc b/third_party/llvm-project/compiler-rt/test/tsan/heap_race.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/heap_race.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/heap_race.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/ignore_free.cc b/third_party/llvm-project/compiler-rt/test/tsan/ignore_free.cpp
similarity index 73%
rename from third_party/llvm-project/compiler-rt/test/tsan/ignore_free.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/ignore_free.cpp
index 4e67895..51037b1 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/ignore_free.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/ignore_free.cpp
@@ -1,13 +1,6 @@
// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
#include "test.h"
-extern "C" {
-void AnnotateIgnoreReadsBegin(const char *f, int l);
-void AnnotateIgnoreReadsEnd(const char *f, int l);
-void AnnotateIgnoreWritesBegin(const char *f, int l);
-void AnnotateIgnoreWritesEnd(const char *f, int l);
-}
-
void *Thread(void *p) {
*(int*)p = 42;
barrier_wait(&barrier);
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/ignore_lib0.cc b/third_party/llvm-project/compiler-rt/test/tsan/ignore_lib0.cpp
similarity index 68%
rename from third_party/llvm-project/compiler-rt/test/tsan/ignore_lib0.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/ignore_lib0.cpp
index 2b217f2..cba58c6 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/ignore_lib0.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/ignore_lib0.cpp
@@ -1,12 +1,14 @@
// RUN: rm -rf %t-dir
// RUN: mkdir %t-dir
-// RUN: %clangxx_tsan -O1 %s -DLIB -fPIC -fno-sanitize=thread -shared -o %t-dir/libignore_lib0.so
-// RUN: %clangxx_tsan -O1 %s -L%t-dir -lignore_lib0 -o %t
+// RUN: %clangxx_tsan -O1 -fno-builtin %s -DLIB -fPIC -fno-sanitize=thread -shared -o %t-dir/libignore_lib0.so
+// RUN: %clangxx_tsan -O1 %s -L%t-dir -lignore_lib0 %link_libcxx_tsan -o %t
// RUN: echo running w/o suppressions:
// RUN: env LD_LIBRARY_PATH=%t-dir${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} %deflake %run %t | FileCheck %s --check-prefix=CHECK-NOSUPP
// RUN: echo running with suppressions:
// RUN: env LD_LIBRARY_PATH=%t-dir${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} %env_tsan_opts=suppressions='%s.supp' %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-WITHSUPP
+// RUN: echo running with generic suppression of noninstrumented code:
+// RUN: env LD_LIBRARY_PATH=%t-dir${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} %env_tsan_opts=ignore_noninstrumented_modules=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-WITHSUPP
// Tests that interceptors coming from a library specified in called_from_lib
// suppression are ignored.
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/ignore_lib0.cc.supp b/third_party/llvm-project/compiler-rt/test/tsan/ignore_lib0.cpp.supp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/ignore_lib0.cc.supp
rename to third_party/llvm-project/compiler-rt/test/tsan/ignore_lib0.cpp.supp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/ignore_lib1.cc b/third_party/llvm-project/compiler-rt/test/tsan/ignore_lib1.cpp
similarity index 85%
rename from third_party/llvm-project/compiler-rt/test/tsan/ignore_lib1.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/ignore_lib1.cpp
index 1660cf3..c8cd3f4 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/ignore_lib1.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/ignore_lib1.cpp
@@ -1,8 +1,8 @@
// RUN: rm -rf %t-dir
// RUN: mkdir %t-dir
-// RUN: %clangxx_tsan -O1 %s -DLIB -fPIC -fno-sanitize=thread -shared -o %t-dir/libignore_lib1.so
-// RUN: %clangxx_tsan -O1 %s -o %t-dir/executable
+// RUN: %clangxx_tsan -O1 -fno-builtin %s -DLIB -fPIC -fno-sanitize=thread -shared -o %t-dir/libignore_lib1.so
+// RUN: %clangxx_tsan -O1 %s %link_libcxx_tsan -o %t-dir/executable
// RUN: echo running w/o suppressions:
// RUN: %deflake %run %t-dir/executable | FileCheck %s --check-prefix=CHECK-NOSUPP
// RUN: echo running with suppressions:
@@ -12,7 +12,7 @@
// in called_from_lib suppression are ignored.
// REQUIRES: stable-runtime
-// UNSUPPORTED: powerpc64le
+// UNSUPPORTED: target=powerpc64le{{.*}}
// FIXME: This test regularly fails on powerpc64 LE possibly starting with
// r279664. Re-enable the test once the problem(s) have been fixed.
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/ignore_lib1.cc.supp b/third_party/llvm-project/compiler-rt/test/tsan/ignore_lib1.cpp.supp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/ignore_lib1.cc.supp
rename to third_party/llvm-project/compiler-rt/test/tsan/ignore_lib1.cpp.supp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/ignore_lib2.cc b/third_party/llvm-project/compiler-rt/test/tsan/ignore_lib2.cpp
similarity index 93%
rename from third_party/llvm-project/compiler-rt/test/tsan/ignore_lib2.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/ignore_lib2.cpp
index e0dac56..05b7c2e 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/ignore_lib2.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/ignore_lib2.cpp
@@ -3,7 +3,7 @@
// RUN: %clangxx_tsan -O1 %s -DLIB -fPIC -fno-sanitize=thread -shared -o %t-dir/libignore_lib2_0.so
// RUN: %clangxx_tsan -O1 %s -DLIB -fPIC -fno-sanitize=thread -shared -o %t-dir/libignore_lib2_1.so
-// RUN: %clangxx_tsan -O1 %s -o %t-dir/executable
+// RUN: %clangxx_tsan -O1 %s %link_libcxx_tsan -o %t-dir/executable
// RUN: %env_tsan_opts=suppressions='%s.supp' %deflake %run %t-dir/executable | FileCheck %s
// Tests that called_from_lib suppression matched against 2 libraries
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/ignore_lib2.cc.supp b/third_party/llvm-project/compiler-rt/test/tsan/ignore_lib2.cpp.supp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/ignore_lib2.cc.supp
rename to third_party/llvm-project/compiler-rt/test/tsan/ignore_lib2.cpp.supp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/ignore_lib3.cc b/third_party/llvm-project/compiler-rt/test/tsan/ignore_lib3.cpp
similarity index 93%
rename from third_party/llvm-project/compiler-rt/test/tsan/ignore_lib3.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/ignore_lib3.cpp
index a5af07f..b1a3940 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/ignore_lib3.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/ignore_lib3.cpp
@@ -2,7 +2,7 @@
// RUN: mkdir %t-dir
// RUN: %clangxx_tsan -O1 %s -DLIB -fPIC -fno-sanitize=thread -shared -o %t-dir/libignore_lib3.so
-// RUN: %clangxx_tsan -O1 %s -o %t-dir/executable
+// RUN: %clangxx_tsan -O1 %s %link_libcxx_tsan -o %t-dir/executable
// RUN: %env_tsan_opts=suppressions='%s.supp' %deflake %run %t-dir/executable | FileCheck %s
// Tests that unloading of a library matched against called_from_lib suppression
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/ignore_lib3.cc.supp b/third_party/llvm-project/compiler-rt/test/tsan/ignore_lib3.cpp.supp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/ignore_lib3.cc.supp
rename to third_party/llvm-project/compiler-rt/test/tsan/ignore_lib3.cpp.supp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/ignore_lib4.cc b/third_party/llvm-project/compiler-rt/test/tsan/ignore_lib4.cpp
similarity index 87%
rename from third_party/llvm-project/compiler-rt/test/tsan/ignore_lib4.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/ignore_lib4.cpp
index da636ae..d65ecd8 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/ignore_lib4.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/ignore_lib4.cpp
@@ -2,16 +2,16 @@
// RUN: mkdir %t-dir
// RUN: %clangxx_tsan -O1 %s -DLIB -fPIC -shared -o %t-dir/libignore_lib4.so
-// RUN: %clangxx_tsan -O1 %s -o %t-dir/executable
+// RUN: %clangxx_tsan -O1 %s %link_libcxx_tsan -o %t-dir/executable
// RUN: echo "called_from_lib:libignore_lib4.so" > %t-dir/executable.supp
// RUN: %env_tsan_opts=suppressions='%t-dir/executable.supp' %run %t-dir/executable 2>&1 | FileCheck %s
// powerpc64 big endian bots failed with "FileCheck error: '-' is empty" due
// to a segmentation fault.
-// UNSUPPORTED: powerpc64-unknown-linux-gnu
+// UNSUPPORTED: target=powerpc64-unknown-linux-gnu{{.*}}
// aarch64 bots failed with "called_from_lib suppression 'libignore_lib4.so'
// is matched against 2 libraries".
-// UNSUPPORTED: aarch64
+// UNSUPPORTED: target=aarch64{{.*}}
// Test longjmp in ignored lib.
// It used to crash since we jumped out of ScopedInterceptor scope.
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/ignore_lib5.cc.supp b/third_party/llvm-project/compiler-rt/test/tsan/ignore_lib5.cc.supp
deleted file mode 100644
index 9f4119e..0000000
--- a/third_party/llvm-project/compiler-rt/test/tsan/ignore_lib5.cc.supp
+++ /dev/null
@@ -1,2 +0,0 @@
-called_from_lib:/libignore_lib1.so$
-
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/ignore_lib5.cc b/third_party/llvm-project/compiler-rt/test/tsan/ignore_lib5.cpp
similarity index 86%
rename from third_party/llvm-project/compiler-rt/test/tsan/ignore_lib5.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/ignore_lib5.cpp
index d6c3f87..8850c12 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/ignore_lib5.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/ignore_lib5.cpp
@@ -1,15 +1,15 @@
// RUN: rm -rf %t-dir
// RUN: mkdir %t-dir
-// RUN: %clangxx_tsan -O1 %s -DLIB -fPIC -fno-sanitize=thread -shared -o %t-dir/libignore_lib1.so
-// RUN: %clangxx_tsan -O1 %s -o %t-dir/executable
+// RUN: %clangxx_tsan -O1 -fno-builtin %s -DLIB -fPIC -fno-sanitize=thread -shared -o %t-dir/libignore_lib1.so
+// RUN: %clangxx_tsan -O1 %s %link_libcxx_tsan -o %t-dir/executable
// RUN: echo running w/o suppressions:
// RUN: %deflake %run %t-dir/executable | FileCheck %s --check-prefix=CHECK-NOSUPP
// RUN: echo running with suppressions:
// RUN: %env_tsan_opts=suppressions='%s.supp' %run %t-dir/executable 2>&1 | FileCheck %s --check-prefix=CHECK-WITHSUPP
// REQUIRES: stable-runtime
-// UNSUPPORTED: powerpc64le
+// UNSUPPORTED: target=powerpc64le{{.*}}
// FIXME: This test occasionally fails on powerpc64 LE possibly starting with
// r279664. Re-enable the test once the problem(s) have been fixed.
@@ -18,6 +18,9 @@
// matched against 2 libraries: '/libignore_lib1.so' and '/libignore_lib1.so'
// This was caused by non-atomicity of reading of /proc/self/maps.
+// ReadProcMaps() on NetBSD does not handle >=1MB of memory layout information
+// UNSUPPORTED: target={{.*netbsd.*}}
+
#ifndef LIB
#include <dlfcn.h>
@@ -78,4 +81,3 @@
// CHECK-WITHSUPP-NOT: WARNING: ThreadSanitizer: data race
// CHECK-WITHSUPP: OK
-
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/ignore_lib1.cc.supp b/third_party/llvm-project/compiler-rt/test/tsan/ignore_lib5.cpp.supp
similarity index 100%
copy from third_party/llvm-project/compiler-rt/test/tsan/ignore_lib1.cc.supp
copy to third_party/llvm-project/compiler-rt/test/tsan/ignore_lib5.cpp.supp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/ignore_lib6.cpp b/third_party/llvm-project/compiler-rt/test/tsan/ignore_lib6.cpp
new file mode 100644
index 0000000..507c929
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/ignore_lib6.cpp
@@ -0,0 +1,74 @@
+// RUN: rm -rf %t-dir
+// RUN: mkdir %t-dir
+// RUN: %clangxx_tsan -O1 %s -DLIB -fPIC -fno-sanitize=thread -shared -o %t-dir/libignore_lib.so
+// RUN: %clangxx_tsan -O1 %s %link_libcxx_tsan -o %t-dir/executable
+// RUN: %env_tsan_opts=suppressions='%s.supp' %run %t-dir/executable 2>&1 | FileCheck %s
+
+// Copied from ignore_lib5.cpp:
+// REQUIRES: stable-runtime
+// UNSUPPORTED: target=powerpc64le{{.*}}
+// UNSUPPORTED: target={{.*netbsd.*}}
+
+// Test that pthread_detach works in libraries ignored by called_from_lib.
+// For more context see:
+// https://groups.google.com/forum/#!topic/thread-sanitizer/ecH2P0QUqPs
+
+#include "test.h"
+#include <dlfcn.h>
+#include <errno.h>
+#include <libgen.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string>
+#include <sys/mman.h>
+
+#ifndef LIB
+
+void *thr(void *arg) {
+ *(volatile long long *)arg = 1;
+ return 0;
+}
+
+int main(int argc, char **argv) {
+ std::string lib = std::string(dirname(argv[0])) + "/libignore_lib.so";
+ void *h = dlopen(lib.c_str(), RTLD_GLOBAL | RTLD_NOW);
+ if (h == 0)
+ exit(printf("failed to load the library (%d)\n", errno));
+ void (*libfunc)() = (void (*)())dlsym(h, "libfunc");
+ if (libfunc == 0)
+ exit(printf("failed to find the func (%d)\n", errno));
+ libfunc();
+
+ const int kThreads = 10;
+ pthread_t t[kThreads];
+ volatile long long data[kThreads];
+ for (int i = 0; i < kThreads; i++)
+ pthread_create(&t[i], 0, thr, (void *)&data[i]);
+ for (int i = 0; i < kThreads; i++) {
+ pthread_join(t[i], 0);
+ data[i] = 2;
+ }
+ fprintf(stderr, "DONE\n");
+}
+
+// CHECK-NOT: WARNING: ThreadSanitizer:
+// CHECK: DONE
+// CHECK-NOT: WARNING: ThreadSanitizer:
+
+#else // #ifdef LIB
+
+void *thr(void *p) {
+ sleep(1);
+ pthread_detach(pthread_self());
+ return 0;
+}
+
+extern "C" void libfunc() {
+ const int kThreads = 10;
+ pthread_t t[kThreads];
+ for (int i = 0; i < kThreads; i++)
+ pthread_create(&t[i], 0, thr, 0);
+ sleep(2);
+}
+
+#endif // #ifdef LIB
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/ignore_lib6.cpp.supp b/third_party/llvm-project/compiler-rt/test/tsan/ignore_lib6.cpp.supp
new file mode 100644
index 0000000..78ec27c
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/ignore_lib6.cpp.supp
@@ -0,0 +1 @@
+called_from_lib:/libignore_lib.so$
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/ignore_malloc.cc b/third_party/llvm-project/compiler-rt/test/tsan/ignore_malloc.cpp
similarity index 72%
rename from third_party/llvm-project/compiler-rt/test/tsan/ignore_malloc.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/ignore_malloc.cpp
index 100b4e5..6f293e3 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/ignore_malloc.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/ignore_malloc.cpp
@@ -1,13 +1,6 @@
// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
#include "test.h"
-extern "C" {
-void AnnotateIgnoreReadsBegin(const char *f, int l);
-void AnnotateIgnoreReadsEnd(const char *f, int l);
-void AnnotateIgnoreWritesBegin(const char *f, int l);
-void AnnotateIgnoreWritesEnd(const char *f, int l);
-}
-
int *g;
void *Thread(void *a) {
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/ignore_race.cc b/third_party/llvm-project/compiler-rt/test/tsan/ignore_race.cpp
similarity index 70%
rename from third_party/llvm-project/compiler-rt/test/tsan/ignore_race.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/ignore_race.cpp
index e410006..ecbc4c0 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/ignore_race.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/ignore_race.cpp
@@ -3,11 +3,6 @@
int Global;
-extern "C" void AnnotateIgnoreWritesBegin(const char *f, int l);
-extern "C" void AnnotateIgnoreWritesEnd(const char *f, int l);
-extern "C" void AnnotateIgnoreReadsBegin(const char *f, int l);
-extern "C" void AnnotateIgnoreReadsEnd(const char *f, int l);
-
void *Thread(void *x) {
AnnotateIgnoreWritesBegin(__FILE__, __LINE__);
AnnotateIgnoreReadsBegin(__FILE__, __LINE__);
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/ignore_sync.cc b/third_party/llvm-project/compiler-rt/test/tsan/ignore_sync.cpp
similarity index 76%
rename from third_party/llvm-project/compiler-rt/test/tsan/ignore_sync.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/ignore_sync.cpp
index ae24a8c..7a129fb 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/ignore_sync.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/ignore_sync.cpp
@@ -1,9 +1,5 @@
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
-#include <pthread.h>
-#include <stdio.h>
-
-extern "C" void AnnotateIgnoreSyncBegin(const char*, int);
-extern "C" void AnnotateIgnoreSyncEnd(const char*, int);
+#include "test.h"
int Global;
pthread_mutex_t Mutex = PTHREAD_MUTEX_INITIALIZER;
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/ignored-interceptors-mmap.cc b/third_party/llvm-project/compiler-rt/test/tsan/ignored-interceptors-mmap.cc
deleted file mode 100644
index 796ea93..0000000
--- a/third_party/llvm-project/compiler-rt/test/tsan/ignored-interceptors-mmap.cc
+++ /dev/null
@@ -1,62 +0,0 @@
-// RUN: %clangxx_tsan -O0 %s -o %t
-// RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NORMAL
-// RUN: %env_tsan_opts=ignore_interceptors_accesses=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-IGNORE
-// XFAIL: freebsd
-
-#include <errno.h>
-#include <sys/mman.h>
-
-#include "test.h"
-
-extern "C" {
-void AnnotateIgnoreReadsBegin(const char *f, int l);
-void AnnotateIgnoreReadsEnd(const char *f, int l);
-void AnnotateIgnoreWritesBegin(const char *f, int l);
-void AnnotateIgnoreWritesEnd(const char *f, int l);
-}
-
-void *global_p;
-
-int mmap_and_ignore_reads_and_writes() {
- const size_t kSize = sysconf(_SC_PAGESIZE);
- void *p = mmap(0, kSize, PROT_READ|PROT_WRITE,
- MAP_PRIVATE|MAP_ANON, -1, 0);
- if (p == MAP_FAILED)
- return printf("mmap failed with %d\n", errno);
- munmap(p, kSize);
-
- void *new_p = mmap(p, kSize, PROT_READ|PROT_WRITE,
- MAP_PRIVATE|MAP_ANON, -1, 0);
- if (p == MAP_FAILED || p != new_p)
- return printf("second mmap failed with %d\n", errno);
-
- AnnotateIgnoreWritesBegin(__FILE__, __LINE__);
- global_p = p;
- AnnotateIgnoreWritesEnd(__FILE__, __LINE__);
- barrier_wait(&barrier);
- return 0;
-}
-
-void *Thread(void *a) {
- barrier_wait(&barrier);
-
- ((int*)global_p)[1] = 10;
- printf("Read the zero value from mmapped memory %d\n", ((int*)global_p)[1]);
- return 0;
-}
-
-int main() {
- barrier_init(&barrier, 2);
- pthread_t t;
- pthread_create(&t, 0, Thread, 0);
- if (mmap_and_ignore_reads_and_writes())
- return 1;
- pthread_join(t, 0);
- printf("OK\n");
- return 0;
-}
-
-// CHECK-NORMAL: WARNING: ThreadSanitizer: data race
-// CHECK-NORMAL: OK
-// CHECK-IGNORE_NOT: WARNING: ThreadSanitizer: data race
-// CHECK-IGNORE: OK
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/ignored-interceptors-mmap.cpp b/third_party/llvm-project/compiler-rt/test/tsan/ignored-interceptors-mmap.cpp
new file mode 100644
index 0000000..2b35627
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/ignored-interceptors-mmap.cpp
@@ -0,0 +1,55 @@
+// RUN: %clangxx_tsan -O0 %s -o %t
+// RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-RACE
+// Test size larger than clear_shadow_mmap_threshold, which is handled differently.
+// RUN: not %run %t - 262144 2>&1 | FileCheck %s --check-prefix=CHECK-RACE
+// RUN: %run %t ignore 2>&1 | FileCheck %s --check-prefix=CHECK-IGNORE
+
+#include <sys/mman.h>
+#include <string.h>
+#include <assert.h>
+#include <atomic>
+
+#include "test.h"
+
+// Use atomic to ensure we do not have a race for the pointer value itself. We
+// only want to check races in the mmap'd memory to isolate the test that mmap
+// respects ignore annotations.
+std::atomic<int*> global_p;
+
+void mmap_ignored(bool ignore, size_t size) {
+ if (ignore) AnnotateIgnoreWritesBegin(__FILE__, __LINE__);
+ void *p =
+ mmap(0, size, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0);
+ if (ignore) AnnotateIgnoreWritesEnd(__FILE__, __LINE__);
+
+ // Use relaxed to retain the race between the mmap call and the memory write
+ global_p.store((int *)p, std::memory_order_relaxed);
+ barrier_wait(&barrier);
+}
+
+void *WriteToMemory(void *unused) {
+ barrier_wait(&barrier);
+ global_p[0] = 7;
+ return 0;
+}
+
+// Create race between allocating (mmap) and writing memory
+int main(int argc, const char *argv[]) {
+ bool ignore = (argc > 1) && (strcmp(argv[1], "ignore") == 0);
+ size_t size = argc > 2 ? atoi(argv[2]) : sysconf(_SC_PAGESIZE);
+
+ barrier_init(&barrier, 2);
+ pthread_t t;
+ pthread_create(&t, 0, WriteToMemory, 0);
+ mmap_ignored(ignore, size);
+ pthread_join(t, 0);
+
+ assert(global_p[0] == 7);
+ printf("OK\n");
+ return 0;
+}
+
+// CHECK-RACE: WARNING: ThreadSanitizer: data race
+// CHECK-RACE: OK
+// CHECK-IGNORE-NOT: WARNING: ThreadSanitizer: data race
+// CHECK-IGNORE: OK
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/ignorelist.cpp b/third_party/llvm-project/compiler-rt/test/tsan/ignorelist.cpp
new file mode 100644
index 0000000..dc7ed6d
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/ignorelist.cpp
@@ -0,0 +1,30 @@
+// Test ignorelist functionality for TSan.
+
+// RUN: echo "fun:*Ignorelisted_Thread2*" > %t.ignorelist
+// RUN: %clangxx_tsan -O1 %s -fsanitize-ignorelist=%t.ignorelist -o %t && %run %t 2>&1 | FileCheck %s
+#include <pthread.h>
+#include <stdio.h>
+
+int Global;
+
+void *Thread1(void *x) {
+ Global++;
+ return NULL;
+}
+
+void *Ignorelisted_Thread2(void *x) {
+ Global--;
+ return NULL;
+}
+
+int main() {
+ pthread_t t[2];
+ pthread_create(&t[0], NULL, Thread1, NULL);
+ pthread_create(&t[1], NULL, Ignorelisted_Thread2, NULL);
+ pthread_join(t[0], NULL);
+ pthread_join(t[1], NULL);
+ fprintf(stderr, "PASS\n");
+ return 0;
+}
+
+// CHECK-NOT: ThreadSanitizer: data race
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/ignorelist2.cpp b/third_party/llvm-project/compiler-rt/test/tsan/ignorelist2.cpp
new file mode 100644
index 0000000..f3f636a
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/ignorelist2.cpp
@@ -0,0 +1,49 @@
+// Test that ignorelisted functions are still contained in the stack trace.
+
+// RUN: echo "fun:*Ignorelisted_Thread2*" > %t.ignorelist
+// RUN: echo "fun:*CallTouchGlobal*" >> %t.ignorelist
+
+// RUN: %clangxx_tsan -O1 %s -fsanitize-ignorelist=%t.ignorelist -o %t
+// RUN: %deflake %run %t 2>&1 | FileCheck %s
+#include "test.h"
+
+int Global;
+
+void *Thread1(void *x) {
+ barrier_wait(&barrier);
+ // CHECK: ThreadSanitizer: data race
+ // CHECK: Write of size 4
+ // CHECK: #0 Thread1{{.*}}ignorelist2.cpp:[[@LINE+1]]
+ Global++;
+ return NULL;
+}
+
+__attribute__((noinline)) void TouchGlobal() {
+ // CHECK: Previous write of size 4
+ // CHECK: #0 TouchGlobal{{.*}}ignorelist2.cpp:[[@LINE+1]]
+ Global--;
+}
+
+__attribute__((noinline)) void CallTouchGlobal() {
+ // CHECK: #1 CallTouchGlobal{{.*}}ignorelist2.cpp:[[@LINE+1]]
+ TouchGlobal();
+}
+
+void *Ignorelisted_Thread2(void *x) {
+ Global--;
+ // CHECK: #2 Ignorelisted_Thread2{{.*}}ignorelist2.cpp:[[@LINE+1]]
+ CallTouchGlobal();
+ barrier_wait(&barrier);
+ return NULL;
+}
+
+int main() {
+ barrier_init(&barrier, 2);
+ pthread_t t[2];
+ pthread_create(&t[0], NULL, Thread1, NULL);
+ pthread_create(&t[1], NULL, Ignorelisted_Thread2, NULL);
+ pthread_join(t[0], NULL);
+ pthread_join(t[1], NULL);
+ fprintf(stderr, "PASS\n");
+ return 0;
+}
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/inlined_memcpy_race.cc b/third_party/llvm-project/compiler-rt/test/tsan/inlined_memcpy_race.cpp
similarity index 83%
rename from third_party/llvm-project/compiler-rt/test/tsan/inlined_memcpy_race.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/inlined_memcpy_race.cpp
index 4d08589..5f17cfb 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/inlined_memcpy_race.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/inlined_memcpy_race.cpp
@@ -29,9 +29,8 @@
}
// CHECK: WARNING: ThreadSanitizer: data race
-// CHECK: #0 memset
-// CHECK: #1 MemSetThread
+// CHECK: #0 {{.*}}memset
+// CHECK: #{{[12]}} MemSetThread
// CHECK: Previous write
-// CHECK: #0 {{(memcpy|memmove)}}
-// CHECK: #1 MemCpyThread
-
+// CHECK: #0 {{.*mem(cpy|move)}}
+// CHECK: #{{[12]}} MemCpyThread
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/inlined_memcpy_race2.cc b/third_party/llvm-project/compiler-rt/test/tsan/inlined_memcpy_race2.cpp
similarity index 83%
rename from third_party/llvm-project/compiler-rt/test/tsan/inlined_memcpy_race2.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/inlined_memcpy_race2.cpp
index 906a52b..cd4bb58 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/inlined_memcpy_race2.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/inlined_memcpy_race2.cpp
@@ -30,8 +30,8 @@
}
// CHECK: WARNING: ThreadSanitizer: data race
-// CHECK: #0 memset
-// CHECK: #1 MemSetThread
+// CHECK: #0 {{.*}}memset
+// CHECK: #{{[12]}} MemSetThread
// CHECK: Previous write
-// CHECK: #0 {{(memcpy|memmove)}}
-// CHECK: #1 MemMoveThread
+// CHECK: #0 {{.*mem(cpy|move)}}
+// CHECK: #{{[12]}} MemMoveThread
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/java.h b/third_party/llvm-project/compiler-rt/test/tsan/java.h
index e9aa4ee..9df7fb6 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/java.h
+++ b/third_party/llvm-project/compiler-rt/test/tsan/java.h
@@ -1,7 +1,7 @@
#include "test.h"
extern "C" {
-typedef unsigned long jptr; // NOLINT
+typedef unsigned long jptr;
void __tsan_java_preinit(const char *libjvm_path);
void __tsan_java_init(jptr heap_begin, jptr heap_size);
int __tsan_java_fini();
@@ -22,6 +22,8 @@
void __tsan_read1_pc(jptr addr, jptr pc);
void __tsan_write1_pc(jptr addr, jptr pc);
+void __tsan_func_entry(jptr pc);
+void __tsan_func_exit();
}
const jptr kExternalPCBit = 1ULL << 60;
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/java_alloc.cc b/third_party/llvm-project/compiler-rt/test/tsan/java_alloc.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/java_alloc.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/java_alloc.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/java_finalizer.cc b/third_party/llvm-project/compiler-rt/test/tsan/java_finalizer.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/java_finalizer.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/java_finalizer.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/java_finalizer2.cpp b/third_party/llvm-project/compiler-rt/test/tsan/java_finalizer2.cpp
new file mode 100644
index 0000000..8752890
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/java_finalizer2.cpp
@@ -0,0 +1,86 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
+// Regression test for https://github.com/golang/go/issues/39186
+
+// pthread barriers are not available on OS X
+// UNSUPPORTED: darwin
+
+#include "java.h"
+#include <string.h>
+
+struct Heap {
+ uint64_t data;
+ uint64_t ready;
+ uint64_t finalized;
+ uint64_t wg;
+ pthread_barrier_t barrier_finalizer;
+ pthread_barrier_t barrier_ballast;
+};
+
+void *Thread1(void *p) {
+ Heap* heap = (Heap*)p;
+ pthread_barrier_wait(&heap->barrier_finalizer);
+ __tsan_java_finalize();
+ __atomic_fetch_add(&heap->wg, 1, __ATOMIC_RELEASE);
+ __atomic_store_n(&heap->finalized, 1, __ATOMIC_RELAXED);
+ return 0;
+}
+
+void *Thread2(void *p) {
+ Heap* heap = (Heap*)p;
+ pthread_barrier_wait(&heap->barrier_finalizer);
+ heap->data = 1;
+ __atomic_store_n(&heap->ready, 1, __ATOMIC_RELEASE);
+ return 0;
+}
+
+void *Thread3(void *p) {
+ Heap* heap = (Heap*)p;
+ pthread_barrier_wait(&heap->barrier_finalizer);
+ while (__atomic_load_n(&heap->ready, __ATOMIC_ACQUIRE) != 1)
+ pthread_yield();
+ while (__atomic_load_n(&heap->finalized, __ATOMIC_RELAXED) != 1)
+ pthread_yield();
+ __atomic_fetch_add(&heap->wg, 1, __ATOMIC_RELEASE);
+ return 0;
+}
+
+void *Ballast(void *p) {
+ Heap* heap = (Heap*)p;
+ pthread_barrier_wait(&heap->barrier_ballast);
+ return 0;
+}
+
+int main() {
+ Heap* heap = (Heap*)calloc(sizeof(Heap), 2) + 1;
+ __tsan_java_init((jptr)heap, sizeof(*heap));
+ __tsan_java_alloc((jptr)heap, sizeof(*heap));
+ // Ballast threads merely make the bug a bit easier to trigger.
+ const int kBallastThreads = 100;
+ pthread_barrier_init(&heap->barrier_finalizer, 0, 4);
+ pthread_barrier_init(&heap->barrier_ballast, 0, kBallastThreads + 1);
+ pthread_t th[3];
+ pthread_create(&th[0], 0, Thread1, heap);
+ pthread_create(&th[1], 0, Thread2, heap);
+ pthread_t ballast[kBallastThreads];
+ for (int i = 0; i < kBallastThreads; i++)
+ pthread_create(&ballast[i], 0, Ballast, heap);
+ pthread_create(&th[2], 0, Thread3, heap);
+ pthread_barrier_wait(&heap->barrier_ballast);
+ for (int i = 0; i < kBallastThreads; i++)
+ pthread_join(ballast[i], 0);
+ pthread_barrier_wait(&heap->barrier_finalizer);
+ while (__atomic_load_n(&heap->wg, __ATOMIC_ACQUIRE) != 2)
+ pthread_yield();
+ if (heap->data != 1)
+ exit(printf("no data\n"));
+ for (int i = 0; i < 3; i++)
+ pthread_join(th[i], 0);
+ pthread_barrier_destroy(&heap->barrier_ballast);
+ pthread_barrier_destroy(&heap->barrier_finalizer);
+ __tsan_java_free((jptr)heap, sizeof(*heap));
+ fprintf(stderr, "DONE\n");
+ return __tsan_java_fini();
+}
+
+// CHECK-NOT: WARNING: ThreadSanitizer: data race
+// CHECK: DONE
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/java_find.cc b/third_party/llvm-project/compiler-rt/test/tsan/java_find.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/java_find.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/java_find.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/java_heap_init.cc b/third_party/llvm-project/compiler-rt/test/tsan/java_heap_init.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/java_heap_init.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/java_heap_init.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/java_lock.cc b/third_party/llvm-project/compiler-rt/test/tsan/java_lock.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/java_lock.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/java_lock.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/java_lock_move.cc b/third_party/llvm-project/compiler-rt/test/tsan/java_lock_move.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/java_lock_move.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/java_lock_move.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/java_lock_rec.cc b/third_party/llvm-project/compiler-rt/test/tsan/java_lock_rec.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/java_lock_rec.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/java_lock_rec.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/java_lock_rec_race.cc b/third_party/llvm-project/compiler-rt/test/tsan/java_lock_rec_race.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/java_lock_rec_race.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/java_lock_rec_race.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/java_move_overlap.cc b/third_party/llvm-project/compiler-rt/test/tsan/java_move_overlap.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/java_move_overlap.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/java_move_overlap.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/java_move_overlap_race.cc b/third_party/llvm-project/compiler-rt/test/tsan/java_move_overlap_race.cpp
similarity index 80%
rename from third_party/llvm-project/compiler-rt/test/tsan/java_move_overlap_race.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/java_move_overlap_race.cpp
index fbbcf2c..efe90b6 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/java_move_overlap_race.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/java_move_overlap_race.cpp
@@ -1,6 +1,6 @@
// RUN: %clangxx_tsan -O1 %s -o %t
-// RUN: %deflake %run %t 2>&1 | FileCheck %s
-// RUN: %deflake %run %t arg 2>&1 | FileCheck %s
+// RUN: %run %t 2>&1 | FileCheck %s
+// RUN: %run %t arg 2>&1 | FileCheck %s
#include "java.h"
jptr varaddr1_old;
@@ -50,6 +50,7 @@
return __tsan_java_fini();
}
-// CHECK: WARNING: ThreadSanitizer: data race
-// CHECK: WARNING: ThreadSanitizer: data race
+// Note: there is a race on the moved object (which we used to detect),
+// but now __tsan_java_move resets the object shadow, so we don't detect it anymore.
+// CHECK-NOT: WARNING: ThreadSanitizer: data race
// CHECK: DONE
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/java_race.cc b/third_party/llvm-project/compiler-rt/test/tsan/java_race.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/java_race.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/java_race.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/java_race_move.cc b/third_party/llvm-project/compiler-rt/test/tsan/java_race_move.cpp
similarity index 72%
rename from third_party/llvm-project/compiler-rt/test/tsan/java_race_move.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/java_race_move.cpp
index 6d1b092..eb4dba8 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/java_race_move.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/java_race_move.cpp
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
#include "java.h"
jptr varaddr;
@@ -31,5 +31,7 @@
return __tsan_java_fini();
}
-// CHECK: WARNING: ThreadSanitizer: data race
+// Note: there is a race on the moved object (which we used to detect),
+// but now __tsan_java_move resets the object shadow, so we don't detect it anymore.
+// CHECK-NOT: WARNING: ThreadSanitizer: data race
// CHECK: DONE
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/java_race_pc.cc b/third_party/llvm-project/compiler-rt/test/tsan/java_race_pc.cpp
similarity index 94%
rename from third_party/llvm-project/compiler-rt/test/tsan/java_race_pc.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/java_race_pc.cpp
index be1c5f2..ccd996c 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/java_race_pc.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/java_race_pc.cpp
@@ -2,7 +2,7 @@
// This test fails on powerpc64 big endian.
// The Tsan report is returning wrong information about
// the location of the race.
-// XFAIL: powerpc64-unknown-linux-gnu
+// XFAIL: target=powerpc64-unknown-linux-gnu{{.*}}
#include "java.h"
void foobar() {
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/java_rwlock.cc b/third_party/llvm-project/compiler-rt/test/tsan/java_rwlock.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/java_rwlock.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/java_rwlock.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/java_symbolization.cc b/third_party/llvm-project/compiler-rt/test/tsan/java_symbolization.cc
deleted file mode 100644
index f82bd5e..0000000
--- a/third_party/llvm-project/compiler-rt/test/tsan/java_symbolization.cc
+++ /dev/null
@@ -1,40 +0,0 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
-#include "java.h"
-#include <memory.h>
-
-extern "C" void __tsan_symbolize_external_ex(
- jptr pc, void (*add_frame)(void *, const char *, const char *, int, int),
- void *ctx) {
- if (pc == (1234 | kExternalPCBit)) {
- add_frame(ctx, "MyInnerFunc", "MyInnerFile.java", 1234, 56);
- add_frame(ctx, "MyOuterFunc", "MyOuterFile.java", 4321, 65);
- }
-}
-
-void *Thread(void *p) {
- barrier_wait(&barrier);
- __tsan_write1_pc((jptr)p, 1234 | kExternalPCBit);
- return 0;
-}
-
-int main() {
- barrier_init(&barrier, 2);
- int const kHeapSize = 1024 * 1024;
- jptr jheap = (jptr)malloc(kHeapSize + 8) + 8;
- __tsan_java_init(jheap, kHeapSize);
- const int kBlockSize = 16;
- __tsan_java_alloc(jheap, kBlockSize);
- pthread_t th;
- pthread_create(&th, 0, Thread, (void*)jheap);
- __tsan_write1_pc((jptr)jheap, 1234 | kExternalPCBit);
- barrier_wait(&barrier);
- pthread_join(th, 0);
- __tsan_java_free(jheap, kBlockSize);
- fprintf(stderr, "DONE\n");
- return __tsan_java_fini();
-}
-
-// CHECK: WARNING: ThreadSanitizer: data race
-// CHECK: #0 MyInnerFunc MyInnerFile.java:1234:56
-// CHECK: #1 MyOuterFunc MyOuterFile.java:4321:65
-// CHECK: DONE
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/java_symbolization.cpp b/third_party/llvm-project/compiler-rt/test/tsan/java_symbolization.cpp
new file mode 100644
index 0000000..e6a3ee8
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/java_symbolization.cpp
@@ -0,0 +1,75 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
+#include "java.h"
+#include <memory.h>
+
+#if (__APPLE__)
+__attribute__((weak)) // Required for dyld macOS 12.0+
+#endif
+__attribute__((disable_sanitizer_instrumentation))
+extern "C" void
+__tsan_symbolize_external_ex(jptr pc,
+ void (*add_frame)(void *, const char *,
+ const char *, int, int),
+ void *ctx) {
+ if (pc == (1234 | kExternalPCBit)) {
+ add_frame(ctx, "MyInnerFunc", "MyInnerFile.java", 1234, 56);
+ add_frame(ctx, "MyOuterFunc", "MyOuterFile.java", 4321, 65);
+ }
+ if (pc == (2345 | kExternalPCBit)) {
+ add_frame(ctx, "Caller1", "CallerFile.java", 111, 22);
+ add_frame(ctx, "Caller2", "CallerFile.java", 333, 44);
+ }
+ if (pc == (3456 | kExternalPCBit)) {
+ add_frame(ctx, "Allocer1", "Alloc.java", 11, 222);
+ add_frame(ctx, "Allocer2", "Alloc.java", 33, 444);
+ }
+}
+
+void *Thread(void *p) {
+ barrier_wait(&barrier);
+ __tsan_func_entry(2345 | kExternalPCBit);
+ __tsan_write1_pc((jptr)p + 16, 1234 | kExternalPCBit);
+ __tsan_func_exit();
+ return 0;
+}
+
+jptr const kHeapSize = 64 * 1024;
+jptr java_heap[kHeapSize];
+
+int main() {
+ barrier_init(&barrier, 2);
+ jptr jheap = (jptr)java_heap;
+ __tsan_java_init(jheap, kHeapSize);
+ const int kBlockSize = 32;
+ __tsan_func_entry(3456 | kExternalPCBit);
+ __tsan_java_alloc(jheap, kBlockSize);
+ print_address("addr:", 2, jheap, jheap + 16);
+ __tsan_func_exit();
+ pthread_t th;
+ pthread_create(&th, 0, Thread, (void*)jheap);
+ __tsan_func_entry(2345 | kExternalPCBit);
+ __tsan_write1_pc(jheap + 16, 1234 | kExternalPCBit);
+ __tsan_func_exit();
+ barrier_wait(&barrier);
+ pthread_join(th, 0);
+ __tsan_java_free(jheap, kBlockSize);
+ fprintf(stderr, "DONE\n");
+ return __tsan_java_fini();
+}
+
+// CHECK: addr:[[BLOCK:0x[0-9,a-f]+]] [[ADDR:0x[0-9,a-f]+]]
+// CHECK: WARNING: ThreadSanitizer: data race
+// CHECK: Write of size 1 at [[ADDR]] by thread T1:
+// CHECK: #0 MyInnerFunc MyInnerFile.java:1234:56
+// CHECK: #1 MyOuterFunc MyOuterFile.java:4321:65
+// CHECK: #2 Caller1 CallerFile.java:111:22
+// CHECK: #3 Caller2 CallerFile.java:333:44
+// CHECK: Previous write of size 1 at [[ADDR]] by main thread:
+// CHECK: #0 MyInnerFunc MyInnerFile.java:1234:56
+// CHECK: #1 MyOuterFunc MyOuterFile.java:4321:65
+// CHECK: #2 Caller1 CallerFile.java:111:22
+// CHECK: #3 Caller2 CallerFile.java:333:44
+// CHECK: Location is heap block of size 32 at [[BLOCK]] allocated by main thread:
+// CHECK: #0 Allocer1 Alloc.java:11:222
+// CHECK: #1 Allocer2 Alloc.java:33:444
+// CHECK: DONE
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/java_symbolization_legacy.cc b/third_party/llvm-project/compiler-rt/test/tsan/java_symbolization_legacy.cpp
similarity index 78%
rename from third_party/llvm-project/compiler-rt/test/tsan/java_symbolization_legacy.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/java_symbolization_legacy.cpp
index aa5ec0c..bdf986a 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/java_symbolization_legacy.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/java_symbolization_legacy.cpp
@@ -2,10 +2,13 @@
#include "java.h"
#include <memory.h>
-extern "C" bool __tsan_symbolize_external(jptr pc,
- char *func_buf, jptr func_siz,
- char *file_buf, jptr file_siz,
- int *line, int *col) {
+#if (__APPLE__)
+__attribute__((weak)) // Required for dyld macOS 12.0+
+#endif
+__attribute__((disable_sanitizer_instrumentation))
+extern "C" bool
+__tsan_symbolize_external(jptr pc, char *func_buf, jptr func_siz,
+ char *file_buf, jptr file_siz, int *line, int *col) {
if (pc == (1234 | kExternalPCBit)) {
memcpy(func_buf, "MyFunc", sizeof("MyFunc"));
memcpy(file_buf, "MyFile.java", sizeof("MyFile.java"));
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/java_volatile.cc b/third_party/llvm-project/compiler-rt/test/tsan/java_volatile.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/java_volatile.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/java_volatile.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/large_malloc_meta.cc b/third_party/llvm-project/compiler-rt/test/tsan/large_malloc_meta.cpp
similarity index 97%
rename from third_party/llvm-project/compiler-rt/test/tsan/large_malloc_meta.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/large_malloc_meta.cpp
index e830048..0d0eec3 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/large_malloc_meta.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/large_malloc_meta.cpp
@@ -1,4 +1,7 @@
// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
+
+// UNSUPPORTED: ios
+
#include "test.h"
#include <sys/mman.h>
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/libcxx/lit.local.cfg b/third_party/llvm-project/compiler-rt/test/tsan/libcxx/lit.local.cfg.py
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/libcxx/lit.local.cfg
rename to third_party/llvm-project/compiler-rt/test/tsan/libcxx/lit.local.cfg.py
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/libcxx/std_shared_ptr.cc b/third_party/llvm-project/compiler-rt/test/tsan/libcxx/std_shared_ptr.cpp
similarity index 83%
rename from third_party/llvm-project/compiler-rt/test/tsan/libcxx/std_shared_ptr.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/libcxx/std_shared_ptr.cpp
index 191a17c..e8e168a 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/libcxx/std_shared_ptr.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/libcxx/std_shared_ptr.cpp
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s %link_libcxx_tsan -o %t && %run %t 2>&1 | FileCheck %s
#include <stdio.h>
#include <memory>
#include <thread>
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/after.c b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/after.c
new file mode 100644
index 0000000..7ec2e10
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/after.c
@@ -0,0 +1,41 @@
+// RUN: %clang_tsan %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
+
+#include "dispatch/dispatch.h"
+
+#include <stdio.h>
+
+long my_global;
+long my_global2;
+dispatch_semaphore_t done;
+
+void callback(void *context) {
+ my_global2 = 42;
+
+ dispatch_semaphore_signal(done);
+}
+
+int main(int argc, const char *argv[]) {
+ fprintf(stderr, "start\n");
+ done = dispatch_semaphore_create(0);
+
+ dispatch_queue_t q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
+
+ my_global = 10;
+ dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10 * NSEC_PER_MSEC)), q, ^{
+ my_global = 42;
+
+ dispatch_semaphore_signal(done);
+ });
+
+ my_global2 = 10;
+ dispatch_after_f(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10 * NSEC_PER_MSEC)), q, NULL, &callback);
+
+ dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);
+ dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);
+ fprintf(stderr, "done\n");
+ return 0;
+}
+
+// CHECK: start
+// CHECK: done
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-apply-race.mm b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/apply-race.c
similarity index 85%
rename from third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-apply-race.mm
rename to third_party/llvm-project/compiler-rt/test/tsan/libdispatch/apply-race.c
index a7bf663..10e954c 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-apply-race.mm
+++ b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/apply-race.c
@@ -1,9 +1,9 @@
-// RUN: %clang_tsan %s -o %t -framework Foundation
+// RUN: %clang_tsan %s -o %t
// RUN: %deflake %run %t 2>&1 | FileCheck %s
-#import <Foundation/Foundation.h>
+#include <dispatch/dispatch.h>
-#import "../test.h"
+#include "../test.h"
long global;
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/apply.c b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/apply.c
new file mode 100644
index 0000000..08735b3
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/apply.c
@@ -0,0 +1,57 @@
+// RUN: %clang_tsan %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
+
+#include <dispatch/dispatch.h>
+
+#include "../test.h"
+
+const size_t size = 2;
+long global;
+long array[size];
+
+void callback(void *context, size_t i) {
+ long n = global;
+ array[i] = n + i;
+ barrier_wait(&barrier);
+}
+
+int main(int argc, const char *argv[]) {
+ fprintf(stderr, "start\n");
+
+ // Warm up GCD (workaround for macOS Sierra where dispatch_apply might run single-threaded).
+ dispatch_sync(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ });
+
+ dispatch_queue_t q = dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT);
+
+ global = 42;
+
+ barrier_init(&barrier, size);
+ dispatch_apply(size, q, ^(size_t i) {
+ long n = global;
+ array[i] = n + i;
+ barrier_wait(&barrier);
+ });
+
+ for (size_t i = 0; i < size; i++) {
+ fprintf(stderr, "array[%ld] = %ld\n", i, array[i]);
+ }
+
+ global = 142;
+
+ barrier_init(&barrier, size);
+ dispatch_apply_f(size, q, NULL, &callback);
+
+ for (size_t i = 0; i < size; i++) {
+ fprintf(stderr, "array[%ld] = %ld\n", i, array[i]);
+ }
+
+ fprintf(stderr, "done\n");
+ return 0;
+}
+
+// CHECK: start
+// CHECK: array[0] = 42
+// CHECK: array[1] = 43
+// CHECK: array[0] = 142
+// CHECK: array[1] = 143
+// CHECK: done
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/async-norace.c b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/async-norace.c
new file mode 100644
index 0000000..ccda845
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/async-norace.c
@@ -0,0 +1,26 @@
+// RUN: %clang_tsan %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
+
+#include "dispatch/dispatch.h"
+
+#include <stdio.h>
+
+long global;
+
+int main() {
+ fprintf(stderr, "Hello world.\n");
+ dispatch_semaphore_t done = dispatch_semaphore_create(0);
+
+ global = 42;
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+ global = 43;
+
+ dispatch_semaphore_signal(done);
+ });
+
+ dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);
+ fprintf(stderr, "Done.\n");
+}
+
+// CHECK: Hello world.
+// CHECK: Done.
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-async-race.mm b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/async-race.c
similarity index 64%
rename from third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-async-race.mm
rename to third_party/llvm-project/compiler-rt/test/tsan/libdispatch/async-race.c
index cb8fb4b..6701f10 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-async-race.mm
+++ b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/async-race.c
@@ -1,15 +1,16 @@
-// RUN: %clang_tsan %s -o %t -framework Foundation
+// RUN: %clang_tsan %s -o %t
// RUN: %deflake %run %t 2>&1 | FileCheck %s
-#import <Foundation/Foundation.h>
+#include "dispatch/dispatch.h"
-#import "../test.h"
+#include "../test.h"
long global;
int main() {
- NSLog(@"Hello world.");
+ fprintf(stderr, "Hello world.\n");
print_address("addr=", 1, &global);
+ dispatch_semaphore_t done = dispatch_semaphore_create(0);
barrier_init(&barrier, 2);
global = 42;
@@ -22,17 +23,15 @@
barrier_wait(&barrier);
global = 44;
- dispatch_sync(dispatch_get_main_queue(), ^{
- CFRunLoopStop(CFRunLoopGetCurrent());
- });
+ dispatch_semaphore_signal(done);
});
- CFRunLoopRun();
- NSLog(@"Done.");
+ dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);
+ fprintf(stderr, "Done.\n");
}
// CHECK: Hello world.
// CHECK: addr=[[ADDR:0x[0-9,a-f]+]]
// CHECK: WARNING: ThreadSanitizer: data race
-// CHECK: Location is global 'global' {{(of size 8 )?}}at [[ADDR]] (gcd-async-race.mm.tmp+0x{{[0-9,a-f]+}})
+// CHECK: Location is global 'global' {{(of size 8 )?}}at [[ADDR]] (async-race.c.tmp+0x{{[0-9,a-f]+}})
// CHECK: Done.
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/async_and_wait.c b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/async_and_wait.c
new file mode 100644
index 0000000..b8d2398
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/async_and_wait.c
@@ -0,0 +1,44 @@
+// RUN: %clang_tsan %s -o %t -undefined dynamic_lookup
+// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
+
+#include "dispatch/dispatch.h"
+
+#include <stdio.h>
+
+// Allow compilation with pre-macOS 10.14 (and aligned) SDKs
+API_AVAILABLE(macos(10.14), ios(12.0), tvos(12.0), watchos(5.0))
+DISPATCH_EXPORT DISPATCH_NONNULL_ALL DISPATCH_NOTHROW
+void dispatch_async_and_wait(dispatch_queue_t queue,
+ DISPATCH_NOESCAPE dispatch_block_t block);
+
+long global;
+
+int main() {
+ // Guard execution on pre-macOS 10.14 (and aligned) platforms
+ if (dispatch_async_and_wait == NULL) {
+ fprintf(stderr, "Done.\n");
+ return 0;
+ }
+
+ dispatch_queue_t q = dispatch_queue_create("my.queue", DISPATCH_QUEUE_SERIAL);
+ dispatch_semaphore_t s = dispatch_semaphore_create(0);
+
+ // Force queue to context switch onto separate thread.
+ dispatch_async(q, ^{
+ dispatch_semaphore_wait(s, DISPATCH_TIME_FOREVER);
+ });
+ dispatch_semaphore_signal(s);
+
+ global++;
+ dispatch_async_and_wait(q, ^{
+ // The queue continues to execute on separate thread. This would cause a
+ // race if we had used `dispatch_async()` without the `_and_wait` part.
+ global++;
+ });
+ global++;
+
+ fprintf(stderr, "Done.\n");
+ return 0;
+}
+
+// CHECK: Done.
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-barrier-race.mm b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/barrier-race.c
similarity index 74%
rename from third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-barrier-race.mm
rename to third_party/llvm-project/compiler-rt/test/tsan/libdispatch/barrier-race.c
index c11e147..2788244 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-barrier-race.mm
+++ b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/barrier-race.c
@@ -1,15 +1,16 @@
-// RUN: %clang_tsan %s -o %t -framework Foundation
+// RUN: %clang_tsan %s -o %t
// RUN: %deflake %run %t 2>&1 | FileCheck %s
-#import <Foundation/Foundation.h>
+#include "dispatch/dispatch.h"
-#import "../test.h"
+#include "../test.h"
long global;
int main() {
fprintf(stderr, "Hello world.\n");
print_address("addr=", 1, &global);
+ dispatch_semaphore_t done = dispatch_semaphore_create(0);
barrier_init(&barrier, 2);
dispatch_queue_t q = dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT);
@@ -31,18 +32,16 @@
barrier_wait(&barrier);
global = 44;
- dispatch_sync(dispatch_get_main_queue(), ^{
- CFRunLoopStop(CFRunLoopGetCurrent());
- });
+ dispatch_semaphore_signal(done);
});
});
- CFRunLoopRun();
+ dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);
fprintf(stderr, "Done.\n");
}
// CHECK: Hello world.
// CHECK: addr=[[ADDR:0x[0-9,a-f]+]]
// CHECK: WARNING: ThreadSanitizer: data race
-// CHECK: Location is global 'global' {{(of size 8 )?}}at [[ADDR]] (gcd-barrier-race.mm.tmp+0x{{[0-9,a-f]+}})
+// CHECK: Location is global 'global' {{(of size 8 )?}}at [[ADDR]] (barrier-race.c.tmp+0x{{[0-9,a-f]+}})
// CHECK: Done.
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-barrier.mm b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/barrier.c
similarity index 66%
rename from third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-barrier.mm
rename to third_party/llvm-project/compiler-rt/test/tsan/libdispatch/barrier.c
index 9d4dcb2..7702ee6 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-barrier.mm
+++ b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/barrier.c
@@ -1,15 +1,15 @@
-// RUN: %clang_tsan %s -o %t -framework Foundation
-// RUN: %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
-#import <Foundation/Foundation.h>
+#include "dispatch/dispatch.h"
-#import "../test.h"
+#include "../test.h"
long global;
int main() {
fprintf(stderr, "Hello world.\n");
- print_address("addr=", 1, &global);
+ dispatch_semaphore_t done = dispatch_semaphore_create(0);
barrier_init(&barrier, 2);
dispatch_queue_t q = dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT);
@@ -34,16 +34,13 @@
});
barrier_wait(&barrier);
-
- dispatch_sync(dispatch_get_main_queue(), ^{
- CFRunLoopStop(CFRunLoopGetCurrent());
- });
+
+ dispatch_semaphore_signal(done);
});
- CFRunLoopRun();
+ dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);
fprintf(stderr, "Done.\n");
}
// CHECK: Hello world.
// CHECK: Done.
-// CHECK-NOT: WARNING: ThreadSanitizer
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/blocks.c b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/blocks.c
new file mode 100644
index 0000000..e8f1e28
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/blocks.c
@@ -0,0 +1,35 @@
+// RUN: %clang_tsan %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
+
+#include "dispatch/dispatch.h"
+
+#include <stdio.h>
+#include <assert.h>
+
+int main() {
+ fprintf(stderr, "start\n");
+ dispatch_semaphore_t done = dispatch_semaphore_create(0);
+
+ dispatch_queue_t background_q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
+ dispatch_queue_t serial_q = dispatch_queue_create("my.queue", DISPATCH_QUEUE_SERIAL);
+ assert(background_q != serial_q);
+
+ dispatch_async(background_q, ^{
+ __block long block_var = 0;
+
+ dispatch_sync(serial_q, ^{
+ block_var = 42;
+ });
+
+ fprintf(stderr, "block_var = %ld\n", block_var);
+
+ dispatch_semaphore_signal(done);
+ });
+
+ dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);
+ fprintf(stderr, "done\n");
+}
+
+// CHECK: start
+// CHECK: block_var = 42
+// CHECK: done
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/data.c b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/data.c
new file mode 100644
index 0000000..70c503b
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/data.c
@@ -0,0 +1,38 @@
+// RUN: %clang_tsan %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
+
+#include <dispatch/dispatch.h>
+
+#include <stdio.h>
+#include <string.h>
+
+long global = 42;
+
+int main(int argc, const char *argv[]) {
+ fprintf(stderr, "Hello world.\n");
+
+ dispatch_queue_t q = dispatch_queue_create("my.queue", DISPATCH_QUEUE_SERIAL);
+ dispatch_semaphore_t sem = dispatch_semaphore_create(0);
+
+ const char *buffer = "buffer";
+ size_t size = strlen(buffer);
+
+ dispatch_data_t data = dispatch_data_create(buffer, size, q, ^{
+ fprintf(stderr, "Data destructor.\n");
+ global++;
+
+ dispatch_semaphore_signal(sem);
+ });
+ dispatch_release(data);
+
+ dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
+
+ data = dispatch_data_create(buffer, size, q, DISPATCH_DATA_DESTRUCTOR_DEFAULT);
+ dispatch_release(data);
+
+ fprintf(stderr, "Done.\n");
+}
+
+// CHECK: Hello world.
+// CHECK: Data destructor.
+// CHECK: Done.
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/dispatch_main.mm b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/dispatch_main.c
similarity index 74%
rename from third_party/llvm-project/compiler-rt/test/tsan/Darwin/dispatch_main.mm
rename to third_party/llvm-project/compiler-rt/test/tsan/libdispatch/dispatch_main.c
index f4c1e44..9e4a3ea 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/dispatch_main.mm
+++ b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/dispatch_main.c
@@ -1,10 +1,13 @@
// Check that we don't crash when dispatch_main calls pthread_exit which
// quits the main thread.
-// RUN: %clang_tsan %s -o %t -framework Foundation
-// RUN: %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
-#import <Foundation/Foundation.h>
+#include <dispatch/dispatch.h>
+
+#include <stdio.h>
+#include <stdlib.h>
int main() {
fprintf(stderr,"Hello world");
@@ -33,6 +36,5 @@
}
// CHECK: Hello world
+// CHECK: 123
// CHECK: Done.
-// CHECK-NOT: WARNING: ThreadSanitizer
-// CHECK-NOT: CHECK failed
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/dispatch_once_deadlock.c b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/dispatch_once_deadlock.c
new file mode 100644
index 0000000..70faa60
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/dispatch_once_deadlock.c
@@ -0,0 +1,60 @@
+// Check that dispatch_once() is always intercepted.
+
+// RUN: %clang_tsan %s -o %t
+// RUN: not %env_tsan_opts=ignore_noninstrumented_modules=0 %run %t 2>&1 | FileCheck %s
+
+#include <dispatch/dispatch.h>
+
+#include <pthread.h>
+#include <stdio.h>
+
+#include "../test.h"
+
+long g = 0;
+long h = 0;
+
+__attribute__((disable_sanitizer_instrumentation))
+void f() {
+ static dispatch_once_t onceToken;
+ dispatch_once(&onceToken, ^{
+ g++;
+ });
+ h++;
+}
+
+// Required for dyld macOS 12.0+
+#if (__APPLE__)
+__attribute__((weak))
+#endif
+__attribute__((disable_sanitizer_instrumentation))
+extern void
+__tsan_on_report() {
+ fprintf(stderr, "Report.\n");
+
+ // Without these annotations this test deadlocks for COMPILER_RT_DEBUG=ON
+ // builds. Conceptually, the TSan runtime does not support reentrancy from
+ // runtime callbacks, but the main goal here is just to check that
+ // dispatch_once() is always intercepted.
+ AnnotateIgnoreSyncBegin(__FILE__, __LINE__);
+ f();
+ AnnotateIgnoreSyncEnd(__FILE__, __LINE__);
+}
+
+int main() {
+ fprintf(stderr, "Hello world.\n");
+
+ f();
+
+ pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
+ pthread_mutex_unlock(&mutex); // Unlock of an unlocked mutex
+
+ fprintf(stderr, "g = %ld.\n", g);
+ fprintf(stderr, "h = %ld.\n", h);
+ fprintf(stderr, "Done.\n");
+}
+
+// CHECK: Hello world.
+// CHECK: Report.
+// CHECK: g = 1
+// CHECK: h = 2
+// CHECK: Done.
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-fd.mm b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/fd.c
similarity index 69%
rename from third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-fd.mm
rename to third_party/llvm-project/compiler-rt/test/tsan/libdispatch/fd.c
index 838cf20..107f625 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-fd.mm
+++ b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/fd.c
@@ -1,7 +1,9 @@
-// RUN: %clang_tsan %s -o %t -framework Foundation
-// RUN: %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
-#import <Foundation/Foundation.h>
+#include <dispatch/dispatch.h>
+
+#include <stdio.h>
long my_global = 0;
@@ -11,14 +13,14 @@
dispatch_queue_t queue = dispatch_queue_create("my.queue", DISPATCH_QUEUE_SERIAL);
dispatch_semaphore_t sem = dispatch_semaphore_create(0);
- NSString *path = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"temp-gcd-io.%d", getpid()]];
+ const char *path = tempnam(NULL, "libdispatch-fd-");
- dispatch_io_t channel = dispatch_io_create_with_path(DISPATCH_IO_STREAM, path.fileSystemRepresentation, O_CREAT | O_WRONLY,
+ dispatch_io_t channel = dispatch_io_create_with_path(DISPATCH_IO_STREAM, path, O_CREAT | O_WRONLY,
0666, queue, ^(int error) { });
dispatch_io_set_high_water(channel, 1);
- NSData *ns_data = [NSMutableData dataWithLength:1000];
- dispatch_data_t data = dispatch_data_create(ns_data.bytes, ns_data.length, NULL, DISPATCH_DATA_DESTRUCTOR_DEFAULT);
+ char buf[1000];
+ dispatch_data_t data = dispatch_data_create(buf, sizeof(buf), NULL, DISPATCH_DATA_DESTRUCTOR_DEFAULT);
my_global++;
dispatch_io_write(channel, 0, data, queue, ^(bool done, dispatch_data_t remainingData, int error) {
@@ -34,7 +36,7 @@
dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
my_global++;
dispatch_io_close(channel, 0);
- channel = dispatch_io_create_with_path(DISPATCH_IO_STREAM, path.fileSystemRepresentation, O_RDONLY,
+ channel = dispatch_io_create_with_path(DISPATCH_IO_STREAM, path, O_RDONLY,
0, queue, ^(int error) { });
dispatch_io_set_high_water(channel, 1);
@@ -56,5 +58,4 @@
}
// CHECK: Hello world.
-// CHECK-NOT: WARNING: ThreadSanitizer
// CHECK: Done.
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/groups-destructor.cpp b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/groups-destructor.cpp
new file mode 100644
index 0000000..2ea1f2d
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/groups-destructor.cpp
@@ -0,0 +1,43 @@
+// RUN: %clangxx_tsan %s %link_libcxx_tsan -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
+
+#include <dispatch/dispatch.h>
+
+#include <atomic>
+#include <cstdio>
+#include <memory>
+
+std::atomic<long> destructor_counter(0);
+
+struct MyStruct {
+ virtual ~MyStruct() {
+ usleep(10000);
+ std::atomic_fetch_add_explicit(&destructor_counter, 1, std::memory_order_relaxed);
+ }
+};
+
+int main(int argc, const char *argv[]) {
+ std::fprintf(stderr, "Hello world.\n");
+
+ dispatch_queue_t q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
+ dispatch_group_t g = dispatch_group_create();
+
+ for (int i = 0; i < 100; i++) {
+ std::shared_ptr<MyStruct> shared(new MyStruct());
+
+ dispatch_group_async(g, q, ^{
+ shared.get(); // just to make sure the object is captured by the block
+ });
+ }
+
+ dispatch_group_wait(g, DISPATCH_TIME_FOREVER);
+
+ if (destructor_counter != 100) {
+ std::abort();
+ }
+
+ std::fprintf(stderr, "Done.\n");
+}
+
+// CHECK: Hello world.
+// CHECK: Done.
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-groups-leave.mm b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/groups-leave.c
similarity index 84%
rename from third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-groups-leave.mm
rename to third_party/llvm-project/compiler-rt/test/tsan/libdispatch/groups-leave.c
index 49fd8e2..f63d6e5 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-groups-leave.mm
+++ b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/groups-leave.c
@@ -1,9 +1,9 @@
-// RUN: %clang_tsan %s -o %t -framework Foundation
-// RUN: %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
-#import <Foundation/Foundation.h>
+#include <dispatch/dispatch.h>
-#import "../test.h"
+#include "../test.h"
dispatch_semaphore_t sem;
@@ -52,5 +52,4 @@
}
// CHECK: Hello world.
-// CHECK-NOT: WARNING: ThreadSanitizer
// CHECK: Done.
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-groups-norace.mm b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/groups-norace.c
similarity index 63%
rename from third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-groups-norace.mm
rename to third_party/llvm-project/compiler-rt/test/tsan/libdispatch/groups-norace.c
index e850169..ed6311d 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-groups-norace.mm
+++ b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/groups-norace.c
@@ -1,15 +1,15 @@
-// RUN: %clang_tsan %s -o %t -framework Foundation
-// RUN: %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
-#import <Foundation/Foundation.h>
+#include "dispatch/dispatch.h"
-#import "../test.h"
+#include <stdio.h>
long global;
int main() {
- NSLog(@"Hello world.");
- NSLog(@"addr=%p\n", &global);
+ fprintf(stderr, "Hello world.\n");
+ dispatch_semaphore_t done = dispatch_semaphore_create(0);
dispatch_queue_t q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
global = 42;
@@ -39,15 +39,12 @@
dispatch_group_notify(g, q, ^{
global = 48;
- dispatch_sync(dispatch_get_main_queue(), ^{
- CFRunLoopStop(CFRunLoopGetCurrent());
- });
+ dispatch_semaphore_signal(done);
});
- CFRunLoopRun();
- NSLog(@"Done.");
+ dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);
+ fprintf(stderr, "Done.\n");
}
// CHECK: Hello world.
// CHECK: Done.
-// CHECK-NOT: WARNING: ThreadSanitizer
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-groups-stress.mm b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/groups-stress.c
similarity index 75%
rename from third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-groups-stress.mm
rename to third_party/llvm-project/compiler-rt/test/tsan/libdispatch/groups-stress.c
index cfe4deb..0f24ff7 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-groups-stress.mm
+++ b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/groups-stress.c
@@ -1,17 +1,19 @@
-// RUN: %clang_tsan %s -o %t -framework Foundation
-// RUN: %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
-#import <Foundation/Foundation.h>
+#include <dispatch/dispatch.h>
+
+#include <stdio.h>
void notify_callback(void *context) {
// Do nothing.
}
int main() {
- NSLog(@"Hello world.");
+ fprintf(stderr, "Hello world.");
dispatch_queue_t q = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
-
+
for (int i = 0; i < 300000; i++) {
dispatch_group_t g = dispatch_group_create();
dispatch_group_enter(g);
@@ -34,10 +36,8 @@
dispatch_release(g);
}
- NSLog(@"Done.");
+ fprintf(stderr, "Done.");
}
// CHECK: Hello world.
// CHECK: Done.
-// CHECK-NOT: WARNING: ThreadSanitizer
-// CHECK-NOT: CHECK failed
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-io-barrier-race.mm b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/io-barrier-race.c
similarity index 72%
rename from third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-io-barrier-race.mm
rename to third_party/llvm-project/compiler-rt/test/tsan/libdispatch/io-barrier-race.c
index 137c3b2..5e7fe80 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-io-barrier-race.mm
+++ b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/io-barrier-race.c
@@ -1,7 +1,7 @@
-// RUN: %clang_tsan %s -o %t -framework Foundation
+// RUN: %clang_tsan %s -o %t
// RUN: %deflake %run %t 2>&1 | FileCheck %s
-#import <Foundation/Foundation.h>
+#include <dispatch/dispatch.h>
#import "../test.h"
@@ -19,10 +19,9 @@
queue = dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT);
sem = dispatch_semaphore_create(0);
- NSString *ns_path = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"temp-gcd-io.%d", getpid()]];
- path = ns_path.fileSystemRepresentation;
- NSData *ns_data = [NSMutableData dataWithLength:1000];
- data = dispatch_data_create(ns_data.bytes, ns_data.length, NULL, DISPATCH_DATA_DESTRUCTOR_DEFAULT);
+ path = tempnam(NULL, "libdispatch-io-barrier-race-");
+ char buf[1000];
+ data = dispatch_data_create(buf, sizeof(buf), NULL, DISPATCH_DATA_DESTRUCTOR_DEFAULT);
dispatch_io_t channel = dispatch_io_create_with_path(DISPATCH_IO_STREAM, path, O_CREAT | O_WRONLY, 0666, queue, ^(int error) { });
if (! channel) abort();
@@ -51,5 +50,5 @@
// CHECK: Hello world.
// CHECK: addr=[[ADDR:0x[0-9,a-f]+]]
// CHECK: WARNING: ThreadSanitizer: data race
-// CHECK: Location is global 'my_global' {{(of size 8 )?}}at [[ADDR]] (gcd-io-barrier-race.mm.tmp+0x{{[0-9,a-f]+}})
+// CHECK: Location is global 'my_global' {{(of size 8 )?}}at [[ADDR]] (io-barrier-race.c.tmp+0x{{[0-9,a-f]+}})
// CHECK: Done.
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-io-barrier.mm b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/io-barrier.c
similarity index 63%
rename from third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-io-barrier.mm
rename to third_party/llvm-project/compiler-rt/test/tsan/libdispatch/io-barrier.c
index af92b03..c0d3fb0 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-io-barrier.mm
+++ b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/io-barrier.c
@@ -1,7 +1,10 @@
-// RUN: %clang_tsan %s -o %t -framework Foundation
-// RUN: %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
-#import <Foundation/Foundation.h>
+#include <dispatch/dispatch.h>
+
+#include <stdio.h>
+#include <stdlib.h>
dispatch_queue_t queue;
dispatch_data_t data;
@@ -15,10 +18,9 @@
queue = dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT);
sem = dispatch_semaphore_create(0);
- NSString *ns_path = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"temp-gcd-io.%d", getpid()]];
- path = ns_path.fileSystemRepresentation;
- NSData *ns_data = [NSMutableData dataWithLength:1000];
- data = dispatch_data_create(ns_data.bytes, ns_data.length, NULL, DISPATCH_DATA_DESTRUCTOR_DEFAULT);
+ path = tempnam(NULL, "libdispatch-io-barrier");
+ char buf[1000];
+ data = dispatch_data_create(buf, sizeof(buf), NULL, DISPATCH_DATA_DESTRUCTOR_DEFAULT);
dispatch_io_t channel = dispatch_io_create_with_path(DISPATCH_IO_STREAM, path, O_CREAT | O_WRONLY, 0666, queue, ^(int error) { });
if (! channel) abort();
@@ -44,5 +46,4 @@
}
// CHECK: Hello world.
-// CHECK-NOT: WARNING: ThreadSanitizer
// CHECK: Done.
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-io-cleanup.mm b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/io-cleanup.c
similarity index 80%
rename from third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-io-cleanup.mm
rename to third_party/llvm-project/compiler-rt/test/tsan/libdispatch/io-cleanup.c
index 570e37d..8c0ad8f 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-io-cleanup.mm
+++ b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/io-cleanup.c
@@ -1,7 +1,10 @@
-// RUN: %clang_tsan %s -o %t -framework Foundation
-// RUN: %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
-#import <Foundation/Foundation.h>
+#include <dispatch/dispatch.h>
+
+#include <stdio.h>
+#include <stdlib.h>
long my_global = 0;
@@ -10,8 +13,7 @@
dispatch_queue_t queue = dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT);
dispatch_semaphore_t sem = dispatch_semaphore_create(0);
- NSString *ns_path = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"temp-gcd-io.%d", getpid()]];
- const char *path = ns_path.fileSystemRepresentation;
+ const char *path = tempnam(NULL, "libdispatch-io-cleanup-");
dispatch_io_t channel;
dispatch_fd_t fd = open(path, O_CREAT | O_WRONLY, 0666);
@@ -52,5 +54,4 @@
}
// CHECK: Hello world.
-// CHECK-NOT: WARNING: ThreadSanitizer
// CHECK: Done.
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-io-race.mm b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/io-race.c
similarity index 71%
rename from third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-io-race.mm
rename to third_party/llvm-project/compiler-rt/test/tsan/libdispatch/io-race.c
index 99000fc..d415104 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-io-race.mm
+++ b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/io-race.c
@@ -1,11 +1,9 @@
-// RUN: %clang_tsan %s -o %t -framework Foundation
+// RUN: %clang_tsan %s -o %t
// RUN: %deflake %run %t 2>&1 | FileCheck %s
-// REQUIRES: disabled
+#include <dispatch/dispatch.h>
-#import <Foundation/Foundation.h>
-
-#import "../test.h"
+#include "../test.h"
dispatch_queue_t queue;
dispatch_data_t data;
@@ -21,10 +19,9 @@
queue = dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT);
sem = dispatch_semaphore_create(0);
- NSString *ns_path = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"temp-gcd-io.%d", getpid()]];
- path = ns_path.fileSystemRepresentation;
- NSData *ns_data = [NSMutableData dataWithLength:1000];
- data = dispatch_data_create(ns_data.bytes, ns_data.length, NULL, DISPATCH_DATA_DESTRUCTOR_DEFAULT);
+ path = tempnam(NULL, "libdispatch-io-race");
+ char buf[1000];
+ data = dispatch_data_create(buf, sizeof(buf), NULL, DISPATCH_DATA_DESTRUCTOR_DEFAULT);
dispatch_io_t channel = dispatch_io_create_with_path(DISPATCH_IO_STREAM, path, O_CREAT | O_WRONLY, 0666, queue, ^(int error) { });
if (! channel) abort();
@@ -52,5 +49,5 @@
// CHECK: Hello world.
// CHECK: addr=[[ADDR:0x[0-9,a-f]+]]
// CHECK: WARNING: ThreadSanitizer: data race
-// CHECK: Location is global 'my_global' {{(of size 8 )?}}at [[ADDR]] (gcd-io-race.mm.tmp+0x{{[0-9,a-f]+}})
+// CHECK: Location is global 'my_global' {{(of size 8 )?}}at [[ADDR]] (io-race.c.tmp+0x{{[0-9,a-f]+}})
// CHECK: Done.
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-io.mm b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/io.c
similarity index 83%
rename from third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-io.mm
rename to third_party/llvm-project/compiler-rt/test/tsan/libdispatch/io.c
index 70ded40..eeededd 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-io.mm
+++ b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/io.c
@@ -1,7 +1,10 @@
-// RUN: %clang_tsan %s -o %t -framework Foundation
-// RUN: %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
-#import <Foundation/Foundation.h>
+#include <dispatch/dispatch.h>
+
+#include <stdio.h>
+#include <stdlib.h>
dispatch_queue_t queue;
dispatch_data_t data;
@@ -98,10 +101,9 @@
queue = dispatch_queue_create("my.queue", DISPATCH_QUEUE_SERIAL);
sem = dispatch_semaphore_create(0);
- NSString *ns_path = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"temp-gcd-io.%d", getpid()]];
- path = ns_path.fileSystemRepresentation;
- NSData *ns_data = [NSMutableData dataWithLength:1000];
- data = dispatch_data_create(ns_data.bytes, ns_data.length, NULL, DISPATCH_DATA_DESTRUCTOR_DEFAULT);
+ path = tempnam(NULL, "libdispatch-io-");
+ char buf[1000];
+ data = dispatch_data_create(buf, sizeof(buf), NULL, DISPATCH_DATA_DESTRUCTOR_DEFAULT);
test_dispatch_io_write();
test_dispatch_write();
@@ -113,5 +115,4 @@
}
// CHECK: Hello world.
-// CHECK-NOT: WARNING: ThreadSanitizer
// CHECK: Done.
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/lit.local.cfg.py b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/lit.local.cfg.py
new file mode 100644
index 0000000..9d3cf75
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/lit.local.cfg.py
@@ -0,0 +1,17 @@
+def getRoot(config):
+ if not config.parent:
+ return config
+ return getRoot(config.parent)
+
+root = getRoot(config)
+
+if 'libdispatch' in root.available_features:
+ additional_cflags = ' -fblocks '
+ for index, (template, replacement) in enumerate(config.substitutions):
+ if template in ['%clang_tsan ', '%clangxx_tsan ']:
+ config.substitutions[index] = (template, replacement + additional_cflags)
+else:
+ config.unsupported = True
+
+if config.host_os == 'Darwin':
+ config.environment['TSAN_OPTIONS'] += ':ignore_noninstrumented_modules=1'
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-once.mm b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/once.c
similarity index 80%
rename from third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-once.mm
rename to third_party/llvm-project/compiler-rt/test/tsan/libdispatch/once.c
index 70e588a..d473b34 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-once.mm
+++ b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/once.c
@@ -1,9 +1,9 @@
-// RUN: %clang_tsan %s -o %t -framework Foundation
-// RUN: %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
-#import <Foundation/Foundation.h>
+#include <dispatch/dispatch.h>
-#import "../test.h"
+#include "../test.h"
static const long kNumThreads = 4;
@@ -13,7 +13,7 @@
static dispatch_once_t once_token;
static dispatch_once_t once_token2;
-void f(void *) {
+void f(void *a) {
global2 = 42;
usleep(100000);
}
@@ -52,4 +52,3 @@
// CHECK: Hello world.
// CHECK: Done.
-// CHECK-NOT: WARNING: ThreadSanitizer
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-semaphore-norace.mm b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/semaphore-norace.c
similarity index 62%
rename from third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-semaphore-norace.mm
rename to third_party/llvm-project/compiler-rt/test/tsan/libdispatch/semaphore-norace.c
index fd5d146..36e03dc 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-semaphore-norace.mm
+++ b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/semaphore-norace.c
@@ -1,29 +1,30 @@
-// RUN: %clang_tsan %s -o %t -framework Foundation
-// RUN: %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
-#import <Foundation/Foundation.h>
+#include <dispatch/dispatch.h>
+
+#include <stdio.h>
long global;
int main() {
- NSLog(@"Hello world.");
+ fprintf(stderr, "Hello world.");
global = 42;
-
+
dispatch_semaphore_t sem = dispatch_semaphore_create(0);
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
-
+
global = 43;
dispatch_semaphore_signal(sem);
});
-
+
dispatch_semaphore_wait(sem, DISPATCH_TIME_FOREVER);
global = 44;
- NSLog(@"Done.");
+ fprintf(stderr, "Done.");
return 0;
}
// CHECK: Hello world.
// CHECK: Done.
-// CHECK-NOT: WARNING: ThreadSanitizer
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/serial-queue-norace.c b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/serial-queue-norace.c
new file mode 100644
index 0000000..2b8009d
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/serial-queue-norace.c
@@ -0,0 +1,37 @@
+// RUN: %clang_tsan %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
+
+#include "dispatch/dispatch.h"
+
+#include <stdio.h>
+
+long global;
+
+int main() {
+ fprintf(stderr, "Hello world.\n");
+ dispatch_semaphore_t done = dispatch_semaphore_create(0);
+
+ dispatch_queue_t q1 = dispatch_queue_create("my.queue1", DISPATCH_QUEUE_CONCURRENT);
+ dispatch_queue_t q2 = dispatch_queue_create("my.queue2", DISPATCH_QUEUE_SERIAL);
+
+ global = 42;
+ for (int i = 0; i < 10; i++) {
+ dispatch_async(q1, ^{
+ for (int i = 0; i < 100; i++) {
+ dispatch_sync(q2, ^{
+ global++;
+ });
+ }
+ });
+ }
+
+ dispatch_barrier_async(q1, ^{
+ dispatch_semaphore_signal(done);
+ });
+
+ dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);
+ fprintf(stderr, "Done.\n");
+}
+
+// CHECK: Hello world.
+// CHECK: Done.
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-source-cancel.mm b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/source-cancel.c
similarity index 63%
rename from third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-source-cancel.mm
rename to third_party/llvm-project/compiler-rt/test/tsan/libdispatch/source-cancel.c
index 8aa6f10..a85de95 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-source-cancel.mm
+++ b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/source-cancel.c
@@ -1,11 +1,15 @@
-// RUN: %clang_tsan %s -o %t -framework Foundation
-// RUN: %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
-#import <Foundation/Foundation.h>
+#include "dispatch/dispatch.h"
+
+#include <stdio.h>
long global;
int main(int argc, const char *argv[]) {
+ dispatch_semaphore_t done = dispatch_semaphore_create(0);
+
dispatch_queue_t queue =
dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT);
@@ -19,18 +23,15 @@
dispatch_source_set_cancel_handler(source, ^{
fprintf(stderr, "global = %ld\n", global);
- dispatch_sync(dispatch_get_main_queue(), ^{
- CFRunLoopStop(CFRunLoopGetCurrent());
- });
+ dispatch_semaphore_signal(done);
});
dispatch_resume(source);
dispatch_cancel(source);
- CFRunLoopRun();
+ dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);
return 0;
}
// CHECK: global = 42
-// CHECK-NOT: WARNING: ThreadSanitizer
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-source-cancel2.mm b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/source-cancel2.c
similarity index 64%
rename from third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-source-cancel2.mm
rename to third_party/llvm-project/compiler-rt/test/tsan/libdispatch/source-cancel2.c
index 92b31d7..7531512 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-source-cancel2.mm
+++ b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/source-cancel2.c
@@ -1,19 +1,22 @@
-// RUN: %clang_tsan %s -o %t -framework Foundation
-// RUN: %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
-#import <Foundation/Foundation.h>
+#include "dispatch/dispatch.h"
+
+#include <stdio.h>
long global;
+dispatch_semaphore_t done;
void handler(void *arg) {
fprintf(stderr, "global = %ld\n", global);
- dispatch_sync(dispatch_get_main_queue(), ^{
- CFRunLoopStop(CFRunLoopGetCurrent());
- });
+ dispatch_semaphore_signal(done);
}
int main(int argc, const char *argv[]) {
+ done = dispatch_semaphore_create(0);
+
dispatch_queue_t queue =
dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT);
@@ -29,10 +32,9 @@
dispatch_resume(source);
dispatch_cancel(source);
- CFRunLoopRun();
+ dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);
return 0;
}
// CHECK: global = 42
-// CHECK-NOT: WARNING: ThreadSanitizer
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-source-event.mm b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/source-event.c
similarity index 61%
rename from third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-source-event.mm
rename to third_party/llvm-project/compiler-rt/test/tsan/libdispatch/source-event.c
index e707b65..2a907ae 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-source-event.mm
+++ b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/source-event.c
@@ -1,11 +1,15 @@
-// RUN: %clang_tsan %s -o %t -framework Foundation
-// RUN: %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
-#import <Foundation/Foundation.h>
+#include "dispatch/dispatch.h"
+
+#include <stdio.h>
long global;
int main(int argc, const char *argv[]) {
+ dispatch_semaphore_t done = dispatch_semaphore_create(0);
+
dispatch_queue_t queue =
dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT);
@@ -19,17 +23,14 @@
dispatch_source_set_event_handler(source, ^{
fprintf(stderr, "global = %ld\n", global);
- dispatch_sync(dispatch_get_main_queue(), ^{
- CFRunLoopStop(CFRunLoopGetCurrent());
- });
+ dispatch_semaphore_signal(done);
});
dispatch_resume(source);
- CFRunLoopRun();
+ dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);
return 0;
}
// CHECK: global = 42
-// CHECK-NOT: WARNING: ThreadSanitizer
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-source-event2.mm b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/source-event2.c
similarity index 62%
rename from third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-source-event2.mm
rename to third_party/llvm-project/compiler-rt/test/tsan/libdispatch/source-event2.c
index b10e474..1afad95 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-source-event2.mm
+++ b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/source-event2.c
@@ -1,19 +1,22 @@
-// RUN: %clang_tsan %s -o %t -framework Foundation
-// RUN: %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
-#import <Foundation/Foundation.h>
+#include "dispatch/dispatch.h"
+
+#include <stdio.h>
long global;
+dispatch_semaphore_t done;
void handler(void *arg) {
fprintf(stderr, "global = %ld\n", global);
- dispatch_sync(dispatch_get_main_queue(), ^{
- CFRunLoopStop(CFRunLoopGetCurrent());
- });
+ dispatch_semaphore_signal(done);
}
int main(int argc, const char *argv[]) {
+ done = dispatch_semaphore_create(0);
+
dispatch_queue_t queue =
dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT);
@@ -28,10 +31,9 @@
dispatch_resume(source);
- CFRunLoopRun();
+ dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);
return 0;
}
// CHECK: global = 42
-// CHECK-NOT: WARNING: ThreadSanitizer
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/source-registration.c b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/source-registration.c
new file mode 100644
index 0000000..f21103e
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/source-registration.c
@@ -0,0 +1,34 @@
+// RUN: %clang_tsan %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
+
+#include "dispatch/dispatch.h"
+
+#include <stdio.h>
+
+long global;
+
+int main(int argc, const char *argv[]) {
+ dispatch_semaphore_t done = dispatch_semaphore_create(0);
+
+ dispatch_queue_t queue =
+ dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT);
+
+ dispatch_source_t source =
+ dispatch_source_create(DISPATCH_SOURCE_TYPE_SIGNAL, SIGHUP, 0, queue);
+
+ global = 42;
+
+ dispatch_source_set_registration_handler(source, ^{
+ fprintf(stderr, "global = %ld\n", global);
+
+ dispatch_semaphore_signal(done);
+ });
+
+ dispatch_resume(source);
+
+ dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);
+
+ return 0;
+}
+
+// CHECK: global = 42
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-source-registration2.mm b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/source-registration2.c
similarity index 60%
rename from third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-source-registration2.mm
rename to third_party/llvm-project/compiler-rt/test/tsan/libdispatch/source-registration2.c
index 6365787..2bfd0b5 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-source-registration2.mm
+++ b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/source-registration2.c
@@ -1,19 +1,22 @@
-// RUN: %clang_tsan %s -o %t -framework Foundation
-// RUN: %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
-#import <Foundation/Foundation.h>
+#include "dispatch/dispatch.h"
+
+#include <stdio.h>
long global;
+dispatch_semaphore_t done;
void handler(void *arg) {
fprintf(stderr, "global = %ld\n", global);
- dispatch_sync(dispatch_get_main_queue(), ^{
- CFRunLoopStop(CFRunLoopGetCurrent());
- });
+ dispatch_semaphore_signal(done);
}
int main(int argc, const char *argv[]) {
+ done = dispatch_semaphore_create(0);
+
dispatch_queue_t queue =
dispatch_queue_create("my.queue", DISPATCH_QUEUE_CONCURRENT);
@@ -26,10 +29,9 @@
dispatch_resume(source);
- CFRunLoopRun();
+ dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);
return 0;
}
// CHECK: global = 42
-// CHECK-NOT: WARNING: ThreadSanitizer
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-source-serial.mm b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/source-serial.c
similarity index 77%
rename from third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-source-serial.mm
rename to third_party/llvm-project/compiler-rt/test/tsan/libdispatch/source-serial.c
index 9922030..3f22c44 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-source-serial.mm
+++ b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/source-serial.c
@@ -1,7 +1,9 @@
-// RUN: %clang_tsan %s -o %t -framework Foundation
-// RUN: %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
-#import <Foundation/Foundation.h>
+#include <dispatch/dispatch.h>
+
+#include <stdio.h>
long global;
@@ -9,16 +11,18 @@
fprintf(stderr, "Hello world.\n");
dispatch_queue_t q = dispatch_queue_create("my.queue", DISPATCH_QUEUE_SERIAL);
- dispatch_semaphore_t sem = dispatch_semaphore_create(0);
dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, q);
long long interval_ms = 10;
dispatch_source_set_timer(timer, dispatch_time(DISPATCH_TIME_NOW, 0), interval_ms * NSEC_PER_MSEC, 0);
+
+ dispatch_semaphore_t sem = dispatch_semaphore_create(0);
dispatch_source_set_event_handler(timer, ^{
fprintf(stderr, "timer\n");
global++;
if (global > 50) {
dispatch_semaphore_signal(sem);
+ dispatch_suspend(timer);
}
});
dispatch_resume(timer);
@@ -29,5 +33,6 @@
}
// CHECK: Hello world.
-// CHECK-NOT: WARNING: ThreadSanitizer
+// CHECK: timer
// CHECK: Done.
+// CHECK-NOT: timer
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-suspend.mm b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/suspend.c
similarity index 83%
rename from third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-suspend.mm
rename to third_party/llvm-project/compiler-rt/test/tsan/libdispatch/suspend.c
index 561e7c0..617ad91 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-suspend.mm
+++ b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/suspend.c
@@ -1,7 +1,9 @@
-// RUN: %clang_tsan %s -o %t -framework Foundation
-// RUN: %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
-#import <Foundation/Foundation.h>
+#include <dispatch/dispatch.h>
+
+#include <stdio.h>
long my_global = 0;
@@ -41,5 +43,4 @@
}
// CHECK: Hello world.
-// CHECK-NOT: WARNING: ThreadSanitizer
// CHECK: Done.
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/sync-block-copy.cpp b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/sync-block-copy.cpp
new file mode 100644
index 0000000..1f10d95
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/sync-block-copy.cpp
@@ -0,0 +1,45 @@
+// This test verifies that dispatch_sync() doesn't actually copy the block under TSan (without TSan, it doesn't).
+
+// RUN: %clangxx_tsan %s -o %t_no_tsan -fno-sanitize=thread
+// RUN: %clangxx_tsan %s -o %t_with_tsan
+
+// RUN: %run %t_no_tsan 2>&1 | FileCheck %s
+// RUN: %run %t_with_tsan 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
+
+#include <dispatch/dispatch.h>
+
+#include <stdio.h>
+
+struct MyClass {
+ static int copyCount;
+ static void printCopyCount() {
+ fprintf(stderr, "copyCount = %d\n", copyCount);
+ }
+ MyClass(){};
+ MyClass(const MyClass &obj) { copyCount++; };
+ void foo() const {
+ fprintf(stderr, "MyClass::foo\n");
+ }
+};
+int MyClass::copyCount = 0;
+
+int main(int argc, const char* argv[]) {
+ dispatch_queue_t q = dispatch_queue_create("my.queue", NULL);
+ MyClass obj;
+ MyClass::printCopyCount();
+ void (^block)(void) = ^{
+ obj.foo();
+ };
+ MyClass::printCopyCount();
+ dispatch_sync(q, block);
+ MyClass::printCopyCount();
+
+ fprintf(stderr, "Done.\n");
+ return 0;
+}
+
+// CHECK: copyCount = 0
+// CHECK: copyCount = 1
+// CHECK: MyClass::foo
+// CHECK: copyCount = 1
+// CHECK: Done.
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/sync-norace.c b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/sync-norace.c
new file mode 100644
index 0000000..c707dd6
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/sync-norace.c
@@ -0,0 +1,36 @@
+// RUN: %clang_tsan %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
+
+#include "dispatch/dispatch.h"
+
+#include <stdio.h>
+
+long global;
+
+static const long nIter = 1000;
+
+int main() {
+ fprintf(stderr, "Hello world.\n");
+ dispatch_semaphore_t done = dispatch_semaphore_create(0);
+
+ dispatch_queue_t serial_q = dispatch_queue_create("my.queue", DISPATCH_QUEUE_SERIAL);
+
+ global = 42;
+ for (int i = 0; i < nIter; i++) {
+ dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
+ dispatch_sync(serial_q, ^{
+ global = i;
+
+ if (i == nIter - 1) {
+ dispatch_semaphore_signal(done);
+ }
+ });
+ });
+ }
+
+ dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);
+ fprintf(stderr, "Done.\n");
+}
+
+// CHECK: Hello world.
+// CHECK: Done.
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-sync-race.mm b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/sync-race.c
similarity index 71%
rename from third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-sync-race.mm
rename to third_party/llvm-project/compiler-rt/test/tsan/libdispatch/sync-race.c
index b7f3266..ec0d43c 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/Darwin/gcd-sync-race.mm
+++ b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/sync-race.c
@@ -1,15 +1,15 @@
-// RUN: %clang_tsan %s -o %t -framework Foundation
+// RUN: %clang_tsan %s -o %t
// RUN: %deflake %run %t 2>&1 | FileCheck %s
-#import <Foundation/Foundation.h>
-
-#import "../test.h"
+#include "dispatch/dispatch.h"
+#include "../test.h"
long global;
int main() {
- NSLog(@"Hello world.");
+ fprintf(stderr, "Hello world.\n");
print_address("addr=", 1, &global);
+ dispatch_semaphore_t done = dispatch_semaphore_create(0);
barrier_init(&barrier, 2);
dispatch_queue_t q1 = dispatch_queue_create("my.queue1", DISPATCH_QUEUE_CONCURRENT);
@@ -27,18 +27,16 @@
barrier_wait(&barrier);
global = 44;
- dispatch_sync(dispatch_get_main_queue(), ^{
- CFRunLoopStop(CFRunLoopGetCurrent());
- });
+ dispatch_semaphore_signal(done);
});
});
- CFRunLoopRun();
- NSLog(@"Done.");
+ dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);
+ fprintf(stderr, "Done.\n");
}
// CHECK: Hello world.
// CHECK: addr=[[ADDR:0x[0-9,a-f]+]]
// CHECK: WARNING: ThreadSanitizer: data race
-// CHECK: Location is global 'global' {{(of size 8 )?}}at [[ADDR]] (gcd-sync-race.mm.tmp+0x{{[0-9,a-f]+}})
+// CHECK: Location is global 'global' {{(of size 8 )?}}at [[ADDR]] (sync-race.c.tmp+0x{{[0-9,a-f]+}})
// CHECK: Done.
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/target-queue-norace.c b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/target-queue-norace.c
new file mode 100644
index 0000000..893e0c4
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/libdispatch/target-queue-norace.c
@@ -0,0 +1,40 @@
+// RUN: %clang_tsan %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s --implicit-check-not='ThreadSanitizer'
+
+#include "dispatch/dispatch.h"
+
+#include <stdio.h>
+
+long global;
+
+int main(int argc, const char *argv[]) {
+ dispatch_semaphore_t done = dispatch_semaphore_create(0);
+ dispatch_queue_t target_queue = dispatch_queue_create(NULL, DISPATCH_QUEUE_SERIAL);
+ dispatch_queue_t q1 = dispatch_queue_create(NULL, DISPATCH_QUEUE_CONCURRENT);
+ dispatch_queue_t q2 = dispatch_queue_create(NULL, DISPATCH_QUEUE_CONCURRENT);
+ dispatch_set_target_queue(q1, target_queue);
+ dispatch_set_target_queue(q2, target_queue);
+
+ for (int i = 0; i < 100000; i++) {
+ dispatch_async(q1, ^{
+ global++;
+
+ if (global == 200000) {
+ dispatch_semaphore_signal(done);
+ }
+ });
+ dispatch_async(q2, ^{
+ global++;
+
+ if (global == 200000) {
+ dispatch_semaphore_signal(done);
+ }
+ });
+ }
+
+ dispatch_semaphore_wait(done, DISPATCH_TIME_FOREVER);
+ fprintf(stderr, "Done.\n");
+ return 0;
+}
+
+// CHECK: Done.
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/lit.cfg b/third_party/llvm-project/compiler-rt/test/tsan/lit.cfg.py
similarity index 81%
rename from third_party/llvm-project/compiler-rt/test/tsan/lit.cfg
rename to third_party/llvm-project/compiler-rt/test/tsan/lit.cfg.py
index 233d273..4295514 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/lit.cfg
+++ b/third_party/llvm-project/compiler-rt/test/tsan/lit.cfg.py
@@ -8,7 +8,7 @@
lit_config.fatal(
"No attribute %r in test configuration! You may need to run "
"tests from your build directory or add this attribute "
- "to lit.site.cfg " % attr_name)
+ "to lit.site.cfg.py " % attr_name)
return attr_value
# Setup config name.
@@ -26,8 +26,9 @@
default_tsan_opts += ':abort_on_error=0'
# On Darwin, we default to ignore_noninstrumented_modules=1, which also
# suppresses some races the tests are supposed to find. Let's run without this
- # setting, but turn it back on for Darwin tests (see Darwin/lit.local.cfg).
+ # setting, but turn it back on for Darwin tests (see Darwin/lit.local.cfg.py).
default_tsan_opts += ':ignore_noninstrumented_modules=0'
+ default_tsan_opts += ':ignore_interceptors_accesses=0'
# Platform-specific default TSAN_OPTIONS for lit tests.
if default_tsan_opts:
@@ -38,7 +39,7 @@
# GCC driver doesn't add necessary compile/link flags with -fsanitize=thread.
if config.compiler_id == 'GNU':
- extra_cflags = ["-fPIE", "-pthread", "-ldl", "-lstdc++", "-lrt", "-pie"]
+ extra_cflags = ["-fPIE", "-pthread", "-ldl", "-lrt", "-pie"]
else:
extra_cflags = []
@@ -59,11 +60,12 @@
"tsan", "libcxx_tsan_%s" % config.target_arch)
libcxx_incdir = os.path.join(libcxx_path, "include", "c++", "v1")
libcxx_libdir = os.path.join(libcxx_path, "lib")
- libcxx_so = os.path.join(libcxx_libdir, "libc++.so")
+ libcxx_a = os.path.join(libcxx_libdir, "libc++.a")
clang_tsan_cxxflags += ["-nostdinc++",
- "-I%s" % libcxx_incdir,
- libcxx_so,
- "-Wl,-rpath=%s" % libcxx_libdir]
+ "-I%s" % libcxx_incdir]
+ config.substitutions.append( ("%link_libcxx_tsan", libcxx_a) )
+else:
+ config.substitutions.append( ("%link_libcxx_tsan", "") )
def build_invocation(compile_flags):
return " " + " ".join([config.clang] + compile_flags) + " "
@@ -74,10 +76,10 @@
# Define CHECK-%os to check for OS-dependent output.
config.substitutions.append( ('CHECK-%os', ("CHECK-" + config.host_os)))
-config.substitutions.append( ("%deflake ", os.path.join(os.path.dirname(__file__), "deflake.bash") + " "))
+config.substitutions.append( ("%deflake ", os.path.join(os.path.dirname(__file__), "deflake.bash") + " " + config.deflake_threshold + " "))
# Default test suffixes.
-config.suffixes = ['.c', '.cc', '.cpp', '.m', '.mm']
+config.suffixes = ['.c', '.cpp', '.m', '.mm']
if config.host_os not in ['FreeBSD', 'Linux', 'Darwin', 'NetBSD']:
config.unsupported = True
@@ -85,8 +87,8 @@
if config.android:
config.unsupported = True
-if config.host_os == 'Darwin':
- if config.target_arch in ["x86_64", "x86_64h"]:
- config.parallelism_group = "darwin-64bit-sanitizer"
- elif config.apple_platform != "osx" and not config.apple_platform.endswith("sim"):
- config.parallelism_group = "darwin-ios-device-sanitizer"
+if not config.parallelism_group:
+ config.parallelism_group = 'shadow-memory'
+
+if config.host_os == 'NetBSD':
+ config.substitutions.insert(0, ('%run', config.netbsd_noaslr_prefix))
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/lit.site.cfg.in b/third_party/llvm-project/compiler-rt/test/tsan/lit.site.cfg.py.in
similarity index 78%
rename from third_party/llvm-project/compiler-rt/test/tsan/lit.site.cfg.in
rename to third_party/llvm-project/compiler-rt/test/tsan/lit.site.cfg.py.in
index 6dec5f9..c6d453a 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/lit.site.cfg.in
+++ b/third_party/llvm-project/compiler-rt/test/tsan/lit.site.cfg.py.in
@@ -4,11 +4,13 @@
config.tsan_lit_source_dir = "@TSAN_LIT_SOURCE_DIR@"
config.has_libcxx = @TSAN_HAS_LIBCXX@
config.apple_platform = "@TSAN_TEST_APPLE_PLATFORM@"
+config.apple_platform_min_deployment_target_flag = "@TSAN_TEST_MIN_DEPLOYMENT_TARGET_FLAG@"
config.target_cflags = "@TSAN_TEST_TARGET_CFLAGS@"
config.target_arch = "@TSAN_TEST_TARGET_ARCH@"
+config.deflake_threshold = "@TSAN_TEST_DEFLAKE_THRESHOLD@"
# Load common config for all compiler-rt lit tests.
lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured")
# Load tool-specific config that would do the real work.
-lit_config.load_config(config, "@CMAKE_CURRENT_SOURCE_DIR@/lit.cfg")
+lit_config.load_config(config, "@CMAKE_CURRENT_SOURCE_DIR@/lit.cfg.py")
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/load_shared_lib.cc b/third_party/llvm-project/compiler-rt/test/tsan/load_shared_lib.cpp
similarity index 93%
rename from third_party/llvm-project/compiler-rt/test/tsan/load_shared_lib.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/load_shared_lib.cpp
index f022808..a8939be 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/load_shared_lib.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/load_shared_lib.cpp
@@ -3,7 +3,7 @@
// symbolized correctly.
// RUN: %clangxx_tsan -O1 %s -DBUILD_SO -fPIC -shared -o %t-so.so
-// RUN: %clangxx_tsan -O1 %s -o %t -rdynamic && %deflake %run %t | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s %link_libcxx_tsan -o %t -rdynamic && %deflake %run %t | FileCheck %s
#ifdef BUILD_SO
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/longjmp.cc b/third_party/llvm-project/compiler-rt/test/tsan/longjmp.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/longjmp.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/longjmp.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/longjmp2.cc b/third_party/llvm-project/compiler-rt/test/tsan/longjmp2.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/longjmp2.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/longjmp2.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/longjmp3.cc b/third_party/llvm-project/compiler-rt/test/tsan/longjmp3.cpp
similarity index 89%
rename from third_party/llvm-project/compiler-rt/test/tsan/longjmp3.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/longjmp3.cpp
index 842cf26..db92ec7 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/longjmp3.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/longjmp3.cpp
@@ -17,14 +17,14 @@
x++;
}
-void badguy() {
+__attribute__((noinline)) void badguy() {
pthread_mutex_t mtx;
pthread_mutex_init(&mtx, 0);
pthread_mutex_lock(&mtx);
pthread_mutex_destroy(&mtx);
}
-void mymain() {
+__attribute__((noinline)) void mymain() {
jmp_buf env;
if (setjmp(env) == 42) {
badguy();
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/longjmp4.cc b/third_party/llvm-project/compiler-rt/test/tsan/longjmp4.cpp
similarity index 90%
rename from third_party/llvm-project/compiler-rt/test/tsan/longjmp4.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/longjmp4.cpp
index 4c2fbf0..fd31c9c 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/longjmp4.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/longjmp4.cpp
@@ -20,14 +20,14 @@
x++;
}
-void badguy() {
+__attribute__((noinline)) void badguy() {
pthread_mutex_t mtx;
pthread_mutex_init(&mtx, 0);
pthread_mutex_lock(&mtx);
pthread_mutex_destroy(&mtx);
}
-void mymain() {
+__attribute__((noinline)) void mymain() {
jmp_buf env;
if (setjmp(env) == 42) {
badguy();
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/lots_of_threads.c b/third_party/llvm-project/compiler-rt/test/tsan/lots_of_threads.c
index eef9b1c..172a8c0 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/lots_of_threads.c
+++ b/third_party/llvm-project/compiler-rt/test/tsan/lots_of_threads.c
@@ -10,18 +10,26 @@
}
int main() {
- const int kThreads = 10;
+ const int kThreads = 300;
+ const int kIters = 10;
barrier_init(&barrier, kThreads + 1);
- pthread_t t[kThreads];
pthread_attr_t attr;
pthread_attr_init(&attr);
pthread_attr_setstacksize(&attr, 16 << 20);
- pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
- for (int i = 0; i < kThreads; i++)
- pthread_create(&t[i], &attr, thr, 0);
+ for (int iter = 0; iter < kIters; iter++) {
+ pthread_t threads[kThreads];
+ for (int t = 0; t < kThreads; t++) {
+ int err = pthread_create(&threads[t], &attr, thr, 0);
+ if (err) {
+ fprintf(stderr, "Failed to create thread #%d\n", t);
+ return 1;
+ }
+ }
+ barrier_wait(&barrier);
+ for (int t = 0; t < kThreads; t++)
+ pthread_join(threads[t], 0);
+ }
pthread_attr_destroy(&attr);
- barrier_wait(&barrier);
- sleep(1);
fprintf(stderr, "DONE\n");
return 0;
}
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/malloc_overflow.cc b/third_party/llvm-project/compiler-rt/test/tsan/malloc_overflow.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/malloc_overflow.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/malloc_overflow.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/malloc_stack.cc b/third_party/llvm-project/compiler-rt/test/tsan/malloc_stack.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/malloc_stack.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/malloc_stack.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/map32bit.cc b/third_party/llvm-project/compiler-rt/test/tsan/map32bit.cpp
similarity index 83%
rename from third_party/llvm-project/compiler-rt/test/tsan/map32bit.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/map32bit.cpp
index 8aef27b..e8bac22 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/map32bit.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/map32bit.cpp
@@ -8,12 +8,14 @@
// https://github.com/google/sanitizers/issues/412
// MAP_32BIT flag for mmap is supported only for x86_64.
-// XFAIL: mips
-// XFAIL: aarch64
-// XFAIL: powerpc64
+// XFAIL: target=mips{{.*}}
+// XFAIL: target=aarch64{{.*}}
+// XFAIL: target=powerpc64{{.*}}
+// XFAIL: target=s390x{{.*}}
+// XFAIL: target=loongarch64{{.*}}
// MAP_32BIT doesn't exist on OS X and NetBSD.
-// UNSUPPORTED: darwin,netbsd
+// UNSUPPORTED: darwin,target={{.*netbsd.*}}
void *Thread(void *ptr) {
*(int*)ptr = 42;
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/memcmp_race.cc b/third_party/llvm-project/compiler-rt/test/tsan/memcmp_race.cpp
similarity index 82%
rename from third_party/llvm-project/compiler-rt/test/tsan/memcmp_race.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/memcmp_race.cpp
index b76f427..4c9ee4a 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/memcmp_race.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/memcmp_race.cpp
@@ -34,9 +34,9 @@
// CHECK: addr=[[ADDR:0x[0-9,a-f]+]]
// CHECK: WARNING: ThreadSanitizer: data race
-// CHECK: Write of size 1 at [[ADDR]] by thread T2:
-// CHECK: #0 {{(memcpy|memmove)}}
-// CHECK: #1 Thread2
+// CHECK: Write of size 3 at [[ADDR]] by thread T2:
+// CHECK: #0 {{.*mem(cpy|move)}}
+// CHECK: #{{[12]}} Thread2
// CHECK: Previous read of size 1 at [[ADDR]] by thread T1:
-// CHECK: #0 memcmp
-// CHECK: #1 Thread1
+// CHECK: #0 {{.*}}memcmp
+// CHECK: #{{[12]}} Thread1
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/memcpy_race.cc b/third_party/llvm-project/compiler-rt/test/tsan/memcpy_race.cpp
similarity index 63%
rename from third_party/llvm-project/compiler-rt/test/tsan/memcpy_race.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/memcpy_race.cpp
index 4a098c0..aed047a 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/memcpy_race.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/memcpy_race.cpp
@@ -22,7 +22,8 @@
int main() {
barrier_init(&barrier, 2);
- print_address("addr=", 1, &data[5]);
+ print_address("addr1=", 1, &data[3]);
+ print_address("addr2=", 1, &data[5]);
pthread_t t[2];
pthread_create(&t[0], NULL, Thread1, NULL);
pthread_create(&t[1], NULL, Thread2, NULL);
@@ -31,11 +32,12 @@
return 0;
}
-// CHECK: addr=[[ADDR:0x[0-9,a-f]+]]
+// CHECK: addr1=[[ADDR1:0x[0-9,a-f]+]]
+// CHECK: addr2=[[ADDR2:0x[0-9,a-f]+]]
// CHECK: WARNING: ThreadSanitizer: data race
-// CHECK: Write of size 1 at [[ADDR]] by thread T2:
-// CHECK: #0 {{(memcpy|memmove)}}
-// CHECK: #1 Thread2
-// CHECK: Previous write of size 1 at [[ADDR]] by thread T1:
-// CHECK: #0 {{(memcpy|memmove)}}
-// CHECK: #1 Thread1
+// CHECK: Write of size 4 at [[ADDR1]] by thread T2:
+// CHECK: #0 {{.*mem(cpy|move)}}
+// CHECK: #{{[12]}} Thread2
+// CHECK: Previous write of size 1 at [[ADDR2]] by thread T1:
+// CHECK: #0 {{.*mem(cpy|move)}}
+// CHECK: #{{[12]}} Thread1
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/mmap_large.cc b/third_party/llvm-project/compiler-rt/test/tsan/mmap_large.cpp
similarity index 83%
rename from third_party/llvm-project/compiler-rt/test/tsan/mmap_large.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/mmap_large.cpp
index 764e954..85ebe7f 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/mmap_large.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/mmap_large.cpp
@@ -1,4 +1,7 @@
// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
+
+// UNSUPPORTED: ios
+
#include <stdint.h>
#include <stdio.h>
#include <errno.h>
@@ -14,10 +17,12 @@
int main() {
#ifdef __x86_64__
const size_t kLog2Size = 39;
-#elif defined(__mips64) || defined(__aarch64__)
+#elif defined(__mips64) || defined(__aarch64__) || defined(__loongarch_lp64)
const size_t kLog2Size = 32;
#elif defined(__powerpc64__)
const size_t kLog2Size = 39;
+#elif defined(__s390x__)
+ const size_t kLog2Size = 43;
#endif
const uintptr_t kLocation = 0x40ULL << kLog2Size;
void *p = mmap(
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/mmap_lots.cpp b/third_party/llvm-project/compiler-rt/test/tsan/mmap_lots.cpp
new file mode 100644
index 0000000..a397de0
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/mmap_lots.cpp
@@ -0,0 +1,35 @@
+// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
+
+// Test that mmap does not return unexpected addresses
+// (the check is in the interceptor).
+
+#include <fcntl.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+int main() {
+ int fd = open("/dev/zero", O_RDWR);
+ if (fd == -1) perror("open(/dev/zero)"), exit(1);
+ for (size_t mmap_size = 64ull << 30; mmap_size >= 4 << 10; mmap_size /= 2) {
+ size_t allocated = 0;
+ while (mmap(0, mmap_size, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE,
+ fd, 0) != MAP_FAILED) {
+ allocated += mmap_size;
+ }
+ fprintf(stderr, "allocated %zu with size %zu\n", allocated, mmap_size);
+ }
+ fprintf(stderr, "DONE\n");
+ // If tsan runtime will try to allocate something during exit handling,
+ // the allocation will fail because there is no VA whatsoever.
+ // It's observed to fail with the following error in some cases:
+ // failed to allocate 0x1000 (4096) bytes of DTLS_NextBlock.
+ // So terminate the process immediately.
+ _exit(0);
+}
+
+// CHECK: DONE
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/mmap_stress.cc b/third_party/llvm-project/compiler-rt/test/tsan/mmap_stress.cpp
similarity index 84%
rename from third_party/llvm-project/compiler-rt/test/tsan/mmap_stress.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/mmap_stress.cpp
index f272779..c6fd8f0 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/mmap_stress.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/mmap_stress.cpp
@@ -1,4 +1,9 @@
// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
+// This test is flaky on several builders:
+// https://groups.google.com/d/msg/llvm-dev/KUFPdLhBN3Q/L75rwW9xBgAJ
+// The cause is unknown (lit hides test output on failures).
+// Let's try to re-enable it at least in one configutaion.
+// REQUIRES: linux, x86_64-target-arch
#include "test.h"
#include <errno.h>
#include <sys/mman.h>
@@ -47,10 +52,6 @@
}
int main() {
- // This test is flaky on several builders:
- // https://groups.google.com/d/msg/llvm-dev/KUFPdLhBN3Q/L75rwW9xBgAJ
- // The cause is unknown (lit hides test output on failures).
-#if 0
pthread_t th[4];
for (int i = 0; i < 4; i++) {
if (pthread_create(&th[i], 0, Worker, 0))
@@ -60,7 +61,6 @@
if (pthread_join(th[i], 0))
exit(printf("pthread_join failed: %d\n", errno));
}
-#endif
fprintf(stderr, "DONE\n");
}
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/mmap_stress2.cpp b/third_party/llvm-project/compiler-rt/test/tsan/mmap_stress2.cpp
new file mode 100644
index 0000000..23ff831
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/mmap_stress2.cpp
@@ -0,0 +1,51 @@
+// RUN: %clang_tsan -O1 %s -o %t && %env_tsan_opts=report_atomic_races=0 %run %t 2>&1 | FileCheck %s
+// This test exposed non-atomicity in mmap interceptor
+// which made shadow for the region temporarily unmapped.
+// This resulted in crashes in the Accesser thread.
+#include "test.h"
+#include <errno.h>
+#include <sys/mman.h>
+
+// The size needs to be large enough to trigger
+// large region optimization in the runtime.
+const size_t kMmapSize = 16 << 20;
+
+void *Remapper(void *arg) {
+ for (;;) {
+ void *p = mmap(arg, kMmapSize, PROT_READ | PROT_WRITE,
+ MAP_FIXED | MAP_PRIVATE | MAP_ANON, -1, 0);
+ if (p == MAP_FAILED)
+ exit(printf("mmap failed: %d\n", errno));
+ }
+ return 0;
+}
+
+void *Accesser(void *arg) {
+ unsigned rnd = time(0);
+ for (;;) {
+ int index = rand_r(&rnd) % kMmapSize;
+ char *p = &((char *)arg)[index];
+ __atomic_fetch_add(p, 1, __ATOMIC_ACQ_REL);
+ }
+ return 0;
+}
+
+int main() {
+ void *p = mmap(0, kMmapSize, PROT_READ | PROT_WRITE,
+ MAP_PRIVATE | MAP_ANON, -1, 0);
+ if (p == MAP_FAILED)
+ exit(printf("mmap failed: %d\n", errno));
+ pthread_attr_t attr;
+ pthread_attr_init(&attr);
+ pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
+ pthread_t th[2];
+ if (pthread_create(&th[0], &attr, Remapper, p))
+ exit(printf("pthread_create failed: %d\n", errno));
+ if (pthread_create(&th[1], &attr, Accesser, p))
+ exit(printf("pthread_create failed: %d\n", errno));
+ pthread_attr_destroy(&attr);
+ sleep(3);
+ fprintf(stderr, "DONE\n");
+}
+
+// CHECK: DONE
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/mop_with_offset.cc b/third_party/llvm-project/compiler-rt/test/tsan/mop_with_offset.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/mop_with_offset.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/mop_with_offset.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/mop_with_offset2.cc b/third_party/llvm-project/compiler-rt/test/tsan/mop_with_offset2.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/mop_with_offset2.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/mop_with_offset2.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/munmap_invalid.cpp b/third_party/llvm-project/compiler-rt/test/tsan/munmap_invalid.cpp
new file mode 100644
index 0000000..07dc5bd
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/munmap_invalid.cpp
@@ -0,0 +1,29 @@
+// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
+
+// Fails on Darwin bots:
+// https://green.lab.llvm.org/green//job/clang-stage1-RA/25954/consoleFull
+// and on clang-s390x-linux-lnt:
+// https://lab.llvm.org/buildbot#builders/45/builds/5224
+// Presumably the test is not 100% legal and kernel is allowed
+// to unmap part of the range (e.g. .text) and then fail.
+// So let's be conservative:
+// REQUIRES: linux, x86_64-target-arch
+
+#include "test.h"
+#include <sys/mman.h>
+
+int main() {
+ // These bogus munmap's must not crash tsan runtime.
+ munmap(0, 1);
+ munmap(0, -1);
+ munmap((void *)main, -1);
+ void *p =
+ mmap(0, 4096, PROT_READ | PROT_WRITE, MAP_ANON | MAP_PRIVATE, -1, 0);
+ munmap(p, (1ull << 60));
+ munmap(p, -10000);
+ munmap(p, 0);
+ fprintf(stderr, "DONE\n");
+ return 0;
+}
+
+// CHECK: DONE
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/must_deadlock.cc b/third_party/llvm-project/compiler-rt/test/tsan/must_deadlock.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/must_deadlock.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/must_deadlock.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/mutex_annotations.cc b/third_party/llvm-project/compiler-rt/test/tsan/mutex_annotations.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/mutex_annotations.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/mutex_annotations.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/mutex_bad_read_lock.cc b/third_party/llvm-project/compiler-rt/test/tsan/mutex_bad_read_lock.cpp
similarity index 87%
rename from third_party/llvm-project/compiler-rt/test/tsan/mutex_bad_read_lock.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/mutex_bad_read_lock.cpp
index 84a2976..8f1fe77 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/mutex_bad_read_lock.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/mutex_bad_read_lock.cpp
@@ -1,5 +1,5 @@
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
-extern "C" void AnnotateRWLockAcquired(const char *f, int l, void *m, long rw);
+#include "test.h"
int main() {
int m = 0;
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/mutex_bad_read_unlock.cc b/third_party/llvm-project/compiler-rt/test/tsan/mutex_bad_read_unlock.cpp
similarity index 77%
rename from third_party/llvm-project/compiler-rt/test/tsan/mutex_bad_read_unlock.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/mutex_bad_read_unlock.cpp
index dcee515..6a88261 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/mutex_bad_read_unlock.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/mutex_bad_read_unlock.cpp
@@ -1,6 +1,5 @@
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
-extern "C" void AnnotateRWLockAcquired(const char *f, int l, void *m, long rw);
-extern "C" void AnnotateRWLockReleased(const char *f, int l, void *m, long rw);
+#include "test.h"
int main() {
int m = 0;
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/mutex_bad_unlock.cc b/third_party/llvm-project/compiler-rt/test/tsan/mutex_bad_unlock.cpp
similarity index 86%
rename from third_party/llvm-project/compiler-rt/test/tsan/mutex_bad_unlock.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/mutex_bad_unlock.cpp
index 6b483cf..a31485a 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/mutex_bad_unlock.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/mutex_bad_unlock.cpp
@@ -1,5 +1,5 @@
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
-extern "C" void AnnotateRWLockReleased(const char *f, int l, void *m, long rw);
+#include "test.h"
int main() {
int m = 0;
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/mutex_cycle2.c b/third_party/llvm-project/compiler-rt/test/tsan/mutex_cycle2.c
index 32659d4..0dc96d0 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/mutex_cycle2.c
+++ b/third_party/llvm-project/compiler-rt/test/tsan/mutex_cycle2.c
@@ -1,5 +1,5 @@
// RUN: %clangxx_tsan %s -o %t
-// RUN: not %run %t 2>&1 | FileCheck %s
+// RUN: not %run %t 2>&1 | FileCheck %s
// RUN: %env_tsan_opts=detect_deadlocks=1 not %run %t 2>&1 | FileCheck %s
// RUN: %env_tsan_opts=detect_deadlocks=0 %run %t 2>&1 | FileCheck %s --check-prefix=DISABLED
// RUN: echo "deadlock:main" > %t.supp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/mutex_destroy_locked.cc b/third_party/llvm-project/compiler-rt/test/tsan/mutex_destroy_locked.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/mutex_destroy_locked.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/mutex_destroy_locked.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/mutex_destroy_locked2.cc b/third_party/llvm-project/compiler-rt/test/tsan/mutex_destroy_locked2.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/mutex_destroy_locked2.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/mutex_destroy_locked2.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/mutex_double_lock.cc b/third_party/llvm-project/compiler-rt/test/tsan/mutex_double_lock.cpp
similarity index 80%
rename from third_party/llvm-project/compiler-rt/test/tsan/mutex_double_lock.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/mutex_double_lock.cpp
index c1bebf7..2bef93a 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/mutex_double_lock.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/mutex_double_lock.cpp
@@ -1,8 +1,5 @@
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
-#include <pthread.h>
-#include <unistd.h>
-
-extern "C" void AnnotateRWLockAcquired(const char *f, int l, void *m, long rw);
+#include "test.h"
void *ThreadFunc(void *m) {
AnnotateRWLockAcquired(__FILE__, __LINE__, m, 1);
@@ -25,5 +22,5 @@
// CHECK: Mutex {{.*}} created at:
// CHECK: #0 AnnotateRWLockAcquired
// CHECK: #1 main
-// CHECK: SUMMARY: ThreadSanitizer: double lock of a mutex {{.*}}mutex_double_lock.cc{{.*}}ThreadFunc
+// CHECK: SUMMARY: ThreadSanitizer: double lock of a mutex {{.*}}mutex_double_lock.cpp{{.*}}ThreadFunc
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/mutex_lock_destroyed.cc b/third_party/llvm-project/compiler-rt/test/tsan/mutex_lock_destroyed.cpp
similarity index 77%
rename from third_party/llvm-project/compiler-rt/test/tsan/mutex_lock_destroyed.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/mutex_lock_destroyed.cpp
index 52d6be6..b727b92 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/mutex_lock_destroyed.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/mutex_lock_destroyed.cpp
@@ -2,6 +2,9 @@
// RUN: %deflake %run %t | FileCheck %s
// RUN: %deflake %run %t 1 | FileCheck %s
+// The pthread_mutex_lock interceptor assumes incompatible internals w/ NetBSD
+// XFAIL: target={{.*netbsd.*}}
+
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
@@ -19,7 +22,7 @@
pthread_mutex_lock(m);
// CHECK: WARNING: ThreadSanitizer: use of an invalid mutex (e.g. uninitialized or destroyed)
// CHECK: #0 pthread_mutex_lock
- // CHECK: #1 main {{.*}}mutex_lock_destroyed.cc:[[@LINE-3]]
+ // CHECK: #1 main {{.*}}mutex_lock_destroyed.cpp:[[@LINE-3]]
return 0;
}
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/mutexset1.cc b/third_party/llvm-project/compiler-rt/test/tsan/mutexset1.cpp
similarity index 93%
rename from third_party/llvm-project/compiler-rt/test/tsan/mutexset1.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/mutexset1.cpp
index 8403b34..4aeeeda 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/mutexset1.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/mutexset1.cpp
@@ -26,7 +26,7 @@
// CHECK: Previous write of size 4 at {{.*}} by thread T2:
// CHECK: Mutex [[M1]] (0x{{.*}}) created at:
// CHECK: #0 pthread_mutex_init
- // CHECK: #1 main {{.*}}mutexset1.cc:[[@LINE+1]]
+ // CHECK: #1 main {{.*}}mutexset1.cpp:[[@LINE+1]]
pthread_mutex_init(&mtx, 0);
pthread_t t[2];
pthread_create(&t[0], NULL, Thread1, NULL);
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/mutexset2.cc b/third_party/llvm-project/compiler-rt/test/tsan/mutexset2.cpp
similarity index 93%
rename from third_party/llvm-project/compiler-rt/test/tsan/mutexset2.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/mutexset2.cpp
index 5f7c0c4..58a43c2 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/mutexset2.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/mutexset2.cpp
@@ -26,7 +26,7 @@
// CHECK: (mutexes: write [[M1:M[0-9]+]]):
// CHECK: Mutex [[M1]] (0x{{.*}}) created at:
// CHECK: #0 pthread_mutex_init
- // CHECK: #1 main {{.*}}mutexset2.cc:[[@LINE+1]]
+ // CHECK: #1 main {{.*}}mutexset2.cpp:[[@LINE+1]]
pthread_mutex_init(&mtx, 0);
pthread_t t[2];
pthread_create(&t[0], NULL, Thread1, NULL);
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/mutexset3.cc b/third_party/llvm-project/compiler-rt/test/tsan/mutexset3.cpp
similarity index 90%
rename from third_party/llvm-project/compiler-rt/test/tsan/mutexset3.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/mutexset3.cpp
index 24a9d9b..6e5d9cc 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/mutexset3.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/mutexset3.cpp
@@ -29,10 +29,10 @@
// CHECK: Previous write of size 4 at {{.*}} by thread T2:
// CHECK: Mutex [[M1]] (0x{{.*}}) created at:
// CHECK: #0 pthread_mutex_init
- // CHECK: #1 main {{.*}}mutexset3.cc:[[@LINE+4]]
+ // CHECK: #1 main {{.*}}mutexset3.cpp:[[@LINE+4]]
// CHECK: Mutex [[M2]] (0x{{.*}}) created at:
// CHECK: #0 pthread_mutex_init
- // CHECK: #1 main {{.*}}mutexset3.cc:[[@LINE+2]]
+ // CHECK: #1 main {{.*}}mutexset3.cpp:[[@LINE+2]]
pthread_mutex_init(&mtx1, 0);
pthread_mutex_init(&mtx2, 0);
pthread_t t[2];
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/mutexset4.cc b/third_party/llvm-project/compiler-rt/test/tsan/mutexset4.cpp
similarity index 90%
rename from third_party/llvm-project/compiler-rt/test/tsan/mutexset4.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/mutexset4.cpp
index 5d8ea9e..417efbd 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/mutexset4.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/mutexset4.cpp
@@ -29,10 +29,10 @@
// CHECK: (mutexes: write [[M1:M[0-9]+]], write [[M2:M[0-9]+]]):
// CHECK: Mutex [[M1]] (0x{{.*}}) created at:
// CHECK: #0 pthread_mutex_init
- // CHECK: #1 main {{.*}}mutexset4.cc:[[@LINE+4]]
+ // CHECK: #1 main {{.*}}mutexset4.cpp:[[@LINE+4]]
// CHECK: Mutex [[M2]] (0x{{.*}}) created at:
// CHECK: #0 pthread_mutex_init
- // CHECK: #1 main {{.*}}mutexset4.cc:[[@LINE+2]]
+ // CHECK: #1 main {{.*}}mutexset4.cpp:[[@LINE+2]]
pthread_mutex_init(&mtx1, 0);
pthread_mutex_init(&mtx2, 0);
pthread_t t[2];
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/mutexset5.cc b/third_party/llvm-project/compiler-rt/test/tsan/mutexset5.cpp
similarity index 91%
rename from third_party/llvm-project/compiler-rt/test/tsan/mutexset5.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/mutexset5.cpp
index b5f4e77..ad5a767 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/mutexset5.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/mutexset5.cpp
@@ -30,10 +30,10 @@
// CHECK: (mutexes: write [[M2:M[0-9]+]]):
// CHECK: Mutex [[M1]] (0x{{.*}}) created at:
// CHECK: #0 pthread_mutex_init
- // CHECK: #1 main {{.*}}mutexset5.cc:[[@LINE+4]]
+ // CHECK: #1 main {{.*}}mutexset5.cpp:[[@LINE+4]]
// CHECK: Mutex [[M2]] (0x{{.*}}) created at:
// CHECK: #0 pthread_mutex_init
- // CHECK: #1 main {{.*}}mutexset5.cc:[[@LINE+5]]
+ // CHECK: #1 main {{.*}}mutexset5.cpp:[[@LINE+2]]
pthread_mutex_init(&mtx1, 0);
pthread_mutex_init(&mtx2, 0);
pthread_t t[2];
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/mutexset6.cc b/third_party/llvm-project/compiler-rt/test/tsan/mutexset6.cpp
similarity index 89%
rename from third_party/llvm-project/compiler-rt/test/tsan/mutexset6.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/mutexset6.cpp
index ca349aa..89a5905 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/mutexset6.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/mutexset6.cpp
@@ -34,11 +34,11 @@
// CHECK: Previous write of size 4 at {{.*}} by thread T2
// CHECK: (mutexes: write [[M2:M[0-9]+]], read [[M3:M[0-9]+]]):
// CHECK: Mutex [[M1]] (0x{{.*}}) created at:
- // CHECK: #1 main {{.*}}mutexset6.cc:[[@LINE+5]]
+ // CHECK: #1 main {{.*}}mutexset6.cpp:[[@LINE+5]]
// CHECK: Mutex [[M2]] (0x{{.*}}) created at:
- // CHECK: #1 main {{.*}}mutexset6.cc:[[@LINE+4]]
+ // CHECK: #1 main {{.*}}mutexset6.cpp:[[@LINE+4]]
// CHECK: Mutex [[M3]] (0x{{.*}}) created at:
- // CHECK: #1 main {{.*}}mutexset6.cc:[[@LINE+3]]
+ // CHECK: #1 main {{.*}}mutexset6.cpp:[[@LINE+3]]
pthread_mutex_init(&mtx1, 0);
pthread_mutex_init(&mtx2, 0);
pthread_rwlock_init(&mtx3, 0);
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/mutexset7.cc b/third_party/llvm-project/compiler-rt/test/tsan/mutexset7.cpp
similarity index 78%
rename from third_party/llvm-project/compiler-rt/test/tsan/mutexset7.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/mutexset7.cpp
index d3a221d..5b4c7b9 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/mutexset7.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/mutexset7.cpp
@@ -1,4 +1,5 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
+// RUN: %clangxx_tsan %darwin_min_target_with_tls_support -O1 %s -o %t && \
+// RUN: %deflake %run %t | FileCheck %s
#include "test.h"
int Global;
@@ -35,6 +36,6 @@
// CHECK: Write of size 4 at {{.*}} by thread T1:
// CHECK: Previous write of size 4 at {{.*}} by thread T2
// CHECK: (mutexes: write [[M1:M[0-9]+]]):
-// CHECK: Mutex [[M1]] is already destroyed
-// CHECK-NOT: Mutex {{.*}} created at
-
+// CHECK: Mutex [[M1]] (0x{{.*}}) created at:
+// CHECK: #0 pthread_mutex_init
+// CHECK: #1 Thread2
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/mutexset8.cc b/third_party/llvm-project/compiler-rt/test/tsan/mutexset8.cpp
similarity index 95%
rename from third_party/llvm-project/compiler-rt/test/tsan/mutexset8.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/mutexset8.cpp
index 69854e2..e2fbfdb 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/mutexset8.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/mutexset8.cpp
@@ -26,7 +26,7 @@
// CHECK: Previous write of size 4 at {{.*}} by thread T2:
// CHECK: Mutex [[M1]] (0x{{.*}}) created at:
// CHECK: #0 pthread_mutex_init
- // CHECK: #1 main {{.*}}mutexset8.cc
+ // CHECK: #1 main {{.*}}mutexset8.cpp
mtx = new pthread_mutex_t;
pthread_mutex_init(mtx, 0);
pthread_t t[2];
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/on_exit.cpp b/third_party/llvm-project/compiler-rt/test/tsan/on_exit.cpp
new file mode 100644
index 0000000..2dadd68
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/on_exit.cpp
@@ -0,0 +1,36 @@
+// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
+
+// on_exit() is not available on Darwin.
+// UNSUPPORTED: darwin
+
+#include "test.h"
+
+volatile long global;
+
+void *thread(void *x) {
+ global++;
+ barrier_wait(&barrier);
+ return nullptr;
+}
+
+void on_exit_callback(int status, void *arg) {
+ fprintf(stderr, "on_exit_callback(%d, %lu)\n", status, (long)arg);
+ global++;
+}
+
+int main() {
+ on_exit(on_exit_callback, (void *)42l);
+ barrier_init(&barrier, 2);
+ pthread_t th;
+ pthread_create(&th, nullptr, thread, nullptr);
+ pthread_detach(th);
+ barrier_wait(&barrier);
+ return 2;
+}
+
+// CHECK: on_exit_callback(2, 42)
+// CHECK: WARNING: ThreadSanitizer: data race
+// CHECK: Write of size 8
+// CHECK: #0 on_exit_callback
+// CHECK: #1 on_exit_callback_installed_at
+// CHECK: #2 main
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/on_initialize_finalize_hooks.cpp b/third_party/llvm-project/compiler-rt/test/tsan/on_initialize_finalize_hooks.cpp
new file mode 100644
index 0000000..3f7b56b
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/on_initialize_finalize_hooks.cpp
@@ -0,0 +1,33 @@
+// RUN: %clang_tsan -O1 %s -DBUILD_LIB=1 -fno-sanitize=thread -shared -fPIC -o %dynamiclib %ld_flags_rpath_so
+// RUN: %clang_tsan -O1 %s -o %t %ld_flags_rpath_exe
+// RUN: %run %t | FileCheck %s
+
+// Test that initialization/finalization hooks are called, even when they are
+// not defined in the main executable, but by another another library that
+// doesn't directly link against the TSan runtime.
+
+#include <stdio.h>
+
+#if BUILD_LIB
+
+extern "C" void __tsan_on_initialize() {
+ printf("__tsan_on_initialize()\n");
+}
+
+extern "C" int __tsan_on_finalize(int failed) {
+ printf("__tsan_on_finalize()\n");
+ return failed;
+}
+
+#else // BUILD_LIB
+
+int main() {
+ printf("main()\n");
+ return 0;
+}
+
+#endif // BUILD_LIB
+
+// CHECK: __tsan_on_initialize()
+// CHECK: main()
+// CHECK: __tsan_on_finalize()
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/pie_test.cc b/third_party/llvm-project/compiler-rt/test/tsan/pie_test.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/pie_test.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/pie_test.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/print_full_thread_history.cpp b/third_party/llvm-project/compiler-rt/test/tsan/print_full_thread_history.cpp
new file mode 100644
index 0000000..ff341f6
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/print_full_thread_history.cpp
@@ -0,0 +1,40 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %env_tsan_opts=print_full_thread_history=true %deflake %run %t 2>&1 | FileCheck %s
+
+#include "test.h"
+
+int Global;
+
+void *Thread2(void *x) {
+ barrier_wait(&barrier);
+ Global++;
+ return NULL;
+}
+
+void *Thread3(void *x) {
+ Global--;
+ barrier_wait(&barrier);
+ return NULL;
+}
+
+void *Thread1(void *x) {
+ pthread_t t[2];
+ pthread_create(&t[0], NULL, Thread2, NULL);
+ pthread_create(&t[1], NULL, Thread3, NULL);
+ pthread_join(t[0], NULL);
+ pthread_join(t[1], NULL);
+ return NULL;
+}
+
+int main() {
+ barrier_init(&barrier, 2);
+ pthread_t t;
+ pthread_create(&t, NULL, Thread1, NULL);
+ pthread_join(t, NULL);
+ return 0;
+}
+
+// CHECK: WARNING: ThreadSanitizer: data race
+// CHECK: Thread T2 {{.*}} created by thread T1 at
+// CHECK: Thread T3 {{.*}} created by thread T1 at:
+// CHECK: Thread T1 {{.*}} created by main thread at:
+// CHECK: SUMMARY: ThreadSanitizer: data race{{.*}}
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/pthread_atfork_deadlock.c b/third_party/llvm-project/compiler-rt/test/tsan/pthread_atfork_deadlock.c
index 01107ee..b002d7d 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/pthread_atfork_deadlock.c
+++ b/third_party/llvm-project/compiler-rt/test/tsan/pthread_atfork_deadlock.c
@@ -21,7 +21,7 @@
int main() {
barrier_init(&barrier, 2);
- pthread_atfork(atfork, NULL, NULL);
+ pthread_atfork(atfork, atfork, atfork);
pthread_t t;
pthread_create(&t, NULL, worker, NULL);
glob++;
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/pthread_atfork_deadlock2.c b/third_party/llvm-project/compiler-rt/test/tsan/pthread_atfork_deadlock2.c
new file mode 100644
index 0000000..43f24f0
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/pthread_atfork_deadlock2.c
@@ -0,0 +1,53 @@
+// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
+// Regression test for
+// https://groups.google.com/d/msg/thread-sanitizer/e_zB9gYqFHM/DmAiTsrLAwAJ
+// pthread_atfork() callback triggers a data race and we deadlocked
+// on the report_mtx as we lock it around fork.
+#include "test.h"
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <errno.h>
+
+int glob = 0;
+
+void *worker(void *unused) {
+ glob++;
+ barrier_wait(&barrier);
+ return NULL;
+}
+
+void atfork() {
+ glob++;
+}
+
+int main() {
+ barrier_init(&barrier, 2);
+ pthread_atfork(atfork, atfork, atfork);
+ pthread_t t;
+ pthread_create(&t, NULL, worker, NULL);
+ barrier_wait(&barrier);
+ pid_t pid = fork();
+ if (pid < 0) {
+ fprintf(stderr, "fork failed: %d\n", errno);
+ return 1;
+ }
+ if (pid == 0) {
+ fprintf(stderr, "CHILD\n");
+ return 0;
+ }
+ if (pid != waitpid(pid, NULL, 0)) {
+ fprintf(stderr, "waitpid failed: %d\n", errno);
+ return 1;
+ }
+ pthread_join(t, NULL);
+ fprintf(stderr, "PARENT\n");
+ return 0;
+}
+
+// CHECK: ThreadSanitizer: data race
+// CHECK: Write of size 4
+// CHECK: #0 atfork
+// CHECK: Previous write of size 4
+// CHECK: #0 worker
+// CHECK: CHILD
+// CHECK: PARENT
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/pthread_atfork_deadlock3.c b/third_party/llvm-project/compiler-rt/test/tsan/pthread_atfork_deadlock3.c
new file mode 100644
index 0000000..793eaf6
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/pthread_atfork_deadlock3.c
@@ -0,0 +1,97 @@
+// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t > %t.out
+// RUN: FileCheck %s --check-prefixes=CHECK,PARENT --input-file %t.out
+// RUN: FileCheck %s --check-prefixes=CHECK,CHILD --input-file %t.out
+// Regression test for
+// https://groups.google.com/g/thread-sanitizer/c/TQrr4-9PRYo/m/HFR4FMi6AQAJ
+#include "test.h"
+#include <errno.h>
+#include <signal.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+
+long glob = 0;
+
+void *worker(void *main) {
+ glob++;
+ // synchronize with main
+ barrier_wait(&barrier);
+ // synchronize with atfork
+ barrier_wait(&barrier);
+ pthread_kill((pthread_t)main, SIGPROF);
+ barrier_wait(&barrier);
+ // synchronize with afterfork
+ barrier_wait(&barrier);
+ pthread_kill((pthread_t)main, SIGPROF);
+ barrier_wait(&barrier);
+ return NULL;
+}
+
+void atfork() {
+ barrier_wait(&barrier);
+ barrier_wait(&barrier);
+ write(2, "in atfork\n", strlen("in atfork\n"));
+ static volatile long a;
+ __atomic_fetch_add(&a, 1, __ATOMIC_RELEASE);
+}
+
+void afterfork() {
+ barrier_wait(&barrier);
+ barrier_wait(&barrier);
+ write(2, "in afterfork\n", strlen("in afterfork\n"));
+ static volatile long a;
+ __atomic_fetch_add(&a, 1, __ATOMIC_RELEASE);
+}
+
+void afterfork_child() {
+ write(2, "in afterfork_child\n", strlen("in afterfork_child\n"));
+ glob++;
+}
+
+void handler(int sig) {
+ write(2, "in handler\n", strlen("in handler\n"));
+ glob++;
+}
+
+int main() {
+ barrier_init(&barrier, 2);
+ struct sigaction act = {};
+ act.sa_handler = &handler;
+ if (sigaction(SIGPROF, &act, 0)) {
+ perror("sigaction");
+ exit(1);
+ }
+ pthread_atfork(atfork, afterfork, afterfork_child);
+ pthread_t t;
+ pthread_create(&t, NULL, worker, (void *)pthread_self());
+ barrier_wait(&barrier);
+ pid_t pid = fork();
+ if (pid < 0) {
+ fprintf(stderr, "fork failed: %d\n", errno);
+ return 1;
+ }
+ if (pid == 0) {
+ fprintf(stderr, "CHILD\n");
+ return 0;
+ }
+ if (pid != waitpid(pid, NULL, 0)) {
+ fprintf(stderr, "waitpid failed: %d\n", errno);
+ return 1;
+ }
+ pthread_join(t, NULL);
+ fprintf(stderr, "PARENT\n");
+ return 0;
+}
+
+// CHECK: in atfork
+// CHECK: in handler
+// CHECK: ThreadSanitizer: data race
+// CHECK: Write of size 8
+// CHECK: #0 handler
+// CHECK: Previous write of size 8
+// CHECK: #0 worker
+// PARENT: afterfork
+// PARENT: in handler
+// CHILD: afterfork_child
+// CHILD: CHILD
+// CHECK: PARENT
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/pthread_key.cc b/third_party/llvm-project/compiler-rt/test/tsan/pthread_key.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/pthread_key.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/pthread_key.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/race_on_fputs.cc b/third_party/llvm-project/compiler-rt/test/tsan/race_on_fputs.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/race_on_fputs.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/race_on_fputs.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/race_on_heap.cc b/third_party/llvm-project/compiler-rt/test/tsan/race_on_heap.cpp
similarity index 93%
rename from third_party/llvm-project/compiler-rt/test/tsan/race_on_heap.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/race_on_heap.cpp
index 6c2defc..8dd1d26 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/race_on_heap.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/race_on_heap.cpp
@@ -14,7 +14,7 @@
return 0;
}
-void *alloc() {
+__attribute__((noinline)) void *alloc() {
return malloc(99);
}
@@ -39,7 +39,7 @@
// CHECK: WARNING: ThreadSanitizer: data race
// ...
// CHECK: Location is heap block of size 99 at [[ADDR]] allocated by thread T1:
-// CHCEK: #0 malloc
+// CHECK: #0 malloc
// CHECK: #{{1|2}} alloc
// CHECK: #{{2|3}} AllocThread
// ...
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/race_on_puts.cc b/third_party/llvm-project/compiler-rt/test/tsan/race_on_puts.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/race_on_puts.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/race_on_puts.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/race_on_read.cc b/third_party/llvm-project/compiler-rt/test/tsan/race_on_read.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/race_on_read.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/race_on_read.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/race_on_speculative_load.cc b/third_party/llvm-project/compiler-rt/test/tsan/race_on_speculative_load.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/race_on_speculative_load.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/race_on_speculative_load.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/race_on_write.cc b/third_party/llvm-project/compiler-rt/test/tsan/race_on_write.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/race_on_write.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/race_on_write.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/race_range_pc.cpp b/third_party/llvm-project/compiler-rt/test/tsan/race_range_pc.cpp
new file mode 100644
index 0000000..30d89e5
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/race_range_pc.cpp
@@ -0,0 +1,40 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
+// This test fails on powerpc64 big endian.
+// The Tsan report is returning wrong information about
+// the location of the race.
+// XFAIL: target=powerpc64-unknown-linux-gnu{{.*}}
+
+#include "test.h"
+
+typedef unsigned long uptr;
+extern "C" void __tsan_read_range_pc(uptr addr, uptr size, uptr pc);
+extern "C" void __tsan_write_range_pc(uptr addr, uptr size, uptr pc);
+
+void foobar() {
+}
+
+void barbaz() {
+}
+
+void *Thread(void *p) {
+ barrier_wait(&barrier);
+ __tsan_read_range_pc((uptr)p, 32, (uptr)foobar + kPCInc);
+ return 0;
+}
+
+int main() {
+ barrier_init(&barrier, 2);
+ int a[128];
+ pthread_t th;
+ pthread_create(&th, 0, Thread, (void*)a);
+ __tsan_write_range_pc((uptr)(a+2), 32, (uptr)barbaz + kPCInc);
+ barrier_wait(&barrier);
+ pthread_join(th, 0);
+ fprintf(stderr, "DONE\n");
+ return 0;
+}
+
+// CHECK: WARNING: ThreadSanitizer: data race
+// CHECK: #0 foobar
+// CHECK: #0 barbaz
+// CHECK: DONE
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/race_stress.cc b/third_party/llvm-project/compiler-rt/test/tsan/race_stress.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/race_stress.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/race_stress.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/race_top_suppression.cc b/third_party/llvm-project/compiler-rt/test/tsan/race_top_suppression.cpp
similarity index 90%
rename from third_party/llvm-project/compiler-rt/test/tsan/race_top_suppression.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/race_top_suppression.cpp
index bd5c1bd..8e494c1 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/race_top_suppression.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/race_top_suppression.cpp
@@ -6,7 +6,7 @@
int Global;
-void TopFunction(int *p) {
+__attribute__((noinline)) void TopFunction(int *p) {
*p = 1;
}
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/race_top_suppression1.cc b/third_party/llvm-project/compiler-rt/test/tsan/race_top_suppression1.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/race_top_suppression1.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/race_top_suppression1.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/race_with_finished_thread.cc b/third_party/llvm-project/compiler-rt/test/tsan/race_with_finished_thread.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/race_with_finished_thread.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/race_with_finished_thread.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/real_deadlock_detector_stress_test.cc b/third_party/llvm-project/compiler-rt/test/tsan/real_deadlock_detector_stress_test.cpp
similarity index 97%
rename from third_party/llvm-project/compiler-rt/test/tsan/real_deadlock_detector_stress_test.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/real_deadlock_detector_stress_test.cpp
index feb1117..8106ab8 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/real_deadlock_detector_stress_test.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/real_deadlock_detector_stress_test.cpp
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s %link_libcxx_tsan -o %t && %run %t 2>&1 | FileCheck %s
#include <pthread.h>
#include <stdlib.h>
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/restore_stack.cc b/third_party/llvm-project/compiler-rt/test/tsan/restore_stack.cpp
similarity index 73%
rename from third_party/llvm-project/compiler-rt/test/tsan/restore_stack.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/restore_stack.cpp
index 39c1101..4ffce70 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/restore_stack.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/restore_stack.cpp
@@ -39,10 +39,10 @@
// Previously this test produced bogus stack traces like:
// Previous write of size 8 at 0x0000006a8ff8 by thread T17:
-// #0 foo() restore_stack.cc:13:5 (restore_stack.cc.exe+0x00000040622c)
-// #1 Thread(void*) restore_stack.cc:18:3 (restore_stack.cc.exe+0x000000406283)
-// #2 __tsan_thread_start_func rtl/tsan_interceptors.cc:886 (restore_stack.cc.exe+0x00000040a749)
-// #3 Thread(void*) restore_stack.cc:18:3 (restore_stack.cc.exe+0x000000406283)
+// #0 foo() restore_stack.cpp:13:5 (restore_stack.cpp.exe+0x00000040622c)
+// #1 Thread(void*) restore_stack.cpp:18:3 (restore_stack.cpp.exe+0x000000406283)
+// #2 __tsan_thread_start_func rtl/tsan_interceptors.cpp:886 (restore_stack.cpp.exe+0x00000040a749)
+// #3 Thread(void*) restore_stack.cpp:18:3 (restore_stack.cpp.exe+0x000000406283)
// CHECK: WARNING: ThreadSanitizer: data race
// CHECK-NOT: __tsan_thread_start_func
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/setuid.c b/third_party/llvm-project/compiler-rt/test/tsan/setuid.c
deleted file mode 100644
index 2d6b7c8..0000000
--- a/third_party/llvm-project/compiler-rt/test/tsan/setuid.c
+++ /dev/null
@@ -1,32 +0,0 @@
-// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
-//
-// setuid(0) hangs on powerpc64 big endian. When this is fixed remove
-// the unsupported flag.
-// https://llvm.org/bugs/show_bug.cgi?id=25799
-//
-// UNSUPPORTED: powerpc64-unknown-linux-gnu
-#include "test.h"
-#include <sys/types.h>
-#include <unistd.h>
-
-// Setuid call used to hang because the background tsan thread did not handle
-// SIGSETXID signal. Note that we don't care whether setuid call succeeds
-// or not.
-
-static void *thread(void *arg) {
- (void)arg;
- sleep(1);
- return 0;
-}
-
-int main() {
- // Create another thread just for completeness of the picture.
- pthread_t th;
- pthread_create(&th, 0, thread, 0);
- setuid(0);
- pthread_join(th, 0);
- fprintf(stderr, "DONE\n");
- return 0;
-}
-
-// CHECK: DONE
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/setuid2.c b/third_party/llvm-project/compiler-rt/test/tsan/setuid2.c
index 3ea8978..6f42223 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/setuid2.c
+++ b/third_party/llvm-project/compiler-rt/test/tsan/setuid2.c
@@ -4,7 +4,7 @@
// the unsupported flag.
// https://llvm.org/bugs/show_bug.cgi?id=25799
//
-// UNSUPPORTED: powerpc64-unknown-linux-gnu
+// UNSUPPORTED: target=powerpc64-unknown-linux-gnu{{.*}}
#include "test.h"
#include <sys/types.h>
#include <unistd.h>
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/signal_block.cc b/third_party/llvm-project/compiler-rt/test/tsan/signal_block.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/signal_block.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/signal_block.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/signal_block2.cpp b/third_party/llvm-project/compiler-rt/test/tsan/signal_block2.cpp
new file mode 100644
index 0000000..f93ce1b
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/signal_block2.cpp
@@ -0,0 +1,91 @@
+// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
+// The test was reported to hang sometimes on Darwin:
+// https://lists.llvm.org/pipermail/llvm-commits/Week-of-Mon-20210517/917003.html
+// UNSUPPORTED: darwin
+
+#include "test.h"
+#include <signal.h>
+#include <string.h>
+#include <sys/time.h>
+
+int test;
+int done;
+int signals_handled;
+pthread_t main_thread;
+pthread_mutex_t mutex;
+pthread_cond_t cond;
+
+void timer_handler(int signum) {
+ write(2, "timer_handler\n", strlen("timer_handler\n"));
+ if (++signals_handled < 10)
+ return;
+ switch (test) {
+ case 0:
+ __atomic_store_n(&done, 1, __ATOMIC_RELEASE);
+ (void)pthread_kill(main_thread, SIGUSR1);
+ case 1:
+ if (pthread_mutex_trylock(&mutex) == 0) {
+ __atomic_store_n(&done, 1, __ATOMIC_RELEASE);
+ pthread_cond_signal(&cond);
+ pthread_mutex_unlock(&mutex);
+ }
+ case 2:
+ __atomic_store_n(&done, 1, __ATOMIC_RELEASE);
+ }
+}
+
+int main(int argc, char **argv) {
+ main_thread = pthread_self();
+ pthread_mutex_init(&mutex, 0);
+ pthread_cond_init(&cond, 0);
+
+ sigset_t sigset;
+ sigemptyset(&sigset);
+ sigaddset(&sigset, SIGUSR1);
+ if (sigprocmask(SIG_BLOCK, &sigset, NULL))
+ exit((perror("sigprocmask"), 1));
+
+ struct sigaction sa;
+ memset(&sa, 0, sizeof(sa));
+ sa.sa_handler = &timer_handler;
+ if (sigaction(SIGALRM, &sa, NULL))
+ exit((perror("setitimer"), 1));
+
+ for (test = 0; test < 3; test++) {
+ fprintf(stderr, "test %d\n", test);
+ struct itimerval timer;
+ timer.it_value.tv_sec = 0;
+ timer.it_value.tv_usec = 50000;
+ timer.it_interval = timer.it_value;
+ if (setitimer(ITIMER_REAL, &timer, NULL))
+ exit((perror("setitimer"), 1));
+
+ switch (test) {
+ case 0:
+ while (__atomic_load_n(&done, __ATOMIC_ACQUIRE) == 0) {
+ int signum;
+ sigwait(&sigset, &signum);
+ write(2, "sigwait\n", strlen("sigwait\n"));
+ }
+ case 1:
+ pthread_mutex_lock(&mutex);
+ while (__atomic_load_n(&done, __ATOMIC_ACQUIRE) == 0) {
+ pthread_cond_wait(&cond, &mutex);
+ write(2, "pthread_cond_wait\n", strlen("pthread_cond_wait\n"));
+ }
+ pthread_mutex_unlock(&mutex);
+ case 2:
+ while (__atomic_load_n(&done, __ATOMIC_ACQUIRE) == 0) {
+ }
+ }
+
+ memset(&timer, 0, sizeof(timer));
+ if (setitimer(ITIMER_REAL, &timer, NULL))
+ exit((perror("setitimer"), 1));
+ done = 0;
+ signals_handled = 0;
+ }
+ fprintf(stderr, "DONE\n");
+}
+
+// CHECK: DONE
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/signal_cond.cc b/third_party/llvm-project/compiler-rt/test/tsan/signal_cond.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/signal_cond.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/signal_cond.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/signal_errno.cc b/third_party/llvm-project/compiler-rt/test/tsan/signal_errno.cpp
similarity index 90%
rename from third_party/llvm-project/compiler-rt/test/tsan/signal_errno.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/signal_errno.cpp
index e13e156..7e1fd4b 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/signal_errno.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/signal_errno.cpp
@@ -1,7 +1,7 @@
// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
// This test fails on powerpc64 BE (VMA=44), it does not appear to be
// a functional problem, but the Tsan report is missing some info.
-// XFAIL: powerpc64-unknown-linux-gnu
+// XFAIL: target=powerpc64-unknown-linux-gnu{{.*}}
#include "test.h"
#include <signal.h>
@@ -46,7 +46,7 @@
}
// CHECK: WARNING: ThreadSanitizer: signal handler spoils errno
-// CHECK: #0 MyHandler(int, {{(__)?}}siginfo{{(_t)?}}*, void*) {{.*}}signal_errno.cc
+// CHECK: Signal 27 handler invoked at:
+// CHECK: #0 MyHandler(int, {{(__)?}}siginfo{{(_t)?}}*, void*) {{.*}}signal_errno.cpp
// CHECK: main
// CHECK: SUMMARY: ThreadSanitizer: signal handler spoils errno{{.*}}MyHandler
-
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/signal_exit.cpp b/third_party/llvm-project/compiler-rt/test/tsan/signal_exit.cpp
new file mode 100644
index 0000000..0c4444d
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/signal_exit.cpp
@@ -0,0 +1,22 @@
+// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
+#include "test.h"
+#include <signal.h>
+#include <sys/types.h>
+
+static void handler(int, siginfo_t *, void *) {
+ write(2, "SIGNAL\n", 7);
+ // CHECK: SIGNAL
+ _exit(0);
+ // CHECK-NOT: ThreadSanitizer: signal-unsafe call
+}
+
+int main() {
+ struct sigaction act = {};
+ act.sa_sigaction = &handler;
+ act.sa_flags = SA_SIGINFO;
+ sigaction(SIGPROF, &act, 0);
+ raise(SIGPROF);
+ fprintf(stderr, "DONE\n");
+ // CHECK-NOT: DONE
+ return 0;
+}
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/signal_longjmp.cc b/third_party/llvm-project/compiler-rt/test/tsan/signal_longjmp.cpp
similarity index 96%
rename from third_party/llvm-project/compiler-rt/test/tsan/signal_longjmp.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/signal_longjmp.cpp
index f9fa4f5..7e9ffca 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/signal_longjmp.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/signal_longjmp.cpp
@@ -6,7 +6,7 @@
// This test fails on powerpc64 BE (VMA=44), a segmentation fault
// error happens at the second assignment
// "((volatile int *volatile)mem)[1] = 1".
-// XFAIL: powerpc64-unknown-linux-gnu
+// XFAIL: target=powerpc64-unknown-linux-gnu{{.*}}
#include <setjmp.h>
#include <signal.h>
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/signal_malloc.cc b/third_party/llvm-project/compiler-rt/test/tsan/signal_malloc.cpp
similarity index 63%
rename from third_party/llvm-project/compiler-rt/test/tsan/signal_malloc.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/signal_malloc.cpp
index 1dccb13..9f73ee9 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/signal_malloc.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/signal_malloc.cpp
@@ -6,10 +6,14 @@
static void handler(int, siginfo_t*, void*) {
// CHECK: WARNING: ThreadSanitizer: signal-unsafe call inside of a signal
// CHECK: #0 malloc
- // CHECK: #{{(1|2)}} handler(int, {{(__)?}}siginfo{{(_t)?}}*, void*) {{.*}}signal_malloc.cc:[[@LINE+2]]
+ // CHECK: #{{(1|2)}} handler(int, {{(__)?}}siginfo{{(_t)?}}*, void*) {{.*}}signal_malloc.cpp:[[@LINE+2]]
// CHECK: SUMMARY: ThreadSanitizer: signal-unsafe call inside of a signal{{.*}}handler
volatile char *p = (char*)malloc(1);
p[0] = 0;
+ // CHECK: WARNING: ThreadSanitizer: signal-unsafe call inside of a signal
+ // CHECK: #0 free
+ // CHECK: #{{(1|2)}} handler(int, {{(__)?}}siginfo{{(_t)?}}*, void*) {{.*}}signal_malloc.cpp:[[@LINE+2]]
+ // CHECK: SUMMARY: ThreadSanitizer: signal-unsafe call inside of a signal{{.*}}handler
free((void*)p);
}
@@ -19,6 +23,8 @@
sigaction(SIGPROF, &act, 0);
kill(getpid(), SIGPROF);
sleep(1); // let the signal handler run
+ fprintf(stderr, "DONE\n");
+ // CHECK: DONE
return 0;
}
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/signal_pause.cc b/third_party/llvm-project/compiler-rt/test/tsan/signal_pause.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/signal_pause.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/signal_pause.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/signal_recursive.cc b/third_party/llvm-project/compiler-rt/test/tsan/signal_recursive.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/signal_recursive.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/signal_recursive.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/signal_reset.cc b/third_party/llvm-project/compiler-rt/test/tsan/signal_reset.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/signal_reset.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/signal_reset.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/signal_sync.cc b/third_party/llvm-project/compiler-rt/test/tsan/signal_sync.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/signal_sync.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/signal_sync.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/signal_sync2.cc b/third_party/llvm-project/compiler-rt/test/tsan/signal_sync2.cpp
similarity index 88%
rename from third_party/llvm-project/compiler-rt/test/tsan/signal_sync2.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/signal_sync2.cpp
index 163f206..2bc1383 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/signal_sync2.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/signal_sync2.cpp
@@ -1,19 +1,16 @@
// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
// UNSUPPORTED: darwin
-#include <pthread.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <signal.h>
-#include <sys/types.h>
-#include <sys/time.h>
-#include <unistd.h>
+// Fails episodically on powerpc bots:
+// https://lab.llvm.org/buildbot/#/builders/121/builds/13391
+// UNSUPPORTED: target=powerpc64{{.*}}
+#include "test.h"
#include <errno.h>
+#include <signal.h>
+#include <sys/time.h>
+#include <sys/types.h>
// Test synchronization in signal handled within IgnoreSync region.
-extern "C" void AnnotateIgnoreSyncBegin(const char *f, int l);
-extern "C" void AnnotateIgnoreSyncEnd(const char *f, int l);
-
const int kSignalCount = 500;
__thread int process_signals;
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/signal_thread.cc b/third_party/llvm-project/compiler-rt/test/tsan/signal_thread.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/signal_thread.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/signal_thread.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/signal_thread2.cpp b/third_party/llvm-project/compiler-rt/test/tsan/signal_thread2.cpp
new file mode 100644
index 0000000..a773058
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/signal_thread2.cpp
@@ -0,0 +1,66 @@
+// RUN: %clangxx_tsan %s -o %t && %run %t 2>&1 | FileCheck %s
+// UNSUPPORTED: darwin
+
+// Test case for https://github.com/google/sanitizers/issues/1540
+
+#include <errno.h>
+#include <pthread.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+volatile int X;
+
+static void handler(int sig) {
+ (void)sig;
+ if (X != 0)
+ printf("bad");
+}
+
+static void *thr1(void *p) {
+ sleep(1);
+ return 0;
+}
+
+static void *thr(void *p) {
+ pthread_t th[10];
+ for (int i = 0; i < sizeof(th) / sizeof(th[0]); i++)
+ pthread_create(&th[i], 0, thr1, 0);
+ for (int i = 0; i < sizeof(th) / sizeof(th[0]); i++)
+ pthread_join(th[i], 0);
+ return 0;
+}
+
+int main() {
+ struct sigaction act = {};
+ act.sa_handler = &handler;
+ if (sigaction(SIGPROF, &act, 0)) {
+ perror("sigaction");
+ exit(1);
+ }
+
+ itimerval t;
+ t.it_value.tv_sec = 0;
+ t.it_value.tv_usec = 10;
+ t.it_interval = t.it_value;
+ if (setitimer(ITIMER_PROF, &t, 0)) {
+ perror("setitimer");
+ exit(1);
+ }
+
+ pthread_t th[100];
+ for (int i = 0; i < sizeof(th) / sizeof(th[0]); i++)
+ pthread_create(&th[i], 0, thr, 0);
+ for (int i = 0; i < sizeof(th) / sizeof(th[0]); i++)
+ pthread_join(th[i], 0);
+
+ fprintf(stderr, "DONE\n");
+ return 0;
+}
+
+// CHECK-NOT: WARNING: ThreadSanitizer:
+// CHECK: DONE
+// CHECK-NOT: WARNING: ThreadSanitizer:
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/signal_thread_sigctx_race.cpp b/third_party/llvm-project/compiler-rt/test/tsan/signal_thread_sigctx_race.cpp
new file mode 100644
index 0000000..a3a206f
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/signal_thread_sigctx_race.cpp
@@ -0,0 +1,84 @@
+// RUN: %clangxx_tsan %s -o %t && %run %t 2>&1 | FileCheck %s
+// UNSUPPORTED: darwin
+
+#include <errno.h>
+#include <limits.h>
+#include <pthread.h>
+#include <signal.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/select.h>
+#include <sys/time.h>
+#include <sys/types.h>
+#include <unistd.h>
+
+// This attempts to exercise a race condition where both a thread and its signal
+// handler allocate the SigCtx. If the race is allowed, it leads to a leak and
+// the first signal being dropped.
+// Spawn threads in a loop and send it SIGUSR1 concurrently with the thread
+// doing a bogus kill() call. The signal handler writes to a self-pipe which the
+// thread detects and then exits. A dropped signal results in a timeout.
+int pipes[2];
+static void handler(int sig) { write(pipes[1], "x", 1); }
+
+static int do_select() {
+ struct timeval tvs {
+ 0, 1000
+ };
+ fd_set fds;
+ FD_ZERO(&fds);
+ FD_SET(pipes[0], &fds);
+ return select(pipes[0] + 1, &fds, 0, 0, &tvs);
+}
+
+static void *thr(void *p) {
+ // This kill() is expected to fail; it exists only to trigger a call to SigCtx
+ // outside of the signal handler.
+ kill(INT_MIN, 0);
+ int success = 0;
+ for (int i = 0; i < 1024; i++) {
+ if (do_select() > 0) {
+ success = 1;
+ break;
+ }
+ }
+ if (success) {
+ char c;
+ read(pipes[0], &c, 1);
+ } else {
+ fprintf(stderr, "Failed to receive signal\n");
+ exit(1);
+ }
+ return p;
+}
+
+int main() {
+ if (pipe(pipes)) {
+ perror("pipe");
+ exit(1);
+ }
+
+ struct sigaction act = {};
+ act.sa_handler = &handler;
+ if (sigaction(SIGUSR1, &act, 0)) {
+ perror("sigaction");
+ exit(1);
+ }
+
+ for (int i = 0; i < (1 << 10); i++) {
+ pthread_t th{};
+ if (pthread_create(&th, 0, thr, 0)) {
+ perror("pthread_create");
+ exit(1);
+ }
+ pthread_kill(th, SIGUSR1);
+ pthread_join(th, 0);
+ }
+
+ fprintf(stderr, "DONE\n");
+ return 0;
+}
+
+// CHECK-NOT: WARNING: ThreadSanitizer:
+// CHECK: DONE
+// CHECK-NOT: WARNING: ThreadSanitizer:
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/signal_write.cc b/third_party/llvm-project/compiler-rt/test/tsan/signal_write.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/signal_write.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/signal_write.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/sigsuspend.cc b/third_party/llvm-project/compiler-rt/test/tsan/sigsuspend.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/sigsuspend.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/sigsuspend.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/simple_race.cc b/third_party/llvm-project/compiler-rt/test/tsan/simple_race.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/simple_race.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/simple_race.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/simple_stack.c b/third_party/llvm-project/compiler-rt/test/tsan/simple_stack.c
index 71a3911..0c02cbd 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/simple_stack.c
+++ b/third_party/llvm-project/compiler-rt/test/tsan/simple_stack.c
@@ -32,7 +32,7 @@
return NULL;
}
-void StartThread(pthread_t *t, void *(*f)(void*)) {
+void __attribute__((noinline)) StartThread(pthread_t *t, void *(*f)(void*)) {
pthread_create(t, NULL, f, NULL);
}
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/simple_stack2.cc b/third_party/llvm-project/compiler-rt/test/tsan/simple_stack2.cpp
similarity index 62%
rename from third_party/llvm-project/compiler-rt/test/tsan/simple_stack2.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/simple_stack2.cpp
index bbea713..5428dbc 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/simple_stack2.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/simple_stack2.cpp
@@ -44,10 +44,10 @@
// CHECK: WARNING: ThreadSanitizer: data race
// CHECK-NEXT: Write of size 4 at {{.*}} by thread T1:
-// CHECK-NEXT: #0 foo1{{.*}} {{.*}}simple_stack2.cc:[[@LINE-40]]{{(:10)?}} ({{.*}})
-// CHECK-NEXT: #1 bar1{{.*}} {{.*}}simple_stack2.cc:[[@LINE-34]]{{(:3)?}} ({{.*}})
-// CHECK-NEXT: #2 Thread1{{.*}} {{.*}}simple_stack2.cc:[[@LINE-17]]{{(:3)?}} ({{.*}})
+// CHECK-NEXT: #0 foo1{{.*}} {{.*}}simple_stack2.cpp:[[@LINE-40]]{{(:10)?}} ({{.*}})
+// CHECK-NEXT: #1 bar1{{.*}} {{.*}}simple_stack2.cpp:[[@LINE-34]]{{(:3)?}} ({{.*}})
+// CHECK-NEXT: #2 Thread1{{.*}} {{.*}}simple_stack2.cpp:[[@LINE-17]]{{(:3)?}} ({{.*}})
// CHECK: Previous read of size 4 at {{.*}} by main thread:
-// CHECK-NEXT: #0 foo2{{.*}} {{.*}}simple_stack2.cc:[[@LINE-33]]{{(:22)?}} ({{.*}})
-// CHECK-NEXT: #1 bar2{{.*}} {{.*}}simple_stack2.cc:[[@LINE-25]]{{(:3)?}} ({{.*}})
-// CHECK-NEXT: #2 main{{.*}} {{.*}}simple_stack2.cc:[[@LINE-13]]{{(:3)?}} ({{.*}})
+// CHECK-NEXT: #0 foo2{{.*}} {{.*}}simple_stack2.cpp:[[@LINE-33]]{{(:22)?}} ({{.*}})
+// CHECK-NEXT: #1 bar2{{.*}} {{.*}}simple_stack2.cpp:[[@LINE-25]]{{(:3)?}} ({{.*}})
+// CHECK-NEXT: #2 main{{.*}} {{.*}}simple_stack2.cpp:[[@LINE-13]]{{(:3)?}} ({{.*}})
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/sleep_sync.cc b/third_party/llvm-project/compiler-rt/test/tsan/sleep_sync.cpp
similarity index 93%
rename from third_party/llvm-project/compiler-rt/test/tsan/sleep_sync.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/sleep_sync.cpp
index b2c6a12..7d6787e 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/sleep_sync.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/sleep_sync.cpp
@@ -3,7 +3,7 @@
int X = 0;
-void MySleep() {
+__attribute__((noinline)) void MySleep() {
sleep(1); // the sleep that must appear in the report
}
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/sleep_sync2.cc b/third_party/llvm-project/compiler-rt/test/tsan/sleep_sync2.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/sleep_sync2.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/sleep_sync2.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/stack_race.cc b/third_party/llvm-project/compiler-rt/test/tsan/stack_race.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/stack_race.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/stack_race.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/stack_race2.cc b/third_party/llvm-project/compiler-rt/test/tsan/stack_race2.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/stack_race2.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/stack_race2.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/stack_sync_reuse.cc b/third_party/llvm-project/compiler-rt/test/tsan/stack_sync_reuse.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/stack_sync_reuse.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/stack_sync_reuse.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/static_init1.cc b/third_party/llvm-project/compiler-rt/test/tsan/static_init1.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/static_init1.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/static_init1.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/static_init2.cc b/third_party/llvm-project/compiler-rt/test/tsan/static_init2.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/static_init2.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/static_init2.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/static_init3.cc b/third_party/llvm-project/compiler-rt/test/tsan/static_init3.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/static_init3.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/static_init3.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/static_init4.cc b/third_party/llvm-project/compiler-rt/test/tsan/static_init4.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/static_init4.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/static_init4.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/static_init5.cc b/third_party/llvm-project/compiler-rt/test/tsan/static_init5.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/static_init5.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/static_init5.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/static_init6.cc b/third_party/llvm-project/compiler-rt/test/tsan/static_init6.cc
deleted file mode 100644
index 06215ce..0000000
--- a/third_party/llvm-project/compiler-rt/test/tsan/static_init6.cc
+++ /dev/null
@@ -1,43 +0,0 @@
-// 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
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/static_init5.cc b/third_party/llvm-project/compiler-rt/test/tsan/static_init6.cpp
similarity index 100%
copy from third_party/llvm-project/compiler-rt/test/tsan/static_init5.cc
copy to third_party/llvm-project/compiler-rt/test/tsan/static_init6.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/static_init7.cpp b/third_party/llvm-project/compiler-rt/test/tsan/static_init7.cpp
new file mode 100644
index 0000000..7d48302
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/static_init7.cpp
@@ -0,0 +1,39 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
+#include <pthread.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+struct P {
+ int x;
+ int y;
+};
+
+int Helper() {
+ try {
+ static int i = []() {
+ throw P{};
+ return 1;
+ }();
+ return i;
+ } catch (P) {
+ return 0;
+ }
+}
+
+void *Thread(void *x) {
+ for (int i = 0; i < 1000; ++i) {
+ Helper();
+ }
+ return 0;
+}
+
+int main() {
+ pthread_t t[2];
+ pthread_create(&t[0], 0, Thread, 0);
+ pthread_create(&t[1], 0, Thread, 0);
+ pthread_join(t[0], 0);
+ pthread_join(t[1], 0);
+ fprintf(stderr, "PASS\n");
+}
+
+// CHECK-NOT: WARNING: ThreadSanitizer: data race
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/strerror_r.cc b/third_party/llvm-project/compiler-rt/test/tsan/strerror_r.cpp
similarity index 80%
rename from third_party/llvm-project/compiler-rt/test/tsan/strerror_r.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/strerror_r.cpp
index cfe8a18..6adab1e 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/strerror_r.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/strerror_r.cpp
@@ -1,8 +1,7 @@
// RUN: %clangxx_tsan -O1 -DTEST_ERROR=ERANGE %s -o %t && %run %t 2>&1 | FileCheck --check-prefixes=CHECK,CHECK-SYS %s
// RUN: %clangxx_tsan -O1 -DTEST_ERROR=-1 %s -o %t && not %run %t 2>&1 | FileCheck --check-prefixes=CHECK,CHECK-USER %s
-// UNSUPPORTED: darwin
-// This test provokes a data race under FreeBSD
-// XFAIL: freebsd
+// This test is for GNU specific version of strerror_r()
+// UNSUPPORTED: darwin, target={{.*(netbsd|freebsd).*}}
#include "test.h"
@@ -14,8 +13,7 @@
void *Thread(void *p) {
barrier_wait(&barrier);
- strerror_r(TEST_ERROR, buffer, sizeof(buffer));
- return buffer;
+ return strerror_r(TEST_ERROR, buffer, sizeof(buffer));
}
int main() {
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/stress.cpp b/third_party/llvm-project/compiler-rt/test/tsan/stress.cpp
new file mode 100644
index 0000000..d1f0933
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/stress.cpp
@@ -0,0 +1,102 @@
+// This run stresses global reset happenning concurrently with everything else.
+// RUN: %clangxx_tsan -O1 %s -o %t && %env_tsan_opts=flush_memory_ms=1:flush_symbolizer_ms=1:memory_limit_mb=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NORACE
+// This run stresses race reporting happenning concurrently with everything else.
+// RUN: %clangxx_tsan -O1 %s -DRACE=1 -o %t && %env_tsan_opts=suppress_equal_stacks=0 %deflake %run %t | FileCheck %s --check-prefix=CHECK-RACE
+#include "test.h"
+#include <fcntl.h>
+#include <string.h>
+
+volatile long stop;
+long atomic, read_only, racy;
+int fds[2];
+
+__attribute__((noinline)) void *SecondaryThread(void *x) {
+ __atomic_fetch_add(&atomic, 1, __ATOMIC_ACQ_REL);
+ return NULL;
+}
+
+void *Thread(void *x) {
+ const int me = (long)x;
+ volatile long sink = 0;
+ int fd = -1;
+ while (!stop) {
+ // If me == 0, we do all of the following,
+ // otherwise only 1 type of action.
+ if (me == 0 || me == 1) {
+ // just read the stop variable
+ }
+ if (me == 0 || me == 2) {
+ __atomic_store_n(&atomic, sink, __ATOMIC_RELEASE);
+ }
+ if (me == 0 || me == 3) {
+ sink += __atomic_fetch_add(&atomic, 1, __ATOMIC_ACQ_REL);
+ }
+ if (me == 0 || me == 4) {
+ SecondaryThread(NULL);
+ }
+ if (me == 0 || me == 5) {
+ write(fds[1], fds, 1);
+ }
+ if (me == 0 || me == 6) {
+ char buf[2];
+ read(fds[0], &buf, sizeof(buf));
+ }
+ if (me == 0 || me == 7) {
+ pthread_t th;
+ pthread_create(&th, NULL, SecondaryThread, NULL);
+ pthread_join(th, NULL);
+ }
+ if (me == 0 || me == 8) {
+ long buf;
+ memcpy(&buf, &read_only, sizeof(buf));
+ sink += buf;
+ }
+ if (me == 0 || me == 9) {
+#if RACE
+ sink += racy++;
+#else
+ sink += racy;
+#endif
+ }
+ if (me == 0 || me == 10) {
+ fd = open("/dev/null", O_RDONLY);
+ if (fd != -1) {
+ close(fd);
+ fd = -1;
+ }
+ }
+ // If you add more actions, update kActions in main.
+ }
+ return NULL;
+}
+
+int main() {
+ ANNOTATE_BENIGN_RACE(stop);
+ if (pipe(fds))
+ exit((perror("pipe"), 1));
+ if (fcntl(fds[0], F_SETFL, O_NONBLOCK))
+ exit((perror("fcntl"), 1));
+ if (fcntl(fds[1], F_SETFL, O_NONBLOCK))
+ exit((perror("fcntl"), 1));
+ const int kActions = 11;
+#if RACE
+ const int kMultiplier = 1;
+#else
+ const int kMultiplier = 4;
+#endif
+ pthread_t t[kActions * kMultiplier];
+ for (int i = 0; i < kActions * kMultiplier; i++)
+ pthread_create(&t[i], NULL, Thread, (void *)(long)(i % kActions));
+ sleep(5);
+ stop = 1;
+ for (int i = 0; i < kActions * kMultiplier; i++)
+ pthread_join(t[i], NULL);
+ fprintf(stderr, "DONE\n");
+ return 0;
+}
+
+// CHECK-NORACE-NOT: ThreadSanitizer:
+// CHECK-NORACE: DONE
+// CHECK-NORACE-NOT: ThreadSanitizer:
+// CHECK-RACE: ThreadSanitizer: data race
+// CHECK-RACE: DONE
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/sunrpc.cc b/third_party/llvm-project/compiler-rt/test/tsan/sunrpc.cpp
similarity index 95%
rename from third_party/llvm-project/compiler-rt/test/tsan/sunrpc.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/sunrpc.cpp
index 5cfb534..8e32d6d 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/sunrpc.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/sunrpc.cpp
@@ -1,3 +1,5 @@
+// REQUIRES: sunrpc
+
// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
#include <pthread.h>
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/suppress_same_address.cc b/third_party/llvm-project/compiler-rt/test/tsan/suppress_same_address.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/suppress_same_address.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/suppress_same_address.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/suppress_same_stacks.cc b/third_party/llvm-project/compiler-rt/test/tsan/suppress_same_stacks.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/suppress_same_stacks.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/suppress_same_stacks.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/suppressions_global.cc b/third_party/llvm-project/compiler-rt/test/tsan/suppressions_global.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/suppressions_global.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/suppressions_global.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/suppressions_global.cc.supp b/third_party/llvm-project/compiler-rt/test/tsan/suppressions_global.cpp.supp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/suppressions_global.cc.supp
rename to third_party/llvm-project/compiler-rt/test/tsan/suppressions_global.cpp.supp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/suppressions_mutex.cc b/third_party/llvm-project/compiler-rt/test/tsan/suppressions_mutex.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/suppressions_mutex.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/suppressions_mutex.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/suppressions_mutex.cc.supp b/third_party/llvm-project/compiler-rt/test/tsan/suppressions_mutex.cpp.supp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/suppressions_mutex.cc.supp
rename to third_party/llvm-project/compiler-rt/test/tsan/suppressions_mutex.cpp.supp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/suppressions_race.cc b/third_party/llvm-project/compiler-rt/test/tsan/suppressions_race.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/suppressions_race.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/suppressions_race.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/suppressions_race.cc.supp b/third_party/llvm-project/compiler-rt/test/tsan/suppressions_race.cpp.supp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/suppressions_race.cc.supp
rename to third_party/llvm-project/compiler-rt/test/tsan/suppressions_race.cpp.supp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/suppressions_race2.cc b/third_party/llvm-project/compiler-rt/test/tsan/suppressions_race2.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/suppressions_race2.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/suppressions_race2.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/suppressions_race2.cc.supp b/third_party/llvm-project/compiler-rt/test/tsan/suppressions_race2.cpp.supp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/suppressions_race2.cc.supp
rename to third_party/llvm-project/compiler-rt/test/tsan/suppressions_race2.cpp.supp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/test.h b/third_party/llvm-project/compiler-rt/test/tsan/test.h
index 595590b..efd66cb 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/test.h
+++ b/third_party/llvm-project/compiler-rt/test/tsan/test.h
@@ -14,10 +14,23 @@
#include <mach/mach_time.h>
#endif
+#ifndef TSAN_VECTORIZE
+# define TSAN_VECTORIZE __SSE4_2__
+#endif
+
+#if TSAN_VECTORIZE
+# include <emmintrin.h>
+# include <smmintrin.h>
+#else
+struct __m128i {
+ unsigned long long x[2];
+};
+#endif
+
// TSan-invisible barrier.
// Tests use it to establish necessary execution order in a way that does not
// interfere with tsan (does not establish synchronization between threads).
-typedef unsigned long long invisible_barrier_t;
+typedef unsigned invisible_barrier_t;
#ifdef __cplusplus
extern "C" {
@@ -56,25 +69,42 @@
#endif
//The const kPCInc must be in sync with StackTrace::GetPreviousInstructionPc
-#if defined(__powerpc64__) || defined(__arm__) || defined(__aarch64__)
-// PCs are always 4 byte aligned.
-const int kPCInc = 4;
+#if defined(__s390__) || defined(__i386__) || defined(__x86_64__)
+const int kPCInc = 1;
#elif defined(__sparc__) || defined(__mips__)
const int kPCInc = 8;
#else
-const int kPCInc = 1;
+const int kPCInc = 4;
#endif
#ifdef __cplusplus
extern "C" {
#endif
+void AnnotateThreadName(const char *f, int l, const char *name);
+
void AnnotateRWLockCreate(const char *f, int l, void *m);
void AnnotateRWLockCreateStatic(const char *f, int l, void *m);
void AnnotateRWLockDestroy(const char *f, int l, void *m);
void AnnotateRWLockAcquired(const char *f, int l, void *m, long is_w);
void AnnotateRWLockReleased(const char *f, int l, void *m, long is_w);
+void AnnotateIgnoreReadsBegin(const char *f, int l);
+void AnnotateIgnoreReadsEnd(const char *f, int l);
+void AnnotateIgnoreWritesBegin(const char *f, int l);
+void AnnotateIgnoreWritesEnd(const char *f, int l);
+
+void AnnotateIgnoreSyncBegin(const char *f, int l);
+void AnnotateIgnoreSyncEnd(const char *f, int l);
+
+void AnnotateHappensBefore(const char *f, int l, void *addr);
+void AnnotateHappensAfter(const char *f, int l, void *addr);
+
+void AnnotateBenignRaceSized(const char *f, int l, const volatile void *mem,
+ unsigned int size, const char *desc);
+void WTFAnnotateBenignRaceSized(const char *f, int l, const volatile void *mem,
+ unsigned int size, const char *desc);
+
#ifdef __cplusplus
}
#endif
@@ -89,3 +119,17 @@
AnnotateRWLockAcquired(__FILE__, __LINE__, m, is_w)
#define ANNOTATE_RWLOCK_RELEASED(m, is_w) \
AnnotateRWLockReleased(__FILE__, __LINE__, m, is_w)
+#define ANNOTATE_HAPPENS_BEFORE(addr) \
+ AnnotateHappensBefore(__FILE__, __LINE__, (void *)(addr))
+#define ANNOTATE_HAPPENS_AFTER(addr) \
+ AnnotateHappensAfter(__FILE__, __LINE__, (void *)(addr))
+#define ANNOTATE_BENIGN_RACE(var) \
+ AnnotateBenignRaceSized(__FILE__, __LINE__, &(var), sizeof(var), #var)
+#define WTF_ANNOTATE_BENIGN_RACE(var) \
+ WTFAnnotateBenignRaceSized(__FILE__, __LINE__, &(var), sizeof(var), #var)
+
+#ifdef __APPLE__
+#define ASM_SYMBOL(symbol) "_" #symbol
+#else
+#define ASM_SYMBOL(symbol) #symbol
+#endif
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/thread_end_with_ignore.cc b/third_party/llvm-project/compiler-rt/test/tsan/thread_end_with_ignore.cpp
similarity index 78%
rename from third_party/llvm-project/compiler-rt/test/tsan/thread_end_with_ignore.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/thread_end_with_ignore.cpp
index 79bb08d..b33c9c9 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/thread_end_with_ignore.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/thread_end_with_ignore.cpp
@@ -1,8 +1,8 @@
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
-#include <pthread.h>
-#include <stdio.h>
-extern "C" void AnnotateIgnoreReadsBegin(const char *f, int l);
+// ReportIgnoresEnabled is disabled on Darwin, see comment in tsan_rtl_thread.cpp.
+// UNSUPPORTED: darwin
+#include "test.h"
void *Thread(void *x) {
AnnotateIgnoreReadsBegin("", 0);
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/thread_end_with_ignore2.cc b/third_party/llvm-project/compiler-rt/test/tsan/thread_end_with_ignore2.cpp
similarity index 70%
rename from third_party/llvm-project/compiler-rt/test/tsan/thread_end_with_ignore2.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/thread_end_with_ignore2.cpp
index 9387ea4..eee7a9e 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/thread_end_with_ignore2.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/thread_end_with_ignore2.cpp
@@ -1,5 +1,8 @@
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
-extern "C" void AnnotateIgnoreWritesBegin(const char *f, int l);
+
+// ReportIgnoresEnabled is disabled on Darwin, see comment in tsan_rtl_thread.cpp.
+// UNSUPPORTED: darwin
+#include "test.h"
int main() {
AnnotateIgnoreWritesBegin("", 0);
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/thread_end_with_ignore3.cc b/third_party/llvm-project/compiler-rt/test/tsan/thread_end_with_ignore3.cpp
similarity index 69%
rename from third_party/llvm-project/compiler-rt/test/tsan/thread_end_with_ignore3.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/thread_end_with_ignore3.cpp
index 55688b2..372ba25 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/thread_end_with_ignore3.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/thread_end_with_ignore3.cpp
@@ -1,6 +1,8 @@
// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
-extern "C" void AnnotateIgnoreReadsBegin(const char *f, int l);
-extern "C" void AnnotateIgnoreReadsEnd(const char *f, int l);
+
+// ReportIgnoresEnabled is disabled on Darwin, see comment in tsan_rtl_thread.cpp.
+// UNSUPPORTED: darwin
+#include "test.h"
int main() {
AnnotateIgnoreReadsBegin("", 0);
@@ -15,8 +17,7 @@
// CHECK: ThreadSanitizer: main thread finished with ignores enabled
// CHECK: Ignore was enabled at:
// CHECK: #0 AnnotateIgnoreReadsBegin
-// CHECK: #1 main {{.*}}thread_end_with_ignore3.cc:10
+// CHECK: #1 main {{.*}}thread_end_with_ignore3.cpp:12
// CHECK: Ignore was enabled at:
// CHECK: #0 AnnotateIgnoreReadsBegin
-// CHECK: #1 main {{.*}}thread_end_with_ignore3.cc:11
-
+// CHECK: #1 main {{.*}}thread_end_with_ignore3.cpp:13
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/thread_exit.c b/third_party/llvm-project/compiler-rt/test/tsan/thread_exit.c
new file mode 100644
index 0000000..9c97672
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/thread_exit.c
@@ -0,0 +1,29 @@
+// RUN: %clang_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
+
+// Crashes on powerpc64be
+// UNSUPPORTED: target=powerpc64{{.*}}
+
+#include "test.h"
+
+int var;
+
+void *Thread(void *x) {
+ pthread_exit(&var);
+ return 0;
+}
+
+int main() {
+ pthread_t t;
+ pthread_create(&t, 0, Thread, 0);
+ void *retval = 0;
+ pthread_join(t, &retval);
+ if (retval != &var) {
+ fprintf(stderr, "Unexpected return value\n");
+ exit(1);
+ }
+ fprintf(stderr, "PASS\n");
+ return 0;
+}
+
+// CHECK-NOT: WARNING: ThreadSanitizer:
+// CHECK: PASS
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/thread_name.cc b/third_party/llvm-project/compiler-rt/test/tsan/thread_name.cpp
similarity index 93%
rename from third_party/llvm-project/compiler-rt/test/tsan/thread_name.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/thread_name.cpp
index 1fa0555..bc65421 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/thread_name.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/thread_name.cpp
@@ -15,8 +15,6 @@
#define USE_PTHREAD_SETNAME_NP 0
#endif
-extern "C" void AnnotateThreadName(const char *f, int l, const char *name);
-
int Global;
void *Thread1(void *x) {
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/thread_name2.cc b/third_party/llvm-project/compiler-rt/test/tsan/thread_name2.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/thread_name2.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/thread_name2.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/tls_race.cc b/third_party/llvm-project/compiler-rt/test/tsan/tls_race.cpp
similarity index 75%
rename from third_party/llvm-project/compiler-rt/test/tsan/tls_race.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/tls_race.cpp
index dd37ff0..5f5b6aa 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/tls_race.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/tls_race.cpp
@@ -1,4 +1,6 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK
+// RUN: %clangxx_tsan %darwin_min_target_with_tls_support -O1 %s -o %t && \
+// RUN: %deflake %run %t | \
+// RUN: FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK
#include "test.h"
void *Thread(void *a) {
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/tls_race2.cc b/third_party/llvm-project/compiler-rt/test/tsan/tls_race2.cpp
similarity index 79%
rename from third_party/llvm-project/compiler-rt/test/tsan/tls_race2.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/tls_race2.cpp
index 5968e66..0e00831 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/tls_race2.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/tls_race2.cpp
@@ -1,4 +1,6 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK
+// RUN: %clangxx_tsan %darwin_min_target_with_tls_support -O1 %s -o %t && \
+// RUN: %deflake %run %t | \
+// RUN: FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK
#include "test.h"
void *Thread2(void *a) {
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/tsan-vs-gvn.cc b/third_party/llvm-project/compiler-rt/test/tsan/tsan-vs-gvn.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/tsan-vs-gvn.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/tsan-vs-gvn.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/unaligned_norace.cc b/third_party/llvm-project/compiler-rt/test/tsan/unaligned_norace.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/unaligned_norace.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/unaligned_norace.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/unaligned_race.cc b/third_party/llvm-project/compiler-rt/test/tsan/unaligned_race.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/unaligned_race.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/unaligned_race.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/vector_race.cpp b/third_party/llvm-project/compiler-rt/test/tsan/vector_race.cpp
new file mode 100644
index 0000000..33bddd8
--- /dev/null
+++ b/third_party/llvm-project/compiler-rt/test/tsan/vector_race.cpp
@@ -0,0 +1,92 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t 2>&1 | FileCheck %s
+#include "test.h"
+
+__m128i data[20];
+
+__m128i load(__m128i *v) {
+#if TSAN_VECTORIZE
+ return _mm_load_si128(v);
+#else
+ return *v;
+#endif
+}
+
+void store(__m128i *v, __m128i a) {
+#if TSAN_VECTORIZE
+ _mm_store_si128(v, a);
+#else
+ *v = a;
+#endif
+}
+
+void *Thread(void *arg);
+
+int main() {
+ barrier_init(&barrier, 2);
+ pthread_t th;
+ pthread_create(&th, NULL, Thread, NULL);
+ barrier_wait(&barrier);
+
+ print_address("addr0:", 2, &data[0], &data[0]);
+ auto v0 = load(&data[1]);
+ store(&data[0], v0);
+ // CHECK: addr0:[[ADDR0_0:0x[0-9,a-f]+]] [[ADDR0_1:0x[0-9,a-f]+]]
+ // CHECK: WARNING: ThreadSanitizer: data race
+ // CHECK: Write of size 8 at [[ADDR0_0]] by main thread:
+ // CHECK: Previous read of size 8 at [[ADDR0_1]] by thread T1:
+
+ print_address("addr1:", 2, (char *)&data[2] + 8, (char *)&data[2] + 8);
+ ((volatile unsigned long long *)(&data[2]))[1] = 42;
+ // CHECK: addr1:[[ADDR1_0:0x[0-9,a-f]+]] [[ADDR1_1:0x[0-9,a-f]+]]
+ // CHECK: WARNING: ThreadSanitizer: data race
+ // CHECK: Write of size 8 at [[ADDR1_0]] by main thread:
+ // CHECK: Previous read of size 8 at [[ADDR1_1]] by thread T1:
+
+ print_address("addr2:", 2, (char *)&data[4] + 15, (char *)&data[4] + 8);
+ ((volatile char *)(&data[4]))[15] = 42;
+ // CHECK: addr2:[[ADDR2_0:0x[0-9,a-f]+]] [[ADDR2_1:0x[0-9,a-f]+]]
+ // CHECK: WARNING: ThreadSanitizer: data race
+ // CHECK: Write of size 1 at [[ADDR2_0]] by main thread:
+ // CHECK: Previous read of size 8 at [[ADDR2_1]] by thread T1:
+
+ store(&data[12], v0);
+ ((volatile unsigned long long *)(&data[14]))[1] = 42;
+ ((volatile char *)(&data[16]))[15] = 42;
+ barrier_wait(&barrier);
+ pthread_join(th, NULL);
+ return 0;
+}
+
+void *Thread(void *arg) {
+ // Use only even indexes so that compiler does not insert memcpy.
+ auto v0 = load(&data[0]);
+ auto v1 = load(&data[2]);
+ auto v2 = load(&data[4]);
+ store(&data[6], v0);
+ store(&data[8], v1);
+ store(&data[10], v2);
+ barrier_wait(&barrier);
+ barrier_wait(&barrier);
+
+ print_address("addr3:", 2, &data[12], &data[12]);
+ store(&data[12], v0);
+ // CHECK: addr3:[[ADDR3_0:0x[0-9,a-f]+]] [[ADDR3_1:0x[0-9,a-f]+]]
+ // CHECK: WARNING: ThreadSanitizer: data race
+ // CHECK: Write of size 8 at [[ADDR3_0]] by thread T1:
+ // CHECK: Previous write of size 8 at [[ADDR3_1]] by main thread:
+
+ print_address("addr4:", 2, (char *)&data[14] + 8, (char *)&data[14] + 8);
+ store(&data[14], v0);
+ // CHECK: addr4:[[ADDR4_0:0x[0-9,a-f]+]] [[ADDR4_1:0x[0-9,a-f]+]]
+ // CHECK: WARNING: ThreadSanitizer: data race
+ // CHECK: Write of size 8 at [[ADDR4_0]] by thread T1:
+ // CHECK: Previous write of size 8 at [[ADDR4_1]] by main thread:
+
+ print_address("addr5:", 2, (char *)&data[16] + 8, (char *)&data[16] + 15);
+ store(&data[16], v0);
+ // CHECK: addr5:[[ADDR5_0:0x[0-9,a-f]+]] [[ADDR5_1:0x[0-9,a-f]+]]
+ // CHECK: WARNING: ThreadSanitizer: data race
+ // CHECK: Write of size 8 at [[ADDR5_0]] by thread T1:
+ // CHECK: Previous write of size 1 at [[ADDR5_1]] by main thread:
+ return NULL;
+}
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/vfork.cc b/third_party/llvm-project/compiler-rt/test/tsan/vfork.cpp
similarity index 97%
rename from third_party/llvm-project/compiler-rt/test/tsan/vfork.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/vfork.cpp
index 2d669b3..1e34a56 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/vfork.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/vfork.cpp
@@ -1,4 +1,6 @@
// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
+// UNSUPPORTED: ios
+
#include <pthread.h>
#include <stdio.h>
#include <stdlib.h>
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/virtual_inheritance_compile_bug.cc b/third_party/llvm-project/compiler-rt/test/tsan/virtual_inheritance_compile_bug.cpp
similarity index 65%
rename from third_party/llvm-project/compiler-rt/test/tsan/virtual_inheritance_compile_bug.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/virtual_inheritance_compile_bug.cpp
index 3b1e08b..69fda3a 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/virtual_inheritance_compile_bug.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/virtual_inheritance_compile_bug.cpp
@@ -3,10 +3,16 @@
// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
#include <stdio.h>
-struct AAA { virtual long aaa () { return 0; } }; // NOLINT
-struct BBB: virtual AAA { unsigned long bbb; }; // NOLINT
+struct AAA {
+ virtual long aaa() { return 0; }
+};
+struct BBB : virtual AAA {
+ unsigned long bbb;
+};
struct CCC: virtual AAA { };
-struct DDD: CCC, BBB { DDD(); }; // NOLINT
+struct DDD : CCC, BBB {
+ DDD();
+};
DDD::DDD() { }
int main() {
DDD d;
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/vptr_benign_race.cc b/third_party/llvm-project/compiler-rt/test/tsan/vptr_benign_race.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/vptr_benign_race.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/vptr_benign_race.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/vptr_harmful_race.cc b/third_party/llvm-project/compiler-rt/test/tsan/vptr_harmful_race.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/vptr_harmful_race.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/vptr_harmful_race.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/vptr_harmful_race2.cc b/third_party/llvm-project/compiler-rt/test/tsan/vptr_harmful_race2.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/vptr_harmful_race2.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/vptr_harmful_race2.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/vptr_harmful_race3.cc b/third_party/llvm-project/compiler-rt/test/tsan/vptr_harmful_race3.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/vptr_harmful_race3.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/vptr_harmful_race3.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/vptr_harmful_race4.cc b/third_party/llvm-project/compiler-rt/test/tsan/vptr_harmful_race4.cpp
similarity index 100%
rename from third_party/llvm-project/compiler-rt/test/tsan/vptr_harmful_race4.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/vptr_harmful_race4.cpp
diff --git a/third_party/llvm-project/compiler-rt/test/tsan/write_in_reader_lock.cc b/third_party/llvm-project/compiler-rt/test/tsan/write_in_reader_lock.cpp
similarity index 86%
rename from third_party/llvm-project/compiler-rt/test/tsan/write_in_reader_lock.cc
rename to third_party/llvm-project/compiler-rt/test/tsan/write_in_reader_lock.cpp
index 3f7cb35..56aa1ab 100644
--- a/third_party/llvm-project/compiler-rt/test/tsan/write_in_reader_lock.cc
+++ b/third_party/llvm-project/compiler-rt/test/tsan/write_in_reader_lock.cpp
@@ -31,6 +31,6 @@
// CHECK: WARNING: ThreadSanitizer: data race
// CHECK: Write of size 4 at {{.*}} by thread T1{{.*}}:
-// CHECK: #0 Thread1(void*) {{.*}}write_in_reader_lock.cc:12
+// CHECK: #0 Thread1(void*) {{.*}}write_in_reader_lock.cpp:12
// CHECK: Previous read of size 4 at {{.*}} by main thread{{.*}}:
-// CHECK: #0 main {{.*}}write_in_reader_lock.cc:23
+// CHECK: #0 main {{.*}}write_in_reader_lock.cpp:23