Skip to content

[SYCL] Fix int-footer spec-const generation for deduced types. #3908

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 8 commits into from
Jun 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
14 changes: 13 additions & 1 deletion clang/lib/Sema/SemaSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4852,7 +4852,6 @@ void SYCLIntegrationFooter::addVarDecl(const VarDecl *VD) {
// rest of this file, is called during Sema instead of after it. We will
// also have to filter out after deduction later.
QualType Ty = VD->getType().getCanonicalType();

if (!Ty->isUndeducedType())
return;
}
Expand Down Expand Up @@ -5024,11 +5023,24 @@ bool SYCLIntegrationFooter::emit(raw_ostream &OS) {
Policy.SuppressTypedefs = true;
Policy.SuppressUnwrittenScope = true;

llvm::SmallSet<const VarDecl *, 8> VisitedSpecConstants;

// Used to uniquely name the 'shim's as we generate the names in each
// anonymous namespace.
unsigned ShimCounter = 0;
for (const VarDecl *VD : SpecConstants) {
VD = VD->getCanonicalDecl();

// Skip if this isn't a SpecIdType. This can happen if it was a deduced
// type.
if (!Util::isSyclSpecIdType(VD->getType()))
continue;

// Skip if we've already visited this.
if (llvm::find(VisitedSpecConstants, VD) != VisitedSpecConstants.end())
continue;

VisitedSpecConstants.insert(VD);
std::string TopShim = EmitSpecIdShims(OS, ShimCounter, VD);
OS << "__SYCL_INLINE_NAMESPACE(cl) {\n";
OS << "namespace sycl {\n";
Expand Down
15 changes: 15 additions & 0 deletions clang/test/CodeGenSYCL/integration_footer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,19 @@ specialization_id<int> AnonNSSpecID;

} // namespace Foo

// make sure we don't emit a deduced type that isn't a spec constant.
enum SomeEnum { SE_A };
enum AnotherEnum : unsigned int { AE_A };

template<SomeEnum E> struct GetThing{};
template<> struct GetThing<SE_A>{
static constexpr auto thing = AE_A;
};

struct container {
static constexpr auto Thing = GetThing<SE_A>::thing;
};
// CHECK-NOT: ::GetThing
// CHECK-NOT: ::container::Thing

// CHECK: #include <CL/sycl/detail/spec_const_integration.hpp>