Skip to content

Commit 8790576

Browse files
committed
[clang][bytecode] Add more checks to _ai32_* builtins
They are called in a few different forms that we don't support.
1 parent 602f436 commit 8790576

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

clang/lib/AST/ByteCode/InterpBuiltin.cpp

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

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

12911293
PrimType ValT = *S.Ctx.classify(Call->getArg(0));
@@ -1310,7 +1312,8 @@ static bool interp__builtin_ia32_lzcnt(InterpState &S, CodePtr OpPC,
13101312
const Function *Func,
13111313
const CallExpr *Call) {
13121314
QualType CallType = Call->getType();
1313-
if (!CallType->isIntegerType())
1315+
if (!CallType->isIntegerType() ||
1316+
!Call->getArg(0)->getType()->isIntegerType())
13141317
return false;
13151318

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

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

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

clang/test/CodeGen/builtins-hexagon.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// REQUIRES: hexagon-registered-target
22
// RUN: %clang_cc1 -triple hexagon-unknown-elf -target-cpu hexagonv65 -target-feature +hvxv65 -target-feature +hvx-length128b -emit-llvm %s -o - | FileCheck %s
3+
// RUN: %clang_cc1 -triple hexagon-unknown-elf -target-cpu hexagonv65 -target-feature +hvxv65 -target-feature +hvx-length128b -emit-llvm %s -o - -fexperimental-new-constant-interpreter | FileCheck %s
34

45
void test() {
56
int v64 __attribute__((__vector_size__(64)));

0 commit comments

Comments
 (0)