[llvm-branch-commits] [llvm] [DirectX] Improve error accumulation in root signature parsing (PR #144465)
llvm-beanz wrote: Looking at this PR and https://github.com/llvm/llvm-project/pull/144577 led me to look a bit more at the code around this. I think the way you're handling errors in this code is a bit sub-optimal. Instead of having a bunch of report functions and chains of functions returning `bool`, you could instead have the functions return `llvm::Error` and use `joinErrors` to build up chains of errors which you can then choose to report at a higher level in the API. The LLVM Programmers Manual has a good section about `llvm::Error`: https://llvm.org/docs/ProgrammersManual.html#id23 https://github.com/llvm/llvm-project/pull/144465 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [DirectX] Improve error accumulation in root signature parsing (PR #144465)
@@ -699,19 +736,20 @@ static bool verifyBorderColor(uint32_t BorderColor) {
static bool verifyLOD(float LOD) { return !std::isnan(LOD); }
static bool validate(LLVMContext *Ctx, const mcdxbc::RootSignatureDesc &RSD) {
-
+ bool HasError = false;
if (!verifyVersion(RSD.Version)) {
-return reportValueError(Ctx, "Version", RSD.Version);
+HasError = reportValueError(Ctx, "Version", RSD.Version) || HasError;
llvm-beanz wrote:
This pattern seems really awkward because the report functions always return
`true`. That means that the `||` is always unnecessary, but also the assignment
itself isn't really as clear to understand as it could be.
You could instead write this code as something like:
```
if (!verifyVersion(RSD.Version)) {
reportValueError(...);
HasError = true;
}
```
This is more verbose but a lot easier to see what is happening.
https://github.com/llvm/llvm-project/pull/144465
___
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [DirectX] Improve error accumulation in root signature parsing (PR #144465)
https://github.com/Icohedron approved this pull request. Looks fine to me https://github.com/llvm/llvm-project/pull/144465 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [DirectX] Improve error accumulation in root signature parsing (PR #144465)
https://github.com/joaosaffran edited https://github.com/llvm/llvm-project/pull/144465 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [DirectX] Improve error accumulation in root signature parsing (PR #144465)
https://github.com/inbelic edited https://github.com/llvm/llvm-project/pull/144465 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [DirectX] Improve error accumulation in root signature parsing (PR #144465)
inbelic wrote: I guess the awkward part is that it might be nice to clean up all the current error tests that are spread across many files to just one for each param type. https://github.com/llvm/llvm-project/pull/144465 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [DirectX] Improve error accumulation in root signature parsing (PR #144465)
llvmbot wrote: @llvm/pr-subscribers-backend-directx Author: None (joaosaffran) Changes This patch enhances error handling in the DirectX backend's root signature parsing, specifically in DXILRootSignature.cpp. The changes include: 1. Modify error handling to accumulate errors: - Replace early returns with error accumulation using HasError - Allow validation to continue after encountering an invalid type - Maintain original error reporting functionality while collecting multiple errors 2. Fix root flag parsing: - Use boolean accumulator for multiple validation errors - Improve invalid type reporting for root flag nodes - Maintain consistency with existing error reporting patterns Before this change, the parser would stop at the first error encountered. Now it continues validation, collecting all errors before returning. This provides a better developer experience by showing all issues that need to be fixed at once. Example of changes: ```cpp bool HasError = false; if (std::optionalVal = extractMdIntValue(RootFlagNode, 1)) RSD.Flags = *Val; else HasError = HasError || reportInvalidTypeError ( Ctx, "RootFlagNode", RootFlagNode, 1); return HasError; ``` Testing: - All existing DirectX backend tests pass - Verified error accumulation with multiple validation failures - Root signature parsing continues to work as expected --- Patch is 25.66 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/144465.diff 2 Files Affected: - (modified) llvm/lib/Target/DirectX/DXILRootSignature.cpp (+171-110) - (added) llvm/test/CodeGen/DirectX/ContainerData/RootSignature-Error-Accumulation.ll (+23) ``diff diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.cpp b/llvm/lib/Target/DirectX/DXILRootSignature.cpp index 57d5ee8ac467c..eea46e714b756 100644 --- a/llvm/lib/Target/DirectX/DXILRootSignature.cpp +++ b/llvm/lib/Target/DirectX/DXILRootSignature.cpp @@ -141,14 +141,15 @@ static bool parseRootFlags(LLVMContext *Ctx, mcdxbc::RootSignatureDesc &RSD, if (RootFlagNode->getNumOperands() != 2) return reportError(Ctx, "Invalid format for RootFlag Element"); - + bool HasError = false; if (std::optional Val = extractMdIntValue(RootFlagNode, 1)) RSD.Flags = *Val; else -return reportInvalidTypeError(Ctx, "RootFlagNode", - RootFlagNode, 1); +HasError = reportInvalidTypeError(Ctx, "RootFlagNode", + RootFlagNode, 1) || + HasError; - return false; + return HasError; } static bool parseRootConstants(LLVMContext *Ctx, mcdxbc::RootSignatureDesc &RSD, @@ -157,6 +158,7 @@ static bool parseRootConstants(LLVMContext *Ctx, mcdxbc::RootSignatureDesc &RSD, if (RootConstantNode->getNumOperands() != 5) return reportError(Ctx, "Invalid format for RootConstants Element"); + bool HasError = false; dxbc::RTS0::v1::RootParameterHeader Header; // The parameter offset doesn't matter here - we recalculate it during // serialization Header.ParameterOffset = 0; @@ -166,31 +168,35 @@ static bool parseRootConstants(LLVMContext *Ctx, mcdxbc::RootSignatureDesc &RSD, if (std::optional Val = extractMdIntValue(RootConstantNode, 1)) Header.ShaderVisibility = *Val; else -return reportInvalidTypeError(Ctx, "RootConstantNode", - RootConstantNode, 1); +HasError = reportInvalidTypeError(Ctx, "RootConstantNode", + RootConstantNode, 1) || + HasError; dxbc::RTS0::v1::RootConstants Constants; if (std::optional Val = extractMdIntValue(RootConstantNode, 2)) Constants.ShaderRegister = *Val; else -return reportInvalidTypeError(Ctx, "RootConstantNode", - RootConstantNode, 2); +HasError = reportInvalidTypeError(Ctx, "RootConstantNode", + RootConstantNode, 2) || + HasError; if (std::optional Val = extractMdIntValue(RootConstantNode, 3)) Constants.RegisterSpace = *Val; else -return reportInvalidTypeError(Ctx, "RootConstantNode", - RootConstantNode, 3); +HasError = reportInvalidTypeError(Ctx, "RootConstantNode", + RootConstantNode, 3) || + HasError; if (std::optional Val = extractMdIntValue(RootConstantNode, 4)) Constants.Num32BitValues = *Val; else -return reportInvalidTypeError(Ctx, "RootConstantNode", - RootConstantNode, 4); - - RSD.ParametersContainer.addParameter(Header, Constants); +HasError = reportInvalidTypeError(Ctx, "RootConstantNode", + RootConstantNode, 4)
[llvm-branch-commits] [llvm] [DirectX] Improve error accumulation in root signature parsing (PR #144465)
https://github.com/joaosaffran ready_for_review https://github.com/llvm/llvm-project/pull/144465 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [DirectX] Improve error accumulation in root signature parsing (PR #144465)
https://github.com/joaosaffran edited https://github.com/llvm/llvm-project/pull/144465 ___ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
[llvm-branch-commits] [llvm] [DirectX] Improve error accumulation in root signature parsing (PR #144465)
https://github.com/joaosaffran updated
https://github.com/llvm/llvm-project/pull/144465
>From ef396288dc10569cb1298e11ac4c67de6a5b5e03 Mon Sep 17 00:00:00 2001
From: joaosaffran
Date: Mon, 16 Jun 2025 21:54:47 +
Subject: [PATCH 1/3] allowing multiple errors
---
llvm/lib/Target/DirectX/DXILRootSignature.cpp | 250 ++
1 file changed, 141 insertions(+), 109 deletions(-)
diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.cpp
b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
index 57d5ee8ac467c..a09398864259a 100644
--- a/llvm/lib/Target/DirectX/DXILRootSignature.cpp
+++ b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
@@ -141,14 +141,14 @@ static bool parseRootFlags(LLVMContext *Ctx,
mcdxbc::RootSignatureDesc &RSD,
if (RootFlagNode->getNumOperands() != 2)
return reportError(Ctx, "Invalid format for RootFlag Element");
-
+ bool HasError = false;
if (std::optional Val = extractMdIntValue(RootFlagNode, 1))
RSD.Flags = *Val;
else
-return reportInvalidTypeError(Ctx, "RootFlagNode",
- RootFlagNode, 1);
+HasError = HasError || reportInvalidTypeError(
+ Ctx, "RootFlagNode", RootFlagNode, 1);
- return false;
+ return HasError;
}
static bool parseRootConstants(LLVMContext *Ctx, mcdxbc::RootSignatureDesc
&RSD,
@@ -157,6 +157,7 @@ static bool parseRootConstants(LLVMContext *Ctx,
mcdxbc::RootSignatureDesc &RSD,
if (RootConstantNode->getNumOperands() != 5)
return reportError(Ctx, "Invalid format for RootConstants Element");
+ bool HasError = false;
dxbc::RTS0::v1::RootParameterHeader Header;
// The parameter offset doesn't matter here - we recalculate it during
// serialization Header.ParameterOffset = 0;
@@ -166,31 +167,31 @@ static bool parseRootConstants(LLVMContext *Ctx,
mcdxbc::RootSignatureDesc &RSD,
if (std::optional Val = extractMdIntValue(RootConstantNode, 1))
Header.ShaderVisibility = *Val;
else
-return reportInvalidTypeError(Ctx, "RootConstantNode",
- RootConstantNode, 1);
+HasError = HasError || reportInvalidTypeError(
+ Ctx, "RootConstantNode", RootConstantNode, 1);
dxbc::RTS0::v1::RootConstants Constants;
if (std::optional Val = extractMdIntValue(RootConstantNode, 2))
Constants.ShaderRegister = *Val;
else
-return reportInvalidTypeError(Ctx, "RootConstantNode",
- RootConstantNode, 2);
+HasError = HasError || reportInvalidTypeError(
+ Ctx, "RootConstantNode", RootConstantNode, 2);
if (std::optional Val = extractMdIntValue(RootConstantNode, 3))
Constants.RegisterSpace = *Val;
else
-return reportInvalidTypeError(Ctx, "RootConstantNode",
- RootConstantNode, 3);
+HasError = HasError || reportInvalidTypeError(
+ Ctx, "RootConstantNode", RootConstantNode, 3);
if (std::optional Val = extractMdIntValue(RootConstantNode, 4))
Constants.Num32BitValues = *Val;
else
-return reportInvalidTypeError(Ctx, "RootConstantNode",
- RootConstantNode, 4);
-
- RSD.ParametersContainer.addParameter(Header, Constants);
+HasError = HasError || reportInvalidTypeError(
+ Ctx, "RootConstantNode", RootConstantNode, 4);
+ if (!HasError)
+RSD.ParametersContainer.addParameter(Header, Constants);
- return false;
+ return HasError;
}
static bool parseRootDescriptors(LLVMContext *Ctx,
@@ -205,6 +206,7 @@ static bool parseRootDescriptors(LLVMContext *Ctx,
if (RootDescriptorNode->getNumOperands() != 5)
return reportError(Ctx, "Invalid format for Root Descriptor Element");
+ bool HasError = false;
dxbc::RTS0::v1::RootParameterHeader Header;
switch (ElementKind) {
case RootSignatureElementKind::SRV:
@@ -224,36 +226,41 @@ static bool parseRootDescriptors(LLVMContext *Ctx,
if (std::optional Val = extractMdIntValue(RootDescriptorNode, 1))
Header.ShaderVisibility = *Val;
else
-return reportInvalidTypeError(Ctx, "RootDescriptorNode",
- RootDescriptorNode, 1);
+HasError = HasError ||
+ reportInvalidTypeError(Ctx, "RootDescriptorNode",
+ RootDescriptorNode, 1);
dxbc::RTS0::v2::RootDescriptor Descriptor;
if (std::optional Val = extractMdIntValue(RootDescriptorNode, 2))
Descriptor.ShaderRegister = *Val;
else
-return reportInvalidTypeError(Ctx, "RootDescriptorNode",
- RootDescriptorNode, 2);
+HasError = HasError ||
+ reportInvalidTypeError(Ctx, "RootDescriptorNode",
+ RootDescriptorNode, 2);
if (std::optional Val = extrac
[llvm-branch-commits] [llvm] [DirectX] Improve error accumulation in root signature parsing (PR #144465)
github-actions[bot] wrote:
:warning: C/C++ code formatter, clang-format found issues in your code.
:warning:
You can test this locally with the following command:
``bash
git-clang-format --diff HEAD~1 HEAD --extensions cpp --
llvm/lib/Target/DirectX/DXILRootSignature.cpp
``
View the diff from clang-format here.
``diff
diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.cpp
b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
index e96c680c6..eea46e714 100644
--- a/llvm/lib/Target/DirectX/DXILRootSignature.cpp
+++ b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
@@ -145,8 +145,9 @@ static bool parseRootFlags(LLVMContext *Ctx,
mcdxbc::RootSignatureDesc &RSD,
if (std::optional Val = extractMdIntValue(RootFlagNode, 1))
RSD.Flags = *Val;
else
-HasError = reportInvalidTypeError(
- Ctx, "RootFlagNode", RootFlagNode, 1) ||
HasError;
+HasError = reportInvalidTypeError(Ctx, "RootFlagNode",
+ RootFlagNode, 1) ||
+ HasError;
return HasError;
}
@@ -167,27 +168,31 @@ static bool parseRootConstants(LLVMContext *Ctx,
mcdxbc::RootSignatureDesc &RSD,
if (std::optional Val = extractMdIntValue(RootConstantNode, 1))
Header.ShaderVisibility = *Val;
else
-HasError = reportInvalidTypeError(
- Ctx, "RootConstantNode", RootConstantNode, 1)
|| HasError;
+HasError = reportInvalidTypeError(Ctx, "RootConstantNode",
+ RootConstantNode, 1) ||
+ HasError;
dxbc::RTS0::v1::RootConstants Constants;
if (std::optional Val = extractMdIntValue(RootConstantNode, 2))
Constants.ShaderRegister = *Val;
else
-HasError = reportInvalidTypeError (
- Ctx, "RootConstantNode", RootConstantNode, 2)
|| HasError;
+HasError = reportInvalidTypeError(Ctx, "RootConstantNode",
+ RootConstantNode, 2) ||
+ HasError;
if (std::optional Val = extractMdIntValue(RootConstantNode, 3))
Constants.RegisterSpace = *Val;
else
-HasError = reportInvalidTypeError (
- Ctx, "RootConstantNode", RootConstantNode, 3)
|| HasError;
+HasError = reportInvalidTypeError(Ctx, "RootConstantNode",
+ RootConstantNode, 3) ||
+ HasError;
if (std::optional Val = extractMdIntValue(RootConstantNode, 4))
Constants.Num32BitValues = *Val;
else
-HasError = reportInvalidTypeError (
- Ctx, "RootConstantNode", RootConstantNode, 4)
|| HasError;
+HasError = reportInvalidTypeError(Ctx, "RootConstantNode",
+ RootConstantNode, 4) ||
+ HasError;
if (!HasError)
RSD.ParametersContainer.addParameter(Header, Constants);
@@ -226,24 +231,24 @@ static bool parseRootDescriptors(LLVMContext *Ctx,
if (std::optional Val = extractMdIntValue(RootDescriptorNode, 1))
Header.ShaderVisibility = *Val;
else
-HasError =
- reportInvalidTypeError(Ctx, "RootDescriptorNode",
- RootDescriptorNode, 1)||
HasError;
+HasError = reportInvalidTypeError(Ctx, "RootDescriptorNode",
+ RootDescriptorNode, 1) ||
+ HasError;
dxbc::RTS0::v2::RootDescriptor Descriptor;
if (std::optional Val = extractMdIntValue(RootDescriptorNode, 2))
Descriptor.ShaderRegister = *Val;
else
-HasError =
- reportInvalidTypeError(Ctx, "RootDescriptorNode",
- RootDescriptorNode, 2)||
HasError;
+HasError = reportInvalidTypeError(Ctx, "RootDescriptorNode",
+ RootDescriptorNode, 2) ||
+ HasError;
if (std::optional Val = extractMdIntValue(RootDescriptorNode, 3))
Descriptor.RegisterSpace = *Val;
else
-HasError =
- reportInvalidTypeError(Ctx, "RootDescriptorNode",
- RootDescriptorNode, 3)||
HasError;
+HasError = reportInvalidTypeError(Ctx, "RootDescriptorNode",
+ RootDescriptorNode, 3) ||
+ HasError;
if (RSD.Version == 1) {
if (!HasError)
@@ -255,9 +260,9 @@ static bool parseRootDescriptors(LLVMContext *Ctx,
if (std::optional Val = extractMdIntValue(RootDescriptorNode, 4))
Descriptor.Flags = *Val;
else
-HasError =
- reportInvalidTypeError(Ctx, "RootDescriptorNode",
- RootDescriptorNode, 4)||
HasError;
+HasError = reportInvalidTypeError(Ctx, "RootDescriptorNode",
+ RootDes
[llvm-branch-commits] [llvm] [DirectX] Improve error accumulation in root signature parsing (PR #144465)
https://github.com/joaosaffran updated
https://github.com/llvm/llvm-project/pull/144465
>From ef396288dc10569cb1298e11ac4c67de6a5b5e03 Mon Sep 17 00:00:00 2001
From: joaosaffran
Date: Mon, 16 Jun 2025 21:54:47 +
Subject: [PATCH 1/2] allowing multiple errors
---
llvm/lib/Target/DirectX/DXILRootSignature.cpp | 250 ++
1 file changed, 141 insertions(+), 109 deletions(-)
diff --git a/llvm/lib/Target/DirectX/DXILRootSignature.cpp
b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
index 57d5ee8ac467c..a09398864259a 100644
--- a/llvm/lib/Target/DirectX/DXILRootSignature.cpp
+++ b/llvm/lib/Target/DirectX/DXILRootSignature.cpp
@@ -141,14 +141,14 @@ static bool parseRootFlags(LLVMContext *Ctx,
mcdxbc::RootSignatureDesc &RSD,
if (RootFlagNode->getNumOperands() != 2)
return reportError(Ctx, "Invalid format for RootFlag Element");
-
+ bool HasError = false;
if (std::optional Val = extractMdIntValue(RootFlagNode, 1))
RSD.Flags = *Val;
else
-return reportInvalidTypeError(Ctx, "RootFlagNode",
- RootFlagNode, 1);
+HasError = HasError || reportInvalidTypeError(
+ Ctx, "RootFlagNode", RootFlagNode, 1);
- return false;
+ return HasError;
}
static bool parseRootConstants(LLVMContext *Ctx, mcdxbc::RootSignatureDesc
&RSD,
@@ -157,6 +157,7 @@ static bool parseRootConstants(LLVMContext *Ctx,
mcdxbc::RootSignatureDesc &RSD,
if (RootConstantNode->getNumOperands() != 5)
return reportError(Ctx, "Invalid format for RootConstants Element");
+ bool HasError = false;
dxbc::RTS0::v1::RootParameterHeader Header;
// The parameter offset doesn't matter here - we recalculate it during
// serialization Header.ParameterOffset = 0;
@@ -166,31 +167,31 @@ static bool parseRootConstants(LLVMContext *Ctx,
mcdxbc::RootSignatureDesc &RSD,
if (std::optional Val = extractMdIntValue(RootConstantNode, 1))
Header.ShaderVisibility = *Val;
else
-return reportInvalidTypeError(Ctx, "RootConstantNode",
- RootConstantNode, 1);
+HasError = HasError || reportInvalidTypeError(
+ Ctx, "RootConstantNode", RootConstantNode, 1);
dxbc::RTS0::v1::RootConstants Constants;
if (std::optional Val = extractMdIntValue(RootConstantNode, 2))
Constants.ShaderRegister = *Val;
else
-return reportInvalidTypeError(Ctx, "RootConstantNode",
- RootConstantNode, 2);
+HasError = HasError || reportInvalidTypeError(
+ Ctx, "RootConstantNode", RootConstantNode, 2);
if (std::optional Val = extractMdIntValue(RootConstantNode, 3))
Constants.RegisterSpace = *Val;
else
-return reportInvalidTypeError(Ctx, "RootConstantNode",
- RootConstantNode, 3);
+HasError = HasError || reportInvalidTypeError(
+ Ctx, "RootConstantNode", RootConstantNode, 3);
if (std::optional Val = extractMdIntValue(RootConstantNode, 4))
Constants.Num32BitValues = *Val;
else
-return reportInvalidTypeError(Ctx, "RootConstantNode",
- RootConstantNode, 4);
-
- RSD.ParametersContainer.addParameter(Header, Constants);
+HasError = HasError || reportInvalidTypeError(
+ Ctx, "RootConstantNode", RootConstantNode, 4);
+ if (!HasError)
+RSD.ParametersContainer.addParameter(Header, Constants);
- return false;
+ return HasError;
}
static bool parseRootDescriptors(LLVMContext *Ctx,
@@ -205,6 +206,7 @@ static bool parseRootDescriptors(LLVMContext *Ctx,
if (RootDescriptorNode->getNumOperands() != 5)
return reportError(Ctx, "Invalid format for Root Descriptor Element");
+ bool HasError = false;
dxbc::RTS0::v1::RootParameterHeader Header;
switch (ElementKind) {
case RootSignatureElementKind::SRV:
@@ -224,36 +226,41 @@ static bool parseRootDescriptors(LLVMContext *Ctx,
if (std::optional Val = extractMdIntValue(RootDescriptorNode, 1))
Header.ShaderVisibility = *Val;
else
-return reportInvalidTypeError(Ctx, "RootDescriptorNode",
- RootDescriptorNode, 1);
+HasError = HasError ||
+ reportInvalidTypeError(Ctx, "RootDescriptorNode",
+ RootDescriptorNode, 1);
dxbc::RTS0::v2::RootDescriptor Descriptor;
if (std::optional Val = extractMdIntValue(RootDescriptorNode, 2))
Descriptor.ShaderRegister = *Val;
else
-return reportInvalidTypeError(Ctx, "RootDescriptorNode",
- RootDescriptorNode, 2);
+HasError = HasError ||
+ reportInvalidTypeError(Ctx, "RootDescriptorNode",
+ RootDescriptorNode, 2);
if (std::optional Val = extrac
