[llvm] [Offload] Fix segfault when looking for host device name (PR #141632)
Joseph Huber via llvm-commits
llvm-commits at lists.llvm.org
Tue May 27 09:57:15 PDT 2025
https://github.com/jhuber6 created https://github.com/llvm/llvm-project/pull/141632
Summary:
This is done using the generic device into pointe, but no such thing
exists for the host device, leading to a segfault. This patch fixes that
for now, but in the future we should probably be more careful in general
handling the possibility that the handle is null everywhere.
Fixes: https://github.com/llvm/llvm-project/issues/141434
>From 880de292d1ee71ef3d738127df7fc5a498ab36ac Mon Sep 17 00:00:00 2001
From: Joseph Huber <huberjn at outlook.com>
Date: Tue, 27 May 2025 11:52:25 -0500
Subject: [PATCH] [Offload] Fix segfault when looking for host device name
Summary:
This is done using the generic device into pointe, but no such thing
exists for the host device, leading to a segfault. This patch fixes that
for now, but in the future we should probably be more careful in general
handling the possibility that the handle is null everywhere.
Fixes: https://github.com/llvm/llvm-project/issues/141434
---
offload/liboffload/src/OffloadImpl.cpp | 6 ++++++
.../unittests/OffloadAPI/device/olGetDeviceInfo.cpp | 10 ++++++++++
2 files changed, 16 insertions(+)
diff --git a/offload/liboffload/src/OffloadImpl.cpp b/offload/liboffload/src/OffloadImpl.cpp
index ea65282e3ba52..ac2ca20601cae 100644
--- a/offload/liboffload/src/OffloadImpl.cpp
+++ b/offload/liboffload/src/OffloadImpl.cpp
@@ -230,6 +230,12 @@ ol_impl_result_t olGetDeviceInfoImplDetail(ol_device_handle_t Device,
// Find the info if it exists under any of the given names
auto GetInfo = [&](std::vector<std::string> Names) {
InfoQueueTy DevInfo;
+ if (Device == HostDevice())
+ return std::string("Host");
+
+ if (!Device->Device)
+ return std::string("");
+
if (auto Err = Device->Device->obtainInfoImpl(DevInfo))
return std::string("");
diff --git a/offload/unittests/OffloadAPI/device/olGetDeviceInfo.cpp b/offload/unittests/OffloadAPI/device/olGetDeviceInfo.cpp
index 46ed622fa8b81..1240f219813e2 100644
--- a/offload/unittests/OffloadAPI/device/olGetDeviceInfo.cpp
+++ b/offload/unittests/OffloadAPI/device/olGetDeviceInfo.cpp
@@ -37,6 +37,16 @@ TEST_P(olGetDeviceInfoTest, SuccessName) {
ASSERT_EQ(std::strlen(Name.data()), Size - 1);
}
+TEST_P(olGetDeviceInfoTest, HostName) {
+ size_t Size = 0;
+ ASSERT_SUCCESS(olGetDeviceInfoSize(Host, OL_DEVICE_INFO_NAME, &Size));
+ ASSERT_GT(Size, 0ul);
+ std::vector<char> Name;
+ Name.resize(Size);
+ ASSERT_SUCCESS(olGetDeviceInfo(Host, OL_DEVICE_INFO_NAME, Size, Name.data()));
+ ASSERT_EQ(std::strlen(Name.data()), Size - 1);
+}
+
TEST_P(olGetDeviceInfoTest, SuccessVendor) {
size_t Size = 0;
ASSERT_SUCCESS(olGetDeviceInfoSize(Device, OL_DEVICE_INFO_VENDOR, &Size));
More information about the llvm-commits
mailing list