[llvm] [Offload] Use llvm::Error throughout liboffload internals (PR #140879)

Joseph Huber via llvm-commits llvm-commits at lists.llvm.org
Wed May 21 05:48:57 PDT 2025


================
@@ -69,48 +69,31 @@ struct ErrPtrHash {
 using ErrSetT = std::unordered_set<ErrPtrT, ErrPtrHash, ErrPtrEqual>;
 ErrSetT &errors();
 
-struct ol_impl_result_t {
-  ol_impl_result_t(std::nullptr_t) : Result(OL_SUCCESS) {}
-  ol_impl_result_t(ol_errc_t Code) {
-    if (Code == OL_ERRC_SUCCESS) {
-      Result = nullptr;
-    } else {
-      auto Err = std::unique_ptr<ol_error_struct_t>(
-          new ol_error_struct_t{Code, nullptr});
-      Result = errors().emplace(std::move(Err)).first->get();
-    }
-  }
-
-  ol_impl_result_t(ol_errc_t Code, llvm::StringRef Details) {
-    assert(Code != OL_ERRC_SUCCESS);
-    Result = nullptr;
-    auto DetailsStr = errorStrs().insert(Details).first->getKeyData();
-    auto Err = std::unique_ptr<ol_error_struct_t>(
-        new ol_error_struct_t{Code, DetailsStr});
-    Result = errors().emplace(std::move(Err)).first->get();
+namespace {
+ol_errc_t GetErrorCode(std::error_code Code) {
+  if (Code.category() ==
+      error::make_error_code(error::ErrorCode::SUCCESS).category()) {
+    return static_cast<ol_errc_t>(Code.value());
   }
+  return OL_ERRC_UNKNOWN;
+}
+} // namespace
 
-  static ol_impl_result_t fromError(llvm::Error &&Error) {
-    ol_errc_t ErrCode;
-    llvm::StringRef Details;
-    llvm::handleAllErrors(std::move(Error), [&](llvm::StringError &Err) {
-      ErrCode = GetErrorCode(Err.convertToErrorCode());
-      Details = errorStrs().insert(Err.getMessage()).first->getKeyData();
-    });
-
-    return ol_impl_result_t{ErrCode, Details};
+inline ol_result_t llvmErrorToOffloadError(llvm::Error &&Err) {
+  if (!Err) {
+    // No error
+    return nullptr;
   }
----------------
jhuber6 wrote:

```suggestion
  if (!Err)
    return nullptr;
```
Shouldn't we have a success type?

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


More information about the llvm-commits mailing list