@@ -1529,72 +1529,82 @@ void SemaHLSL::handleResourceBindingAttr(Decl *TheDecl, const ParsedAttr &AL) {
15291529 diag::err_incomplete_type))
15301530 return ;
15311531 }
1532- StringRef Space = " space0 " ;
1532+
15331533 StringRef Slot = " " ;
1534+ StringRef Space = " " ;
1535+ SourceLocation SlotLoc, SpaceLoc;
15341536
15351537 if (!AL.isArgIdent (0 )) {
15361538 Diag (AL.getLoc (), diag::err_attribute_argument_type)
15371539 << AL << AANT_ArgumentIdentifier;
15381540 return ;
15391541 }
1540-
15411542 IdentifierLoc *Loc = AL.getArgAsIdent (0 );
1542- StringRef Str = Loc->Ident ->getName ();
1543- SourceLocation ArgLoc = Loc->Loc ;
15441543
1545- SourceLocation SpaceArgLoc;
1546- bool SpecifiedSpace = false ;
15471544 if (AL.getNumArgs () == 2 ) {
1548- SpecifiedSpace = true ;
1549- Slot = Str;
1545+ Slot = Loc->Ident ->getName ();
1546+ SlotLoc = Loc->Loc ;
1547+
15501548 if (!AL.isArgIdent (1 )) {
15511549 Diag (AL.getLoc (), diag::err_attribute_argument_type)
15521550 << AL << AANT_ArgumentIdentifier;
15531551 return ;
15541552 }
15551553
1556- IdentifierLoc * Loc = AL.getArgAsIdent (1 );
1554+ Loc = AL.getArgAsIdent (1 );
15571555 Space = Loc->Ident ->getName ();
1558- SpaceArgLoc = Loc->Loc ;
1556+ SpaceLoc = Loc->Loc ;
15591557 } else {
1560- Slot = Str;
1558+ StringRef Str = Loc->Ident ->getName ();
1559+ if (Str.starts_with (" space" )) {
1560+ Space = Str;
1561+ SpaceLoc = Loc->Loc ;
1562+ } else {
1563+ Slot = Str;
1564+ SlotLoc = Loc->Loc ;
1565+ Space = " space0" ;
1566+ }
15611567 }
15621568
1563- RegisterType RegType;
1564- unsigned SlotNum = 0 ;
1569+ RegisterType RegType = RegisterType::SRV ;
1570+ int SlotNum = - 1 ;
15651571 unsigned SpaceNum = 0 ;
15661572
1567- // Validate.
1573+ // Validate slot
15681574 if (!Slot.empty ()) {
15691575 if (!convertToRegisterType (Slot, &RegType)) {
1570- Diag (ArgLoc , diag::err_hlsl_binding_type_invalid) << Slot.substr (0 , 1 );
1576+ Diag (SlotLoc , diag::err_hlsl_binding_type_invalid) << Slot.substr (0 , 1 );
15711577 return ;
15721578 }
15731579 if (RegType == RegisterType::I) {
1574- Diag (ArgLoc , diag::warn_hlsl_deprecated_register_type_i);
1580+ Diag (SlotLoc , diag::warn_hlsl_deprecated_register_type_i);
15751581 return ;
15761582 }
1577-
15781583 StringRef SlotNumStr = Slot.substr (1 );
15791584 if (SlotNumStr.getAsInteger (10 , SlotNum)) {
1580- Diag (ArgLoc , diag::err_hlsl_unsupported_register_number);
1585+ Diag (SlotLoc , diag::err_hlsl_unsupported_register_number);
15811586 return ;
15821587 }
15831588 }
15841589
1585- if (!Space.starts_with (" space" )) {
1586- Diag (SpaceArgLoc, diag::err_hlsl_expected_space) << Space;
1587- return ;
1588- }
1589- StringRef SpaceNumStr = Space.substr (5 );
1590- if (SpaceNumStr.getAsInteger (10 , SpaceNum)) {
1591- Diag (SpaceArgLoc, diag::err_hlsl_expected_space) << Space;
1592- return ;
1590+ // Validate space
1591+ if (!Space.empty ()) {
1592+ if (!Space.starts_with (" space" )) {
1593+ Diag (SpaceLoc, diag::err_hlsl_expected_space) << Space;
1594+ return ;
1595+ }
1596+ StringRef SpaceNumStr = Space.substr (5 );
1597+ if (SpaceNumStr.getAsInteger (10 , SpaceNum)) {
1598+ Diag (SpaceLoc, diag::err_hlsl_expected_space) << Space;
1599+ return ;
1600+ }
15931601 }
15941602
1595- if (!DiagnoseHLSLRegisterAttribute (SemaRef, ArgLoc, TheDecl, RegType,
1596- SpecifiedSpace))
1597- return ;
1603+ // If we have slot, diagnose it is the right register type for the decl
1604+ if (SlotNum >= 0 )
1605+ if (!DiagnoseHLSLRegisterAttribute (SemaRef, SlotLoc, TheDecl, RegType,
1606+ !SpaceLoc.isInvalid ()))
1607+ return ;
15981608
15991609 HLSLResourceBindingAttr *NewAttr =
16001610 HLSLResourceBindingAttr::Create (getASTContext (), Slot, Space, AL);
@@ -1967,7 +1977,7 @@ void SemaHLSL::ActOnEndOfTranslationUnit(TranslationUnitDecl *TU) {
19671977 for (const Decl *VD : DefaultCBufferDecls) {
19681978 const HLSLResourceBindingAttr *RBA =
19691979 VD->getAttr <HLSLResourceBindingAttr>();
1970- if (RBA &&
1980+ if (RBA && !RBA-> isImplicit () &&
19711981 RBA->getRegisterType () == HLSLResourceBindingAttr::RegisterType::C) {
19721982 DefaultCBuffer->setHasValidPackoffset (true );
19731983 break ;
@@ -3227,7 +3237,7 @@ static bool initVarDeclWithCtor(Sema &S, VarDecl *VD,
32273237
32283238static bool initGlobalResourceDecl (Sema &S, VarDecl *VD) {
32293239 HLSLResourceBindingAttr *RBA = VD->getAttr <HLSLResourceBindingAttr>();
3230- if (!RBA)
3240+ if (!RBA || RBA-> isImplicit () )
32313241 // FIXME: add support for implicit binding (llvm/llvm-project#110722)
32323242 return false ;
32333243
@@ -3310,7 +3320,7 @@ void SemaHLSL::processExplicitBindingsOnDecl(VarDecl *VD) {
33103320
33113321 for (Attr *A : VD->attrs ()) {
33123322 HLSLResourceBindingAttr *RBA = dyn_cast<HLSLResourceBindingAttr>(A);
3313- if (!RBA)
3323+ if (!RBA || RBA-> isImplicit () )
33143324 continue ;
33153325
33163326 RegisterType RT = RBA->getRegisterType ();
0 commit comments