Skip to content

Commit d10f986

Browse files
committed
ADT: Migrate users of AlignedCharArrayUnion to std::aligned_union_t, NFC
Prepare to delete `AlignedCharArrayUnion` by migrating its users over to `std::aligned_union_t`. I will delete `AlignedCharArrayUnion` and its tests in a follow-up commit so that it's easier to revert in isolation in case some downstream wants to keep using it. Differential Revision: https://reviews.llvm.org/D92516
1 parent fa4c3f7 commit d10f986

File tree

19 files changed

+29
-44
lines changed

19 files changed

+29
-44
lines changed

clang/include/clang/AST/APValue.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#include "llvm/ADT/FoldingSet.h"
2121
#include "llvm/ADT/PointerIntPair.h"
2222
#include "llvm/ADT/PointerUnion.h"
23-
#include "llvm/Support/AlignOf.h"
23+
#include <type_traits>
2424

2525
namespace clang {
2626
class AddrLabelExpr;
@@ -286,9 +286,10 @@ class APValue {
286286
struct MemberPointerData;
287287

288288
// We ensure elsewhere that Data is big enough for LV and MemberPointerData.
289-
typedef llvm::AlignedCharArrayUnion<void *, APSInt, APFloat, ComplexAPSInt,
290-
ComplexAPFloat, Vec, Arr, StructData,
291-
UnionData, AddrLabelDiffData> DataType;
289+
typedef std::aligned_union_t<1, void *, APSInt, APFloat, ComplexAPSInt,
290+
ComplexAPFloat, Vec, Arr, StructData, UnionData,
291+
AddrLabelDiffData>
292+
DataType;
292293
static const size_t DataSize = sizeof(DataType);
293294

294295
DataType Data;

clang/include/clang/AST/ASTContext.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@
5757
#include "llvm/ADT/TinyPtrVector.h"
5858
#include "llvm/ADT/Triple.h"
5959
#include "llvm/ADT/iterator_range.h"
60-
#include "llvm/Support/AlignOf.h"
6160
#include "llvm/Support/Allocator.h"
6261
#include "llvm/Support/Casting.h"
6362
#include "llvm/Support/Compiler.h"

clang/include/clang/AST/ASTTypeTraits.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#include "clang/AST/TypeLoc.h"
2323
#include "clang/Basic/LLVM.h"
2424
#include "llvm/ADT/DenseMapInfo.h"
25-
#include "llvm/Support/AlignOf.h"
25+
#include <type_traits>
2626

2727
namespace llvm {
2828

@@ -456,9 +456,8 @@ class DynTypedNode {
456456
/// \c QualTypes, \c NestedNameSpecifierLocs, \c TypeLocs,
457457
/// \c TemplateArguments and \c TemplateArgumentLocs on the other hand do not
458458
/// have storage or unique pointers and thus need to be stored by value.
459-
llvm::AlignedCharArrayUnion<const void *, TemplateArgument,
460-
TemplateArgumentLoc, NestedNameSpecifierLoc,
461-
QualType, TypeLoc>
459+
std::aligned_union_t<1, const void *, TemplateArgument, TemplateArgumentLoc,
460+
NestedNameSpecifierLoc, QualType, TypeLoc>
462461
Storage;
463462
};
464463

clang/include/clang/AST/ParentMapContext.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ class TraversalKindScope {
8989
/// Container for either a single DynTypedNode or for an ArrayRef to
9090
/// DynTypedNode. For use with ParentMap.
9191
class DynTypedNodeList {
92-
llvm::AlignedCharArrayUnion<DynTypedNode, ArrayRef<DynTypedNode>> Storage;
92+
std::aligned_union_t<1, DynTypedNode, ArrayRef<DynTypedNode>> Storage;
9393
bool IsSingleNode;
9494

9595
public:

clang/include/clang/Frontend/PrecompiledPreamble.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "clang/Lex/Preprocessor.h"
1818
#include "llvm/ADT/IntrusiveRefCntPtr.h"
1919
#include "llvm/ADT/StringRef.h"
20-
#include "llvm/Support/AlignOf.h"
2120
#include "llvm/Support/MD5.h"
2221
#include <cstddef>
2322
#include <memory>
@@ -198,7 +197,7 @@ class PrecompiledPreamble {
198197

199198
private:
200199
Kind StorageKind = Kind::Empty;
201-
llvm::AlignedCharArrayUnion<TempPCHFile, InMemoryPreamble> Storage = {};
200+
std::aligned_union_t<1, TempPCHFile, InMemoryPreamble> Storage = {};
202201
};
203202

204203
/// Data used to determine if a file used in the preamble has been changed.

clang/include/clang/Sema/Overload.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@
3131
#include "llvm/ADT/SmallPtrSet.h"
3232
#include "llvm/ADT/SmallVector.h"
3333
#include "llvm/ADT/StringRef.h"
34-
#include "llvm/Support/AlignOf.h"
3534
#include "llvm/Support/Allocator.h"
3635
#include "llvm/Support/Casting.h"
3736
#include "llvm/Support/ErrorHandling.h"

clang/lib/DirectoryWatcher/linux/DirectoryWatcher-linux.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
#include "llvm/ADT/STLExtras.h"
1313
#include "llvm/ADT/ScopeExit.h"
14-
#include "llvm/Support/AlignOf.h"
1514
#include "llvm/Support/Errno.h"
1615
#include "llvm/Support/Error.h"
1716
#include "llvm/Support/Path.h"

clang/lib/DirectoryWatcher/windows/DirectoryWatcher-windows.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
#include "llvm/ADT/STLExtras.h"
1616
#include "llvm/ADT/ScopeExit.h"
17-
#include "llvm/Support/AlignOf.h"
1817
#include "llvm/Support/Errno.h"
1918
#include "llvm/Support/Mutex.h"
2019
#include "llvm/Support/Path.h"

clang/lib/Lex/PPDirectives.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@
3939
#include "llvm/ADT/STLExtras.h"
4040
#include "llvm/ADT/StringSwitch.h"
4141
#include "llvm/ADT/StringRef.h"
42-
#include "llvm/Support/AlignOf.h"
4342
#include "llvm/Support/ErrorHandling.h"
4443
#include "llvm/Support/Path.h"
4544
#include <algorithm>

llvm/include/llvm/ADT/DenseMap.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
#include "llvm/ADT/DenseMapInfo.h"
1717
#include "llvm/ADT/EpochTracker.h"
18-
#include "llvm/Support/AlignOf.h"
1918
#include "llvm/Support/Compiler.h"
2019
#include "llvm/Support/MathExtras.h"
2120
#include "llvm/Support/MemAlloc.h"
@@ -901,7 +900,7 @@ class SmallDenseMap
901900

902901
/// A "union" of an inline bucket array and the struct representing
903902
/// a large bucket. This union will be discriminated by the 'Small' bit.
904-
AlignedCharArrayUnion<BucketT[InlineBuckets], LargeRep> storage;
903+
std::aligned_union_t<1, BucketT[InlineBuckets], LargeRep> storage;
905904

906905
public:
907906
explicit SmallDenseMap(unsigned NumInitBuckets = 0) {
@@ -1041,7 +1040,7 @@ class SmallDenseMap
10411040

10421041
if (Small) {
10431042
// First move the inline buckets into a temporary storage.
1044-
AlignedCharArrayUnion<BucketT[InlineBuckets]> TmpStorage;
1043+
std::aligned_union_t<1, BucketT[InlineBuckets]> TmpStorage;
10451044
BucketT *TmpBegin = reinterpret_cast<BucketT *>(&TmpStorage);
10461045
BucketT *TmpEnd = TmpBegin;
10471046

llvm/include/llvm/ADT/IntervalMap.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,14 @@
101101
#include "llvm/ADT/PointerIntPair.h"
102102
#include "llvm/ADT/SmallVector.h"
103103
#include "llvm/ADT/bit.h"
104-
#include "llvm/Support/AlignOf.h"
105104
#include "llvm/Support/Allocator.h"
106105
#include "llvm/Support/RecyclingAllocator.h"
107106
#include <algorithm>
108107
#include <cassert>
109108
#include <cstdint>
110109
#include <iterator>
111110
#include <new>
111+
#include <type_traits>
112112
#include <utility>
113113

114114
namespace llvm {
@@ -963,7 +963,7 @@ class IntervalMap {
963963

964964
private:
965965
// The root data is either a RootLeaf or a RootBranchData instance.
966-
AlignedCharArrayUnion<RootLeaf, RootBranchData> data;
966+
std::aligned_union_t<1, RootLeaf, RootBranchData> data;
967967

968968
// Tree height.
969969
// 0: Leaves in root.

llvm/include/llvm/CodeGen/DIE.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
#include "llvm/ADT/iterator_range.h"
2323
#include "llvm/BinaryFormat/Dwarf.h"
2424
#include "llvm/CodeGen/DwarfStringPoolEntry.h"
25-
#include "llvm/Support/AlignOf.h"
2625
#include "llvm/Support/Allocator.h"
2726
#include <cassert>
2827
#include <cstddef>
@@ -368,9 +367,9 @@ class DIEValue {
368367
///
369368
/// All values that aren't standard layout (or are larger than 8 bytes)
370369
/// should be stored by reference instead of by value.
371-
using ValTy = AlignedCharArrayUnion<DIEInteger, DIEString, DIEExpr, DIELabel,
372-
DIEDelta *, DIEEntry, DIEBlock *,
373-
DIELoc *, DIELocList, DIEBaseTypeRef *>;
370+
using ValTy = std::aligned_union_t<1, DIEInteger, DIEString, DIEExpr,
371+
DIELabel, DIEDelta *, DIEEntry, DIEBlock *,
372+
DIELoc *, DIELocList, DIEBaseTypeRef *>;
374373

375374
static_assert(sizeof(ValTy) <= sizeof(uint64_t) ||
376375
sizeof(ValTy) <= sizeof(void *),

llvm/include/llvm/CodeGen/SelectionDAGNodes.h

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
#include "llvm/IR/Instructions.h"
3939
#include "llvm/IR/Metadata.h"
4040
#include "llvm/IR/Operator.h"
41-
#include "llvm/Support/AlignOf.h"
4241
#include "llvm/Support/AtomicOrdering.h"
4342
#include "llvm/Support/Casting.h"
4443
#include "llvm/Support/ErrorHandling.h"
@@ -2628,10 +2627,9 @@ template <> struct GraphTraits<SDNode*> {
26282627
///
26292628
/// This needs to be a union because the largest node differs on 32 bit systems
26302629
/// with 4 and 8 byte pointer alignment, respectively.
2631-
using LargestSDNode = AlignedCharArrayUnion<AtomicSDNode, TargetIndexSDNode,
2632-
BlockAddressSDNode,
2633-
GlobalAddressSDNode,
2634-
PseudoProbeSDNode>;
2630+
using LargestSDNode =
2631+
std::aligned_union_t<1, AtomicSDNode, TargetIndexSDNode, BlockAddressSDNode,
2632+
GlobalAddressSDNode, PseudoProbeSDNode>;
26352633

26362634
/// The SDNode class with the greatest alignment requirement.
26372635
using MostAlignedSDNode = GlobalAddressSDNode;

llvm/include/llvm/Support/Error.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
#include "llvm/ADT/StringExtras.h"
2020
#include "llvm/ADT/Twine.h"
2121
#include "llvm/Config/abi-breaking.h"
22-
#include "llvm/Support/AlignOf.h"
2322
#include "llvm/Support/Compiler.h"
2423
#include "llvm/Support/Debug.h"
2524
#include "llvm/Support/ErrorHandling.h"
@@ -678,8 +677,8 @@ template <class T> class LLVM_NODISCARD Expected {
678677
}
679678

680679
union {
681-
AlignedCharArrayUnion<storage_type> TStorage;
682-
AlignedCharArrayUnion<error_type> ErrorStorage;
680+
std::aligned_union_t<1, storage_type> TStorage;
681+
std::aligned_union_t<1, error_type> ErrorStorage;
683682
};
684683
bool HasError : 1;
685684
#if LLVM_ENABLE_ABI_BREAKING_CHECKS

llvm/include/llvm/Support/ErrorOr.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#ifndef LLVM_SUPPORT_ERROROR_H
1616
#define LLVM_SUPPORT_ERROROR_H
1717

18-
#include "llvm/Support/AlignOf.h"
1918
#include <cassert>
2019
#include <system_error>
2120
#include <type_traits>
@@ -253,8 +252,8 @@ class ErrorOr {
253252
}
254253

255254
union {
256-
AlignedCharArrayUnion<storage_type> TStorage;
257-
AlignedCharArrayUnion<std::error_code> ErrorStorage;
255+
std::aligned_union_t<1, storage_type> TStorage;
256+
std::aligned_union_t<1, std::error_code> ErrorStorage;
258257
};
259258
bool HasError : 1;
260259
};

llvm/include/llvm/Support/JSON.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,8 @@ class Value {
479479
};
480480
// All members mutable, see moveFrom().
481481
mutable ValueType Type;
482-
mutable llvm::AlignedCharArrayUnion<bool, double, int64_t, llvm::StringRef,
483-
std::string, json::Array, json::Object>
482+
mutable std::aligned_union_t<1, bool, double, int64_t, llvm::StringRef,
483+
std::string, json::Array, json::Object>
484484
Union;
485485
friend bool operator==(const Value &, const Value &);
486486
};

llvm/include/llvm/Support/TrailingObjects.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
#ifndef LLVM_SUPPORT_TRAILINGOBJECTS_H
4747
#define LLVM_SUPPORT_TRAILINGOBJECTS_H
4848

49-
#include "llvm/Support/AlignOf.h"
5049
#include "llvm/Support/Alignment.h"
5150
#include "llvm/Support/Compiler.h"
5251
#include "llvm/Support/MathExtras.h"

llvm/include/llvm/Support/YAMLTraits.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
#include "llvm/ADT/StringMap.h"
1616
#include "llvm/ADT/StringRef.h"
1717
#include "llvm/ADT/Twine.h"
18-
#include "llvm/Support/AlignOf.h"
1918
#include "llvm/Support/Allocator.h"
2019
#include "llvm/Support/Endian.h"
2120
#include "llvm/Support/Regex.h"
@@ -1311,7 +1310,7 @@ struct MappingNormalization {
13111310
TNorm* operator->() { return BufPtr; }
13121311

13131312
private:
1314-
using Storage = AlignedCharArrayUnion<TNorm>;
1313+
using Storage = std::aligned_union_t<1, TNorm>;
13151314

13161315
Storage Buffer;
13171316
IO &io;
@@ -1348,7 +1347,7 @@ struct MappingNormalizationHeap {
13481347
TNorm* operator->() { return BufPtr; }
13491348

13501349
private:
1351-
using Storage = AlignedCharArrayUnion<TNorm>;
1350+
using Storage = std::aligned_union_t<1, TNorm>;
13521351

13531352
Storage Buffer;
13541353
IO &io;

llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
#include "llvm/IR/PatternMatch.h"
2727
#include "llvm/IR/Type.h"
2828
#include "llvm/IR/Value.h"
29-
#include "llvm/Support/AlignOf.h"
3029
#include "llvm/Support/Casting.h"
3130
#include "llvm/Support/KnownBits.h"
3231
#include "llvm/Transforms/InstCombine/InstCombiner.h"
@@ -120,7 +119,7 @@ namespace {
120119
// is overkill of this end.
121120
short IntVal = 0;
122121

123-
AlignedCharArrayUnion<APFloat> FpValBuf;
122+
std::aligned_union_t<1, APFloat> FpValBuf;
124123
};
125124

126125
/// FAddend is used to represent floating-point addend. An addend is

0 commit comments

Comments
 (0)