diff --git a/compiler-rt/lib/msan/msan_interceptors.cpp b/compiler-rt/lib/msan/msan_interceptors.cpp index b883c5b2a24de..c2d740e7762b4 100644 --- a/compiler-rt/lib/msan/msan_interceptors.cpp +++ b/compiler-rt/lib/msan/msan_interceptors.cpp @@ -243,15 +243,16 @@ INTERCEPTOR(uptr, malloc_usable_size, void *ptr) { #define MSAN_MAYBE_INTERCEPT_MALLOC_USABLE_SIZE #endif -#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD - +#if (!SANITIZER_FREEBSD && !SANITIZER_NETBSD) || __GLIBC_PREREQ(2, 33) template static NOINLINE void clear_mallinfo(T *sret) { ENSURE_MSAN_INITED(); internal_memset(sret, 0, sizeof(*sret)); __msan_unpoison(sret, sizeof(*sret)); } +#endif +#if !SANITIZER_FREEBSD && !SANITIZER_NETBSD // Interceptors use NRVO and assume that sret will be pre-allocated in // caller frame. INTERCEPTOR(__sanitizer_struct_mallinfo, mallinfo) { @@ -259,16 +260,19 @@ INTERCEPTOR(__sanitizer_struct_mallinfo, mallinfo) { clear_mallinfo(&sret); return sret; } +# define MSAN_MAYBE_INTERCEPT_MALLINFO INTERCEPT_FUNCTION(mallinfo) +#else +# define MSAN_MAYBE_INTERCEPT_MALLINFO +#endif +#if __GLIBC_PREREQ(2, 33) INTERCEPTOR(__sanitizer_struct_mallinfo2, mallinfo2) { __sanitizer_struct_mallinfo2 sret; clear_mallinfo(&sret); return sret; } -# define MSAN_MAYBE_INTERCEPT_MALLINFO INTERCEPT_FUNCTION(mallinfo) # define MSAN_MAYBE_INTERCEPT_MALLINFO2 INTERCEPT_FUNCTION(mallinfo2) #else -#define MSAN_MAYBE_INTERCEPT_MALLINFO # define MSAN_MAYBE_INTERCEPT_MALLINFO2 #endif diff --git a/compiler-rt/test/lit.common.cfg.py b/compiler-rt/test/lit.common.cfg.py index 7a91558d51542..1753a55508c7c 100644 --- a/compiler-rt/test/lit.common.cfg.py +++ b/compiler-rt/test/lit.common.cfg.py @@ -629,7 +629,7 @@ def add_glibc_versions(ver_string): ver = LooseVersion(ver_string) any_glibc = False - for required in ["2.19", "2.27", "2.30", "2.34", "2.37"]: + for required in ["2.19", "2.27", "2.30", "2.33", "2.34", "2.37"]: if ver >= LooseVersion(required): config.available_features.add("glibc-" + required) any_glibc = True diff --git a/compiler-rt/test/msan/Linux/mallinfo.cpp b/compiler-rt/test/msan/Linux/mallinfo.cpp index f061218c615a3..3c3692969852f 100644 --- a/compiler-rt/test/msan/Linux/mallinfo.cpp +++ b/compiler-rt/test/msan/Linux/mallinfo.cpp @@ -8,8 +8,5 @@ int main(void) { struct mallinfo mi = mallinfo(); assert(__msan_test_shadow(&mi, sizeof(mi)) == -1); - - struct mallinfo2 mi2 = mallinfo2(); - assert(__msan_test_shadow(&mi2, sizeof(mi2)) == -1); return 0; } diff --git a/compiler-rt/test/msan/Linux/mallinfo2.cpp b/compiler-rt/test/msan/Linux/mallinfo2.cpp new file mode 100644 index 0000000000000..5e6e5d952ff1b --- /dev/null +++ b/compiler-rt/test/msan/Linux/mallinfo2.cpp @@ -0,0 +1,13 @@ +// RUN: %clangxx_msan -O0 -g %s -o %t && %run %t +// REQUIRES: glibc-2.33 + +#include +#include + +#include + +int main(void) { + struct mallinfo2 mi2 = mallinfo2(); + assert(__msan_test_shadow(&mi2, sizeof(mi2)) == -1); + return 0; +}