forked from OSchip/llvm-project
[flang] 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. Original-commit: flang-compiler/f18@4542cb5708 Reviewed-on: https://github.com/flang-compiler/f18/pull/968
This commit is contained in:
parent
b6363facf5
commit
a8ef13ea25
|
@ -153,15 +153,12 @@ template<typename... Ts> struct VariantToTupleHelper<std::variant<Ts...>> {
|
|||
template<typename VARIANT>
|
||||
using VariantToTuple = typename VariantToTupleHelper<VARIANT>::type;
|
||||
|
||||
template<typename A, typename B, typename... REST>
|
||||
struct AreTypesDistinctHelper {
|
||||
template<typename A, typename... REST> struct AreTypesDistinctHelper {
|
||||
static constexpr bool value() {
|
||||
if constexpr (std::is_same_v<A, B>) {
|
||||
return false;
|
||||
}
|
||||
if constexpr (sizeof...(REST) > 0) {
|
||||
return AreTypesDistinctHelper<A, REST...>::value() &&
|
||||
AreTypesDistinctHelper<B, REST...>::value();
|
||||
// extra () for clang-format
|
||||
return ((... && !std::is_same_v<A, REST>)) &&
|
||||
AreTypesDistinctHelper<REST...>::value();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue