Skip to content

Commit

Permalink
Modify handling of SYCL special types to account for default construc…
Browse files Browse the repository at this point in the history
…tor access specifier
  • Loading branch information
lbushi25 committed Nov 8, 2024
1 parent d6709ed commit 847163d
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions clang/lib/Sema/SemaSYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3950,13 +3950,28 @@ class SyclKernelBodyCreator : public SyclKernelFieldHandler {
}

// Default inits the type, then calls the init-method in the body.
// A type may not have a public private default constructor as per its spec so
// typically the default constructor will be private and in such cases we must
// manually override the access specifier from private to public just for the
// duration of this default initialization.
bool handleSpecialType(FieldDecl *FD, QualType Ty) {
const auto *RecordDecl = Ty->getAsCXXRecordDecl();
AccessSpecifier default_constructor_access;
CXXConstructorDecl *default_constructor;
std::for_each(RecordDecl->ctor_begin(), RecordDecl->ctor_end(),
[&](auto elem) {
if (elem->isDefaultConstructor()) {
default_constructor_access = elem->getAccess();
elem->setAccess(AS_public);
default_constructor = elem;
}
});

addFieldInit(FD, Ty, std::nullopt,
InitializationKind::CreateDefault(KernelCallerSrcLoc));

default_constructor->setAccess(default_constructor_access);
addFieldMemberExpr(FD, Ty);

const auto *RecordDecl = Ty->getAsCXXRecordDecl();
createSpecialMethodCall(RecordDecl, getInitMethodName(), BodyStmts);
CXXMethodDecl *FinalizeMethod =
getMethodByName(RecordDecl, FinalizeMethodName);
Expand Down

0 comments on commit 847163d

Please sign in to comment.