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

Chris B via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 28 11:47:56 PDT 2025


================
@@ -26,6 +28,80 @@ class Metadata;
 namespace hlsl {
 namespace rootsig {
 
+template <typename T>
+class RootSignatureValidationError
+    : public ErrorInfo<RootSignatureValidationError<T>> {
+public:
+  static char ID;
+  std::string ParamName;
+  T Value;
+
+  RootSignatureValidationError(StringRef ParamName, T Value)
+      : ParamName(ParamName.str()), Value(Value) {}
+
+  void log(raw_ostream &OS) const override {
+    OS << "Invalid value for " << ParamName << ": " << Value;
+  }
+
+  std::error_code convertToErrorCode() const override {
+    return llvm::inconvertibleErrorCode();
+  }
+};
+
+class GenericRSMetadataError : public ErrorInfo<GenericRSMetadataError> {
+public:
+  static char ID;
+  Twine Message;
----------------
llvm-beanz wrote:

Storing twines is bad. Twines don't actually own the underlying components of the construction, so if anything goes out of scope it will be a memory violation.

The only places where you're doing any string construction is where you are storing strings derived from the MDNode, which is why I suggested instead just taking the MDNode and printing it.

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


More information about the llvm-commits mailing list