@@ -1533,72 +1533,80 @@ void SemaHLSL::handleResourceBindingAttr(Decl *TheDecl, const ParsedAttr &AL) {
15331533                                    diag::err_incomplete_type))
15341534      return ;
15351535  }
1536-   StringRef Space =  " space0 " ; 
1536+ 
15371537  StringRef Slot = " "  ;
1538+   StringRef Space = " "  ;
1539+   SourceLocation SlotLoc, SpaceLoc;
15381540
15391541  if  (!AL.isArgIdent (0 )) {
15401542    Diag (AL.getLoc (), diag::err_attribute_argument_type)
15411543        << AL << AANT_ArgumentIdentifier;
15421544    return ;
15431545  }
1544- 
15451546  IdentifierLoc *Loc = AL.getArgAsIdent (0 );
1546-   StringRef Str = Loc->getIdentifierInfo ()->getName ();
1547-   SourceLocation ArgLoc = Loc->getLoc ();
15481547
1549-   SourceLocation SpaceArgLoc;
1550-   bool  SpecifiedSpace = false ;
15511548  if  (AL.getNumArgs () == 2 ) {
1552-     SpecifiedSpace  = true ;
1553-     Slot  = Str ;
1549+     Slot  = Loc-> getIdentifierInfo ()-> getName () ;
1550+     SlotLoc  = Loc-> getLoc () ;
15541551    if  (!AL.isArgIdent (1 )) {
15551552      Diag (AL.getLoc (), diag::err_attribute_argument_type)
15561553          << AL << AANT_ArgumentIdentifier;
15571554      return ;
15581555    }
1559- 
1560-     IdentifierLoc *Loc = AL.getArgAsIdent (1 );
1556+     Loc = AL.getArgAsIdent (1 );
15611557    Space = Loc->getIdentifierInfo ()->getName ();
1562-     SpaceArgLoc  = Loc->getLoc ();
1558+     SpaceLoc  = Loc->getLoc ();
15631559  } else  {
1564-     Slot = Str;
1560+     StringRef Str = Loc->getIdentifierInfo ()->getName ();
1561+     if  (Str.starts_with (" space"  )) {
1562+       Space = Str;
1563+       SpaceLoc = Loc->getLoc ();
1564+     } else  {
1565+       Slot = Str;
1566+       SlotLoc = Loc->getLoc ();
1567+       Space = " space0"  ;
1568+     }
15651569  }
15661570
1567-   RegisterType RegType;
1568-   unsigned  SlotNum =  0 ;
1571+   RegisterType RegType = RegisterType::SRV ;
1572+   std::optional< unsigned >  SlotNum;
15691573  unsigned  SpaceNum = 0 ;
15701574
1571-   //  Validate. 
1575+   //  Validate slot 
15721576  if  (!Slot.empty ()) {
15731577    if  (!convertToRegisterType (Slot, &RegType)) {
1574-       Diag (ArgLoc , diag::err_hlsl_binding_type_invalid) << Slot.substr (0 , 1 );
1578+       Diag (SlotLoc , diag::err_hlsl_binding_type_invalid) << Slot.substr (0 , 1 );
15751579      return ;
15761580    }
15771581    if  (RegType == RegisterType::I) {
1578-       Diag (ArgLoc , diag::warn_hlsl_deprecated_register_type_i);
1582+       Diag (SlotLoc , diag::warn_hlsl_deprecated_register_type_i);
15791583      return ;
15801584    }
1581- 
15821585    StringRef SlotNumStr = Slot.substr (1 );
1583-     if  (SlotNumStr.getAsInteger (10 , SlotNum)) {
1584-       Diag (ArgLoc, diag::err_hlsl_unsupported_register_number);
1586+     unsigned  N;
1587+     if  (SlotNumStr.getAsInteger (10 , N)) {
1588+       Diag (SlotLoc, diag::err_hlsl_unsupported_register_number);
15851589      return ;
15861590    }
1591+     SlotNum = N;
15871592  }
15881593
1594+   //  Validate space
15891595  if  (!Space.starts_with (" space"  )) {
1590-     Diag (SpaceArgLoc , diag::err_hlsl_expected_space) << Space;
1596+     Diag (SpaceLoc , diag::err_hlsl_expected_space) << Space;
15911597    return ;
15921598  }
15931599  StringRef SpaceNumStr = Space.substr (5 );
15941600  if  (SpaceNumStr.getAsInteger (10 , SpaceNum)) {
1595-     Diag (SpaceArgLoc , diag::err_hlsl_expected_space) << Space;
1601+     Diag (SpaceLoc , diag::err_hlsl_expected_space) << Space;
15961602    return ;
15971603  }
15981604
1599-   if  (!DiagnoseHLSLRegisterAttribute (SemaRef, ArgLoc, TheDecl, RegType,
1600-                                      SpecifiedSpace))
1601-     return ;
1605+   //  If we have slot, diagnose it is the right register type for the decl
1606+   if  (SlotNum.has_value ())
1607+     if  (!DiagnoseHLSLRegisterAttribute (SemaRef, SlotLoc, TheDecl, RegType,
1608+                                        !SpaceLoc.isInvalid ()))
1609+       return ;
16021610
16031611  HLSLResourceBindingAttr *NewAttr =
16041612      HLSLResourceBindingAttr::Create (getASTContext (), Slot, Space, AL);
@@ -1971,7 +1979,7 @@ void SemaHLSL::ActOnEndOfTranslationUnit(TranslationUnitDecl *TU) {
19711979    for  (const  Decl *VD : DefaultCBufferDecls) {
19721980      const  HLSLResourceBindingAttr *RBA =
19731981          VD->getAttr <HLSLResourceBindingAttr>();
1974-       if  (RBA &&
1982+       if  (RBA && !RBA-> isImplicit () && 
19751983          RBA->getRegisterType () == HLSLResourceBindingAttr::RegisterType::C) {
19761984        DefaultCBuffer->setHasValidPackoffset (true );
19771985        break ;
@@ -3262,7 +3270,7 @@ static bool initVarDeclWithCtor(Sema &S, VarDecl *VD,
32623270
32633271static  bool  initGlobalResourceDecl (Sema &S, VarDecl *VD) {
32643272  HLSLResourceBindingAttr *RBA = VD->getAttr <HLSLResourceBindingAttr>();
3265-   if  (!RBA)
3273+   if  (!RBA || RBA-> isImplicit () )
32663274    //  FIXME: add support for implicit binding (llvm/llvm-project#110722)
32673275    return  false ;
32683276
@@ -3347,7 +3355,7 @@ void SemaHLSL::processExplicitBindingsOnDecl(VarDecl *VD) {
33473355  bool  HasBinding = false ;
33483356  for  (Attr *A : VD->attrs ()) {
33493357    HLSLResourceBindingAttr *RBA = dyn_cast<HLSLResourceBindingAttr>(A);
3350-     if  (!RBA)
3358+     if  (!RBA || RBA-> isImplicit () )
33513359      continue ;
33523360    HasBinding = true ;
33533361
0 commit comments