Skip to content

Commit

Permalink
[SYCL] Add initialization captured lambda variables of built-in types.
Browse files Browse the repository at this point in the history
Signed-off-by: Vladimir Lazarev <vladimir.lazarev@intel.com>
  • Loading branch information
vladimirlaz committed Jan 22, 2019
1 parent bab1e6a commit f037419
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion clang/lib/Sema/SemaSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,8 @@ CompoundStmt *CreateSYCLKernelBody(Sema &S, FunctionDecl *KernelHelper,
SourceLocation(), *TargetFuncParam, false,
DeclarationNameInfo(), ParamType, VK_LValue);

CXXRecordDecl *CRD = Field->getType()->getAsCXXRecordDecl();
QualType FieldType = Field->getType();
CXXRecordDecl *CRD = FieldType->getAsCXXRecordDecl();
if (CRD) {
llvm::SmallVector<Expr *, 16> ParamStmts;
DeclAccessPair FieldDAP = DeclAccessPair::make(Field, AS_none);
Expand Down Expand Up @@ -205,6 +206,22 @@ CompoundStmt *CreateSYCLKernelBody(Sema &S, FunctionDecl *KernelHelper,
BodyStmts.push_back(Call);
}
}
} else if (FieldType->isBuiltinType()) {
// If field have built-in type just initialize this field
// with corresponding kernel argument using '=' binary operator.
DeclAccessPair FieldDAP = DeclAccessPair::make(Field, AS_none);
auto Lhs = MemberExpr::Create(
S.Context, LambdaDRE, false, SourceLocation(),
NestedNameSpecifierLoc(), SourceLocation(), Field, FieldDAP,
DeclarationNameInfo(Field->getDeclName(), SourceLocation()),
nullptr, Field->getType(), VK_LValue, OK_Ordinary);
auto Rhs = ImplicitCastExpr::Create(
S.Context, ParamType, CK_LValueToRValue, DRE, nullptr, VK_RValue);
// lambda.field = kernel_parameter
Expr *Res = new (S.Context)
BinaryOperator(Lhs, Rhs, BO_Assign, FieldType, VK_LValue,
OK_Ordinary, SourceLocation(), FPOptions());
BodyStmts.push_back(Res);
}
TargetFuncParam++;
}
Expand Down

0 comments on commit f037419

Please sign in to comment.