https://gcc.gnu.org/bugzilla/show_bug.cgi?id=127369

            Bug ID: 127369
           Summary: std::isfinite/std::isinf do not work reliably
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: gero.peterhoff at gmx dot net
  Target Milestone: ---

With -O1/2/3/s/z, std::isfinite/std::isinf do not work in an inline context. It
appears that the functions are “optimized away” in that case. However, they
seem to work with noinline or constexpr values. The problem always occurs (not
just with U64->FP16 as in the example), e.g., U128 -> FP32.
This means that many math functions do not work correctly --> showstopper.
Other functions may also be affected.

template <std::floating_point Float>
__attribute__ ((__noinline__))  constexpr bool  is_finite(const Float x)       
noexcept        { return std::isfinite(x);      }

template <std::floating_point Float>
__attribute__ ((__noinline__))  constexpr bool  is_inf(const Float x)          
noexcept        { return std::isinf(x); }

int main(const int argc, const char*const*const args)
{
        if (argc > 0)
        {
                using F = std::float16_t;
                using U = std::uint64_t;
                using I = std::int64_t;

                I i = std::atoll(args[1]);
                F f = F(U(i));  // inf

                std::cout << f << "\n";
                std::cout << "finite\t" << std::isfinite(f) << "\t" <<
is_finite(f) << "\n";
                std::cout << "inf\t" << std::isinf(f) << "\t" << is_inf(f) <<
"\n";
        }
        return 0;
}


Compile with -O3 and run with -1:
inf
finite  true    false
inf     false   true
  • [Bug c++/127369] New: std::isfi... gero.peterhoff at gmx dot net via Gcc-bugs

Reply via email to