aboutsummaryrefslogtreecommitdiff
path: root/test/msan
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2016-07-23 20:45:36 +0000
committerDimitry Andric <dim@FreeBSD.org>2016-07-23 20:45:36 +0000
commit6f08730ec5f639f05f2f15354171e4a3c9af9dc1 (patch)
tree7374e9d4448083010ada98d17976199c7e945d47 /test/msan
parentc003a57e2e4a1ad9be0338806bc1038b6987155f (diff)
downloadsrc-6f08730ec5f639f05f2f15354171e4a3c9af9dc1.tar.gz
src-6f08730ec5f639f05f2f15354171e4a3c9af9dc1.zip
Vendor import of compiler-rt release_39 branch r276489:vendor/compiler-rt/compiler-rt-release_39-r276489
Notes
Notes: svn path=/vendor/compiler-rt/dist/; revision=303235 svn path=/vendor/compiler-rt/compiler-rt-release_39-r276489/; revision=303236; tag=vendor/compiler-rt/compiler-rt-release_39-r276489
Diffstat (limited to 'test/msan')
-rw-r--r--test/msan/CMakeLists.txt36
-rw-r--r--test/msan/Linux/cmsghdr.cc101
-rw-r--r--test/msan/Linux/eventfd.cc18
-rw-r--r--test/msan/Linux/process_vm_readv.cc22
-rw-r--r--test/msan/Linux/sendmsg.cc83
-rw-r--r--test/msan/Linux/syscalls.cc14
-rw-r--r--test/msan/Linux/syscalls_sigaction.cc40
-rw-r--r--test/msan/Unit/lit.site.cfg.in3
-rw-r--r--test/msan/coverage-levels.cc4
-rw-r--r--test/msan/dlerror.cc4
-rw-r--r--test/msan/dtls_test.c2
-rw-r--r--test/msan/fork.cc5
-rw-r--r--test/msan/lit.cfg16
-rw-r--r--test/msan/lit.site.cfg.in7
-rw-r--r--test/msan/memcmp_test.cc5
-rw-r--r--test/msan/msan_print_shadow3.cc2
-rw-r--r--test/msan/param_tls_limit.cc19
-rw-r--r--test/msan/vector_cvt.cc2
18 files changed, 343 insertions, 40 deletions
diff --git a/test/msan/CMakeLists.txt b/test/msan/CMakeLists.txt
index 08786ee777eb..176fb4ae1846 100644
--- a/test/msan/CMakeLists.txt
+++ b/test/msan/CMakeLists.txt
@@ -1,8 +1,33 @@
set(MSAN_LIT_SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR})
-configure_lit_site_cfg(
- ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
- ${CMAKE_CURRENT_BINARY_DIR}/lit.site.cfg)
+set(MSAN_TESTSUITES)
+
+set(MSAN_TEST_ARCH ${MSAN_SUPPORTED_ARCH})
+if(APPLE)
+ darwin_filter_host_archs(MSAN_SUPPORTED_ARCH MSAN_TEST_ARCH)
+endif()
+
+foreach(arch ${MSAN_TEST_ARCH})
+ set(MSAN_TEST_TARGET_ARCH ${arch})
+ string(TOLOWER "-${arch}" MSAN_TEST_CONFIG_SUFFIX)
+ if(ANDROID OR ${arch} MATCHES "arm|aarch64")
+ # This is only true if we are cross-compiling.
+ # Build all tests with host compiler and use host tools.
+ set(MSAN_TEST_TARGET_CC ${COMPILER_RT_TEST_COMPILER})
+ set(MSAN_TEST_TARGET_CFLAGS ${COMPILER_RT_TEST_COMPILER_CFLAGS})
+ else()
+ get_target_flags_for_arch(${arch} MSAN_TEST_TARGET_CFLAGS)
+ string(REPLACE ";" " " MSAN_TEST_TARGET_CFLAGS "${MSAN_TEST_TARGET_CFLAGS}")
+ endif()
+
+ string(TOUPPER ${arch} ARCH_UPPER_CASE)
+ set(CONFIG_NAME ${ARCH_UPPER_CASE}Config)
+
+ configure_lit_site_cfg(
+ ${CMAKE_CURRENT_SOURCE_DIR}/lit.site.cfg.in
+ ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME}/lit.site.cfg)
+ list(APPEND MSAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/${CONFIG_NAME})
+endforeach()
set(MSAN_TEST_DEPS ${SANITIZER_COMMON_LIT_TEST_DEPS})
if(NOT COMPILER_RT_STANDALONE_BUILD)
@@ -14,10 +39,11 @@ if(COMPILER_RT_INCLUDE_TESTS AND COMPILER_RT_HAS_LIBCXX_SOURCES)
${CMAKE_CURRENT_SOURCE_DIR}/Unit/lit.site.cfg.in
${CMAKE_CURRENT_BINARY_DIR}/Unit/lit.site.cfg)
list(APPEND MSAN_TEST_DEPS MsanUnitTests)
+ list(APPEND MSAN_TESTSUITES ${CMAKE_CURRENT_BINARY_DIR}/Unit)
endif()
add_lit_testsuite(check-msan "Running the MemorySanitizer tests"
- ${CMAKE_CURRENT_BINARY_DIR}
+ ${MSAN_TESTSUITES}
DEPENDS ${MSAN_TEST_DEPS}
)
-set_target_properties(check-msan PROPERTIES FOLDER "MSan tests")
+set_target_properties(check-msan PROPERTIES FOLDER "Compiler-RT Misc")
diff --git a/test/msan/Linux/cmsghdr.cc b/test/msan/Linux/cmsghdr.cc
new file mode 100644
index 000000000000..daed1baad20d
--- /dev/null
+++ b/test/msan/Linux/cmsghdr.cc
@@ -0,0 +1,101 @@
+// RUN: %clangxx_msan %s -std=c++11 -DSENDMSG -DPOISONFD -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=SENDMSG
+// RUN: %clangxx_msan %s -std=c++11 -DSENDMSG -DPOISONCRED -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=SENDMSG
+// RUN: %clangxx_msan %s -std=c++11 -DSENDMSG -DPOISONLEN -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=SENDMSG
+// RUN: %clangxx_msan %s -std=c++11 -DSENDMSG -DPOISONLEVEL -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=SENDMSG
+// RUN: %clangxx_msan %s -std=c++11 -DSENDMSG -DPOISONTYPE -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=SENDMSG
+// RUN: %clangxx_msan %s -std=c++11 -DSENDMSG -DPOISONLEN2 -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=SENDMSG
+// RUN: %clangxx_msan %s -std=c++11 -DSENDMSG -DPOISONLEVEL2 -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=SENDMSG
+// RUN: %clangxx_msan %s -std=c++11 -DSENDMSG -DPOISONTYPE2 -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=SENDMSG
+// RUN: %clangxx_msan %s -std=c++11 -DSENDMSG -o %t && %run %t 2>&1 | FileCheck %s --check-prefix=NEGATIVE
+
+// UNSUPPORTED: android
+
+#include <assert.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+#include <netdb.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <sanitizer/msan_interface.h>
+
+const int kBufSize = 10;
+
+int main() {
+ int ret;
+ char buf[kBufSize] = {0};
+ pthread_t client_thread;
+ struct sockaddr_un serveraddr;
+
+ int sock[2];
+ ret = socketpair(AF_UNIX, SOCK_STREAM, 0, sock);
+ assert(ret == 0);
+
+ int sockfd = sock[0];
+
+ struct iovec iov[] = {{buf, 10}};
+ struct msghdr msg = {0};
+ msg.msg_iov = iov;
+ msg.msg_iovlen = 1;
+ msg.msg_flags = 0;
+
+ static const int kNumFds = 3;
+ char controlbuf[CMSG_SPACE(kNumFds * sizeof(int)) +
+ CMSG_SPACE(sizeof(struct ucred))];
+ msg.msg_control = &controlbuf;
+ msg.msg_controllen = sizeof(controlbuf);
+
+ struct cmsghdr *cmsg = (struct cmsghdr *)&controlbuf;
+ assert(cmsg);
+ int myfds[kNumFds];
+ for (int &fd : myfds)
+ fd = sockfd;
+#ifdef POISONFD
+ __msan_poison(&myfds[1], sizeof(int));
+#endif
+ cmsg->cmsg_level = SOL_SOCKET;
+ cmsg->cmsg_type = SCM_RIGHTS;
+ cmsg->cmsg_len = CMSG_LEN(kNumFds * sizeof(int));
+ memcpy(CMSG_DATA(cmsg), myfds, kNumFds * sizeof(int));
+#ifdef POISONLEVEL
+ __msan_poison(&cmsg->cmsg_level, sizeof(cmsg->cmsg_level));
+#endif
+#ifdef POISONTYPE
+ __msan_poison(&cmsg->cmsg_type, sizeof(cmsg->cmsg_type));
+#endif
+#ifdef POISONLEN
+ __msan_poison(&cmsg->cmsg_len, sizeof(cmsg->cmsg_len));
+#endif
+
+ cmsg = (struct cmsghdr *)(&controlbuf[CMSG_SPACE(kNumFds * sizeof(int))]);
+ assert(cmsg);
+ struct ucred cred = {getpid(), getuid(), getgid()};
+#ifdef POISONCRED
+ __msan_poison(&cred.uid, sizeof(cred.uid));
+#endif
+ cmsg->cmsg_level = SOL_SOCKET;
+ cmsg->cmsg_type = SCM_CREDENTIALS;
+ cmsg->cmsg_len = CMSG_LEN(sizeof(struct ucred));
+ memcpy(CMSG_DATA(cmsg), &cred, sizeof(struct ucred));
+#ifdef POISONLEVEL2
+ __msan_poison(&cmsg->cmsg_level, sizeof(cmsg->cmsg_level));
+#endif
+#ifdef POISONTYPE2
+ __msan_poison(&cmsg->cmsg_type, sizeof(cmsg->cmsg_type));
+#endif
+#ifdef POISONLEN2
+ __msan_poison(&cmsg->cmsg_len, sizeof(cmsg->cmsg_len));
+#endif
+
+ ret = sendmsg(sockfd, &msg, 0);
+ // SENDMSG: MemorySanitizer: use-of-uninitialized-value
+ if (ret == -1) printf("%d: %s\n", errno, strerror(errno));
+ assert(ret > 0);
+
+ fprintf(stderr, "== done\n");
+ // NEGATIVE: == done
+ return 0;
+}
diff --git a/test/msan/Linux/eventfd.cc b/test/msan/Linux/eventfd.cc
new file mode 100644
index 000000000000..4399211258ff
--- /dev/null
+++ b/test/msan/Linux/eventfd.cc
@@ -0,0 +1,18 @@
+// RUN: %clangxx_msan -O0 %s -o %t && %run %t 2>&1
+
+#include <assert.h>
+#include <sys/eventfd.h>
+
+#include <sanitizer/msan_interface.h>
+
+int main(int argc, char *argv[]) {
+ int efd = eventfd(42, 0);
+ assert(efd >= 0);
+
+ eventfd_t v;
+ int ret = eventfd_read(efd, &v);
+ assert(ret == 0);
+ __msan_check_mem_is_initialized(&v, sizeof(v));
+
+ assert(v == 42);
+}
diff --git a/test/msan/Linux/process_vm_readv.cc b/test/msan/Linux/process_vm_readv.cc
index 601c0d247dc2..b61578d1bfda 100644
--- a/test/msan/Linux/process_vm_readv.cc
+++ b/test/msan/Linux/process_vm_readv.cc
@@ -9,26 +9,31 @@
#include <sys/types.h>
#include <sys/uio.h>
#include <unistd.h>
+#include <errno.h>
typedef ssize_t (*process_vm_readwritev_fn)(pid_t, const iovec *, unsigned long,
const iovec *, unsigned long,
unsigned long);
-int main(void) {
- // This requires glibc 2.15.
- process_vm_readwritev_fn libc_process_vm_readv =
- (process_vm_readwritev_fn)dlsym(RTLD_NEXT, "process_vm_readv");
- if (!libc_process_vm_readv) {
// Exit with success, emulating the expected output.
+int exit_dummy()
+{
#ifdef POSITIVE
- printf("process_vm_readv not found!\n");
+ printf("process_vm_readv not found or not implemented!\n");
printf(
"WARNING: MemorySanitizer: use-of-uninitialized-value (not really)\n");
return 1;
#else
return 0;
#endif
- }
+}
+
+int main(void) {
+ // This requires glibc 2.15.
+ process_vm_readwritev_fn libc_process_vm_readv =
+ (process_vm_readwritev_fn)dlsym(RTLD_NEXT, "process_vm_readv");
+ if (!libc_process_vm_readv)
+ return exit_dummy();
process_vm_readwritev_fn process_vm_readv =
(process_vm_readwritev_fn)dlsym(RTLD_DEFAULT, "process_vm_readv");
@@ -44,6 +49,9 @@ int main(void) {
__msan_poison(&b, sizeof(b));
ssize_t res = process_vm_readv(getpid(), iov_b, 2, iov_a, 2, 0);
+ if (errno == ENOSYS) // Function not implemented
+ return exit_dummy();
+
assert(res == 30);
__msan_check_mem_is_initialized(b + 10, 10);
__msan_check_mem_is_initialized(b + 30, 20);
diff --git a/test/msan/Linux/sendmsg.cc b/test/msan/Linux/sendmsg.cc
new file mode 100644
index 000000000000..6a8ef83c118b
--- /dev/null
+++ b/test/msan/Linux/sendmsg.cc
@@ -0,0 +1,83 @@
+// RUN: %clangxx_msan %s -DSEND -DPOISON -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=SEND
+// RUN: %clangxx_msan %s -DSENDTO -DPOISON -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=SENDTO
+// RUN: %clangxx_msan %s -DSENDMSG -DPOISON -o %t && not %run %t 2>&1 | FileCheck %s --check-prefix=SENDMSG
+
+// RUN: %clangxx_msan %s -DSEND -o %t && %run %t 2>&1 | FileCheck %s --check-prefix=NEGATIVE
+// RUN: %clangxx_msan %s -DSENDTO -o %t && %run %t 2>&1 | FileCheck %s --check-prefix=NEGATIVE
+// RUN: %clangxx_msan %s -DSENDMSG -o %t && %run %t 2>&1 | FileCheck %s --check-prefix=NEGATIVE
+
+// RUN: %clangxx_msan %s -DSEND -DPOISON -o %t && \
+// RUN: MSAN_OPTIONS=intercept_send=0 %run %t 2>&1 | FileCheck %s --check-prefix=NEGATIVE
+// RUN: %clangxx_msan %s -DSENDTO -DPOISON -o %t && \
+// RUN: MSAN_OPTIONS=intercept_send=0 %run %t 2>&1 | FileCheck %s --check-prefix=NEGATIVE
+// RUN: %clangxx_msan %s -DSENDMSG -DPOISON -o %t && \
+// RUN: MSAN_OPTIONS=intercept_send=0 %run %t 2>&1 | FileCheck %s --check-prefix=NEGATIVE
+
+// UNSUPPORTED: android
+
+#include <assert.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <string.h>
+#include <netdb.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <sanitizer/msan_interface.h>
+
+const int kBufSize = 10;
+int sockfd;
+
+int main() {
+ int ret;
+ char buf[kBufSize] = {0};
+ pthread_t client_thread;
+ struct sockaddr_in serveraddr;
+
+ sockfd = socket(AF_INET, SOCK_DGRAM, 0);
+
+ memset(&serveraddr, 0, sizeof(serveraddr));
+ serveraddr.sin_family = AF_INET;
+ serveraddr.sin_addr.s_addr = htonl(INADDR_ANY);
+ serveraddr.sin_port = 0;
+
+ bind(sockfd, (struct sockaddr *)&serveraddr, sizeof(serveraddr));
+ socklen_t addrlen = sizeof(serveraddr);
+ getsockname(sockfd, (struct sockaddr *)&serveraddr, &addrlen);
+
+#if defined(POISON)
+ __msan_poison(buf + 7, 1);
+#endif
+
+#if defined(SENDMSG)
+ struct iovec iov[2] = {{buf, 5}, {buf + 5, 5}};
+ struct msghdr msg;
+ msg.msg_name = &serveraddr;
+ msg.msg_namelen = addrlen;
+ msg.msg_iov = iov;
+ msg.msg_iovlen = 2;
+ msg.msg_control = 0;
+ msg.msg_controllen = 0;
+ msg.msg_flags = 0;
+#endif
+
+#if defined(SEND)
+ ret = connect(sockfd, (struct sockaddr *)&serveraddr, addrlen);
+ assert(ret == 0);
+ ret = send(sockfd, buf, kBufSize, 0);
+ // SEND: Uninitialized bytes in __interceptor_send at offset 7 inside [{{.*}}, 10)
+ assert(ret > 0);
+#elif defined(SENDTO)
+ ret =
+ sendto(sockfd, buf, kBufSize, 0, (struct sockaddr *)&serveraddr, addrlen);
+ // SENDTO: Uninitialized bytes in __interceptor_sendto at offset 7 inside [{{.*}}, 10)
+ assert(ret > 0);
+#elif defined(SENDMSG)
+ ret = sendmsg(sockfd, &msg, 0);
+ // SENDMSG: Uninitialized bytes in {{.*}} at offset 2 inside [{{.*}}, 5)
+ assert(ret > 0);
+#endif
+ fprintf(stderr, "== done\n");
+ // NEGATIVE: == done
+ return 0;
+}
diff --git a/test/msan/Linux/syscalls.cc b/test/msan/Linux/syscalls.cc
index 78dba36638a6..c5ac3e27fa11 100644
--- a/test/msan/Linux/syscalls.cc
+++ b/test/msan/Linux/syscalls.cc
@@ -19,7 +19,7 @@
sanity of their behaviour. */
int main(int argc, char *argv[]) {
- char buf[1000];
+ char buf[1000] __attribute__((aligned(8)));
const int kTen = 10;
const int kFortyTwo = 42;
memset(buf, 0, sizeof(buf));
@@ -111,5 +111,17 @@ int main(int argc, char *argv[]) {
assert(__msan_test_shadow(&p, sizeof(p)) == -1);
assert(__msan_test_shadow(buf, sizeof(buf)) >= 32);
+ __msan_poison(buf, sizeof(buf));
+ __sanitizer_syscall_post_pipe(0, (int *)buf);
+ assert(__msan_test_shadow(buf, sizeof(buf)) == 2 * sizeof(int));
+
+ __msan_poison(buf, sizeof(buf));
+ __sanitizer_syscall_post_pipe2(0, (int *)buf, 0);
+ assert(__msan_test_shadow(buf, sizeof(buf)) == 2 * sizeof(int));
+
+ __msan_poison(buf, sizeof(buf));
+ __sanitizer_syscall_post_socketpair(0, 0, 0, 0, (int *)buf);
+ assert(__msan_test_shadow(buf, sizeof(buf)) == 2 * sizeof(int));
+
return 0;
}
diff --git a/test/msan/Linux/syscalls_sigaction.cc b/test/msan/Linux/syscalls_sigaction.cc
new file mode 100644
index 000000000000..1297fae13d12
--- /dev/null
+++ b/test/msan/Linux/syscalls_sigaction.cc
@@ -0,0 +1,40 @@
+// RUN: %clangxx_msan -DPRE1 -O0 %s -o %t && not %run %t 2>&1
+// RUN: %clangxx_msan -DPRE2 -O0 %s -o %t && not %run %t 2>&1
+// RUN: %clangxx_msan -DPRE3 -O0 %s -o %t && not %run %t 2>&1
+// RUN: %clangxx_msan -O0 %s -o %t && %run %t 2>&1
+
+#include <assert.h>
+#include <signal.h>
+#include <string.h>
+
+#include <sanitizer/linux_syscall_hooks.h>
+#include <sanitizer/msan_interface.h>
+
+struct my_kernel_sigaction {
+ long handler, flags, restorer;
+ uint64_t mask[20]; // larger than any known platform
+};
+
+int main() {
+ my_kernel_sigaction act = {}, oldact = {};
+
+#if defined(PRE1)
+ __msan_poison(&act.handler, sizeof(act.handler));
+ __sanitizer_syscall_pre_rt_sigaction(SIGUSR1, &act, &oldact, 20 * 8);
+#elif defined(PRE2)
+ __msan_poison(&act.flags, sizeof(act.flags));
+ __sanitizer_syscall_pre_rt_sigaction(SIGUSR1, &act, &oldact, 20 * 8);
+#elif defined(PRE3)
+ __msan_poison(&act.mask, 1);
+ __sanitizer_syscall_pre_rt_sigaction(SIGUSR1, &act, &oldact, 20 * 8);
+#else
+ // Uninit past the end of the mask is ignored.
+ __msan_poison(((char *)&act.mask) + 5, 1);
+ __sanitizer_syscall_pre_rt_sigaction(SIGUSR1, &act, &oldact, 5);
+
+ memset(&act, 0, sizeof(act));
+ __msan_poison(&oldact, sizeof(oldact));
+ __sanitizer_syscall_post_rt_sigaction(0, SIGUSR1, &act, &oldact, 5);
+ assert(__msan_test_shadow(&oldact, sizeof(oldact)) == sizeof(long)*3 + 5);
+#endif
+}
diff --git a/test/msan/Unit/lit.site.cfg.in b/test/msan/Unit/lit.site.cfg.in
index dc0e9613d59e..083a25bc882b 100644
--- a/test/msan/Unit/lit.site.cfg.in
+++ b/test/msan/Unit/lit.site.cfg.in
@@ -1,5 +1,4 @@
-## Autogenerated by LLVM/Clang configuration.
-# Do not edit!
+@LIT_SITE_CFG_IN_HEADER@
# Load common config for all compiler-rt unit tests.
lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/unittests/lit.common.unit.configured")
diff --git a/test/msan/coverage-levels.cc b/test/msan/coverage-levels.cc
index d71bfecb2ebb..710a69aff53a 100644
--- a/test/msan/coverage-levels.cc
+++ b/test/msan/coverage-levels.cc
@@ -24,5 +24,5 @@ int main(int argc, char **argv) {
// CHECK_WARN: WARNING: MemorySanitizer: use-of-uninitialized-value
// CHECK_NOWARN-NOT: ERROR
// CHECK1: 1 PCs written
-// CHECK2: 2 PCs written
-// CHECK3: 3 PCs written
+// CHECK2: 1 PCs written
+// CHECK3: 2 PCs written
diff --git a/test/msan/dlerror.cc b/test/msan/dlerror.cc
index 0ad5b35f5218..d5510b65c4a5 100644
--- a/test/msan/dlerror.cc
+++ b/test/msan/dlerror.cc
@@ -1,8 +1,4 @@
// RUN: %clangxx_msan -O0 %s -o %t && %run %t
-//
-// AArch64 shows fails with uninitialized bytes in __interceptor_strcmp from
-// dlfcn/dlerror.c:107 (glibc).
-// XFAIL: aarch64
#include <assert.h>
#include <dlfcn.h>
diff --git a/test/msan/dtls_test.c b/test/msan/dtls_test.c
index 4036f71a7f8e..49d95c44c1d8 100644
--- a/test/msan/dtls_test.c
+++ b/test/msan/dtls_test.c
@@ -4,7 +4,7 @@
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
+ and https://github.com/google/sanitizers/issues/547
*/
#ifndef BUILD_SO
diff --git a/test/msan/fork.cc b/test/msan/fork.cc
index 38c3616ec164..78a62d549ec3 100644
--- a/test/msan/fork.cc
+++ b/test/msan/fork.cc
@@ -4,11 +4,6 @@
// RUN: %clangxx_msan -std=c++11 -fsanitize-memory-track-origins=2 -g -O3 %s -o %t
// RUN: MSAN_OPTIONS=store_context_size=1000,origin_history_size=0,origin_history_per_stack_limit=0 %run %t |& FileCheck %s
-//
-// Big-endian mips64 currently hangs on this test. Mark it unsupported to allow
-// llvm-lit to finish. This also marks mips unsupported in most cases but msan
-// is already unsupported for 32-bit mips.
-// UNSUPPORTED: mips64-supported-target
// Fun fact: if test output is redirected to a file (as opposed to
// being piped directly to FileCheck), we may lose some "done"s due to
diff --git a/test/msan/lit.cfg b/test/msan/lit.cfg
index 011ccd2fae74..d23ff31bc748 100644
--- a/test/msan/lit.cfg
+++ b/test/msan/lit.cfg
@@ -3,17 +3,18 @@
import os
# Setup config name.
-config.name = 'MemorySanitizer'
+config.name = 'MemorySanitizer' + getattr(config, 'name_suffix', 'default')
# Setup source root.
config.test_source_root = os.path.dirname(__file__)
# Setup default compiler flags used with -fsanitize=memory option.
-clang_msan_cflags = ["-fsanitize=memory",
- "-mno-omit-leaf-frame-pointer",
- "-fno-omit-frame-pointer",
- "-fno-optimize-sibling-calls",
- "-m64"] + config.debug_info_flags
+clang_msan_cflags = (["-fsanitize=memory",
+ "-mno-omit-leaf-frame-pointer",
+ "-fno-omit-frame-pointer",
+ "-fno-optimize-sibling-calls"] +
+ [config.target_cflags] +
+ config.debug_info_flags)
# Some Msan tests leverage backtrace() which requires libexecinfo on FreeBSD.
if config.host_os == 'FreeBSD':
clang_msan_cflags += ["-lexecinfo"]
@@ -31,3 +32,6 @@ config.suffixes = ['.c', '.cc', '.cpp']
# MemorySanitizer tests are currently supported on Linux only.
if config.host_os not in ['Linux']:
config.unsupported = True
+
+if config.target_arch != 'aarch64':
+ config.available_features.add('stable-runtime')
diff --git a/test/msan/lit.site.cfg.in b/test/msan/lit.site.cfg.in
index fb22a57a9e66..a9656f24d603 100644
--- a/test/msan/lit.site.cfg.in
+++ b/test/msan/lit.site.cfg.in
@@ -1,3 +1,10 @@
+@LIT_SITE_CFG_IN_HEADER@
+
+# Tool-specific config options.
+config.name_suffix = "@MSAN_TEST_CONFIG_SUFFIX@"
+config.target_cflags = "@MSAN_TEST_TARGET_CFLAGS@"
+config.target_arch = "@MSAN_TEST_TARGET_ARCH@"
+
# Load common config for all compiler-rt lit tests.
lit_config.load_config(config, "@COMPILER_RT_BINARY_DIR@/test/lit.common.configured")
diff --git a/test/msan/memcmp_test.cc b/test/msan/memcmp_test.cc
index 95228eb127dd..5ade58a6004a 100644
--- a/test/msan/memcmp_test.cc
+++ b/test/msan/memcmp_test.cc
@@ -3,13 +3,16 @@
// RUN: MSAN_OPTIONS=intercept_memcmp=0 %run %t
#include <string.h>
+#include <stdio.h>
int main(int argc, char **argv) {
char a1[4];
char a2[4];
for (int i = 0; i < argc * 3; i++)
a2[i] = a1[i] = i;
int res = memcmp(a1, a2, 4);
- return res;
+ if (!res)
+ printf("equals");
+ return 0;
// CHECK: Uninitialized bytes in __interceptor_memcmp at offset 3
// CHECK: MemorySanitizer: use-of-uninitialized-value
}
diff --git a/test/msan/msan_print_shadow3.cc b/test/msan/msan_print_shadow3.cc
index b29f3222dc33..4783152797eb 100644
--- a/test/msan/msan_print_shadow3.cc
+++ b/test/msan/msan_print_shadow3.cc
@@ -6,7 +6,7 @@
int main(void) {
unsigned long long x = 0; // For 8-byte alignment.
- uint32_t x_s = 0x12345678U;
+ char x_s[4] = {0x87, 0x65, 0x43, 0x21};
__msan_partial_poison(&x, &x_s, sizeof(x_s));
__msan_print_shadow(&x, sizeof(x_s));
return 0;
diff --git a/test/msan/param_tls_limit.cc b/test/msan/param_tls_limit.cc
index 1c504da42825..d34376a1f0c4 100644
--- a/test/msan/param_tls_limit.cc
+++ b/test/msan/param_tls_limit.cc
@@ -20,6 +20,17 @@
// In case of no overflow, it is still poisoned.
#define NO_OVERFLOW(x) assert(__msan_test_shadow(&x, sizeof(x)) == 0)
+#if defined(__x86_64__)
+// In x86_64, if argument is partially outside tls, it is considered completly
+// unpoisoned
+#define PARTIAL_OVERFLOW(x) OVERFLOW(x)
+#else
+// In other archs, bigger arguments are splitted in multiple IR arguments, so
+// they are considered poisoned till tls limit. Checking last byte of such arg:
+#define PARTIAL_OVERFLOW(x) assert(__msan_test_shadow((char *)(&(x) + 1) - 1, 1) == -1)
+#endif
+
+
template<int N>
struct S {
char x[N];
@@ -34,17 +45,17 @@ void f800(S<800> s) {
}
void f801(S<801> s) {
- OVERFLOW(s);
+ PARTIAL_OVERFLOW(s);
}
void f1000(S<1000> s) {
- OVERFLOW(s);
+ PARTIAL_OVERFLOW(s);
}
void f_many(int a, double b, S<800> s, int c, double d) {
NO_OVERFLOW(a);
NO_OVERFLOW(b);
- OVERFLOW(s);
+ PARTIAL_OVERFLOW(s);
OVERFLOW(c);
OVERFLOW(d);
}
@@ -54,7 +65,7 @@ void f_many(int a, double b, S<800> s, int c, double d) {
void f_many2(int a, S<800 - 8 - 2> s, int c, double d) {
NO_OVERFLOW(a);
NO_OVERFLOW(s);
- OVERFLOW(c);
+ PARTIAL_OVERFLOW(c);
OVERFLOW(d);
}
diff --git a/test/msan/vector_cvt.cc b/test/msan/vector_cvt.cc
index 633a8b15c444..5541436ead82 100644
--- a/test/msan/vector_cvt.cc
+++ b/test/msan/vector_cvt.cc
@@ -1,6 +1,6 @@
// RUN: %clangxx_msan -O0 %s -o %t && %run %t
// RUN: %clangxx_msan -DPOSITIVE -O0 %s -o %t && not %run %t 2>&1 | FileCheck %s
-// REQUIRES: x86_64-supported-target
+// REQUIRES: x86_64-target-arch
#include <emmintrin.h>