Skip to content

[SYCL] Ensure int-header fwd decls work with references #4281

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 11, 2021
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
6 changes: 6 additions & 0 deletions clang/lib/Sema/SemaSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4459,6 +4459,12 @@ class SYCLFwdDeclEmitter
InnerTypeVisitor::Visit(T.getTypePtr());
}

void VisitReferenceType(const ReferenceType *RT) {
// Our forward declarations don't care about references, so we should just
// ignore the reference and continue on.
Visit(RT->getPointeeType());
}

void Visit(const TemplateArgument &TA) {
if (TA.isNull())
return;
Expand Down
33 changes: 33 additions & 0 deletions clang/test/CodeGenSYCL/int_header_reference_fwd_decl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// RUN: %clang_cc1 -fsycl-is-device -internal-isystem %S/Inputs -sycl-std=2020 -fsycl-int-header=%t.h %s -o %t.out
// RUN: FileCheck -input-file=%t.h %s

// This test validates that we handle reference types properly in forward
// declarations, the bug was that the PassedAsRefType didn't get forward
// declared, so it resulted in a compile error during host compile. SO, we make
// sure that we properly forward declare the type (and any template children!).

#include <sycl.hpp>

// CHECK: // Forward declarations of templated kernel function types:
// CHECK-NEXT: namespace WrapsType {
// CHECK-NEXT: struct InsidePassedAsRef;
// CHECK-NEXT: }
// CHECK: namespace WrapsType {
// CHECK-NEXT: template <typename T> struct PassedAsRef;
// CHECK-NEXT: }
// CHECK: template <typename T> class Wrapper;

namespace WrapsType {
struct InsidePassedAsRef{};
template<typename T>
struct PassedAsRef{};
}

template<typename T>
class Wrapper{};

void foo() {
using namespace WrapsType;
using KernelName = Wrapper<PassedAsRef<InsidePassedAsRef>&>;
sycl::kernel_single_task<KernelName>([]{});
}