[llvm] [DirectX] Error handling improve in root signature metadata Parser (PR #149232)

Chris B via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 25 10:29:45 PDT 2025


================
@@ -111,14 +110,23 @@ analyzeModule(Module &M) {
       reportError(Ctx, "Root Element is not a metadata node.");
       continue;
     }
-    mcdxbc::RootSignatureDesc RSD;
-    if (std::optional<uint32_t> Version = extractMdIntValue(RSDefNode, 2))
-      RSD.Version = *Version;
-    else {
+    std::optional<uint32_t> V = extractMdIntValue(RSDefNode, 2);
+    if (!V.has_value()) {
       reportError(Ctx, "Invalid RSDefNode value, expected constant int");
       continue;
     }
 
+    llvm::hlsl::rootsig::MetadataParser MDParser(RootElementListNode);
+    llvm::Expected<mcdxbc::RootSignatureDesc> RSDOrErr =
+        MDParser.ParseRootSignature(V.value());
+
+    if (auto Err = RSDOrErr.takeError()) {
+      reportError(Ctx, toString(std::move(Err)));
----------------
llvm-beanz wrote:

In general with errors especially if they can be more than one error you don't just want to call toString, you should handle each error.

I think this is about right, but you'll need to try it:
```suggestion
    if (!RSDOrErr) {
      handleAllErrors(RSDOrErr.takeError(), [&](ErrorInfoBase &EIB) {
        Ctx->emitError(EI.message());
      });
```

https://github.com/llvm/llvm-project/pull/149232


More information about the llvm-commits mailing list