[llvm] [Offload] Add Error Codes to PluginInterface (PR #138258)
Joseph Huber via llvm-commits
llvm-commits at lists.llvm.org
Mon May 5 08:14:03 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};
+}
----------------
jhuber6 wrote:
Yeah, but shouldn't we be able to use `https://en.cppreference.com/w/cpp/error/errc/make_error_code` for the generic category? I don't think having an `offload` category helps us here since it's not used for anything. The string message is going to come from the person who created the error, so we only care about the numerical part of the error code.
https://github.com/llvm/llvm-project/pull/138258
More information about the llvm-commits
mailing list