Skip to content

Commit ed0ea45

Browse files
Melanie Blowervladimirlaz
Melanie Blower
authored andcommitted
[SYCL] Captured enum variables are incorrect inside SYCL kernels for CPU device
Signed-off-by: Vladimir Lazarev <[email protected]> Signed-off-by: Melanie Blower <[email protected]>
1 parent 7edf29c commit ed0ea45

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ CreateSYCLKernelBody(Sema &S, FunctionDecl *KernelCallerFunc, DeclContext *DC) {
513513
CXXMemberCallExpr *Call = CXXMemberCallExpr::Create(
514514
S.Context, ME, ParamStmts, ResultTy, VK, SourceLocation());
515515
BodyStmts.push_back(Call);
516-
} else if (CRD || FieldType->isBuiltinType()) {
516+
} else if (CRD || FieldType->isScalarType()) {
517517
// If field have built-in or a structure/class type just initialize
518518
// this field with corresponding kernel argument using '=' binary
519519
// operator. The structure/class type must be copy assignable - this
@@ -536,6 +536,8 @@ CreateSYCLKernelBody(Sema &S, FunctionDecl *KernelCallerFunc, DeclContext *DC) {
536536
BinaryOperator(Lhs, Rhs, BO_Assign, FieldType, VK_LValue,
537537
OK_Ordinary, SourceLocation(), FPOptions());
538538
BodyStmts.push_back(Res);
539+
} else {
540+
llvm_unreachable("unsupported field type");
539541
}
540542
TargetFuncParam++;
541543
}

clang/test/SemaSYCL/spir-enum.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// RUN: %clang_cc1 -triple spir64-unknown-linux-sycldevice -std=c++11 -fsycl-is-device -disable-llvm-optzns -disable-llvm-passes -S -emit-llvm -x c++ %s -o - | FileCheck %s
2+
3+
template <typename name, typename Func>
4+
__attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) {
5+
kernelFunc();
6+
}
7+
8+
enum enum_type: int {
9+
A = 0,
10+
B = 1,
11+
};
12+
13+
void test(enum_type val)
14+
{
15+
kernel_single_task<class kernel_function>([=]() {
16+
//expected-warning@+1{{expression result unused}}
17+
val;
18+
});
19+
}
20+
21+
int main() {
22+
23+
// CHECK: define spir_kernel void @_ZTSZ4test9enum_typeE15kernel_function(i32 %_arg_)
24+
25+
// CHECK: getelementptr inbounds %class.anon, %class.anon*
26+
// CHECK: call spir_func void @"_ZZ4test9enum_typeENK3$_0clEv"(%class.anon* %0)
27+
28+
29+
test( enum_type::B );
30+
return 0;
31+
}

0 commit comments

Comments
 (0)