-
Notifications
You must be signed in to change notification settings - Fork 14.4k
[HLSL][RootSignature] Retain SourceLocation
of RootElement
for SemaHLSL
diagnostics
#147094
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
inbelic
merged 8 commits into
llvm:users/inbelic/pr-147084
from
inbelic:inbelic/rs-sema-source-loc
Jul 4, 2025
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
4a5cde3
nfc: introduce wrapper `RootSignatureElement` around `RootElement` to…
inbelic f6d6d97
let `RootSignatureElement` retain its source location
inbelic 67eb653
update resource range analysis to use retained source loc
inbelic 02e9ebd
move wrapper definition to `SemaHLSL`
inbelic b9d40cb
add note to denote where the other overlapping range is
inbelic e1289c1
add testcase to demonstrate source location
inbelic 74ee5ee
clang format
inbelic 72694b7
rebase: clean-ups
inbelic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -1064,21 +1064,25 @@ SemaHLSL::ActOnStartRootSignatureDecl(StringRef Signature) { | |||||
|
||||||
void SemaHLSL::ActOnFinishRootSignatureDecl( | ||||||
SourceLocation Loc, IdentifierInfo *DeclIdent, | ||||||
SmallVector<llvm::hlsl::rootsig::RootElement> &Elements) { | ||||||
ArrayRef<hlsl::RootSignatureElement> RootElements) { | ||||||
|
||||||
if (handleRootSignatureElements(RootElements, Loc)) | ||||||
return; | ||||||
|
||||||
SmallVector<llvm::hlsl::rootsig::RootElement> Elements; | ||||||
for (auto &RootSigElement : RootElements) | ||||||
Elements.push_back(RootSigElement.getElement()); | ||||||
|
||||||
auto *SignatureDecl = HLSLRootSignatureDecl::Create( | ||||||
SemaRef.getASTContext(), /*DeclContext=*/SemaRef.CurContext, Loc, | ||||||
DeclIdent, SemaRef.getLangOpts().HLSLRootSigVer, Elements); | ||||||
|
||||||
if (handleRootSignatureDecl(SignatureDecl, Loc)) | ||||||
return; | ||||||
|
||||||
SignatureDecl->setImplicit(); | ||||||
SemaRef.PushOnScopeChains(SignatureDecl, SemaRef.getCurScope()); | ||||||
} | ||||||
|
||||||
bool SemaHLSL::handleRootSignatureDecl(HLSLRootSignatureDecl *D, | ||||||
SourceLocation Loc) { | ||||||
bool SemaHLSL::handleRootSignatureElements( | ||||||
ArrayRef<hlsl::RootSignatureElement> Elements, SourceLocation Loc) { | ||||||
// The following conducts analysis on resource ranges to detect and report | ||||||
// any overlaps in resource ranges. | ||||||
// | ||||||
|
@@ -1103,9 +1107,15 @@ bool SemaHLSL::handleRootSignatureDecl(HLSLRootSignatureDecl *D, | |||||
using ResourceRange = llvm::hlsl::rootsig::ResourceRange; | ||||||
using GroupT = std::pair<ResourceClass, /*Space*/ uint32_t>; | ||||||
|
||||||
// Introduce a mapping from the collected RangeInfos back to the | ||||||
// RootSignatureElement that will retain its diagnostics info | ||||||
llvm::DenseMap<size_t, const hlsl::RootSignatureElement *> InfoIndexMap; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
size_t InfoIndex = 0; | ||||||
|
||||||
// 1. Collect RangeInfos | ||||||
llvm::SmallVector<RangeInfo> Infos; | ||||||
for (const llvm::hlsl::rootsig::RootElement &Elem : D->getRootElements()) { | ||||||
for (const hlsl::RootSignatureElement &RootSigElem : Elements) { | ||||||
const llvm::hlsl::rootsig::RootElement &Elem = RootSigElem.getElement(); | ||||||
if (const auto *Descriptor = | ||||||
std::get_if<llvm::hlsl::rootsig::RootDescriptor>(&Elem)) { | ||||||
RangeInfo Info; | ||||||
|
@@ -1116,6 +1126,9 @@ bool SemaHLSL::handleRootSignatureDecl(HLSLRootSignatureDecl *D, | |||||
llvm::dxil::ResourceClass(llvm::to_underlying(Descriptor->Type)); | ||||||
Info.Space = Descriptor->Space; | ||||||
Info.Visibility = Descriptor->Visibility; | ||||||
|
||||||
Info.Index = InfoIndex++; | ||||||
InfoIndexMap[Info.Index] = &RootSigElem; | ||||||
Infos.push_back(Info); | ||||||
} else if (const auto *Constants = | ||||||
std::get_if<llvm::hlsl::rootsig::RootConstants>(&Elem)) { | ||||||
|
@@ -1126,6 +1139,9 @@ bool SemaHLSL::handleRootSignatureDecl(HLSLRootSignatureDecl *D, | |||||
Info.Class = llvm::dxil::ResourceClass::CBuffer; | ||||||
Info.Space = Constants->Space; | ||||||
Info.Visibility = Constants->Visibility; | ||||||
|
||||||
Info.Index = InfoIndex++; | ||||||
InfoIndexMap[Info.Index] = &RootSigElem; | ||||||
Infos.push_back(Info); | ||||||
} else if (const auto *Sampler = | ||||||
std::get_if<llvm::hlsl::rootsig::StaticSampler>(&Elem)) { | ||||||
|
@@ -1136,6 +1152,9 @@ bool SemaHLSL::handleRootSignatureDecl(HLSLRootSignatureDecl *D, | |||||
Info.Class = llvm::dxil::ResourceClass::Sampler; | ||||||
Info.Space = Sampler->Space; | ||||||
Info.Visibility = Sampler->Visibility; | ||||||
|
||||||
Info.Index = InfoIndex++; | ||||||
InfoIndexMap[Info.Index] = &RootSigElem; | ||||||
Infos.push_back(Info); | ||||||
} else if (const auto *Clause = | ||||||
std::get_if<llvm::hlsl::rootsig::DescriptorTableClause>( | ||||||
|
@@ -1150,7 +1169,10 @@ bool SemaHLSL::handleRootSignatureDecl(HLSLRootSignatureDecl *D, | |||||
|
||||||
Info.Class = Clause->Type; | ||||||
Info.Space = Clause->Space; | ||||||
|
||||||
// Note: Clause does not hold the visibility this will need to | ||||||
Info.Index = InfoIndex++; | ||||||
InfoIndexMap[Info.Index] = &RootSigElem; | ||||||
Infos.push_back(Info); | ||||||
} else if (const auto *Table = | ||||||
std::get_if<llvm::hlsl::rootsig::DescriptorTable>(&Elem)) { | ||||||
|
@@ -1197,19 +1219,25 @@ bool SemaHLSL::handleRootSignatureDecl(HLSLRootSignatureDecl *D, | |||||
}; | ||||||
|
||||||
// Helper to report diagnostics | ||||||
auto ReportOverlap = [this, Loc, &HadOverlap](const RangeInfo *Info, | ||||||
const RangeInfo *OInfo) { | ||||||
auto ReportOverlap = [this, InfoIndexMap, &HadOverlap]( | ||||||
const RangeInfo *Info, const RangeInfo *OInfo) { | ||||||
HadOverlap = true; | ||||||
auto CommonVis = Info->Visibility == llvm::dxbc::ShaderVisibility::All | ||||||
? OInfo->Visibility | ||||||
: Info->Visibility; | ||||||
this->Diag(Loc, diag::err_hlsl_resource_range_overlap) | ||||||
const hlsl::RootSignatureElement *Elem = InfoIndexMap.at(Info->Index); | ||||||
SourceLocation InfoLoc = Elem->getLocation(); | ||||||
this->Diag(InfoLoc, diag::err_hlsl_resource_range_overlap) | ||||||
<< llvm::to_underlying(Info->Class) << Info->LowerBound | ||||||
<< /*unbounded=*/(Info->UpperBound == RangeInfo::Unbounded) | ||||||
<< Info->UpperBound << llvm::to_underlying(OInfo->Class) | ||||||
<< OInfo->LowerBound | ||||||
<< /*unbounded=*/(OInfo->UpperBound == RangeInfo::Unbounded) | ||||||
<< OInfo->UpperBound << Info->Space << CommonVis; | ||||||
|
||||||
const hlsl::RootSignatureElement *OElem = InfoIndexMap.at(OInfo->Index); | ||||||
SourceLocation OInfoLoc = OElem->getLocation(); | ||||||
this->Diag(OInfoLoc, diag::note_hlsl_resource_range_here); | ||||||
}; | ||||||
|
||||||
// 3: Iterate through collected RangeInfos | ||||||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We no longer are required to use
Loc