Update aosp/master compiler-rt for rebase to r235153

Change-Id: I7c900e78d263fe0f574369e8383ccac7e36f5c3b
diff --git a/test/asan/TestCases/Darwin/interception-in-shared-lib-test.cc b/test/asan/TestCases/Darwin/interception-in-shared-lib-test.cc
deleted file mode 100644
index 028683d..0000000
--- a/test/asan/TestCases/Darwin/interception-in-shared-lib-test.cc
+++ /dev/null
@@ -1,32 +0,0 @@
-// Check that memset() call from a shared library gets intercepted.
-// Please always keep this file in sync with
-// ../Linux/interception-in-shared-lib-test.cc.
-
-// RUN: %clangxx_asan -O0 %s -DSHARED_LIB \
-// RUN:     -shared -o %t-so.so \
-// RUN:     -fPIC -install_name @rpath/interception-in-shared-lib-test.cc.tmp-so.so
-// TODO(glider): figure out how to set rpath in a more portable way and unite
-// this test with ../Linux/interception-in-shared-lib-test.cc.
-// RUN: %clangxx_asan -O0 %s -o %t -Wl,-rpath,@executable_path %t-so.so && \
-// RUN:     not %run %t 2>&1 | FileCheck %s
-
-#include <stdio.h>
-#include <string.h>
-
-#if defined(SHARED_LIB)
-extern "C"
-void my_memset(void *p, size_t sz) {
-  memset(p, 0, sz);
-}
-#else
-extern "C" void my_memset(void *p, size_t sz);
-
-int main(int argc, char *argv[]) {
-  char buf[10];
-  my_memset(buf, 11);
-  // CHECK: {{.*ERROR: AddressSanitizer: stack-buffer-overflow}}
-  // CHECK: {{WRITE of size 11 at 0x.* thread T0}}
-  // CHECK: {{0x.* in my_memset .*interception-in-shared-lib-test.cc:19}}
-  return 0;
-}
-#endif
diff --git a/test/asan/TestCases/Linux/interception-in-shared-lib-test.cc b/test/asan/TestCases/Linux/interception-in-shared-lib-test.cc
deleted file mode 100644
index b828d55..0000000
--- a/test/asan/TestCases/Linux/interception-in-shared-lib-test.cc
+++ /dev/null
@@ -1,32 +0,0 @@
-// Check that memset() call from a shared library gets intercepted.
-// Please always keep this file in sync with
-// ../Darwin/interception-in-shared-lib-test.cc.
-
-// RUN: %clangxx_asan -O0 %s -DSHARED_LIB \
-// RUN:     -shared -o %T/libinterception-in-shared-lib-test.so \
-// RUN:     -fPIC
-// TODO(glider): figure out how to set rpath in a more portable way and unite
-// this test with ../Darwin/interception-in-shared-lib-test.cc.
-// RUN: %clangxx_asan -O0 %s -o %t -Wl,-R,\$ORIGIN -L%T -linterception-in-shared-lib-test && \
-// RUN:     not %run %t 2>&1 | FileCheck %s
-
-#include <stdio.h>
-#include <string.h>
-
-#if defined(SHARED_LIB)
-extern "C"
-void my_memset(void *p, size_t sz) {
-  memset(p, 0, sz);
-}
-#else
-extern "C" void my_memset(void *p, size_t sz);
-
-int main(int argc, char *argv[]) {
-  char buf[10];
-  my_memset(buf, 11);
-  // CHECK: {{.*ERROR: AddressSanitizer: stack-buffer-overflow}}
-  // CHECK: {{WRITE of size 11 at 0x.* thread T0}}
-  // CHECK: {{0x.* in my_memset .*interception-in-shared-lib-test.cc:19}}
-  return 0;
-}
-#endif
diff --git a/test/asan/TestCases/Linux/coverage-direct-activation.cc b/test/asan/TestCases/Posix/coverage-direct-activation.cc
similarity index 86%
rename from test/asan/TestCases/Linux/coverage-direct-activation.cc
rename to test/asan/TestCases/Posix/coverage-direct-activation.cc
index 9b2a0d8..05dc557 100644
--- a/test/asan/TestCases/Linux/coverage-direct-activation.cc
+++ b/test/asan/TestCases/Posix/coverage-direct-activation.cc
@@ -1,18 +1,18 @@
 // Test for direct coverage writing enabled at activation time.
 
-// RUN: %clangxx_asan -fsanitize-coverage=1 -DSHARED %s -shared -o %T/libcoverage_direct_activation_test_1.so -fPIC
+// RUN: %clangxx_asan -fsanitize-coverage=1 -DSHARED %s -shared -o %dynamiclib -fPIC
 // RUN: %clangxx -c -DSO_DIR=\"%T\" %s -o %t.o
 // RUN: %clangxx_asan -fsanitize-coverage=1 %t.o %libdl -o %t
 
 // RUN: rm -rf %T/coverage-direct-activation
 
 // RUN: mkdir -p %T/coverage-direct-activation/normal
-// RUN: ASAN_OPTIONS=coverage=1,coverage_direct=0,coverage_dir=%T/coverage-direct-activation/normal:verbosity=1 %run %t
+// RUN: ASAN_OPTIONS=coverage=1,coverage_direct=0,coverage_dir=%T/coverage-direct-activation/normal:verbosity=1 %run %t %dynamiclib
 // RUN: %sancov print %T/coverage-direct-activation/normal/*.sancov >%T/coverage-direct-activation/normal/out.txt
 
 // RUN: mkdir -p %T/coverage-direct-activation/direct
 // RUN: ASAN_OPTIONS=start_deactivated=1,coverage_direct=1,verbosity=1 \
-// RUN:   ASAN_ACTIVATION_OPTIONS=coverage=1,coverage_dir=%T/coverage-direct-activation/direct %run %t
+// RUN:   ASAN_ACTIVATION_OPTIONS=coverage=1,coverage_dir=%T/coverage-direct-activation/direct %run %t %dynamiclib
 // RUN: cd %T/coverage-direct-activation/direct
 // RUN: %sancov rawunpack *.sancov.raw
 // RUN: %sancov print *.sancov >out.txt
@@ -24,7 +24,7 @@
 
 // RUN: mkdir -p %T/coverage-direct-activation/direct2
 // RUN: ASAN_OPTIONS=start_deactivated=1,coverage=1,coverage_direct=1,verbosity=1 \
-// RUN:   ASAN_ACTIVATION_OPTIONS=coverage_dir=%T/coverage-direct-activation/direct2 %run %t
+// RUN:   ASAN_ACTIVATION_OPTIONS=coverage_dir=%T/coverage-direct-activation/direct2 %run %t %dynamiclib
 // RUN: cd %T/coverage-direct-activation/direct2
 // RUN: %sancov rawunpack *.sancov.raw
 // RUN: %sancov print *.sancov >out.txt
@@ -47,8 +47,8 @@
 
 int main(int argc, char **argv) {
   fprintf(stderr, "PID: %d\n", getpid());
-  void *handle1 =
-      dlopen(SO_DIR "/libcoverage_direct_activation_test_1.so", RTLD_LAZY);
+  assert(argc > 1);
+  void *handle1 = dlopen(argv[1], RTLD_LAZY);  // %dynamiclib
   assert(handle1);
   void (*bar1)() = (void (*)())dlsym(handle1, "bar");
   assert(bar1);
diff --git a/test/asan/TestCases/Linux/coverage-direct-large.cc b/test/asan/TestCases/Posix/coverage-direct-large.cc
similarity index 88%
rename from test/asan/TestCases/Linux/coverage-direct-large.cc
rename to test/asan/TestCases/Posix/coverage-direct-large.cc
index 25c950e..cf7351d 100644
--- a/test/asan/TestCases/Linux/coverage-direct-large.cc
+++ b/test/asan/TestCases/Posix/coverage-direct-large.cc
@@ -2,18 +2,18 @@
 // Current implementation maps output file in chunks of 64K. This test overflows
 // 1 chunk.
 
-// RUN: %clangxx_asan -fsanitize-coverage=1 -O0 -DSHARED %s -shared -o %T/libcoverage_direct_large_test_1.so -fPIC
-// RUN: %clangxx_asan -fsanitize-coverage=1 -O0 -DSO_DIR=\"%T\" %s %libdl -o %t
+// RUN: %clangxx_asan -fsanitize-coverage=1 -O0 -DSHARED %s -shared -o %dynamiclib -fPIC
+// RUN: %clangxx_asan -fsanitize-coverage=1 -O0 %s %libdl -o %t
 
 // RUN: rm -rf %T/coverage-direct-large
 
 // RUN: mkdir -p %T/coverage-direct-large/normal && cd %T/coverage-direct-large/normal
-// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=0:verbosity=1 %run %t
+// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=0:verbosity=1 %run %t %dynamiclib
 // RUN: %sancov print *.sancov >out.txt
 // RUN: cd ../..
 
 // RUN: mkdir -p %T/coverage-direct-large/direct && cd %T/coverage-direct-large/direct
-// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=1:verbosity=1 %run %t
+// RUN: ASAN_OPTIONS=coverage=1:coverage_direct=1:verbosity=1 %run %t %dynamiclib
 // RUN: %sancov rawunpack *.sancov.raw
 // RUN: %sancov print *.sancov >out.txt
 // RUN: cd ../..
@@ -49,11 +49,11 @@
 
 #include <assert.h>
 #include <dlfcn.h>
-int main(void) {
+#include <stdio.h>
+int main(int argc, char **argv) {
   F4(CALL, f)
-
-  void *handle1 =
-      dlopen(SO_DIR "/libcoverage_direct_large_test_1.so", RTLD_LAZY);
+  assert(argc > 1);
+  void *handle1 = dlopen(argv[1], RTLD_LAZY);  // %dynamiclib
   assert(handle1);
   void (*so_entry)() = (void (*)())dlsym(handle1, "so_entry");
   assert(so_entry);
diff --git a/test/asan/TestCases/Posix/coverage-direct.cc b/test/asan/TestCases/Posix/coverage-direct.cc
index 45222fa..60acbb7 100644
--- a/test/asan/TestCases/Posix/coverage-direct.cc
+++ b/test/asan/TestCases/Posix/coverage-direct.cc
@@ -1,16 +1,16 @@
 // Test for direct coverage writing with dlopen at coverage level 1 to 3.
 
-// RUN: %clangxx_asan -fsanitize-coverage=1 -DSHARED %s -shared -o %T/libcoverage_direct_test_1.so -fPIC
-// RUN: %clangxx_asan -fsanitize-coverage=1 -DSO_DIR=\"%T\" %s %libdl -o %t
+// RUN: %clangxx_asan -fsanitize-coverage=1 -DSHARED %s -shared -o %dynamiclib -fPIC
+// RUN: %clangxx_asan -fsanitize-coverage=1 %s %libdl -o %t
 
 // RUN: rm -rf %T/coverage-direct
 
 // 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: ASAN_OPTIONS=coverage=1:coverage_direct=0:coverage_dir=%T/coverage-direct/normal:verbosity=1 %run %t %dynamiclib
 // RUN: %sancov print %T/coverage-direct/normal/*.sancov >%T/coverage-direct/normal/out.txt
 
 // 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: ASAN_OPTIONS=coverage=1:coverage_direct=1:coverage_dir=%T/coverage-direct/direct:verbosity=1 %run %t %dynamiclib
 // RUN: cd %T/coverage-direct/direct
 // RUN: %sancov rawunpack *.sancov.raw
 // RUN: %sancov print *.sancov >out.txt
@@ -19,17 +19,17 @@
 // RUN: diff -u coverage-direct/normal/out.txt coverage-direct/direct/out.txt
 
 
-// RUN: %clangxx_asan -fsanitize-coverage=2 -DSHARED %s -shared -o %T/libcoverage_direct_test_1.so -fPIC
+// RUN: %clangxx_asan -fsanitize-coverage=2 -DSHARED %s -shared -o %dynamiclib -fPIC
 // RUN: %clangxx_asan -fsanitize-coverage=2 -DSO_DIR=\"%T\" %s %libdl -o %t
 
 // RUN: rm -rf %T/coverage-direct
 
 // 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: ASAN_OPTIONS=coverage=1:coverage_direct=0:coverage_dir=%T/coverage-direct/normal:verbosity=1 %run %t %dynamiclib
 // RUN: %sancov print %T/coverage-direct/normal/*.sancov >%T/coverage-direct/normal/out.txt
 
 // 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: ASAN_OPTIONS=coverage=1:coverage_direct=1:coverage_dir=%T/coverage-direct/direct:verbosity=1 %run %t %dynamiclib
 // RUN: cd %T/coverage-direct/direct
 // RUN: %sancov rawunpack *.sancov.raw
 // RUN: %sancov print *.sancov >out.txt
@@ -38,17 +38,17 @@
 // RUN: diff -u coverage-direct/normal/out.txt coverage-direct/direct/out.txt
 
 
-// RUN: %clangxx_asan -fsanitize-coverage=3 -DSHARED %s -shared -o %T/libcoverage_direct_test_1.so -fPIC
+// RUN: %clangxx_asan -fsanitize-coverage=3 -DSHARED %s -shared -o %dynamiclib -fPIC
 // RUN: %clangxx_asan -fsanitize-coverage=3 -DSO_DIR=\"%T\" %s %libdl -o %t
 
 // RUN: rm -rf %T/coverage-direct
 
 // 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: ASAN_OPTIONS=coverage=1:coverage_direct=0:coverage_dir=%T/coverage-direct/normal:verbosity=1 %run %t %dynamiclib
 // RUN: %sancov print %T/coverage-direct/normal/*.sancov >%T/coverage-direct/normal/out.txt
 
 // 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: ASAN_OPTIONS=coverage=1:coverage_direct=1:coverage_dir=%T/coverage-direct/direct:verbosity=1 %run %t %dynamiclib
 // RUN: cd %T/coverage-direct/direct
 // RUN: %sancov rawunpack *.sancov.raw
 // RUN: %sancov print *.sancov >out.txt
@@ -71,8 +71,8 @@
 
 int main(int argc, char **argv) {
   fprintf(stderr, "PID: %d\n", getpid());
-  void *handle1 =
-      dlopen(SO_DIR "/libcoverage_direct_test_1.so", RTLD_LAZY);
+  assert(argc > 1);
+  void *handle1 = dlopen(argv[1], RTLD_LAZY);
   assert(handle1);
   void (*bar1)() = (void (*)())dlsym(handle1, "bar");
   assert(bar1);
diff --git a/test/asan/TestCases/Linux/coverage-fork-direct.cc b/test/asan/TestCases/Posix/coverage-fork-direct.cc
similarity index 100%
rename from test/asan/TestCases/Linux/coverage-fork-direct.cc
rename to test/asan/TestCases/Posix/coverage-fork-direct.cc
diff --git a/test/asan/TestCases/Linux/coverage-module-unloaded.cc b/test/asan/TestCases/Posix/coverage-module-unloaded.cc
similarity index 67%
rename from test/asan/TestCases/Linux/coverage-module-unloaded.cc
rename to test/asan/TestCases/Posix/coverage-module-unloaded.cc
index 573fc46..26ef479 100644
--- a/test/asan/TestCases/Linux/coverage-module-unloaded.cc
+++ b/test/asan/TestCases/Posix/coverage-module-unloaded.cc
@@ -1,13 +1,13 @@
 // Check that unloading a module doesn't break coverage dumping for remaining
 // modules.
-// RUN: %clangxx_asan -fsanitize-coverage=1 -DSHARED %s -shared -o %T/libcoverage_module_unloaded_test_1.so -fPIC
-// RUN: %clangxx_asan -fsanitize-coverage=1 -DSHARED %s -shared -o %T/libcoverage_module_unloaded_test_2.so -fPIC
-// RUN: %clangxx_asan -fsanitize-coverage=1 -DSO_DIR=\"%T\" %s %libdl -o %t
+// RUN: %clangxx_asan -fsanitize-coverage=1 -DSHARED %s -shared -o %dynamiclib1 -fPIC
+// RUN: %clangxx_asan -fsanitize-coverage=1 -DSHARED %s -shared -o %dynamiclib2 -fPIC
+// RUN: %clangxx_asan -fsanitize-coverage=1 %s %libdl -o %t
 // RUN: export ASAN_OPTIONS=coverage=1:verbosity=1
 // RUN: mkdir -p %T/coverage-module-unloaded && cd %T/coverage-module-unloaded
-// RUN: %run %t 2>&1         | FileCheck %s
-// RUN: %run %t foo 2>&1         | FileCheck %s
-// RUN: cd .. && rm coverage-module-unloaded -r
+// RUN: %run %t %dynamiclib1 %dynamiclib2 2>&1        | FileCheck %s
+// RUN: %run %t %dynamiclib1 %dynamiclib2 foo 2>&1    | FileCheck %s
+// RUN: rm -r %T/coverage-module-unloaded
 //
 // https://code.google.com/p/address-sanitizer/issues/detail?id=263
 // XFAIL: android
@@ -25,14 +25,13 @@
 
 int main(int argc, char **argv) {
   fprintf(stderr, "PID: %d\n", getpid());
-  void *handle1 =
-      dlopen(SO_DIR "/libcoverage_module_unloaded_test_1.so", RTLD_LAZY);
+  assert(argc > 2);
+  void *handle1 = dlopen(argv[1], RTLD_LAZY);  // %dynamiclib1
   assert(handle1);
   void (*bar1)() = (void (*)())dlsym(handle1, "bar");
   assert(bar1);
   bar1();
-  void *handle2 =
-      dlopen(SO_DIR "/libcoverage_module_unloaded_test_2.so", RTLD_LAZY);
+  void *handle2 = dlopen(argv[2], RTLD_LAZY);  // %dynamiclib2
   assert(handle2);
   void (*bar2)() = (void (*)())dlsym(handle2, "bar");
   assert(bar2);
@@ -50,7 +49,7 @@
 
 // CHECK: PID: [[PID:[0-9]+]]
 // CHECK: [[PID]].sancov: 1 PCs written
-// CHECK: test_1.so.[[PID]]
-// CHECK: test_2.so.[[PID]]
+// CHECK: coverage-module-unloaded{{.*}}1.[[PID]]
+// CHECK: coverage-module-unloaded{{.*}}2.[[PID]]
 // Even though we've unloaded one of the libs we still dump the coverage file
-// for that lib (although the data will be inaccurate, it at all useful)
+// for that lib (although the data will be inaccurate, if at all useful)
diff --git a/test/asan/TestCases/Linux/coverage-sandboxing.cc b/test/asan/TestCases/Posix/coverage-sandboxing.cc
similarity index 84%
rename from test/asan/TestCases/Linux/coverage-sandboxing.cc
rename to test/asan/TestCases/Posix/coverage-sandboxing.cc
index 15bada8..8f1c1ee 100644
--- a/test/asan/TestCases/Linux/coverage-sandboxing.cc
+++ b/test/asan/TestCases/Posix/coverage-sandboxing.cc
@@ -1,5 +1,5 @@
-// RUN: %clangxx_asan -fsanitize-coverage=2 -DSHARED %s -shared -o %T/libcoverage_sandboxing_test.so -fPIC
-// RUN: %clangxx_asan -fsanitize-coverage=1 %s   -o %t -Wl,-R,\$ORIGIN -L%T -lcoverage_sandboxing_test
+// RUN: %clangxx_asan -fsanitize-coverage=2 -DSHARED %s -shared -o %dynamiclib -fPIC %ld_flags_rpath_so
+// RUN: %clangxx_asan -fsanitize-coverage=1 %s -o %t %ld_flags_rpath_exe
 // RUN: export ASAN_OPTIONS=coverage=1:verbosity=1
 // RUN: rm -rf %T/coverage_sandboxing_test
 // RUN: mkdir %T/coverage_sandboxing_test && cd %T/coverage_sandboxing_test
@@ -12,12 +12,12 @@
 // RUN: %run %t a b 2>&1     | FileCheck %s --check-prefix=CHECK-sandbox
 // RUN: %sancov unpack coverage_sandboxing_test.sancov.packed 
 // RUN: cd ..
-// RUN: %sancov print vanilla/libcoverage_sandboxing_test.so.*.sancov > vanilla.txt
-// RUN: %sancov print sandbox1/libcoverage_sandboxing_test.so.*.sancov > sandbox1.txt
-// RUN: %sancov print sandbox2/libcoverage_sandboxing_test.so.*.sancov > sandbox2.txt
+// RUN: %sancov print vanilla/`basename %dynamiclib`*.sancov > vanilla.txt
+// RUN: %sancov print sandbox1/`basename %dynamiclib`*.sancov > sandbox1.txt
+// RUN: %sancov print sandbox2/`basename %dynamiclib`*.sancov > sandbox2.txt
 // RUN: diff vanilla.txt sandbox1.txt
 // RUN: diff vanilla.txt sandbox2.txt
-// RUN: cd ../ && rm coverage_sandboxing_test -r
+// RUN: rm -r %T/coverage_sandboxing_test
 // https://code.google.com/p/address-sanitizer/issues/detail?id=263
 // XFAIL: android
 
diff --git a/test/asan/TestCases/Linux/coverage.cc b/test/asan/TestCases/Posix/coverage.cc
similarity index 75%
rename from test/asan/TestCases/Linux/coverage.cc
rename to test/asan/TestCases/Posix/coverage.cc
index 1ad19e6..7b59015 100644
--- a/test/asan/TestCases/Linux/coverage.cc
+++ b/test/asan/TestCases/Posix/coverage.cc
@@ -1,21 +1,21 @@
-// RUN: %clangxx_asan -fsanitize-coverage=1 -DSHARED %s -shared -o %T/libcoverage_test.so -fPIC
-// RUN: %clangxx_asan -fsanitize-coverage=1 %s   -o %t -Wl,-R,\$ORIGIN -L%T -lcoverage_test
+// RUN: %clangxx_asan -fsanitize-coverage=1 -DSHARED %s -shared -o %dynamiclib -fPIC %ld_flags_rpath_so
+// RUN: %clangxx_asan -fsanitize-coverage=1 %s %ld_flags_rpath_exe -o %t
 // RUN: export ASAN_OPTIONS=coverage=1:verbosity=1
 // RUN: rm -rf %T/coverage && mkdir -p %T/coverage && cd %T/coverage
 // RUN: %run %t 2>&1         | FileCheck %s --check-prefix=CHECK-main
-// RUN: %sancov print coverage.*sancov 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV1
+// RUN: %sancov print `ls coverage.*sancov | grep -v '.so'` 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV1
 // RUN: %run %t foo 2>&1     | FileCheck %s --check-prefix=CHECK-foo
-// RUN: %sancov print coverage.*sancov 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV2
+// RUN: %sancov print `ls coverage.*sancov | grep -v '.so'` 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV2
 // RUN: %run %t bar 2>&1     | FileCheck %s --check-prefix=CHECK-bar
-// RUN: %sancov print coverage.*sancov 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV2
+// RUN: %sancov print `ls *coverage.*sancov | grep -v '.so'` 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV2
 // RUN: %run %t foo bar 2>&1 | FileCheck %s --check-prefix=CHECK-foo-bar
-// RUN: %sancov print coverage.*sancov 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV2
-// RUN: %sancov print libcoverage_test.*sancov 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV1
-// RUN: %sancov merge coverage.*sancov > merged-cov
+// RUN: %sancov print `ls *coverage.*sancov | grep -v '.so'` 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV2
+// RUN: %sancov print `ls *coverage.*sancov | grep '.so'` 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV1
+// RUN: %sancov merge `ls *coverage.*sancov | grep -v '.so'` > merged-cov
 // RUN: %sancov print merged-cov 2>&1 | FileCheck %s --check-prefix=CHECK-SANCOV2
 // RUN: not %run %t foo bar 4    2>&1 | FileCheck %s --check-prefix=CHECK-report
 // RUN: not %run %t foo bar 4 5  2>&1 | FileCheck %s --check-prefix=CHECK-segv
-// RUN: cd .. && rm coverage -r
+// RUN: rm -r %T/coverage
 //
 // https://code.google.com/p/address-sanitizer/issues/detail?id=263
 // XFAIL: android
diff --git a/test/asan/TestCases/Posix/interception-in-shared-lib-test.cc b/test/asan/TestCases/Posix/interception-in-shared-lib-test.cc
new file mode 100644
index 0000000..a7d2bfb
--- /dev/null
+++ b/test/asan/TestCases/Posix/interception-in-shared-lib-test.cc
@@ -0,0 +1,27 @@
+// Check that memset() call from a shared library gets intercepted.
+
+// RUN: %clangxx_asan -O0 %s -DSHARED_LIB \
+// RUN:     -shared -o %dynamiclib -fPIC %ld_flags_rpath_so
+// RUN: %clangxx_asan -O0 %s -o %t %ld_flags_rpath_exe && \
+// RUN:     not %run %t 2>&1 | FileCheck %s
+
+#include <stdio.h>
+#include <string.h>
+
+#if defined(SHARED_LIB)
+extern "C"
+void my_memset(void *p, size_t sz) {
+  memset(p, 0, sz);
+}
+#else
+extern "C" void my_memset(void *p, size_t sz);
+
+int main(int argc, char *argv[]) {
+  char buf[10];
+  my_memset(buf, 11);
+  // CHECK: {{.*ERROR: AddressSanitizer: stack-buffer-overflow}}
+  // CHECK: {{WRITE of size 11 at 0x.* thread T0}}
+  // CHECK: {{0x.* in my_memset .*interception-in-shared-lib-test.cc:}}[[@LINE-10]]
+  return 0;
+}
+#endif
diff --git a/test/asan/TestCases/Windows/coverage-basic.cc b/test/asan/TestCases/Windows/coverage-basic.cc
new file mode 100644
index 0000000..3081d7c
--- /dev/null
+++ b/test/asan/TestCases/Windows/coverage-basic.cc
@@ -0,0 +1,25 @@
+// RUN: rm -rf %T/coverage-basic
+// RUN: mkdir %T/coverage-basic && cd %T/coverage-basic
+// RUN: %clangxx_asan -fsanitize-coverage=1 %s -o test.exe
+// RUN: env ASAN_OPTIONS=coverage=1 %run test.exe
+//
+// RUN: %sancov print *.sancov | FileCheck %s
+#include <stdio.h>
+
+void foo() { fprintf(stderr, "FOO\n"); }
+void bar() { fprintf(stderr, "BAR\n"); }
+
+int main(int argc, char **argv) {
+  if (argc == 2) {
+    foo();
+    bar();
+  } else {
+    bar();
+    foo();
+  }
+}
+
+// CHECK: 0x{{[0-9a-f]*}}
+// CHECK: 0x{{[0-9a-f]*}}
+// CHECK: 0x{{[0-9a-f]*}}
+// CHECK-NOT: 0x{{[0-9a-f]*}}
diff --git a/test/asan/TestCases/atoi_strict.c b/test/asan/TestCases/atoi_strict.c
new file mode 100644
index 0000000..d60af6f
--- /dev/null
+++ b/test/asan/TestCases/atoi_strict.c
@@ -0,0 +1,55 @@
+// Test strict_string_checks option in atoi function
+// RUN: %clang_asan %s -o %t
+// RUN: %run %t test1 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=false %run %t test1 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=true not %run %t test1 2>&1 | FileCheck %s --check-prefix=CHECK1
+// RUN: %run %t test2 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=false %run %t test2 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=true not %run %t test2 2>&1 | FileCheck %s --check-prefix=CHECK2
+// RUN: %run %t test3 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=false %run %t test3 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=true not %run %t test3 2>&1 | FileCheck %s --check-prefix=CHECK3
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+
+void test1(char *array) {
+  // Last symbol is non-digit
+  memset(array, '1', 10);
+  array[9] = 'a';
+  int r = atoi(array);
+  assert(r == 111111111);
+}
+
+void test2(char *array) {
+  // Single non-digit symbol
+  array[9] = 'a';
+  int r = atoi(array + 9);
+  assert(r == 0);
+}
+
+void test3(char *array) {
+  // Incorrect number format
+  memset(array, ' ', 10);
+  array[9] = '-';
+  array[8] = '-';
+  int r = atoi(array);
+  assert(r == 0);
+}
+
+int main(int argc, char **argv) {
+  char *array = (char*)malloc(10);
+  if (argc != 2) return 1;
+  if (!strcmp(argv[1], "test1")) test1(array);
+  // CHECK1: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+  // CHECK1: READ of size 11
+  if (!strcmp(argv[1], "test2")) test2(array);
+  // CHECK2: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+  // CHECK2: READ of size 2
+  if (!strcmp(argv[1], "test3")) test3(array);
+  // CHECK3: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+  // CHECK3: READ of size 11
+  free(array);
+  return 0;
+}
diff --git a/test/asan/TestCases/atol_strict.c b/test/asan/TestCases/atol_strict.c
new file mode 100644
index 0000000..97ec5ba
--- /dev/null
+++ b/test/asan/TestCases/atol_strict.c
@@ -0,0 +1,55 @@
+// Test strict_string_checks option in atol function
+// RUN: %clang_asan %s -o %t
+// RUN: %run %t test1 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=false %run %t test1 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=true not %run %t test1 2>&1 | FileCheck %s --check-prefix=CHECK1
+// RUN: %run %t test2 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=false %run %t test2 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=true not %run %t test2 2>&1 | FileCheck %s --check-prefix=CHECK2
+// RUN: %run %t test3 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=false %run %t test3 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=true not %run %t test3 2>&1 | FileCheck %s --check-prefix=CHECK3
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+
+void test1(char *array) {
+  // Last symbol is non-digit
+  memset(array, '1', 10);
+  array[9] = 'a';
+  long r = atol(array);
+  assert(r == 111111111);
+}
+
+void test2(char *array) {
+  // Single non-digit symbol
+  array[9] = 'a';
+  long r = atol(array + 9);
+  assert(r == 0);
+}
+
+void test3(char *array) {
+  // Incorrect number format
+  memset(array, ' ', 10);
+  array[9] = '-';
+  array[8] = '-';
+  long r = atol(array);
+  assert(r == 0);
+}
+
+int main(int argc, char **argv) {
+  char *array = (char*)malloc(10);
+  if (argc != 2) return 1;
+  if (!strcmp(argv[1], "test1")) test1(array);
+  // CHECK1: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+  // CHECK1: READ of size 11
+  if (!strcmp(argv[1], "test2")) test2(array);
+  // CHECK2: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+  // CHECK2: READ of size 2
+  if (!strcmp(argv[1], "test3")) test3(array);
+  // CHECK3: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+  // CHECK3: READ of size 11
+  free(array);
+  return 0;
+}
diff --git a/test/asan/TestCases/atoll_strict.c b/test/asan/TestCases/atoll_strict.c
new file mode 100644
index 0000000..cd0ef69
--- /dev/null
+++ b/test/asan/TestCases/atoll_strict.c
@@ -0,0 +1,55 @@
+// Test strict_string_checks option in atoll function
+// RUN: %clang_asan %s -o %t
+// RUN: %run %t test1 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=false %run %t test1 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=true not %run %t test1 2>&1 | FileCheck %s --check-prefix=CHECK1
+// RUN: %run %t test2 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=false %run %t test2 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=true not %run %t test2 2>&1 | FileCheck %s --check-prefix=CHECK2
+// RUN: %run %t test3 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=false %run %t test3 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=true not %run %t test3 2>&1 | FileCheck %s --check-prefix=CHECK3
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+
+void test1(char *array) {
+  // Last symbol is non-digit
+  memset(array, '1', 10);
+  array[9] = 'a';
+  long long r = atoll(array);
+  assert(r == 111111111);
+}
+
+void test2(char *array) {
+  // Single non-digit symbol
+  array[9] = 'a';
+  long long r = atoll(array + 9);
+  assert(r == 0);
+}
+
+void test3(char *array) {
+  // Incorrect number format
+  memset(array, ' ', 10);
+  array[9] = '-';
+  array[8] = '-';
+  long long r = atoll(array);
+  assert(r == 0);
+}
+
+int main(int argc, char **argv) {
+  char *array = (char*)malloc(10);
+  if (argc != 2) return 1;
+  if (!strcmp(argv[1], "test1")) test1(array);
+  // CHECK1: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+  // CHECK1: READ of size 11
+  if (!strcmp(argv[1], "test2")) test2(array);
+  // CHECK2: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+  // CHECK2: READ of size 2
+  if (!strcmp(argv[1], "test3")) test3(array);
+  // CHECK3: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+  // CHECK3: READ of size 11
+  free(array);
+  return 0;
+}
diff --git a/test/asan/TestCases/strcat_strict.c b/test/asan/TestCases/strcat_strict.c
new file mode 100644
index 0000000..806b682
--- /dev/null
+++ b/test/asan/TestCases/strcat_strict.c
@@ -0,0 +1,44 @@
+// Test strict_string_checks option in strcat function
+// RUN: %clang_asan %s -o %t
+// RUN: not %run %t test1 2>&1 | FileCheck %s --check-prefix=CHECK1-NONSTRICT --check-prefix=CHECK1
+// RUN: ASAN_OPTIONS=strict_string_checks=false not  %run %t test1 2>&1 | FileCheck %s --check-prefix=CHECK1-NONSTRICT --check-prefix=CHECK1
+// RUN: ASAN_OPTIONS=strict_string_checks=true not %run %t test1 2>&1 | FileCheck %s --check-prefix=CHECK1-STRICT --check-prefix=CHECK1
+// RUN: not %run %t test2 2>&1 | FileCheck %s --check-prefix=CHECK2-NONSTRICT --check-prefix=CHECK2
+// RUN: ASAN_OPTIONS=strict_string_checks=false not  %run %t test2 2>&1 | FileCheck %s --check-prefix=CHECK2-NONSTRICT --check-prefix=CHECK2
+// RUN: ASAN_OPTIONS=strict_string_checks=true not %run %t test2 2>&1 | FileCheck %s --check-prefix=CHECK2-STRICT --check-prefix=CHECK2
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+
+void test1(char *to, int to_size, char *from) {
+  // One of arguments points to not allocated memory.
+  char* r = strcat(to + to_size, from);
+}
+
+void test2(char *to, int to_size, char *from) {
+  // "to" is not zero-terminated.
+  memset(to, 'z', to_size);
+  char* r = strcat(to, from);
+}
+
+int main(int argc, char **argv) {
+  size_t to_size = 100;
+  char *to = (char*)malloc(to_size);
+  size_t from_size = 20;
+  char *from = (char*)malloc(from_size);
+  memset(from, 'z', from_size);
+  from[from_size - 1] = '\0';
+  if (argc != 2) return 1;
+  if (!strcmp(argv[1], "test1")) test1(to, to_size, from);
+  // CHECK1: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+  // CHECK1-STRICT: READ of size 1
+  // CHECK1-NONSTRICT: WRITE of size 20
+  if (!strcmp(argv[1], "test2")) test2(to, to_size, from);
+  // CHECK2: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+  // CHECK2-STRICT: READ of size 101
+  // CHECK2-NONSTRICT: WRITE of size 20
+  free(to);
+  free(from);
+  return 0;
+}
diff --git a/test/asan/TestCases/strchr_strict.c b/test/asan/TestCases/strchr_strict.c
new file mode 100644
index 0000000..d0c32f7
--- /dev/null
+++ b/test/asan/TestCases/strchr_strict.c
@@ -0,0 +1,22 @@
+// Test strict_string_checks option in strchr function
+// RUN: %clang_asan %s -o %t && %run %t 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=false %run %t 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=true not %run %t 2>&1 | FileCheck %s
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+
+int main(int argc, char **argv) {
+  size_t size = 100;
+  char fill = 'o';
+  char *s = (char*)malloc(size);
+  memset(s, fill, size);
+  char c = 'o';
+  char* r = strchr(s, c);
+  // CHECK: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+  // CHECK: READ of size 101
+  assert(r == s);
+  free(s);
+  return 0;
+}
diff --git a/test/asan/TestCases/strcmp_strict.c b/test/asan/TestCases/strcmp_strict.c
new file mode 100644
index 0000000..6514ab9
--- /dev/null
+++ b/test/asan/TestCases/strcmp_strict.c
@@ -0,0 +1,26 @@
+// Test strict_string_checks option in strcmp function
+// RUN: %clang_asan %s -o %t && %run %t 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=false %run %t 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=true not %run %t 2>&1 | FileCheck %s
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+
+int main(int argc, char **argv) {
+  size_t size = 100;
+  char fill = 'o';
+  char *s1 = (char*)malloc(size);
+  memset(s1, fill, size);
+  char *s2 = (char*)malloc(size);
+  memset(s2, fill, size);
+  s1[size - 1] = 'z';
+  s2[size - 1] = 'x';
+  int r = strcmp(s1, s2);
+  // CHECK: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+  // CHECK: READ of size 101
+  assert(r == 1);
+  free(s1);
+  free(s2);
+  return 0;
+}
diff --git a/test/asan/TestCases/strncat_strict.c b/test/asan/TestCases/strncat_strict.c
new file mode 100644
index 0000000..377af96
--- /dev/null
+++ b/test/asan/TestCases/strncat_strict.c
@@ -0,0 +1,44 @@
+// Test strict_string_checks option in strncat function
+// RUN: %clang_asan %s -o %t
+// RUN: not %run %t test1 2>&1 | FileCheck %s --check-prefix=CHECK1-NONSTRICT --check-prefix=CHECK1
+// RUN: ASAN_OPTIONS=strict_string_checks=false not  %run %t test1 2>&1 | FileCheck %s --check-prefix=CHECK1-NONSTRICT --check-prefix=CHECK1
+// RUN: ASAN_OPTIONS=strict_string_checks=true not %run %t test1 2>&1 | FileCheck %s --check-prefix=CHECK1-STRICT --check-prefix=CHECK1
+// RUN: not %run %t test2 2>&1 | FileCheck %s --check-prefix=CHECK2-NONSTRICT --check-prefix=CHECK2
+// RUN: ASAN_OPTIONS=strict_string_checks=false not  %run %t test2 2>&1 | FileCheck %s --check-prefix=CHECK2-NONSTRICT --check-prefix=CHECK2
+// RUN: ASAN_OPTIONS=strict_string_checks=true not %run %t test2 2>&1 | FileCheck %s --check-prefix=CHECK2-STRICT --check-prefix=CHECK2
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+
+void test1(char *to, int to_size, char *from) {
+  // One of arguments points to not allocated memory.
+  char* r = strncat(to + to_size, from, 2);
+}
+
+void test2(char *to, int to_size, char *from) {
+  // "to" is not zero-terminated.
+  memset(to, 'z', to_size);
+  char* r = strncat(to, from, 1);
+}
+
+int main(int argc, char **argv) {
+  size_t to_size = 100;
+  char *to = (char*)malloc(to_size);
+  size_t from_size = 20;
+  char *from = (char*)malloc(from_size);
+  memset(from, 'z', from_size);
+  from[from_size - 1] = '\0';
+  if (argc != 2) return 1;
+  if (!strcmp(argv[1], "test1")) test1(to, to_size, from);
+  // CHECK1: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+  // CHECK1-STRICT: READ of size 1
+  // CHECK1-NONSTRICT: WRITE of size 3
+  if (!strcmp(argv[1], "test2")) test2(to, to_size, from);
+  // CHECK2: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+  // CHECK2-STRICT: READ of size 101
+  // CHECK2-NONSTRICT: WRITE of size 2
+  free(to);
+  free(from);
+  return 0;
+}
diff --git a/test/asan/TestCases/strtol_strict.c b/test/asan/TestCases/strtol_strict.c
new file mode 100644
index 0000000..2ff5028
--- /dev/null
+++ b/test/asan/TestCases/strtol_strict.c
@@ -0,0 +1,111 @@
+// Test strict_string_checks option in strtol function
+// RUN: %clang_asan -DTEST1 %s -o %t
+// RUN: %run %t test1 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=false %run %t test1 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=true not %run %t test1 2>&1 | FileCheck %s --check-prefix=CHECK1
+// RUN: %run %t test2 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=false %run %t test2 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=true not %run %t test2 2>&1 | FileCheck %s --check-prefix=CHECK2
+// RUN: %run %t test3 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=false %run %t test3 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=true not %run %t test3 2>&1 | FileCheck %s --check-prefix=CHECK3
+// RUN: %run %t test4 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=false %run %t test4 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=true not %run %t test4 2>&1 | FileCheck %s --check-prefix=CHECK4
+// RUN: %run %t test5 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=false %run %t test5 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=true not %run %t test5 2>&1 | FileCheck %s --check-prefix=CHECK5
+// RUN: %run %t test6 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=false %run %t test6 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=true not %run %t test6 2>&1 | FileCheck %s --check-prefix=CHECK6
+// RUN: %run %t test7 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=false %run %t test7 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=true not %run %t test7 2>&1 | FileCheck %s --check-prefix=CHECK7
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+
+void test1(char *array, char *endptr) {
+  // Buffer overflow if there is no terminating null (depends on base)
+  long r = strtol(array, &endptr, 3);
+  assert(array + 2 == endptr);
+  assert(r == 5);
+}
+
+void test2(char *array, char *endptr) {
+  // Buffer overflow if there is no terminating null (depends on base)
+  array[2] = 'z';
+  long r = strtol(array, &endptr, 35);
+  assert(array + 2 == endptr);
+  assert(r == 37);
+}
+
+void test3(char *array, char *endptr) {
+  // Buffer overflow if base is invalid.
+  long r = strtol(array - 1, NULL, -1);
+  assert(r == 0);
+}
+
+void test4(char *array, char *endptr) {
+  // Buffer overflow if base is invalid.
+  long r = strtol(array + 3, NULL, 1);
+  assert(r == 0);
+}
+
+void test5(char *array, char *endptr) {
+  // Overflow if no digits are found.
+  array[0] = ' ';
+  array[1] = '+';
+  array[2] = '-';
+  long r = strtol(array, NULL, 0);
+  assert(r == 0);
+}
+
+void test6(char *array, char *endptr) {
+  // Overflow if no digits are found.
+  array[0] = ' ';
+  array[1] = array[2] = 'z';
+  long r = strtol(array, &endptr, 0);
+  assert(array == endptr);
+  assert(r == 0);
+}
+
+void test7(char *array, char *endptr) {
+  // Overflow if no digits are found.
+  array[2] = 'z';
+  long r = strtol(array + 2, NULL, 0);
+  assert(r == 0);
+}
+
+int main(int argc, char **argv) {
+  char *array = (char*)malloc(3);
+  char *endptr = NULL;
+  array[0] = '1';
+  array[1] = '2';
+  array[2] = '3';
+  if (argc != 2) return 1;
+  if (!strcmp(argv[1], "test1")) test1(array, endptr);
+  // CHECK1: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+  // CHECK1: READ of size 4
+  if (!strcmp(argv[1], "test2")) test2(array, endptr);
+  // CHECK2: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+  // CHECK2: READ of size 4
+  if (!strcmp(argv[1], "test3")) test3(array, endptr);
+  // CHECK3: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+  // CHECK3: READ of size 5
+  if (!strcmp(argv[1], "test4")) test4(array, endptr);
+  // CHECK4: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+  // CHECK4: READ of size 1
+  if (!strcmp(argv[1], "test5")) test5(array, endptr);
+  // CHECK5: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+  // CHECK5: READ of size 4
+  if (!strcmp(argv[1], "test6")) test6(array, endptr);
+  // CHECK6: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+  // CHECK6: READ of size 4
+  if (!strcmp(argv[1], "test7")) test7(array, endptr);
+  // CHECK7: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+  // CHECK7: READ of size 2
+  free(array);
+  return 0;
+}
diff --git a/test/asan/TestCases/strtoll_strict.c b/test/asan/TestCases/strtoll_strict.c
new file mode 100644
index 0000000..1f0e54f
--- /dev/null
+++ b/test/asan/TestCases/strtoll_strict.c
@@ -0,0 +1,111 @@
+// Test strict_string_checks option in strtoll function
+// RUN: %clang_asan -DTEST1 %s -o %t
+// RUN: %run %t test1 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=false %run %t test1 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=true not %run %t test1 2>&1 | FileCheck %s --check-prefix=CHECK1
+// RUN: %run %t test2 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=false %run %t test2 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=true not %run %t test2 2>&1 | FileCheck %s --check-prefix=CHECK2
+// RUN: %run %t test3 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=false %run %t test3 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=true not %run %t test3 2>&1 | FileCheck %s --check-prefix=CHECK3
+// RUN: %run %t test4 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=false %run %t test4 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=true not %run %t test4 2>&1 | FileCheck %s --check-prefix=CHECK4
+// RUN: %run %t test5 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=false %run %t test5 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=true not %run %t test5 2>&1 | FileCheck %s --check-prefix=CHECK5
+// RUN: %run %t test6 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=false %run %t test6 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=true not %run %t test6 2>&1 | FileCheck %s --check-prefix=CHECK6
+// RUN: %run %t test7 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=false %run %t test7 2>&1
+// RUN: ASAN_OPTIONS=strict_string_checks=true not %run %t test7 2>&1 | FileCheck %s --check-prefix=CHECK7
+
+#include <assert.h>
+#include <stdlib.h>
+#include <string.h>
+
+void test1(char *array, char *endptr) {
+  // Buffer overflow if there is no terminating null (depends on base)
+  long long r = strtoll(array, &endptr, 3);
+  assert(array + 2 == endptr);
+  assert(r == 5);
+}
+
+void test2(char *array, char *endptr) {
+  // Buffer overflow if there is no terminating null (depends on base)
+  array[2] = 'z';
+  long long r = strtoll(array, &endptr, 35);
+  assert(array + 2 == endptr);
+  assert(r == 37);
+}
+
+void test3(char *array, char *endptr) {
+  // Buffer overflow if base is invalid.
+  long long r = strtoll(array - 1, NULL, -1);
+  assert(r == 0);
+}
+
+void test4(char *array, char *endptr) {
+  // Buffer overflow if base is invalid.
+  long long r = strtoll(array + 3, NULL, 1);
+  assert(r == 0);
+}
+
+void test5(char *array, char *endptr) {
+  // Overflow if no digits are found.
+  array[0] = ' ';
+  array[1] = '+';
+  array[2] = '-';
+  long long r = strtoll(array, NULL, 0);
+  assert(r == 0);
+}
+
+void test6(char *array, char *endptr) {
+  // Overflow if no digits are found.
+  array[0] = ' ';
+  array[1] = array[2] = 'z';
+  long long r = strtoll(array, &endptr, 0);
+  assert(array == endptr);
+  assert(r == 0);
+}
+
+void test7(char *array, char *endptr) {
+  // Overflow if no digits are found.
+  array[2] = 'z';
+  long long r = strtoll(array + 2, NULL, 0);
+  assert(r == 0);
+}
+
+int main(int argc, char **argv) {
+  char *array = (char*)malloc(3);
+  char *endptr = NULL;
+  array[0] = '1';
+  array[1] = '2';
+  array[2] = '3';
+  if (argc != 2) return 1;
+  if (!strcmp(argv[1], "test1")) test1(array, endptr);
+  // CHECK1: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+  // CHECK1: READ of size 4
+  if (!strcmp(argv[1], "test2")) test2(array, endptr);
+  // CHECK2: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+  // CHECK2: READ of size 4
+  if (!strcmp(argv[1], "test3")) test3(array, endptr);
+  // CHECK3: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+  // CHECK3: READ of size 5
+  if (!strcmp(argv[1], "test4")) test4(array, endptr);
+  // CHECK4: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+  // CHECK4: READ of size 1
+  if (!strcmp(argv[1], "test5")) test5(array, endptr);
+  // CHECK5: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+  // CHECK5: READ of size 4
+  if (!strcmp(argv[1], "test6")) test6(array, endptr);
+  // CHECK6: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+  // CHECK6: READ of size 4
+  if (!strcmp(argv[1], "test7")) test7(array, endptr);
+  // CHECK7: {{.*ERROR: AddressSanitizer: heap-buffer-overflow on address}}
+  // CHECK7: READ of size 2
+  free(array);
+  return 0;
+}
diff --git a/test/asan/TestCases/suppressions-library.cc b/test/asan/TestCases/suppressions-library.cc
index 28f19f5..b7fee23 100644
--- a/test/asan/TestCases/suppressions-library.cc
+++ b/test/asan/TestCases/suppressions-library.cc
@@ -1,10 +1,10 @@
-// RUN: %clangxx_asan -O0 -DSHARED_LIB %s -fPIC -shared -o %t-so.so -install_name @rpath/suppressions-library.cc.tmp-so.so
-// RUN: %clangxx_asan -O0 %s %t-so.so -o %t -rpath @executable_path
+// RUN: %clangxx_asan -O0 -DSHARED_LIB %s -fPIC -shared -o %dynamiclib %ld_flags_rpath_so
+// RUN: %clangxx_asan -O0 %s -o %t %ld_flags_rpath_exe
 
 // Check that without suppressions, we catch the issue.
 // RUN: not %run %t 2>&1 | FileCheck --check-prefix=CHECK-CRASH %s
 
-// RUN: echo "interceptor_via_lib:suppressions-library.cc.tmp-so.so" > %t.supp
+// RUN: echo "interceptor_via_lib:"`basename %dynamiclib` > %t.supp
 // RUN: ASAN_OPTIONS="suppressions='%t.supp'" %run %t 2>&1 | FileCheck --check-prefix=CHECK-IGNORE %s
 
 // XFAIL: android
diff --git a/test/asan/lit.cfg b/test/asan/lit.cfg
index a6f443c..05a5715 100644
--- a/test/asan/lit.cfg
+++ b/test/asan/lit.cfg
@@ -135,6 +135,17 @@
 
 config.available_features.add("asan-" + config.bits + "-bits")
 
+if config.host_os == 'Darwin':
+  config.substitutions.append( ("%ld_flags_rpath_exe", '-Wl,-rpath,@executable_path/ %dynamiclib') )
+  config.substitutions.append( ("%ld_flags_rpath_so", '-install_name @rpath/`basename %dynamiclib`') )
+elif config.host_os in ['Linux', 'FreeBSD']:
+  config.substitutions.append( ("%ld_flags_rpath_exe", "-Wl,-rpath,\$ORIGIN -L%T -l%xdynamiclib_namespec") )
+  config.substitutions.append( ("%ld_flags_rpath_so", '') )
+
+# Must be defined after the substitutions that use %dynamiclib.
+config.substitutions.append( ("%dynamiclib", '%T/lib%xdynamiclib_namespec.so') )
+config.substitutions.append( ("%xdynamiclib_namespec", '$(basename %t).dynamic') )
+
 # Allow tests to use REQUIRES=stable-runtime.  For use when you cannot use XFAIL
 # because the test hangs.
 if config.target_arch != 'arm':