diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp --- a/clang/lib/AST/ExprConstant.cpp +++ b/clang/lib/AST/ExprConstant.cpp @@ -9609,6 +9609,58 @@ return Success(N == Val.getBitWidth() ? 0 : N + 1, E); } + case Builtin::BIlround: + case Builtin::BI__builtin_lround: { + APFloat Val(0.0); + return EvaluateFloat(E->getArg(0), Val, Info) && + Success(lround(Val.convertToDouble()), E); + } + case Builtin::BIlroundf: + case Builtin::BI__builtin_lroundf: { + APFloat Val(0.0); + return EvaluateFloat(E->getArg(0), Val, Info) && + Success(lround(Val.convertToFloat()), E); + } + + case Builtin::BIllround: + case Builtin::BI__builtin_llround: { + APFloat Val(0.0); + return EvaluateFloat(E->getArg(0), Val, Info) && + Success(lround(Val.convertToDouble()), E); + } + case Builtin::BIllroundf: + case Builtin::BI__builtin_llroundf: { + APFloat Val(0.0); + return EvaluateFloat(E->getArg(0), Val, Info) && + Success(llround(Val.convertToFloat()), E); + } + + case Builtin::BIlrint: + case Builtin::BI__builtin_lrint: { + APFloat Val(0.0); + return EvaluateFloat(E->getArg(0), Val, Info) && + Success(lround(Val.convertToDouble()), E); + } + case Builtin::BIlrintf: + case Builtin::BI__builtin_lrintf: { + APFloat Val(0.0); + return EvaluateFloat(E->getArg(0), Val, Info) && + Success(lrint(Val.convertToFloat()), E); + } + + case Builtin::BIllrint: + case Builtin::BI__builtin_llrint: { + APFloat Val(0.0); + return EvaluateFloat(E->getArg(0), Val, Info) && + Success(lround(Val.convertToDouble()), E); + } + case Builtin::BIllrintf: + case Builtin::BI__builtin_llrintf: { + APFloat Val(0.0); + return EvaluateFloat(E->getArg(0), Val, Info) && + Success(llrint(Val.convertToFloat()), E); + } + case Builtin::BI__builtin_fpclassify: { APFloat Val(0.0); if (!EvaluateFloat(E->getArg(5), Val, Info)) diff --git a/clang/test/SemaCXX/math-builtins.cpp b/clang/test/SemaCXX/math-builtins.cpp new file mode 100644 --- /dev/null +++ b/clang/test/SemaCXX/math-builtins.cpp @@ -0,0 +1,18 @@ +// RUN: %clang_cc1 -std=c++11 %s + +int main() +{ + constexpr float f = 12345.6789; + + static_assert(__builtin_llround(f) == 12346, ""); + static_assert(__builtin_llroundf(f) == 12346, ""); + + static_assert(__builtin_llrint(f) == 12346, ""); + static_assert(__builtin_llrintf(f) == 12346, ""); + + static_assert(__builtin_lrint(f) == 12346, ""); + static_assert(__builtin_lrintf(f) == 12346, ""); + + static_assert(__builtin_lround(f) == 12346, ""); + static_assert(__builtin_lroundf(f) == 12346, ""); +} \ No newline at end of file