Skip to content

Commit eb25f69

Browse files
[ADT] Replace Min with variadic std::min
Without this patch, NumTagBits and MinTag use a recursive template Min to compute Min. This patch replaces Min with variadic std::min. While I'm at it, this patch changes the type of NumTagBits to static constexpr int.
1 parent 193df2a commit eb25f69

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

llvm/include/llvm/ADT/PointerSumType.h

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
#ifndef LLVM_ADT_POINTERSUMTYPE_H
1010
#define LLVM_ADT_POINTERSUMTYPE_H
1111

12-
#include "llvm/ADT/bit.h"
1312
#include "llvm/ADT/DenseMapInfo.h"
13+
#include "llvm/ADT/bit.h"
1414
#include "llvm/Support/PointerLikeTypeTraits.h"
15+
#include <algorithm>
1516
#include <cassert>
1617
#include <cstdint>
1718
#include <type_traits>
@@ -226,19 +227,13 @@ struct PointerSumTypeHelper : MemberTs... {
226227
};
227228

228229
// Next we need to compute the number of bits available for the discriminant
229-
// by taking the min of the bits available for each member. Much of this
230-
// would be amazingly easier with good constexpr support.
231-
template <uintptr_t V, uintptr_t... Vs>
232-
struct Min : std::integral_constant<
233-
uintptr_t, (V < Min<Vs...>::value ? V : Min<Vs...>::value)> {
234-
};
235-
template <uintptr_t V>
236-
struct Min<V> : std::integral_constant<uintptr_t, V> {};
237-
enum { NumTagBits = Min<MemberTs::TraitsT::NumLowBitsAvailable...>::value };
230+
// by taking the min of the bits available for each member.
231+
static constexpr int NumTagBits =
232+
std::min({MemberTs::TraitsT::NumLowBitsAvailable...});
238233

239234
// Also compute the smallest discriminant and various masks for convenience.
240235
constexpr static TagT MinTag =
241-
static_cast<TagT>(Min<MemberTs::Tag...>::value);
236+
static_cast<TagT>(std::min({static_cast<TagT>(MemberTs::Tag)...}));
242237
enum : uint64_t {
243238
PointerMask = static_cast<uint64_t>(-1) << NumTagBits,
244239
TagMask = ~PointerMask

0 commit comments

Comments
 (0)