[llvm] [Offload][Omp] Ensure errors are consumed when debug is off (PR #230668)

Alex Duran via llvm-commits llvm-commits at lists.llvm.org
Fri Oct 9 13:57:52 PDT 2026


https://github.com/adurang created https://github.com/llvm/llvm-project/pull/230668

When debug is off (either not enabled at compile or runtime) the code consuming the Error (e.g., toString) is not executed and the program can potentially abort with an unconsumed error (reported by @ro-i).

Claude scanned for ocurrences of this pattern and only the messages introduced by #226450 seem to be affected.

Note that messages using `REPORT()` unlike `ODBG` are safe.

>From b5959a9f85438ac8adf03ddec30ab48a89bd8c81 Mon Sep 17 00:00:00 2001
From: "Duran, Alex" <alejandro.duran at intel.com>
Date: Fri, 9 Oct 2026 13:29:16 -0700
Subject: [PATCH] [Offload][Omp] Ensure errors are consumed when debug is off

When debug is off (either not enabled at compile or runtime) the code
consuming the Error (e.g., toString) is not executed and the program
can potentially abort with an unconsumed error (reported by @ro-i).

Claude scanned for ocurrences of this pattern and only the messages
introduced by #226450 seem to be affected.

Note that messages using `REPORT()` unlike `ODBG` are safe.
---
 offload/libomptarget/omptarget.cpp | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/offload/libomptarget/omptarget.cpp b/offload/libomptarget/omptarget.cpp
index 67afa9c13e4aa..5176e94e71c3b 100644
--- a/offload/libomptarget/omptarget.cpp
+++ b/offload/libomptarget/omptarget.cpp
@@ -222,8 +222,8 @@ void *targetLockExplicit(void *HostPtr, size_t Size, int DeviceNum,
   // Register and page-lock the memory.
   auto LockedPtrOrErr = DeviceOrErr->registerMemory(HostPtr, Size);
   if (!LockedPtrOrErr) {
-    ODBG(ODT_Interface) << "Could not lock ptr " << HostPtr << ": "
-                        << toString(LockedPtrOrErr.takeError());
+    std::string ErrStr = toString(LockedPtrOrErr.takeError());
+    ODBG(ODT_Interface) << "Could not lock ptr " << HostPtr << ": " << ErrStr;
     return nullptr;
   }
   ODBG(ODT_Interface) << Name << " returns device ptr " << *LockedPtrOrErr;
@@ -239,9 +239,10 @@ void targetUnlockExplicit(void *HostPtr, int DeviceNum, const char *Name) {
     FATAL_MESSAGE(DeviceNum, "%s", toString(DeviceOrErr.takeError()).c_str());
 
   // Unregister and unlock the memory.
-  if (auto Err = DeviceOrErr->unregisterMemory(HostPtr))
-    ODBG(ODT_Interface) << "Could not unlock ptr " << HostPtr << ": "
-                        << toString(std::move(Err));
+  if (auto Err = DeviceOrErr->unregisterMemory(HostPtr)) {
+    std::string ErrStr = toString(std::move(Err));
+    ODBG(ODT_Interface) << "Could not unlock ptr " << HostPtr << ": " << ErrStr;
+  }
   ODBG(ODT_Interface) << Name << " returns";
 }
 



More information about the llvm-commits mailing list