[clang] f444f39 - [clang][Interp] Implement __builtin_isfinite
Timm Bäder via cfe-commits
cfe-commits at lists.llvm.org
Mon Jul 31 00:12:48 PDT 2023
Author: Timm Bäder
Date: 2023-07-31T09:12:32+02:00
New Revision: f444f396863ceba0e0572a721d102fb48e8ca1b3
URL: https://github.com/llvm/llvm-project/commit/f444f396863ceba0e0572a721d102fb48e8ca1b3
DIFF: https://github.com/llvm/llvm-project/commit/f444f396863ceba0e0572a721d102fb48e8ca1b3.diff
LOG: [clang][Interp] Implement __builtin_isfinite
Differential Revision: https://reviews.llvm.org/D155372
Added:
Modified:
clang/lib/AST/Interp/InterpBuiltin.cpp
clang/test/AST/Interp/builtin-functions.cpp
Removed:
################################################################################
diff --git a/clang/lib/AST/Interp/InterpBuiltin.cpp b/clang/lib/AST/Interp/InterpBuiltin.cpp
index b5e19af5c37288..6fe9bc7628efef 100644
--- a/clang/lib/AST/Interp/InterpBuiltin.cpp
+++ b/clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -187,6 +187,15 @@ static bool interp__builtin_isinf(InterpState &S, CodePtr OpPC,
return true;
}
+static bool interp__builtin_isfinite(InterpState &S, CodePtr OpPC,
+ const InterpFrame *Frame,
+ const Function *F) {
+ const Floating &Arg = S.Stk.peek<Floating>();
+
+ S.Stk.push<Integral<32, true>>(Integral<32, true>::from(Arg.isFinite()));
+ return true;
+}
+
bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F) {
InterpFrame *Frame = S.Current;
APValue Dummy;
@@ -263,6 +272,11 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F) {
return Ret<PT_Sint32>(S, OpPC, Dummy);
break;
+ case Builtin::BI__builtin_isfinite:
+ if (interp__builtin_isfinite(S, OpPC, Frame, F))
+ return Ret<PT_Sint32>(S, OpPC, Dummy);
+ break;
+
default:
return false;
}
diff --git a/clang/test/AST/Interp/builtin-functions.cpp b/clang/test/AST/Interp/builtin-functions.cpp
index 7eb3e187d28ead..9457100a15f528 100644
--- a/clang/test/AST/Interp/builtin-functions.cpp
+++ b/clang/test/AST/Interp/builtin-functions.cpp
@@ -76,4 +76,7 @@ namespace fmin {
namespace inf {
static_assert(__builtin_isinf(__builtin_inf()), "");
static_assert(!__builtin_isinf(1.0), "");
+
+ static_assert(__builtin_isfinite(1.0), "");
+ static_assert(!__builtin_isfinite(__builtin_inf()), "");
}
More information about the cfe-commits
mailing list