[PATCH] D155371: [clang][Interp] Implement __builtin_isinf
Timm Bäder via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Jul 15 09:09:03 PDT 2023
tbaeder updated this revision to Diff 540693.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D155371/new/
https://reviews.llvm.org/D155371
Files:
clang/lib/AST/Interp/Floating.h
clang/lib/AST/Interp/InterpBuiltin.cpp
clang/test/AST/Interp/builtin-functions.cpp
Index: clang/test/AST/Interp/builtin-functions.cpp
===================================================================
--- clang/test/AST/Interp/builtin-functions.cpp
+++ clang/test/AST/Interp/builtin-functions.cpp
@@ -62,3 +62,8 @@
constexpr float Nan2 = __builtin_nans([](){return "0xAE98";}()); // ref-error {{must be initialized by a constant expression}}
}
+
+namespace inf {
+ static_assert(__builtin_isinf(__builtin_inf()), "");
+ static_assert(!__builtin_isinf(1.0), "");
+}
Index: clang/lib/AST/Interp/InterpBuiltin.cpp
===================================================================
--- clang/lib/AST/Interp/InterpBuiltin.cpp
+++ clang/lib/AST/Interp/InterpBuiltin.cpp
@@ -172,6 +172,20 @@
return true;
}
+static bool interp__builtin_isinf(InterpState &S, CodePtr OpPC,
+ const InterpFrame *Frame, const Function *F,
+ bool CheckSign) {
+ const Floating &Arg = S.Stk.peek<Floating>();
+ bool IsInf = Arg.isInf();
+
+ if (CheckSign)
+ S.Stk.push<Integral<32, true>>(
+ Integral<32, true>::from(IsInf ? (Arg.isNegative() ? -1 : 1) : 0));
+ else
+ S.Stk.push<Integral<32, true>>(Integral<32, true>::from(Arg.isInf()));
+ return true;
+}
+
bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F) {
InterpFrame *Frame = S.Current;
APValue Dummy;
@@ -232,6 +246,16 @@
return Ret<PT_Sint32>(S, OpPC, Dummy);
break;
+ case Builtin::BI__builtin_isinf:
+ if (interp__builtin_isinf(S, OpPC, Frame, F, /*Sign=*/false))
+ return Ret<PT_Sint32>(S, OpPC, Dummy);
+ break;
+
+ case Builtin::BI__builtin_isinf_sign:
+ if (interp__builtin_isinf(S, OpPC, Frame, F, /*Sign=*/true))
+ return Ret<PT_Sint32>(S, OpPC, Dummy);
+ break;
+
default:
return false;
}
Index: clang/lib/AST/Interp/Floating.h
===================================================================
--- clang/lib/AST/Interp/Floating.h
+++ clang/lib/AST/Interp/Floating.h
@@ -94,6 +94,7 @@
bool isMin() const { return F.isSmallest(); }
bool isMinusOne() const { return F.isExactlyValue(-1.0); }
bool isNan() const { return F.isNaN(); }
+ bool isInf() const { return F.isInfinity(); }
bool isFinite() const { return F.isFinite(); }
ComparisonCategoryResult compare(const Floating &RHS) const {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D155371.540693.patch
Type: text/x-patch
Size: 2340 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230715/f450222f/attachment.bin>
More information about the cfe-commits
mailing list