Skip to content

Commit c3305b6

Browse files
committed
proto: use Cookie for diagnostics
1 parent 1c983b5 commit c3305b6

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,10 +1086,6 @@ bool SemaHLSL::handleRootSignatureElements(
10861086
using RangeInfo = llvm::hlsl::rootsig::RangeInfo;
10871087
using OverlappingRanges = llvm::hlsl::rootsig::OverlappingRanges;
10881088

1089-
// Each RangeInfo will contain an index back to its associated
1090-
// RootSignatureElement in our Elements ArrayRef
1091-
size_t InfoIndex = 0;
1092-
10931089
// 1. Collect RangeInfos
10941090
llvm::SmallVector<RangeInfo> Infos;
10951091
for (const hlsl::RootSignatureElement &RootSigElem : Elements) {
@@ -1105,7 +1101,7 @@ bool SemaHLSL::handleRootSignatureElements(
11051101
Info.Space = Descriptor->Space;
11061102
Info.Visibility = Descriptor->Visibility;
11071103

1108-
Info.Index = InfoIndex;
1104+
Info.Cookie = static_cast<void *>(&RootSigElem);
11091105
Infos.push_back(Info);
11101106
} else if (const auto *Constants =
11111107
std::get_if<llvm::hlsl::rootsig::RootConstants>(&Elem)) {
@@ -1117,7 +1113,7 @@ bool SemaHLSL::handleRootSignatureElements(
11171113
Info.Space = Constants->Space;
11181114
Info.Visibility = Constants->Visibility;
11191115

1120-
Info.Index = InfoIndex;
1116+
Info.Cookie = static_cast<void *>(&RootSigElem);
11211117
Infos.push_back(Info);
11221118
} else if (const auto *Sampler =
11231119
std::get_if<llvm::hlsl::rootsig::StaticSampler>(&Elem)) {
@@ -1129,7 +1125,7 @@ bool SemaHLSL::handleRootSignatureElements(
11291125
Info.Space = Sampler->Space;
11301126
Info.Visibility = Sampler->Visibility;
11311127

1132-
Info.Index = InfoIndex;
1128+
Info.Cookie = static_cast<void *>(&RootSigElem);
11331129
Infos.push_back(Info);
11341130
} else if (const auto *Clause =
11351131
std::get_if<llvm::hlsl::rootsig::DescriptorTableClause>(
@@ -1146,7 +1142,7 @@ bool SemaHLSL::handleRootSignatureElements(
11461142
Info.Space = Clause->Space;
11471143

11481144
// Note: Clause does not hold the visibility this will need to
1149-
Info.Index = InfoIndex;
1145+
Info.Cookie = static_cast<void *>(&RootSigElem);
11501146
Infos.push_back(Info);
11511147
} else if (const auto *Table =
11521148
std::get_if<llvm::hlsl::rootsig::DescriptorTable>(&Elem)) {
@@ -1160,28 +1156,26 @@ bool SemaHLSL::handleRootSignatureElements(
11601156
for (RangeInfo &Info : TableInfos)
11611157
Info.Visibility = Table->Visibility;
11621158
}
1163-
1164-
InfoIndex++;
11651159
}
11661160

11671161
// Helper to report diagnostics
1168-
auto ReportOverlap = [this, &Elements](OverlappingRanges Overlap) {
1162+
auto ReportOverlap = [this](OverlappingRanges Overlap) {
11691163
const RangeInfo *Info = Overlap.A;
11701164
const RangeInfo *OInfo = Overlap.B;
11711165
auto CommonVis = Info->Visibility == llvm::dxbc::ShaderVisibility::All
11721166
? OInfo->Visibility
11731167
: Info->Visibility;
1174-
SourceLocation InfoLoc = Elements[Info->Index].getLocation();
1175-
this->Diag(InfoLoc, diag::err_hlsl_resource_range_overlap)
1168+
auto Elem = static_cast<const hlsl::RootSignatureElement *>(Info->Cookie);
1169+
this->Diag(Elem->getLocation(), diag::err_hlsl_resource_range_overlap)
11761170
<< llvm::to_underlying(Info->Class) << Info->LowerBound
11771171
<< /*unbounded=*/(Info->UpperBound == RangeInfo::Unbounded)
11781172
<< Info->UpperBound << llvm::to_underlying(OInfo->Class)
11791173
<< OInfo->LowerBound
11801174
<< /*unbounded=*/(OInfo->UpperBound == RangeInfo::Unbounded)
11811175
<< OInfo->UpperBound << Info->Space << CommonVis;
11821176

1183-
SourceLocation OInfoLoc = Elements[OInfo->Index].getLocation();
1184-
this->Diag(OInfoLoc, diag::note_hlsl_resource_range_here);
1177+
auto OElem = static_cast<const hlsl::RootSignatureElement *>(OInfo->Cookie);
1178+
this->Diag(OElem->getLocation(), diag::note_hlsl_resource_range_here);
11851179
};
11861180

11871181
llvm::SmallVector<OverlappingRanges> Overlaps =

llvm/include/llvm/Frontend/HLSL/RootSignatureValidations.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ struct RangeInfo {
5252
uint32_t Space;
5353
llvm::dxbc::ShaderVisibility Visibility;
5454

55-
// The index retains its original position before being sorted by group.
56-
size_t Index;
55+
// Retain information for diagnostic reporting
56+
void *Cookie;
5757
};
5858

5959
class ResourceRange {

0 commit comments

Comments
 (0)