Skip to content

Commit 7339028

Browse files
committed
proto: dealing with duplicates
1 parent 1b9fdff commit 7339028

File tree

2 files changed

+35
-4
lines changed

2 files changed

+35
-4
lines changed

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,19 +1165,19 @@ bool SemaHLSL::handleRootSignatureElements(
11651165
Infos.push_back(Pair.first);
11661166

11671167
// Helpers to report diagnostics
1168+
uint32_t DuplicateCounter = 0;
11681169
using ElemPair = std::pair<const hlsl::RootSignatureElement *,
11691170
const hlsl::RootSignatureElement *>;
1170-
auto GetElemPair = [&Infos, &InfoPairs](
1171+
auto GetElemPair = [&Infos, &InfoPairs, &DuplicateCounter](
11711172
OverlappingRanges Overlap) -> ElemPair {
11721173
auto InfoB = std::lower_bound(Infos.begin(), Infos.end(), *Overlap.B);
11731174
auto DistB = std::distance(Infos.begin(), InfoB);
11741175
auto PairB = InfoPairs.begin();
11751176
std::advance(PairB, DistB);
11761177

11771178
auto InfoA = std::lower_bound(InfoB, Infos.end(), *Overlap.A);
1178-
if (InfoA == InfoB)
1179-
InfoA++;
1180-
auto DistA = std::distance(InfoB, InfoA);
1179+
DuplicateCounter = InfoA == InfoB ? DuplicateCounter + 1 : 0;
1180+
auto DistA = std::distance(InfoB, InfoA) + DuplicateCounter;
11811181
auto PairA = PairB;
11821182
std::advance(PairA, DistA);
11831183

clang/test/SemaHLSL/RootSignature-resource-ranges-err.hlsl

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,34 @@ void valid_root_signature_13() {}
105105
// expected-note@+1 {{overlapping resource range here}}
106106
[RootSignature(DemoNoteSourceLocations)]
107107
void bad_root_signature_14() {}
108+
109+
#define DuplicatesRootSignature \
110+
"CBV(b0), CBV(b0), CBV(b0), CBV(b0)"
111+
112+
// CHECK: [[@LINE-2]]:13: note: expanded from macro 'DuplicatesRootSignature'
113+
// CHECK-NEXT: [[@LINE-3]] | "CBV(b0), CBV(b0), CBV(b0), CBV(b0)"
114+
// CHECK-NEXT: | ^
115+
// CHECK: [[@LINE-5]]:4: note: expanded from macro 'DuplicatesRootSignature'
116+
// CHECK-NEXT: [[@LINE-6]] | "CBV(b0), CBV(b0), CBV(b0), CBV(b0)"
117+
// CHECK-NEXT: | ^
118+
// CHECK: [[@LINE-8]]:22: note: expanded from macro 'DuplicatesRootSignature'
119+
// CHECK-NEXT: [[@LINE-9]] | "CBV(b0), CBV(b0), CBV(b0), CBV(b0)"
120+
// CHECK-NEXT: | ^
121+
// CHECK: [[@LINE-11]]:4: note: expanded from macro 'DuplicatesRootSignature'
122+
// CHECK-NEXT: [[@LINE-12]] | "CBV(b0), CBV(b0), CBV(b0), CBV(b0)"
123+
// CHECK-NEXT: | ^
124+
// CHECK: [[@LINE-14]]:31: note: expanded from macro 'DuplicatesRootSignature'
125+
// CHECK-NEXT: [[@LINE-15]] | "CBV(b0), CBV(b0), CBV(b0), CBV(b0)"
126+
// CHECK-NEXT: | ^
127+
// CHECK: [[@LINE-17]]:4: note: expanded from macro 'DuplicatesRootSignature'
128+
// CHECK-NEXT: [[@LINE-18]] | "CBV(b0), CBV(b0), CBV(b0), CBV(b0)"
129+
// CHECK-NEXT: | ^
130+
131+
// expected-error@+6 {{resource ranges b[0;0] and b[0;0] overlap within space = 0 and visibility = All}}
132+
// expected-note@+5 {{overlapping resource range here}}
133+
// expected-error@+4 {{resource ranges b[0;0] and b[0;0] overlap within space = 0 and visibility = All}}
134+
// expected-note@+3 {{overlapping resource range here}}
135+
// expected-error@+2 {{resource ranges b[0;0] and b[0;0] overlap within space = 0 and visibility = All}}
136+
// expected-note@+1 {{overlapping resource range here}}
137+
[RootSignature(DuplicatesRootSignature)]
138+
void valid_root_signature_15() {}

0 commit comments

Comments
 (0)