[llvm] [Offload] Fix Error checking (PR #141939)

Ross Brunton via llvm-commits llvm-commits at lists.llvm.org
Thu May 29 06:04:49 PDT 2025


https://github.com/RossBrunton created https://github.com/llvm/llvm-project/pull/141939

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.


>From dd58a88342fa9d97cfc09661ba17d7c58608d38a Mon Sep 17 00:00:00 2001
From: Ross Brunton <ross at codeplay.com>
Date: Thu, 29 May 2025 14:01:58 +0100
Subject: [PATCH] [Offload] Fix Error checking

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.
---
 offload/liboffload/src/OffloadImpl.cpp | 16 +++++++++-------
 1 file changed, 9 insertions(+), 7 deletions(-)

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);



More information about the llvm-commits mailing list