Issue |
141434
|
Summary |
[Offload] Segmentation fault when calling `olGetDeviceInfoSize` for host device name
|
Labels |
new issue
|
Assignees |
|
Reporter |
leandrolcampos
|
A segmentation fault occurs when calling `olGetDeviceInfoSize` to retrieve the size of the device name for the host device.
The crash happens specifically when `olGetDeviceInfoSize` is called with `OL_DEVICE_INFO_NAME` for the host device handle.
**Steps to Reproduce:**
1. Compile the C++ code snippet provided below using Clang and linking against the LLVMOffload library.
```bash
$ clang++ -std=c++17 host.cpp -I"$LLVM_HOME/include" -L"$LLVM_HOME/lib" -lLLVMOffload -ldl -lpthread -Wl,-rpath,"$LLVM_HOME/lib" -o host
```
2. Execute the compiled program:
```bash
$ ./host
```
3. Observe the output.
**Program Output:**
```bash
Getting the storage size of the device name...
Segmentation fault (core dumped)
```
**Code Snippet:**
```cpp
#include <iostream>
#include <offload/OffloadAPI.h>
#include <string>
ol_device_handle_t getHostDevice() {
static ol_device_handle_t HostDevice = nullptr;
if (!HostDevice) {
olIterateDevices(
[](ol_device_handle_t D, void *Data) {
ol_platform_handle_t Platform;
olGetDeviceInfo(D, OL_DEVICE_INFO_PLATFORM, sizeof(Platform),
&Platform);
ol_platform_backend_t Backend;
olGetPlatformInfo(Platform, OL_PLATFORM_INFO_BACKEND, sizeof(Backend),
&Backend);
if (Backend == OL_PLATFORM_BACKEND_HOST) {
*(static_cast<ol_device_handle_t *>(Data)) = D;
return false;
}
return true;
},
&HostDevice);
}
return HostDevice;
}
int main() {
olInit();
auto HostDevice = getHostDevice();
if (HostDevice == nullptr) {
std::cout << "Host device not found." << std::endl;
return 1;
}
std::cout << "Getting the storage size of the device name..." << std::endl;
size_t Size = 0;
olGetDeviceInfoSize(HostDevice, OL_DEVICE_INFO_NAME, &Size);
std::cout << "Getting the device name..." << std::endl;
std::string Name(Size, '\0');
olGetDeviceInfo(HostDevice, OL_DEVICE_INFO_NAME, Size, Name.data());
Name.pop_back();
std::cout << "Device name: " << Name << std::endl;
olShutDown();
return 0;
}
```
**Environment:**
* LLVM version: Custom build from git
* LLVM Project Commit Hash: `1e4841881ef89aeee77cbf081de42af376bfa3fb`
* Operating System: Ubuntu 24.04.2 LTS (WSL2)
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs