[PATCH] D155371: [clang][Interp] Implement __builtin_isinf

Timm Bäder via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Jul 30 23:49:58 PDT 2023


This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG72450a77937c: [clang][Interp] Implement __builtin_isinf (authored by tbaeder).

Changed prior to commit:
  https://reviews.llvm.org/D155371?vs=540693&id=545515#toc

Repository:
  rG LLVM Github Monorepo

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
@@ -72,3 +72,8 @@
   constexpr float min3 = __builtin_fmin(__builtin_inf(), __builtin_nan(""));
   static_assert(min3 == __builtin_inf(), "");
 }
+
+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
@@ -173,6 +173,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;
@@ -239,6 +253,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
@@ -87,6 +87,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.545515.patch
Type: text/x-patch
Size: 2333 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230731/9e27beba/attachment.bin>


More information about the cfe-commits mailing list