Skip to content

Commit 4542cb5

Browse files
committed
Fix template step limit issue with clang
While working on PR 959, I instanciated a `common::TupleToVariant` with ~50+ types inside the tuple. Clang would then crash after 1hr compilation with message: "constexpr evaluation hit maximum step limit; possible infinite loop" After investigating, it turned out clang handles very badly the way `common::AreTypesDistinctHelper` was implemented. Its "number of steps" was exponential with the number of types. This fix makes this number quadratic which solves the issue.
1 parent bedca14 commit 4542cb5

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

include/flang/common/template.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,12 @@ template<typename... Ts> struct VariantToTupleHelper<std::variant<Ts...>> {
153153
template<typename VARIANT>
154154
using VariantToTuple = typename VariantToTupleHelper<VARIANT>::type;
155155

156-
template<typename A, typename B, typename... REST>
157-
struct AreTypesDistinctHelper {
156+
template<typename A, typename... REST> struct AreTypesDistinctHelper {
158157
static constexpr bool value() {
159-
if constexpr (std::is_same_v<A, B>) {
160-
return false;
161-
}
162158
if constexpr (sizeof...(REST) > 0) {
163-
return AreTypesDistinctHelper<A, REST...>::value() &&
164-
AreTypesDistinctHelper<B, REST...>::value();
159+
// extra () for clang-format
160+
return ((... && !std::is_same_v<A, REST>)) &&
161+
AreTypesDistinctHelper<REST...>::value();
165162
}
166163
return true;
167164
}

0 commit comments

Comments
 (0)