File tree Expand file tree Collapse file tree 4 files changed +19
-1
lines changed
Expand file tree Collapse file tree 4 files changed +19
-1
lines changed Original file line number Diff line number Diff line change @@ -429,6 +429,7 @@ cc_test(
429429 deps = [
430430 ":container_memory" ,
431431 ":test_instance_tracker" ,
432+ "//absl/base:config" ,
432433 "//absl/base:no_destructor" ,
433434 "//absl/meta:type_traits" ,
434435 "//absl/strings" ,
Original file line number Diff line number Diff line change @@ -484,6 +484,7 @@ absl_cc_test(
484484 COPTS
485485 ${ABSL_TEST_COPTS}
486486 DEPS
487+ absl::config
487488 absl::container_memory
488489 absl::no_destructor
489490 absl::strings
Original file line number Diff line number Diff line change @@ -44,7 +44,12 @@ ABSL_NAMESPACE_BEGIN
4444namespace container_internal {
4545
4646template <size_t Alignment>
47- struct alignas (Alignment) AlignedType {};
47+ struct alignas (Alignment) AlignedType {
48+ // When alignment is sufficient for the allocated memory to store pointers,
49+ // include a pointer member so that swisstable backing arrays end up in the
50+ // pointer-containing partition for heap partitioning.
51+ std::conditional_t <(Alignment < alignof (void *)), char , void *> pointer;
52+ };
4853
4954// Allocates at least n bytes aligned to the specified alignment.
5055// Alignment must be a power of 2. It must be positive.
Original file line number Diff line number Diff line change 2525
2626#include " gmock/gmock.h"
2727#include " gtest/gtest.h"
28+ #include " absl/base/config.h"
2829#include " absl/base/no_destructor.h"
2930#include " absl/container/internal/test_instance_tracker.h"
3031#include " absl/meta/type_traits.h"
@@ -42,6 +43,16 @@ using ::testing::ElementsAre;
4243using ::testing::Gt;
4344using ::testing::Pair;
4445
46+ #if ABSL_HAVE_BUILTIN(__builtin_infer_alloc_token)
47+ TEST (Memory, AlignedTypeAllocToken) {
48+ #if defined(__wasm__)
49+ GTEST_SKIP () << " Fails on wasm due to lack of heap partitioning support." ;
50+ #endif
51+ EXPECT_GT (__builtin_infer_alloc_token (sizeof (AlignedType<alignof (void *)>)),
52+ __builtin_infer_alloc_token (sizeof (int )));
53+ }
54+ #endif
55+
4556TEST (Memory, AlignmentLargerThanBase) {
4657 std::allocator<int8_t > alloc;
4758 void * mem = Allocate<2 >(&alloc, 3 );
You can’t perform that action at this time.
0 commit comments