Skip to content

Commit

Permalink
[clang][Interp] Implement __builtin_isfinite
Browse files Browse the repository at this point in the history
Differential Revision: https://reviews.llvm.org/D155372
  • Loading branch information
tbaederr committed Jul 31, 2023
1 parent 5962942 commit f444f39
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
14 changes: 14 additions & 0 deletions clang/lib/AST/Interp/InterpBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
3 changes: 3 additions & 0 deletions clang/test/AST/Interp/builtin-functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()), "");
}

0 comments on commit f444f39

Please sign in to comment.