Skip to content

Commit c6b5c08

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 c6b5c08

File tree

2 files changed

+10
-6
lines changed

2 files changed

+10
-6
lines changed

clang/lib/AST/ByteCode/InterpBuiltin.cpp

Lines changed: 9 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() != 0 || !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,7 @@ 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() || Call->getArg(0)->getType()->isIntegerType())
13141316
return false;
13151317

13161318
APSInt Val = peekToAPSInt(S.Stk, *S.Ctx.classify(Call->getArg(0)));
@@ -1323,7 +1325,8 @@ static bool interp__builtin_ia32_tzcnt(InterpState &S, CodePtr OpPC,
13231325
const Function *Func,
13241326
const CallExpr *Call) {
13251327
QualType CallType = Call->getType();
1326-
if (!CallType->isIntegerType())
1328+
if (!CallType->isIntegerType() ||
1329+
!Call->getArg(0)->getType()->isIntegerType())
13271330
return false;
13281331

13291332
APSInt Val = peekToAPSInt(S.Stk, *S.Ctx.classify(Call->getArg(0)));
@@ -1335,7 +1338,7 @@ static bool interp__builtin_ia32_pdep(InterpState &S, CodePtr OpPC,
13351338
const InterpFrame *Frame,
13361339
const Function *Func,
13371340
const CallExpr *Call) {
1338-
if (!Call->getArg(0)->getType()->isIntegerType() ||
1341+
if (Call->getNumArgs() != 2 || !Call->getArg(0)->getType()->isIntegerType() ||
13391342
!Call->getArg(1)->getType()->isIntegerType())
13401343
return false;
13411344

@@ -1360,7 +1363,7 @@ static bool interp__builtin_ia32_pext(InterpState &S, CodePtr OpPC,
13601363
const InterpFrame *Frame,
13611364
const Function *Func,
13621365
const CallExpr *Call) {
1363-
if (!Call->getArg(0)->getType()->isIntegerType() ||
1366+
if (Call->getNumArgs() != 2 || !Call->getArg(0)->getType()->isIntegerType() ||
13641367
!Call->getArg(1)->getType()->isIntegerType())
13651368
return false;
13661369

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 - | FileCheck %s -fexperimental-new-constant-interpreter
34

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

0 commit comments

Comments
 (0)