@@ -1533,72 +1533,80 @@ void SemaHLSL::handleResourceBindingAttr(Decl *TheDecl, const ParsedAttr &AL) {
1533
1533
diag::err_incomplete_type))
1534
1534
return ;
1535
1535
}
1536
- StringRef Space = " space0 " ;
1536
+
1537
1537
StringRef Slot = " " ;
1538
+ StringRef Space = " " ;
1539
+ SourceLocation SlotLoc, SpaceLoc;
1538
1540
1539
1541
if (!AL.isArgIdent (0 )) {
1540
1542
Diag (AL.getLoc (), diag::err_attribute_argument_type)
1541
1543
<< AL << AANT_ArgumentIdentifier;
1542
1544
return ;
1543
1545
}
1544
-
1545
1546
IdentifierLoc *Loc = AL.getArgAsIdent (0 );
1546
- StringRef Str = Loc->getIdentifierInfo ()->getName ();
1547
- SourceLocation ArgLoc = Loc->getLoc ();
1548
1547
1549
- SourceLocation SpaceArgLoc;
1550
- bool SpecifiedSpace = false ;
1551
1548
if (AL.getNumArgs () == 2 ) {
1552
- SpecifiedSpace = true ;
1553
- Slot = Str ;
1549
+ Slot = Loc-> getIdentifierInfo ()-> getName () ;
1550
+ SlotLoc = Loc-> getLoc () ;
1554
1551
if (!AL.isArgIdent (1 )) {
1555
1552
Diag (AL.getLoc (), diag::err_attribute_argument_type)
1556
1553
<< AL << AANT_ArgumentIdentifier;
1557
1554
return ;
1558
1555
}
1559
-
1560
- IdentifierLoc *Loc = AL.getArgAsIdent (1 );
1556
+ Loc = AL.getArgAsIdent (1 );
1561
1557
Space = Loc->getIdentifierInfo ()->getName ();
1562
- SpaceArgLoc = Loc->getLoc ();
1558
+ SpaceLoc = Loc->getLoc ();
1563
1559
} 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
+ }
1565
1569
}
1566
1570
1567
- RegisterType RegType;
1568
- unsigned SlotNum = 0 ;
1571
+ RegisterType RegType = RegisterType::SRV ;
1572
+ std::optional< unsigned > SlotNum;
1569
1573
unsigned SpaceNum = 0 ;
1570
1574
1571
- // Validate.
1575
+ // Validate slot
1572
1576
if (!Slot.empty ()) {
1573
1577
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 );
1575
1579
return ;
1576
1580
}
1577
1581
if (RegType == RegisterType::I) {
1578
- Diag (ArgLoc , diag::warn_hlsl_deprecated_register_type_i);
1582
+ Diag (SlotLoc , diag::warn_hlsl_deprecated_register_type_i);
1579
1583
return ;
1580
1584
}
1581
-
1582
1585
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);
1585
1589
return ;
1586
1590
}
1591
+ SlotNum = N;
1587
1592
}
1588
1593
1594
+ // Validate space
1589
1595
if (!Space.starts_with (" space" )) {
1590
- Diag (SpaceArgLoc , diag::err_hlsl_expected_space) << Space;
1596
+ Diag (SpaceLoc , diag::err_hlsl_expected_space) << Space;
1591
1597
return ;
1592
1598
}
1593
1599
StringRef SpaceNumStr = Space.substr (5 );
1594
1600
if (SpaceNumStr.getAsInteger (10 , SpaceNum)) {
1595
- Diag (SpaceArgLoc , diag::err_hlsl_expected_space) << Space;
1601
+ Diag (SpaceLoc , diag::err_hlsl_expected_space) << Space;
1596
1602
return ;
1597
1603
}
1598
1604
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 ;
1602
1610
1603
1611
HLSLResourceBindingAttr *NewAttr =
1604
1612
HLSLResourceBindingAttr::Create (getASTContext (), Slot, Space, AL);
@@ -1971,7 +1979,7 @@ void SemaHLSL::ActOnEndOfTranslationUnit(TranslationUnitDecl *TU) {
1971
1979
for (const Decl *VD : DefaultCBufferDecls) {
1972
1980
const HLSLResourceBindingAttr *RBA =
1973
1981
VD->getAttr <HLSLResourceBindingAttr>();
1974
- if (RBA &&
1982
+ if (RBA && !RBA-> isImplicit () &&
1975
1983
RBA->getRegisterType () == HLSLResourceBindingAttr::RegisterType::C) {
1976
1984
DefaultCBuffer->setHasValidPackoffset (true );
1977
1985
break ;
@@ -3262,7 +3270,7 @@ static bool initVarDeclWithCtor(Sema &S, VarDecl *VD,
3262
3270
3263
3271
static bool initGlobalResourceDecl (Sema &S, VarDecl *VD) {
3264
3272
HLSLResourceBindingAttr *RBA = VD->getAttr <HLSLResourceBindingAttr>();
3265
- if (!RBA)
3273
+ if (!RBA || RBA-> isImplicit () )
3266
3274
// FIXME: add support for implicit binding (llvm/llvm-project#110722)
3267
3275
return false ;
3268
3276
@@ -3347,7 +3355,7 @@ void SemaHLSL::processExplicitBindingsOnDecl(VarDecl *VD) {
3347
3355
bool HasBinding = false ;
3348
3356
for (Attr *A : VD->attrs ()) {
3349
3357
HLSLResourceBindingAttr *RBA = dyn_cast<HLSLResourceBindingAttr>(A);
3350
- if (!RBA)
3358
+ if (!RBA || RBA-> isImplicit () )
3351
3359
continue ;
3352
3360
HasBinding = true ;
3353
3361
0 commit comments