[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


================
@@ -26,6 +28,73 @@ 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;
+  std::string Message;
+
+  GenericRSMetadataError(Twine Message) : Message(Message.str()) {}
+
+  void log(raw_ostream &OS) const override { OS << Message; }
+
+  std::error_code convertToErrorCode() const override {
+    return llvm::inconvertibleErrorCode();
+  }
+};
+
+class InvalidRSMetadataFormat : public ErrorInfo<InvalidRSMetadataFormat> {
+public:
+  static char ID;
+  std::string ElementName;
----------------
llvm-beanz wrote:

Does this need to be a `std::string`? Looks like it is always called with a constant string, so this could just be a `StringRef`.

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


More information about the llvm-commits mailing list