Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions clang/lib/Sema/SemaSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,12 +385,23 @@ class KernelBodyTransform : public TreeTransform<KernelBodyTransform> {
auto NewDecl = MappingPair.second;
return DeclRefExpr::Create(
SemaRef.getASTContext(), DRE->getQualifierLoc(),
DRE->getTemplateKeywordLoc(), NewDecl, false, DRE->getNameInfo(),
DRE->getTemplateKeywordLoc(), NewDecl, false,
DeclarationNameInfo(DRE->getNameInfo().getName(), SourceLocation(),
DRE->getNameInfo().getInfo()),
NewDecl->getType(), DRE->getValueKind());
}
return DRE;
}

StmtResult RebuildCompoundStmt(SourceLocation LBraceLoc,
MultiStmtArg Statements,
SourceLocation RBraceLoc,
bool IsStmtExpr) {
// Build a new compound statement but clear the source locations.
return getSema().ActOnCompoundStmt(SourceLocation(), SourceLocation(),
Statements, IsStmtExpr);
}

private:
std::pair<DeclaratorDecl *, DeclaratorDecl *> MappingPair;
Sema &SemaRef;
Expand Down Expand Up @@ -520,8 +531,8 @@ static CompoundStmt *CreateOpenCLKernelBody(Sema &S,
auto ME = MemberExpr::Create(
S.Context, SpecialObjME, false, SourceLocation(),
NestedNameSpecifierLoc(), SourceLocation(), InitMethod, MethodDAP,
InitMethod->getNameInfo(), nullptr, InitMethod->getType(),
VK_LValue, OK_Ordinary);
DeclarationNameInfo(InitMethod->getDeclName(), SourceLocation()),
nullptr, InitMethod->getType(), VK_LValue, OK_Ordinary);

// Not referenced -> not emitted
S.MarkFunctionReferenced(SourceLocation(), InitMethod, true);
Expand Down
39 changes: 23 additions & 16 deletions clang/test/CodeGenSYCL/debug-info-srcpos-kernel.cpp
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
// RUN: DISABLE_INFER_AS=1 %clang --sycl %s -S -emit-llvm -g -o - | FileCheck %s --check-prefixes CHECK,CHECK-OLD
// RUN: %clang --sycl %s -S -emit-llvm -g -o - | FileCheck %s --check-prefixes CHECK,CHECK-NEW
// RUN: %clang --sycl %s -S -I %S/Inputs -emit-llvm -g -o - | FileCheck %s
//
// Verify the SYCL kernel routine is marked artificial.
// Verify the SYCL kernel routine is marked artificial and has no source
// correlation.
//
// Since it has no source correlation of its own, the SYCL kernel needs to be
// marked artificial or it will inherit source correlation from the surrounding
// code.
// The SYCL kernel should have no source correlation of its own, so it needs
// to be marked artificial or it will inherit source correlation from the
// surrounding code.
//

template <typename Name, typename Func>
__attribute__((sycl_kernel)) void kernel_single_task(Func kernelFunc) {
#include <sycl.hpp>

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

int main() {
int value = 0;
int* captured = &value;
kernel_single_task<class kernel_function>([=]() {
*captured = 1;
});
cl::sycl::sampler Sampler;
kernel<class use_kernel_for_test>([=]() {
Sampler.use();
});
return 0;
}

// CHECK-OLD: define{{.*}} spir_kernel {{.*}}void @_ZTSZ4mainE15kernel_function(i32*{{.*}}){{.*}} !dbg [[KERNEL:![0-9]+]] {{.*}}{
// CHECK-NEW: define{{.*}} spir_kernel {{.*}}void @_ZTSZ4mainE15kernel_function(i32 addrspace(4)*{{.*}}){{.*}} !dbg [[KERNEL:![0-9]+]] {{.*}}{
// CHECK: define{{.*}} spir_kernel {{.*}}19use_kernel_for_test({{.*}}){{.*}} !dbg [[KERNEL:![0-9]+]] {{.*}}{
// CHECK: getelementptr inbounds %"class.{{.*}}.anon"{{.*}} !dbg [[LINE_A0:![0-9]+]]
// CHECK: call spir_func void {{.*}}6__init{{.*}} !dbg [[LINE_A0]]
// CHECK: call spir_func void @"_ZZ4mainENK3$_0clEv"{{.*}} !dbg [[LINE_B0:![0-9]+]]
// CHECK: ret void, !dbg [[LINE_A0]]
// CHECK: [[FILE:![0-9]+]] = !DIFile(filename: "{{.*}}debug-info-srcpos-kernel.cpp"{{.*}})
// CHECK: [[KERNEL]] = {{.*}}!DISubprogram(name: "_ZTSZ4mainE15kernel_function"
// CHECK: [[KERNEL]] = {{.*}}!DISubprogram(name: "{{.*}}19use_kernel_for_test"
// CHECK-SAME: scope: [[FILE]]
// CHECK-SAME: file: [[FILE]]
// CHECK-SAME: flags: DIFlagArtificial | DIFlagPrototyped
// CHECK: [[LINE_A0]] = !DILocation(line: 0
// CHECK: [[LINE_B0]] = !DILocation(line: 0