Skip to content

Commit

Permalink
[clang][bytecode] Make sure ia32_bzhi input is an integer
Browse files Browse the repository at this point in the history
  • Loading branch information
tbaederr committed Oct 8, 2024
1 parent 5cfc6bc commit bca04d7
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions clang/lib/AST/ByteCode/InterpBuiltin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1184,6 +1184,10 @@ static bool interp__builtin_ia32_bzhi(InterpState &S, CodePtr OpPC,
const InterpFrame *Frame,
const Function *Func,
const CallExpr *Call) {
QualType CallType = Call->getType();
if (!CallType->isIntegerType())
return false;

PrimType ValT = *S.Ctx.classify(Call->getArg(0));
PrimType IndexT = *S.Ctx.classify(Call->getArg(1));

Expand All @@ -1197,7 +1201,7 @@ static bool interp__builtin_ia32_bzhi(InterpState &S, CodePtr OpPC,
if (Index < BitWidth)
Val.clearHighBits(BitWidth - Index);

pushInteger(S, Val, Call->getType());
pushInteger(S, Val, CallType);
return true;
}

Expand All @@ -1210,7 +1214,7 @@ static bool interp__builtin_ia32_lzcnt(InterpState &S, CodePtr OpPC,
return false;

APSInt Val = peekToAPSInt(S.Stk, *S.Ctx.classify(Call->getArg(0)));
pushInteger(S, Val.countLeadingZeros(), Call->getType());
pushInteger(S, Val.countLeadingZeros(), CallType);
return true;
}

Expand All @@ -1223,7 +1227,7 @@ static bool interp__builtin_ia32_tzcnt(InterpState &S, CodePtr OpPC,
return false;

APSInt Val = peekToAPSInt(S.Stk, *S.Ctx.classify(Call->getArg(0)));
pushInteger(S, Val.countTrailingZeros(), Call->getType());
pushInteger(S, Val.countTrailingZeros(), CallType);
return true;
}

Expand Down

0 comments on commit bca04d7

Please sign in to comment.