[llvm] 25e2e92 - [ADT] Fix SmallVector unused template instantiation on 32-bit systems.

Andrew Browne via llvm-commits llvm-commits at lists.llvm.org
Thu Apr 30 16:24:23 PDT 2020


Author: Andrew Browne
Date: 2020-04-30T16:22:54-07:00
New Revision: 25e2e92297e21bb4e0acab1b6bb5b2fdd5dc49ad

URL: https://github.com/llvm/llvm-project/commit/25e2e92297e21bb4e0acab1b6bb5b2fdd5dc49ad
DIFF: https://github.com/llvm/llvm-project/commit/25e2e92297e21bb4e0acab1b6bb5b2fdd5dc49ad.diff

LOG: [ADT] Fix SmallVector unused template instantiation on 32-bit systems.

Summary:
This was introduced in dda3c19a3618dce94 aka D77621.

The unused template instantiation causes a warning on 32 bit systems
about truncating a uint64_t to 32-bit size_t.

Reviewed By: dblaikie, smeenai

Differential Revision: https://reviews.llvm.org/D79214

Added: 
    

Modified: 
    llvm/lib/Support/SmallVector.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Support/SmallVector.cpp b/llvm/lib/Support/SmallVector.cpp
index 776b0981409f..0c9ac83f300a 100644
--- a/llvm/lib/Support/SmallVector.cpp
+++ b/llvm/lib/Support/SmallVector.cpp
@@ -78,4 +78,18 @@ void SmallVectorBase<Size_T>::grow_pod(void *FirstEl, size_t MinCapacity,
 }
 
 template class llvm::SmallVectorBase<uint32_t>;
+
+// Disable the uint64_t instantiation for 32-bit builds.
+// Both uint32_t and uint64_t instantations are needed for 64-bit builds.
+// This instantiation will never be used in 32-bit builds, and will cause
+// warnings when sizeof(Size_T) > sizeof(size_t).
+#if SIZE_MAX > UINT32_MAX
 template class llvm::SmallVectorBase<uint64_t>;
+
+// Assertions to ensure this #if stays in sync with SmallVectorSizeType.
+static_assert(sizeof(SmallVectorSizeType<char>) == sizeof(uint64_t),
+              "Expected SmallVectorBase<uint64_t> variant to be in use.");
+#else
+static_assert(sizeof(SmallVectorSizeType<char>) == sizeof(uint32_t),
+              "Expected SmallVectorBase<uint32_t> variant to be in use.");
+#endif


        


More information about the llvm-commits mailing list