From: Jean Perier Date: Tue, 4 Feb 2020 18:30:16 +0000 (-0800) Subject: [flang] Fix template step limit issue with clang X-Git-Tag: llvmorg-12-init~9537^2~156 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a8ef13ea25e9a21906aad4489f461f19cdb3fa37;p=platform%2Fupstream%2Fllvm.git [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@4542cb57082eaf578799c76482d4b706ae5da077 Reviewed-on: https://github.com/flang-compiler/f18/pull/968 --- diff --git a/flang/include/flang/common/template.h b/flang/include/flang/common/template.h index c8a18e7..460f1a8 100644 --- a/flang/include/flang/common/template.h +++ b/flang/include/flang/common/template.h @@ -153,15 +153,12 @@ template struct VariantToTupleHelper> { template using VariantToTuple = typename VariantToTupleHelper::type; -template -struct AreTypesDistinctHelper { +template struct AreTypesDistinctHelper { static constexpr bool value() { - if constexpr (std::is_same_v) { - return false; - } if constexpr (sizeof...(REST) > 0) { - return AreTypesDistinctHelper::value() && - AreTypesDistinctHelper::value(); + // extra () for clang-format + return ((... && !std::is_same_v)) && + AreTypesDistinctHelper::value(); } return true; }