diff --git a/clang/lib/AST/Interp/Floating.h b/clang/lib/AST/Interp/Floating.h --- a/clang/lib/AST/Interp/Floating.h +++ b/clang/lib/AST/Interp/Floating.h @@ -90,7 +90,18 @@ bool isFinite() const { return F.isFinite(); } ComparisonCategoryResult compare(const Floating &RHS) const { - return Compare(F, RHS.F); + llvm::APFloatBase::cmpResult CmpRes = F.compare(RHS.F); + switch (CmpRes) { + case llvm::APFloatBase::cmpLessThan: + return ComparisonCategoryResult::Less; + case llvm::APFloatBase::cmpEqual: + return ComparisonCategoryResult::Equal; + case llvm::APFloatBase::cmpGreaterThan: + return ComparisonCategoryResult::Greater; + case llvm::APFloatBase::cmpUnordered: + return ComparisonCategoryResult::Unordered; + } + llvm_unreachable("Inavlid cmpResult value"); } static APFloat::opStatus fromIntegral(APSInt Val, diff --git a/clang/test/AST/Interp/floats.cpp b/clang/test/AST/Interp/floats.cpp --- a/clang/test/AST/Interp/floats.cpp +++ b/clang/test/AST/Interp/floats.cpp @@ -145,3 +145,12 @@ namespace LongDouble { constexpr long double ld = 3.1425926539; } + +namespace Compare { + constexpr float nan = __builtin_nan(""); + constexpr float inf = __builtin_inf(); + static_assert(!(nan == nan), ""); + static_assert(nan != nan, ""); + static_assert(!(inf < nan), ""); + static_assert(!(inf > nan), ""); +}