Skip to content

Commit 54fc9fd

Browse files
chelcassanovaarsenm
authored andcommitted
Revert "[ADT] Always use 32-bit size type for SmallVector with 16-bit elements" (#96826)
Reverts #95536, this is breaking macOS GreenDragon buildbots on arm64 and x86_64 https://green.lab.llvm.org/job/llvm.org/view/LLDB/job/as-lldb-cmake/6522/console, also breaks the Darwin LLVM buildbots: https://lab.llvm.org/buildbot/#/builders/23/builds/398
1 parent 9de9168 commit 54fc9fd

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

llvm/include/llvm/ADT/SmallVector.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ template <class Size_T> class SmallVectorBase {
116116

117117
template <class T>
118118
using SmallVectorSizeType =
119-
std::conditional_t<sizeof(T) == 1, size_t, uint32_t>;
119+
std::conditional_t<sizeof(T) < 4 && sizeof(void *) >= 8, uint64_t,
120+
uint32_t>;
120121

121122
/// Figure out the offset of the first element.
122123
template <class T, typename = void> struct SmallVectorAlignmentAndSize {

llvm/lib/Support/SmallVector.cpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@ struct Struct32B {
3737
#pragma GCC diagnostic pop
3838
#endif
3939
}
40-
40+
static_assert(sizeof(SmallVector<void *, 0>) ==
41+
sizeof(unsigned) * 2 + sizeof(void *),
42+
"wasted space in SmallVector size 0");
4143
static_assert(alignof(SmallVector<Struct16B, 0>) >= alignof(Struct16B),
4244
"wrong alignment for 16-byte aligned T");
4345
static_assert(alignof(SmallVector<Struct32B, 0>) >= alignof(Struct32B),
@@ -46,19 +48,13 @@ static_assert(sizeof(SmallVector<Struct16B, 0>) >= alignof(Struct16B),
4648
"missing padding for 16-byte aligned T");
4749
static_assert(sizeof(SmallVector<Struct32B, 0>) >= alignof(Struct32B),
4850
"missing padding for 32-byte aligned T");
49-
50-
static_assert(sizeof(SmallVector<void *, 0>) ==
51-
sizeof(unsigned) * 2 + sizeof(void *),
52-
"wasted space in SmallVector size 0");
5351
static_assert(sizeof(SmallVector<void *, 1>) ==
5452
sizeof(unsigned) * 2 + sizeof(void *) * 2,
5553
"wasted space in SmallVector size 1");
54+
5655
static_assert(sizeof(SmallVector<char, 0>) ==
5756
sizeof(void *) * 2 + sizeof(void *),
5857
"1 byte elements have word-sized type for size and capacity");
59-
static_assert(sizeof(SmallVector<int16_t, 0>) ==
60-
sizeof(unsigned) * 2 + sizeof(void *),
61-
"2 byte elements have 32-bit type for size and capacity");
6258

6359
/// Report that MinSize doesn't fit into this vector's size type. Throws
6460
/// std::length_error or calls report_fatal_error.

0 commit comments

Comments
 (0)