Skip to content

Commit 2a0bc20

Browse files
localspookmahesh-attarde
authored andcommitted
[llvm][NFC] Simplify alignment calculations in TrailingObjects (llvm#161134)
1 parent 4dba02f commit 2a0bc20

File tree

1 file changed

+8
-25
lines changed

1 file changed

+8
-25
lines changed

llvm/include/llvm/Support/TrailingObjects.h

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -57,25 +57,9 @@
5757
namespace llvm {
5858

5959
namespace trailing_objects_internal {
60-
/// Helper template to calculate the max alignment requirement for a set of
61-
/// objects.
62-
template <typename First, typename... Rest> class AlignmentCalcHelper {
63-
private:
64-
enum {
65-
FirstAlignment = alignof(First),
66-
RestAlignment = AlignmentCalcHelper<Rest...>::Alignment,
67-
};
6860

69-
public:
70-
enum {
71-
Alignment = FirstAlignment > RestAlignment ? FirstAlignment : RestAlignment
72-
};
73-
};
74-
75-
template <typename First> class AlignmentCalcHelper<First> {
76-
public:
77-
enum { Alignment = alignof(First) };
78-
};
61+
template <typename... T>
62+
inline constexpr size_t MaxAlignment = std::max({alignof(T)...});
7963

8064
/// The base class for TrailingObjects* classes.
8165
class TrailingObjectsBase {
@@ -209,20 +193,19 @@ class alignas(Align) TrailingObjectsImpl<Align, BaseTy, TopTrailingObj, PrevTy>
209193
/// See the file comment for details on the usage of the
210194
/// TrailingObjects type.
211195
template <typename BaseTy, typename... TrailingTys>
212-
class TrailingObjects : private trailing_objects_internal::TrailingObjectsImpl<
213-
trailing_objects_internal::AlignmentCalcHelper<
214-
TrailingTys...>::Alignment,
215-
BaseTy, TrailingObjects<BaseTy, TrailingTys...>,
216-
BaseTy, TrailingTys...> {
196+
class TrailingObjects
197+
: private trailing_objects_internal::TrailingObjectsImpl<
198+
trailing_objects_internal::MaxAlignment<TrailingTys...>, BaseTy,
199+
TrailingObjects<BaseTy, TrailingTys...>, BaseTy, TrailingTys...> {
217200

218201
template <int A, typename B, typename T, typename P, typename... M>
219202
friend class trailing_objects_internal::TrailingObjectsImpl;
220203

221204
template <typename... Tys> class Foo {};
222205

223206
typedef trailing_objects_internal::TrailingObjectsImpl<
224-
trailing_objects_internal::AlignmentCalcHelper<TrailingTys...>::Alignment,
225-
BaseTy, TrailingObjects<BaseTy, TrailingTys...>, BaseTy, TrailingTys...>
207+
trailing_objects_internal::MaxAlignment<TrailingTys...>, BaseTy,
208+
TrailingObjects<BaseTy, TrailingTys...>, BaseTy, TrailingTys...>
226209
ParentType;
227210
using TrailingObjectsBase = trailing_objects_internal::TrailingObjectsBase;
228211

0 commit comments

Comments
 (0)