From 6d138906ec1dfc697d493e2c6a1147301240922a Mon Sep 17 00:00:00 2001 From: Antonio SJ Musumeci Date: Sat, 14 Nov 2026 18:19:46 -0600 Subject: [PATCH] Fix ARMv5 atomic loads from Boost dummy storage --- DEPENDENCIES | 3 +++ tests/tests.cpp | 11 +++++++++++ vendored/boost/unordered/detail/foa/core.hpp | 7 ++++--- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/DEPENDENCIES b/DEPENDENCIES index 7f398e64..e3fcbb4d 100644 --- a/DEPENDENCIES +++ b/DEPENDENCIES @@ -15,3 +15,6 @@ * ./bootstrap.sh * ./b2 tools/bcp * ./dist/bin/bcp unordered/concurrent_flat_map.hpp + * local patch: keep unordered dummy-group storage writable with C++20 + `constinit`; ARMv5 atomic loads can write back to memory (#1695). + Preserve this change when updating Boost. diff --git a/tests/tests.cpp b/tests/tests.cpp index 7793fbad..de7fdf67 100644 --- a/tests/tests.cpp +++ b/tests/tests.cpp @@ -16,6 +16,7 @@ #include "str.hpp" #include "thread_pool.hpp" +#include #include #include #include @@ -57,6 +58,15 @@ test_nop() TEST_CHECK(true); } +void +test_boost_concurrent_flat_map_empty_lookup() +{ + boost::concurrent_flat_map map; + + // An unallocated map uses dummy metadata; atomic reads must be safe on ARMv5. + TEST_CHECK(map.count(42) == 0); +} + void test_config_bool() { @@ -4244,6 +4254,7 @@ test_clonepath_modes() TEST_LIST = { {"nop",test_nop}, + {"boost_concurrent_flat_map_empty_lookup",test_boost_concurrent_flat_map_empty_lookup}, {"config_bool",test_config_bool}, {"config_uint64",test_config_uint64}, {"config_int",test_config_int}, diff --git a/vendored/boost/unordered/detail/foa/core.hpp b/vendored/boost/unordered/detail/foa/core.hpp index 38d50e68..0224c8b4 100644 --- a/vendored/boost/unordered/detail/foa/core.hpp +++ b/vendored/boost/unordered/detail/foa/core.hpp @@ -949,13 +949,14 @@ Group* dummy_groups() * we are not allocating any dynamic memory and yet lookup can be implemented * without checking for groups==nullptr. This space won't ever be used for * insertion as the container's capacity is precisely zero. + * Keep the storage writable: atomic loads on ARMv5 can write back through + * compare-and-swap. constinit preserves static initialization without const. */ - static constexpr typename Group::dummy_group_type + static constinit typename Group::dummy_group_type storage[Size]={typename Group::dummy_group_type(),}; - return reinterpret_cast( - const_cast(storage)); + return reinterpret_cast(storage); } template<