Skip to content

Commit f71a1d5

Browse files
author
Erich Keane
authored
[SYCL] Omit TemplatedDecl from int-footer for a VarTemplateDecl (#4108)
The hook we had always added the VarDecl when it was visited, however when evaluating a VarTemplateDecl, Clang creates a VarDecl to represent the declaration as a child of the VarTemplateDecl. We don't need to capture it in our collection since the VarTemplateSpecializationDecl will provide the info we need. If we DON'T do this, we end up having 2 specializations for the specialization_id, one of which is invalid.
1 parent 5c0f748 commit f71a1d5

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

clang/lib/Sema/SemaTemplateInstantiateDecl.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1421,7 +1421,10 @@ Decl *TemplateDeclInstantiator::VisitVarDecl(VarDecl *D,
14211421
if (Var->isStaticLocal())
14221422
SemaRef.CheckStaticLocalForDllExport(Var);
14231423

1424-
SemaRef.addSyclVarDecl(Var);
1424+
// Only add this if we aren't instantiating a variable template. We'll end up
1425+
// adding the VarTemplateSpecializationDecl later.
1426+
if (!InstantiatingVarTemplate)
1427+
SemaRef.addSyclVarDecl(Var);
14251428
return Var;
14261429
}
14271430

clang/test/CodeGenSYCL/integration_footer.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,4 +190,14 @@ auto x = HasVarTemplate::VarTempl<int, 2>.getDefaultValue();
190190
// CHECK-NEXT: } // namespace sycl
191191
// CHECK-NEXT: } // __SYCL_INLINE_NAMESPACE(cl)
192192

193+
template <typename T> struct GlobalWrapper {
194+
template<int Value> static constexpr specialization_id<T> sc{Value};
195+
};
196+
197+
auto &y = GlobalWrapper<int>::template sc<20>;
198+
199+
// Should not generate the uninstantiated template.
200+
// CHECK-NOT: inline const char *get_spec_constant_symbolic_ID_impl<::GlobalWrapper<int>::sc>()
201+
// CHECK: inline const char *get_spec_constant_symbolic_ID_impl<::GlobalWrapper<int>::sc<20>>()
202+
193203
// CHECK: #include <CL/sycl/detail/spec_const_integration.hpp>

0 commit comments

Comments
 (0)