@@ -3950,13 +3950,26 @@ 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 default constructor as per its spec so
3954+ // typically if this is the case the default constructor will be private and
3955+ // in such cases we must manually override the access specifier from private
3956+ // to public just for the duration of this default initialization.
3957+ // TODO: Revisit this approach once https://github.com/intel/llvm/issues/16061
3958+ // is closed.
39533959 bool handleSpecialType (FieldDecl *FD, QualType Ty) {
3960+ const auto *RecordDecl = Ty->getAsCXXRecordDecl ();
3961+ AccessSpecifier DefaultConstructorAccess;
3962+ auto DefaultConstructor =
3963+ std::find_if (RecordDecl->ctor_begin (), RecordDecl->ctor_end (),
3964+ [](auto it) { return it->isDefaultConstructor (); });
3965+ DefaultConstructorAccess = DefaultConstructor->getAccess ();
3966+ DefaultConstructor->setAccess (AS_public);
3967+
39543968 addFieldInit (FD, Ty, std::nullopt ,
39553969 InitializationKind::CreateDefault (KernelCallerSrcLoc));
3956-
3970+ DefaultConstructor-> setAccess (DefaultConstructorAccess);
39573971 addFieldMemberExpr (FD, Ty);
39583972
3959- const auto *RecordDecl = Ty->getAsCXXRecordDecl ();
39603973 createSpecialMethodCall (RecordDecl, getInitMethodName (), BodyStmts);
39613974 CXXMethodDecl *FinalizeMethod =
39623975 getMethodByName (RecordDecl, FinalizeMethodName);
@@ -3970,9 +3983,17 @@ class SyclKernelBodyCreator : public SyclKernelFieldHandler {
39703983 }
39713984
39723985 bool handleSpecialType (const CXXBaseSpecifier &BS, QualType Ty) {
3973- const auto *RecordDecl = Ty->getAsCXXRecordDecl ();
3986+ const auto *BaseRecordDecl = BS.getType ()->getAsCXXRecordDecl ();
3987+ AccessSpecifier DefaultConstructorAccess;
3988+ auto DefaultConstructor =
3989+ std::find_if (BaseRecordDecl->ctor_begin (), BaseRecordDecl->ctor_end (),
3990+ [](auto it) { return it->isDefaultConstructor (); });
3991+ DefaultConstructorAccess = DefaultConstructor->getAccess ();
3992+ DefaultConstructor->setAccess (AS_public);
3993+
39743994 addBaseInit (BS, Ty, InitializationKind::CreateDefault (KernelCallerSrcLoc));
3975- createSpecialMethodCall (RecordDecl, getInitMethodName (), BodyStmts);
3995+ DefaultConstructor->setAccess (DefaultConstructorAccess);
3996+ createSpecialMethodCall (BaseRecordDecl, getInitMethodName (), BodyStmts);
39763997 return true ;
39773998 }
39783999
@@ -4669,16 +4690,21 @@ class SyclKernelIntHeaderCreator : public SyclKernelFieldHandler {
46694690 bool handleSyclSpecialType (const CXXRecordDecl *RD,
46704691 const CXXBaseSpecifier &BC,
46714692 QualType FieldTy) final {
4672- const auto *AccTy =
4673- cast<ClassTemplateSpecializationDecl>(FieldTy->getAsRecordDecl ());
4674- assert (AccTy->getTemplateArgs ().size () >= 2 &&
4675- " Incorrect template args for Accessor Type" );
4676- int Dims = static_cast <int >(
4677- AccTy->getTemplateArgs ()[1 ].getAsIntegral ().getExtValue ());
4678- int Info = getAccessTarget (FieldTy, AccTy) | (Dims << 11 );
4679- Header.addParamDesc (SYCLIntegrationHeader::kind_accessor, Info,
4680- CurOffset +
4681- offsetOf (RD, BC.getType ()->getAsCXXRecordDecl ()));
4693+ if (isSyclAccessorType (FieldTy)) {
4694+ const auto *AccTy =
4695+ cast<ClassTemplateSpecializationDecl>(FieldTy->getAsRecordDecl ());
4696+ assert (AccTy->getTemplateArgs ().size () >= 2 &&
4697+ " Incorrect template args for Accessor Type" );
4698+ int Dims = static_cast <int >(
4699+ AccTy->getTemplateArgs ()[1 ].getAsIntegral ().getExtValue ());
4700+ int Info = getAccessTarget (FieldTy, AccTy) | (Dims << 11 );
4701+ Header.addParamDesc (SYCLIntegrationHeader::kind_accessor, Info,
4702+ CurOffset +
4703+ offsetOf (RD, BC.getType ()->getAsCXXRecordDecl ()));
4704+ } else if (SemaSYCL::isSyclType (FieldTy, SYCLTypeAttr::work_group_memory)) {
4705+ addParam (FieldTy, SYCLIntegrationHeader::kind_work_group_memory,
4706+ offsetOf (RD, BC.getType ()->getAsCXXRecordDecl ()));
4707+ }
46824708 return true ;
46834709 }
46844710
0 commit comments