Skip to content

[Offload] Fix Error checking #141939

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 29, 2025
Merged

[Offload] Fix Error checking #141939

merged 1 commit into from
May 29, 2025

Conversation

RossBrunton
Copy link
Contributor

All errors must be checked - this includes the local variable we were
using to increase the lifetime of Res. As we were not explicitly
checking it, it resulted in an abort in debug builds.

All errors must be checked - this includes the local variable we were
using to increase the lifetime of `Res`. As we were not explicitly
checking it, it resulted in an `abort` in debug builds.
@llvmbot
Copy link
Member

llvmbot commented May 29, 2025

@llvm/pr-subscribers-offload

Author: Ross Brunton (RossBrunton)

Changes

All errors must be checked - this includes the local variable we were
using to increase the lifetime of Res. As we were not explicitly
checking it, it resulted in an abort in debug builds.


Full diff: https://github.com/llvm/llvm-project/pull/141939.diff

1 Files Affected:

  • (modified) offload/liboffload/src/OffloadImpl.cpp (+9-7)
diff --git a/offload/liboffload/src/OffloadImpl.cpp b/offload/liboffload/src/OffloadImpl.cpp
index a5935a7e5b318..7b67cbba43e68 100644
--- a/offload/liboffload/src/OffloadImpl.cpp
+++ b/offload/liboffload/src/OffloadImpl.cpp
@@ -416,18 +416,20 @@ Error olMemcpy_impl(ol_queue_handle_t Queue, void *DstPtr,
 
   // If no queue is given the memcpy will be synchronous
   auto QueueImpl = Queue ? Queue->AsyncInfo : nullptr;
-  Error Res = Error::success();
 
   if (DstDevice == HostDevice()) {
-    Res = SrcDevice->Device->dataRetrieve(DstPtr, SrcPtr, Size, QueueImpl);
+    if (auto Res =
+            SrcDevice->Device->dataRetrieve(DstPtr, SrcPtr, Size, QueueImpl))
+      return Res;
   } else if (SrcDevice == HostDevice()) {
-    Res = DstDevice->Device->dataSubmit(DstPtr, SrcPtr, Size, QueueImpl);
+    if (auto Res =
+            DstDevice->Device->dataSubmit(DstPtr, SrcPtr, Size, QueueImpl))
+      return Res;
   } else {
-    Res = SrcDevice->Device->dataExchange(SrcPtr, *DstDevice->Device, DstPtr,
-                                          Size, QueueImpl);
+    if (auto Res = SrcDevice->Device->dataExchange(SrcPtr, *DstDevice->Device,
+                                                   DstPtr, Size, QueueImpl))
+      return Res;
   }
-  if (Res)
-    return Res;
 
   if (EventOut)
     *EventOut = makeEvent(Queue);

@jhuber6 jhuber6 merged commit 7efb79b into llvm:main May 29, 2025
11 checks passed
svkeerthy pushed a commit that referenced this pull request May 29, 2025
All errors must be checked - this includes the local variable we were
using to increase the lifetime of `Res`. As we were not explicitly
checking it, it resulted in an `abort` in debug builds.
google-yfyang pushed a commit to google-yfyang/llvm-project that referenced this pull request May 29, 2025
All errors must be checked - this includes the local variable we were
using to increase the lifetime of `Res`. As we were not explicitly
checking it, it resulted in an `abort` in debug builds.
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Jun 3, 2025
All errors must be checked - this includes the local variable we were
using to increase the lifetime of `Res`. As we were not explicitly
checking it, it resulted in an `abort` in debug builds.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants