@@ -189,12 +189,29 @@ struct BuiltinTypeDeclBuilder {
189189 BuiltinTypeDeclBuilder &addArraySubscriptOperators (Sema &S) {
190190 if (Record->isCompleteDefinition ())
191191 return *this ;
192- addArraySubscriptOperator (S, true );
193- addArraySubscriptOperator (S, false );
192+ ASTContext &AST = Record->getASTContext ();
193+ DeclarationName Subscript =
194+ AST.DeclarationNames .getCXXOperatorName (OO_Subscript);
195+ addHandleAccessFunction (S, Subscript, /* IsConst=*/ true , /* IsRef=*/ true );
196+ addHandleAccessFunction (S, Subscript, /* IsConst=*/ false , /* IsRef=*/ true );
197+ return *this ;
198+ }
199+
200+ BuiltinTypeDeclBuilder &addLoadMethods (Sema &S) {
201+ if (Record->isCompleteDefinition ())
202+ return *this ;
203+
204+ ASTContext &AST = Record->getASTContext ();
205+ IdentifierInfo &II =
206+ AST.Idents .get (" Load" , tok::TokenKind::identifier);
207+ DeclarationName Load (&II);
208+ addHandleAccessFunction (S, Load, /* IsConst=*/ false , /* IsRef=*/ false );
209+
194210 return *this ;
195211 }
196212
197- BuiltinTypeDeclBuilder &addArraySubscriptOperator (Sema &S, bool IsConst) {
213+ BuiltinTypeDeclBuilder &addHandleAccessFunction (Sema &S, DeclarationName Name,
214+ bool IsConst, bool IsRef) {
198215 if (Record->isCompleteDefinition ())
199216 return *this ;
200217
@@ -216,18 +233,16 @@ struct BuiltinTypeDeclBuilder {
216233 ExtInfo.TypeQuals .addConst ();
217234 ReturnTy.addConst ();
218235 }
219- ReturnTy = AST.getLValueReferenceType (ReturnTy);
236+ if (IsRef)
237+ ReturnTy = AST.getLValueReferenceType (ReturnTy);
220238
221239 QualType MethodTy =
222240 AST.getFunctionType (ReturnTy, {AST.UnsignedIntTy }, ExtInfo);
223241 auto *TSInfo = AST.getTrivialTypeSourceInfo (MethodTy, SourceLocation ());
224242 auto *MethodDecl = CXXMethodDecl::Create (
225243 AST, Record, SourceLocation (),
226- DeclarationNameInfo (
227- AST.DeclarationNames .getCXXOperatorName (OO_Subscript),
228- SourceLocation ()),
229- MethodTy, TSInfo, SC_None, false , false , ConstexprSpecKind::Unspecified,
230- SourceLocation ());
244+ DeclarationNameInfo (Name, SourceLocation ()), MethodTy, TSInfo, SC_None,
245+ false , false , ConstexprSpecKind::Unspecified, SourceLocation ());
231246
232247 IdentifierInfo &II = AST.Idents .get (" Idx" , tok::TokenKind::identifier);
233248 auto *IdxParam = ParmVarDecl::Create (
@@ -489,6 +504,7 @@ void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
489504 ResourceKind::TypedBuffer, /* IsROV=*/ false ,
490505 /* RawBuffer=*/ false )
491506 .addArraySubscriptOperators (*SemaPtr)
507+ .addLoadMethods (*SemaPtr)
492508 .completeDefinition ();
493509 });
494510
@@ -501,6 +517,7 @@ void HLSLExternalSemaSource::defineHLSLTypesWithForwardDeclarations() {
501517 ResourceKind::TypedBuffer, /* IsROV=*/ true ,
502518 /* RawBuffer=*/ false )
503519 .addArraySubscriptOperators (*SemaPtr)
520+ .addLoadMethods (*SemaPtr)
504521 .completeDefinition ();
505522 });
506523
0 commit comments