From: Paul Floyd Date: Tue, 7 Mar 2023 21:47:19 +0000 (+0100) Subject: Add checks to all new / delete overload arguments X-Git-Tag: VALGRIND_3_21_0~135 X-Git-Url: https://sourceware.org/git/?a=commitdiff_plain;h=ceee3e8922b734f9d80166d88611c2d14ec9f06e;p=valgrind.git Add checks to all new / delete overload arguments --- diff --git a/.gitignore b/.gitignore index 67e6b545fe..a4c7b510ba 100644 --- a/.gitignore +++ b/.gitignore @@ -961,6 +961,7 @@ /memcheck/tests/sendmsg /memcheck/tests/sh-mem /memcheck/tests/sh-mem-random +/memcheck/tests/sized_aligned_new_delete_args /memcheck/tests/sigaltstack /memcheck/tests/sigkill /memcheck/tests/signal2 diff --git a/coregrind/m_replacemalloc/vg_replace_malloc.c b/coregrind/m_replacemalloc/vg_replace_malloc.c index 6addfe80f9..e07ab50504 100644 --- a/coregrind/m_replacemalloc/vg_replace_malloc.c +++ b/coregrind/m_replacemalloc/vg_replace_malloc.c @@ -930,6 +930,19 @@ extern int *___errno (void) __attribute__((weak)); /*---------------------- delete ----------------------*/ +#define DELETE_SIZED(soname, fnname, vg_replacement) \ + \ + void VG_REPLACE_FUNCTION_EZU(10050,soname,fnname) (void *p, size_t size); \ + void VG_REPLACE_FUNCTION_EZU(10050,soname,fnname) (void *p, size_t size) \ + { \ + DO_INIT; \ + TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED((UWord)size); \ + MALLOC_TRACE(#fnname "(%p)\n", p ); \ + if (p == NULL) \ + return; \ + (void)VALGRIND_NON_SIMD_CALL1( info.tl_##vg_replacement, p ); \ + } + #if defined(VGO_linux) // operator delete(void*), not mangled (for gcc 2.96) FREE(VG_Z_LIBSTDCXX_SONAME, __builtin_delete, __builtin_delete ); @@ -941,16 +954,16 @@ extern int *___errno (void) __attribute__((weak)); FREE(SO_SYN_MALLOC, _ZdlPv, __builtin_delete ); // operator delete(void*, unsigned int), C++14, GNU mangling #if __SIZEOF_SIZE_T__ == 4 - FREE(VG_Z_LIBSTDCXX_SONAME, _ZdlPvj, __builtin_delete ); - FREE(VG_Z_LIBCXX_SONAME, _ZdlPvj, __builtin_delete ); - FREE(VG_Z_LIBC_SONAME, _ZdlPvj, __builtin_delete ); - FREE(SO_SYN_MALLOC, _ZdlPvj, __builtin_delete ); + DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvj, __builtin_delete ); + DELETE_SIZED(VG_Z_LIBCXX_SONAME, _ZdlPvj, __builtin_delete ); + DELETE_SIZED(VG_Z_LIBC_SONAME, _ZdlPvj, __builtin_delete ); + DELETE_SIZED(SO_SYN_MALLOC, _ZdlPvj, __builtin_delete ); // operator delete(void*, unsigned long), C++14, GNU mangling #elif __SIZEOF_SIZE_T__ == 8 - FREE(VG_Z_LIBSTDCXX_SONAME, _ZdlPvm, __builtin_delete ); - FREE(VG_Z_LIBCXX_SONAME, _ZdlPvm, __builtin_delete ); - FREE(VG_Z_LIBC_SONAME, _ZdlPvm, __builtin_delete ); - FREE(SO_SYN_MALLOC, _ZdlPvm, __builtin_delete ); + DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvm, __builtin_delete ); + DELETE_SIZED(VG_Z_LIBCXX_SONAME, _ZdlPvm, __builtin_delete ); + DELETE_SIZED(VG_Z_LIBC_SONAME, _ZdlPvm, __builtin_delete ); + DELETE_SIZED(SO_SYN_MALLOC, _ZdlPvm, __builtin_delete ); #endif @@ -960,13 +973,13 @@ extern int *___errno (void) __attribute__((weak)); FREE(SO_SYN_MALLOC, _ZdlPv, __builtin_delete ); // operator delete(void*, unsigned long), C++14, GNU mangling #if __SIZEOF_SIZE_T__ == 4 - FREE(VG_Z_LIBSTDCXX_SONAME, _ZdlPvj, __builtin_delete ); - FREE(VG_Z_LIBCXX_SONAME, _ZdlPvj, __builtin_delete ); - FREE(SO_SYN_MALLOC, _ZdlPvj, __builtin_delete ); + DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvj, __builtin_delete ); + DELETE_SIZED(VG_Z_LIBCXX_SONAME, _ZdlPvj, __builtin_delete ); + DELETE_SIZED(SO_SYN_MALLOC, _ZdlPvj, __builtin_delete ); #elif __SIZEOF_SIZE_T__ == 8 - FREE(VG_Z_LIBSTDCXX_SONAME, _ZdlPvm, __builtin_delete ); - FREE(VG_Z_LIBCXX_SONAME, _ZdlPvm, __builtin_delete ); - FREE(SO_SYN_MALLOC, _ZdlPvm, __builtin_delete ); + DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvm, __builtin_delete ); + DELETE_SIZED(VG_Z_LIBCXX_SONAME, _ZdlPvm, __builtin_delete ); + DELETE_SIZED(SO_SYN_MALLOC, _ZdlPvm, __builtin_delete ); #endif #elif defined(VGO_darwin) @@ -981,11 +994,11 @@ extern int *___errno (void) __attribute__((weak)); // operator delete(void*, unsigned long), C++14, GNU mangling #if __SIZEOF_SIZE_T__ == 4 - FREE(VG_Z_LIBSTDCXX_SONAME, _ZdlPvj, __builtin_delete ); - FREE(SO_SYN_MALLOC, _ZdlPvj, __builtin_delete ); + DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvj, __builtin_delete ); + DELETE_SIZED(SO_SYN_MALLOC, _ZdlPvj, __builtin_delete ); #elif __SIZEOF_SIZE_T__ == 8 - FREE(VG_Z_LIBSTDCXX_SONAME, _ZdlPvm, __builtin_delete ); - FREE(SO_SYN_MALLOC, _ZdlPvm, __builtin_delete ); + DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvm, __builtin_delete ); + DELETE_SIZED(SO_SYN_MALLOC, _ZdlPvm, __builtin_delete ); #endif @@ -993,43 +1006,70 @@ extern int *___errno (void) __attribute__((weak)); /*------------------- C++17 delete aligned -------------------*/ +#define DELETE_ALIGNED(soname, fnname, vg_replacement) \ + \ + void VG_REPLACE_FUNCTION_EZU(10050,soname,fnname) (void *p, size_t alignment); \ + void VG_REPLACE_FUNCTION_EZU(10050,soname,fnname) (void *p, size_t alignment) \ + { \ + DO_INIT; \ + TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED((UWord)alignment); \ + MALLOC_TRACE(#fnname "(%p)\n", p ); \ + if (p == NULL) \ + return; \ + (void)VALGRIND_NON_SIMD_CALL1( info.tl_##vg_replacement, p ); \ + } + +#define DELETE_SIZED_ALIGNED(soname, fnname, vg_replacement) \ + \ + void VG_REPLACE_FUNCTION_EZU(10050,soname,fnname) (void *p, size_t size, size_t alignment); \ + void VG_REPLACE_FUNCTION_EZU(10050,soname,fnname) (void *p, size_t size, size_t alignment) \ + { \ + DO_INIT; \ + TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED((UWord)size); \ + TRIGGER_MEMCHECK_ERROR_IF_UNDEFINED((UWord)alignment); \ + MALLOC_TRACE(#fnname "(%p)\n", p ); \ + if (p == NULL) \ + return; \ + (void)VALGRIND_NON_SIMD_CALL1( info.tl_##vg_replacement, p ); \ + } + #if defined(VGO_linux) // operator delete(void*, std::align_val_t), GNU mangling - FREE(VG_Z_LIBSTDCXX_SONAME, _ZdlPvSt11align_val_t, __builtin_delete_aligned ); - FREE(VG_Z_LIBCXX_SONAME, _ZdlPvSt11align_val_t, __builtin_delete_aligned ); - FREE(VG_Z_LIBC_SONAME, _ZdlPvSt11align_val_t, __builtin_delete_aligned ); + DELETE_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvSt11align_val_t, __builtin_delete_aligned ); + DELETE_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdlPvSt11align_val_t, __builtin_delete_aligned ); + DELETE_ALIGNED(VG_Z_LIBC_SONAME, _ZdlPvSt11align_val_t, __builtin_delete_aligned ); FREE(SO_SYN_MALLOC, _ZdlPvSt11align_val_t, __builtin_delete_aligned ); // operator delete(void*, unsigned int, std::align_val_t), GNU mangling #if __SIZEOF_SIZE_T__ == 4 - FREE(VG_Z_LIBSTDCXX_SONAME, _ZdlPvjSt11align_val_t, __builtin_delete_aligned ); - FREE(VG_Z_LIBCXX_SONAME, _ZdlPvjSt11align_val_t, __builtin_delete_aligned ); - FREE(VG_Z_LIBC_SONAME, _ZdlPvjSt11align_val_t, __builtin_delete_aligned ); - FREE(SO_SYN_MALLOC, _ZdlPvjSt11align_val_t, __builtin_delete_aligned ); + DELETE_SIZED_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvjSt11align_val_t, __builtin_delete_aligned ); + DELETE_SIZED_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdlPvjSt11align_val_t, __builtin_delete_aligned ); + DELETE_SIZED_ALIGNED(VG_Z_LIBC_SONAME, _ZdlPvjSt11align_val_t, __builtin_delete_aligned ); + DELETE_SIZED_ALIGNED(SO_SYN_MALLOC, _ZdlPvjSt11align_val_t, __builtin_delete_aligned ); // operator delete(void*, unsigned long, std::align_val_t), GNU mangling #elif __SIZEOF_SIZE_T__ == 8 - FREE(VG_Z_LIBSTDCXX_SONAME, _ZdlPvmSt11align_val_t, __builtin_delete_aligned ); - FREE(VG_Z_LIBCXX_SONAME, _ZdlPvmSt11align_val_t, __builtin_delete_aligned ); - FREE(VG_Z_LIBC_SONAME, _ZdlPvmSt11align_val_t, __builtin_delete_aligned ); - FREE(SO_SYN_MALLOC, _ZdlPvmSt11align_val_t, __builtin_delete_aligned ); + DELETE_SIZED_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvmSt11align_val_t, __builtin_delete_aligned ); + DELETE_SIZED_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdlPvmSt11align_val_t, __builtin_delete_aligned ); + DELETE_SIZED_ALIGNED(VG_Z_LIBC_SONAME, _ZdlPvmSt11align_val_t, __builtin_delete_aligned ); + DELETE_SIZED_ALIGNED(SO_SYN_MALLOC, _ZdlPvmSt11align_val_t, __builtin_delete_aligned ); #endif #elif defined(VGO_freebsd) // operator delete(void*, std::align_val_t), GNU mangling - FREE(VG_Z_LIBSTDCXX_SONAME, _ZdlPvSt11align_val_t, __builtin_delete_aligned ); - FREE(VG_Z_LIBCXX_SONAME, _ZdlPvSt11align_val_t, __builtin_delete_aligned ); - FREE(SO_SYN_MALLOC, _ZdlPvSt11align_val_t, __builtin_delete_aligned ); + DELETE_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvSt11align_val_t, __builtin_delete_aligned ); + DELETE_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdlPvSt11align_val_t, __builtin_delete_aligned ); + DELETE_ALIGNED(SO_SYN_MALLOC, _ZdlPvSt11align_val_t, __builtin_delete_aligned ); // operator delete(void*, unsigned int, std::align_val_t), GNU mangling #if __SIZEOF_SIZE_T__ == 4 - FREE(VG_Z_LIBSTDCXX_SONAME, _ZdlPvjSt11align_val_t, __builtin_delete_aligned ); - FREE(VG_Z_LIBCXX_SONAME, _ZdlPvjSt11align_val_t, __builtin_delete_aligned ); - FREE(SO_SYN_MALLOC, _ZdlPvjSt11align_val_t, __builtin_delete_aligned ); + DELETE_SIZED_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvjSt11align_val_t, __builtin_delete_aligned ); + DELETE_SIZED_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdlPvjSt11align_val_t, __builtin_delete_aligned ); + DELETE_SIZED_ALIGNED(SO_SYN_MALLOC, _ZdlPvjSt11align_val_t, __builtin_delete_aligned ); // operator delete(void*, unsigned long, std::align_val_t), GNU mangling #elif __SIZEOF_SIZE_T__ == 8 - FREE(VG_Z_LIBSTDCXX_SONAME, _ZdlPvmSt11align_val_t, __builtin_delete_aligned ); - FREE(VG_Z_LIBCXX_SONAME, _ZdlPvmSt11align_val_t, __builtin_delete_aligned ); - FREE(SO_SYN_MALLOC, _ZdlPvmSt11align_val_t, __builtin_delete_aligned ); + DELETE_SIZED_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvmSt11align_val_t, __builtin_delete_aligned ); + DELETE_SIZED_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdlPvmSt11align_val_t, __builtin_delete_aligned ); + DELETE_SIZED_ALIGNED(SO_SYN_MALLOC, _ZdlPvmSt11align_val_t, __builtin_delete_aligned ); #endif #elif defined(VGO_darwin) @@ -1037,17 +1077,17 @@ extern int *___errno (void) __attribute__((weak)); #elif defined(VGO_solaris) // operator delete(void*, std::align_val_t) - FREE(VG_Z_LIBSTDCXX_SONAME, _ZdlPvSt11align_val_t, __builtin_delete_aligned ); - FREE(SO_SYN_MALLOC, _ZdlPvSt11align_val_t, __builtin_delete_aligned ); + DELETE_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvSt11align_val_t, __builtin_delete_aligned ); + DELETE_ALIGNED(SO_SYN_MALLOC, _ZdlPvSt11align_val_t, __builtin_delete_aligned ); // operator delete(void*, unsigned int, std::align_val_t) #if __SIZEOF_SIZE_T__ == 4 - FREE(VG_Z_LIBSTDCXX_SONAME, _ZdlPvjSt11align_val_t, __builtin_delete_aligned ); - FREE(SO_SYN_MALLOC, _ZdlPvjSt11align_val_t, __builtin_delete_aligned ); + DELETE_SIZED_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvjSt11align_val_t, __builtin_delete_aligned ); + DELETE_SIZED_ALIGNED(SO_SYN_MALLOC, _ZdlPvjSt11align_val_t, __builtin_delete_aligned ); // operator delete(void*, unsigned long, std::align_val_t) #elif __SIZEOF_SIZE_T__ == 8 - FREE(VG_Z_LIBSTDCXX_SONAME, _ZdlPvmSt11align_val_t, __builtin_delete_aligned ); - FREE(SO_SYN_MALLOC, _ZdlPvmSt11align_val_t, __builtin_delete_aligned ); + DELETE_SIZED_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvmSt11align_val_t, __builtin_delete_aligned ); + DELETE_SIZED_ALIGNED(SO_SYN_MALLOC, _ZdlPvmSt11align_val_t, __builtin_delete_aligned ); #endif #endif @@ -1083,25 +1123,25 @@ extern int *___errno (void) __attribute__((weak)); #if defined(VGO_linux) // operator delete(void*, std::align_val_t, std::nothrow_t const&), GNU mangling - FREE(VG_Z_LIBSTDCXX_SONAME, _ZdlPvSt11align_val_tRKSt9nothrow_t, __builtin_delete_aligned ); - FREE(VG_Z_LIBCXX_SONAME, _ZdlPvSt11align_val_tRKSt9nothrow_t, __builtin_delete_aligned ); - FREE(VG_Z_LIBC_SONAME, _ZdlPvSt11align_val_tRKSt9nothrow_t, __builtin_delete_aligned ); - FREE(SO_SYN_MALLOC, _ZdlPvSt11align_val_tRKSt9nothrow_t, __builtin_delete_aligned ); + DELETE_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvSt11align_val_tRKSt9nothrow_t, __builtin_delete_aligned ); + DELETE_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdlPvSt11align_val_tRKSt9nothrow_t, __builtin_delete_aligned ); + DELETE_ALIGNED(VG_Z_LIBC_SONAME, _ZdlPvSt11align_val_tRKSt9nothrow_t, __builtin_delete_aligned ); + DELETE_ALIGNED(SO_SYN_MALLOC, _ZdlPvSt11align_val_tRKSt9nothrow_t, __builtin_delete_aligned ); // no sized version of this operator #elif defined(VGO_freebsd) // operator delete(void*, std::align_val_t, std::nothrow_t const&), GNU mangling - FREE(VG_Z_LIBSTDCXX_SONAME, _ZdlPvSt11align_val_tRKSt9nothrow_t, __builtin_delete_aligned ); - FREE(VG_Z_LIBCXX_SONAME, _ZdlPvSt11align_val_tRKSt9nothrow_t, __builtin_delete_aligned ); - FREE(SO_SYN_MALLOC, _ZdlPvSt11align_val_tRKSt9nothrow_t, __builtin_delete_aligned ); + DELETE_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvSt11align_val_tRKSt9nothrow_t, __builtin_delete_aligned ); + DELETE_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdlPvSt11align_val_tRKSt9nothrow_t, __builtin_delete_aligned ); + DELETE_ALIGNED(SO_SYN_MALLOC, _ZdlPvSt11align_val_tRKSt9nothrow_t, __builtin_delete_aligned ); #elif defined(VGO_darwin) #elif defined(VGO_solaris) // operator delete(void*, std::align_val_t, std::nothrow_t const&), GNU mangling - FREE(VG_Z_LIBSTDCXX_SONAME, _ZdlPvSt11align_val_tRKSt9nothrow_t, __builtin_delete_aligned ); - FREE(SO_SYN_MALLOC, _ZdlPvSt11align_val_tRKSt9nothrow_t, __builtin_delete_aligned ); + DELETE_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdlPvSt11align_val_tRKSt9nothrow_t, __builtin_delete_aligned ); + DELETE_ALIGNED(SO_SYN_MALLOC, _ZdlPvSt11align_val_tRKSt9nothrow_t, __builtin_delete_aligned ); // no sized version of this operator @@ -1122,16 +1162,16 @@ extern int *___errno (void) __attribute__((weak)); // operator delete[](void*, unsigned long), C++14, GNU mangling #if __SIZEOF_SIZE_T__ == 4 - FREE(VG_Z_LIBSTDCXX_SONAME, _ZdaPvj, __builtin_vec_delete ); - FREE(VG_Z_LIBCXX_SONAME, _ZdaPvj, __builtin_vec_delete ); - FREE(VG_Z_LIBC_SONAME, _ZdaPvj, __builtin_vec_delete ); - FREE(SO_SYN_MALLOC, _ZdaPvj, __builtin_vec_delete ); + DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvj, __builtin_vec_delete ); + DELETE_SIZED(VG_Z_LIBCXX_SONAME, _ZdaPvj, __builtin_vec_delete ); + DELETE_SIZED(VG_Z_LIBC_SONAME, _ZdaPvj, __builtin_vec_delete ); + DELETE_SIZED(SO_SYN_MALLOC, _ZdaPvj, __builtin_vec_delete ); #elif __SIZEOF_SIZE_T__ == 8 - FREE(VG_Z_LIBSTDCXX_SONAME, _ZdaPvm, __builtin_vec_delete ); - FREE(VG_Z_LIBCXX_SONAME, _ZdaPvm, __builtin_vec_delete ); - FREE(VG_Z_LIBC_SONAME, _ZdaPvm, __builtin_vec_delete ); - FREE(SO_SYN_MALLOC, _ZdaPvm, __builtin_vec_delete ); + DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvm, __builtin_vec_delete ); + DELETE_SIZED(VG_Z_LIBCXX_SONAME, _ZdaPvm, __builtin_vec_delete ); + DELETE_SIZED(VG_Z_LIBC_SONAME, _ZdaPvm, __builtin_vec_delete ); + DELETE_SIZED(SO_SYN_MALLOC, _ZdaPvm, __builtin_vec_delete ); #endif #elif defined(VGO_freebsd) @@ -1141,13 +1181,13 @@ extern int *___errno (void) __attribute__((weak)); FREE(SO_SYN_MALLOC, _ZdaPv, __builtin_vec_delete ); // operator delete[](void*, unsigned long), C++14, GNU mangling #if __SIZEOF_SIZE_T__ == 4 - FREE(VG_Z_LIBSTDCXX_SONAME, _ZdaPvj, __builtin_vec_delete ); - FREE(VG_Z_LIBCXX_SONAME, _ZdaPvj, __builtin_vec_delete ); - FREE(SO_SYN_MALLOC, _ZdaPvj, __builtin_vec_delete ); + DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvj, __builtin_vec_delete ); + DELETE_SIZED(VG_Z_LIBCXX_SONAME, _ZdaPvj, __builtin_vec_delete ); + DELETE_SIZED(SO_SYN_MALLOC, _ZdaPvj, __builtin_vec_delete ); #elif __SIZEOF_SIZE_T__ == 8 - FREE(VG_Z_LIBSTDCXX_SONAME, _ZdaPvm, __builtin_vec_delete ); - FREE(VG_Z_LIBCXX_SONAME, _ZdaPvm, __builtin_vec_delete ); - FREE(SO_SYN_MALLOC, _ZdaPvm, __builtin_vec_delete ); + DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvm, __builtin_vec_delete ); + DELETE_SIZED(VG_Z_LIBCXX_SONAME, _ZdaPvm, __builtin_vec_delete ); + DELETE_SIZED(SO_SYN_MALLOC, _ZdaPvm, __builtin_vec_delete ); #endif #elif defined(VGO_darwin) @@ -1165,12 +1205,12 @@ extern int *___errno (void) __attribute__((weak)); // operator delete[](void*, unsigned int), C++14, GNU mangling #if __SIZEOF_SIZE_T__ == 4 - FREE(VG_Z_LIBSTDCXX_SONAME, _ZdaPvj, __builtin_vec_delete ); - FREE(SO_SYN_MALLOC, _ZdaPvj, __builtin_vec_delete ); + DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvj, __builtin_vec_delete ); + DELETE_SIZED(SO_SYN_MALLOC, _ZdaPvj, __builtin_vec_delete ); // operator delete[](void*, unsigned long), C++14, GNU mangling #elif __SIZEOF_SIZE_T__ == 8 - FREE(VG_Z_LIBSTDCXX_SONAME, _ZdaPvm, __builtin_vec_delete ); - FREE(SO_SYN_MALLOC, _ZdaPvm, __builtin_vec_delete ); + DELETE_SIZED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvm, __builtin_vec_delete ); + DELETE_SIZED(SO_SYN_MALLOC, _ZdaPvm, __builtin_vec_delete ); #endif #endif @@ -1179,58 +1219,58 @@ extern int *___errno (void) __attribute__((weak)); #if defined(VGO_linux) // operator delete[](void*, std::align_val_t), GNU mangling - FREE(VG_Z_LIBSTDCXX_SONAME, _ZdaPvSt11align_val_t, __builtin_vec_delete_aligned ); - FREE(VG_Z_LIBCXX_SONAME, _ZdaPvSt11align_val_t, __builtin_vec_delete_aligned ); - FREE(VG_Z_LIBC_SONAME, _ZdaPvSt11align_val_t, __builtin_vec_delete_aligned ); - FREE(SO_SYN_MALLOC, _ZdaPvSt11align_val_t, __builtin_vec_delete_aligned ); + DELETE_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvSt11align_val_t, __builtin_vec_delete_aligned ); + DELETE_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdaPvSt11align_val_t, __builtin_vec_delete_aligned ); + DELETE_ALIGNED(VG_Z_LIBC_SONAME, _ZdaPvSt11align_val_t, __builtin_vec_delete_aligned ); + DELETE_ALIGNED(SO_SYN_MALLOC, _ZdaPvSt11align_val_t, __builtin_vec_delete_aligned ); // operator delete[](void*, unsigned int, std::align_val_t), GNU mangling #if __SIZEOF_SIZE_T__ == 4 - FREE(VG_Z_LIBSTDCXX_SONAME, _ZdaPvjSt11align_val_t, __builtin_vec_delete_aligned ); - FREE(VG_Z_LIBCXX_SONAME, _ZdaPvjSt11align_val_t, __builtin_vec_delete_aligned ); - FREE(VG_Z_LIBC_SONAME, _ZdaPvjSt11align_val_t, __builtin_vec_delete_aligned ); - FREE(SO_SYN_MALLOC, _ZdaPvjSt11align_val_t, __builtin_vec_delete_aligned ); + DELETE_SIZED_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvjSt11align_val_t, __builtin_vec_delete_aligned ); + DELETE_SIZED_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdaPvjSt11align_val_t, __builtin_vec_delete_aligned ); + DELETE_SIZED_ALIGNED(VG_Z_LIBC_SONAME, _ZdaPvjSt11align_val_t, __builtin_vec_delete_aligned ); + DELETE_SIZED_ALIGNED(SO_SYN_MALLOC, _ZdaPvjSt11align_val_t, __builtin_vec_delete_aligned ); // operator delete[](void*, unsigned long, std::align_val_t), GNU mangling #elif __SIZEOF_SIZE_T__ == 8 - FREE(VG_Z_LIBSTDCXX_SONAME, _ZdaPvmSt11align_val_t, __builtin_vec_delete_aligned ); - FREE(VG_Z_LIBCXX_SONAME, _ZdaPvmSt11align_val_t, __builtin_vec_delete_aligned ); - FREE(VG_Z_LIBC_SONAME, _ZdaPvmSt11align_val_t, __builtin_vec_delete_aligned ); - FREE(SO_SYN_MALLOC, _ZdaPvmSt11align_val_t, __builtin_vec_delete_aligned ); + DELETE_SIZED_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvmSt11align_val_t, __builtin_vec_delete_aligned ); + DELETE_SIZED_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdaPvmSt11align_val_t, __builtin_vec_delete_aligned ); + DELETE_SIZED_ALIGNED(VG_Z_LIBC_SONAME, _ZdaPvmSt11align_val_t, __builtin_vec_delete_aligned ); + DELETE_SIZED_ALIGNED(SO_SYN_MALLOC, _ZdaPvmSt11align_val_t, __builtin_vec_delete_aligned ); #endif #elif defined(VGO_freebsd) // operator delete[](void*, std::align_val_t), GNU mangling - FREE(VG_Z_LIBSTDCXX_SONAME, _ZdaPvSt11align_val_t, __builtin_vec_delete_aligned ); - FREE(VG_Z_LIBCXX_SONAME, _ZdaPvSt11align_val_t, __builtin_vec_delete_aligned ); - FREE(SO_SYN_MALLOC, _ZdaPvSt11align_val_t, __builtin_vec_delete_aligned ); + DELETE_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvSt11align_val_t, __builtin_vec_delete_aligned ); + DELETE_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdaPvSt11align_val_t, __builtin_vec_delete_aligned ); + DELETE_ALIGNED(SO_SYN_MALLOC, _ZdaPvSt11align_val_t, __builtin_vec_delete_aligned ); // operator delete[](void*, unsigned int, std::align_val_t), GNU mangling #if __SIZEOF_SIZE_T__ == 4 - FREE(VG_Z_LIBSTDCXX_SONAME, _ZdaPvjSt11align_val_t, __builtin_vec_delete_aligned ); - FREE(VG_Z_LIBCXX_SONAME, _ZdaPvjSt11align_val_t, __builtin_vec_delete_aligned ); - FREE(SO_SYN_MALLOC, _ZdaPvjSt11align_val_t, __builtin_vec_delete_aligned ); + DELETE_SIZED_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvjSt11align_val_t, __builtin_vec_delete_aligned ); + DELETE_SIZED_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdaPvjSt11align_val_t, __builtin_vec_delete_aligned ); + DELETE_SIZED_ALIGNED(SO_SYN_MALLOC, _ZdaPvjSt11align_val_t, __builtin_vec_delete_aligned ); // operator delete[](void*, unsigned long, std::align_val_t), GNU mangling #elif __SIZEOF_SIZE_T__ == 8 - FREE(VG_Z_LIBSTDCXX_SONAME, _ZdaPvmSt11align_val_t, __builtin_vec_delete_aligned ); - FREE(VG_Z_LIBCXX_SONAME, _ZdaPvmSt11align_val_t, __builtin_vec_delete_aligned ); - FREE(SO_SYN_MALLOC, _ZdaPvmSt11align_val_t, __builtin_vec_delete_aligned ); + DELETE_SIZED_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvmSt11align_val_t, __builtin_vec_delete_aligned ); + DELETE_SIZED_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdaPvmSt11align_val_t, __builtin_vec_delete_aligned ); + DELETE_SIZED_ALIGNED(SO_SYN_MALLOC, _ZdaPvmSt11align_val_t, __builtin_vec_delete_aligned ); #endif #elif defined(VGO_darwin) #elif defined(VGO_solaris) // operator delete[](void*, std::align_val_t), GNU mangling - FREE(VG_Z_LIBSTDCXX_SONAME, _ZdaPvSt11align_val_t, __builtin_vec_delete_aligned ); - FREE(SO_SYN_MALLOC, _ZdaPvSt11align_val_t, __builtin_vec_delete_aligned ); + DELETE_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvSt11align_val_t, __builtin_vec_delete_aligned ); + DELETE_ALIGNED(SO_SYN_MALLOC, _ZdaPvSt11align_val_t, __builtin_vec_delete_aligned ); // operator delete[](void*, unsigned int, std::align_val_t) #if __SIZEOF_SIZE_T__ == 4 - FREE(VG_Z_LIBSTDCXX_SONAME, _ZdaPvjSt11align_val_t, __builtin_vec_delete_aligned ); - FREE(SO_SYN_MALLOC, _ZdaPvjSt11align_val_t, __builtin_vec_delete_aligned ); + DELETE_SIZED_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvjSt11align_val_t, __builtin_vec_delete_aligned ); + DELETE_SIZED_ALIGNED(SO_SYN_MALLOC, _ZdaPvjSt11align_val_t, __builtin_vec_delete_aligned ); // operator delete[](void*, unsigned long), GNU mangling #elif __SIZEOF_SIZE_T__ == 8 - FREE(VG_Z_LIBSTDCXX_SONAME, _ZdaPvmSt11align_val_t, __builtin_vec_delete_aligned ); - FREE(SO_SYN_MALLOC, _ZdaPvmSt11align_val_t, __builtin_vec_delete_aligned ); + DELETE_SIZED_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvmSt11align_val_t, __builtin_vec_delete_aligned ); + DELETE_SIZED_ALIGNED(SO_SYN_MALLOC, _ZdaPvmSt11align_val_t, __builtin_vec_delete_aligned ); #endif #endif @@ -1266,25 +1306,25 @@ extern int *___errno (void) __attribute__((weak)); #if defined(VGO_linux) // operator delete[](void*, std::align_val_t, std::nothrow_t const&), GNU mangling - FREE(VG_Z_LIBSTDCXX_SONAME, _ZdaPvSt11align_val_tRKSt9nothrow_t, __builtin_vec_delete_aligned ); - FREE(VG_Z_LIBCXX_SONAME, _ZdaPvSt11align_val_tRKSt9nothrow_t, __builtin_vec_delete_aligned ); - FREE(VG_Z_LIBC_SONAME, _ZdaPvSt11align_val_tRKSt9nothrow_t, __builtin_vec_delete_aligned ); - FREE(SO_SYN_MALLOC, _ZdaPvSt11align_val_tRKSt9nothrow_t, __builtin_vec_delete_aligned ); + DELETE_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvSt11align_val_tRKSt9nothrow_t, __builtin_vec_delete_aligned ); + DELETE_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdaPvSt11align_val_tRKSt9nothrow_t, __builtin_vec_delete_aligned ); + DELETE_ALIGNED(VG_Z_LIBC_SONAME, _ZdaPvSt11align_val_tRKSt9nothrow_t, __builtin_vec_delete_aligned ); + DELETE_ALIGNED(SO_SYN_MALLOC, _ZdaPvSt11align_val_tRKSt9nothrow_t, __builtin_vec_delete_aligned ); // no sized version of this operator #elif defined(VGO_freebsd) // operator delete[](void*, std::align_val_t, std::nothrow_t const&), GNU mangling - FREE(VG_Z_LIBSTDCXX_SONAME, _ZdaPvSt11align_val_tRKSt9nothrow_t, __builtin_vec_delete_aligned ); - FREE(VG_Z_LIBCXX_SONAME, _ZdaPvSt11align_val_tRKSt9nothrow_t, __builtin_vec_delete_aligned ); - FREE(SO_SYN_MALLOC, _ZdaPvSt11align_val_tRKSt9nothrow_t, __builtin_vec_delete_aligned ); + DELETE_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvSt11align_val_tRKSt9nothrow_t, __builtin_vec_delete_aligned ); + DELETE_ALIGNED(VG_Z_LIBCXX_SONAME, _ZdaPvSt11align_val_tRKSt9nothrow_t, __builtin_vec_delete_aligned ); + DELETE_ALIGNED(SO_SYN_MALLOC, _ZdaPvSt11align_val_tRKSt9nothrow_t, __builtin_vec_delete_aligned ); #elif defined(VGO_darwin) #elif defined(VGO_solaris) // operator delete[](void*, std::align_val_t, std::nothrow_t const&), GNU mangling - FREE(VG_Z_LIBSTDCXX_SONAME, _ZdaPvSt11align_val_tRKSt9nothrow_t, __builtin_vec_delete_aligned ); - FREE(SO_SYN_MALLOC, _ZdaPvSt11align_val_tRKSt9nothrow_t, __builtin_vec_delete_aligned ); + DELETE_ALIGNED(VG_Z_LIBSTDCXX_SONAME, _ZdaPvSt11align_val_tRKSt9nothrow_t, __builtin_vec_delete_aligned ); + DELETE_ALIGNED(SO_SYN_MALLOC, _ZdaPvSt11align_val_tRKSt9nothrow_t, __builtin_vec_delete_aligned ); // no sized version of this operator diff --git a/memcheck/tests/Makefile.am b/memcheck/tests/Makefile.am index 6c1c20185a..dc0f39aa65 100644 --- a/memcheck/tests/Makefile.am +++ b/memcheck/tests/Makefile.am @@ -139,6 +139,8 @@ EXTRA_DIST = \ cxx17_aligned_new.stderr.exp cxx17_aligned_new.vgtest \ cxx17_aligned_new.stderr.exp_32 \ cxx17_aligned_new.stdout.exp \ + sized_aligned_new_delete_args.stderr.exp \ + sized_aligned_new_delete_args.vgtest \ deep-backtrace.vgtest deep-backtrace.stderr.exp \ demangle.stderr.exp demangle.vgtest \ big_debuginfo_symbol.stderr.exp big_debuginfo_symbol.vgtest \ @@ -485,7 +487,7 @@ cdebug_zlib_gnu_CFLAGS = $(AM_CFLAGS) -g -gz=zlib-gnu @FLAG_W_NO_UNINITIALIZED@ endif if HAVE_ALIGNED_CXX_ALLOC -check_PROGRAMS += cxx17_aligned_new +check_PROGRAMS += cxx17_aligned_new sized_aligned_new_delete_args endif if HAVE_PTHREAD_BARRIER @@ -546,6 +548,8 @@ bug340392_CFLAGS = $(AM_CFLAGS) -O3 @FLAG_W_NO_MAYBE_UNINITIALIZED@ if HAVE_ALIGNED_CXX_ALLOC cxx17_aligned_new_SOURCES = cxx17_aligned_new.cpp cxx17_aligned_new_CXXFLAGS = -std=c++17 @FLAG_W_NO_MISMATCHED_NEW_DELETE@ +sized_aligned_new_delete_args_SOURCES = sized_aligned_new_delete_args.cpp +sized_aligned_new_delete_args_CXXFLAGS = -std=c++17 endif demangle_SOURCES = demangle.cpp diff --git a/memcheck/tests/sized_aligned_new_delete_args.cpp b/memcheck/tests/sized_aligned_new_delete_args.cpp new file mode 100644 index 0000000000..a8d5024ac5 --- /dev/null +++ b/memcheck/tests/sized_aligned_new_delete_args.cpp @@ -0,0 +1,42 @@ +#include +#include +#include +#include "../memcheck.h" + +int main() { + std::align_val_t align(static_cast(64U)); + std::align_val_t uninitalign(static_cast(64U)); + size_t uninitsize(16); + size_t size(16); + std::nothrow_t tag; + void *mem; + VALGRIND_MAKE_MEM_UNDEFINED(&uninitsize, sizeof(uninitsize)); + VALGRIND_MAKE_MEM_UNDEFINED(&uninitalign, sizeof(uninitalign)); + + mem = operator new(uninitsize, uninitalign); + operator delete(mem, uninitalign); + + mem = operator new[](uninitsize, uninitalign); + operator delete[](mem, uninitalign); + + // doesn't matter that tag is uninit + // don't want to see an error + mem = operator new(uninitsize, uninitalign, tag); + operator delete(mem, uninitalign, tag); + + mem = operator new[](uninitsize, uninitalign, tag); + operator delete[](mem, uninitalign, tag); + + mem = operator new(size); + operator delete(mem, uninitsize); + + mem = operator new[](size); + operator delete[](mem, uninitsize); + + mem = operator new(size, align); + operator delete(mem, uninitsize, uninitalign); + + mem = operator new[](size, align); + operator delete[](mem, uninitsize, uninitalign); +} + diff --git a/memcheck/tests/sized_aligned_new_delete_args.stderr.exp b/memcheck/tests/sized_aligned_new_delete_args.stderr.exp new file mode 100644 index 0000000000..c086f1d266 --- /dev/null +++ b/memcheck/tests/sized_aligned_new_delete_args.stderr.exp @@ -0,0 +1,83 @@ + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator new(unsigned long, std::align_val_t) (vg_replace_malloc.c:...) + by 0x........: main (in /usr/home/paulf/scratch/valgrind/memcheck/tests/sized_aligned_new_delete_args) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator new(unsigned long, std::align_val_t) (vg_replace_malloc.c:...) + by 0x........: main (in /usr/home/paulf/scratch/valgrind/memcheck/tests/sized_aligned_new_delete_args) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator delete(void*, std::align_val_t) (vg_replace_malloc.c:...) + by 0x........: main (in /usr/home/paulf/scratch/valgrind/memcheck/tests/sized_aligned_new_delete_args) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator new[](unsigned long, std::align_val_t) (vg_replace_malloc.c:...) + by 0x........: main (in /usr/home/paulf/scratch/valgrind/memcheck/tests/sized_aligned_new_delete_args) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator new[](unsigned long, std::align_val_t) (vg_replace_malloc.c:...) + by 0x........: main (in /usr/home/paulf/scratch/valgrind/memcheck/tests/sized_aligned_new_delete_args) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator delete[](void*, std::align_val_t) (vg_replace_malloc.c:...) + by 0x........: main (in /usr/home/paulf/scratch/valgrind/memcheck/tests/sized_aligned_new_delete_args) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator new(unsigned long, std::align_val_t, std::nothrow_t const&) (vg_replace_malloc.c:...) + by 0x........: main (in /usr/home/paulf/scratch/valgrind/memcheck/tests/sized_aligned_new_delete_args) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator new(unsigned long, std::align_val_t, std::nothrow_t const&) (vg_replace_malloc.c:...) + by 0x........: main (in /usr/home/paulf/scratch/valgrind/memcheck/tests/sized_aligned_new_delete_args) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator delete(void*, std::align_val_t, std::nothrow_t const&) (vg_replace_malloc.c:...) + by 0x........: main (in /usr/home/paulf/scratch/valgrind/memcheck/tests/sized_aligned_new_delete_args) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator new[](unsigned long, std::align_val_t, std::nothrow_t const&) (vg_replace_malloc.c:...) + by 0x........: main (in /usr/home/paulf/scratch/valgrind/memcheck/tests/sized_aligned_new_delete_args) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator new[](unsigned long, std::align_val_t, std::nothrow_t const&) (vg_replace_malloc.c:...) + by 0x........: main (in /usr/home/paulf/scratch/valgrind/memcheck/tests/sized_aligned_new_delete_args) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator delete[](void*, std::align_val_t, std::nothrow_t const&) (vg_replace_malloc.c:...) + by 0x........: main (in /usr/home/paulf/scratch/valgrind/memcheck/tests/sized_aligned_new_delete_args) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: ...operator delete... (vg_replace_malloc.c:...) + by 0x........: main (in /usr/home/paulf/scratch/valgrind/memcheck/tests/sized_aligned_new_delete_args) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator delete[](void*, unsigned long) (vg_replace_malloc.c:...) + by 0x........: main (in /usr/home/paulf/scratch/valgrind/memcheck/tests/sized_aligned_new_delete_args) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator delete(void*, unsigned long, std::align_val_t) (vg_replace_malloc.c:...) + by 0x........: main (in /usr/home/paulf/scratch/valgrind/memcheck/tests/sized_aligned_new_delete_args) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator delete(void*, unsigned long, std::align_val_t) (vg_replace_malloc.c:...) + by 0x........: main (in /usr/home/paulf/scratch/valgrind/memcheck/tests/sized_aligned_new_delete_args) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator delete[](void*, unsigned long, std::align_val_t) (vg_replace_malloc.c:...) + by 0x........: main (in /usr/home/paulf/scratch/valgrind/memcheck/tests/sized_aligned_new_delete_args) + +Conditional jump or move depends on uninitialised value(s) + at 0x........: operator delete[](void*, unsigned long, std::align_val_t) (vg_replace_malloc.c:...) + by 0x........: main (in /usr/home/paulf/scratch/valgrind/memcheck/tests/sized_aligned_new_delete_args) + + +HEAP SUMMARY: + in use at exit: 0 bytes in 0 blocks + total heap usage: 8 allocs, 8 frees, 128 bytes allocated + +For a detailed leak analysis, rerun with: --leak-check=full + +Use --track-origins=yes to see where uninitialised values come from +For lists of detected and suppressed errors, rerun with: -s +ERROR SUMMARY: 18 errors from 18 contexts (suppressed: 0 from 0) diff --git a/memcheck/tests/sized_aligned_new_delete_args.vgtest b/memcheck/tests/sized_aligned_new_delete_args.vgtest new file mode 100644 index 0000000000..8df8db4df2 --- /dev/null +++ b/memcheck/tests/sized_aligned_new_delete_args.vgtest @@ -0,0 +1,2 @@ +prog: sized_aligned_new_delete_args +prereq: test -e ./sized_aligned_new_delete_args