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 3 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
18 changes: 15 additions & 3 deletions clang/lib/Sema/SemaSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4846,13 +4846,12 @@ void SYCLIntegrationFooter::addVarDecl(const VarDecl *VD) {
return;
// Step 1: ensure that this is of the correct type-spec-constant template
// specialization).
if (!Util::isSyclSpecIdType(VD->getType())) {
QualType Ty = VD->getType().getCanonicalType();
if (!Util::isSyclSpecIdType(Ty)) {
// Handle the case where this could be a deduced type, such as a deduction
// guide. We have to do this here since this function, unlike most of the
// 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().getCanonicalType()))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we always want isSyclSpecIdType() to inspect the canonical type (e.g., sink the calls to getCanonicalType() into the definition of the function rather than letting the caller decide which to pass)?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we do, yes. All we care about is whether this is a spec-id type, we don't really care about whether it is wrapped in typedefs or not.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, then I'd change the implementation of isSyclSpecIdType() to do the canonicalization rather than adding the calls here. I don't care if that's a follow-up or done as part of this patch though. WDYT?

Copy link
Contributor Author

@erichkeane erichkeane Jun 10, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right here, we probably want the entire list of isNNNType functions in Util to canonicalize. I'll look into doing it in a follow-up

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

continue;

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

VisitedSpecConstants.push_back(VD);
std::string TopShim = EmitSpecIdShims(OS, ShimCounter, VD);
OS << "__SYCL_INLINE_NAMESPACE(cl) {\n";
OS << "namespace sycl {\n";
Expand Down
17 changes: 17 additions & 0 deletions clang/test/CodeGenSYCL/integration_footer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,4 +144,21 @@ 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>