[PATCH] D77621: ADT: SmallVector size/capacity use word-size integers when elements are small
Andrew via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 30 11:47:21 PDT 2020
browneee added a comment.
Thanks for the tips, MaskRay.
Yes, I expect this would fix that issue.
smeenai, SizeTypeMax() is intended to return size_t.
---
I see a couple of options for fixing the truncation warning on 32-bit platforms:
1. Add an explicit cast to remove the warning.
- Disadvantage: the second instantiation still exists even though it is unused.
static constexpr size_t SizeTypeMax() {
return static_cast<size_t>(std::numeric_limits<Size_T>::max());
}
2. Use a std::conditional to swap the type of one instantiation to avoid conflicts.
In this case I'd probably swap back to using uintptr_t and disable the uint32_t on 32bit.
- Disadvantage: the second instantiation still exists even though it is unused.
// Will be unused when instantiated with char.
// This is to avoid instantiation for uint32_t conflicting with uintptr_t on 32-bit systems.
template class llvm::SmallVectorBase<std::conditional<sizeof(void *) != 4, uint32_t, char>::type>;
template class llvm::SmallVectorBase<uintptr_t>;
3. Use preprocessor to disable one of the instantiations on 32-bit platforms.
In this case I'd probably swap back to using uintptr_t and disable the uint32_t on 32bit.
- Disadvantage: uses preprocessor
- Disadvantage: potential for portability issues with different platforms lacking certain macros
#if __SIZEOF_POINTER__ != 4 && !defined(_WIN32) && !defined(__ILP32)
template class llvm::SmallVectorBase<uint32_t>;
#endif
template class llvm::SmallVectorBase<uintptr_t>;
My order of preference would be 1, 2, 3.
Is there another solution I've missed? Thoughts on which is best? @dblaikie
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D77621/new/
https://reviews.llvm.org/D77621
More information about the llvm-commits
mailing list