From 909deebfc8b90eee317424646f6bdf358160164e Mon Sep 17 00:00:00 2001 From: Eric Fiselier Date: Mon, 24 Nov 2014 18:17:04 +0000 Subject: [PATCH] [compiler-rt] Make the MSAN wmemset intercepter call wmemset instead of memset. Fixes PR 21579 Summary: Exactly what the title says. I've tested this change against the libc++ test failures and it solves all of them. The check-msan rule also still passes. I'm not sure why it called memset originally. I can add tests if requested but currently there are no tests involving wide chars and they are a c++11 features. Reviewers: kcc, eugenis Reviewed By: eugenis Subscribers: llvm-commits Differential Revision: http://reviews.llvm.org/D6352 llvm-svn: 222673 --- compiler-rt/lib/msan/msan_interceptors.cc | 2 +- compiler-rt/lib/msan/tests/msan_test.cc | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/compiler-rt/lib/msan/msan_interceptors.cc b/compiler-rt/lib/msan/msan_interceptors.cc index aa6b1ff..94af2d7 100644 --- a/compiler-rt/lib/msan/msan_interceptors.cc +++ b/compiler-rt/lib/msan/msan_interceptors.cc @@ -531,7 +531,7 @@ INTERCEPTOR(wchar_t *, wmempcpy, wchar_t *dest, const wchar_t *src, SIZE_T n) { INTERCEPTOR(wchar_t *, wmemset, wchar_t *s, wchar_t c, SIZE_T n) { CHECK(MEM_IS_APP(s)); ENSURE_MSAN_INITED(); - wchar_t *res = (wchar_t *)REAL(memset)(s, c, n * sizeof(wchar_t)); + wchar_t *res = REAL(wmemset)(s, c, n); __msan_unpoison(s, n * sizeof(wchar_t)); return res; } diff --git a/compiler-rt/lib/msan/tests/msan_test.cc b/compiler-rt/lib/msan/tests/msan_test.cc index 12012a0..84fa962 100644 --- a/compiler-rt/lib/msan/tests/msan_test.cc +++ b/compiler-rt/lib/msan/tests/msan_test.cc @@ -1834,6 +1834,16 @@ TEST(MemorySanitizer, wcsnrtombs) { EXPECT_POISONED(buff[2]); } +TEST(MemorySanitizer, wmemset) { + wchar_t x[25]; + break_optimization(x); + EXPECT_POISONED(x[0]); + wmemset(x, L'A', 10); + EXPECT_EQ(x[0], L'A'); + EXPECT_EQ(x[9], L'A'); + EXPECT_POISONED(x[10]); +} + TEST(MemorySanitizer, mbtowc) { const char *x = "abc"; wchar_t wx; -- 2.7.4