Skip to content

Commit 4f6a246

Browse files
authored
[SYCL] Handle non-type template parameters in integration headers (#18914)
A recent community change llvm/llvm-project#124858 affected how we render some non-type template parameters in the integration header. We were generating malformed arguments of the form 'value-parameter-0-1', which obviously led to compilation errors when including the header in host compilations.
1 parent 6e92e5f commit 4f6a246

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

clang/lib/AST/StmtPrinter.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,8 +1316,9 @@ void StmtPrinter::VisitDeclRefExpr(DeclRefExpr *Node) {
13161316
if (Node->hasTemplateKeyword())
13171317
OS << "template ";
13181318

1319-
bool ForceAnonymous =
1320-
Policy.PrintAsCanonical && VD->getKind() == Decl::NonTypeTemplateParm;
1319+
bool ForceAnonymous = Policy.PrintAsCanonical &&
1320+
!Policy.SkipCanonicalizationOfTemplateTypeParms &&
1321+
VD->getKind() == Decl::NonTypeTemplateParm;
13211322
DeclarationNameInfo NameInfo = Node->getNameInfo();
13221323
if (IdentifierInfo *ID = NameInfo.getName().getAsIdentifierInfo();
13231324
!ForceAnonymous &&

clang/test/CodeGenSYCL/int_header_nttp.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// CHECK: Forward declarations of templated kernel function types:
99
// CHECK-NEXT: template <typename T, T nttp> struct SelfReferentialNTTP;
1010
// CHECK-NEXT: template <typename U, int nttp> struct NonSelfRef;
11+
// CHECK-NEXT: template <int N> struct alignas(N) OpaqueType;
1112

1213
template<typename T, T nttp>
1314
struct SelfReferentialNTTP {};
@@ -17,7 +18,15 @@ using Foo = int;
1718
template<typename U, Foo nttp>
1819
struct NonSelfRef {};
1920

21+
template <int N> struct alignas(N) OpaqueType {
22+
char data[N];
23+
};
24+
template <typename T> class Kernel;
25+
2026
void foo() {
21-
sycl::kernel_single_task<SelfReferentialNTTP<int, 1>>([](){});
22-
sycl::kernel_single_task<NonSelfRef<int, 1>>([](){});
27+
auto Lambda = [](){};
28+
sycl::kernel_single_task<SelfReferentialNTTP<int, 1>>(Lambda);
29+
sycl::kernel_single_task<NonSelfRef<int, 1>>(Lambda);
30+
using scalar_t = OpaqueType<sizeof(int)>;
31+
sycl::kernel_single_task<class Kernel<scalar_t>>(Lambda);
2332
}

0 commit comments

Comments
 (0)