Skip to content

Commit 847163d

Browse files
committed
Modify handling of SYCL special types to account for default constructor access specifier
1 parent d6709ed commit 847163d

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

clang/lib/Sema/SemaSYCL.cpp

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3950,13 +3950,28 @@ class SyclKernelBodyCreator : public SyclKernelFieldHandler {
39503950
}
39513951

39523952
// Default inits the type, then calls the init-method in the body.
3953+
// A type may not have a public private default constructor as per its spec so
3954+
// typically the default constructor will be private and in such cases we must
3955+
// manually override the access specifier from private to public just for the
3956+
// duration of this default initialization.
39533957
bool handleSpecialType(FieldDecl *FD, QualType Ty) {
3958+
const auto *RecordDecl = Ty->getAsCXXRecordDecl();
3959+
AccessSpecifier default_constructor_access;
3960+
CXXConstructorDecl *default_constructor;
3961+
std::for_each(RecordDecl->ctor_begin(), RecordDecl->ctor_end(),
3962+
[&](auto elem) {
3963+
if (elem->isDefaultConstructor()) {
3964+
default_constructor_access = elem->getAccess();
3965+
elem->setAccess(AS_public);
3966+
default_constructor = elem;
3967+
}
3968+
});
3969+
39543970
addFieldInit(FD, Ty, std::nullopt,
39553971
InitializationKind::CreateDefault(KernelCallerSrcLoc));
3956-
3972+
default_constructor->setAccess(default_constructor_access);
39573973
addFieldMemberExpr(FD, Ty);
39583974

3959-
const auto *RecordDecl = Ty->getAsCXXRecordDecl();
39603975
createSpecialMethodCall(RecordDecl, getInitMethodName(), BodyStmts);
39613976
CXXMethodDecl *FinalizeMethod =
39623977
getMethodByName(RecordDecl, FinalizeMethodName);

0 commit comments

Comments
 (0)