From 3b71196fcaf2c9677bcec761397e5c5315e28b76 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Thu, 30 Jan 2025 10:23:05 -0500 Subject: [PATCH 1/6] Remove standard includes. --- src/chain/block.cpp | 1 - src/chain/point.cpp | 1 - src/chain/script.cpp | 1 - src/chain/transaction.cpp | 1 - 4 files changed, 4 deletions(-) diff --git a/src/chain/block.cpp b/src/chain/block.cpp index 31c05c7f5a..0a750b596f 100644 --- a/src/chain/block.cpp +++ b/src/chain/block.cpp @@ -20,7 +20,6 @@ #include #include -#include #include #include #include diff --git a/src/chain/point.cpp b/src/chain/point.cpp index 05fa87f309..9d9c29dbcf 100644 --- a/src/chain/point.cpp +++ b/src/chain/point.cpp @@ -18,7 +18,6 @@ */ #include -#include #include #include #include diff --git a/src/chain/script.cpp b/src/chain/script.cpp index b0384cdad8..bc06d44521 100644 --- a/src/chain/script.cpp +++ b/src/chain/script.cpp @@ -20,7 +20,6 @@ #include #include -#include #include #include #include diff --git a/src/chain/transaction.cpp b/src/chain/transaction.cpp index f90f6ad928..7a6da3ac44 100644 --- a/src/chain/transaction.cpp +++ b/src/chain/transaction.cpp @@ -20,7 +20,6 @@ #include #include -#include #include #include #include From b9b6a638b284b70c43ffe21e8c5994c5a4c8b7c3 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Thu, 30 Jan 2025 10:32:08 -0500 Subject: [PATCH 2/6] Update clang comments. --- include/bitcoin/system/have.hpp | 3 --- include/bitcoin/system/literals.hpp | 2 +- test/allocator.cpp | 4 ---- 3 files changed, 1 insertion(+), 8 deletions(-) diff --git a/include/bitcoin/system/have.hpp b/include/bitcoin/system/have.hpp index 31ed4f9758..5bb5011d6b 100644 --- a/include/bitcoin/system/have.hpp +++ b/include/bitcoin/system/have.hpp @@ -204,9 +204,6 @@ #endif #endif -/// C++20: parenthesized initialization of aggregates requires clang16/xcode16. -/// We don't have macro treatment for that, just ad-hoc HAVE_CLANG conditions. - /// None on xcode. /// Requires link with -ltbb on gcc (v9). /// Experimental on clang (libcxx.llvm.org/Status/PSTL.html), requires: diff --git a/include/bitcoin/system/literals.hpp b/include/bitcoin/system/literals.hpp index d94fd83197..60560fe888 100644 --- a/include/bitcoin/system/literals.hpp +++ b/include/bitcoin/system/literals.hpp @@ -35,7 +35,7 @@ namespace libbitcoin { /// not be subject to regressions in other code, as a break here causes a large /// number of test and other failures. See tests for usage and detailed info. /// --------------------------------------------------------------------------- -/// These should be consteval for safety, but waiting on clang++20 to catch up. +/// These should be consteval for safety, but waiting on clang++ v17. // Functions are consteval where available (bogus warning). BC_PUSH_WARNING(USE_CONSTEXPR_FOR_FUNCTION) diff --git a/test/allocator.cpp b/test/allocator.cpp index 88f0ff1f62..5ade65cc17 100644 --- a/test/allocator.cpp +++ b/test/allocator.cpp @@ -26,10 +26,6 @@ BC_PUSH_WARNING(NO_UNGUARDED_POINTERS) BC_PUSH_WARNING(NO_DELETE_RAW_POINTER) BC_PUSH_WARNING(NO_UNCLEARED_OWNER_POINTER) -// Clang is not yet C++20 compliant in terms of aggregate initialization. -// See [reviews.llvm.org/D140327] for details. So vectors provide constructors. -/////////////////////////////////////////////////////////////////////////////// - struct simple { simple(size_t arg={}) NOEXCEPT From 569fa0962d738ffdb24a8655c3c8231d3a78cc4d Mon Sep 17 00:00:00 2001 From: evoskuil Date: Thu, 30 Jan 2025 20:49:13 -0500 Subject: [PATCH 3/6] Comments. --- include/bitcoin/system/have.hpp | 6 +++--- include/bitcoin/system/intrinsics/haves.hpp | 1 - 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/include/bitcoin/system/have.hpp b/include/bitcoin/system/have.hpp index 5bb5011d6b..ac4eccd62c 100644 --- a/include/bitcoin/system/have.hpp +++ b/include/bitcoin/system/have.hpp @@ -128,10 +128,10 @@ #define HAVE_ICU #endif -/// XCPU architecture intrinsics sse41, avx2, avx512f, sha-ni. +/// XCPU architecture intrinsics sse41, avx2, avx512f/bw, sha-ni. /// This assumes that avx512 implies avx2 and that all imply sse41. #if defined(HAVE_XCPU) - // TODO: CLANG/GCC compile test and set -msse4 -mavx2 -mavx512f -msha. + // CLANG/GCC compile with -msse4 -mavx2 -mavx512f/-mavx512bw -msha. #if defined(WITH_SHANI) #define HAVE_SHANI #endif @@ -224,7 +224,7 @@ #define HAVE_SUPPRESSION /// Disable noexcept to capture stack trace. -#define HAVE_NOEXCEPT +////#define HAVE_NOEXCEPT /// Disable to emit all suppressed warnings. #define HAVE_WARNINGS diff --git a/include/bitcoin/system/intrinsics/haves.hpp b/include/bitcoin/system/intrinsics/haves.hpp index 282c84f5e8..3e206dc5db 100644 --- a/include/bitcoin/system/intrinsics/haves.hpp +++ b/include/bitcoin/system/intrinsics/haves.hpp @@ -74,7 +74,6 @@ namespace cpu1_0 constexpr auto avx_ecx_bit = 28; } -// wikichip.org/wiki/x86/avx-512 namespace cpu7_0 { constexpr auto leaf = 7; From 5a28ad0accbf849393b23a9ce4ab0a30169b79ca Mon Sep 17 00:00:00 2001 From: evoskuil Date: Fri, 31 Jan 2025 01:33:45 -0500 Subject: [PATCH 4/6] Regenerate artifacts (sets _CRTDBG_MAP_ALLOC). --- builds/msvc/vs2022/libbitcoin-system.import.props | 3 +-- builds/msvc/vs2022/libbitcoin-system/libbitcoin-system.props | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/builds/msvc/vs2022/libbitcoin-system.import.props b/builds/msvc/vs2022/libbitcoin-system.import.props index 390dc00393..bb11eeb347 100644 --- a/builds/msvc/vs2022/libbitcoin-system.import.props +++ b/builds/msvc/vs2022/libbitcoin-system.import.props @@ -51,8 +51,7 @@ WITH_ICU;WIN32_LEAN_AND_MEAN;NOMINMAX;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions) BC_STATIC;%(PreprocessorDefinitions) - - + _CRTDBG_MAP_ALLOC;%(PreprocessorDefinitions) WITH_AVX512;%(PreprocessorDefinitions) WITH_AVX2;%(PreprocessorDefinitions) diff --git a/builds/msvc/vs2022/libbitcoin-system/libbitcoin-system.props b/builds/msvc/vs2022/libbitcoin-system/libbitcoin-system.props index 3bf5c75a6e..bc258cc4e9 100644 --- a/builds/msvc/vs2022/libbitcoin-system/libbitcoin-system.props +++ b/builds/msvc/vs2022/libbitcoin-system/libbitcoin-system.props @@ -25,6 +25,7 @@ WITH_ICU;WIN32_LEAN_AND_MEAN;NOMINMAX;_WIN32_WINNT=0x0600;%(PreprocessorDefinitions) BC_DLL;%(PreprocessorDefinitions) BC_STATIC;%(PreprocessorDefinitions) + _CRTDBG_MAP_ALLOC;%(PreprocessorDefinitions) WITH_AVX512;%(PreprocessorDefinitions) WITH_AVX2;%(PreprocessorDefinitions) From 20b9d2245f7c455154282eb3d32714caa6f201a8 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Fri, 31 Jan 2025 01:37:17 -0500 Subject: [PATCH 5/6] Set _CRTDBG_MAP_ALLOC for vc++ debug mode leak tracking. --- include/bitcoin/system/preprocessor.hpp | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/include/bitcoin/system/preprocessor.hpp b/include/bitcoin/system/preprocessor.hpp index f3808b8bca..ccade62d24 100644 --- a/include/bitcoin/system/preprocessor.hpp +++ b/include/bitcoin/system/preprocessor.hpp @@ -32,6 +32,22 @@ /// Debugging. /// --------------------------------------------------------------------------- +/// Enables ETW tracing for VS memory profiler. +#if defined(HAVE_MSC) + #define ALLOCATOR __declspec(allocator) +#else + #define ALLOCATOR +#endif + +/// learn.microsoft.com/en-us/cpp/c-runtime-library/ +/// find-memory-leaks-using-the-crt-library +/// _CRTDBG_MAP_ALLOC must be prior to the includes, so defined in props. +#if defined(HAVE_MSC) && defined(_DEBUG) && defined(_CRTDBG_MAP_ALLOC) + #include + #include + ////_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF); +#endif + /// NDEBUG (conditional exclusion). #if defined(NDEBUG) #define BC_ASSERT(expression) @@ -44,13 +60,6 @@ #define BC_DEBUG_ONLY(expression) expression #endif -/// Enables ETW tracing for VS memory profiler. -#if defined(HAVE_MSC) - #define ALLOCATOR __declspec(allocator) -#else - #define ALLOCATOR -#endif - /// Messages. /// --------------------------------------------------------------------------- From 2aaa37582db46a2fe4027523fd99677af578cb33 Mon Sep 17 00:00:00 2001 From: evoskuil Date: Fri, 31 Jan 2025 01:37:35 -0500 Subject: [PATCH 6/6] Use malloc/free in default arena for leak tracking. --- src/arena.cpp | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/arena.cpp b/src/arena.cpp index 936b868fe2..1ea64cf81f 100644 --- a/src/arena.cpp +++ b/src/arena.cpp @@ -18,12 +18,11 @@ */ #include +#include #include namespace libbitcoin { -BC_PUSH_WARNING(NO_NEW_OR_DELETE) - bool operator==(const arena& left, const arena& right) NOEXCEPT { return &left == &right || left.is_equal(right); @@ -41,14 +40,18 @@ void* default_arena::do_allocate(size_t bytes, size_t) THROWS { ////if (align > __STDCPP_DEFAULT_NEW_ALIGNMENT__) //// return ::operator new(bytes, std::align_val_t{ align }); - return ::operator new(bytes); + BC_PUSH_WARNING(NO_MALLOC_OR_FREE) + return std::malloc(bytes); + BC_POP_WARNING() } void default_arena::do_deallocate(void* ptr, size_t, size_t) NOEXCEPT { ////if (align > __STDCPP_DEFAULT_NEW_ALIGNMENT__) //// ::operator delete(ptr, std::align_val_t{ align }); - ::operator delete(ptr); + BC_PUSH_WARNING(NO_MALLOC_OR_FREE) + std::free(ptr); + BC_POP_WARNING() } bool default_arena::do_is_equal(const arena& other) const NOEXCEPT @@ -57,6 +60,7 @@ bool default_arena::do_is_equal(const arena& other) const NOEXCEPT return &other == this; } +// null return indicates that this arena is not detachable. void* default_arena::start(size_t) THROWS { return nullptr; @@ -71,6 +75,4 @@ void default_arena::release(void*) NOEXCEPT { } -BC_POP_WARNING() - } // namespace libbitcoin