Skip to content

Commit 3590ede

Browse files
committed
[clang][Interp] Support vec_step
1 parent 4c70157 commit 3590ede

File tree

3 files changed

+47
-1
lines changed

3 files changed

+47
-1
lines changed

clang/lib/AST/Interp/ByteCodeExprGen.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,6 +1358,20 @@ bool ByteCodeExprGen<Emitter>::VisitUnaryExprOrTypeTraitExpr(
13581358
assert(E->getTypeOfArgument()->isSizelessVectorType());
13591359
}
13601360

1361+
if (Kind == UETT_VecStep) {
1362+
if (const auto *VT = E->getTypeOfArgument()->getAs<VectorType>()) {
1363+
unsigned N = VT->getNumElements();
1364+
1365+
// The vec_step built-in functions that take a 3-component
1366+
// vector return 4. (OpenCL 1.1 spec 6.11.12)
1367+
if (N == 3)
1368+
N = 4;
1369+
1370+
return this->emitConst(N, E);
1371+
}
1372+
return this->emitConst(1, E);
1373+
}
1374+
13611375
return false;
13621376
}
13631377

clang/test/AST/Interp/opencl.cl

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// RUN: %clang_cc1 -fsyntax-only -verify=ref,both %s
2+
// RUN: %clang_cc1 -fsyntax-only -verify=expected,both %s -fexperimental-new-constant-interpreter
3+
4+
// both-no-diagnostics
5+
6+
typedef int int2 __attribute__((ext_vector_type(2)));
7+
typedef int int3 __attribute__((ext_vector_type(3)));
8+
typedef int int4 __attribute__((ext_vector_type(4)));
9+
typedef int int8 __attribute__((ext_vector_type(8)));
10+
typedef int int16 __attribute__((ext_vector_type(16)));
11+
12+
void foo(int3 arg1, int8 arg2) {
13+
int4 auto1;
14+
int16 *auto2;
15+
int auto3;
16+
int2 auto4;
17+
struct S *incomplete1;
18+
19+
int res1[vec_step(arg1) == 4 ? 1 : -1];
20+
int res2[vec_step(arg2) == 8 ? 1 : -1];
21+
int res3[vec_step(auto1) == 4 ? 1 : -1];
22+
int res4[vec_step(*auto2) == 16 ? 1 : -1];
23+
int res5[vec_step(auto3) == 1 ? 1 : -1];
24+
int res6[vec_step(auto4) == 2 ? 1 : -1];
25+
int res7[vec_step(int2) == 2 ? 1 : -1];
26+
int res8[vec_step(int3) == 4 ? 1 : -1];
27+
int res9[vec_step(int4) == 4 ? 1 : -1];
28+
int res10[vec_step(int8) == 8 ? 1 : -1];
29+
int res11[vec_step(int16) == 16 ? 1 : -1];
30+
int res12[vec_step(void) == 1 ? 1 : -1];
31+
}
32+

clang/test/SemaOpenCL/vec_step.cl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s
1+
// RUN: %clang_cc1 -fsyntax-only -pedantic -verify %s -fexperimental-new-constant-interpreter
22

33
typedef int int2 __attribute__((ext_vector_type(2)));
44
typedef int int3 __attribute__((ext_vector_type(3)));

0 commit comments

Comments
 (0)