Skip to content

Commit 63814e3

Browse files
author
Erich Keane
authored
[SYCL] Ensure int-header fwd decls work with references (#4281)
We weren't properly descending down into reference types, so we ended up not forward declaring any types that were referred to only as a reference type. This patch ensures we do so, just like we did with pointer-type.
1 parent 9eb3222 commit 63814e3

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4482,6 +4482,12 @@ class SYCLFwdDeclEmitter
44824482
InnerTypeVisitor::Visit(T.getTypePtr());
44834483
}
44844484

4485+
void VisitReferenceType(const ReferenceType *RT) {
4486+
// Our forward declarations don't care about references, so we should just
4487+
// ignore the reference and continue on.
4488+
Visit(RT->getPointeeType());
4489+
}
4490+
44854491
void Visit(const TemplateArgument &TA) {
44864492
if (TA.isNull())
44874493
return;
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// RUN: %clang_cc1 -fsycl-is-device -internal-isystem %S/Inputs -sycl-std=2020 -fsycl-int-header=%t.h %s -o %t.out
2+
// RUN: FileCheck -input-file=%t.h %s
3+
4+
// This test validates that we handle reference types properly in forward
5+
// declarations, the bug was that the PassedAsRefType didn't get forward
6+
// declared, so it resulted in a compile error during host compile. SO, we make
7+
// sure that we properly forward declare the type (and any template children!).
8+
9+
#include <sycl.hpp>
10+
11+
// CHECK: // Forward declarations of templated kernel function types:
12+
// CHECK-NEXT: namespace WrapsType {
13+
// CHECK-NEXT: struct InsidePassedAsRef;
14+
// CHECK-NEXT: }
15+
// CHECK: namespace WrapsType {
16+
// CHECK-NEXT: template <typename T> struct PassedAsRef;
17+
// CHECK-NEXT: }
18+
// CHECK: template <typename T> class Wrapper;
19+
20+
namespace WrapsType {
21+
struct InsidePassedAsRef{};
22+
template<typename T>
23+
struct PassedAsRef{};
24+
}
25+
26+
template<typename T>
27+
class Wrapper{};
28+
29+
void foo() {
30+
using namespace WrapsType;
31+
using KernelName = Wrapper<PassedAsRef<InsidePassedAsRef>&>;
32+
sycl::kernel_single_task<KernelName>([]{});
33+
}

0 commit comments

Comments
 (0)