Skip to content

Commit 8951b51

Browse files
authored
[clang][bytecode] Add more checks to _ai32_* builtins (#114412)
They are called in a few different forms that we don't support.
1 parent e4aeeba commit 8951b51

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1254,7 +1254,7 @@ static bool interp__builtin_ia32_bextr(InterpState &S, CodePtr OpPC,
12541254
const InterpFrame *Frame,
12551255
const Function *Func,
12561256
const CallExpr *Call) {
1257-
if (!Call->getArg(0)->getType()->isIntegerType() ||
1257+
if (Call->getNumArgs() != 2 || !Call->getArg(0)->getType()->isIntegerType() ||
12581258
!Call->getArg(1)->getType()->isIntegerType())
12591259
return false;
12601260

@@ -1286,7 +1286,9 @@ static bool interp__builtin_ia32_bzhi(InterpState &S, CodePtr OpPC,
12861286
const Function *Func,
12871287
const CallExpr *Call) {
12881288
QualType CallType = Call->getType();
1289-
if (!CallType->isIntegerType())
1289+
if (Call->getNumArgs() != 2 || !Call->getArg(0)->getType()->isIntegerType() ||
1290+
!Call->getArg(1)->getType()->isIntegerType() ||
1291+
!CallType->isIntegerType())
12901292
return false;
12911293

12921294
PrimType ValT = *S.Ctx.classify(Call->getArg(0));
@@ -1311,7 +1313,8 @@ static bool interp__builtin_ia32_lzcnt(InterpState &S, CodePtr OpPC,
13111313
const Function *Func,
13121314
const CallExpr *Call) {
13131315
QualType CallType = Call->getType();
1314-
if (!CallType->isIntegerType())
1316+
if (!CallType->isIntegerType() ||
1317+
!Call->getArg(0)->getType()->isIntegerType())
13151318
return false;
13161319

13171320
APSInt Val = peekToAPSInt(S.Stk, *S.Ctx.classify(Call->getArg(0)));
@@ -1324,7 +1327,8 @@ static bool interp__builtin_ia32_tzcnt(InterpState &S, CodePtr OpPC,
13241327
const Function *Func,
13251328
const CallExpr *Call) {
13261329
QualType CallType = Call->getType();
1327-
if (!CallType->isIntegerType())
1330+
if (!CallType->isIntegerType() ||
1331+
!Call->getArg(0)->getType()->isIntegerType())
13281332
return false;
13291333

13301334
APSInt Val = peekToAPSInt(S.Stk, *S.Ctx.classify(Call->getArg(0)));
@@ -1336,7 +1340,7 @@ static bool interp__builtin_ia32_pdep(InterpState &S, CodePtr OpPC,
13361340
const InterpFrame *Frame,
13371341
const Function *Func,
13381342
const CallExpr *Call) {
1339-
if (!Call->getArg(0)->getType()->isIntegerType() ||
1343+
if (Call->getNumArgs() != 2 || !Call->getArg(0)->getType()->isIntegerType() ||
13401344
!Call->getArg(1)->getType()->isIntegerType())
13411345
return false;
13421346

@@ -1361,7 +1365,7 @@ static bool interp__builtin_ia32_pext(InterpState &S, CodePtr OpPC,
13611365
const InterpFrame *Frame,
13621366
const Function *Func,
13631367
const CallExpr *Call) {
1364-
if (!Call->getArg(0)->getType()->isIntegerType() ||
1368+
if (Call->getNumArgs() != 2 || !Call->getArg(0)->getType()->isIntegerType() ||
13651369
!Call->getArg(1)->getType()->isIntegerType())
13661370
return false;
13671371

0 commit comments

Comments
 (0)