@@ -56,6 +56,20 @@ static APSInt popToAPSInt(InterpState &S, QualType T) {
5656 return popToAPSInt (S.Stk , *S.getContext ().classify (T));
5757}
5858
59+ static APInt ROTL_fn (const APSInt &A, const APSInt &B) {
60+ const APInt &X = static_cast <const APInt &>(A);
61+ const unsigned BW = X.getBitWidth ();
62+ const uint64_t Amt = B.getZExtValue ();
63+ return X.rotl (static_cast <unsigned >(Amt % BW));
64+ }
65+
66+ static APInt ROTR_fn (const APSInt &A, const APSInt &B) {
67+ const APInt &X = static_cast <const APInt &>(A);
68+ const unsigned BW = X.getBitWidth ();
69+ const uint64_t Amt = B.getZExtValue ();
70+ return X.rotr (static_cast <unsigned >(Amt % BW));
71+ }
72+
5973// / Pushes \p Val on the stack as the type given by \p QT.
6074static void pushInteger (InterpState &S, const APSInt &Val, QualType QT) {
6175 assert (QT->isSignedIntegerOrEnumerationType () ||
@@ -3162,7 +3176,7 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
31623176 case Builtin::BI_rotl:
31633177 case Builtin::BI_lrotl:
31643178 case Builtin::BI_rotl64:
3165- return interp__builtin_rotate (S, OpPC, Frame, Call, /* Right= */ false );
3179+ return interp__builtin_elementwise_int_binop (S, OpPC, Call, ROTL_fn );
31663180
31673181 case Builtin::BI__builtin_rotateright8:
31683182 case Builtin::BI__builtin_rotateright16:
@@ -3173,7 +3187,7 @@ bool InterpretBuiltin(InterpState &S, CodePtr OpPC, const CallExpr *Call,
31733187 case Builtin::BI_rotr:
31743188 case Builtin::BI_lrotr:
31753189 case Builtin::BI_rotr64:
3176- return interp__builtin_rotate (S, OpPC, Frame, Call, /* Right= */ true );
3190+ return interp__builtin_elementwise_int_binop (S, OpPC, Call, ROTR_fn );
31773191
31783192 case Builtin::BI__builtin_ffs:
31793193 case Builtin::BI__builtin_ffsl:
0 commit comments