[llvm-branch-commits] [clang] [llvm] [HLSL][RootSignature] Implement validation of resource ranges for `RootDescriptors` (PR #140962)
via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Wed May 21 14:29:24 PDT 2025
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff HEAD~1 HEAD --extensions h,cpp -- clang/include/clang/Sema/SemaHLSL.h clang/lib/Sema/SemaHLSL.cpp llvm/include/llvm/Frontend/HLSL/HLSLRootSignature.h
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp
index cc53f25c7..25a64e4b5 100644
--- a/clang/lib/Sema/SemaHLSL.cpp
+++ b/clang/lib/Sema/SemaHLSL.cpp
@@ -970,7 +970,7 @@ public:
}
static const unsigned NumVisEnums = 8;
- // (unsigned)llvm::hlsl::rootsig::ShaderVisibility::NumEnums;
+ // (unsigned)llvm::hlsl::rootsig::ShaderVisibility::NumEnums;
private:
llvm::hlsl::rootsig::ResourceRange::IMap::Allocator Allocator;
@@ -982,25 +982,27 @@ private:
public:
// Returns std::nullopt if there was no collision. Otherwise, it will
// return the RangeInfo of the collision
- std::optional<const llvm::hlsl::rootsig::RangeInfo *> addRange(const llvm::hlsl::rootsig::RangeInfo &Info) {
+ std::optional<const llvm::hlsl::rootsig::RangeInfo *>
+ addRange(const llvm::hlsl::rootsig::RangeInfo &Info) {
MapT &VisRangeMap = RangeMaps[llvm::to_underlying(Info.Vis)];
- auto [It, _] = VisRangeMap.insert({getKey(Info), llvm::hlsl::rootsig::ResourceRange(Allocator)});
+ auto [It, _] = VisRangeMap.insert(
+ {getKey(Info), llvm::hlsl::rootsig::ResourceRange(Allocator)});
auto Res = It->second.insert(Info);
if (Res.has_value())
return Res;
MutableArrayRef<MapT> Maps =
- Info.Vis == llvm::hlsl::rootsig::ShaderVisibility::All
- ? MutableArrayRef<MapT>{RangeMaps}.drop_front()
- : MutableArrayRef<MapT>{RangeMaps}.take_front();
+ Info.Vis == llvm::hlsl::rootsig::ShaderVisibility::All
+ ? MutableArrayRef<MapT>{RangeMaps}.drop_front()
+ : MutableArrayRef<MapT>{RangeMaps}.take_front();
for (MapT &CurMap : Maps) {
auto CurIt = CurMap.find(getKey(Info));
if (CurIt != CurMap.end())
if (auto Overlapping = CurIt->second.getOverlapping(Info))
- return Overlapping;
+ return Overlapping;
}
-
+
return std::nullopt;
}
};
@@ -1015,15 +1017,15 @@ bool SemaHLSL::handleRootSignatureDecl(HLSLRootSignatureDecl *D,
llvm::SmallVector<llvm::hlsl::rootsig::RangeInfo> Infos;
for (const auto &Elem : Elements) {
if (const auto *Param =
- std::get_if<llvm::hlsl::rootsig::RootParam>(&Elem)) {
- llvm::hlsl::rootsig::RangeInfo Info;
- Info.LowerBound = Param->Reg.Number;
- Info.UpperBound = Info.LowerBound; // use inclusive ranges []
+ std::get_if<llvm::hlsl::rootsig::RootParam>(&Elem)) {
+ llvm::hlsl::rootsig::RangeInfo Info;
+ Info.LowerBound = Param->Reg.Number;
+ Info.UpperBound = Info.LowerBound; // use inclusive ranges []
- Info.Class = Param->Type;
- Info.Space = Param->Space;
- Info.Vis = Param->Visibility;
- Infos.push_back(Info);
+ Info.Class = Param->Type;
+ Info.Space = Param->Space;
+ Info.Vis = Param->Visibility;
+ Infos.push_back(Info);
}
}
@@ -1032,14 +1034,16 @@ bool SemaHLSL::handleRootSignatureDecl(HLSLRootSignatureDecl *D,
bool HadOverlap = false;
for (const llvm::hlsl::rootsig::RangeInfo &Info : Infos)
if (auto MaybeOverlappingInfo = Ranges.addRange(Info)) {
- const llvm::hlsl::rootsig::RangeInfo *OInfo = MaybeOverlappingInfo.value();
+ const llvm::hlsl::rootsig::RangeInfo *OInfo =
+ MaybeOverlappingInfo.value();
auto CommonVis = Info.Vis == llvm::hlsl::rootsig::ShaderVisibility::All
- ? OInfo->Vis : Info.Vis;
+ ? OInfo->Vis
+ : Info.Vis;
Diag(Loc, diag::err_hlsl_resource_range_overlap)
- << llvm::to_underlying(Info.Class) << Info.LowerBound << Info.UpperBound
- << llvm::to_underlying(OInfo->Class) << OInfo->LowerBound << OInfo->UpperBound
- << Info.Space << CommonVis;
+ << llvm::to_underlying(Info.Class) << Info.LowerBound
+ << Info.UpperBound << llvm::to_underlying(OInfo->Class)
+ << OInfo->LowerBound << OInfo->UpperBound << Info.Space << CommonVis;
HadOverlap = true;
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/140962
More information about the llvm-branch-commits
mailing list