Skip to content

Commit 1e79dcf

Browse files
committed
cr feedback - add const, rearrange loop, add debug-only checks
1 parent a7fbeae commit 1e79dcf

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

clang/include/clang/Sema/SemaHLSL.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class ResourceBindings {
7070
ResourceClass ResClass);
7171
DeclBindingInfo *getDeclBindingInfo(const VarDecl *VD,
7272
ResourceClass ResClass);
73-
bool hasBindingInfoForDecl(const VarDecl *VD);
73+
bool hasBindingInfoForDecl(const VarDecl *VD) const;
7474

7575
private:
7676
// List of all resource bindings required by the shader.

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)