[llvm] [Offload] Add Error Codes to PluginInterface (PR #138258)

Ross Brunton via llvm-commits llvm-commits at lists.llvm.org
Wed May 7 06:54:41 PDT 2025


================
@@ -58,6 +58,30 @@ struct GenericKernelTy;
 struct GenericDeviceTy;
 struct RecordReplayTy;
 
+enum class ErrorCode {
+#define OFFLOAD_ERRC(Name, _, Value) Name = Value,
+#include "OffloadErrcodes.inc"
+#undef OFFLOAD_ERRC
+};
+
+class OffloadErrorCategory : public std::error_category {
+  const char *name() const noexcept override { return "Offload Error"; }
+  std::string message(int ev) const override {
+    switch (static_cast<ErrorCode>(ev)) {
+#define OFFLOAD_ERRC(Name, Desc, Value)                                        \
+  case ErrorCode::Name:                                                        \
+    return #Desc;
+#include "OffloadErrcodes.inc"
+#undef OFFLOAD_ERRC
+    }
+  }
+};
+
+inline std::error_code make_error_code(ErrorCode EC) {
+  static OffloadErrorCategory Cat{};
+  return {static_cast<int>(EC), Cat};
+}
----------------
RossBrunton wrote:

I've just pushed a new version where I've basically copied how PDB/MSF/etc handle their string-based error types. They do seem to have their own error category though, so I've left that in.

I did do some more digging and I found that apparently the generic category should only be used for `errno` error codes, which means we can't use it for liboffload.

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


More information about the llvm-commits mailing list