Update compiler-rt for rebase to r212749.

Includes a cherry-pick of:
r213309 - fixes umodsi3

Change-Id: Ic7367e3586b6af7ef74bee6a8cf437d5f28d975a
diff --git a/test/asan/CMakeLists.txt b/test/asan/CMakeLists.txt
index 2488ef1..cca7ccb 100644
--- a/test/asan/CMakeLists.txt
+++ b/test/asan/CMakeLists.txt
@@ -6,10 +6,12 @@
   # This is only true if we are cross-compiling.
   # Build all tests with host compiler and use host tools.
   set(ASAN_TEST_TARGET_CC ${CMAKE_C_COMPILER})
+  set(ASAN_TEST_TARGET_CFLAGS ${COMPILER_RT_TEST_COMPILER_CFLAGS})
   get_filename_component(ASAN_TEST_LLVM_TOOLS_DIR ${CMAKE_C_COMPILER} PATH)
   set(ASAN_TEST_CONFIG_SUFFIX "-arm-android")
   set(ASAN_TEST_BITS "32")
-  get_target_flags_for_arch(arm_android ASAN_TEST_TARGET_CFLAGS)
+  set(ASAN_TEST_DYNAMIC True)
+  set(ASAN_TEST_TARGET_ARCH "arm-android")
   configure_lit_site_cfg(
     ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
     ${CMAKE_CURRENT_BINARY_DIR}/ARMAndroidConfig/lit.site.cfg
@@ -32,6 +34,21 @@
   list(APPEND ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/ARMLinuxConfig)
 endif()
 
+if(CAN_TARGET_aarch64)
+  # This is only true if we are cross-compiling.
+  # Build all tests with host compiler and use host tools.
+  set(ASAN_TEST_TARGET_CC ${COMPILER_RT_TEST_COMPILER})
+  set(ASAN_TEST_TARGET_CFLAGS ${COMPILER_RT_TEST_COMPILER_CFLAGS})
+  set(ASAN_TEST_CONFIG_SUFFIX "-aarch64-linux")
+  set(ASAN_TEST_BITS "64")
+  set(ASAN_TEST_DYNAMIC False)
+  configure_lit_site_cfg(
+    ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
+    ${CMAKE_CURRENT_BINARY_DIR}/AArch64LinuxConfig/lit.site.cfg
+    )
+  list(APPEND ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/AArch64LinuxConfig)
+endif()
+
 if(CAN_TARGET_x86_64 OR CAN_TARGET_powerpc64)
   set(ASAN_TEST_CONFIG_SUFFIX "64")
   set(ASAN_TEST_BITS "64")
@@ -73,6 +90,26 @@
   endif()
 endif()
 
+if(CAN_TARGET_mips)
+  set(ASAN_TEST_CONFIG_SUFFIX "32")
+  set(ASAN_TEST_BITS "32")
+  set(ASAN_TEST_TARGET_CFLAGS ${TARGET_32_BIT_CFLAGS})
+  set(ASAN_TEST_DYNAMIC False)
+  configure_lit_site_cfg(
+    ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
+    ${CMAKE_CURRENT_BINARY_DIR}/32bitConfig/lit.site.cfg
+    )
+  list(APPEND ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/32bitConfig)
+  if(COMPILER_RT_BUILD_SHARED_ASAN)
+    set(ASAN_TEST_CONFIG_SUFFIX "32-Dynamic")
+    set(ASAN_TEST_DYNAMIC True)
+    configure_lit_site_cfg(
+      ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
+      ${CMAKE_CURRENT_BINARY_DIR}/32bitConfig-dynamic/lit.site.cfg)
+    list(APPEND ASAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/32bitConfig-dynamic)
+  endif()
+endif()
+
 if(COMPILER_RT_INCLUDE_TESTS)
   configure_lit_site_cfg(
     ${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.in
@@ -80,7 +117,9 @@
 endif()
 
 set(ASAN_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS})
-if(NOT COMPILER_RT_STANDALONE_BUILD)
+if(COMPILER_RT_STANDALONE_BUILD)
+  list(APPEND ASAN_TEST_DEPS ${LLVM_TOOLS_BINARY_DIR}/FileCheck)
+else()
   list(APPEND ASAN_TEST_DEPS asan)
 endif()
 
diff --git a/test/asan/TestCases/Android/coverage-android.cc b/test/asan/TestCases/Android/coverage-android.cc
new file mode 100644
index 0000000..071a2e3
--- /dev/null
+++ b/test/asan/TestCases/Android/coverage-android.cc
@@ -0,0 +1,67 @@
+// Test for direct coverage writing with dlopen.
+
+// Test normal exit.
+// RUN: %clangxx_asan -mllvm -asan-coverage=1 -DSHARED %s -shared -o %T/libcoverage_android_test_1.so -fPIC
+// RUN: %clangxx_asan -mllvm -asan-coverage=1 -DSO_DIR=\"%device\" %s -o %t
+
+// RUN: adb shell rm -rf %device/coverage-android
+// RUN: rm -rf %T/coverage-android
+
+// RUN: adb shell mkdir -p %device/coverage-android/direct
+// RUN: mkdir -p %T/coverage-android/direct
+// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=1:coverage_dir=%device/coverage-android/direct:verbosity=1 %run %t
+// RUN: adb pull %device/coverage-android/direct %T/coverage-android/direct
+// RUN: ls; pwd
+// RUN: cd %T/coverage-android/direct
+// RUN: %sancov rawunpack *.sancov.raw
+// RUN: %sancov print *.sancov |& FileCheck %s
+
+
+// Test sudden death.
+// RUN: %clangxx_asan -mllvm -asan-coverage=1 -DSHARED -DKILL %s -shared -o %T/libcoverage_android_test_1.so -fPIC
+// RUN: %clangxx_asan -mllvm -asan-coverage=1 -DSO_DIR=\"%device\" %s -o %t
+
+// RUN: adb shell rm -rf %device/coverage-android-kill
+// RUN: rm -rf %T/coverage-android-kill
+
+// RUN: adb shell mkdir -p %device/coverage-android-kill/direct
+// RUN: mkdir -p %T/coverage-android-kill/direct
+// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=1:coverage_dir=%device/coverage-android-kill/direct:verbosity=1 not %run %t
+// RUN: adb pull %device/coverage-android-kill/direct %T/coverage-android-kill/direct
+// RUN: ls; pwd
+// RUN: cd %T/coverage-android-kill/direct
+// RUN: %sancov rawunpack *.sancov.raw
+// RUN: %sancov print *.sancov |& FileCheck %s
+
+#include <assert.h>
+#include <dlfcn.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <sys/types.h>
+#include <signal.h>
+
+#ifdef SHARED
+extern "C" {
+void bar() {
+  printf("bar\n");
+#ifdef KILL
+  kill(getpid(), SIGKILL);
+#endif
+}
+}
+#else
+
+int main(int argc, char **argv) {
+  fprintf(stderr, "PID: %d\n", getpid());
+  void *handle1 =
+      dlopen(SO_DIR "/libcoverage_android_test_1.so", RTLD_LAZY);
+  assert(handle1);
+  void (*bar1)() = (void (*)())dlsym(handle1, "bar");
+  assert(bar1);
+  bar1();
+
+  return 0;
+}
+#endif
+
+// CHECK: 2 PCs total
diff --git a/test/asan/TestCases/Android/lit.local.cfg b/test/asan/TestCases/Android/lit.local.cfg
new file mode 100644
index 0000000..42513dd
--- /dev/null
+++ b/test/asan/TestCases/Android/lit.local.cfg
@@ -0,0 +1,11 @@
+def getRoot(config):
+  if not config.parent:
+    return config
+  return getRoot(config.parent)
+
+root = getRoot(config)
+
+if root.android != "TRUE":
+  config.unsupported = True
+
+config.substitutions.append( ("%device", "/data/local/tmp/Output") )
diff --git a/test/asan/TestCases/Darwin/interface_symbols_darwin.c b/test/asan/TestCases/Darwin/interface_symbols_darwin.c
index ea3e796..e513954 100644
--- a/test/asan/TestCases/Darwin/interface_symbols_darwin.c
+++ b/test/asan/TestCases/Darwin/interface_symbols_darwin.c
@@ -16,6 +16,7 @@
 // RUN:   | grep -v "__asan_on_error" > %t.symbols
 
 // RUN: cat %p/../../../../lib/asan/asan_interface_internal.h \
+// RUN:     %p/../../../../lib/asan/asan_init_version.h \
 // RUN:    | sed "s/\/\/.*//" | sed "s/typedef.*//" \
 // RUN:    | grep -v "OPTIONAL" \
 // RUN:    | grep "__asan_.*(" | sed "s/.* __asan_/__asan_/;s/(.*//" \
diff --git a/test/asan/TestCases/Linux/asan_dlopen_test.cc b/test/asan/TestCases/Linux/asan_dlopen_test.cc
index 663675c..f1e31b0 100644
--- a/test/asan/TestCases/Linux/asan_dlopen_test.cc
+++ b/test/asan/TestCases/Linux/asan_dlopen_test.cc
@@ -3,6 +3,7 @@
 // RUN: %clangxx %s -DRT=\"%shared_libasan\" -o %t -ldl
 // RUN: not %run %t 2>&1 | FileCheck %s
 // REQUIRES: asan-dynamic-runtime
+// XFAIL: android
 
 #include <dlfcn.h>
 
diff --git a/test/asan/TestCases/Linux/asan_preload_test-1.cc b/test/asan/TestCases/Linux/asan_preload_test-1.cc
index bc2da3e..ba96872 100644
--- a/test/asan/TestCases/Linux/asan_preload_test-1.cc
+++ b/test/asan/TestCases/Linux/asan_preload_test-1.cc
@@ -8,6 +8,7 @@
 // RUN: LD_PRELOAD=%shared_libasan not %run %t 2>&1 | FileCheck %s
 
 // REQUIRES: asan-dynamic-runtime
+// XFAIL: android
 
 #if BUILD_SO
 char dummy;
diff --git a/test/asan/TestCases/Linux/asan_preload_test-2.cc b/test/asan/TestCases/Linux/asan_preload_test-2.cc
index c3d7042..0741958 100644
--- a/test/asan/TestCases/Linux/asan_preload_test-2.cc
+++ b/test/asan/TestCases/Linux/asan_preload_test-2.cc
@@ -4,6 +4,7 @@
 // RUN: LD_PRELOAD=%shared_libasan not %run %t 2>&1 | FileCheck %s
 
 // REQUIRES: asan-dynamic-runtime
+// XFAIL: android
 
 #include <stdlib.h>
 
diff --git a/test/asan/TestCases/Linux/asan_rt_confict_test-1.cc b/test/asan/TestCases/Linux/asan_rt_confict_test-1.cc
index 5687f17..30f1c17 100644
--- a/test/asan/TestCases/Linux/asan_rt_confict_test-1.cc
+++ b/test/asan/TestCases/Linux/asan_rt_confict_test-1.cc
@@ -5,6 +5,7 @@
 // RUN: LD_PRELOAD=%shared_libasan not %run %t 2>&1 | FileCheck %s
 
 // REQUIRES: asan-dynamic-runtime
+// XFAIL: android
 
 #include <stdlib.h>
 int main(int argc, char **argv) { return 0; }
diff --git a/test/asan/TestCases/Linux/asan_rt_confict_test-2.cc b/test/asan/TestCases/Linux/asan_rt_confict_test-2.cc
index 9ae8468..4c935e2 100644
--- a/test/asan/TestCases/Linux/asan_rt_confict_test-2.cc
+++ b/test/asan/TestCases/Linux/asan_rt_confict_test-2.cc
@@ -6,6 +6,7 @@
 // RUN: not %run %t 2>&1 | FileCheck %s
 
 // REQUIRES: asan-dynamic-runtime
+// XFAIL: android
 
 #if BUILD_SO
 char dummy;
diff --git a/test/asan/TestCases/Linux/clone_test.cc b/test/asan/TestCases/Linux/clone_test.cc
index bc6ef08..e9c1f16 100644
--- a/test/asan/TestCases/Linux/clone_test.cc
+++ b/test/asan/TestCases/Linux/clone_test.cc
@@ -5,6 +5,7 @@
 // RUN: %clangxx_asan -O1 %s -o %t && %run %t | FileCheck %s
 // RUN: %clangxx_asan -O2 %s -o %t && %run %t | FileCheck %s
 // RUN: %clangxx_asan -O3 %s -o %t && %run %t | FileCheck %s
+// XFAIL: arm-linux-gnueabi
 
 #include <stdio.h>
 #include <sched.h>
diff --git a/test/asan/TestCases/Linux/coverage-direct.cc b/test/asan/TestCases/Linux/coverage-direct.cc
index f6e7801..7fe2514 100644
--- a/test/asan/TestCases/Linux/coverage-direct.cc
+++ b/test/asan/TestCases/Linux/coverage-direct.cc
@@ -4,13 +4,13 @@
 
 // RUN: rm -rf %T/coverage-direct
 
-// RUN: mkdir -p %T/coverage-direct/normal && cd %T/coverage-direct/normal
-// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=0:verbosity=1 %run %t
-// RUN: %sancov print *.sancov >out.txt
-// RUN: cd ../..
+// RUN: mkdir -p %T/coverage-direct/normal
+// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=0:coverage_dir=%T/coverage-direct/normal:verbosity=1 %run %t
+// RUN: %sancov print %T/coverage-direct/normal/*.sancov >%T/coverage-direct/normal/out.txt
 
-// RUN: mkdir -p %T/coverage-direct/direct && cd %T/coverage-direct/direct
-// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=1:verbosity=1 %run %t
+// RUN: mkdir -p %T/coverage-direct/direct
+// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=1:coverage_dir=%T/coverage-direct/direct:verbosity=1 %run %t
+// RUN: cd %T/coverage-direct/direct
 // RUN: %sancov rawunpack *.sancov.raw
 // RUN: %sancov print *.sancov >out.txt
 // RUN: cd ../..
diff --git a/test/asan/TestCases/Linux/coverage-disabled.cc b/test/asan/TestCases/Linux/coverage-disabled.cc
new file mode 100644
index 0000000..315c312
--- /dev/null
+++ b/test/asan/TestCases/Linux/coverage-disabled.cc
@@ -0,0 +1,18 @@
+// Test that no data is collected without a runtime flag.
+//
+// RUN: %clangxx_asan -mllvm -asan-coverage=1 %s -o %t
+//
+// RUN: rm -rf %T/coverage-disabled
+//
+// RUN: mkdir -p %T/coverage-disabled/normal
+// RUN: ASAN_OPTIONS=coverage_direct=0:coverage_dir=%T/coverage-disabled/normal:verbosity=1 %run %t
+// RUN: not %sancov print %T/coverage-disabled/normal/*.sancov 2>&1
+//
+// RUN: mkdir -p %T/coverage-disabled/direct
+// RUN: ASAN_OPTIONS=coverage_direct=1:coverage_dir=%T/coverage-disabled/direct:verbosity=1 %run %t
+// RUN: cd %T/coverage-disabled/direct
+// RUN: not %sancov rawunpack *.sancov
+
+int main(int argc, char **argv) {
+  return 0;
+}
diff --git a/test/asan/TestCases/Linux/coverage-fork-direct.cc b/test/asan/TestCases/Linux/coverage-fork-direct.cc
new file mode 100644
index 0000000..7489b72
--- /dev/null
+++ b/test/asan/TestCases/Linux/coverage-fork-direct.cc
@@ -0,0 +1,38 @@
+// RUN: %clangxx_asan -mllvm -asan-coverage=1 %s -o %t
+// RUN: rm -rf %T/coverage-fork-direct
+// RUN: mkdir -p %T/coverage-fork-direct && cd %T/coverage-fork-direct
+// RUN: (ASAN_OPTIONS=coverage=1:coverage_direct=1:verbosity=1 %run %t; \
+// RUN:  %sancov rawunpack *.sancov.raw; %sancov print *.sancov) 2>&1
+//
+// XFAIL: android
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+__attribute__((noinline))
+void foo() { printf("foo\n"); }
+
+__attribute__((noinline))
+void bar() { printf("bar\n"); }
+
+__attribute__((noinline))
+void baz() { printf("baz\n"); }
+
+int main(int argc, char **argv) {
+  pid_t child_pid = fork();
+  if (child_pid == 0) {
+    fprintf(stderr, "Child PID: %d\n", getpid());
+    baz();
+  } else {
+    fprintf(stderr, "Parent PID: %d\n", getpid());
+    foo();
+    bar();
+  }
+  return 0;
+}
+
+// CHECK-DAG: Child PID: [[ChildPID:[0-9]+]]
+// CHECK-DAG: Parent PID: [[ParentPID:[0-9]+]]
+// CHECK-DAG: read 3 PCs from {{.*}}.[[ParentPID]].sancov
+// CHECK-DAG: read 1 PCs from {{.*}}.[[ChildPID]].sancov
diff --git a/test/asan/TestCases/Linux/coverage-fork.cc b/test/asan/TestCases/Linux/coverage-fork.cc
new file mode 100644
index 0000000..28b2a49
--- /dev/null
+++ b/test/asan/TestCases/Linux/coverage-fork.cc
@@ -0,0 +1,38 @@
+// RUN: %clangxx_asan -mllvm -asan-coverage=1 %s -o %t
+// RUN: export ASAN_OPTIONS=coverage=1:coverage_direct=0:verbosity=1
+// RUN: rm -rf %T/coverage-fork
+// RUN: mkdir -p %T/coverage-fork && cd %T/coverage-fork
+// RUN: %run %t 2>&1 | FileCheck %s
+//
+// XFAIL: android
+
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+__attribute__((noinline))
+void foo() { printf("foo\n"); }
+
+__attribute__((noinline))
+void bar() { printf("bar\n"); }
+
+__attribute__((noinline))
+void baz() { printf("baz\n"); }
+
+int main(int argc, char **argv) {
+  pid_t child_pid = fork();
+  if (child_pid == 0) {
+    fprintf(stderr, "Child PID: %d\n", getpid());
+    baz();
+  } else {
+    fprintf(stderr, "Parent PID: %d\n", getpid());
+    foo();
+    bar();
+  }
+  return 0;
+}
+
+// CHECK-DAG: Child PID: [[ChildPID:[0-9]+]]
+// CHECK-DAG: [[ChildPID]].sancov: 1 PCs written
+// CHECK-DAG: Parent PID: [[ParentPID:[0-9]+]]
+// CHECK-DAG: [[ParentPID]].sancov: 3 PCs written
diff --git a/test/asan/TestCases/Linux/coverage-maybe-open-file.cc b/test/asan/TestCases/Linux/coverage-maybe-open-file.cc
index 4665123..1cd2253 100644
--- a/test/asan/TestCases/Linux/coverage-maybe-open-file.cc
+++ b/test/asan/TestCases/Linux/coverage-maybe-open-file.cc
@@ -1,3 +1,6 @@
+// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316
+// XFAIL: android
+//
 // RUN: %clangxx_asan -mllvm -asan-coverage=1 %s -o %t
 // RUN: rm -rf %T/coverage-maybe-open-file
 // RUN: mkdir -p %T/coverage-maybe-open-file && cd %T/coverage-maybe-open-file
diff --git a/test/asan/TestCases/Linux/glob.cc b/test/asan/TestCases/Linux/glob.cc
index c1dbeda..e0eeb33 100644
--- a/test/asan/TestCases/Linux/glob.cc
+++ b/test/asan/TestCases/Linux/glob.cc
@@ -1,5 +1,9 @@
+// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316
+// XFAIL: android
+//
 // RUN: %clangxx_asan -O0 %s -o %t && %run %t %p 2>&1 | FileCheck %s
 // RUN: %clangxx_asan -O3 %s -o %t && %run %t %p 2>&1 | FileCheck %s
+// XFAIL: arm-linux-gnueabi
 
 #include <assert.h>
 #include <glob.h>
diff --git a/test/asan/TestCases/Linux/heavy_uar_test.cc b/test/asan/TestCases/Linux/heavy_uar_test.cc
index cedd69d..bfea520 100644
--- a/test/asan/TestCases/Linux/heavy_uar_test.cc
+++ b/test/asan/TestCases/Linux/heavy_uar_test.cc
@@ -3,6 +3,7 @@
 // RUN:   not %run %t 2>&1 | FileCheck %s
 // RUN: %clangxx_asan -O2 %s -o %t && \
 // RUN:   not %run %t 2>&1 | FileCheck %s
+// XFAIL: arm-linux-gnueabi
 
 // FIXME: Fix this test under GCC.
 // REQUIRES: Clang
diff --git a/test/asan/TestCases/Linux/interception_readdir_r_test.cc b/test/asan/TestCases/Linux/interception_readdir_r_test.cc
index 347320a..93b553c 100644
--- a/test/asan/TestCases/Linux/interception_readdir_r_test.cc
+++ b/test/asan/TestCases/Linux/interception_readdir_r_test.cc
@@ -1,3 +1,6 @@
+// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316
+// XFAIL: android
+//
 // RUN: %clangxx_asan -O0 %s -DTEMP_DIR='"'"%T"'"' -o %t && %run %t 2>&1 | FileCheck %s
 // RUN: %clangxx_asan -O1 %s -DTEMP_DIR='"'"%T"'"' -o %t && %run %t 2>&1 | FileCheck %s
 // RUN: %clangxx_asan -O2 %s -DTEMP_DIR='"'"%T"'"' -o %t && %run %t 2>&1 | FileCheck %s
diff --git a/test/asan/TestCases/Linux/interface_symbols_linux.c b/test/asan/TestCases/Linux/interface_symbols_linux.c
index d496d95..72416f1 100644
--- a/test/asan/TestCases/Linux/interface_symbols_linux.c
+++ b/test/asan/TestCases/Linux/interface_symbols_linux.c
@@ -9,6 +9,7 @@
 // RUN:    | grep -v "__asan_stack_" \
 // RUN:    | grep -v "__asan_on_error" > %t.symbols
 // RUN: cat %p/../../../../lib/asan/asan_interface_internal.h \
+// RUN:     %p/../../../../lib/asan/asan_init_version.h \
 // RUN:    | sed "s/\/\/.*//" | sed "s/typedef.*//" \
 // RUN:    | grep -v "OPTIONAL" \
 // RUN:    | grep "__asan_.*(" | sed "s/.* __asan_/__asan_/;s/(.*//" \
diff --git a/test/asan/TestCases/Linux/kernel-area.cc b/test/asan/TestCases/Linux/kernel-area.cc
index 4b330f2..8dd509f 100644
--- a/test/asan/TestCases/Linux/kernel-area.cc
+++ b/test/asan/TestCases/Linux/kernel-area.cc
@@ -1,3 +1,6 @@
+// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316
+// XFAIL: android
+//
 // Test that kernel area is not sanitized on 32-bit machines.
 //
 // RUN: %clangxx_asan %s -o %t
diff --git a/test/asan/TestCases/Linux/malloc_delete_mismatch.cc b/test/asan/TestCases/Linux/malloc_delete_mismatch.cc
index c9f61d8..085eb15 100644
--- a/test/asan/TestCases/Linux/malloc_delete_mismatch.cc
+++ b/test/asan/TestCases/Linux/malloc_delete_mismatch.cc
@@ -12,6 +12,7 @@
 // Also works if no malloc context is available.
 // RUN: ASAN_OPTIONS=alloc_dealloc_mismatch=1:malloc_context_size=0:fast_unwind_on_malloc=0 not %run %t 2>&1 | FileCheck %s
 // RUN: ASAN_OPTIONS=alloc_dealloc_mismatch=1:malloc_context_size=0:fast_unwind_on_malloc=1 not %run %t 2>&1 | FileCheck %s
+// XFAIL: arm-linux-gnueabi
 #include <stdlib.h>
 
 static volatile char *x;
diff --git a/test/asan/TestCases/Linux/odr-violation.cc b/test/asan/TestCases/Linux/odr-violation.cc
index 91fa6d5..48e0907 100644
--- a/test/asan/TestCases/Linux/odr-violation.cc
+++ b/test/asan/TestCases/Linux/odr-violation.cc
@@ -1,15 +1,19 @@
+// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316
+// XFAIL: android
+//
 // Different size: detect a bug if detect_odr_violation>=1
-// RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared %s -o %t.so
-// RUN: %clangxx_asan %s %t.so -Wl,-R. -o %t
-// RUN: ASAN_OPTIONS=detect_odr_violation=1 not %run %t 2>&1 | FileCheck %s
-// RUN: ASAN_OPTIONS=detect_odr_violation=2 not %run %t 2>&1 | FileCheck %s
-// RUN: ASAN_OPTIONS=detect_odr_violation=0     %run %t 2>&1 | FileCheck %s --check-prefix=DISABLED
-// RUN:                                         %run %t 2>&1 | FileCheck %s --check-prefix=DISABLED
+// RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared %s -o %t-ODR-SO.so
+// RUN: %clangxx_asan %s %t-ODR-SO.so -Wl,-R. -o %t-ODR-EXE
+// RUN: ASAN_OPTIONS=detect_odr_violation=1 not %run %t-ODR-EXE 2>&1 | FileCheck %s
+// RUN: ASAN_OPTIONS=detect_odr_violation=2 not %run %t-ODR-EXE 2>&1 | FileCheck %s
+// RUN: ASAN_OPTIONS=detect_odr_violation=0     %run %t-ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED
+// RUN:                                     not %run %t-ODR-EXE 2>&1 | FileCheck %s
 //
 // Same size: report a bug only if detect_odr_violation>=2.
-// RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared %s -o %t.so -DSZ=100
-// RUN: ASAN_OPTIONS=detect_odr_violation=1     %run %t 2>&1 | FileCheck %s --check-prefix=DISABLED
-// RUN: ASAN_OPTIONS=detect_odr_violation=2 not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -DBUILD_SO=1 -fPIC -shared %s -o %t-ODR-SO.so -DSZ=100
+// RUN: ASAN_OPTIONS=detect_odr_violation=1     %run %t-ODR-EXE 2>&1 | FileCheck %s --check-prefix=DISABLED
+// RUN: ASAN_OPTIONS=detect_odr_violation=2 not %run %t-ODR-EXE 2>&1 | FileCheck %s
+// RUN:                                     not %run %t-ODR-EXE 2>&1 | FileCheck %s
 
 // GNU driver doesn't handle .so files properly.
 // REQUIRES: Clang
@@ -30,4 +34,8 @@
 
 // CHECK: ERROR: AddressSanitizer: odr-violation
 // CHECK: size=100 G
+// CHECK: size={{4|100}} G
+// CHECK: These globals were registered at these points:
+// CHECK: ODR-EXE
+// CHECK: ODR-SO
 // DISABLED: PASS
diff --git a/test/asan/TestCases/Linux/preinit_test.cc b/test/asan/TestCases/Linux/preinit_test.cc
index ab62d63..10dde67 100644
--- a/test/asan/TestCases/Linux/preinit_test.cc
+++ b/test/asan/TestCases/Linux/preinit_test.cc
@@ -1,3 +1,6 @@
+// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316
+// XFAIL: android
+//
 // RUN: %clangxx      -DFUNC=zzzz %s -shared -o %t.so -fPIC
 // RUN: %clangxx_asan -DFUNC=main %s         -o %t    -Wl,-R. %t.so
 // RUN: %run %t
diff --git a/test/asan/TestCases/Linux/ptrace.cc b/test/asan/TestCases/Linux/ptrace.cc
index 90086a0..45febd3 100644
--- a/test/asan/TestCases/Linux/ptrace.cc
+++ b/test/asan/TestCases/Linux/ptrace.cc
@@ -1,5 +1,9 @@
+// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316
+// XFAIL: android
+//
 // RUN: %clangxx_asan -O0 %s -o %t && %run %t
 // RUN: %clangxx_asan -DPOSITIVE -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// XFAIL: arm-linux-gnueabi
 
 #include <assert.h>
 #include <stdio.h>
diff --git a/test/asan/TestCases/Linux/shmctl.cc b/test/asan/TestCases/Linux/shmctl.cc
index 5fc9b46..e1752bc 100644
--- a/test/asan/TestCases/Linux/shmctl.cc
+++ b/test/asan/TestCases/Linux/shmctl.cc
@@ -1,3 +1,6 @@
+// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316
+// XFAIL: android
+//
 // RUN: %clangxx_asan -O1 %s -o %t && %run %t 2>&1
 // Regression test for
 // https://code.google.com/p/address-sanitizer/issues/detail?id=250
diff --git a/test/asan/TestCases/Linux/stack-trace-dlclose.cc b/test/asan/TestCases/Linux/stack-trace-dlclose.cc
index 3c6812b..44c8a03 100644
--- a/test/asan/TestCases/Linux/stack-trace-dlclose.cc
+++ b/test/asan/TestCases/Linux/stack-trace-dlclose.cc
@@ -1,6 +1,10 @@
+// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316
+// XFAIL: android
+//
 // RUN: %clangxx_asan -DSHARED %s -shared -o %T/stack_trace_dlclose.so -fPIC
 // RUN: %clangxx_asan -DSO_DIR=\"%T\" %s -o %t
 // RUN: ASAN_OPTIONS=exitcode=0 %run %t 2>&1 | FileCheck %s
+// XFAIL: arm-linux-gnueabi
 
 #include <assert.h>
 #include <dlfcn.h>
diff --git a/test/asan/TestCases/Linux/stress_dtls.c b/test/asan/TestCases/Linux/stress_dtls.c
index 814adf3..cb901ee 100644
--- a/test/asan/TestCases/Linux/stress_dtls.c
+++ b/test/asan/TestCases/Linux/stress_dtls.c
@@ -9,7 +9,7 @@
 // RUN: %clangxx_asan -x c -DSO_NAME=f0 %s -shared -o %t-f0.so -fPIC
 // RUN: %clangxx_asan -x c -DSO_NAME=f1 %s -shared -o %t-f1.so -fPIC
 // RUN: %clangxx_asan -x c -DSO_NAME=f2 %s -shared -o %t-f2.so -fPIC
-// RUN: %clangxx_asan %s -ldl -lpthread -o %t
+// RUN: %clangxx_asan %s -ldl -pthread -o %t
 // RUN: %run %t 0 3
 // RUN: %run %t 2 3
 // RUN: ASAN_OPTIONS=verbosity=2 %run %t 10 2 2>&1 | FileCheck %s
@@ -31,7 +31,7 @@
 /*
 cc=your-compiler
 
-$cc stress_dtls.c -lpthread -ldl
+$cc stress_dtls.c -pthread -ldl
 for((i=0;i<100;i++)); do
   $cc -fPIC -shared -DSO_NAME=f$i -o a.out-f$i.so stress_dtls.c;
 done
diff --git a/test/asan/TestCases/Linux/syscalls.cc b/test/asan/TestCases/Linux/syscalls.cc
index ec14bca..bcdd5bc 100644
--- a/test/asan/TestCases/Linux/syscalls.cc
+++ b/test/asan/TestCases/Linux/syscalls.cc
@@ -1,3 +1,6 @@
+// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316
+// XFAIL: android
+//
 // RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
 // RUN: %clangxx_asan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s
 
diff --git a/test/asan/TestCases/Linux/tsd_dtor_leak.cc b/test/asan/TestCases/Linux/tsd_dtor_leak.cc
index fdac964..32253af 100644
--- a/test/asan/TestCases/Linux/tsd_dtor_leak.cc
+++ b/test/asan/TestCases/Linux/tsd_dtor_leak.cc
@@ -1,13 +1,13 @@
 // Regression test for a leak in tsd:
 // https://code.google.com/p/address-sanitizer/issues/detail?id=233
-// RUN: %clangxx_asan -O1 %s -lpthread -o %t
+// RUN: %clangxx_asan -O1 %s -pthread -o %t
 // RUN: ASAN_OPTIONS=quarantine_size=1 %run %t
 #include <pthread.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <assert.h>
+#include <sanitizer/allocator_interface.h>
 
-extern "C" size_t __asan_get_heap_size();
 static pthread_key_t tsd_key;
 
 void *Thread(void *) {
@@ -30,7 +30,7 @@
     pthread_t t;
     pthread_create(&t, 0, Thread, 0);
     pthread_join(t, 0);
-    size_t new_heap_size = __asan_get_heap_size();
+    size_t new_heap_size = __sanitizer_get_heap_size();
     fprintf(stderr, "heap size: new: %zd old: %zd\n", new_heap_size, old_heap_size);
     if (old_heap_size)
       assert(old_heap_size == new_heap_size);
diff --git a/test/asan/TestCases/Linux/uar_signals.cc b/test/asan/TestCases/Linux/uar_signals.cc
index 3c50fcf..f42c3f6 100644
--- a/test/asan/TestCases/Linux/uar_signals.cc
+++ b/test/asan/TestCases/Linux/uar_signals.cc
@@ -1,6 +1,7 @@
 // This test checks that the implementation of use-after-return
 // is async-signal-safe.
-// RUN: %clangxx_asan -O1 %s -o %t -lpthread && %run %t
+// RUN: %clangxx_asan -O1 %s -o %t -pthread && %run %t
+// REQUIRES: stable-runtime
 #include <signal.h>
 #include <stdlib.h>
 #include <stdio.h>
diff --git a/test/asan/TestCases/Linux/unpoison_tls.cc b/test/asan/TestCases/Linux/unpoison_tls.cc
index 4c693b4..9c1d74b 100644
--- a/test/asan/TestCases/Linux/unpoison_tls.cc
+++ b/test/asan/TestCases/Linux/unpoison_tls.cc
@@ -1,7 +1,7 @@
 // Test that TLS is unpoisoned on thread death.
 // REQUIRES: x86_64-supported-target,i386-supported-target
 
-// RUN: %clangxx_asan -O1 %s -lpthread -o %t && %run %t 2>&1
+// RUN: %clangxx_asan -O1 %s -pthread -o %t && %run %t 2>&1
 
 #include <assert.h>
 #include <pthread.h>
diff --git a/test/asan/TestCases/asan-symbolize-sanity-test.cc b/test/asan/TestCases/Posix/asan-symbolize-sanity-test.cc
similarity index 92%
rename from test/asan/TestCases/asan-symbolize-sanity-test.cc
rename to test/asan/TestCases/Posix/asan-symbolize-sanity-test.cc
index 1aa41b6..84dc1c2 100644
--- a/test/asan/TestCases/asan-symbolize-sanity-test.cc
+++ b/test/asan/TestCases/Posix/asan-symbolize-sanity-test.cc
@@ -1,9 +1,13 @@
+// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316
+// XFAIL: android
+//
 // Check that asan_symbolize.py script works (for binaries, ASan RTL and
 // shared object files.
 
 // RUN: %clangxx_asan -O0 -DSHARED_LIB %s -fPIC -shared -o %t-so.so
 // RUN: %clangxx_asan -O0 %s -ldl -o %t
 // RUN: env ASAN_OPTIONS=symbolize=0 not %run %t 2>&1 | %asan_symbolize | FileCheck %s
+// XFAIL: arm-linux-gnueabi
 
 #if !defined(SHARED_LIB)
 #include <dlfcn.h>
diff --git a/test/asan/TestCases/Posix/init-order-dlopen.cc b/test/asan/TestCases/Posix/init-order-dlopen.cc
index f7b0d6a..2b86ace 100644
--- a/test/asan/TestCases/Posix/init-order-dlopen.cc
+++ b/test/asan/TestCases/Posix/init-order-dlopen.cc
@@ -10,8 +10,8 @@
 // If the linker doesn't support --export-dynamic (which is ELF-specific),
 // try to link without that option.
 // FIXME: find a better solution.
-// RUN: %clangxx_asan -O0 %s -lpthread -ldl -o %t -Wl,--export-dynamic || \
-// RUN:     %clangxx_asan -O0 %s -lpthread -ldl -o %t
+// RUN: %clangxx_asan -O0 %s -pthread -ldl -o %t -Wl,--export-dynamic || \
+// RUN:     %clangxx_asan -O0 %s -pthread -ldl -o %t
 // RUN: ASAN_OPTIONS=strict_init_order=true %run %t 2>&1 | FileCheck %s
 #if !defined(SHARED_LIB)
 #include <dlfcn.h>
diff --git a/test/asan/TestCases/Posix/shared-lib-test.cc b/test/asan/TestCases/Posix/shared-lib-test.cc
index ccaeed6..21f26b3 100644
--- a/test/asan/TestCases/Posix/shared-lib-test.cc
+++ b/test/asan/TestCases/Posix/shared-lib-test.cc
@@ -6,6 +6,7 @@
 // RUN: %clangxx_asan -O2 %s -ldl -o %t && not %run %t 2>&1 | FileCheck %s
 // RUN: %clangxx_asan -O3 -DSHARED_LIB %s -fPIC -shared -o %t-so.so
 // RUN: %clangxx_asan -O3 %s -ldl -o %t && not %run %t 2>&1 | FileCheck %s
+// XFAIL: arm-linux-gnueabi
 
 #if !defined(SHARED_LIB)
 #include <dlfcn.h>
diff --git a/test/asan/TestCases/Posix/start-deactivated.cc b/test/asan/TestCases/Posix/start-deactivated.cc
index ac45c16..43023fb 100644
--- a/test/asan/TestCases/Posix/start-deactivated.cc
+++ b/test/asan/TestCases/Posix/start-deactivated.cc
@@ -6,6 +6,7 @@
 // RUN: %clangxx -O0 %s -c -o %t.o
 // RUN: %clangxx_asan -O0 %t.o -ldl -o %t
 // RUN: ASAN_OPTIONS=start_deactivated=1 not %run %t 2>&1 | FileCheck %s
+// XFAIL: arm-linux-gnueabi
 
 #if !defined(SHARED_LIB)
 #include <dlfcn.h>
diff --git a/test/asan/TestCases/Windows/aligned_mallocs.cc b/test/asan/TestCases/Windows/aligned_mallocs.cc
index bbbc423..df740b6 100644
--- a/test/asan/TestCases/Windows/aligned_mallocs.cc
+++ b/test/asan/TestCases/Windows/aligned_mallocs.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %clang_cl_asan -O0 %s -Fe%t
 // RUN: %run %t
 
 #include <windows.h>
diff --git a/test/asan/TestCases/Windows/allocators_sanity.cc b/test/asan/TestCases/Windows/allocators_sanity.cc
index 55cfdff..66a862d 100644
--- a/test/asan/TestCases/Windows/allocators_sanity.cc
+++ b/test/asan/TestCases/Windows/allocators_sanity.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %clang_cl_asan -O0 %s -Fe%t
 // RUN: %run %t | FileCheck %s
 
 #include <malloc.h>
diff --git a/test/asan/TestCases/Windows/beginthreadex.cc b/test/asan/TestCases/Windows/beginthreadex.cc
index 12e2b1f..f2b2b45 100644
--- a/test/asan/TestCases/Windows/beginthreadex.cc
+++ b/test/asan/TestCases/Windows/beginthreadex.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %clang_cl_asan -O0 %s -Fe%t
 // RUN: %run %t
 
 #include <windows.h>
diff --git a/test/asan/TestCases/Windows/bitfield.cc b/test/asan/TestCases/Windows/bitfield.cc
index e1a3fc8..253a759 100644
--- a/test/asan/TestCases/Windows/bitfield.cc
+++ b/test/asan/TestCases/Windows/bitfield.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %clang_cl_asan -O0 %s -Fe%t
 // RUN: %run %t
 
 #include <windows.h>
diff --git a/test/asan/TestCases/Windows/bitfield_uaf.cc b/test/asan/TestCases/Windows/bitfield_uaf.cc
index 63f3941..f49d671 100644
--- a/test/asan/TestCases/Windows/bitfield_uaf.cc
+++ b/test/asan/TestCases/Windows/bitfield_uaf.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %clang_cl_asan -O0 %s -Fe%t
 // RUN: not %run %t 2>&1 | FileCheck %s
 
 #include <windows.h>
diff --git a/test/asan/TestCases/Windows/calloc_left_oob.cc b/test/asan/TestCases/Windows/calloc_left_oob.cc
index 71399a7..459025b 100644
--- a/test/asan/TestCases/Windows/calloc_left_oob.cc
+++ b/test/asan/TestCases/Windows/calloc_left_oob.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %clang_cl_asan -O0 %s -Fe%t
 // RUN: not %run %t 2>&1 | FileCheck %s
 
 #include <malloc.h>
diff --git a/test/asan/TestCases/Windows/calloc_right_oob.cc b/test/asan/TestCases/Windows/calloc_right_oob.cc
index fcf3138..c976b87 100644
--- a/test/asan/TestCases/Windows/calloc_right_oob.cc
+++ b/test/asan/TestCases/Windows/calloc_right_oob.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %clang_cl_asan -O0 %s -Fe%t
 // RUN: not %run %t 2>&1 | FileCheck %s
 
 #include <malloc.h>
diff --git a/test/asan/TestCases/Windows/calloc_uaf.cc b/test/asan/TestCases/Windows/calloc_uaf.cc
index 5a1d936..db5e707 100644
--- a/test/asan/TestCases/Windows/calloc_uaf.cc
+++ b/test/asan/TestCases/Windows/calloc_uaf.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %clang_cl_asan -O0 %s -Fe%t
 // RUN: not %run %t 2>&1 | FileCheck %s
 
 #include <malloc.h>
diff --git a/test/asan/TestCases/Windows/crt_initializers.cc b/test/asan/TestCases/Windows/crt_initializers.cc
index 5544912..084f8a4 100644
--- a/test/asan/TestCases/Windows/crt_initializers.cc
+++ b/test/asan/TestCases/Windows/crt_initializers.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %clang_cl_asan -O0 %s -Fe%t
 // RUN: %run %t | FileCheck %s
 
 // This is a test for http://code.google.com/p/address-sanitizer/issues/detail?id=305
diff --git a/test/asan/TestCases/Windows/dll_aligned_mallocs.cc b/test/asan/TestCases/Windows/dll_aligned_mallocs.cc
index db2b9d1..8b2c4d6 100644
--- a/test/asan/TestCases/Windows/dll_aligned_mallocs.cc
+++ b/test/asan/TestCases/Windows/dll_aligned_mallocs.cc
@@ -1,5 +1,5 @@
-// RUN: %clangxx_asan -O0 %p/dll_host.cc -Fe%t
-// RUN: %clangxx_asan -LD -O0 %s -Fe%t.dll
+// RUN: %clang_cl_asan -O0 %p/dll_host.cc -Fe%t
+// RUN: %clang_cl_asan -LD -O0 %s -Fe%t.dll
 // RUN: %run %t %t.dll | FileCheck %s
 
 #include <malloc.h>
diff --git a/test/asan/TestCases/Windows/dll_allocators_sanity.cc b/test/asan/TestCases/Windows/dll_allocators_sanity.cc
index 2f3f78f..1d31f37 100644
--- a/test/asan/TestCases/Windows/dll_allocators_sanity.cc
+++ b/test/asan/TestCases/Windows/dll_allocators_sanity.cc
@@ -1,5 +1,5 @@
-// RUN: %clangxx_asan -O0 %p/dll_host.cc -Fe%t
-// RUN: %clangxx_asan -LD -O0 %s -Fe%t.dll
+// RUN: %clang_cl_asan -O0 %p/dll_host.cc -Fe%t
+// RUN: %clang_cl_asan -LD -O0 %s -Fe%t.dll
 // RUN: %run %t %t.dll | FileCheck %s
 
 #include <malloc.h>
diff --git a/test/asan/TestCases/Windows/dll_cerr.cc b/test/asan/TestCases/Windows/dll_cerr.cc
new file mode 100644
index 0000000..8f1a699
--- /dev/null
+++ b/test/asan/TestCases/Windows/dll_cerr.cc
@@ -0,0 +1,23 @@
+// RUN: %clang_cl_asan -O0 %p/dll_host.cc -Fe%t
+// RUN: %clang_cl_asan -LD -O0 %s -Fe%t.dll
+// RUN: %run %t %t.dll 2>&1 | FileCheck %s
+
+// Test that it works correctly even with ICF enabled.
+// RUN: %clang_cl_asan -LD -O0 %s -Fe%t.dll -link /OPT:REF /OPT:ICF
+// RUN: %run %t %t.dll 2>&1 | FileCheck %s
+
+#include <iostream>
+
+extern "C" __declspec(dllexport)
+int test_function() {
+  // Just make sure we can use cout.
+  std::cout << "All ok\n";
+// CHECK: All ok
+
+  // This line forces a declaration of some global basic_ostream internal object that
+  // calls memcpy() in its constructor.  This doesn't work if __asan_init is not
+  // called early enough.
+  std::cout << 42;
+// CHECK: 42
+  return 0;
+}
diff --git a/test/asan/TestCases/Windows/dll_host.cc b/test/asan/TestCases/Windows/dll_host.cc
index 470d3fa..5eb710e 100644
--- a/test/asan/TestCases/Windows/dll_host.cc
+++ b/test/asan/TestCases/Windows/dll_host.cc
@@ -2,7 +2,7 @@
 //
 // Just make sure we can compile this.
 // The actual compile&run sequence is to be done by the DLL tests.
-// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %clang_cl_asan -O0 %s -Fe%t
 //
 // Get the list of ASan wrappers exported by the main module RTL:
 // RUN: dumpbin /EXPORTS %t | grep -o "__asan_wrap[^ ]*" | grep -v @ | sort | uniq > %t.exported_wrappers
diff --git a/test/asan/TestCases/Windows/dll_intercept_memchr.cc b/test/asan/TestCases/Windows/dll_intercept_memchr.cc
new file mode 100644
index 0000000..1435bdc
--- /dev/null
+++ b/test/asan/TestCases/Windows/dll_intercept_memchr.cc
@@ -0,0 +1,21 @@
+// RUN: %clang_cl_asan -O0 %p/dll_host.cc -Fe%t
+// RUN: %clang_cl_asan -LD -O0 %s -Fe%t.dll
+// RUN: not %run %t %t.dll 2>&1 | FileCheck %s
+
+#include <string.h>
+
+extern "C" __declspec(dllexport)
+int test_function() {
+  char buff[6] = "Hello";
+
+  memchr(buff, 'z', 7);
+// CHECK: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
+// CHECK: READ of size 7 at [[ADDR]] thread T0
+// CHECK-NEXT:  __asan_wrap_memchr
+// CHECK-NEXT:  memchr
+// CHECK-NEXT:  test_function {{.*}}dll_intercept_memchr.cc:[[@LINE-5]]
+// CHECK: Address [[ADDR]] is located in stack of thread T0 at offset {{.*}} in frame
+// CHECK-NEXT:  test_function {{.*}}dll_intercept_memchr.cc
+// CHECK: 'buff' <== Memory access at offset {{.*}} overflows this variable
+  return 0;
+}
diff --git a/test/asan/TestCases/Windows/dll_intercept_memcpy.cc b/test/asan/TestCases/Windows/dll_intercept_memcpy.cc
index 8a69e7d..7ad0d82 100644
--- a/test/asan/TestCases/Windows/dll_intercept_memcpy.cc
+++ b/test/asan/TestCases/Windows/dll_intercept_memcpy.cc
@@ -1,33 +1,32 @@
-// RUN: %clangxx_asan -O0 %p/dll_host.cc -Fe%t
-// RUN: %clangxx_asan -LD -O0 %s -Fe%t.dll
+// RUN: %clang_cl_asan -O0 %p/dll_host.cc -Fe%t
+// RUN: %clang_cl_asan -LD -O0 %s -Fe%t.dll
+// RUN: not %run %t %t.dll 2>&1 | FileCheck %s
+
+// Test that it works correctly even with ICF enabled.
+// RUN: %clang_cl_asan -LD -O0 %s -Fe%t.dll -link /OPT:REF /OPT:ICF
 // RUN: not %run %t %t.dll 2>&1 | FileCheck %s
 
 #include <stdio.h>
 #include <string.h>
 
-void call_memcpy(void* (*f)(void *, const void *, size_t),
-                 void *a, const void *b, size_t c) {
-  f(a, b, c);
-}
-
 extern "C" __declspec(dllexport)
 int test_function() {
   char buff1[6] = "Hello", buff2[5];
 
-  call_memcpy(&memcpy, buff2, buff1, 5);
+  memcpy(buff2, buff1, 5);
   if (buff1[2] != buff2[2])
     return 2;
   printf("Initial test OK\n");
   fflush(0);
 // CHECK: Initial test OK
 
-  call_memcpy(&memcpy, buff2, buff1, 6);
+  memcpy(buff2, buff1, 6);
 // CHECK: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
 // CHECK: WRITE of size 6 at [[ADDR]] thread T0
 // CHECK-NEXT:  __asan_memcpy
-// CHECK-NEXT:  call_memcpy
-// CHECK-NEXT:  test_function {{.*}}dll_intercept_memcpy.cc:[[@LINE-5]]
+// CHECK-NEXT:  test_function {{.*}}dll_intercept_memcpy.cc:[[@LINE-4]]
 // CHECK: Address [[ADDR]] is located in stack of thread T0 at offset {{.*}} in frame
 // CHECK-NEXT:  test_function {{.*}}dll_intercept_memcpy.cc
 // CHECK: 'buff2' <== Memory access at offset {{.*}} overflows this variable
+  return 0;
 }
diff --git a/test/asan/TestCases/Windows/dll_intercept_memcpy_indirect.cc b/test/asan/TestCases/Windows/dll_intercept_memcpy_indirect.cc
new file mode 100644
index 0000000..0c4bfba
--- /dev/null
+++ b/test/asan/TestCases/Windows/dll_intercept_memcpy_indirect.cc
@@ -0,0 +1,34 @@
+// RUN: %clang_cl_asan -O0 %p/dll_host.cc -Fe%t
+// RUN: %clang_cl_asan -LD -O0 %s -Fe%t.dll
+// RUN: not %run %t %t.dll 2>&1 | FileCheck %s
+
+#include <stdio.h>
+#include <string.h>
+
+void call_memcpy(void* (*f)(void *, const void *, size_t),
+                 void *a, const void *b, size_t c) {
+  f(a, b, c);
+}
+
+extern "C" __declspec(dllexport)
+int test_function() {
+  char buff1[6] = "Hello", buff2[5];
+
+  call_memcpy(&memcpy, buff2, buff1, 5);
+  if (buff1[2] != buff2[2])
+    return 2;
+  printf("Initial test OK\n");
+  fflush(0);
+// CHECK: Initial test OK
+
+  call_memcpy(&memcpy, buff2, buff1, 6);
+// CHECK: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
+// CHECK: WRITE of size 6 at [[ADDR]] thread T0
+// CHECK-NEXT:  __asan_memcpy
+// CHECK-NEXT:  call_memcpy
+// CHECK-NEXT:  test_function {{.*}}dll_intercept_memcpy_indirect.cc:[[@LINE-5]]
+// CHECK: Address [[ADDR]] is located in stack of thread T0 at offset {{.*}} in frame
+// CHECK-NEXT:  test_function {{.*}}dll_intercept_memcpy_indirect.cc
+// CHECK: 'buff2' <== Memory access at offset {{.*}} overflows this variable
+  return 0;
+}
diff --git a/test/asan/TestCases/Windows/dll_intercept_memset.cc b/test/asan/TestCases/Windows/dll_intercept_memset.cc
new file mode 100644
index 0000000..d4be376
--- /dev/null
+++ b/test/asan/TestCases/Windows/dll_intercept_memset.cc
@@ -0,0 +1,32 @@
+// RUN: %clang_cl_asan -O0 %p/dll_host.cc -Fe%t
+// RUN: %clang_cl_asan -LD -O0 %s -Fe%t.dll
+// RUN: not %run %t %t.dll 2>&1 | FileCheck %s
+
+// Test that it works correctly even with ICF enabled.
+// RUN: %clang_cl_asan -LD -O0 %s -Fe%t.dll -link /OPT:REF /OPT:ICF
+// RUN: not %run %t %t.dll 2>&1 | FileCheck %s
+
+#include <stdio.h>
+#include <string.h>
+
+extern "C" __declspec(dllexport)
+int test_function() {
+  char buff[5] = "aaaa";
+
+  memset(buff, 'b', 5);
+  if (buff[2] != 'b')
+    return 2;
+  printf("Initial test OK\n");
+  fflush(0);
+// CHECK: Initial test OK
+
+  memset(buff, 'c', 6);
+// CHECK: AddressSanitizer: stack-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
+// CHECK: WRITE of size 6 at [[ADDR]] thread T0
+// CHECK-NEXT:  __asan_memset
+// CHECK-NEXT:  test_function {{.*}}dll_intercept_memset.cc:[[@LINE-4]]
+// CHECK: Address [[ADDR]] is located in stack of thread T0 at offset {{.*}} in frame
+// CHECK-NEXT:  test_function {{.*}}dll_intercept_memset.cc
+// CHECK: 'buff' <== Memory access at offset {{.*}} overflows this variable
+  return 0;
+}
diff --git a/test/asan/TestCases/Windows/dll_intercept_strlen.cc b/test/asan/TestCases/Windows/dll_intercept_strlen.cc
index caac426..f41d478 100644
--- a/test/asan/TestCases/Windows/dll_intercept_strlen.cc
+++ b/test/asan/TestCases/Windows/dll_intercept_strlen.cc
@@ -1,5 +1,5 @@
-// RUN: %clangxx_asan -O0 %p/dll_host.cc -Fe%t
-// RUN: %clangxx_asan -LD -O0 %s -Fe%t.dll
+// RUN: %clang_cl_asan -O0 %p/dll_host.cc -Fe%t
+// RUN: %clang_cl_asan -LD -O0 %s -Fe%t.dll
 // RUN: not %run %t %t.dll 2>&1 | FileCheck %s
 
 #include <stdio.h>
diff --git a/test/asan/TestCases/Windows/dll_malloc_left_oob.cc b/test/asan/TestCases/Windows/dll_malloc_left_oob.cc
index 8064b83..0653ea4 100644
--- a/test/asan/TestCases/Windows/dll_malloc_left_oob.cc
+++ b/test/asan/TestCases/Windows/dll_malloc_left_oob.cc
@@ -1,5 +1,5 @@
-// RUN: %clangxx_asan -O0 %p/dll_host.cc -Fe%t
-// RUN: %clangxx_asan -LD -O0 %s -Fe%t.dll
+// RUN: %clang_cl_asan -O0 %p/dll_host.cc -Fe%t
+// RUN: %clang_cl_asan -LD -O0 %s -Fe%t.dll
 // RUN: not %run %t %t.dll 2>&1 | FileCheck %s
 
 #include <malloc.h>
diff --git a/test/asan/TestCases/Windows/dll_malloc_uaf.cc b/test/asan/TestCases/Windows/dll_malloc_uaf.cc
index 5842999..b286380 100644
--- a/test/asan/TestCases/Windows/dll_malloc_uaf.cc
+++ b/test/asan/TestCases/Windows/dll_malloc_uaf.cc
@@ -1,5 +1,5 @@
-// RUN: %clangxx_asan -O0 %p/dll_host.cc -Fe%t
-// RUN: %clangxx_asan -LD -O0 %s -Fe%t.dll
+// RUN: %clang_cl_asan -O0 %p/dll_host.cc -Fe%t
+// RUN: %clang_cl_asan -LD -O0 %s -Fe%t.dll
 // RUN: not %run %t %t.dll 2>&1 | FileCheck %s
 
 #include <malloc.h>
diff --git a/test/asan/TestCases/Windows/dll_noreturn.cc b/test/asan/TestCases/Windows/dll_noreturn.cc
index 4b5bf33..6ec9072 100644
--- a/test/asan/TestCases/Windows/dll_noreturn.cc
+++ b/test/asan/TestCases/Windows/dll_noreturn.cc
@@ -1,5 +1,5 @@
-// RUN: %clangxx_asan -O0 %p/dll_host.cc -Fe%t
-// RUN: %clangxx_asan -LD -O0 %s -Fe%t.dll
+// RUN: %clang_cl_asan -O0 %p/dll_host.cc -Fe%t
+// RUN: %clang_cl_asan -LD -O0 %s -Fe%t.dll
 // RUN: not %run %t %t.dll 2>&1 | FileCheck %s
 
 #include <process.h>
diff --git a/test/asan/TestCases/Windows/dll_operator_array_new_left_oob.cc b/test/asan/TestCases/Windows/dll_operator_array_new_left_oob.cc
index 509e0af..e52345e 100644
--- a/test/asan/TestCases/Windows/dll_operator_array_new_left_oob.cc
+++ b/test/asan/TestCases/Windows/dll_operator_array_new_left_oob.cc
@@ -1,5 +1,5 @@
-// RUN: %clangxx_asan -O0 %p/dll_host.cc -Fe%t
-// RUN: %clangxx_asan -LD -O0 %s -Fe%t.dll
+// RUN: %clang_cl_asan -O0 %p/dll_host.cc -Fe%t
+// RUN: %clang_cl_asan -LD -O0 %s -Fe%t.dll
 // RUN: not %run %t %t.dll 2>&1 | FileCheck %s
 
 extern "C" __declspec(dllexport)
diff --git a/test/asan/TestCases/Windows/dll_operator_array_new_with_dtor_left_oob.cc b/test/asan/TestCases/Windows/dll_operator_array_new_with_dtor_left_oob.cc
index 09302c3..c61d4eb 100644
--- a/test/asan/TestCases/Windows/dll_operator_array_new_with_dtor_left_oob.cc
+++ b/test/asan/TestCases/Windows/dll_operator_array_new_with_dtor_left_oob.cc
@@ -1,5 +1,5 @@
-// RUN: %clangxx_asan -O0 %p/dll_host.cc -Fe%t
-// RUN: %clangxx_asan -LD -O0 %s -Fe%t.dll
+// RUN: %clang_cl_asan -O0 %p/dll_host.cc -Fe%t
+// RUN: %clang_cl_asan -LD -O0 %s -Fe%t.dll
 // RUN: not %run %t %t.dll 2>&1 | FileCheck %s
 
 struct C {
diff --git a/test/asan/TestCases/Windows/dll_poison_unpoison.cc b/test/asan/TestCases/Windows/dll_poison_unpoison.cc
index 24f98dd..d486cb1 100644
--- a/test/asan/TestCases/Windows/dll_poison_unpoison.cc
+++ b/test/asan/TestCases/Windows/dll_poison_unpoison.cc
@@ -1,5 +1,5 @@
-// RUN: %clangxx_asan -O0 %p/dll_host.cc -Fe%t
-// RUN: %clangxx_asan -LD -O0 %s -Fe%t.dll
+// RUN: %clang_cl_asan -O0 %p/dll_host.cc -Fe%t
+// RUN: %clang_cl_asan -LD -O0 %s -Fe%t.dll
 // RUN: not %run %t %t.dll 2>&1 | FileCheck %s
 
 #include <sanitizer/asan_interface.h>
diff --git a/test/asan/TestCases/Windows/dll_stack_use_after_return.cc b/test/asan/TestCases/Windows/dll_stack_use_after_return.cc
index 22d9970..6cd74c2 100644
--- a/test/asan/TestCases/Windows/dll_stack_use_after_return.cc
+++ b/test/asan/TestCases/Windows/dll_stack_use_after_return.cc
@@ -1,5 +1,5 @@
-// RUN: %clangxx_asan -O0 %p/dll_host.cc -Fe%t
-// RUN: %clangxx_asan -LD -O0 %s -Fe%t.dll
+// RUN: %clang_cl_asan -O0 %p/dll_host.cc -Fe%t
+// RUN: %clang_cl_asan -LD -O0 %s -Fe%t.dll
 // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=1 not %run %t %t.dll 2>&1 | FileCheck %s
 
 #include <malloc.h>
diff --git a/test/asan/TestCases/Windows/dll_thread_stack_array_left_oob.cc b/test/asan/TestCases/Windows/dll_thread_stack_array_left_oob.cc
index a84eeb9..8f53623 100644
--- a/test/asan/TestCases/Windows/dll_thread_stack_array_left_oob.cc
+++ b/test/asan/TestCases/Windows/dll_thread_stack_array_left_oob.cc
@@ -1,5 +1,5 @@
-// RUN: %clangxx_asan -O0 %p/dll_host.cc -Fe%t
-// RUN: %clangxx_asan -LD -O0 %s -Fe%t.dll
+// RUN: %clang_cl_asan -O0 %p/dll_host.cc -Fe%t
+// RUN: %clang_cl_asan -LD -O0 %s -Fe%t.dll
 // RUN: not %run %t %t.dll 2>&1 | FileCheck %s
 
 #include <windows.h>
diff --git a/test/asan/TestCases/Windows/double_free.cc b/test/asan/TestCases/Windows/double_free.cc
index 6745c59..18a9fcb 100644
--- a/test/asan/TestCases/Windows/double_free.cc
+++ b/test/asan/TestCases/Windows/double_free.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %clang_cl_asan -O0 %s -Fe%t
 // RUN: not %run %t 2>&1 | FileCheck %s
 
 #include <malloc.h>
diff --git a/test/asan/TestCases/Windows/double_operator_delete.cc b/test/asan/TestCases/Windows/double_operator_delete.cc
index 1cd7080..55a6d09 100644
--- a/test/asan/TestCases/Windows/double_operator_delete.cc
+++ b/test/asan/TestCases/Windows/double_operator_delete.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %clang_cl_asan -O0 %s -Fe%t
 // RUN: not %run %t 2>&1 | FileCheck %s
 
 #include <malloc.h>
diff --git a/test/asan/TestCases/Windows/global_const_string.cc b/test/asan/TestCases/Windows/global_const_string.cc
index 6d17b24..8c147c9 100644
--- a/test/asan/TestCases/Windows/global_const_string.cc
+++ b/test/asan/TestCases/Windows/global_const_string.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %clang_cl_asan -O0 %s -Fe%t
 // RUN: %run %t | FileCheck %s
 
 #include <windows.h>
diff --git a/test/asan/TestCases/Windows/global_const_string_oob.cc b/test/asan/TestCases/Windows/global_const_string_oob.cc
index b54a2bb..b39e3db 100644
--- a/test/asan/TestCases/Windows/global_const_string_oob.cc
+++ b/test/asan/TestCases/Windows/global_const_string_oob.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %clang_cl_asan -O0 %s -Fe%t
 // RUN: not %run %t 2>&1 | FileCheck %s
 
 #include <windows.h>
@@ -13,7 +13,7 @@
 // CHECK: AddressSanitizer: global-buffer-overflow on address [[ADDR:0x[0-9a-f]+]]
 // CHECK: READ of size 1 at [[ADDR]] thread T0
 // CHECK-NEXT:   {{#0 .* main .*global_const_string_oob.cc:}}[[@LINE-5]]
-// CHECK: [[ADDR]] is located 5 bytes to the right of global variable [[STR:.*]] from {{'.*global_const_string_oob.cc' .*}} of size 11
+// CHECK: [[ADDR]] is located 5 bytes to the right of global variable [[STR:.*]] defined in {{'.*global_const_string_oob.cc:7:.*' .*}} of size 11
 // CHECK:   [[STR]] is ascii string 'foobarspam'
   return 0;
 }
diff --git a/test/asan/TestCases/Windows/hello_world.cc b/test/asan/TestCases/Windows/hello_world.cc
index 2ef37d0..400ca1b 100644
--- a/test/asan/TestCases/Windows/hello_world.cc
+++ b/test/asan/TestCases/Windows/hello_world.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %clang_cl_asan -O0 %s -Fe%t
 // RUN: %run %t | FileCheck %s
 
 #include <stdio.h>
diff --git a/test/asan/TestCases/Windows/intercept_memcpy.cc b/test/asan/TestCases/Windows/intercept_memcpy.cc
index 73ce951..89eb175 100644
--- a/test/asan/TestCases/Windows/intercept_memcpy.cc
+++ b/test/asan/TestCases/Windows/intercept_memcpy.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %clang_cl_asan -O0 %s -Fe%t
 // RUN: not %run %t 2>&1 | FileCheck %s
 
 #include <stdio.h>
diff --git a/test/asan/TestCases/Windows/intercept_strdup.cc b/test/asan/TestCases/Windows/intercept_strdup.cc
index 1bc235f..0a40d86 100644
--- a/test/asan/TestCases/Windows/intercept_strdup.cc
+++ b/test/asan/TestCases/Windows/intercept_strdup.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %clang_cl_asan -O0 %s -Fe%t
 // RUN: not %run %t 2>&1 | FileCheck %s
 
 #include <stdio.h>
diff --git a/test/asan/TestCases/Windows/intercept_strlen.cc b/test/asan/TestCases/Windows/intercept_strlen.cc
index 62a5be8..928a286 100644
--- a/test/asan/TestCases/Windows/intercept_strlen.cc
+++ b/test/asan/TestCases/Windows/intercept_strlen.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %clang_cl_asan -O0 %s -Fe%t
 // RUN: not %run %t 2>&1 | FileCheck %s
 
 #include <stdio.h>
diff --git a/test/asan/TestCases/Windows/malloc_left_oob.cc b/test/asan/TestCases/Windows/malloc_left_oob.cc
index 2f6516e..ec133c3 100644
--- a/test/asan/TestCases/Windows/malloc_left_oob.cc
+++ b/test/asan/TestCases/Windows/malloc_left_oob.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %clang_cl_asan -O0 %s -Fe%t
 // RUN: not %run %t 2>&1 | FileCheck %s
 
 #include <malloc.h>
diff --git a/test/asan/TestCases/Windows/malloc_right_oob.cc b/test/asan/TestCases/Windows/malloc_right_oob.cc
index ba1bf93..9975316 100644
--- a/test/asan/TestCases/Windows/malloc_right_oob.cc
+++ b/test/asan/TestCases/Windows/malloc_right_oob.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %clang_cl_asan -O0 %s -Fe%t
 // RUN: not %run %t 2>&1 | FileCheck %s
 
 #include <malloc.h>
diff --git a/test/asan/TestCases/Windows/malloc_uaf.cc b/test/asan/TestCases/Windows/malloc_uaf.cc
index 3f873cc..f584789 100644
--- a/test/asan/TestCases/Windows/malloc_uaf.cc
+++ b/test/asan/TestCases/Windows/malloc_uaf.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %clang_cl_asan -O0 %s -Fe%t
 // RUN: not %run %t 2>&1 | FileCheck %s
 
 #include <malloc.h>
diff --git a/test/asan/TestCases/Windows/operator_array_new_left_oob.cc b/test/asan/TestCases/Windows/operator_array_new_left_oob.cc
index 082cf4c..81b709f 100644
--- a/test/asan/TestCases/Windows/operator_array_new_left_oob.cc
+++ b/test/asan/TestCases/Windows/operator_array_new_left_oob.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %clang_cl_asan -O0 %s -Fe%t
 // RUN: not %run %t 2>&1 | FileCheck %s
 
 int main() {
diff --git a/test/asan/TestCases/Windows/operator_array_new_right_oob.cc b/test/asan/TestCases/Windows/operator_array_new_right_oob.cc
index 1465fa0..079c78e 100644
--- a/test/asan/TestCases/Windows/operator_array_new_right_oob.cc
+++ b/test/asan/TestCases/Windows/operator_array_new_right_oob.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %clang_cl_asan -O0 %s -Fe%t
 // RUN: not %run %t 2>&1 | FileCheck %s
 
 #include <windows.h>
diff --git a/test/asan/TestCases/Windows/operator_array_new_uaf.cc b/test/asan/TestCases/Windows/operator_array_new_uaf.cc
index f48d7a6..1817996 100644
--- a/test/asan/TestCases/Windows/operator_array_new_uaf.cc
+++ b/test/asan/TestCases/Windows/operator_array_new_uaf.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %clang_cl_asan -O0 %s -Fe%t
 // RUN: not %run %t 2>&1 | FileCheck %s
 
 #include <windows.h>
diff --git a/test/asan/TestCases/Windows/operator_array_new_with_dtor_left_oob.cc b/test/asan/TestCases/Windows/operator_array_new_with_dtor_left_oob.cc
index 1702b51..c5bdba5 100644
--- a/test/asan/TestCases/Windows/operator_array_new_with_dtor_left_oob.cc
+++ b/test/asan/TestCases/Windows/operator_array_new_with_dtor_left_oob.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %clang_cl_asan -O0 %s -Fe%t
 // RUN: not %run %t 2>&1 | FileCheck %s
 
 struct C {
diff --git a/test/asan/TestCases/Windows/operator_delete_wrong_argument.cc b/test/asan/TestCases/Windows/operator_delete_wrong_argument.cc
index 7358cba..c3e7dac 100644
--- a/test/asan/TestCases/Windows/operator_delete_wrong_argument.cc
+++ b/test/asan/TestCases/Windows/operator_delete_wrong_argument.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %clang_cl_asan -O0 %s -Fe%t
 // RUN: not %run %t 2>&1 | FileCheck %s
 
 #include <windows.h>
diff --git a/test/asan/TestCases/Windows/operator_new_left_oob.cc b/test/asan/TestCases/Windows/operator_new_left_oob.cc
index 77454fa..c077f11 100644
--- a/test/asan/TestCases/Windows/operator_new_left_oob.cc
+++ b/test/asan/TestCases/Windows/operator_new_left_oob.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %clang_cl_asan -O0 %s -Fe%t
 // RUN: not %run %t 2>&1 | FileCheck %s
 
 #include <windows.h>
diff --git a/test/asan/TestCases/Windows/operator_new_right_oob.cc b/test/asan/TestCases/Windows/operator_new_right_oob.cc
index e6df9c9..7a66d17 100644
--- a/test/asan/TestCases/Windows/operator_new_right_oob.cc
+++ b/test/asan/TestCases/Windows/operator_new_right_oob.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %clang_cl_asan -O0 %s -Fe%t
 // RUN: not %run %t 2>&1 | FileCheck %s
 
 #include <windows.h>
diff --git a/test/asan/TestCases/Windows/operator_new_uaf.cc b/test/asan/TestCases/Windows/operator_new_uaf.cc
index 350598a..c435458 100644
--- a/test/asan/TestCases/Windows/operator_new_uaf.cc
+++ b/test/asan/TestCases/Windows/operator_new_uaf.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %clang_cl_asan -O0 %s -Fe%t
 // RUN: not %run %t 2>&1 | FileCheck %s
 
 #include <windows.h>
diff --git a/test/asan/TestCases/Windows/realloc_left_oob.cc b/test/asan/TestCases/Windows/realloc_left_oob.cc
index 511e509..7d30e1d 100644
--- a/test/asan/TestCases/Windows/realloc_left_oob.cc
+++ b/test/asan/TestCases/Windows/realloc_left_oob.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %clang_cl_asan -O0 %s -Fe%t
 // RUN: not %run %t 2>&1 | FileCheck %s
 
 #include <malloc.h>
diff --git a/test/asan/TestCases/Windows/realloc_right_oob.cc b/test/asan/TestCases/Windows/realloc_right_oob.cc
index 3b0ad19..f741390 100644
--- a/test/asan/TestCases/Windows/realloc_right_oob.cc
+++ b/test/asan/TestCases/Windows/realloc_right_oob.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %clang_cl_asan -O0 %s -Fe%t
 // RUN: not %run %t 2>&1 | FileCheck %s
 
 #include <malloc.h>
diff --git a/test/asan/TestCases/Windows/realloc_uaf.cc b/test/asan/TestCases/Windows/realloc_uaf.cc
index 45c5598..c5b6953 100644
--- a/test/asan/TestCases/Windows/realloc_uaf.cc
+++ b/test/asan/TestCases/Windows/realloc_uaf.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %clang_cl_asan -O0 %s -Fe%t
 // RUN: not %run %t 2>&1 | FileCheck %s
 
 #include <malloc.h>
diff --git a/test/asan/TestCases/Windows/stack_array_left_oob.cc b/test/asan/TestCases/Windows/stack_array_left_oob.cc
index 65385e2..040d855 100644
--- a/test/asan/TestCases/Windows/stack_array_left_oob.cc
+++ b/test/asan/TestCases/Windows/stack_array_left_oob.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %clang_cl_asan -O0 %s -Fe%t
 // RUN: not %run %t 2>&1 | FileCheck %s
 
 #include <stdio.h>
diff --git a/test/asan/TestCases/Windows/stack_array_right_oob.cc b/test/asan/TestCases/Windows/stack_array_right_oob.cc
index ac267bf..a370246 100644
--- a/test/asan/TestCases/Windows/stack_array_right_oob.cc
+++ b/test/asan/TestCases/Windows/stack_array_right_oob.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %clang_cl_asan -O0 %s -Fe%t
 // RUN: not %run %t 2>&1 | FileCheck %s
 
 #include <stdio.h>
diff --git a/test/asan/TestCases/Windows/stack_array_sanity.cc b/test/asan/TestCases/Windows/stack_array_sanity.cc
index 7dc75f8..1aef1a9 100644
--- a/test/asan/TestCases/Windows/stack_array_sanity.cc
+++ b/test/asan/TestCases/Windows/stack_array_sanity.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %clang_cl_asan -O0 %s -Fe%t
 // RUN: %run %t | FileCheck %s
 
 #include <stdio.h>
diff --git a/test/asan/TestCases/Windows/stack_use_after_return.cc b/test/asan/TestCases/Windows/stack_use_after_return.cc
index 1eb6442..7955f26 100644
--- a/test/asan/TestCases/Windows/stack_use_after_return.cc
+++ b/test/asan/TestCases/Windows/stack_use_after_return.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %clang_cl_asan -O0 %s -Fe%t
 // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=1 not %run %t 2>&1 | FileCheck %s
 
 char *x;
diff --git a/test/asan/TestCases/Windows/thread_simple.cc b/test/asan/TestCases/Windows/thread_simple.cc
index 6afb0bf..14bb82f 100644
--- a/test/asan/TestCases/Windows/thread_simple.cc
+++ b/test/asan/TestCases/Windows/thread_simple.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %clang_cl_asan -O0 %s -Fe%t
 // RUN: %run %t
 
 #include <windows.h>
diff --git a/test/asan/TestCases/Windows/thread_stack_array_left_oob.cc b/test/asan/TestCases/Windows/thread_stack_array_left_oob.cc
index 30e8ce0..17b9b1b 100644
--- a/test/asan/TestCases/Windows/thread_stack_array_left_oob.cc
+++ b/test/asan/TestCases/Windows/thread_stack_array_left_oob.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %clang_cl_asan -O0 %s -Fe%t
 // RUN: not %run %t 2>&1 | FileCheck %s
 
 #include <windows.h>
diff --git a/test/asan/TestCases/Windows/thread_stack_array_right_oob.cc b/test/asan/TestCases/Windows/thread_stack_array_right_oob.cc
index 365288d..601a1b8 100644
--- a/test/asan/TestCases/Windows/thread_stack_array_right_oob.cc
+++ b/test/asan/TestCases/Windows/thread_stack_array_right_oob.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %clang_cl_asan -O0 %s -Fe%t
 // RUN: not %run %t 2>&1 | FileCheck %s
 
 #include <windows.h>
diff --git a/test/asan/TestCases/Windows/thread_stack_reuse.cc b/test/asan/TestCases/Windows/thread_stack_reuse.cc
index 49611d9..7da3a80 100644
--- a/test/asan/TestCases/Windows/thread_stack_reuse.cc
+++ b/test/asan/TestCases/Windows/thread_stack_reuse.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %clang_cl_asan -O0 %s -Fe%t
 // RUN: %run %t
 
 #include <windows.h>
diff --git a/test/asan/TestCases/Windows/thread_stress.cc b/test/asan/TestCases/Windows/thread_stress.cc
index 3a0d9c5..74be8d8 100644
--- a/test/asan/TestCases/Windows/thread_stress.cc
+++ b/test/asan/TestCases/Windows/thread_stress.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %clang_cl_asan -O0 %s -Fe%t
 // RUN: %run %t
 
 #include <windows.h>
diff --git a/test/asan/TestCases/Windows/use_after_realloc.cc b/test/asan/TestCases/Windows/use_after_realloc.cc
index 6bd722b..9d2c025 100644
--- a/test/asan/TestCases/Windows/use_after_realloc.cc
+++ b/test/asan/TestCases/Windows/use_after_realloc.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %clang_cl_asan -O0 %s -Fe%t
 // RUN: not %run %t 2>&1 | FileCheck %s
 
 #include <malloc.h>
diff --git a/test/asan/TestCases/Windows/windows_h.cc b/test/asan/TestCases/Windows/windows_h.cc
index c221185..40cf5a1 100644
--- a/test/asan/TestCases/Windows/windows_h.cc
+++ b/test/asan/TestCases/Windows/windows_h.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %clang_cl_asan -O0 %s -Fe%t
 // RUN: %run %t
 
 // Just make sure we can parse <windows.h>
diff --git a/test/asan/TestCases/Windows/wrong_downcast_on_heap.cc b/test/asan/TestCases/Windows/wrong_downcast_on_heap.cc
index 0f43a6a..112dd53 100644
--- a/test/asan/TestCases/Windows/wrong_downcast_on_heap.cc
+++ b/test/asan/TestCases/Windows/wrong_downcast_on_heap.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %clang_cl_asan -O0 %s -Fe%t
 // RUN: not %run %t 2>&1 | FileCheck %s
 
 class Parent {
diff --git a/test/asan/TestCases/Windows/wrong_downcast_on_stack.cc b/test/asan/TestCases/Windows/wrong_downcast_on_stack.cc
index 02c9b9f..2859ecc 100644
--- a/test/asan/TestCases/Windows/wrong_downcast_on_stack.cc
+++ b/test/asan/TestCases/Windows/wrong_downcast_on_stack.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_asan -O0 %s -Fe%t
+// RUN: %clang_cl_asan -O0 %s -Fe%t
 // RUN: not %run %t 2>&1 | FileCheck %s
 
 class Parent {
diff --git a/test/asan/TestCases/current_allocated_bytes.cc b/test/asan/TestCases/current_allocated_bytes.cc
index a9cd159..c49e433 100644
--- a/test/asan/TestCases/current_allocated_bytes.cc
+++ b/test/asan/TestCases/current_allocated_bytes.cc
@@ -1,9 +1,10 @@
-// RUN: %clangxx_asan -O0 %s -lpthread -o %t && %run %t
-// RUN: %clangxx_asan -O2 %s -lpthread -o %t && %run %t
+// RUN: %clangxx_asan -O0 %s -pthread -o %t && %run %t
+// RUN: %clangxx_asan -O2 %s -pthread -o %t && %run %t
+// REQUIRES: stable-runtime
 
 #include <assert.h>
 #include <pthread.h>
-#include <sanitizer/asan_interface.h>
+#include <sanitizer/allocator_interface.h>
 #include <stdio.h>
 #include <stdlib.h>
 
@@ -16,12 +17,12 @@
 }
 
 void* check_stats(void *arg) {
-  assert(__asan_get_current_allocated_bytes() > 0);
+  assert(__sanitizer_get_current_allocated_bytes() > 0);
   return 0;
 }
 
 int main() {
-  size_t used_mem = __asan_get_current_allocated_bytes();
+  size_t used_mem = __sanitizer_get_current_allocated_bytes();
   printf("Before: %zu\n", used_mem);
   const int kNumIterations = 1000;
   for (int iter = 0; iter < kNumIterations; iter++) {
@@ -32,7 +33,7 @@
     }
     for (int j = 0; j < 4; j++)
       assert(0 == pthread_join(thr[j], 0));
-    used_mem = __asan_get_current_allocated_bytes();
+    used_mem = __sanitizer_get_current_allocated_bytes();
     if (used_mem > kLargeAlloc) {
       printf("After iteration %d: %zu\n", iter, used_mem);
       return 1;
diff --git a/test/asan/TestCases/deep_stack_uaf.cc b/test/asan/TestCases/deep_stack_uaf.cc
index 9ce27d5..accb70c 100644
--- a/test/asan/TestCases/deep_stack_uaf.cc
+++ b/test/asan/TestCases/deep_stack_uaf.cc
@@ -2,6 +2,7 @@
 
 // RUN: %clangxx_asan -O0 %s -o %t 2>&1
 // RUN: env ASAN_OPTIONS=malloc_context_size=120:redzone=512 not %run %t 2>&1 | FileCheck %s
+// XFAIL: arm-linux-gnueabi
 #include <stdlib.h>
 #include <stdio.h>
 
diff --git a/test/asan/TestCases/deep_thread_stack.cc b/test/asan/TestCases/deep_thread_stack.cc
index 1e802b0..535da79 100644
--- a/test/asan/TestCases/deep_thread_stack.cc
+++ b/test/asan/TestCases/deep_thread_stack.cc
@@ -1,7 +1,8 @@
-// RUN: %clangxx_asan -O0 %s -lpthread -o %t && not %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx_asan -O1 %s -lpthread -o %t && not %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx_asan -O2 %s -lpthread -o %t && not %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx_asan -O3 %s -lpthread -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O0 %s -pthread -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O1 %s -pthread -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O2 %s -pthread -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O3 %s -pthread -o %t && not %run %t 2>&1 | FileCheck %s
+// REQUIRES: stable-runtime
 
 #include <pthread.h>
 
diff --git a/test/asan/TestCases/default_blacklist.cc b/test/asan/TestCases/default_blacklist.cc
index 25a1ae1..9358cc4 100644
--- a/test/asan/TestCases/default_blacklist.cc
+++ b/test/asan/TestCases/default_blacklist.cc
@@ -1,3 +1,6 @@
+// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316
+// XFAIL: android
+//
 // Test that ASan uses the default blacklist from resource directory.
 // RUN: %clangxx_asan -### %s 2>&1 | FileCheck %s
 // CHECK: fsanitize-blacklist={{.*}}asan_blacklist.txt
diff --git a/test/asan/TestCases/default_options.cc b/test/asan/TestCases/default_options.cc
index c77dd49..6453f66 100644
--- a/test/asan/TestCases/default_options.cc
+++ b/test/asan/TestCases/default_options.cc
@@ -1,6 +1,9 @@
 // RUN: %clangxx_asan -O2 %s -o %t
 // RUN: %run %t 2>&1 | FileCheck %s
 
+// __asan_default_options() are not supported on Windows.
+// XFAIL: win32
+
 const char *kAsanDefaultOptions="verbosity=1 foo=bar";
 
 extern "C"
diff --git a/test/asan/TestCases/double-free.cc b/test/asan/TestCases/double-free.cc
index 6bbca24..212d7ea 100644
--- a/test/asan/TestCases/double-free.cc
+++ b/test/asan/TestCases/double-free.cc
@@ -4,6 +4,7 @@
 // Also works if no malloc context is available.
 // RUN: env ASAN_OPTIONS=malloc_context_size=0:fast_unwind_on_malloc=0 not %run %t 2>&1 | FileCheck %s
 // RUN: env ASAN_OPTIONS=malloc_context_size=0:fast_unwind_on_malloc=1 not %run %t 2>&1 | FileCheck %s
+// XFAIL: arm-linux-gnueabi
 
 #include <stdlib.h>
 #include <string.h>
diff --git a/test/asan/TestCases/free_hook_realloc.cc b/test/asan/TestCases/free_hook_realloc.cc
index 2040cad..4b27532 100644
--- a/test/asan/TestCases/free_hook_realloc.cc
+++ b/test/asan/TestCases/free_hook_realloc.cc
@@ -1,13 +1,18 @@
 // Check that free hook doesn't conflict with Realloc.
 // RUN: %clangxx_asan -O2 %s -o %t
 // RUN: %run %t 2>&1 | FileCheck %s
+
+// Malloc/free hooks are not supported on Windows.
+// XFAIL: win32
+
 #include <stdlib.h>
 #include <unistd.h>
+#include <sanitizer/allocator_interface.h>
 
 static void *glob_ptr;
 
 extern "C" {
-void __asan_free_hook(void *ptr) {
+void __sanitizer_free_hook(const volatile void *ptr) {
   if (ptr == glob_ptr) {
     *(int*)ptr = 0;
     write(1, "FreeHook\n", sizeof("FreeHook\n"));
diff --git a/test/asan/TestCases/frexp_interceptor.cc b/test/asan/TestCases/frexp_interceptor.cc
new file mode 100644
index 0000000..d75ba99
--- /dev/null
+++ b/test/asan/TestCases/frexp_interceptor.cc
@@ -0,0 +1,16 @@
+// RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
+
+// Test the frexp() interceptor.
+
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+int main() {
+  double x = 3.14;
+  int *exp = (int*)malloc(sizeof(int));
+  free(exp);
+  double y = frexp(x, exp);
+  // CHECK: use-after-free
+  // CHECK: SUMMARY
+  return 0;
+}
diff --git a/test/asan/TestCases/gc-test.cc b/test/asan/TestCases/gc-test.cc
index b15e668..ffbea85 100644
--- a/test/asan/TestCases/gc-test.cc
+++ b/test/asan/TestCases/gc-test.cc
@@ -1,6 +1,7 @@
-// RUN: %clangxx_asan %s -lpthread -o %t
+// RUN: %clangxx_asan %s -pthread -o %t
 // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=1 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK1
 // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %run %t 2>&1 | FileCheck %s --check-prefix=CHECK0
+// REQUIRES: stable-runtime
 
 #include <assert.h>
 #include <stdio.h>
diff --git a/test/asan/TestCases/global-demangle.cc b/test/asan/TestCases/global-demangle.cc
index 5f7ff91..2bfa0d1 100644
--- a/test/asan/TestCases/global-demangle.cc
+++ b/test/asan/TestCases/global-demangle.cc
@@ -1,3 +1,6 @@
+// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=264
+// XFAIL: android
+//
 // RUN: %clangxx_asan -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
 
 namespace XXX {
diff --git a/test/asan/TestCases/global-location.cc b/test/asan/TestCases/global-location.cc
new file mode 100644
index 0000000..54f2055
--- /dev/null
+++ b/test/asan/TestCases/global-location.cc
@@ -0,0 +1,41 @@
+// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=264
+// XFAIL: android
+
+// RUN: %clangxx_asan -O2 %s -o %t
+// RUN: not %run %t g 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=GLOB
+// RUN: not %run %t c 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CLASS_STATIC
+// RUN: not %run %t f 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=FUNC_STATIC
+// RUN: not %run %t l 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=LITERAL
+
+// CHECK: AddressSanitizer: global-buffer-overflow
+
+#include <string.h>
+
+struct C {
+  static int array[10];
+};
+
+int global[10];
+// GLOB: 0x{{.*}} is located 4 bytes to the right of global variable 'global' defined in '{{.*}}global-location.cc:[[@LINE-1]]:5' {{.*}} of size 40
+int C::array[10];
+// CLASS_STATIC: 0x{{.*}} is located 4 bytes to the right of global variable 'C::array' defined in '{{.*}}global-location.cc:[[@LINE-1]]:8' {{.*}} of size 40
+
+int main(int argc, char **argv) {
+  int one = argc - 1;
+  switch (argv[1][0]) {
+  case 'g': return global[one * 11];
+  case 'c': return C::array[one * 11];
+  case 'f':
+    static int array[10];
+    // FUNC_STATIC: 0x{{.*}} is located 4 bytes to the right of global variable 'main::array' defined in '{{.*}}global-location.cc:[[@LINE-1]]:16' {{.*}} of size 40
+    memset(array, 0, 10);
+    return array[one * 11];
+  case 'l':
+    const char *str = "0123456789";
+    // LITERAL: 0x{{.*}} is located 0 bytes to the right of global variable {{.*}} defined in '{{.*}}global-location.cc:[[@LINE-1]]:23' {{.*}} of size 11
+    return str[one * 11];
+  }
+  return 0;
+}
+
+// CHECK: SUMMARY: AddressSanitizer: global-buffer-overflow
diff --git a/test/asan/TestCases/init-order-atexit.cc b/test/asan/TestCases/init-order-atexit.cc
index c4defaf..e0dac32 100644
--- a/test/asan/TestCases/init-order-atexit.cc
+++ b/test/asan/TestCases/init-order-atexit.cc
@@ -1,3 +1,6 @@
+// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316
+// XFAIL: android
+//
 // Test for the following situation:
 // (1) global A is constructed.
 // (2) exit() is called during construction of global B.
diff --git a/test/asan/TestCases/init-order-pthread-create.cc b/test/asan/TestCases/init-order-pthread-create.cc
index e333436..eeff308 100644
--- a/test/asan/TestCases/init-order-pthread-create.cc
+++ b/test/asan/TestCases/init-order-pthread-create.cc
@@ -1,7 +1,7 @@
 // Check that init-order checking is properly disabled if pthread_create is
 // called.
 
-// RUN: %clangxx_asan %s %p/Helpers/init-order-pthread-create-extra.cc -lpthread -o %t
+// RUN: %clangxx_asan %s %p/Helpers/init-order-pthread-create-extra.cc -pthread -o %t
 // RUN: env ASAN_OPTIONS=strict_init_order=true %run %t
 
 #include <stdio.h>
diff --git a/test/asan/TestCases/initialization-blacklist.cc b/test/asan/TestCases/initialization-blacklist.cc
index 42c78fa..8ea6b46 100644
--- a/test/asan/TestCases/initialization-blacklist.cc
+++ b/test/asan/TestCases/initialization-blacklist.cc
@@ -2,18 +2,15 @@
 
 // RUN: %clangxx_asan -O0 %s %p/Helpers/initialization-blacklist-extra.cc\
 // RUN:   %p/Helpers/initialization-blacklist-extra2.cc \
-// RUN:   -fsanitize-blacklist=%p/Helpers/initialization-blacklist.txt \
-// RUN:   -fsanitize=init-order -o %t
+// RUN:   -fsanitize-blacklist=%p/Helpers/initialization-blacklist.txt -o %t
 // RUN: env ASAN_OPTIONS=check_initialization_order=true %run %t 2>&1
 // RUN: %clangxx_asan -O1 %s %p/Helpers/initialization-blacklist-extra.cc\
 // RUN:   %p/Helpers/initialization-blacklist-extra2.cc \
-// RUN:   -fsanitize-blacklist=%p/Helpers/initialization-blacklist.txt \
-// RUN:   -fsanitize=init-order -o %t
+// RUN:   -fsanitize-blacklist=%p/Helpers/initialization-blacklist.txt -o %t
 // RUN: env ASAN_OPTIONS=check_initialization_order=true %run %t 2>&1
 // RUN: %clangxx_asan -O2 %s %p/Helpers/initialization-blacklist-extra.cc\
 // RUN:   %p/Helpers/initialization-blacklist-extra2.cc \
-// RUN:   -fsanitize-blacklist=%p/Helpers/initialization-blacklist.txt \
-// RUN:   -fsanitize=init-order -o %t
+// RUN:   -fsanitize-blacklist=%p/Helpers/initialization-blacklist.txt -o %t
 // RUN: env ASAN_OPTIONS=check_initialization_order=true %run %t 2>&1
 
 // Function is defined in another TU.
diff --git a/test/asan/TestCases/initialization-constexpr.cc b/test/asan/TestCases/initialization-constexpr.cc
index f964888..6442461 100644
--- a/test/asan/TestCases/initialization-constexpr.cc
+++ b/test/asan/TestCases/initialization-constexpr.cc
@@ -4,17 +4,13 @@
 // constructor implies that it was initialized during constant initialization,
 // not dynamic initialization).
 
-// RUN: %clangxx_asan -O0 %s %p/Helpers/initialization-constexpr-extra.cc\
-// RUN:   --std=c++11 -fsanitize=init-order -o %t
+// RUN: %clangxx_asan -O0 %s %p/Helpers/initialization-constexpr-extra.cc --std=c++11 -o %t
 // RUN: env ASAN_OPTIONS=check_initialization_order=true %run %t 2>&1
-// RUN: %clangxx_asan -O1 %s %p/Helpers/initialization-constexpr-extra.cc\
-// RUN:   --std=c++11 -fsanitize=init-order -o %t
+// RUN: %clangxx_asan -O1 %s %p/Helpers/initialization-constexpr-extra.cc --std=c++11 -o %t
 // RUN: env ASAN_OPTIONS=check_initialization_order=true %run %t 2>&1
-// RUN: %clangxx_asan -O2 %s %p/Helpers/initialization-constexpr-extra.cc\
-// RUN:   --std=c++11 -fsanitize=init-order -o %t
+// RUN: %clangxx_asan -O2 %s %p/Helpers/initialization-constexpr-extra.cc --std=c++11 -o %t
 // RUN: env ASAN_OPTIONS=check_initialization_order=true %run %t 2>&1
-// RUN: %clangxx_asan -O3 %s %p/Helpers/initialization-constexpr-extra.cc\
-// RUN:   --std=c++11 -fsanitize=init-order -o %t
+// RUN: %clangxx_asan -O3 %s %p/Helpers/initialization-constexpr-extra.cc --std=c++11 -o %t
 // RUN: env ASAN_OPTIONS=check_initialization_order=true %run %t 2>&1
 
 class Integer {
diff --git a/test/asan/TestCases/initialization-nobug.cc b/test/asan/TestCases/initialization-nobug.cc
index 87c5dc8..1249deb 100644
--- a/test/asan/TestCases/initialization-nobug.cc
+++ b/test/asan/TestCases/initialization-nobug.cc
@@ -1,13 +1,13 @@
 // A collection of various initializers which shouldn't trip up initialization
 // order checking.  If successful, this will just return 0.
 
-// RUN: %clangxx_asan -O0 %s %p/Helpers/initialization-nobug-extra.cc -fsanitize=init-order -o %t
+// RUN: %clangxx_asan -O0 %s %p/Helpers/initialization-nobug-extra.cc -o %t
 // RUN: env ASAN_OPTIONS=check_initialization_order=true %run %t 2>&1
-// RUN: %clangxx_asan -O1 %s %p/Helpers/initialization-nobug-extra.cc -fsanitize=init-order -o %t
+// RUN: %clangxx_asan -O1 %s %p/Helpers/initialization-nobug-extra.cc -o %t
 // RUN: env ASAN_OPTIONS=check_initialization_order=true %run %t 2>&1
-// RUN: %clangxx_asan -O2 %s %p/Helpers/initialization-nobug-extra.cc -fsanitize=init-order -o %t
+// RUN: %clangxx_asan -O2 %s %p/Helpers/initialization-nobug-extra.cc -o %t
 // RUN: env ASAN_OPTIONS=check_initialization_order=true %run %t 2>&1
-// RUN: %clangxx_asan -O3 %s %p/Helpers/initialization-nobug-extra.cc -fsanitize=init-order -o %t
+// RUN: %clangxx_asan -O3 %s %p/Helpers/initialization-nobug-extra.cc -o %t
 // RUN: env ASAN_OPTIONS=check_initialization_order=true %run %t 2>&1
 
 // Simple access:
diff --git a/test/asan/TestCases/invalid-free.cc b/test/asan/TestCases/invalid-free.cc
index fdfec73..34018fb 100644
--- a/test/asan/TestCases/invalid-free.cc
+++ b/test/asan/TestCases/invalid-free.cc
@@ -4,6 +4,7 @@
 // Also works if no malloc context is available.
 // RUN: env ASAN_OPTIONS=malloc_context_size=0:fast_unwind_on_malloc=0 not %run %t 2>&1 | FileCheck %s
 // RUN: env ASAN_OPTIONS=malloc_context_size=0:fast_unwind_on_malloc=1 not %run %t 2>&1 | FileCheck %s
+// XFAIL: arm-linux-gnueabi
 
 #include <stdlib.h>
 #include <string.h>
diff --git a/test/asan/TestCases/large_func_test.cc b/test/asan/TestCases/large_func_test.cc
index bdd6f8f..0d651f6 100644
--- a/test/asan/TestCases/large_func_test.cc
+++ b/test/asan/TestCases/large_func_test.cc
@@ -2,6 +2,7 @@
 // RUN: %clangxx_asan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK
 // RUN: %clangxx_asan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK
 // RUN: %clangxx_asan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK
+// XFAIL: arm-linux-gnueabi
 
 #include <stdlib.h>
 __attribute__((noinline))
diff --git a/test/asan/TestCases/log-path_test.cc b/test/asan/TestCases/log-path_test.cc
index cac0c5f..5a1d072 100644
--- a/test/asan/TestCases/log-path_test.cc
+++ b/test/asan/TestCases/log-path_test.cc
@@ -1,3 +1,6 @@
+// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316
+// XFAIL: android
+//
 // RUN: %clangxx_asan  %s -o %t
 
 // Regular run.
@@ -23,6 +26,8 @@
 // RUN: env ASAN_OPTIONS=log_path=%t.log  %run %t ARG ARG ARG
 // RUN: not cat %t.log.*
 
+// FIXME: log_path is not supported on Windows yet.
+// XFAIL: win32
 
 #include <stdlib.h>
 #include <string.h>
diff --git a/test/asan/TestCases/lsan_annotations.cc b/test/asan/TestCases/lsan_annotations.cc
index f52b0ff..84c2878 100644
--- a/test/asan/TestCases/lsan_annotations.cc
+++ b/test/asan/TestCases/lsan_annotations.cc
@@ -1,3 +1,6 @@
+// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316
+// XFAIL: android
+//
 // Check that LSan annotations work fine.
 // RUN: %clangxx_asan -O0 %s -o %t && %run %t
 // RUN: %clangxx_asan -O3 %s -o %t && %run %t
diff --git a/test/asan/TestCases/malloc_context_size.cc b/test/asan/TestCases/malloc_context_size.cc
index 9f7ba40..fb158c6 100644
--- a/test/asan/TestCases/malloc_context_size.cc
+++ b/test/asan/TestCases/malloc_context_size.cc
@@ -16,12 +16,16 @@
   // CHECK-Linux-NEXT: #0 0x{{.*}} in operator delete[]
   // CHECK-Darwin: freed by thread T{{.*}} here:
   // CHECK-Darwin-NEXT: #0 0x{{.*}} in wrap__ZdaPv
+  // CHECK-Windows: freed by thread T{{.*}} here:
+  // CHECK-Windows-NEXT: #0 0x{{.*}} in operator delete[]
   // CHECK-NOT: #1 0x{{.*}}
 
   // CHECK-Linux: previously allocated by thread T{{.*}} here:
   // CHECK-Linux-NEXT: #0 0x{{.*}} in operator new[]
   // CHECK-Darwin: previously allocated by thread T{{.*}} here:
   // CHECK-Darwin-NEXT: #0 0x{{.*}} in wrap__Znam
+  // CHECK-Windows: previously allocated by thread T{{.*}} here:
+  // CHECK-Windows-NEXT: #0 0x{{.*}} in operator new[]
   // CHECK-NOT: #1 0x{{.*}}
 
   // CHECK: SUMMARY: AddressSanitizer: heap-use-after-free
diff --git a/test/asan/TestCases/malloc_hook.cc b/test/asan/TestCases/malloc_hook.cc
deleted file mode 100644
index c535ef8..0000000
--- a/test/asan/TestCases/malloc_hook.cc
+++ /dev/null
@@ -1,36 +0,0 @@
-// RUN: %clangxx_asan -O2 %s -o %t
-// RUN: %run %t 2>&1 | FileCheck %s
-#include <stdlib.h>
-#include <unistd.h>
-
-extern "C" {
-bool __asan_get_ownership(const void *p);
-
-void *global_ptr;
-
-// Note: avoid calling functions that allocate memory in malloc/free
-// to avoid infinite recursion.
-void __asan_malloc_hook(void *ptr, size_t sz) {
-  if (__asan_get_ownership(ptr)) {
-    write(1, "MallocHook\n", sizeof("MallocHook\n"));
-    global_ptr = ptr;
-  }
-}
-void __asan_free_hook(void *ptr) {
-  if (__asan_get_ownership(ptr) && ptr == global_ptr)
-    write(1, "FreeHook\n", sizeof("FreeHook\n"));
-}
-}  // extern "C"
-
-int main() {
-  volatile int *x = new int;
-  // CHECK: MallocHook
-  // Check that malloc hook was called with correct argument.
-  if (global_ptr != (void*)x) {
-    _exit(1);
-  }
-  *x = 0;
-  delete x;
-  // CHECK: FreeHook
-  return 0;
-}
diff --git a/test/asan/TestCases/max_redzone.cc b/test/asan/TestCases/max_redzone.cc
index f2c0dee..01c25a9 100644
--- a/test/asan/TestCases/max_redzone.cc
+++ b/test/asan/TestCases/max_redzone.cc
@@ -8,17 +8,17 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <stdint.h>
-#include <sanitizer/asan_interface.h>
+#include <sanitizer/allocator_interface.h>
 
 int main(int argc, char **argv) {
   if (argc < 2)
     return 1;
   bool large_redzone = atoi(argv[1]);
-  size_t before = __asan_get_heap_size();
+  size_t before = __sanitizer_get_heap_size();
   void *pp[10000];
   for (int i = 0; i < 10000; ++i)
     pp[i] = malloc(4096 - 64);
-  size_t after = __asan_get_heap_size();
+  size_t after = __sanitizer_get_heap_size();
   for (int i = 0; i < 10000; ++i)
     free(pp[i]);
   size_t diff = after - before;
diff --git a/test/asan/TestCases/mmap_limit_mb.cc b/test/asan/TestCases/mmap_limit_mb.cc
index 5fc0295..1d697ef 100644
--- a/test/asan/TestCases/mmap_limit_mb.cc
+++ b/test/asan/TestCases/mmap_limit_mb.cc
@@ -7,6 +7,7 @@
 // RUN: env ASAN_OPTIONS=mmap_limit_mb=500 %run %t 50 1000000
 // RUN: env ASAN_OPTIONS=mmap_limit_mb=500 not %run %t 500 16 2>&1 | FileCheck %s
 // RUN: env ASAN_OPTIONS=mmap_limit_mb=500 not %run %t 500 1000000 2>&1 | FileCheck %s
+// XFAIL: arm-linux-gnueabi
 
 #include <assert.h>
 #include <stdlib.h>
diff --git a/test/asan/TestCases/no_asan_gen_globals.c b/test/asan/TestCases/no_asan_gen_globals.c
index a747d7a..0a383da 100644
--- a/test/asan/TestCases/no_asan_gen_globals.c
+++ b/test/asan/TestCases/no_asan_gen_globals.c
@@ -1,3 +1,6 @@
+// FIXME: https://code.google.com/p/address-sanitizer/issues/detail?id=316
+// XFAIL: android
+//
 // Make sure __asan_gen_* strings do not end up in the symbol table.
 
 // RUN: %clang_asan %s -o %t.exe
diff --git a/test/asan/TestCases/on_error_callback.cc b/test/asan/TestCases/on_error_callback.cc
index 0ad83d5..c378c8b 100644
--- a/test/asan/TestCases/on_error_callback.cc
+++ b/test/asan/TestCases/on_error_callback.cc
@@ -1,5 +1,8 @@
 // RUN: %clangxx_asan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s
 
+// FIXME: __asan_on_error() is not supported on Windows yet.
+// XFAIL: win32
+
 #include <stdio.h>
 #include <stdlib.h>
 
diff --git a/test/asan/TestCases/printf-1.c b/test/asan/TestCases/printf-1.c
index dee00a5..5657083 100644
--- a/test/asan/TestCases/printf-1.c
+++ b/test/asan/TestCases/printf-1.c
@@ -4,6 +4,10 @@
 // RUN: %run %t 2>&1 | FileCheck %s
 
 #include <stdio.h>
+#if defined(_WIN32)
+# define snprintf _snprintf
+#endif
+
 int main() {
   volatile char c = '0';
   volatile int x = 12;
diff --git a/test/asan/TestCases/printf-2.c b/test/asan/TestCases/printf-2.c
index f12c0b7..e9cb47e 100644
--- a/test/asan/TestCases/printf-2.c
+++ b/test/asan/TestCases/printf-2.c
@@ -5,6 +5,9 @@
 // RUN: env ASAN_OPTIONS=replace_str=0:replace_intrin=0:check_printf=0 %run %t 2>&1 | FileCheck --check-prefix=CHECK-OFF %s
 // RUN: env ASAN_OPTIONS=replace_str=0:replace_intrin=0 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s
 
+// FIXME: printf is not intercepted on Windows yet.
+// XFAIL: win32
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
diff --git a/test/asan/TestCases/printf-3.c b/test/asan/TestCases/printf-3.c
index 387f6d5..d16833d 100644
--- a/test/asan/TestCases/printf-3.c
+++ b/test/asan/TestCases/printf-3.c
@@ -3,6 +3,9 @@
 // RUN: env ASAN_OPTIONS=check_printf=0 %run %t 2>&1 | FileCheck --check-prefix=CHECK-OFF %s
 // RUN: not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s
 
+// FIXME: printf is not intercepted on Windows yet.
+// XFAIL: win32
+
 #include <stdio.h>
 int main() {
   volatile char c = '0';
diff --git a/test/asan/TestCases/printf-4.c b/test/asan/TestCases/printf-4.c
index b219d6f..e269211 100644
--- a/test/asan/TestCases/printf-4.c
+++ b/test/asan/TestCases/printf-4.c
@@ -4,6 +4,9 @@
 // RUN: env ASAN_OPTIONS=replace_str=0:replace_intrin=0:check_printf=1 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s
 // RUN: env ASAN_OPTIONS=replace_str=0:replace_intrin=0 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s
 
+// FIXME: printf is not intercepted on Windows yet.
+// XFAIL: win32
+
 #include <stdio.h>
 int main() {
   volatile char c = '0';
diff --git a/test/asan/TestCases/printf-5.c b/test/asan/TestCases/printf-5.c
index 5bb43cb..ac2c1c4 100644
--- a/test/asan/TestCases/printf-5.c
+++ b/test/asan/TestCases/printf-5.c
@@ -4,6 +4,9 @@
 // RUN: env ASAN_OPTIONS=replace_intrin=0:check_printf=0 %run %t 2>&1 | FileCheck --check-prefix=CHECK-OFF %s
 // RUN: env ASAN_OPTIONS=replace_intrin=0 not %run %t 2>&1 | FileCheck --check-prefix=CHECK-ON %s
 
+// FIXME: printf is not intercepted on Windows yet.
+// XFAIL: win32
+
 #include <stdio.h>
 #include <string.h>
 int main() {
diff --git a/test/asan/TestCases/sanity_check_pure_c.c b/test/asan/TestCases/sanity_check_pure_c.c
index 0ec86af..01d87e7 100644
--- a/test/asan/TestCases/sanity_check_pure_c.c
+++ b/test/asan/TestCases/sanity_check_pure_c.c
@@ -5,6 +5,7 @@
 // Sanity checking a test in pure C with -pie.
 // RUN: %clang_asan -O2 %s -pie -fPIE -o %t
 // RUN: not %run %t 2>&1 | FileCheck %s
+// XFAIL: arm-linux-gnueabi
 
 #include <stdlib.h>
 int main() {
diff --git a/test/asan/TestCases/stack-overflow.cc b/test/asan/TestCases/stack-overflow.cc
index 4861fd2..234e3c7 100644
--- a/test/asan/TestCases/stack-overflow.cc
+++ b/test/asan/TestCases/stack-overflow.cc
@@ -1,19 +1,20 @@
 // Test ASan detection of stack-overflow condition.
 
-// RUN: %clangxx_asan -O0 %s -DSMALL_FRAME -lpthread -o %t && env ASAN_OPTIONS=use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx_asan -O3 %s -DSMALL_FRAME -lpthread -o %t && env ASAN_OPTIONS=use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx_asan -O0 %s -DSAVE_ALL_THE_REGISTERS -lpthread -o %t && env ASAN_OPTIONS=use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx_asan -O3 %s -DSAVE_ALL_THE_REGISTERS -lpthread -o %t && env ASAN_OPTIONS=use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx_asan -O0 %s -lpthread -o %t && env ASAN_OPTIONS=use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx_asan -O3 %s -lpthread -o %t && env ASAN_OPTIONS=use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O0 %s -DSMALL_FRAME -pthread -o %t && env ASAN_OPTIONS=use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O3 %s -DSMALL_FRAME -pthread -o %t && env ASAN_OPTIONS=use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O0 %s -DSAVE_ALL_THE_REGISTERS -pthread -o %t && env ASAN_OPTIONS=use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O3 %s -DSAVE_ALL_THE_REGISTERS -pthread -o %t && env ASAN_OPTIONS=use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O0 %s -pthread -o %t && env ASAN_OPTIONS=use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O3 %s -pthread -o %t && env ASAN_OPTIONS=use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
 
-// RUN: %clangxx_asan -O0 %s -DTHREAD -DSMALL_FRAME -lpthread -o %t && env ASAN_OPTIONS=use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx_asan -O3 %s -DTHREAD -DSMALL_FRAME -lpthread -o %t && env ASAN_OPTIONS=use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx_asan -O0 %s -DTHREAD -DSAVE_ALL_THE_REGISTERS -lpthread -o %t && env ASAN_OPTIONS=use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx_asan -O3 %s -DTHREAD -DSAVE_ALL_THE_REGISTERS -lpthread -o %t && env ASAN_OPTIONS=use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx_asan -O0 %s -DTHREAD -lpthread -o %t && env ASAN_OPTIONS=use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx_asan -O3 %s -DTHREAD -lpthread -o %t && env ASAN_OPTIONS=use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O0 %s -DTHREAD -DSMALL_FRAME -pthread -o %t && env ASAN_OPTIONS=use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O3 %s -DTHREAD -DSMALL_FRAME -pthread -o %t && env ASAN_OPTIONS=use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O0 %s -DTHREAD -DSAVE_ALL_THE_REGISTERS -pthread -o %t && env ASAN_OPTIONS=use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O3 %s -DTHREAD -DSAVE_ALL_THE_REGISTERS -pthread -o %t && env ASAN_OPTIONS=use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O0 %s -DTHREAD -pthread -o %t && env ASAN_OPTIONS=use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan -O3 %s -DTHREAD -pthread -o %t && env ASAN_OPTIONS=use_sigaltstack=1 not %run %t 2>&1 | FileCheck %s
 // RUN: not %run %t 2>&1 | FileCheck %s
+// REQUIRES: stable-runtime
 
 #include <assert.h>
 #include <stdlib.h>
diff --git a/test/asan/TestCases/stack-use-after-return.cc b/test/asan/TestCases/stack-use-after-return.cc
index e31a63c..437c457 100644
--- a/test/asan/TestCases/stack-use-after-return.cc
+++ b/test/asan/TestCases/stack-use-after-return.cc
@@ -1,14 +1,14 @@
 // RUN: export ASAN_OPTIONS=detect_stack_use_after_return=1
-// RUN: %clangxx_asan  -O0 %s -lpthread -o %t && not %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx_asan  -O1 %s -lpthread -o %t && not %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx_asan  -O2 %s -lpthread -o %t && not %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx_asan  -O3 %s -lpthread -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan  -O0 %s -pthread -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan  -O1 %s -pthread -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan  -O2 %s -pthread -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_asan  -O3 %s -pthread -o %t && not %run %t 2>&1 | FileCheck %s
 // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %run %t
 // Regression test for a CHECK failure with small stack size and large frame.
-// RUN: %clangxx_asan  -O3 %s -lpthread -o %t -DkSize=10000 -DUseThread -DkStackSize=65536 && not %run %t 2>&1 | FileCheck --check-prefix=THREAD %s
+// RUN: %clangxx_asan  -O3 %s -pthread -o %t -DkSize=10000 -DUseThread -DkStackSize=65536 && not %run %t 2>&1 | FileCheck --check-prefix=THREAD %s
 //
 // Test that we can find UAR in a thread other than main:
-// RUN: %clangxx_asan  -DUseThread -O2 %s -lpthread -o %t && not %run %t 2>&1 | FileCheck --check-prefix=THREAD %s
+// RUN: %clangxx_asan  -DUseThread -O2 %s -pthread -o %t && not %run %t 2>&1 | FileCheck --check-prefix=THREAD %s
 //
 // Test the max_uar_stack_size_log/min_uar_stack_size_log flag.
 //
diff --git a/test/asan/TestCases/strdup_oob_test.cc b/test/asan/TestCases/strdup_oob_test.cc
index 7716ee5..a039568 100644
--- a/test/asan/TestCases/strdup_oob_test.cc
+++ b/test/asan/TestCases/strdup_oob_test.cc
@@ -12,8 +12,9 @@
   int x = copy[4 + argc];  // BOOM
   // CHECK: AddressSanitizer: heap-buffer-overflow
   // CHECK: #0 {{.*}}main {{.*}}strdup_oob_test.cc:[[@LINE-2]]
-  // CHECK: allocated by thread T{{.*}} here:
-  // CHECK: #0 {{.*}}strdup
+  // CHECK-LABEL: allocated by thread T{{.*}} here:
+  // CHECK: #{{[01]}} {{.*}}strdup
+  // CHECK-LABEL: SUMMARY
   // CHECK: strdup_oob_test.cc:[[@LINE-6]]
   return x;
 }
diff --git a/test/asan/TestCases/strncpy-overflow.cc b/test/asan/TestCases/strncpy-overflow.cc
index 0d70b79..8001047 100644
--- a/test/asan/TestCases/strncpy-overflow.cc
+++ b/test/asan/TestCases/strncpy-overflow.cc
@@ -4,6 +4,7 @@
 // RUN: %clangxx_asan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK
 
 // REQUIRES: compiler-rt-optimized
+// XFAIL: arm-linux-gnueabi
 
 #include <string.h>
 #include <stdlib.h>
diff --git a/test/asan/TestCases/throw_call_test.cc b/test/asan/TestCases/throw_call_test.cc
index dff112f..20e9a5e 100644
--- a/test/asan/TestCases/throw_call_test.cc
+++ b/test/asan/TestCases/throw_call_test.cc
@@ -5,6 +5,9 @@
 // Android builds with static libstdc++ by default.
 // XFAIL: android
 
+// Clang doesn't support exceptions on Windows yet.
+// XFAIL: win32
+
 #include <stdio.h>
 static volatile int zero = 0;
 inline void pretend_to_do_something(void *x) {
diff --git a/test/asan/TestCases/throw_catch.cc b/test/asan/TestCases/throw_catch.cc
index bb41946..f35378d 100644
--- a/test/asan/TestCases/throw_catch.cc
+++ b/test/asan/TestCases/throw_catch.cc
@@ -1,5 +1,8 @@
 // RUN: %clangxx_asan -O %s -o %t && %run %t
 
+// Clang doesn't support exceptions on Windows yet.
+// XFAIL: win32
+
 #include <assert.h>
 #include <setjmp.h>
 #include <stdlib.h>
diff --git a/test/asan/TestCases/throw_invoke_test.cc b/test/asan/TestCases/throw_invoke_test.cc
index 2fc557d..ec48fc7 100644
--- a/test/asan/TestCases/throw_invoke_test.cc
+++ b/test/asan/TestCases/throw_invoke_test.cc
@@ -1,5 +1,9 @@
 // RUN: %clangxx_asan %s -o %t && %run %t
 // RUN: %clangxx_asan %s -o %t -static-libstdc++ && %run %t
+
+// Clang doesn't support exceptions on Windows yet.
+// XFAIL: win32
+
 #include <stdio.h>
 static volatile int zero = 0;
 inline void pretend_to_do_something(void *x) {
diff --git a/test/asan/TestCases/time_interceptor.cc b/test/asan/TestCases/time_interceptor.cc
index 4fbd433..89b2183 100644
--- a/test/asan/TestCases/time_interceptor.cc
+++ b/test/asan/TestCases/time_interceptor.cc
@@ -2,6 +2,9 @@
 
 // Test the time() interceptor.
 
+// There's no interceptor for time() on Windows yet.
+// XFAIL: win32
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <time.h>
@@ -12,5 +15,8 @@
   time_t t = time(tm);
   printf("Time: %s\n", ctime(&t));  // NOLINT
   // CHECK: use-after-free
+  // Regression check for
+  // https://code.google.com/p/address-sanitizer/issues/detail?id=321
+  // CHECK: SUMMARY
   return 0;
 }
diff --git a/test/asan/TestCases/uar_and_exceptions.cc b/test/asan/TestCases/uar_and_exceptions.cc
index 2e0c864..0bfe297 100644
--- a/test/asan/TestCases/uar_and_exceptions.cc
+++ b/test/asan/TestCases/uar_and_exceptions.cc
@@ -2,6 +2,9 @@
 // export ASAN_OPTIONS=detect_stack_use_after_return=1
 // RUN: %clangxx_asan  -O0 %s -o %t && %run %t
 
+// Clang doesn't support exceptions on Windows yet.
+// XFAIL: win32
+
 #include <stdio.h>
 
 volatile char *g;
diff --git a/test/asan/TestCases/use-after-delete.cc b/test/asan/TestCases/use-after-delete.cc
index 7696e18..f22e9e5 100644
--- a/test/asan/TestCases/use-after-delete.cc
+++ b/test/asan/TestCases/use-after-delete.cc
@@ -2,6 +2,7 @@
 // RUN: %clangxx_asan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK
 // RUN: %clangxx_asan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK
 // RUN: %clangxx_asan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK
+// XFAIL: arm-linux-gnueabi
 
 #include <stdlib.h>
 int main() {
diff --git a/test/asan/TestCases/use-after-free-right.cc b/test/asan/TestCases/use-after-free-right.cc
index 16c4348..68ac158 100644
--- a/test/asan/TestCases/use-after-free-right.cc
+++ b/test/asan/TestCases/use-after-free-right.cc
@@ -2,6 +2,7 @@
 // RUN: %clangxx_asan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK
 // RUN: %clangxx_asan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK
 // RUN: %clangxx_asan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK
+// XFAIL: arm-linux-gnueabi
 
 // Test use-after-free report in the case when access is at the right border of
 // the allocation.
diff --git a/test/asan/TestCases/use-after-free.cc b/test/asan/TestCases/use-after-free.cc
index 7f77aac..0cd87ee 100644
--- a/test/asan/TestCases/use-after-free.cc
+++ b/test/asan/TestCases/use-after-free.cc
@@ -2,6 +2,7 @@
 // RUN: %clangxx_asan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK
 // RUN: %clangxx_asan -O2 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK
 // RUN: %clangxx_asan -O3 %s -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-%os --check-prefix=CHECK
+// XFAIL: arm-linux-gnueabi
 
 #include <stdlib.h>
 int main() {
diff --git a/test/asan/TestCases/use-after-scope-dtor-order.cc b/test/asan/TestCases/use-after-scope-dtor-order.cc
index b045888..7896dd3 100644
--- a/test/asan/TestCases/use-after-scope-dtor-order.cc
+++ b/test/asan/TestCases/use-after-scope-dtor-order.cc
@@ -1,5 +1,6 @@
 // RUN: %clangxx_asan -O0 -fsanitize=use-after-scope %s -o %t && \
 // RUN:     not %run %t 2>&1 | FileCheck %s
+// XFAIL: *
 #include <stdio.h>
 
 struct IntHolder {
diff --git a/test/asan/TestCases/use-after-scope-inlined.cc b/test/asan/TestCases/use-after-scope-inlined.cc
index 7e57a63..a0a0d94 100644
--- a/test/asan/TestCases/use-after-scope-inlined.cc
+++ b/test/asan/TestCases/use-after-scope-inlined.cc
@@ -3,6 +3,7 @@
 // llvm.lifetime intrinsics at -O0.
 //
 // RUN: %clangxx_asan -O2 -fsanitize=use-after-scope %s -o %t && not %run %t 2>&1 | FileCheck %s
+// XFAIL: *
 
 int *arr;
 
diff --git a/test/asan/TestCases/use-after-scope-nobug.cc b/test/asan/TestCases/use-after-scope-nobug.cc
index 0a1bbfe..21b085c 100644
--- a/test/asan/TestCases/use-after-scope-nobug.cc
+++ b/test/asan/TestCases/use-after-scope-nobug.cc
@@ -1,4 +1,5 @@
 // RUN: %clangxx_asan -O0 -fsanitize=use-after-scope %s -o %t && %run %t
+// XFAIL: *
 
 #include <stdio.h>
 
diff --git a/test/asan/TestCases/use-after-scope.cc b/test/asan/TestCases/use-after-scope.cc
index 49f756c..f98a8e6 100644
--- a/test/asan/TestCases/use-after-scope.cc
+++ b/test/asan/TestCases/use-after-scope.cc
@@ -1,6 +1,7 @@
 // RUN: %clangxx_asan -O0 -fsanitize=use-after-scope %s -o %t && \
 // RUN: not %run %t 2>&1 | FileCheck %s
 // RUN: env ASAN_OPTIONS="detect_stack_use_after_return=1" not %run %t 2>&1 | FileCheck %s
+// XFAIL: *
 
 int main() {
   int *p = 0;
diff --git a/test/asan/android_commands/android_run.py b/test/asan/android_commands/android_run.py
index a6ceeb4..7f8c612 100755
--- a/test/asan/android_commands/android_run.py
+++ b/test/asan/android_commands/android_run.py
@@ -23,7 +23,7 @@
 device_stdout = device_binary + '.stdout'
 device_stderr = device_binary + '.stderr'
 device_exitcode = device_binary + '.exitcode'
-ret = adb(['shell', 'cd %s && %s %s %s >%s 2>%s ; echo $? >%s' %
+ret = adb(['shell', 'cd %s && %s asanwrapper %s %s >%s 2>%s ; echo $? >%s' %
            (ANDROID_TMPDIR, device_env, device_binary, device_args,
             device_stdout, device_stderr, device_exitcode)])
 if ret != 0:
diff --git a/test/asan/lit.cfg b/test/asan/lit.cfg
index ef51266..db2459f 100644
--- a/test/asan/lit.cfg
+++ b/test/asan/lit.cfg
@@ -1,6 +1,7 @@
 # -*- Python -*-
 
 import os
+import platform
 
 def get_required_attr(config, attr_name):
   attr_value = getattr(config, attr_name, None)
@@ -25,26 +26,18 @@
 # GCC-ASan doesn't link in all the necessary libraries automatically, so
 # we have to do it ourselves.
 if config.compiler_id == 'GNU':
-  extra_linkflags = ["-lpthread", "-lstdc++", "-ldl"]
+  extra_linkflags = ["-pthread", "-lstdc++", "-ldl"]
 else:
   extra_linkflags = []
 # Setup default compiler flags used with -fsanitize=address option.
 # FIXME: Review the set of required flags and check if it can be reduced.
 target_cflags = [get_required_attr(config, "target_cflags")] + extra_linkflags
 target_cxxflags = config.cxx_mode_flags + target_cflags
-clang_asan_static_cflags = ["-fsanitize=address"] + target_cflags
-
-clang_path = getattr(config, 'clang', None)
-if clang_path.find("clang-cl") == -1:
-  clang_asan_static_cflags += ["-g",
-                               "-mno-omit-leaf-frame-pointer",
-                               "-fno-omit-frame-pointer",
-                               "-fno-optimize-sibling-calls"]
-else:
-  clang_asan_static_cflags += ["-Zi",
-                               "-Wno-deprecated-declarations",
-                               "-D_HAS_EXCEPTIONS=0"]
-
+clang_asan_static_cflags = ["-fsanitize=address",
+                            "-mno-omit-leaf-frame-pointer",
+                            "-fno-omit-frame-pointer",
+                            "-fno-optimize-sibling-calls",
+                            "-g"] + target_cflags
 clang_asan_static_cxxflags = config.cxx_mode_flags + clang_asan_static_cflags
 
 if config.asan_dynamic:
@@ -76,6 +69,17 @@
   config.substitutions.append( ("%clang_asan_static ", build_invocation(clang_asan_static_cflags)) )
   config.substitutions.append( ("%clangxx_asan_static ", build_invocation(clang_asan_static_cxxflags)) )
 
+# Windows-specific tests might also use the clang-cl.exe driver.
+if platform.system() == 'Windows':
+  clang_cl_asan_cxxflags = ["-fsanitize=address",
+                            "-Wno-deprecated-declarations",
+                            "-WX",
+                            "-D_HAS_EXCEPTIONS=0",
+                            "-Zi"] + target_cflags
+  clang_invocation = build_invocation(clang_cl_asan_cxxflags)
+  clang_cl_invocation = clang_invocation.replace("clang.exe","clang-cl.exe")
+  config.substitutions.append( ("%clang_cl_asan ", clang_cl_invocation) )
+
 # FIXME: De-hardcode this path.
 asan_source_dir = os.path.join(
   get_required_attr(config, "compiler_rt_src_root"), "lib", "asan")
@@ -106,6 +110,11 @@
 
 config.available_features.add("asan-" + config.bits + "-bits")
 
+# Allow tests to use REQUIRES=stable-runtime.  For use when you cannot use XFAIL
+# because the test hangs.
+if config.target_arch != 'arm':
+  config.available_features.add('stable-runtime')
+
 # Turn on leak detection on 64-bit Linux.
 if config.host_os == 'Linux' and config.bits == '64':
   config.environment['ASAN_OPTIONS'] = 'detect_leaks=1'
diff --git a/test/builtins/Unit/divtf3_test.c b/test/builtins/Unit/divtf3_test.c
new file mode 100644
index 0000000..dad631c
--- /dev/null
+++ b/test/builtins/Unit/divtf3_test.c
@@ -0,0 +1,94 @@
+//===--------------- divtf3_test.c - Test __divtf3 ------------------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file tests __divtf3 for the compiler_rt library.
+//
+//===----------------------------------------------------------------------===//
+
+#include <stdio.h>
+
+#if __LDBL_MANT_DIG__ == 113
+
+#include "fp_test.h"
+
+// Returns: a / b
+long double __divtf3(long double a, long double b);
+
+int test__divtf3(long double a, long double b,
+                 uint64_t expectedHi, uint64_t expectedLo)
+{
+    long double x = __divtf3(a, b);
+    int ret = compareResultLD(x, expectedHi, expectedLo);
+
+    if (ret){
+        printf("error in test__divtf3(%.20Lf, %.20Lf) = %.20Lf, "
+               "expected %.20Lf\n", a, b, x,
+               fromRep128(expectedHi, expectedLo));
+    }
+    return ret;
+}
+
+char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0};
+
+#endif
+
+int main()
+{
+#if __LDBL_MANT_DIG__ == 113
+    // qNaN / any = qNaN
+    if (test__divtf3(makeQNaN128(),
+                     0x1.23456789abcdefp+5L,
+                     UINT64_C(0x7fff800000000000),
+                     UINT64_C(0x0)))
+        return 1;
+    // NaN / any = NaN
+    if (test__divtf3(makeNaN128(UINT64_C(0x800030000000)),
+                     0x1.23456789abcdefp+5L,
+                     UINT64_C(0x7fff800000000000),
+                     UINT64_C(0x0)))
+        return 1;
+    // inf / any = inf
+    if (test__divtf3(makeInf128(),
+                     0x1.23456789abcdefp+5L,
+                     UINT64_C(0x7fff000000000000),
+                     UINT64_C(0x0)))
+        return 1;
+    // any / any
+    if (test__divtf3(0x1.a23b45362464523375893ab4cdefp+5L,
+                     0x1.eedcbaba3a94546558237654321fp-1L,
+                     UINT64_C(0x4004b0b72924d407),
+                     UINT64_C(0x0717e84356c6eba2)))
+        return 1;
+    if (test__divtf3(0x1.a2b34c56d745382f9abf2c3dfeffp-50L,
+                     0x1.ed2c3ba15935332532287654321fp-9L,
+                     UINT64_C(0x3fd5b2af3f828c9b),
+                     UINT64_C(0x40e51f64cde8b1f2)))
+        return 15;
+    if (test__divtf3(0x1.2345f6aaaa786555f42432abcdefp+456L,
+                     0x1.edacbba9874f765463544dd3621fp+6400L,
+                     UINT64_C(0x28c62e15dc464466),
+                     UINT64_C(0xb5a07586348557ac)))
+        return 1;
+    if (test__divtf3(0x1.2d3456f789ba6322bc665544edefp-234L,
+                     0x1.eddcdba39f3c8b7a36564354321fp-4455L,
+                     UINT64_C(0x507b38442b539266),
+                     UINT64_C(0x22ce0f1d024e1252)))
+        return 1;
+    if (test__divtf3(0x1.2345f6b77b7a8953365433abcdefp+234L,
+                     0x1.edcba987d6bb3aa467754354321fp-4055L,
+                     UINT64_C(0x50bf2e02f0798d36),
+                     UINT64_C(0x5e6fcb6b60044078)))
+        return 1;
+
+#else
+    printf("skipped\n");
+
+#endif
+    return 0;
+}
diff --git a/test/builtins/Unit/extenddftf2_test.c b/test/builtins/Unit/extenddftf2_test.c
new file mode 100644
index 0000000..05acc08
--- /dev/null
+++ b/test/builtins/Unit/extenddftf2_test.c
@@ -0,0 +1,82 @@
+//===--------------- extenddftf2_test.c - Test __extenddftf2 --------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file tests __extenddftf2 for the compiler_rt library.
+//
+//===----------------------------------------------------------------------===//
+
+#include <stdio.h>
+
+#if __LDBL_MANT_DIG__ == 113
+
+#include "fp_test.h"
+
+long double __extenddftf2(double a);
+
+int test__extenddftf2(double a, uint64_t expectedHi, uint64_t expectedLo)
+{
+    long double x = __extenddftf2(a);
+    int ret = compareResultLD(x, expectedHi, expectedLo);
+
+    if (ret){
+        printf("error in test__extenddftf2(%f) = %.20Lf, "
+               "expected %.20Lf\n", a, x, fromRep128(expectedHi, expectedLo));
+    }
+    return ret;
+}
+
+char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0};
+
+#endif
+
+int main()
+{
+#if __LDBL_MANT_DIG__ == 113
+    // qNaN
+    if (test__extenddftf2(makeQNaN64(),
+                          UINT64_C(0x7fff800000000000),
+                          UINT64_C(0x0)))
+        return 1;
+    // NaN
+    if (test__extenddftf2(makeNaN64(UINT64_C(0x7100000000000)),
+                          UINT64_C(0x7fff710000000000),
+                          UINT64_C(0x0)))
+        return 1;
+    // inf
+    if (test__extenddftf2(makeInf64(),
+                          UINT64_C(0x7fff000000000000),
+                          UINT64_C(0x0)))
+        return 1;
+    // zero
+    if (test__extenddftf2(0.0, UINT64_C(0x0), UINT64_C(0x0)))
+        return 1;
+
+    if (test__extenddftf2(0x1.23456789abcdefp+5,
+                          UINT64_C(0x400423456789abcd),
+                          UINT64_C(0xf000000000000000)))
+        return 1;
+    if (test__extenddftf2(0x1.edcba987654321fp-9,
+                          UINT64_C(0x3ff6edcba9876543),
+                          UINT64_C(0x2000000000000000)))
+        return 1;
+    if (test__extenddftf2(0x1.23456789abcdefp+45,
+                          UINT64_C(0x402c23456789abcd),
+                          UINT64_C(0xf000000000000000)))
+        return 1;
+    if (test__extenddftf2(0x1.edcba987654321fp-45,
+                          UINT64_C(0x3fd2edcba9876543),
+                          UINT64_C(0x2000000000000000)))
+        return 1;
+
+#else
+    printf("skipped\n");
+
+#endif
+    return 0;
+}
diff --git a/test/builtins/Unit/extendsftf2_test.c b/test/builtins/Unit/extendsftf2_test.c
new file mode 100644
index 0000000..5f41928
--- /dev/null
+++ b/test/builtins/Unit/extendsftf2_test.c
@@ -0,0 +1,83 @@
+//===--------------- extendsftf2_test.c - Test __extendsftf2 --------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file tests __extendsftf2 for the compiler_rt library.
+//
+//===----------------------------------------------------------------------===//
+
+#include <stdio.h>
+
+#if __LDBL_MANT_DIG__ == 113
+
+#include "fp_test.h"
+
+long double __extendsftf2(float a);
+
+int test__extendsftf2(float a, uint64_t expectedHi, uint64_t expectedLo)
+{
+    long double x = __extendsftf2(a);
+    int ret = compareResultLD(x, expectedHi, expectedLo);
+
+    if (ret)
+    {
+        printf("error in test__extendsftf2(%f) = %.20Lf, "
+               "expected %.20Lf\n", a, x, fromRep128(expectedHi, expectedLo));
+    }
+    return ret;
+}
+
+char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0};
+
+#endif
+
+int main()
+{
+#if __LDBL_MANT_DIG__ == 113
+    // qNaN
+    if (test__extendsftf2(makeQNaN32(),
+                          UINT64_C(0x7fff800000000000),
+                          UINT64_C(0x0)))
+        return 1;
+    // NaN
+    if (test__extendsftf2(makeNaN32(UINT32_C(0x410000)),
+                          UINT64_C(0x7fff820000000000),
+                          UINT64_C(0x0)))
+        return 1;
+    // inf
+    if (test__extendsftf2(makeInf32(),
+                          UINT64_C(0x7fff000000000000),
+                          UINT64_C(0x0)))
+        return 1;
+    // zero
+    if (test__extendsftf2(0.0f, UINT64_C(0x0), UINT64_C(0x0)))
+        return 1;
+
+    if (test__extendsftf2(0x1.23456p+5f,
+                          UINT64_C(0x4004234560000000),
+                          UINT64_C(0x0)))
+        return 1;
+    if (test__extendsftf2(0x1.edcbap-9f,
+                          UINT64_C(0x3ff6edcba0000000),
+                          UINT64_C(0x0)))
+        return 1;
+    if (test__extendsftf2(0x1.23456p+45f,
+                          UINT64_C(0x402c234560000000),
+                          UINT64_C(0x0)))
+        return 1;
+    if (test__extendsftf2(0x1.edcbap-45f,
+                          UINT64_C(0x3fd2edcba0000000),
+                          UINT64_C(0x0)))
+        return 1;
+
+#else
+    printf("skipped\n");
+
+#endif
+    return 0;
+}
diff --git a/test/builtins/Unit/trunctfdf2_test.c b/test/builtins/Unit/trunctfdf2_test.c
new file mode 100644
index 0000000..46855e3
--- /dev/null
+++ b/test/builtins/Unit/trunctfdf2_test.c
@@ -0,0 +1,76 @@
+//===-------------- trunctfdf2_test.c - Test __trunctfdf2 -----------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file tests __trunctfdf2 for the compiler_rt library.
+//
+//===----------------------------------------------------------------------===//
+
+#include <stdio.h>
+
+#if __LDBL_MANT_DIG__ == 113
+
+#include "fp_test.h"
+
+double __trunctfdf2(long double a);
+
+int test__trunctfdf2(long double a, uint64_t expected)
+{
+    double x = __trunctfdf2(a);
+    int ret = compareResultD(x, expected);
+
+    if (ret)
+    {
+        printf("error in test__trunctfdf2(%.20Lf) = %lf, "
+               "expected %lf\n", a, x, fromRep64(expected));
+    }
+    return ret;
+}
+
+char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0};
+
+#endif
+
+int main()
+{
+#if __LDBL_MANT_DIG__ == 113
+    // qNaN
+    if (test__trunctfdf2(makeQNaN128(),
+                         UINT64_C(0x7ff8000000000000)))
+        return 1;
+    // NaN
+    if (test__trunctfdf2(makeNaN128(UINT64_C(0x810000000000)),
+                         UINT64_C(0x7ff8100000000000)))
+        return 1;
+    // inf
+    if (test__trunctfdf2(makeInf128(),
+                         UINT64_C(0x7ff0000000000000)))
+        return 1;
+    // zero
+    if (test__trunctfdf2(0.0L, UINT64_C(0x0)))
+        return 1;
+
+    if (test__trunctfdf2(0x1.af23456789bbaaab347645365cdep+5L,
+                         UINT64_C(0x404af23456789bbb)))
+        return 1;
+    if (test__trunctfdf2(0x1.dedafcff354b6ae9758763545432p-9L,
+                         UINT64_C(0x3f6dedafcff354b7)))
+        return 1;
+    if (test__trunctfdf2(0x1.2f34dd5f437e849b4baab754cdefp+4534L,
+                         UINT64_C(0x7ff0000000000000)))
+        return 1;
+    if (test__trunctfdf2(0x1.edcbff8ad76ab5bf46463233214fp-435L,
+                         UINT64_C(0x24cedcbff8ad76ab)))
+        return 1;
+
+#else
+    printf("skipped\n");
+
+#endif
+    return 0;
+}
diff --git a/test/builtins/Unit/trunctfsf2_test.c b/test/builtins/Unit/trunctfsf2_test.c
new file mode 100644
index 0000000..44e7fd1
--- /dev/null
+++ b/test/builtins/Unit/trunctfsf2_test.c
@@ -0,0 +1,75 @@
+//===--------------- trunctfsf2_test.c - Test __trunctfsf2 ----------------===//
+//
+//                     The LLVM Compiler Infrastructure
+//
+// This file is dual licensed under the MIT and the University of Illinois Open
+// Source Licenses. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+//
+// This file tests __trunctfsf2 for the compiler_rt library.
+//
+//===----------------------------------------------------------------------===//
+
+#include <stdio.h>
+
+#if __LDBL_MANT_DIG__ == 113
+
+#include "fp_test.h"
+
+float __trunctfsf2(long double a);
+
+int test__trunctfsf2(long double a, uint32_t expected)
+{
+    float x = __trunctfsf2(a);
+    int ret = compareResultF(x, expected);
+
+    if (ret){
+        printf("error in test__trunctfsf2(%.20Lf) = %f, "
+               "expected %f\n", a, x, fromRep32(expected));
+    }
+    return ret;
+}
+
+char assumption_1[sizeof(long double) * CHAR_BIT == 128] = {0};
+
+#endif
+
+int main()
+{
+#if __LDBL_MANT_DIG__ == 113
+    // qNaN
+    if (test__trunctfsf2(makeQNaN128(),
+                         UINT32_C(0x7fc00000)))
+        return 1;
+    // NaN
+    if (test__trunctfsf2(makeNaN128(UINT64_C(0x810000000000)),
+                         UINT32_C(0x7fc08000)))
+        return 1;
+    // inf
+    if (test__trunctfsf2(makeInf128(),
+                         UINT32_C(0x7f800000)))
+        return 1;
+    // zero
+    if (test__trunctfsf2(0.0L, UINT32_C(0x0)))
+        return 1;
+
+    if (test__trunctfsf2(0x1.23a2abb4a2ddee355f36789abcdep+5L,
+                         UINT32_C(0x4211d156)))
+        return 1;
+    if (test__trunctfsf2(0x1.e3d3c45bd3abfd98b76a54cc321fp-9L,
+                         UINT32_C(0x3b71e9e2)))
+        return 1;
+    if (test__trunctfsf2(0x1.234eebb5faa678f4488693abcdefp+4534L,
+                         UINT32_C(0x7f800000)))
+        return 1;
+    if (test__trunctfsf2(0x1.edcba9bb8c76a5a43dd21f334634p-435L,
+                         UINT32_C(0x0)))
+        return 1;
+
+#else
+    printf("skipped\n");
+
+#endif
+    return 0;
+}
diff --git a/test/dfsan/basic.c b/test/dfsan/basic.c
index 3c87bdc..6582727 100644
--- a/test/dfsan/basic.c
+++ b/test/dfsan/basic.c
@@ -17,5 +17,12 @@
   dfsan_label read_label = dfsan_read_label(&i, sizeof(i));
   assert(i_label == read_label);
 
+  dfsan_label j_label = dfsan_create_label("j", 0);
+  dfsan_add_label(j_label, &i, sizeof(i));
+
+  read_label = dfsan_read_label(&i, sizeof(i));
+  assert(dfsan_has_label(read_label, i_label));
+  assert(dfsan_has_label(read_label, j_label));
+
   return 0;
 }
diff --git a/test/lit.common.cfg b/test/lit.common.cfg
index 5366073..adf65ee 100644
--- a/test/lit.common.cfg
+++ b/test/lit.common.cfg
@@ -7,6 +7,7 @@
 import platform
 
 import lit.formats
+import lit.util
 
 # Setup test format
 execute_external = (platform.system() != 'Windows'
@@ -77,3 +78,5 @@
 compiler_rt_debug = getattr(config, 'compiler_rt_debug', False)
 if not compiler_rt_debug:
   config.available_features.add('compiler-rt-optimized')
+
+lit.util.usePlatformSdkOnDarwin(config, lit_config)
diff --git a/test/msan/SharedLibs/dso-origin-so.cc b/test/msan/SharedLibs/dso-origin-so.cc
deleted file mode 100644
index 8930a71..0000000
--- a/test/msan/SharedLibs/dso-origin-so.cc
+++ /dev/null
@@ -1,14 +0,0 @@
-#include <stdlib.h>
-
-#include "dso-origin.h"
-
-void my_access(int *p) {
-  volatile int tmp;
-  // Force initialize-ness check.
-  if (*p)
-    tmp = 1;
-}
-
-void *my_alloc(unsigned sz) {
-  return malloc(sz);
-}
diff --git a/test/msan/SharedLibs/dso-origin.h b/test/msan/SharedLibs/dso-origin.h
deleted file mode 100644
index ff926b3..0000000
--- a/test/msan/SharedLibs/dso-origin.h
+++ /dev/null
@@ -1,4 +0,0 @@
-extern "C" {
-void my_access(int *p);
-void *my_alloc(unsigned sz);
-}
diff --git a/test/msan/SharedLibs/lit.local.cfg b/test/msan/SharedLibs/lit.local.cfg
deleted file mode 100644
index b3677c1..0000000
--- a/test/msan/SharedLibs/lit.local.cfg
+++ /dev/null
@@ -1,4 +0,0 @@
-# Sources in this directory are compiled as shared libraries and used by
-# tests in parent directory.
-
-config.suffixes = []
diff --git a/test/msan/chained_origin.cc b/test/msan/chained_origin.cc
index f69de9a..336bbd8 100644
--- a/test/msan/chained_origin.cc
+++ b/test/msan/chained_origin.cc
@@ -6,6 +6,16 @@
 // RUN:     not %run %t >%t.out 2>&1
 // RUN: FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-HEAP < %t.out
 
+
+// RUN: %clangxx_msan -mllvm -msan-instrumentation-with-call-threshold=0 -fsanitize-memory-track-origins=2 -m64 -O3 %s -o %t && \
+// RUN:     not %run %t >%t.out 2>&1
+// RUN: FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-STACK < %t.out
+
+// RUN: %clangxx_msan -mllvm -msan-instrumentation-with-call-threshold=0 -fsanitize-memory-track-origins=2 -DHEAP=1 -m64 -O3 %s -o %t && \
+// RUN:     not %run %t >%t.out 2>&1
+// RUN: FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-HEAP < %t.out
+
+
 #include <stdio.h>
 
 volatile int x, y;
@@ -38,19 +48,19 @@
 }
 
 // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value
-// CHECK: {{#0 .* in main.*chained_origin.cc:37}}
+// CHECK: {{#0 .* in main.*chained_origin.cc:47}}
 
 // CHECK: Uninitialized value was stored to memory at
-// CHECK: {{#0 .* in fn_h.*chained_origin.cc:25}}
-// CHECK: {{#1 .* in main.*chained_origin.cc:36}}
+// CHECK: {{#0 .* in fn_h.*chained_origin.cc:35}}
+// CHECK: {{#1 .* in main.*chained_origin.cc:46}}
 
 // CHECK: Uninitialized value was stored to memory at
-// CHECK: {{#0 .* in fn_g.*chained_origin.cc:15}}
-// CHECK: {{#1 .* in fn_f.*chained_origin.cc:20}}
-// CHECK: {{#2 .* in main.*chained_origin.cc:35}}
+// CHECK: {{#0 .* in fn_g.*chained_origin.cc:25}}
+// CHECK: {{#1 .* in fn_f.*chained_origin.cc:30}}
+// CHECK: {{#2 .* in main.*chained_origin.cc:45}}
 
 // CHECK-STACK: Uninitialized value was created by an allocation of 'z' in the stack frame of function 'main'
-// CHECK-STACK: {{#0 .* in main.*chained_origin.cc:28}}
+// CHECK-STACK: {{#0 .* in main.*chained_origin.cc:38}}
 
 // CHECK-HEAP: Uninitialized value was created by a heap allocation
-// CHECK-HEAP: {{#1 .* in main.*chained_origin.cc:30}}
+// CHECK-HEAP: {{#1 .* in main.*chained_origin.cc:40}}
diff --git a/test/msan/chained_origin_empty_stack.cc b/test/msan/chained_origin_empty_stack.cc
new file mode 100644
index 0000000..36727e3
--- /dev/null
+++ b/test/msan/chained_origin_empty_stack.cc
@@ -0,0 +1,34 @@
+// RUN: %clangxx_msan -fsanitize-memory-track-origins=2 -m64 -O3 %s -o %t && \
+// RUN:     MSAN_OPTIONS=store_context_size=1 not %run %t 2>&1 | FileCheck %s
+
+// Test that stack trace for the intermediate store is not empty.
+
+// CHECK: MemorySanitizer: use-of-uninitialized-value
+// CHECK:   #0 {{.*}} in main
+
+// CHECK: Uninitialized value was stored to memory at
+// CHECK:   #0 {{.*}} in fn_g
+// CHECK-NOT: #1
+
+// CHECK: Uninitialized value was created by an allocation of 'z' in the stack frame of function 'main'
+// CHECK:   #0 {{.*}} in main
+
+#include <stdio.h>
+
+volatile int x;
+
+__attribute__((noinline))
+void fn_g(int a) {
+  x = a;
+}
+
+__attribute__((noinline))
+void fn_f(int a) {
+  fn_g(a);
+}
+
+int main(int argc, char *argv[]) {
+  int volatile z;
+  fn_f(z);
+  return x;
+}
diff --git a/test/msan/chained_origin_limits.cc b/test/msan/chained_origin_limits.cc
index c6f8b62..a8621f3 100644
--- a/test/msan/chained_origin_limits.cc
+++ b/test/msan/chained_origin_limits.cc
@@ -1,5 +1,6 @@
 // This test program creates a very large number of unique histories.
 
+// Heap origin.
 // RUN: %clangxx_msan -fsanitize-memory-track-origins=2 -m64 -O3 %s -o %t
 
 // RUN: MSAN_OPTIONS=origin_history_size=7 not %run %t >%t.out 2>&1
@@ -11,6 +12,44 @@
 // RUN: MSAN_OPTIONS=origin_history_per_stack_limit=1 not %run %t >%t.out 2>&1
 // RUN: FileCheck %s --check-prefix=CHECK-PER-STACK < %t.out
 
+// Stack origin.
+// RUN: %clangxx_msan -DSTACK -fsanitize-memory-track-origins=2 -m64 -O3 %s -o %t
+
+// RUN: MSAN_OPTIONS=origin_history_size=7 not %run %t >%t.out 2>&1
+// RUN: FileCheck %s --check-prefix=CHECK7 < %t.out
+
+// RUN: MSAN_OPTIONS=origin_history_size=2 not %run %t >%t.out 2>&1
+// RUN: FileCheck %s --check-prefix=CHECK2 < %t.out
+
+// RUN: MSAN_OPTIONS=origin_history_per_stack_limit=1 not %run %t >%t.out 2>&1
+// RUN: FileCheck %s --check-prefix=CHECK-PER-STACK < %t.out
+
+
+// Heap origin, with calls.
+// RUN: %clangxx_msan -mllvm -msan-instrumentation-with-call-threshold=0 -fsanitize-memory-track-origins=2 -m64 -O3 %s -o %t
+
+// RUN: MSAN_OPTIONS=origin_history_size=7 not %run %t >%t.out 2>&1
+// RUN: FileCheck %s --check-prefix=CHECK7 < %t.out
+
+// RUN: MSAN_OPTIONS=origin_history_size=2 not %run %t >%t.out 2>&1
+// RUN: FileCheck %s --check-prefix=CHECK2 < %t.out
+
+// RUN: MSAN_OPTIONS=origin_history_per_stack_limit=1 not %run %t >%t.out 2>&1
+// RUN: FileCheck %s --check-prefix=CHECK-PER-STACK < %t.out
+
+
+// Stack origin, with calls.
+// RUN: %clangxx_msan -DSTACK -mllvm -msan-instrumentation-with-call-threshold=0 -fsanitize-memory-track-origins=2 -m64 -O3 %s -o %t
+
+// RUN: MSAN_OPTIONS=origin_history_size=7 not %run %t >%t.out 2>&1
+// RUN: FileCheck %s --check-prefix=CHECK7 < %t.out
+
+// RUN: MSAN_OPTIONS=origin_history_size=2 not %run %t >%t.out 2>&1
+// RUN: FileCheck %s --check-prefix=CHECK2 < %t.out
+
+// RUN: MSAN_OPTIONS=origin_history_per_stack_limit=1 not %run %t >%t.out 2>&1
+// RUN: FileCheck %s --check-prefix=CHECK-PER-STACK < %t.out
+
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -19,6 +58,11 @@
 static char *buf, *cur, *end;
 void init() {
   buf = new char[1000];
+#ifdef STACK
+  char stackbuf[1000];
+  char *volatile p = stackbuf;
+  memcpy(buf, p, 1000);
+#endif
   cur = buf;
   end = buf + 1000;
 }
@@ -83,13 +127,13 @@
 // CHECK7-NOT: Uninitialized value was stored to memory at
 // CHECK7: Uninitialized value was stored to memory at
 // CHECK7-NOT: Uninitialized value was stored to memory at
-// CHECK7: Uninitialized value was created by a heap allocation
+// CHECK7: Uninitialized value was created
 
 // CHECK2: WARNING: MemorySanitizer: use-of-uninitialized-value
 // CHECK2-NOT: Uninitialized value was stored to memory at
 // CHECK2: Uninitialized value was stored to memory at
 // CHECK2-NOT: Uninitialized value was stored to memory at
-// CHECK2: Uninitialized value was created by a heap allocation
+// CHECK2: Uninitialized value was created
 
 // CHECK-PER-STACK: WARNING: MemorySanitizer: use-of-uninitialized-value
 // CHECK-PER-STACK: Uninitialized value was stored to memory at
@@ -98,4 +142,4 @@
 // CHECK-PER-STACK: in fn2
 // CHECK-PER-STACK: Uninitialized value was stored to memory at
 // CHECK-PER-STACK: in fn1
-// CHECK-PER-STACK: Uninitialized value was created by a heap allocation
+// CHECK-PER-STACK: Uninitialized value was created
diff --git a/test/msan/chained_origin_memcpy.cc b/test/msan/chained_origin_memcpy.cc
index e56db9c..f4c2f7f 100644
--- a/test/msan/chained_origin_memcpy.cc
+++ b/test/msan/chained_origin_memcpy.cc
@@ -6,6 +6,16 @@
 // RUN:     not %run %t >%t.out 2>&1
 // RUN: FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-Z2 < %t.out
 
+
+// RUN: %clangxx_msan -mllvm -msan-instrumentation-with-call-threshold=0 -fsanitize-memory-track-origins=2 -m64 -DOFFSET=0 -O3 %s -o %t && \
+// RUN:     not %run %t >%t.out 2>&1
+// RUN: FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-Z1 < %t.out
+
+// RUN: %clangxx_msan -mllvm -msan-instrumentation-with-call-threshold=0 -fsanitize-memory-track-origins=2 -DOFFSET=10 -m64 -O3 %s -o %t && \
+// RUN:     not %run %t >%t.out 2>&1
+// RUN: FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-Z2 < %t.out
+
+
 #include <stdio.h>
 #include <string.h>
 
@@ -37,15 +47,15 @@
 }
 
 // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value
-// CHECK: {{#0 .* in main .*chained_origin_memcpy.cc:36}}
+// CHECK: {{#0 .* in main .*chained_origin_memcpy.cc:46}}
 
 // CHECK: Uninitialized value was stored to memory at
-// CHECK: {{#1 .* in fn_h.*chained_origin_memcpy.cc:28}}
+// CHECK: {{#1 .* in fn_h.*chained_origin_memcpy.cc:38}}
 
 // CHECK: Uninitialized value was stored to memory at
-// CHECK: {{#0 .* in fn_g.*chained_origin_memcpy.cc:18}}
-// CHECK: {{#1 .* in fn_f.*chained_origin_memcpy.cc:23}}
+// CHECK: {{#0 .* in fn_g.*chained_origin_memcpy.cc:28}}
+// CHECK: {{#1 .* in fn_f.*chained_origin_memcpy.cc:33}}
 
 // CHECK-Z1: Uninitialized value was created by an allocation of 'z1' in the stack frame of function 'main'
 // CHECK-Z2: Uninitialized value was created by an allocation of 'z2' in the stack frame of function 'main'
-// CHECK: {{#0 .* in main.*chained_origin_memcpy.cc:31}}
+// CHECK: {{#0 .* in main.*chained_origin_memcpy.cc:41}}
diff --git a/test/msan/chained_origin_with_signals.cc b/test/msan/chained_origin_with_signals.cc
index 5fd497e..ef98385 100644
--- a/test/msan/chained_origin_with_signals.cc
+++ b/test/msan/chained_origin_with_signals.cc
@@ -6,6 +6,10 @@
 // RUN:     not %run %t >%t.out 2>&1
 // RUN: FileCheck %s < %t.out
 
+// RUN: %clangxx_msan -mllvm -msan-instrumentation-with-call-threshold=0 -fsanitize-memory-track-origins=2 -m64 -O3 %s -o %t && \
+// RUN:     not %run %t >%t.out 2>&1
+// RUN: FileCheck %s < %t.out
+
 #include <signal.h>
 #include <stdio.h>
 #include <sys/types.h>
diff --git a/test/msan/dso-origin.cc b/test/msan/dso-origin.cc
index 9bde029..ba008c0 100644
--- a/test/msan/dso-origin.cc
+++ b/test/msan/dso-origin.cc
@@ -1,12 +1,33 @@
 // Build a library with origin tracking and an executable w/o origin tracking.
 // Test that origin tracking is enabled at runtime.
-// RUN: %clangxx_msan -fsanitize-memory-track-origins -m64 -O0 %p/SharedLibs/dso-origin-so.cc \
-// RUN:     -fPIC -shared -o %t-so.so
+// RUN: %clangxx_msan -fsanitize-memory-track-origins -m64 -O0 %s -DBUILD_SO -fPIC -shared -o %t-so.so
 // RUN: %clangxx_msan -m64 -O0 %s %t-so.so -o %t && not %run %t 2>&1 | FileCheck %s
 
+#ifdef BUILD_SO
+
 #include <stdlib.h>
 
-#include "SharedLibs/dso-origin.h"
+extern "C" {
+void my_access(int *p) {
+  volatile int tmp;
+  // Force initialize-ness check.
+  if (*p)
+    tmp = 1;
+}
+
+void *my_alloc(unsigned sz) {
+  return malloc(sz);
+}
+}  // extern "C"
+
+#else  // BUILD_SO
+
+#include <stdlib.h>
+
+extern "C" {
+void my_access(int *p);
+void *my_alloc(unsigned sz);
+}
 
 int main(int argc, char **argv) {
   int *x = (int *)my_alloc(sizeof(int));
@@ -14,12 +35,14 @@
   delete x;
 
   // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value
-  // CHECK: {{#0 0x.* in my_access .*dso-origin-so.cc:}}
+  // CHECK: {{#0 0x.* in my_access .*dso-origin.cc:}}
   // CHECK: {{#1 0x.* in main .*dso-origin.cc:}}[[@LINE-5]]
   // CHECK: Uninitialized value was created by a heap allocation
   // CHECK: {{#0 0x.* in .*malloc}}
-  // CHECK: {{#1 0x.* in my_alloc .*dso-origin-so.cc:}}
+  // CHECK: {{#1 0x.* in my_alloc .*dso-origin.cc:}}
   // CHECK: {{#2 0x.* in main .*dso-origin.cc:}}[[@LINE-10]]
-  // CHECK: SUMMARY: MemorySanitizer: use-of-uninitialized-value {{.*dso-origin-so.cc:.* my_access}}
+  // CHECK: SUMMARY: MemorySanitizer: use-of-uninitialized-value {{.*dso-origin.cc:.* my_access}}
   return 0;
 }
+
+#endif  // BUILD_SO
diff --git a/test/msan/dtls_test.c b/test/msan/dtls_test.c
index 5086389..cb88ede 100644
--- a/test/msan/dtls_test.c
+++ b/test/msan/dtls_test.c
@@ -1,10 +1,10 @@
-/* RUN: %clang_msan -m64 %s -o %t
-   RUN: %clang_msan -m64 %s -DBUILD_SO -fPIC -o %t-so.so -shared
-   RUN: not %run %t 2>&1 | FileCheck %s
-   CHECK: MemorySanitizer: use-of-uninitialized-value
+/* RUN: %clang_msan -g -m64 %s -o %t
+   RUN: %clang_msan -g -m64 %s -DBUILD_SO -fPIC -o %t-so.so -shared
+   RUN: %run %t 2>&1
 
-   This is an actual bug in msan/glibc integration,
+   Regression test for a bug in msan/glibc integration,
    see https://sourceware.org/bugzilla/show_bug.cgi?id=16291
+   and https://code.google.com/p/memory-sanitizer/issues/detail?id=44
 */
 
 #ifndef BUILD_SO
diff --git a/test/msan/getline.cc b/test/msan/getline.cc
index 086d0b9..51e105e 100644
--- a/test/msan/getline.cc
+++ b/test/msan/getline.cc
@@ -1,4 +1,11 @@
-// RUN: %clangxx_msan -O0 %s -o %t && %run %t %p
+// RUN: echo "abcde" > %t-testdata
+// RUN: echo "12345" >> %t-testdata
+// RUN: %clangxx_msan -O0 %s -o %t && %run %t %t-testdata
+// RUN: %clangxx_msan -O2 %s -o %t && %run %t %t-testdata
+// RUN: %clang_msan -O0 -xc %s -o %t && %run %t %t-testdata
+// RUN: %clang_msan -O2 -xc %s -o %t && %run %t %t-testdata
+// RUN: %clang_msan -O0 -xc -D_GNU_SOURCE=1 %s -o %t && %run %t %t-testdata
+// RUN: %clang_msan -O2 -xc -D_GNU_SOURCE=1 %s -o %t && %run %t %t-testdata
 
 #include <assert.h>
 #include <stdio.h>
@@ -7,10 +14,9 @@
 
 int main(int argc, char **argv) {
   assert(argc == 2);
-  char buf[1024];
-  snprintf(buf, sizeof(buf), "%s/%s", argv[1], "getline_test_data");
+  printf("%s\n", argv[1]);
 
-  FILE *fp = fopen(buf, "r");
+  FILE *fp = fopen(argv[1], "r");
   assert(fp);
 
   char *line = 0;
@@ -22,7 +28,7 @@
   n = getline(&line, &len, fp);
   assert(n == 6);
   assert(strcmp(line, "12345\n") == 0);
-  
+
   free(line);
   fclose(fp);
 
diff --git a/test/msan/getline_test_data b/test/msan/getline_test_data
deleted file mode 100644
index 5ba1d4c..0000000
--- a/test/msan/getline_test_data
+++ /dev/null
@@ -1,2 +0,0 @@
-abcde
-12345
diff --git a/test/msan/malloc_hook.cc b/test/msan/malloc_hook.cc
deleted file mode 100644
index 5393080..0000000
--- a/test/msan/malloc_hook.cc
+++ /dev/null
@@ -1,36 +0,0 @@
-// RUN: %clangxx_msan -O2 %s -o %t
-// RUN: %run %t 2>&1 | FileCheck %s
-#include <stdlib.h>
-#include <unistd.h>
-
-extern "C" {
-int __msan_get_ownership(const void *p);
-
-void *global_ptr;
-
-// Note: avoid calling functions that allocate memory in malloc/free
-// to avoid infinite recursion.
-void __msan_malloc_hook(void *ptr, size_t sz) {
-  if (__msan_get_ownership(ptr)) {
-    write(1, "MallocHook\n", sizeof("MallocHook\n"));
-    global_ptr = ptr;
-  }
-}
-void __msan_free_hook(void *ptr) {
-  if (__msan_get_ownership(ptr) && ptr == global_ptr)
-    write(1, "FreeHook\n", sizeof("FreeHook\n"));
-}
-}  // extern "C"
-
-int main() {
-  volatile int *x = new int;
-  // CHECK: MallocHook
-  // Check that malloc hook was called with correct argument.
-  if (global_ptr != (void*)x) {
-    _exit(1);
-  }
-  *x = 0;
-  delete x;
-  // CHECK: FreeHook
-  return 0;
-}
diff --git a/test/msan/msan_print_shadow3.cc b/test/msan/msan_print_shadow3.cc
new file mode 100644
index 0000000..c605ef1
--- /dev/null
+++ b/test/msan/msan_print_shadow3.cc
@@ -0,0 +1,16 @@
+// RUN: %clangxx_msan -m64 -O0 -g %s -o %t && %run %t >%t.out 2>&1
+// RUN: FileCheck %s < %t.out
+
+#include <stdint.h>
+#include <sanitizer/msan_interface.h>
+
+int main(void) {
+  unsigned long long x = 0; // For 8-byte alignment.
+  uint32_t x_s = 0x12345678U;
+  __msan_partial_poison(&x, &x_s, sizeof(x_s));
+  __msan_print_shadow(&x, sizeof(x_s));
+  return 0;
+}
+
+// CHECK: Shadow map of [{{.*}}), 4 bytes:
+// CHECK: 0x{{.*}}: 87654321 ........ ........ ........
diff --git a/test/msan/mul_by_const.cc b/test/msan/mul_by_const.cc
new file mode 100644
index 0000000..a975bb9
--- /dev/null
+++ b/test/msan/mul_by_const.cc
@@ -0,0 +1,27 @@
+// RUN: %clangxx_msan -m64 -O2 %s -o %t && %run %t
+
+#include <sanitizer/msan_interface.h>
+
+struct S {
+  S(int a0) : a(a0) {}
+  int a;
+  int b;
+};
+
+// Here S is passed to FooRun as a 64-bit integer.
+// This triggers an optimization where 10000 * s.a is transformed into
+// ((*(uint64_t *)&s) * (10000 * 2**32)) >> 32
+// Test that MSan understands that this kills the uninitialized high half of S
+// (i.e. S::b).
+void FooRun(S s) {
+  int64_t x = 10000 * s.a;
+  __msan_check_mem_is_initialized(&x, sizeof(x));
+}
+
+int main(void) {
+  S z(1);
+  // Take &z to ensure that it is built on stack.
+  S *volatile p = &z;
+  FooRun(z);
+  return 0;
+}
diff --git a/test/msan/no_sanitize_memory_prop.cc b/test/msan/no_sanitize_memory_prop.cc
index b41e8a1..4275ebb 100644
--- a/test/msan/no_sanitize_memory_prop.cc
+++ b/test/msan/no_sanitize_memory_prop.cc
@@ -1,16 +1,9 @@
 // RUN: %clangxx_msan -m64 -O0 %s -o %t && %run %t >%t.out 2>&1
-// RUN: %clangxx_msan -m64 -O1 %s -o %t && not %run %t >%t.out 2>&1
-// RUN: FileCheck %s < %t.out
-// RUN: %clangxx_msan -m64 -O2 %s -o %t && not %run %t >%t.out 2>&1
-// RUN: FileCheck %s < %t.out
-// RUN: %clangxx_msan -m64 -O3 %s -o %t && not %run %t >%t.out 2>&1
-// RUN: FileCheck %s < %t.out
+// RUN: %clangxx_msan -m64 -O1 %s -o %t && %run %t >%t.out 2>&1
+// RUN: %clangxx_msan -m64 -O2 %s -o %t && %run %t >%t.out 2>&1
+// RUN: %clangxx_msan -m64 -O3 %s -o %t && %run %t >%t.out 2>&1
 
-// Test that (no_sanitize_memory) functions propagate shadow.
-
-// Note that at -O0 there is no report, because 'x' in 'f' is spilled to the
-// stack, and then loaded back as a fully initialiazed value (due to
-// no_sanitize_memory attribute).
+// Test that (no_sanitize_memory) functions DO NOT propagate shadow.
 
 #include <stdlib.h>
 #include <stdio.h>
@@ -25,8 +18,6 @@
   int x;
   int * volatile p = &x;
   int y = f(*p);
-  // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value
-  // CHECK: {{#0 0x.* in main .*no_sanitize_memory_prop.cc:}}[[@LINE+1]]
   if (y)
     exit(0);
   return 0;
diff --git a/test/msan/print_stats.cc b/test/msan/print_stats.cc
index bee364b..7494383 100644
--- a/test/msan/print_stats.cc
+++ b/test/msan/print_stats.cc
@@ -3,6 +3,8 @@
 // RUN:   FileCheck --check-prefix=CHECK --check-prefix=CHECK-NOSTATS %s
 // RUN: MSAN_OPTIONS=print_stats=1 %run %t 2>&1 | \
 // RUN:   FileCheck --check-prefix=CHECK --check-prefix=CHECK-NOSTATS %s
+// RUN: MSAN_OPTIONS=print_stats=1,atexit=1 %run %t 2>&1 | \
+// RUN:   FileCheck --check-prefix=CHECK --check-prefix=CHECK-STATS %s
 
 // RUN: %clangxx_msan -fsanitize-memory-track-origins=2 -m64 -g -DPOSITIVE=1 %s -o %t 
 // RUN: not %run %t 2>&1 | \
@@ -30,8 +32,6 @@
 
 // CHECK: TEST
 
-// CHECK-KEEPGOING: MemorySanitizer: 1 warnings reported.
-
 // CHECK-STATS: Unique heap origins:
 // CHECK-STATS: Stack depot allocated bytes:
 // CHECK-STATS: Unique origin histories:
@@ -41,3 +41,5 @@
 // CHECK-NOSTATS-NOT: Stack depot allocated bytes:
 // CHECK-NOSTATS-NOT: Unique origin histories:
 // CHECK-NOSTATS-NOT: History depot allocated bytes:
+
+// CHECK-KEEPGOING: MemorySanitizer: 1 warnings reported.
diff --git a/test/msan/vector_cvt.cc b/test/msan/vector_cvt.cc
index 6393339..bd9b6a8 100644
--- a/test/msan/vector_cvt.cc
+++ b/test/msan/vector_cvt.cc
@@ -8,7 +8,7 @@
   int x = _mm_cvtsd_si32(t);
   return x;
   // CHECK: WARNING: MemorySanitizer: use-of-uninitialized-value
-  // CHECK: #{{.*}} in to_int{{.*}}vector_cvt.cc:[[@LINE-4]]
+  // CHECK: #{{.*}} in to_int{{.*}}vector_cvt.cc:[[@LINE-3]]
 }
 
 int main() {
diff --git a/test/sanitizer_common/CMakeLists.txt b/test/sanitizer_common/CMakeLists.txt
index dcb09ca..13eecbd 100644
--- a/test/sanitizer_common/CMakeLists.txt
+++ b/test/sanitizer_common/CMakeLists.txt
@@ -10,6 +10,7 @@
 if(CMAKE_SYSTEM_NAME MATCHES "Linux" AND NOT ANDROID)
   list(APPEND SUPPORTED_TOOLS tsan)
   list(APPEND SUPPORTED_TOOLS msan)
+  list(APPEND SUPPORTED_TOOLS lsan)
 endif()
 
 # Create a separate config for each tool we support.
diff --git a/test/sanitizer_common/TestCases/Linux/aligned_alloc.c b/test/sanitizer_common/TestCases/Linux/aligned_alloc.c
new file mode 100644
index 0000000..12af18d
--- /dev/null
+++ b/test/sanitizer_common/TestCases/Linux/aligned_alloc.c
@@ -0,0 +1,8 @@
+// RUN: %clang -std=c11 -O0 %s -o %t && %run %t
+#include <stdlib.h>
+extern void *aligned_alloc (size_t alignment, size_t size);
+int main() {
+  volatile void *p = aligned_alloc(128, 1024);
+  free((void*)p);
+  return 0;
+}
diff --git a/test/sanitizer_common/TestCases/Linux/ptrace.cc b/test/sanitizer_common/TestCases/Linux/ptrace.cc
index 5b6a3e9..797e7b4 100644
--- a/test/sanitizer_common/TestCases/Linux/ptrace.cc
+++ b/test/sanitizer_common/TestCases/Linux/ptrace.cc
@@ -1,5 +1,5 @@
 // RUN: %clangxx -O0 %s -o %t && %run %t
-// XFAIL: arm
+// XFAIL: arm-linux-gnueabi
 
 #include <assert.h>
 #include <signal.h>
diff --git a/test/sanitizer_common/TestCases/malloc_hook.cc b/test/sanitizer_common/TestCases/malloc_hook.cc
new file mode 100644
index 0000000..686e098
--- /dev/null
+++ b/test/sanitizer_common/TestCases/malloc_hook.cc
@@ -0,0 +1,38 @@
+// RUN: %clangxx -O2 %s -o %t && %run %t 2>&1 | FileCheck %s
+
+// Malloc/free hooks are not supported on Windows and doesn't work in LSan.
+// XFAIL: win32, lsan
+
+#include <stdlib.h>
+#include <unistd.h>
+#include <sanitizer/allocator_interface.h>
+
+extern "C" {
+const volatile void *global_ptr;
+
+// Note: avoid calling functions that allocate memory in malloc/free
+// to avoid infinite recursion.
+void __sanitizer_malloc_hook(const volatile void *ptr, size_t sz) {
+  if (__sanitizer_get_ownership(ptr)) {
+    write(1, "MallocHook\n", sizeof("MallocHook\n"));
+    global_ptr = ptr;
+  }
+}
+void __sanitizer_free_hook(const volatile void *ptr) {
+  if (__sanitizer_get_ownership(ptr) && ptr == global_ptr)
+    write(1, "FreeHook\n", sizeof("FreeHook\n"));
+}
+}  // extern "C"
+
+int main() {
+  volatile int *x = new int;
+  // CHECK: MallocHook
+  // Check that malloc hook was called with correct argument.
+  if (global_ptr != (void*)x) {
+    _exit(1);
+  }
+  *x = 0;
+  delete x;
+  // CHECK: FreeHook
+  return 0;
+}
diff --git a/test/sanitizer_common/TestCases/print-stack-trace.cc b/test/sanitizer_common/TestCases/print-stack-trace.cc
index 98d9ddf..c84d0da 100644
--- a/test/sanitizer_common/TestCases/print-stack-trace.cc
+++ b/test/sanitizer_common/TestCases/print-stack-trace.cc
@@ -3,7 +3,7 @@
 //
 // Not yet implemented for TSan.
 // https://code.google.com/p/address-sanitizer/issues/detail?id=243
-// XFAIL: tsan
+// XFAIL: tsan,lsan
 
 #include <sanitizer/common_interface_defs.h>
 
diff --git a/test/sanitizer_common/TestCases/pthread_mutexattr_get.cc b/test/sanitizer_common/TestCases/pthread_mutexattr_get.cc
new file mode 100644
index 0000000..26060f3
--- /dev/null
+++ b/test/sanitizer_common/TestCases/pthread_mutexattr_get.cc
@@ -0,0 +1,19 @@
+// RUN: %clangxx -O0 %s -o %t && %run %t
+
+#include <assert.h>
+#include <pthread.h>
+
+int main(void) {
+  pthread_mutexattr_t ma;
+  int res = pthread_mutexattr_init(&ma);
+  assert(res == 0);
+  res = pthread_mutexattr_setpshared(&ma, 1);
+  assert(res == 0);
+  int pshared;
+  res = pthread_mutexattr_getpshared(&ma, &pshared);
+  assert(res == 0);
+  assert(pshared == 1);
+  res = pthread_mutexattr_destroy(&ma);
+  assert(res == 0);
+  return 0;
+}
diff --git a/test/sanitizer_common/lit.common.cfg b/test/sanitizer_common/lit.common.cfg
index 6e2d772..6e768b1 100644
--- a/test/sanitizer_common/lit.common.cfg
+++ b/test/sanitizer_common/lit.common.cfg
@@ -11,6 +11,8 @@
   tool_cflags = ["-fsanitize=thread"]
 elif config.tool_name == "msan":
   tool_cflags = ["-fsanitize=memory"]
+elif config.tool_name == "lsan":
+  tool_cflags = ["-fsanitize=leak"]
 else:
   lit_config.fatal("Unknown tool for sanitizer_common tests: %r" % config.tool_name)
 
diff --git a/test/tsan/CMakeLists.txt b/test/tsan/CMakeLists.txt
index 5b7be0c..29c0821 100644
--- a/test/tsan/CMakeLists.txt
+++ b/test/tsan/CMakeLists.txt
@@ -3,7 +3,7 @@
   list(APPEND TSAN_TEST_DEPS tsan)
 endif()
 if(COMPILER_RT_HAS_LIBCXX_SOURCES AND
-   COMPILER_RT_TEST_COMPILER STREQUAL "Clang")
+   COMPILER_RT_TEST_COMPILER_ID STREQUAL "Clang")
   list(APPEND TSAN_TEST_DEPS libcxx_tsan)
   set(TSAN_HAS_LIBCXX True)
 else()
diff --git a/test/tsan/Helpers/blacklist.txt b/test/tsan/Helpers/blacklist.txt
deleted file mode 100644
index 22225e5..0000000
--- a/test/tsan/Helpers/blacklist.txt
+++ /dev/null
@@ -1 +0,0 @@
-fun:*Blacklisted_Thread2*
diff --git a/test/tsan/Helpers/lit.local.cfg b/test/tsan/Helpers/lit.local.cfg
deleted file mode 100644
index 9246b10..0000000
--- a/test/tsan/Helpers/lit.local.cfg
+++ /dev/null
@@ -1,2 +0,0 @@
-# Files in this directory are helper files for other output tests.
-config.suffixes = []
diff --git a/test/tsan/SharedLibs/lit.local.cfg b/test/tsan/SharedLibs/lit.local.cfg
deleted file mode 100644
index b3677c1..0000000
--- a/test/tsan/SharedLibs/lit.local.cfg
+++ /dev/null
@@ -1,4 +0,0 @@
-# Sources in this directory are compiled as shared libraries and used by
-# tests in parent directory.
-
-config.suffixes = []
diff --git a/test/tsan/SharedLibs/load_shared_lib-so.cc b/test/tsan/SharedLibs/load_shared_lib-so.cc
deleted file mode 100644
index f449fe9..0000000
--- a/test/tsan/SharedLibs/load_shared_lib-so.cc
+++ /dev/null
@@ -1,25 +0,0 @@
-//===----------- load_shared_lib-so.cc --------------------------*- C++ -*-===//
-//
-//                     The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-//
-// This file is a part of ThreadSanitizer (TSan), a race detector.
-//
-//===----------------------------------------------------------------------===//
-
-#include <stddef.h>
-#include <unistd.h>
-
-int GLOB_SHARED = 0;
-
-extern "C"
-void *write_from_so(void *unused) {
-  if (unused)
-    sleep(1);
-  GLOB_SHARED++;
-  return NULL;
-}
diff --git a/test/tsan/atomic_free.cc b/test/tsan/atomic_free.cc
index c36b8fb..1dcf887 100644
--- a/test/tsan/atomic_free.cc
+++ b/test/tsan/atomic_free.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <unistd.h>
 
diff --git a/test/tsan/atomic_free2.cc b/test/tsan/atomic_free2.cc
index 11204ba..c50be6b 100644
--- a/test/tsan/atomic_free2.cc
+++ b/test/tsan/atomic_free2.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <unistd.h>
 
diff --git a/test/tsan/atomic_race.cc b/test/tsan/atomic_race.cc
index e64ef96..ca444b4 100644
--- a/test/tsan/atomic_race.cc
+++ b/test/tsan/atomic_race.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <unistd.h>
 #include <stdio.h>
diff --git a/test/tsan/atomic_stack.cc b/test/tsan/atomic_stack.cc
index d28b5b9..7e3176f 100644
--- a/test/tsan/atomic_stack.cc
+++ b/test/tsan/atomic_stack.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <unistd.h>
 
diff --git a/test/tsan/blacklist.cc b/test/tsan/blacklist.cc
index ab6f1d1..d6ca383 100644
--- a/test/tsan/blacklist.cc
+++ b/test/tsan/blacklist.cc
@@ -1,8 +1,7 @@
 // Test blacklist functionality for TSan.
 
-// RUN: %clangxx_tsan -O1 %s \
-// RUN:   -fsanitize-blacklist=%p/Helpers/blacklist.txt \
-// RUN:   -o %t && %run %t 2>&1 | FileCheck %s
+// 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>
 
diff --git a/test/tsan/blacklist2.cc b/test/tsan/blacklist2.cc
new file mode 100644
index 0000000..1258208
--- /dev/null
+++ b/test/tsan/blacklist2.cc
@@ -0,0 +1,49 @@
+// 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 <pthread.h>
+#include <stdio.h>
+#include <unistd.h>
+
+int Global;
+
+void *Thread1(void *x) {
+  sleep(1);
+  // 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();
+  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);
+  printf("PASS\n");
+  return 0;
+}
diff --git a/test/tsan/cond_race.cc b/test/tsan/cond_race.cc
index 375bd92..fa42faf 100644
--- a/test/tsan/cond_race.cc
+++ b/test/tsan/cond_race.cc
@@ -1,4 +1,4 @@
-// RUN: %clang_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 // CHECK-NOT: unlock of unlocked mutex
 // CHECK: ThreadSanitizer: data race
 // CHECK: pthread_cond_signal
diff --git a/test/tsan/deadlock_detector_stress_test.cc b/test/tsan/deadlock_detector_stress_test.cc
index ac9fcbd..5362478 100644
--- a/test/tsan/deadlock_detector_stress_test.cc
+++ b/test/tsan/deadlock_detector_stress_test.cc
@@ -1,12 +1,12 @@
 // RUN: %clangxx_tsan %s -o %t -DLockType=PthreadMutex
-// RUN: TSAN_OPTIONS=detect_deadlocks=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NOT-SECOND
-// TSAN_OPTIONS="detect_deadlocks=1 second_deadlock_stack=1" not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-SECOND
+// RUN: TSAN_OPTIONS=detect_deadlocks=1 %deflake %run %t | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-NOT-SECOND
+// TSAN_OPTIONS="detect_deadlocks=1 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: TSAN_OPTIONS=detect_deadlocks=1 not %run %t 2>&1 | FileCheck %s
+// RUN: TSAN_OPTIONS=detect_deadlocks=1 %deflake %run %t | FileCheck %s
 // RUN: %clangxx_tsan %s -o %t -DLockType=PthreadRWLock
-// RUN: TSAN_OPTIONS=detect_deadlocks=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-RD
+// RUN: TSAN_OPTIONS=detect_deadlocks=1 %deflake %run %t | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-RD
 // RUN: %clangxx_tsan %s -o %t -DLockType=PthreadRecursiveMutex
-// RUN: TSAN_OPTIONS=detect_deadlocks=1 not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-REC
+// RUN: TSAN_OPTIONS=detect_deadlocks=1 %deflake %run %t | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-REC
 #include <pthread.h>
 #undef NDEBUG
 #include <assert.h>
diff --git a/test/tsan/deep_stack1.cc b/test/tsan/deep_stack1.cc
index 617f102..1d00a0e 100644
--- a/test/tsan/deep_stack1.cc
+++ b/test/tsan/deep_stack1.cc
@@ -1,5 +1,5 @@
-// RUN: %clangxx_tsan -O1 %s -o %t -DORDER1 && not %run %t 2>&1 | FileCheck %s
-// RUN: %clangxx_tsan -O1 %s -o %t -DORDER2 && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t -DORDER1 && %deflake %run %t | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t -DORDER2 && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <stdio.h>
 #include <unistd.h>
diff --git a/test/tsan/deflake.bash b/test/tsan/deflake.bash
new file mode 100755
index 0000000..9731fa5
--- /dev/null
+++ b/test/tsan/deflake.bash
@@ -0,0 +1,17 @@
+#!/usr/bin/env bash
+# This script is used to deflake inherently flaky tsan tests.
+# It is invoked from lit tests as:
+# %deflake mybinary
+# which is then substituted by lit to:
+# $(dirname %s)/deflake.bash mybinary
+# The script runs the target program up to 10 times,
+# until it fails (i.e. produces a race report).
+
+for i in $(seq 1 10); do
+	OUT=`$@ 2>&1`
+	if [[ $? != 0 ]]; then
+		echo "$OUT"
+		exit 0
+	fi
+done
+exit 1
diff --git a/test/tsan/fd_location.cc b/test/tsan/fd_location.cc
index ebe33be..535329e 100644
--- a/test/tsan/fd_location.cc
+++ b/test/tsan/fd_location.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <stdio.h>
 #include <unistd.h>
diff --git a/test/tsan/fd_pipe_race.cc b/test/tsan/fd_pipe_race.cc
index 384cafa..88c4ed4 100644
--- a/test/tsan/fd_pipe_race.cc
+++ b/test/tsan/fd_pipe_race.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <stdio.h>
 #include <unistd.h>
diff --git a/test/tsan/fd_stdout_race.cc b/test/tsan/fd_stdout_race.cc
index 47f3c6f..d6a2c7c 100644
--- a/test/tsan/fd_stdout_race.cc
+++ b/test/tsan/fd_stdout_race.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <stdio.h>
 #include <unistd.h>
diff --git a/test/tsan/free_race.c b/test/tsan/free_race.c
index 040f223..663d7bc 100644
--- a/test/tsan/free_race.c
+++ b/test/tsan/free_race.c
@@ -1,5 +1,5 @@
 // RUN: %clang_tsan -O1 %s -o %t
-// RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NOZUPP
+// RUN: %deflake %run %t | FileCheck %s --check-prefix=CHECK-NOZUPP
 // RUN: TSAN_OPTIONS="suppressions=%s.supp print_suppressions=1" %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-SUPP
 
 #include <pthread.h>
diff --git a/test/tsan/free_race2.c b/test/tsan/free_race2.c
index 2b979f3..de6b2ae 100644
--- a/test/tsan/free_race2.c
+++ b/test/tsan/free_race2.c
@@ -1,4 +1,4 @@
-// RUN: %clang_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <stdlib.h>
 
 void __attribute__((noinline)) foo(int *mem) {
diff --git a/test/tsan/global_race.cc b/test/tsan/global_race.cc
index d28700c..224ab22 100644
--- a/test/tsan/global_race.cc
+++ b/test/tsan/global_race.cc
@@ -1,44 +1,26 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <stdio.h>
 #include <stddef.h>
 #include <unistd.h>
 
 int GlobalData[10];
-int x;
-namespace XXX {
-  struct YYY {
-    static int ZZZ[10];
-  };
-  int YYY::ZZZ[10];
-}
 
 void *Thread(void *a) {
   sleep(1);
   GlobalData[2] = 42;
-  x = 1;
-  XXX::YYY::ZZZ[0] = 1;
   return 0;
 }
 
 int main() {
   fprintf(stderr, "addr=%p\n", GlobalData);
-  fprintf(stderr, "addr2=%p\n", &x);
-  fprintf(stderr, "addr3=%p\n", XXX::YYY::ZZZ);
   pthread_t t;
   pthread_create(&t, 0, Thread, 0);
   GlobalData[2] = 43;
-  x = 0;
-  XXX::YYY::ZZZ[0] = 0;
   pthread_join(t, 0);
 }
 
 // CHECK: addr=[[ADDR:0x[0-9,a-f]+]]
-// CHECK: addr2=[[ADDR2:0x[0-9,a-f]+]]
-// CHECK: addr3=[[ADDR3:0x[0-9,a-f]+]]
 // CHECK: WARNING: ThreadSanitizer: data race
 // CHECK: Location is global 'GlobalData' of size 40 at [[ADDR]] ({{.*}}+0x{{[0-9,a-f]+}})
-// CHECK: WARNING: ThreadSanitizer: data race
-// CHECK: Location is global 'x' of size 4 at [[ADDR2]] ({{.*}}+0x{{[0-9,a-f]+}})
-// CHECK: WARNING: ThreadSanitizer: data race
-// CHECK: Location is global 'XXX::YYY::ZZZ' of size 40 at [[ADDR3]] ({{.*}}+0x{{[0-9,a-f]+}})
+
diff --git a/test/tsan/global_race2.cc b/test/tsan/global_race2.cc
new file mode 100644
index 0000000..b8352ba
--- /dev/null
+++ b/test/tsan/global_race2.cc
@@ -0,0 +1,26 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
+#include <pthread.h>
+#include <stdio.h>
+#include <stddef.h>
+#include <unistd.h>
+
+int x;
+
+void *Thread(void *a) {
+  sleep(1);
+  x = 1;
+  return 0;
+}
+
+int main() {
+  fprintf(stderr, "addr2=%p\n", &x);
+  pthread_t t;
+  pthread_create(&t, 0, Thread, 0);
+  x = 0;
+  pthread_join(t, 0);
+}
+
+// CHECK: addr2=[[ADDR2:0x[0-9,a-f]+]]
+// CHECK: WARNING: ThreadSanitizer: data race
+// CHECK: Location is global 'x' of size 4 at [[ADDR2]] ({{.*}}+0x{{[0-9,a-f]+}})
+
diff --git a/test/tsan/global_race3.cc b/test/tsan/global_race3.cc
new file mode 100644
index 0000000..e37bf78
--- /dev/null
+++ b/test/tsan/global_race3.cc
@@ -0,0 +1,30 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
+#include <pthread.h>
+#include <stdio.h>
+#include <stddef.h>
+#include <unistd.h>
+
+namespace XXX {
+  struct YYY {
+    static int ZZZ[10];
+  };
+  int YYY::ZZZ[10];
+}
+
+void *Thread(void *a) {
+  sleep(1);
+  XXX::YYY::ZZZ[0] = 1;
+  return 0;
+}
+
+int main() {
+  fprintf(stderr, "addr3=%p\n", XXX::YYY::ZZZ);
+  pthread_t t;
+  pthread_create(&t, 0, Thread, 0);
+  XXX::YYY::ZZZ[0] = 0;
+  pthread_join(t, 0);
+}
+
+// CHECK: addr3=[[ADDR3:0x[0-9,a-f]+]]
+// CHECK: WARNING: ThreadSanitizer: data race
+// CHECK: Location is global 'XXX::YYY::ZZZ' of size 40 at [[ADDR3]] ({{.*}}+0x{{[0-9,a-f]+}})
diff --git a/test/tsan/halt_on_error.cc b/test/tsan/halt_on_error.cc
index 4574801..3c55c60 100644
--- a/test/tsan/halt_on_error.cc
+++ b/test/tsan/halt_on_error.cc
@@ -1,4 +1,4 @@
-// RUN: %clang_tsan -O1 %s -o %t && TSAN_OPTIONS="$TSAN_OPTIONS halt_on_error=1" not %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan -O1 %s -o %t && TSAN_OPTIONS="$TSAN_OPTIONS halt_on_error=1" %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <stdio.h>
 #include <unistd.h>
diff --git a/test/tsan/heap_race.cc b/test/tsan/heap_race.cc
index 63591e0..c3da68f 100644
--- a/test/tsan/heap_race.cc
+++ b/test/tsan/heap_race.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <stdio.h>
 #include <stddef.h>
diff --git a/test/tsan/ignore_lib0.cc b/test/tsan/ignore_lib0.cc
index d62aa99..fe1a355 100644
--- a/test/tsan/ignore_lib0.cc
+++ b/test/tsan/ignore_lib0.cc
@@ -1,7 +1,7 @@
 // RUN: %clangxx_tsan -O1 %s -DLIB -fPIC -fno-sanitize=thread -shared -o %T/libignore_lib0.so
 // RUN: %clangxx_tsan -O1 %s -L%T -lignore_lib0 -o %t
 // RUN: echo running w/o suppressions:
-// RUN: LD_LIBRARY_PATH=%T${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NOSUPP
+// RUN: LD_LIBRARY_PATH=%T${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} %deflake %run %t | FileCheck %s --check-prefix=CHECK-NOSUPP
 // RUN: echo running with suppressions:
 // RUN: LD_LIBRARY_PATH=%T${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} TSAN_OPTIONS="$TSAN_OPTIONS suppressions=%s.supp" %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-WITHSUPP
 
diff --git a/test/tsan/ignore_lib1.cc b/test/tsan/ignore_lib1.cc
index b848350..30a9994 100644
--- a/test/tsan/ignore_lib1.cc
+++ b/test/tsan/ignore_lib1.cc
@@ -1,7 +1,7 @@
 // RUN: %clangxx_tsan -O1 %s -DLIB -fPIC -fno-sanitize=thread -shared -o %T/libignore_lib1.so
 // RUN: %clangxx_tsan -O1 %s -o %t
 // RUN: echo running w/o suppressions:
-// RUN: not %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-NOSUPP
+// RUN: %deflake %run %t | FileCheck %s --check-prefix=CHECK-NOSUPP
 // RUN: echo running with suppressions:
 // RUN: TSAN_OPTIONS="$TSAN_OPTIONS suppressions=%s.supp" %run %t 2>&1 | FileCheck %s --check-prefix=CHECK-WITHSUPP
 
diff --git a/test/tsan/ignore_lib2.cc b/test/tsan/ignore_lib2.cc
index 7467ec0..23a0872 100644
--- a/test/tsan/ignore_lib2.cc
+++ b/test/tsan/ignore_lib2.cc
@@ -1,7 +1,7 @@
 // RUN: %clangxx_tsan -O1 %s -DLIB -fPIC -fno-sanitize=thread -shared -o %T/libignore_lib2_0.so
 // RUN: %clangxx_tsan -O1 %s -DLIB -fPIC -fno-sanitize=thread -shared -o %T/libignore_lib2_1.so
 // RUN: %clangxx_tsan -O1 %s -o %t
-// RUN: TSAN_OPTIONS="$TSAN_OPTIONS suppressions=%s.supp" not %run %t 2>&1 | FileCheck %s
+// RUN: TSAN_OPTIONS="$TSAN_OPTIONS suppressions=%s.supp" %deflake %run %t | FileCheck %s
 
 // Tests that called_from_lib suppression matched against 2 libraries
 // causes program crash (this is not supported).
diff --git a/test/tsan/ignore_lib3.cc b/test/tsan/ignore_lib3.cc
index 6a5f5cc..137109e 100644
--- a/test/tsan/ignore_lib3.cc
+++ b/test/tsan/ignore_lib3.cc
@@ -1,6 +1,6 @@
 // RUN: %clangxx_tsan -O1 %s -DLIB -fPIC -fno-sanitize=thread -shared -o %T/libignore_lib3.so
 // RUN: %clangxx_tsan -O1 %s -o %t
-// RUN: TSAN_OPTIONS="$TSAN_OPTIONS suppressions=%s.supp" not %run %t 2>&1 | FileCheck %s
+// RUN: TSAN_OPTIONS="$TSAN_OPTIONS suppressions=%s.supp" %deflake %run %t | FileCheck %s
 
 // Tests that unloading of a library matched against called_from_lib suppression
 // causes program crash (this is not supported).
diff --git a/test/tsan/ignore_sync.cc b/test/tsan/ignore_sync.cc
index ae6edae..ae24a8c 100644
--- a/test/tsan/ignore_sync.cc
+++ b/test/tsan/ignore_sync.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <stdio.h>
 
diff --git a/test/tsan/inlined_memcpy_race.cc b/test/tsan/inlined_memcpy_race.cc
index 12f82d2..a95576a 100644
--- a/test/tsan/inlined_memcpy_race.cc
+++ b/test/tsan/inlined_memcpy_race.cc
@@ -1,22 +1,17 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <stddef.h>
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
 
-int x[4], y[4], z[4];
+int x[4], z[4];
 
 void *MemCpyThread(void *a) {
   memcpy((int*)a, z, 16);
   return NULL;
 }
 
-void *MemMoveThread(void *a) {
-  memmove((int*)a, z, 16);
-  return NULL;
-}
-
 void *MemSetThread(void *a) {
   sleep(1);
   memset((int*)a, 0, 16);
@@ -30,12 +25,6 @@
   pthread_create(&t[1], NULL, MemSetThread, x);
   pthread_join(t[0], NULL);
   pthread_join(t[1], NULL);
-  // Race on y between memmove and memset
-  pthread_create(&t[0], NULL, MemMoveThread, y);
-  pthread_create(&t[1], NULL, MemSetThread, y);
-  pthread_join(t[0], NULL);
-  pthread_join(t[1], NULL);
-
   printf("PASS\n");
   return 0;
 }
@@ -47,9 +36,3 @@
 // CHECK:   #0 memcpy
 // CHECK:   #1 MemCpyThread
 
-// CHECK: WARNING: ThreadSanitizer: data race
-// CHECK:   #0 memset
-// CHECK:   #1 MemSetThread
-// CHECK:  Previous write
-// CHECK:   #0 memmove
-// CHECK:   #1 MemMoveThread
diff --git a/test/tsan/inlined_memcpy_race2.cc b/test/tsan/inlined_memcpy_race2.cc
new file mode 100644
index 0000000..63b560f
--- /dev/null
+++ b/test/tsan/inlined_memcpy_race2.cc
@@ -0,0 +1,38 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
+#include <pthread.h>
+#include <stddef.h>
+#include <stdio.h>
+#include <string.h>
+#include <unistd.h>
+
+int y[4], z[4];
+
+void *MemMoveThread(void *a) {
+  memmove((int*)a, z, 16);
+  return NULL;
+}
+
+void *MemSetThread(void *a) {
+  sleep(1);
+  memset((int*)a, 0, 16);
+  return NULL;
+}
+
+int main() {
+  pthread_t t[2];
+  // Race on y between memmove and memset
+  pthread_create(&t[0], NULL, MemMoveThread, y);
+  pthread_create(&t[1], NULL, MemSetThread, y);
+  pthread_join(t[0], NULL);
+  pthread_join(t[1], NULL);
+
+  printf("PASS\n");
+  return 0;
+}
+
+// CHECK: WARNING: ThreadSanitizer: data race
+// CHECK:   #0 memset
+// CHECK:   #1 MemSetThread
+// CHECK:  Previous write
+// CHECK:   #0 memmove
+// CHECK:   #1 MemMoveThread
diff --git a/test/tsan/java.h b/test/tsan/java.h
index 7aa0bca..d986d08 100644
--- a/test/tsan/java.h
+++ b/test/tsan/java.h
@@ -11,6 +11,7 @@
 void __tsan_java_alloc(jptr ptr, jptr size);
 void __tsan_java_free(jptr ptr, jptr size);
 void __tsan_java_move(jptr src, jptr dst, jptr size);
+void __tsan_java_finalize();
 void __tsan_java_mutex_lock(jptr addr);
 void __tsan_java_mutex_unlock(jptr addr);
 void __tsan_java_mutex_read_lock(jptr addr);
diff --git a/test/tsan/java_alloc.cc b/test/tsan/java_alloc.cc
index 0c9c4eb..4a606f7 100644
--- a/test/tsan/java_alloc.cc
+++ b/test/tsan/java_alloc.cc
@@ -19,14 +19,20 @@
 }
 
 int main() {
-  jptr jheap = (jptr)malloc(kHeapSize);
+  jptr jheap = (jptr)malloc(kHeapSize + 8) + 8;
   __tsan_java_init(jheap, kHeapSize);
   pthread_t th;
   pthread_create(&th, 0, Thread, (void*)(jheap + kHeapSize / 4));
   stress(jheap);
   pthread_join(th, 0);
-  printf("OK\n");
-  return __tsan_java_fini();
+  if (__tsan_java_fini() != 0) {
+    printf("FAILED\n");
+    return 1;
+  }
+  printf("DONE\n");
+  return 0;
 }
 
 // CHECK-NOT: WARNING: ThreadSanitizer: data race
+// CHECK-NOT: FAILED
+// CHECK: DONE
diff --git a/test/tsan/java_finalizer.cc b/test/tsan/java_finalizer.cc
new file mode 100644
index 0000000..d5c6a22
--- /dev/null
+++ b/test/tsan/java_finalizer.cc
@@ -0,0 +1,27 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %run %t 2>&1 | FileCheck %s
+#include "java.h"
+
+void *Thread(void *p) {
+  sleep(1);
+  __tsan_java_finalize();
+  *(int*)p = 42;
+  return 0;
+}
+
+int main() {
+  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);
+  *(int*)jheap = 43;
+  pthread_join(th, 0);
+  __tsan_java_free(jheap, kBlockSize);
+  fprintf(stderr, "DONE\n");
+  return __tsan_java_fini();
+}
+
+// CHECK-NOT: WARNING: ThreadSanitizer: data race
+// CHECK: DONE
diff --git a/test/tsan/java_lock.cc b/test/tsan/java_lock.cc
index e5513cd..36a0f8b 100644
--- a/test/tsan/java_lock.cc
+++ b/test/tsan/java_lock.cc
@@ -15,21 +15,22 @@
 
 int main() {
   int const kHeapSize = 1024 * 1024;
-  void *jheap = malloc(kHeapSize);
-  __tsan_java_init((jptr)jheap, kHeapSize);
+  jptr jheap = (jptr)malloc(kHeapSize + 8) + 8;
+  __tsan_java_init(jheap, kHeapSize);
   const int kBlockSize = 16;
-  __tsan_java_alloc((jptr)jheap, kBlockSize);
-  varaddr = (jptr)jheap;
-  lockaddr = (jptr)jheap + 8;
+  __tsan_java_alloc(jheap, kBlockSize);
+  varaddr = jheap;
+  lockaddr = jheap + 8;
   pthread_t th;
   pthread_create(&th, 0, Thread, 0);
   __tsan_java_mutex_lock(lockaddr);
   *(int*)varaddr = 43;
   __tsan_java_mutex_unlock(lockaddr);
   pthread_join(th, 0);
-  __tsan_java_free((jptr)jheap, kBlockSize);
-  printf("OK\n");
+  __tsan_java_free(jheap, kBlockSize);
+  fprintf(stderr, "DONE\n");
   return __tsan_java_fini();
 }
 
 // CHECK-NOT: WARNING: ThreadSanitizer: data race
+// CHECK: DONE
diff --git a/test/tsan/java_lock_move.cc b/test/tsan/java_lock_move.cc
index 15a72c7..19c3e35 100644
--- a/test/tsan/java_lock_move.cc
+++ b/test/tsan/java_lock_move.cc
@@ -16,13 +16,13 @@
 
 int main() {
   int const kHeapSize = 1024 * 1024;
-  void *jheap = malloc(kHeapSize);
-  __tsan_java_init((jptr)jheap, kHeapSize);
+  jptr jheap = (jptr)malloc(kHeapSize + 8) + 8;
+  __tsan_java_init(jheap, kHeapSize);
   const int kBlockSize = 64;
   int const kMove = 1024;
-  __tsan_java_alloc((jptr)jheap, kBlockSize);
-  varaddr = (jptr)jheap;
-  lockaddr = (jptr)jheap + 46;
+  __tsan_java_alloc(jheap, kBlockSize);
+  varaddr = jheap;
+  lockaddr = jheap + 46;
   varaddr2 = varaddr + kMove;
   lockaddr2 = lockaddr + kMove;
   pthread_t th;
@@ -33,8 +33,9 @@
   __tsan_java_move(varaddr, varaddr2, kBlockSize);
   pthread_join(th, 0);
   __tsan_java_free(varaddr2, kBlockSize);
-  printf("OK\n");
+  printf("DONE\n");
   return __tsan_java_fini();
 }
 
 // CHECK-NOT: WARNING: ThreadSanitizer: data race
+// CHECK: DONE
diff --git a/test/tsan/java_lock_rec.cc b/test/tsan/java_lock_rec.cc
index 9223695..2b0ab0e 100644
--- a/test/tsan/java_lock_rec.cc
+++ b/test/tsan/java_lock_rec.cc
@@ -27,13 +27,13 @@
 
 int main() {
   int const kHeapSize = 1024 * 1024;
-  void *jheap = malloc(kHeapSize);
-  __tsan_java_init((jptr)jheap, kHeapSize);
+  jptr jheap = (jptr)malloc(kHeapSize + 8) + 8;
+  __tsan_java_init(jheap, kHeapSize);
   const int kBlockSize = 16;
-  __tsan_java_alloc((jptr)jheap, kBlockSize);
-  varaddr = (jptr)jheap;
+  __tsan_java_alloc(jheap, kBlockSize);
+  varaddr = jheap;
   *(int*)varaddr = 0;
-  lockaddr = (jptr)jheap + 8;
+  lockaddr = jheap + 8;
   pthread_t th;
   pthread_create(&th, 0, Thread, 0);
   sleep(1);
@@ -45,10 +45,11 @@
   *(int*)varaddr = 43;
   __tsan_java_mutex_unlock(lockaddr);
   pthread_join(th, 0);
-  __tsan_java_free((jptr)jheap, kBlockSize);
-  printf("OK\n");
+  __tsan_java_free(jheap, kBlockSize);
+  printf("DONE\n");
   return __tsan_java_fini();
 }
 
 // CHECK-NOT: WARNING: ThreadSanitizer: data race
 // CHECK-NOT: FAILED
+// CHECK: DONE
diff --git a/test/tsan/java_lock_rec_race.cc b/test/tsan/java_lock_rec_race.cc
index 41aa1ca..841aa39 100644
--- a/test/tsan/java_lock_rec_race.cc
+++ b/test/tsan/java_lock_rec_race.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include "java.h"
 #include <unistd.h>
 
@@ -25,13 +25,13 @@
 
 int main() {
   int const kHeapSize = 1024 * 1024;
-  void *jheap = malloc(kHeapSize);
-  __tsan_java_init((jptr)jheap, kHeapSize);
+  jptr jheap = (jptr)malloc(kHeapSize + 8) + 8;
+  __tsan_java_init(jheap, kHeapSize);
   const int kBlockSize = 16;
-  __tsan_java_alloc((jptr)jheap, kBlockSize);
-  varaddr = (jptr)jheap;
+  __tsan_java_alloc(jheap, kBlockSize);
+  varaddr = jheap;
   *(int*)varaddr = 0;
-  lockaddr = (jptr)jheap + 8;
+  lockaddr = jheap + 8;
   pthread_t th;
   pthread_create(&th, 0, Thread, 0);
   sleep(1);
@@ -39,10 +39,11 @@
   *(int*)varaddr = 43;
   __tsan_java_mutex_unlock(lockaddr);
   pthread_join(th, 0);
-  __tsan_java_free((jptr)jheap, kBlockSize);
-  printf("OK\n");
+  __tsan_java_free(jheap, kBlockSize);
+  printf("DONE\n");
   return __tsan_java_fini();
 }
 
 // CHECK: WARNING: ThreadSanitizer: data race
 // CHECK-NOT: FAILED
+// CHECK: DONE
diff --git a/test/tsan/java_move_overlap.cc b/test/tsan/java_move_overlap.cc
new file mode 100644
index 0000000..12955b4
--- /dev/null
+++ b/test/tsan/java_move_overlap.cc
@@ -0,0 +1,72 @@
+// RUN: %clangxx_tsan -O1 %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s
+// RUN: %run %t arg 2>&1 | FileCheck %s
+#include "java.h"
+
+jptr varaddr1_old;
+jptr varaddr2_old;
+jptr lockaddr1_old;
+jptr lockaddr2_old;
+jptr varaddr1_new;
+jptr varaddr2_new;
+jptr lockaddr1_new;
+jptr lockaddr2_new;
+
+void *Thread(void *p) {
+  sleep(1);
+  __tsan_java_mutex_lock(lockaddr1_new);
+  *(char*)varaddr1_new = 43;
+  __tsan_java_mutex_unlock(lockaddr1_new);
+  __tsan_java_mutex_lock(lockaddr2_new);
+  *(char*)varaddr2_new = 43;
+  __tsan_java_mutex_unlock(lockaddr2_new);
+  return 0;
+}
+
+int main(int argc, char **argv) {
+  int const kHeapSize = 1024 * 1024;
+  void *jheap = malloc(kHeapSize);
+  jheap = (char*)jheap + 8;
+  __tsan_java_init((jptr)jheap, kHeapSize);
+  const int kBlockSize = 64;
+  int const kMove = 32;
+  varaddr1_old = (jptr)jheap;
+  lockaddr1_old = (jptr)jheap + 1;
+  varaddr2_old = (jptr)jheap + kBlockSize - 1;
+  lockaddr2_old = (jptr)jheap + kBlockSize - 16;
+  varaddr1_new = varaddr1_old + kMove;
+  lockaddr1_new = lockaddr1_old + kMove;
+  varaddr2_new = varaddr2_old + kMove;
+  lockaddr2_new = lockaddr2_old + kMove;
+  if (argc > 1) {
+    // Move memory backwards.
+    varaddr1_old += kMove;
+    lockaddr1_old += kMove;
+    varaddr2_old += kMove;
+    lockaddr2_old += kMove;
+    varaddr1_new -= kMove;
+    lockaddr1_new -= kMove;
+    varaddr2_new -= kMove;
+    lockaddr2_new -= kMove;
+  }
+  __tsan_java_alloc(varaddr1_old, kBlockSize);
+
+  pthread_t th;
+  pthread_create(&th, 0, Thread, 0);
+
+  __tsan_java_mutex_lock(lockaddr1_old);
+  *(char*)varaddr1_old = 43;
+  __tsan_java_mutex_unlock(lockaddr1_old);
+  __tsan_java_mutex_lock(lockaddr2_old);
+  *(char*)varaddr2_old = 43;
+  __tsan_java_mutex_unlock(lockaddr2_old);
+
+  __tsan_java_move(varaddr1_old, varaddr1_new, kBlockSize);
+  pthread_join(th, 0);
+  __tsan_java_free(varaddr1_new, kBlockSize);
+  printf("DONE\n");
+  return __tsan_java_fini();
+}
+
+// CHECK-NOT: WARNING: ThreadSanitizer: data race
+// CHECK: DONE
diff --git a/test/tsan/java_move_overlap_race.cc b/test/tsan/java_move_overlap_race.cc
new file mode 100644
index 0000000..2b3769b
--- /dev/null
+++ b/test/tsan/java_move_overlap_race.cc
@@ -0,0 +1,53 @@
+// RUN: %clangxx_tsan -O1 %s -o %t
+// RUN: %deflake %run %t | FileCheck %s
+// RUN: %deflake %run %t arg | FileCheck %s
+#include "java.h"
+
+jptr varaddr1_old;
+jptr varaddr2_old;
+jptr varaddr1_new;
+jptr varaddr2_new;
+
+void *Thread(void *p) {
+  sleep(1);
+  *(int*)varaddr1_new = 43;
+  *(int*)varaddr2_new = 43;
+  return 0;
+}
+
+int main(int argc, char **argv) {
+  int const kHeapSize = 1024 * 1024;
+  void *jheap = malloc(kHeapSize);
+  jheap = (char*)jheap + 8;
+  __tsan_java_init((jptr)jheap, kHeapSize);
+  const int kBlockSize = 64;
+  int const kMove = 32;
+  varaddr1_old = (jptr)jheap;
+  varaddr2_old = (jptr)jheap + kBlockSize - 1;
+  varaddr1_new = varaddr1_old + kMove;
+  varaddr2_new = varaddr2_old + kMove;
+  if (argc > 1) {
+    // Move memory backwards.
+    varaddr1_old += kMove;
+    varaddr2_old += kMove;
+    varaddr1_new -= kMove;
+    varaddr2_new -= kMove;
+  }
+  __tsan_java_alloc(varaddr1_old, kBlockSize);
+
+  pthread_t th;
+  pthread_create(&th, 0, Thread, 0);
+
+  *(int*)varaddr1_old = 43;
+  *(int*)varaddr2_old = 43;
+
+  __tsan_java_move(varaddr1_old, varaddr1_new, kBlockSize);
+  pthread_join(th, 0);
+  __tsan_java_free(varaddr1_new, kBlockSize);
+  printf("DONE\n");
+  return __tsan_java_fini();
+}
+
+// CHECK: WARNING: ThreadSanitizer: data race
+// CHECK: WARNING: ThreadSanitizer: data race
+// CHECK: DONE
diff --git a/test/tsan/java_race.cc b/test/tsan/java_race.cc
index 70ad8c4..ede058e 100644
--- a/test/tsan/java_race.cc
+++ b/test/tsan/java_race.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include "java.h"
 
 void *Thread(void *p) {
@@ -8,16 +8,18 @@
 
 int main() {
   int const kHeapSize = 1024 * 1024;
-  void *jheap = malloc(kHeapSize);
-  __tsan_java_init((jptr)jheap, kHeapSize);
+  jptr jheap = (jptr)malloc(kHeapSize + 8) + 8;
+  __tsan_java_init(jheap, kHeapSize);
   const int kBlockSize = 16;
-  __tsan_java_alloc((jptr)jheap, kBlockSize);
+  __tsan_java_alloc(jheap, kBlockSize);
   pthread_t th;
-  pthread_create(&th, 0, Thread, jheap);
+  pthread_create(&th, 0, Thread, (void*)jheap);
   *(int*)jheap = 43;
   pthread_join(th, 0);
-  __tsan_java_free((jptr)jheap, kBlockSize);
+  __tsan_java_free(jheap, kBlockSize);
+  fprintf(stderr, "DONE\n");
   return __tsan_java_fini();
 }
 
 // CHECK: WARNING: ThreadSanitizer: data race
+// CHECK: DONE
diff --git a/test/tsan/java_race_move.cc b/test/tsan/java_race_move.cc
index 76da91b..8a51be9 100644
--- a/test/tsan/java_race_move.cc
+++ b/test/tsan/java_race_move.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include "java.h"
 
 jptr varaddr;
@@ -12,12 +12,12 @@
 
 int main() {
   int const kHeapSize = 1024 * 1024;
-  void *jheap = malloc(kHeapSize);
-  __tsan_java_init((jptr)jheap, kHeapSize);
+  jptr jheap = (jptr)malloc(kHeapSize + 8) + 8;
+  __tsan_java_init(jheap, kHeapSize);
   const int kBlockSize = 64;
   int const kMove = 1024;
-  __tsan_java_alloc((jptr)jheap, kBlockSize);
-  varaddr = (jptr)jheap + 16;
+  __tsan_java_alloc(jheap, kBlockSize);
+  varaddr = jheap + 16;
   varaddr2 = varaddr + kMove;
   pthread_t th;
   pthread_create(&th, 0, Thread, 0);
@@ -25,7 +25,9 @@
   __tsan_java_move(varaddr, varaddr2, kBlockSize);
   pthread_join(th, 0);
   __tsan_java_free(varaddr2, kBlockSize);
+  fprintf(stderr, "DONE\n");
   return __tsan_java_fini();
 }
 
 // CHECK: WARNING: ThreadSanitizer: data race
+// CHECK: DONE
diff --git a/test/tsan/java_rwlock.cc b/test/tsan/java_rwlock.cc
index d43dfe1..b03afa6 100644
--- a/test/tsan/java_rwlock.cc
+++ b/test/tsan/java_rwlock.cc
@@ -15,21 +15,22 @@
 
 int main() {
   int const kHeapSize = 1024 * 1024;
-  void *jheap = malloc(kHeapSize);
-  __tsan_java_init((jptr)jheap, kHeapSize);
+  jptr jheap = (jptr)malloc(kHeapSize + 8) + 8;
+  __tsan_java_init(jheap, kHeapSize);
   const int kBlockSize = 16;
-  __tsan_java_alloc((jptr)jheap, kBlockSize);
-  varaddr = (jptr)jheap;
-  lockaddr = (jptr)jheap + 8;
+  __tsan_java_alloc(jheap, kBlockSize);
+  varaddr = jheap;
+  lockaddr = jheap + 8;
   pthread_t th;
   pthread_create(&th, 0, Thread, 0);
   __tsan_java_mutex_lock(lockaddr);
   *(int*)varaddr = 43;
   __tsan_java_mutex_unlock(lockaddr);
   pthread_join(th, 0);
-  __tsan_java_free((jptr)jheap, kBlockSize);
-  printf("OK\n");
+  __tsan_java_free(jheap, kBlockSize);
+  printf("DONE\n");
   return __tsan_java_fini();
 }
 
 // CHECK-NOT: WARNING: ThreadSanitizer: data race
+// CHECK: DONE
diff --git a/test/tsan/lit.cfg b/test/tsan/lit.cfg
index ae21971..f7051b3 100644
--- a/test/tsan/lit.cfg
+++ b/test/tsan/lit.cfg
@@ -24,7 +24,7 @@
 
 # GCC driver doesn't add necessary compile/link flags with -fsanitize=thread.
 if config.compiler_id == 'GNU':
-  extra_cflags = ["-fPIE", "-lpthread", "-ldl", "-lstdc++", "-lrt", "-pie"]
+  extra_cflags = ["-fPIE", "-pthread", "-ldl", "-lstdc++", "-lrt", "-pie"]
 else:
   extra_cflags = []
 
@@ -57,6 +57,8 @@
 # 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")) )
+
 # Default test suffixes.
 config.suffixes = ['.c', '.cc', '.cpp']
 
diff --git a/test/tsan/load_shared_lib.cc b/test/tsan/load_shared_lib.cc
index 2b250e3..a27dc1c 100644
--- a/test/tsan/load_shared_lib.cc
+++ b/test/tsan/load_shared_lib.cc
@@ -2,9 +2,25 @@
 // reports, the second report occurring in a new shared library is still
 // symbolized correctly.
 
-// RUN: %clangxx_tsan -O1 %p/SharedLibs/load_shared_lib-so.cc \
-// RUN:     -fPIC -shared -o %t-so.so
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -DBUILD_SO -fPIC -shared -o %t-so.so
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
+
+#ifdef BUILD_SO
+
+#include <stddef.h>
+#include <unistd.h>
+
+int GLOB_SHARED = 0;
+
+extern "C"
+void *write_from_so(void *unused) {
+  if (unused)
+    sleep(1);
+  GLOB_SHARED++;
+  return NULL;
+}
+
+#else  // BUILD_SO
 
 #include <dlfcn.h>
 #include <pthread.h>
@@ -46,3 +62,5 @@
   // CHECK: write_from_so
   return 0;
 }
+
+#endif  // BUILD_SO
diff --git a/test/tsan/longjmp3.cc b/test/tsan/longjmp3.cc
index afb4996..71d964d 100644
--- a/test/tsan/longjmp3.cc
+++ b/test/tsan/longjmp3.cc
@@ -1,4 +1,4 @@
-// RUN: %clang_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/test/tsan/longjmp4.cc b/test/tsan/longjmp4.cc
index 1ec3b4b..15330f5 100644
--- a/test/tsan/longjmp4.cc
+++ b/test/tsan/longjmp4.cc
@@ -1,4 +1,4 @@
-// RUN: %clang_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/test/tsan/malloc_hook.cc b/test/tsan/malloc_hook.cc
deleted file mode 100644
index 63e1c3c..0000000
--- a/test/tsan/malloc_hook.cc
+++ /dev/null
@@ -1,52 +0,0 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
-#include <pthread.h>
-#include <unistd.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <stddef.h>
-
-static int malloc_count;
-static int free_count;
-
-extern "C" {
-void __tsan_malloc_hook(void *ptr, size_t size) {
-  (void)ptr;
-  (void)size;
-  __sync_fetch_and_add(&malloc_count, 1);
-}
-
-void __tsan_free_hook(void *ptr) {
-  (void)ptr;
-  __sync_fetch_and_add(&free_count, 1);
-}
-}
-
-void *Thread1(void *x) {
-  ((int*)x)[0]++;
-  return 0;
-}
-
-void *Thread2(void *x) {
-  sleep(1);
-  ((int*)x)[0]++;
-  return 0;
-}
-
-int main() {
-  int *x = new int;
-  pthread_t t[2];
-  pthread_create(&t[0], 0, Thread1, x);
-  pthread_create(&t[1], 0, Thread2, x);
-  pthread_join(t[0], 0);
-  pthread_join(t[1], 0);
-  delete x;
-  if (malloc_count == 0 || free_count == 0) {
-    fprintf(stderr, "FAILED %d %d\n", malloc_count, free_count);
-    exit(1);
-  }
-  fprintf(stderr, "DONE\n");
-}
-
-// CHECK: WARNING: ThreadSanitizer: data race
-// CHECK-NOT: FAILED
-// CHECK: DONE
diff --git a/test/tsan/malloc_stack.cc b/test/tsan/malloc_stack.cc
index cea6020..6027360 100644
--- a/test/tsan/malloc_stack.cc
+++ b/test/tsan/malloc_stack.cc
@@ -1,4 +1,4 @@
-// RUN: %clang_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <unistd.h>
 
diff --git a/test/tsan/memcpy_race.cc b/test/tsan/memcpy_race.cc
index d7314d2..8ec8e0a 100644
--- a/test/tsan/memcpy_race.cc
+++ b/test/tsan/memcpy_race.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <stddef.h>
 #include <stdio.h>
diff --git a/test/tsan/mop_with_offset.cc b/test/tsan/mop_with_offset.cc
index e934279..e44c78b 100644
--- a/test/tsan/mop_with_offset.cc
+++ b/test/tsan/mop_with_offset.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <stddef.h>
 #include <stdio.h>
diff --git a/test/tsan/mop_with_offset2.cc b/test/tsan/mop_with_offset2.cc
index 31b4a40..a465d5f 100644
--- a/test/tsan/mop_with_offset2.cc
+++ b/test/tsan/mop_with_offset2.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <stddef.h>
 #include <stdio.h>
diff --git a/test/tsan/mutex_bad_read_lock.cc b/test/tsan/mutex_bad_read_lock.cc
index c64bf88..84a2976 100644
--- a/test/tsan/mutex_bad_read_lock.cc
+++ b/test/tsan/mutex_bad_read_lock.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// 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);
 
 int main() {
diff --git a/test/tsan/mutex_bad_read_unlock.cc b/test/tsan/mutex_bad_read_unlock.cc
index ab417f4..dcee515 100644
--- a/test/tsan/mutex_bad_read_unlock.cc
+++ b/test/tsan/mutex_bad_read_unlock.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// 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);
 
diff --git a/test/tsan/mutex_bad_unlock.cc b/test/tsan/mutex_bad_unlock.cc
index 3019035..6b483cf 100644
--- a/test/tsan/mutex_bad_unlock.cc
+++ b/test/tsan/mutex_bad_unlock.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// 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);
 
 int main() {
diff --git a/test/tsan/mutex_cycle2.c b/test/tsan/mutex_cycle2.c
index fb2b533..031830d 100644
--- a/test/tsan/mutex_cycle2.c
+++ b/test/tsan/mutex_cycle2.c
@@ -1,10 +1,13 @@
 // RUN: %clangxx_tsan %s -o %t
+// RUN:                                 not %run %t 2>&1 | FileCheck %s
 // RUN: TSAN_OPTIONS=detect_deadlocks=1 not %run %t 2>&1 | FileCheck %s
-// RUN: echo "deadlock:main" > sup
-// RUN: TSAN_OPTIONS="detect_deadlocks=1 suppressions=sup" %run %t
-// RUN: echo "deadlock:zzzz" > sup
-// RUN: TSAN_OPTIONS="detect_deadlocks=1 suppressions=sup" not %run %t 2>&1 | FileCheck %s
+// RUN: TSAN_OPTIONS=detect_deadlocks=0     %run %t 2>&1 | FileCheck %s --check-prefix=DISABLED
+// RUN: echo "deadlock:main" > %t.sup
+// RUN: TSAN_OPTIONS="suppressions=%t.sup" %run %t 2>&1 | FileCheck %s --check-prefix=DISABLED
+// RUN: echo "deadlock:zzzz" > %t.sup
+// RUN: TSAN_OPTIONS="suppressions=%t.sup" not %run %t 2>&1 | FileCheck %s
 #include <pthread.h>
+#include <stdio.h>
 
 int main() {
   pthread_mutex_t mu1, mu2;
@@ -21,9 +24,12 @@
   pthread_mutex_lock(&mu2);
   pthread_mutex_lock(&mu1);
   // CHECK: ThreadSanitizer: lock-order-inversion (potential deadlock)
+  // DISABLED-NOT: ThreadSanitizer
+  // DISABLED: PASS
   pthread_mutex_unlock(&mu1);
   pthread_mutex_unlock(&mu2);
 
   pthread_mutex_destroy(&mu1);
   pthread_mutex_destroy(&mu2);
+  fprintf(stderr, "PASS\n");
 }
diff --git a/test/tsan/mutex_destroy_locked.cc b/test/tsan/mutex_destroy_locked.cc
index 6c5dcbf..b81905e 100644
--- a/test/tsan/mutex_destroy_locked.cc
+++ b/test/tsan/mutex_destroy_locked.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <unistd.h>
 
diff --git a/test/tsan/mutex_double_lock.cc b/test/tsan/mutex_double_lock.cc
index 551d911..c1bebf7 100644
--- a/test/tsan/mutex_double_lock.cc
+++ b/test/tsan/mutex_double_lock.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <unistd.h>
 
diff --git a/test/tsan/mutex_robust2.cc b/test/tsan/mutex_robust2.cc
index f3125c1..0914c17 100644
--- a/test/tsan/mutex_robust2.cc
+++ b/test/tsan/mutex_robust2.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <stdlib.h>
 #include <stdio.h>
diff --git a/test/tsan/mutexset1.cc b/test/tsan/mutexset1.cc
index 49607d7..72964ed 100644
--- a/test/tsan/mutexset1.cc
+++ b/test/tsan/mutexset1.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <stdio.h>
 #include <unistd.h>
diff --git a/test/tsan/mutexset2.cc b/test/tsan/mutexset2.cc
index 80b690d..01a5f5d 100644
--- a/test/tsan/mutexset2.cc
+++ b/test/tsan/mutexset2.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <stdio.h>
 #include <unistd.h>
diff --git a/test/tsan/mutexset3.cc b/test/tsan/mutexset3.cc
index 17c27ea..e14bb11 100644
--- a/test/tsan/mutexset3.cc
+++ b/test/tsan/mutexset3.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <stdio.h>
 #include <unistd.h>
diff --git a/test/tsan/mutexset4.cc b/test/tsan/mutexset4.cc
index f56d37a..db860e0 100644
--- a/test/tsan/mutexset4.cc
+++ b/test/tsan/mutexset4.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <stdio.h>
 #include <unistd.h>
diff --git a/test/tsan/mutexset5.cc b/test/tsan/mutexset5.cc
index ea12553..e1cc2fc 100644
--- a/test/tsan/mutexset5.cc
+++ b/test/tsan/mutexset5.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <stdio.h>
 #include <unistd.h>
diff --git a/test/tsan/mutexset6.cc b/test/tsan/mutexset6.cc
index a42a743..07dcc0a 100644
--- a/test/tsan/mutexset6.cc
+++ b/test/tsan/mutexset6.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <stdio.h>
 #include <unistd.h>
diff --git a/test/tsan/mutexset7.cc b/test/tsan/mutexset7.cc
index a8a907a..1217484 100644
--- a/test/tsan/mutexset7.cc
+++ b/test/tsan/mutexset7.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <stdio.h>
 #include <unistd.h>
@@ -13,12 +13,13 @@
 }
 
 void *Thread2(void *x) {
-  pthread_mutex_t mtx;
-  pthread_mutex_init(&mtx, 0);
-  pthread_mutex_lock(&mtx);
+  pthread_mutex_t *mtx = new pthread_mutex_t;
+  pthread_mutex_init(mtx, 0);
+  pthread_mutex_lock(mtx);
   Global--;
-  pthread_mutex_unlock(&mtx);
-  pthread_mutex_destroy(&mtx);
+  pthread_mutex_unlock(mtx);
+  pthread_mutex_destroy(mtx);
+  delete mtx;
   return NULL;
 }
 
diff --git a/test/tsan/mutexset8.cc b/test/tsan/mutexset8.cc
index 23449ab..3e1ab8c 100644
--- a/test/tsan/mutexset8.cc
+++ b/test/tsan/mutexset8.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <stdio.h>
 #include <unistd.h>
diff --git a/test/tsan/oob_race.cc b/test/tsan/oob_race.cc
deleted file mode 100644
index 16c59c6..0000000
--- a/test/tsan/oob_race.cc
+++ /dev/null
@@ -1,26 +0,0 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
-#include <pthread.h>
-#include <stdio.h>
-#include <unistd.h>
-
-const long kOffset = 64*1024;
-
-void *Thread(void *p) {
-  sleep(1);
-  ((char*)p)[-kOffset] = 43;
-  return 0;
-}
-
-int main() {
-  char *volatile p0 = new char[16];
-  delete[] p0;
-  char *p = new char[32];
-  pthread_t th;
-  pthread_create(&th, 0, Thread, p);
-  p[-kOffset] = 42;
-  pthread_join(th, 0);
-}
-
-// Used to crash with CHECK failed.
-// CHECK: WARNING: ThreadSanitizer: data race
-
diff --git a/test/tsan/pthread_atfork_deadlock.c b/test/tsan/pthread_atfork_deadlock.c
index 3e91f3e..965de05 100644
--- a/test/tsan/pthread_atfork_deadlock.c
+++ b/test/tsan/pthread_atfork_deadlock.c
@@ -1,4 +1,4 @@
-// RUN: %clang_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 // Regression test for
 // https://code.google.com/p/thread-sanitizer/issues/detail?id=61
 // When the data race was reported, pthread_atfork() handler used to be
diff --git a/test/tsan/race_on_barrier.c b/test/tsan/race_on_barrier.c
index e93995a..99b18fe 100644
--- a/test/tsan/race_on_barrier.c
+++ b/test/tsan/race_on_barrier.c
@@ -1,4 +1,4 @@
-// RUN: %clang_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <stdio.h>
 #include <stddef.h>
diff --git a/test/tsan/race_on_barrier2.c b/test/tsan/race_on_barrier2.c
index 75f9b4a..98c028e 100644
--- a/test/tsan/race_on_barrier2.c
+++ b/test/tsan/race_on_barrier2.c
@@ -1,4 +1,4 @@
-// RUN: %clang_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <stdio.h>
 #include <stddef.h>
diff --git a/test/tsan/race_on_heap.cc b/test/tsan/race_on_heap.cc
index 54c4a9b..a66e0c4 100644
--- a/test/tsan/race_on_heap.cc
+++ b/test/tsan/race_on_heap.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <stdlib.h>
 #include <stdio.h>
@@ -38,7 +38,7 @@
 // CHECK: WARNING: ThreadSanitizer: data race
 // ...
 // CHECK: Location is heap block of size 99 at [[ADDR]] allocated by thread T1:
-// CHCEKL     #0 malloc
+// CHCEK:     #0 malloc
 // CHECK:     #{{1|2}} alloc
 // CHECK:     #{{2|3}} AllocThread
 // ...
diff --git a/test/tsan/race_on_mutex.c b/test/tsan/race_on_mutex.c
index d3e6210..b4adeeb 100644
--- a/test/tsan/race_on_mutex.c
+++ b/test/tsan/race_on_mutex.c
@@ -1,4 +1,4 @@
-// RUN: %clang_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <stdio.h>
 #include <stddef.h>
diff --git a/test/tsan/race_on_mutex2.c b/test/tsan/race_on_mutex2.c
index c860fc6..1796d0c 100644
--- a/test/tsan/race_on_mutex2.c
+++ b/test/tsan/race_on_mutex2.c
@@ -1,4 +1,4 @@
-// RUN: %clang_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <stdio.h>
 #include <stddef.h>
diff --git a/test/tsan/race_on_puts.cc b/test/tsan/race_on_puts.cc
new file mode 100644
index 0000000..1f2b4db
--- /dev/null
+++ b/test/tsan/race_on_puts.cc
@@ -0,0 +1,29 @@
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
+#include <pthread.h>
+#include <stdio.h>
+#include <unistd.h>
+
+char s[] = "abracadabra";
+
+void *Thread0(void *p) {
+  puts(s);
+  return 0;
+}
+
+void *Thread1(void *p) {
+  s[3] = 'z';
+  return 0;
+}
+
+int main() {
+  pthread_t th[2];
+  pthread_create(&th[0], 0, Thread0, 0);
+  pthread_create(&th[1], 0, Thread1, 0);
+  pthread_join(th[0], 0);
+  pthread_join(th[1], 0);
+  fprintf(stderr, "DONE");
+}
+
+// CHECK: WARNING: ThreadSanitizer: data race
+// CHECK: DONE
+
diff --git a/test/tsan/race_on_read.cc b/test/tsan/race_on_read.cc
index 4dc976d..1ec0522 100644
--- a/test/tsan/race_on_read.cc
+++ b/test/tsan/race_on_read.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <stdio.h>
 #include <unistd.h>
diff --git a/test/tsan/race_on_write.cc b/test/tsan/race_on_write.cc
index add22ce..484bbb7 100644
--- a/test/tsan/race_on_write.cc
+++ b/test/tsan/race_on_write.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <stdio.h>
 #include <unistd.h>
diff --git a/test/tsan/race_with_finished_thread.cc b/test/tsan/race_with_finished_thread.cc
index b3f9b70..d287600 100644
--- a/test/tsan/race_with_finished_thread.cc
+++ b/test/tsan/race_with_finished_thread.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <stddef.h>
 #include <stdio.h>
diff --git a/test/tsan/signal_errno.cc b/test/tsan/signal_errno.cc
index 326953e..27d4ecd 100644
--- a/test/tsan/signal_errno.cc
+++ b/test/tsan/signal_errno.cc
@@ -1,4 +1,4 @@
-// RUN: %clang_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/test/tsan/signal_malloc.cc b/test/tsan/signal_malloc.cc
index f6fc3fa..db5e79b 100644
--- a/test/tsan/signal_malloc.cc
+++ b/test/tsan/signal_malloc.cc
@@ -1,4 +1,4 @@
-// RUN: %clang_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <stdio.h>
 #include <stdlib.h>
 #include <signal.h>
diff --git a/test/tsan/sigsuspend.cc b/test/tsan/sigsuspend.cc
index dc96066..f614c12 100644
--- a/test/tsan/sigsuspend.cc
+++ b/test/tsan/sigsuspend.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 
 // Always enable asserts.
 #ifdef NDEBUG
diff --git a/test/tsan/simple_race.c b/test/tsan/simple_race.c
index 78f105f..7b60c5e 100644
--- a/test/tsan/simple_race.c
+++ b/test/tsan/simple_race.c
@@ -1,4 +1,4 @@
-// RUN: %clang_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <stdio.h>
 #include <unistd.h>
@@ -26,3 +26,4 @@
 }
 
 // CHECK: WARNING: ThreadSanitizer: data race
+
diff --git a/test/tsan/simple_race.cc b/test/tsan/simple_race.cc
index 9010ed5..0236b9f 100644
--- a/test/tsan/simple_race.cc
+++ b/test/tsan/simple_race.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t 2>&1 | FileCheck %s
 #include <pthread.h>
 #include <stdio.h>
 
diff --git a/test/tsan/simple_stack.c b/test/tsan/simple_stack.c
index f2326eb..899277f 100644
--- a/test/tsan/simple_stack.c
+++ b/test/tsan/simple_stack.c
@@ -1,4 +1,4 @@
-// RUN: %clang_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <stdio.h>
 #include <unistd.h>
diff --git a/test/tsan/simple_stack2.cc b/test/tsan/simple_stack2.cc
index 080387a..ba0303c 100644
--- a/test/tsan/simple_stack2.cc
+++ b/test/tsan/simple_stack2.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <stdio.h>
 #include <unistd.h>
diff --git a/test/tsan/sleep_sync.cc b/test/tsan/sleep_sync.cc
index 5047fdf..c7614e1 100644
--- a/test/tsan/sleep_sync.cc
+++ b/test/tsan/sleep_sync.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <unistd.h>
 
diff --git a/test/tsan/sleep_sync2.cc b/test/tsan/sleep_sync2.cc
index 7739405..4e61699 100644
--- a/test/tsan/sleep_sync2.cc
+++ b/test/tsan/sleep_sync2.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <unistd.h>
 
diff --git a/test/tsan/stack_race.cc b/test/tsan/stack_race.cc
index 90da2f8..2e02f46 100644
--- a/test/tsan/stack_race.cc
+++ b/test/tsan/stack_race.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <stddef.h>
 #include <unistd.h>
diff --git a/test/tsan/stack_race2.cc b/test/tsan/stack_race2.cc
index 83a67f4..818db36 100644
--- a/test/tsan/stack_race2.cc
+++ b/test/tsan/stack_race2.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <stddef.h>
 #include <unistd.h>
diff --git a/test/tsan/static_init3.cc b/test/tsan/static_init3.cc
index 94934b4..3b9fe62 100644
--- a/test/tsan/static_init3.cc
+++ b/test/tsan/static_init3.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <stdlib.h>
 #include <stdio.h>
diff --git a/test/tsan/suppress_same_address.cc b/test/tsan/suppress_same_address.cc
index c172140..df19da1 100644
--- a/test/tsan/suppress_same_address.cc
+++ b/test/tsan/suppress_same_address.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <unistd.h>
 
diff --git a/test/tsan/suppress_same_stacks.cc b/test/tsan/suppress_same_stacks.cc
index 23008b4..9305650 100644
--- a/test/tsan/suppress_same_stacks.cc
+++ b/test/tsan/suppress_same_stacks.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 
 volatile int N;  // Prevent loop unrolling.
diff --git a/test/tsan/test_output.sh b/test/tsan/test_output.sh
index 8a15a67..8b286f4 100755
--- a/test/tsan/test_output.sh
+++ b/test/tsan/test_output.sh
@@ -5,7 +5,6 @@
 
 HERE=$(dirname $0)
 TSAN_DIR=$(dirname $0)/../../lib/tsan
-BLACKLIST=$HERE/Helpers/blacklist.txt
 
 # Assume clang and clang++ are in path.
 : ${CC:=clang}
@@ -13,8 +12,8 @@
 : ${FILECHECK:=FileCheck}
 
 # TODO: add testing for all of -O0...-O3
-CFLAGS="-fsanitize=thread -fsanitize-blacklist=$BLACKLIST -fPIE -O1 -g -Wall"
-LDFLAGS="-pie -lpthread -ldl -lrt -lm -Wl,--whole-archive $TSAN_DIR/rtl/libtsan.a -Wl,--no-whole-archive"
+CFLAGS="-fsanitize=thread -fPIE -O1 -g -Wall"
+LDFLAGS="-pie -pthread -ldl -lrt -lm -Wl,--whole-archive $TSAN_DIR/rtl/libtsan.a -Wl,--no-whole-archive"
 
 test_file() {
   SRC=$1
@@ -41,6 +40,10 @@
       echo TEST $c is not supported
       continue
     fi
+    if [[ $c == */*blacklist*.cc ]]; then
+      echo TEST $c is not supported
+      continue
+    fi
     if [ "`grep "TSAN_OPTIONS" $c`" ]; then
       echo SKIPPING $c -- requires TSAN_OPTIONS
       continue
diff --git a/test/tsan/thread_end_with_ignore.cc b/test/tsan/thread_end_with_ignore.cc
index 438a738..79bb08d 100644
--- a/test/tsan/thread_end_with_ignore.cc
+++ b/test/tsan/thread_end_with_ignore.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <stdio.h>
 
diff --git a/test/tsan/thread_end_with_ignore2.cc b/test/tsan/thread_end_with_ignore2.cc
index ca9b5ca..9387ea4 100644
--- a/test/tsan/thread_end_with_ignore2.cc
+++ b/test/tsan/thread_end_with_ignore2.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 extern "C" void AnnotateIgnoreWritesBegin(const char *f, int l);
 
 int main() {
diff --git a/test/tsan/thread_end_with_ignore3.cc b/test/tsan/thread_end_with_ignore3.cc
index f066f9e..55688b2 100644
--- a/test/tsan/thread_end_with_ignore3.cc
+++ b/test/tsan/thread_end_with_ignore3.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// 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);
 
diff --git a/test/tsan/thread_leak3.c b/test/tsan/thread_leak3.c
index efc4dd0..f4db484 100644
--- a/test/tsan/thread_leak3.c
+++ b/test/tsan/thread_leak3.c
@@ -1,4 +1,4 @@
-// RUN: %clang_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <unistd.h>
 
diff --git a/test/tsan/thread_leak5.c b/test/tsan/thread_leak5.c
index 130858c..ca244a9 100644
--- a/test/tsan/thread_leak5.c
+++ b/test/tsan/thread_leak5.c
@@ -1,4 +1,4 @@
-// RUN: %clang_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <unistd.h>
 
diff --git a/test/tsan/thread_name.cc b/test/tsan/thread_name.cc
index af29a2e..05b0a35 100644
--- a/test/tsan/thread_name.cc
+++ b/test/tsan/thread_name.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <stdio.h>
 #include <unistd.h>
diff --git a/test/tsan/thread_name2.cc b/test/tsan/thread_name2.cc
index 0530c98..b9a5746 100644
--- a/test/tsan/thread_name2.cc
+++ b/test/tsan/thread_name2.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <stdio.h>
 #include <unistd.h>
diff --git a/test/tsan/tiny_race.c b/test/tsan/tiny_race.c
index 9d84224..c10eab1 100644
--- a/test/tsan/tiny_race.c
+++ b/test/tsan/tiny_race.c
@@ -1,4 +1,4 @@
-// RUN: %clang_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clang_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <unistd.h>
 
diff --git a/test/tsan/tls_race.cc b/test/tsan/tls_race.cc
index dbfc553..1858934 100644
--- a/test/tsan/tls_race.cc
+++ b/test/tsan/tls_race.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <stddef.h>
 #include <unistd.h>
diff --git a/test/tsan/tls_race2.cc b/test/tsan/tls_race2.cc
index ed9f4d0..0ca629a 100644
--- a/test/tsan/tls_race2.cc
+++ b/test/tsan/tls_race2.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <stddef.h>
 #include <unistd.h>
diff --git a/test/tsan/unaligned_race.cc b/test/tsan/unaligned_race.cc
index a2b2675..6e9b5a3 100644
--- a/test/tsan/unaligned_race.cc
+++ b/test/tsan/unaligned_race.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <stdio.h>
 #include <stdlib.h>
diff --git a/test/tsan/vptr_harmful_race.cc b/test/tsan/vptr_harmful_race.cc
index c7d4b74..68e12e8 100644
--- a/test/tsan/vptr_harmful_race.cc
+++ b/test/tsan/vptr_harmful_race.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <semaphore.h>
 #include <stdio.h>
diff --git a/test/tsan/vptr_harmful_race2.cc b/test/tsan/vptr_harmful_race2.cc
index b018d5c..aa53bbb 100644
--- a/test/tsan/vptr_harmful_race2.cc
+++ b/test/tsan/vptr_harmful_race2.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <semaphore.h>
 #include <stdio.h>
diff --git a/test/tsan/vptr_harmful_race3.cc b/test/tsan/vptr_harmful_race3.cc
index 01c94e2..ac6ea94 100644
--- a/test/tsan/vptr_harmful_race3.cc
+++ b/test/tsan/vptr_harmful_race3.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <semaphore.h>
 #include <stdio.h>
diff --git a/test/tsan/write_in_reader_lock.cc b/test/tsan/write_in_reader_lock.cc
index 77373be..5588213 100644
--- a/test/tsan/write_in_reader_lock.cc
+++ b/test/tsan/write_in_reader_lock.cc
@@ -1,4 +1,4 @@
-// RUN: %clangxx_tsan -O1 %s -o %t && not %run %t 2>&1 | FileCheck %s
+// RUN: %clangxx_tsan -O1 %s -o %t && %deflake %run %t | FileCheck %s
 #include <pthread.h>
 #include <unistd.h>
 
diff --git a/test/ubsan/CMakeLists.txt b/test/ubsan/CMakeLists.txt
index ded124d..4c6b0bc 100644
--- a/test/ubsan/CMakeLists.txt
+++ b/test/ubsan/CMakeLists.txt
@@ -4,11 +4,15 @@
 configure_lit_site_cfg(
   ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
   ${CMAKE_CURRENT_BINARY_DIR}/UbsanConfig/lit.site.cfg)
+set(UBSAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/UbsanConfig)
 
-set(UBSAN_LIT_TEST_MODE "AddressSanitizer")
-configure_lit_site_cfg(
-  ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
-  ${CMAKE_CURRENT_BINARY_DIR}/AsanConfig/lit.site.cfg)
+if(ASAN_SUPPORTED_ARCH)
+  set(UBSAN_LIT_TEST_MODE "AddressSanitizer")
+  configure_lit_site_cfg(
+    ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
+    ${CMAKE_CURRENT_BINARY_DIR}/AsanConfig/lit.site.cfg)
+  list(APPEND UBSAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/AsanConfig)
+endif()
 
 set(UBSAN_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS})
 if(NOT COMPILER_RT_STANDALONE_BUILD)
@@ -16,7 +20,6 @@
 endif()
 
 add_lit_testsuite(check-ubsan "Running UndefinedBehaviorSanitizer tests"
-  ${CMAKE_CURRENT_BINARY_DIR}/UbsanConfig
-  ${CMAKE_CURRENT_BINARY_DIR}/AsanConfig
+  ${UBSAN_TESTSUITES}
   DEPENDS ${UBSAN_TEST_DEPS})
 set_target_properties(check-ubsan PROPERTIES FOLDER "UBSan unittests")