Skip to content

Commit 5d8a731

Browse files
committed
[clang][Interp] Support __builtin_eh_return_data_regno
1 parent 5c84054 commit 5d8a731

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

clang/lib/AST/Interp/InterpBuiltin.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,19 @@ static bool interp__builtin_move(InterpState &S, CodePtr OpPC,
645645
return Func->getDecl()->isConstexpr();
646646
}
647647

648+
static bool interp__builtin_eh_return_data_regno(InterpState &S, CodePtr OpPC,
649+
const InterpFrame *Frame,
650+
const Function *Func,
651+
const CallExpr *Call) {
652+
PrimType ArgT = *S.getContext().classify(Call->getArg(0)->getType());
653+
APSInt Arg = peekToAPSInt(S.Stk, ArgT);
654+
655+
int Result =
656+
S.getCtx().getTargetInfo().getEHDataRegisterNumber(Arg.getZExtValue());
657+
pushInt(S, Result);
658+
return true;
659+
}
660+
648661
bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
649662
const CallExpr *Call) {
650663
InterpFrame *Frame = S.Current;
@@ -869,6 +882,11 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const Function *F,
869882
return false;
870883
break;
871884

885+
case Builtin::BI__builtin_eh_return_data_regno:
886+
if (!interp__builtin_eh_return_data_regno(S, OpPC, Frame, F, Call))
887+
return false;
888+
break;
889+
872890
default:
873891
return false;
874892
}

clang/test/AST/Interp/builtin-functions.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -363,3 +363,16 @@ namespace ffs {
363363
char ffs6[__builtin_ffsl(0x10L) == 5 ? 1 : -1];
364364
char ffs7[__builtin_ffsll(0x100LL) == 9 ? 1 : -1];
365365
}
366+
367+
namespace EhReturnDataRegno {
368+
void test11(int X) {
369+
switch (X) {
370+
case __builtin_eh_return_data_regno(0): // constant foldable.
371+
break;
372+
}
373+
374+
__builtin_eh_return_data_regno(X); // expected-error {{argument to '__builtin_eh_return_data_regno' must be a constant integer}} \
375+
// ref-error {{argument to '__builtin_eh_return_data_regno' must be a constant integer}}
376+
377+
}
378+
}

0 commit comments

Comments
 (0)