Skip to content

Commit 0b0f02d

Browse files
authored
[libc] Fix llvm-gpu-loader passing uninitialized device memory (llvm#186804)
Summary: The return value was not zeroed, this was accidentally dropped when we did the port and it's zero "almost always" so I didn't notice. Hopefully this makes the test suite no longer flaky.
1 parent 02a2ccb commit 0b0f02d

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

llvm/tools/llvm-gpu-loader/llvm-gpu-loader.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,9 @@ int main(int argc, const char **argv, const char **envp) {
268268
void *DevEnvp = copyEnvironment(envp, Device);
269269

270270
void *DevRet;
271+
int Zero = 0;
271272
OFFLOAD_ERR(olMemAlloc(Device, OL_ALLOC_TYPE_DEVICE, sizeof(int), &DevRet));
273+
OFFLOAD_ERR(olMemcpy(Queue, DevRet, Device, &Zero, Host, sizeof(int)));
272274

273275
ol_kernel_launch_size_args_t BeginLaunch{1, {1, 1, 1}, {1, 1, 1}, 0};
274276
BeginArgs BeginArgs = {DevArgc, DevArgv, DevEnvp};
@@ -291,6 +293,7 @@ int main(int argc, const char **argv, const char **envp) {
291293
OFFLOAD_ERR(olMemcpy(Queue, &Ret, Host, DevRet, Device, sizeof(int)));
292294
OFFLOAD_ERR(olSyncQueue(Queue));
293295

296+
OFFLOAD_ERR(olMemFree(DevRet));
294297
OFFLOAD_ERR(olMemFree(DevArgv));
295298
OFFLOAD_ERR(olMemFree(DevEnvp));
296299
OFFLOAD_ERR(olDestroyQueue(Queue));

0 commit comments

Comments
 (0)