@@ -110,6 +110,19 @@ DeclBindingInfo *ResourceBindings::addDeclBindingInfo(const VarDecl *VD,
110110 ResourceClass ResClass) {
111111 assert (getDeclBindingInfo (VD, ResClass) == nullptr &&
112112 " DeclBindingInfo already added" );
113+ #ifndef NDEBUG
114+ // Verify that existing bindings for this decl are stored sequentially
115+ // and at the end of the BindingsList
116+ auto I = DeclToBindingListIndex.find (VD);
117+ if (I != DeclToBindingListIndex.end ()) {
118+ for (unsigned Index = I->getSecond (); Index < BindingsList.size (); ++Index)
119+ assert (BindingsList[Index].Decl == VD);
120+ }
121+ #endif
122+ // VarDecl may have multiple entries for different resource classes.
123+ // DeclToBindingListIndex stores the index of the first binding we saw
124+ // for this decl. If there are any additional ones then that index
125+ // shouldn't be updated.
113126 DeclToBindingListIndex.try_emplace (VD, BindingsList.size ());
114127 return &BindingsList.emplace_back (VD, ResClass);
115128}
@@ -118,17 +131,17 @@ DeclBindingInfo *ResourceBindings::getDeclBindingInfo(const VarDecl *VD,
118131 ResourceClass ResClass) {
119132 auto Entry = DeclToBindingListIndex.find (VD);
120133 if (Entry != DeclToBindingListIndex.end ()) {
121- unsigned Index = Entry->getSecond ();
122- while (Index < BindingsList.size () && BindingsList[Index].Decl == VD) {
134+ for (unsigned Index = Entry->getSecond ();
135+ Index < BindingsList.size () && BindingsList[Index].Decl == VD;
136+ ++Index) {
123137 if (BindingsList[Index].ResClass == ResClass)
124138 return &BindingsList[Index];
125- Index++;
126139 }
127140 }
128141 return nullptr ;
129142}
130143
131- bool ResourceBindings::hasBindingInfoForDecl (const VarDecl *VD) {
144+ bool ResourceBindings::hasBindingInfoForDecl (const VarDecl *VD) const {
132145 return DeclToBindingListIndex.contains (VD);
133146}
134147
0 commit comments