Skip to content

Commit

Permalink
[SYCL] Captured enum variables are incorrect inside SYCL kernels for …
Browse files Browse the repository at this point in the history
…CPU device

Signed-off-by: Vladimir Lazarev <vladimir.lazarev@intel.com>
Signed-off-by: Melanie Blower <melanie.blower@intel.com>
  • Loading branch information
Melanie Blower authored and vladimirlaz committed Mar 22, 2019
1 parent 7edf29c commit ed0ea45
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
4 changes: 3 additions & 1 deletion clang/lib/Sema/SemaSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ CreateSYCLKernelBody(Sema &S, FunctionDecl *KernelCallerFunc, DeclContext *DC) {
CXXMemberCallExpr *Call = CXXMemberCallExpr::Create(
S.Context, ME, ParamStmts, ResultTy, VK, SourceLocation());
BodyStmts.push_back(Call);
} else if (CRD || FieldType->isBuiltinType()) {
} else if (CRD || FieldType->isScalarType()) {
// If field have built-in or a structure/class type just initialize
// this field with corresponding kernel argument using '=' binary
// operator. The structure/class type must be copy assignable - this
Expand All @@ -536,6 +536,8 @@ CreateSYCLKernelBody(Sema &S, FunctionDecl *KernelCallerFunc, DeclContext *DC) {
BinaryOperator(Lhs, Rhs, BO_Assign, FieldType, VK_LValue,
OK_Ordinary, SourceLocation(), FPOptions());
BodyStmts.push_back(Res);
} else {
llvm_unreachable("unsupported field type");
}
TargetFuncParam++;
}
Expand Down
31 changes: 31 additions & 0 deletions clang/test/SemaSYCL/spir-enum.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// 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

template <typename name, typename Func>
__attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) {
kernelFunc();
}

enum enum_type: int {
A = 0,
B = 1,
};

void test(enum_type val)
{
kernel_single_task<class kernel_function>([=]() {
//expected-warning@+1{{expression result unused}}
val;
});
}

int main() {

// CHECK: define spir_kernel void @_ZTSZ4test9enum_typeE15kernel_function(i32 %_arg_)

// CHECK: getelementptr inbounds %class.anon, %class.anon*
// CHECK: call spir_func void @"_ZZ4test9enum_typeENK3$_0clEv"(%class.anon* %0)


test( enum_type::B );
return 0;
}

0 comments on commit ed0ea45

Please sign in to comment.