From: Reid Kleckner Date: Thu, 27 Feb 2020 22:55:13 +0000 (-0800) Subject: [ADT] Use alignas + sizeof for inline storage, NFC X-Git-Tag: llvmorg-13-init~9243 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=8b6d1c0467b2dfa14cb2d2dec7637bf95c78364b;p=platform%2Fupstream%2Fllvm.git [ADT] Use alignas + sizeof for inline storage, NFC AlignedCharArrayUnion is really only needed to handle the "union" case when we need memory of suitable size and alignment for multiple types. SmallVector only needs storage for one type, so use that directly. --- diff --git a/clang/include/clang/AST/APValue.h b/clang/include/clang/AST/APValue.h index ac8ed08..5eb1f68 100644 --- a/clang/include/clang/AST/APValue.h +++ b/clang/include/clang/AST/APValue.h @@ -17,9 +17,10 @@ #include "llvm/ADT/APFixedPoint.h" #include "llvm/ADT/APFloat.h" #include "llvm/ADT/APSInt.h" +#include "llvm/ADT/FoldingSet.h" #include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/PointerUnion.h" -#include "llvm/ADT/FoldingSet.h" +#include "llvm/Support/AlignOf.h" namespace clang { class AddrLabelExpr; diff --git a/llvm/include/llvm/ADT/SmallVector.h b/llvm/include/llvm/ADT/SmallVector.h index c3c6a36..dd5cd95 100644 --- a/llvm/include/llvm/ADT/SmallVector.h +++ b/llvm/include/llvm/ADT/SmallVector.h @@ -14,7 +14,6 @@ #define LLVM_ADT_SMALLVECTOR_H #include "llvm/ADT/iterator_range.h" -#include "llvm/Support/AlignOf.h" #include "llvm/Support/Compiler.h" #include "llvm/Support/ErrorHandling.h" #include "llvm/Support/MathExtras.h" @@ -97,8 +96,9 @@ using SmallVectorSizeType = /// Figure out the offset of the first element. template struct SmallVectorAlignmentAndSize { - AlignedCharArrayUnion>> Base; - AlignedCharArrayUnion FirstEl; + alignas(SmallVectorBase>) char Base[sizeof( + SmallVectorBase>)]; + alignas(T) char FirstEl[sizeof(T)]; }; /// This is the part of SmallVectorTemplateBase which does not depend on whether @@ -870,13 +870,13 @@ SmallVectorImpl &SmallVectorImpl::operator=(SmallVectorImpl &&RHS) { /// to avoid allocating unnecessary storage. template struct SmallVectorStorage { - AlignedCharArrayUnion InlineElts[N]; + alignas(T) char InlineElts[N * sizeof(T)]; }; /// We need the storage to be properly aligned even for small-size of 0 so that /// the pointer math in \a SmallVectorTemplateCommon::getFirstEl() is /// well-defined. -template struct alignas(alignof(T)) SmallVectorStorage {}; +template struct alignas(T) SmallVectorStorage {}; /// This is a 'vector' (really, a variable-sized array), optimized /// for the case when the array is small. It contains some number of elements diff --git a/llvm/include/llvm/ADT/iterator_range.h b/llvm/include/llvm/ADT/iterator_range.h index f038f6b..a9b46a3 100644 --- a/llvm/include/llvm/ADT/iterator_range.h +++ b/llvm/include/llvm/ADT/iterator_range.h @@ -18,7 +18,6 @@ #ifndef LLVM_ADT_ITERATOR_RANGE_H #define LLVM_ADT_ITERATOR_RANGE_H -#include #include namespace llvm {