diff --git a/flang/include/flang/Common/constexpr-bitset.h b/flang/include/flang/Common/constexpr-bitset.h index f1f4682689099..1aafb6eff84c6 100644 --- a/flang/include/flang/Common/constexpr-bitset.h +++ b/flang/include/flang/Common/constexpr-bitset.h @@ -10,9 +10,10 @@ #define FORTRAN_COMMON_CONSTEXPR_BITSET_H_ // Implements a replacement for std::bitset<> that is suitable for use -// in constexpr expressions. Limited to elements in [0..63]. +// in constexpr expressions. Limited to elements in [0..127]. #include "bit-population-count.h" +#include "uint128.h" #include #include #include @@ -22,11 +23,10 @@ namespace Fortran::common { template class BitSet { - static_assert(BITS > 0 && BITS <= 64); - static constexpr bool partialWord{BITS != 32 && BITS != 64}; - using Word = std::conditional_t<(BITS > 32), std::uint64_t, std::uint32_t>; + static_assert(BITS > 0 && BITS <= 128); + using Word = HostUnsignedIntType<(BITS <= 32 ? 32 : BITS)>; static constexpr Word allBits{ - partialWord ? (static_cast(1) << BITS) - 1 : ~static_cast(0)}; + ~static_cast(0) >> (8 * sizeof(Word) - BITS)}; constexpr BitSet(Word b) : bits_{b} {}