Skip to content

Commit 7d76c97

Browse files
committed
Merge bitcoin#31766: leveldb: pull upstream C++23 changes
c8fab35 ci: remove -Wno-error=deprecated-declarations from ASAN (fanquake) a130bbd Squashed 'src/leveldb/' changes from 04b5790928..4188247086 (fanquake) Pull request description: Cherry-picks two commits from upstream (google/leveldb@302786e, google/leveldb@e829478), which remove the usage of `std::aligned_storage/std::aligned_union`. Note the first cherry-pick is not clean, because due to Google tooling issues, it accidently contained a revert of the prior two commits. See google/leveldb#1249 for more details. Also see https://issues.chromium.org/issues/388068052, although note that they [reverted the roll to latest leveldb](https://issues.chromium.org/issues/388068052#comment9). I'm guessing due to the acidental reversion issue above. ACKs for top commit: l0rinc: ACK c8fab35 darosior: ACK c8fab35 -- checked it's a clean subtree pull from https://github.com/bitcoin-core/leveldb-subtree/tree/bitcoin-fork dergoegge: utACK c8fab35 Tree-SHA512: 966e61b9ac88af5ae7bf71514bfd5bbdbd8c38c7af65feb6d5e4415062dcff5896dc33fe968ded3462cc599abd921d49ee8336db3e12ed3f59c91ceb949317b7
2 parents 780bcf8 + c8fab35 commit 7d76c97

File tree

4 files changed

+23
-13
lines changed

4 files changed

+23
-13
lines changed

ci/test/00_setup_env_native_asan.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export BITCOIN_CONFIG="\
2929
-DCMAKE_C_COMPILER=clang-${APT_LLVM_V} \
3030
-DCMAKE_CXX_COMPILER=clang++-${APT_LLVM_V} \
3131
-DCMAKE_C_FLAGS='-ftrivial-auto-var-init=pattern' \
32-
-DCMAKE_CXX_FLAGS='-ftrivial-auto-var-init=pattern -Wno-error=deprecated-declarations' \
32+
-DCMAKE_CXX_FLAGS='-ftrivial-auto-var-init=pattern' \
3333
-DAPPEND_CXXFLAGS='-std=c++23' \
3434
-DAPPEND_CPPFLAGS='-DARENA_DEBUG -DDEBUG_LOCKORDER' \
3535
"

src/leveldb/util/env_posix.cc

+7-4
Original file line numberDiff line numberDiff line change
@@ -854,9 +854,13 @@ class SingletonEnv {
854854
#endif // !defined(NDEBUG)
855855
static_assert(sizeof(env_storage_) >= sizeof(EnvType),
856856
"env_storage_ will not fit the Env");
857-
static_assert(alignof(decltype(env_storage_)) >= alignof(EnvType),
857+
static_assert(std::is_standard_layout_v<SingletonEnv<EnvType>>);
858+
static_assert(
859+
offsetof(SingletonEnv<EnvType>, env_storage_) % alignof(EnvType) == 0,
860+
"env_storage_ does not meet the Env's alignment needs");
861+
static_assert(alignof(SingletonEnv<EnvType>) % alignof(EnvType) == 0,
858862
"env_storage_ does not meet the Env's alignment needs");
859-
new (&env_storage_) EnvType();
863+
new (env_storage_) EnvType();
860864
}
861865
~SingletonEnv() = default;
862866

@@ -872,8 +876,7 @@ class SingletonEnv {
872876
}
873877

874878
private:
875-
typename std::aligned_storage<sizeof(EnvType), alignof(EnvType)>::type
876-
env_storage_;
879+
alignas(EnvType) char env_storage_[sizeof(EnvType)];
877880
#if !defined(NDEBUG)
878881
static std::atomic<bool> env_initialized_;
879882
#endif // !defined(NDEBUG)

src/leveldb/util/env_windows.cc

+7-4
Original file line numberDiff line numberDiff line change
@@ -802,9 +802,13 @@ class SingletonEnv {
802802
#endif // !defined(NDEBUG)
803803
static_assert(sizeof(env_storage_) >= sizeof(EnvType),
804804
"env_storage_ will not fit the Env");
805-
static_assert(alignof(decltype(env_storage_)) >= alignof(EnvType),
805+
static_assert(std::is_standard_layout_v<SingletonEnv<EnvType>>);
806+
static_assert(
807+
offsetof(SingletonEnv<EnvType>, env_storage_) % alignof(EnvType) == 0,
808+
"env_storage_ does not meet the Env's alignment needs");
809+
static_assert(alignof(SingletonEnv<EnvType>) % alignof(EnvType) == 0,
806810
"env_storage_ does not meet the Env's alignment needs");
807-
new (&env_storage_) EnvType();
811+
new (env_storage_) EnvType();
808812
}
809813
~SingletonEnv() = default;
810814

@@ -820,8 +824,7 @@ class SingletonEnv {
820824
}
821825

822826
private:
823-
typename std::aligned_storage<sizeof(EnvType), alignof(EnvType)>::type
824-
env_storage_;
827+
alignas(EnvType) char env_storage_[sizeof(EnvType)];
825828
#if !defined(NDEBUG)
826829
static std::atomic<bool> env_initialized_;
827830
#endif // !defined(NDEBUG)

src/leveldb/util/no_destructor.h

+8-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#ifndef STORAGE_LEVELDB_UTIL_NO_DESTRUCTOR_H_
66
#define STORAGE_LEVELDB_UTIL_NO_DESTRUCTOR_H_
77

8+
#include <cstddef>
89
#include <type_traits>
910
#include <utility>
1011

@@ -20,10 +21,14 @@ class NoDestructor {
2021
explicit NoDestructor(ConstructorArgTypes&&... constructor_args) {
2122
static_assert(sizeof(instance_storage_) >= sizeof(InstanceType),
2223
"instance_storage_ is not large enough to hold the instance");
24+
static_assert(std::is_standard_layout_v<NoDestructor<InstanceType>>);
2325
static_assert(
24-
alignof(decltype(instance_storage_)) >= alignof(InstanceType),
26+
offsetof(NoDestructor, instance_storage_) % alignof(InstanceType) == 0,
2527
"instance_storage_ does not meet the instance's alignment requirement");
26-
new (&instance_storage_)
28+
static_assert(
29+
alignof(NoDestructor<InstanceType>) % alignof(InstanceType) == 0,
30+
"instance_storage_ does not meet the instance's alignment requirement");
31+
new (instance_storage_)
2732
InstanceType(std::forward<ConstructorArgTypes>(constructor_args)...);
2833
}
2934

@@ -37,8 +42,7 @@ class NoDestructor {
3742
}
3843

3944
private:
40-
typename std::aligned_storage<sizeof(InstanceType),
41-
alignof(InstanceType)>::type instance_storage_;
45+
alignas(InstanceType) char instance_storage_[sizeof(InstanceType)];
4246
};
4347

4448
} // namespace leveldb

0 commit comments

Comments
 (0)