[llvm] [OMPIRBuilder] Fix use of uninitialized variable. (PR #145883)

Abid Qadeer via llvm-commits llvm-commits at lists.llvm.org
Thu Jun 26 05:54:13 PDT 2025


https://github.com/abidh created https://github.com/llvm/llvm-project/pull/145883

The code in `OpenMPIRBuilder::getTargetEntryUniqueInfo` calls `ID.getDevice()` even when `getUniqueID` has failed and ID is un-initialized. This caused a sanitizer fail for me in https://github.com/llvm/llvm-project/pull/145026. Fix it by giving a default value to `ID`. The value chosen is the same as used in `OpenMPToLLVMIRTranslation.cpp`.

>From 500d2ba23a5f6a7e3701294be2c07a77420f73d1 Mon Sep 17 00:00:00 2001
From: Abid Qadeer <haqadeer at amd.com>
Date: Thu, 26 Jun 2025 13:47:36 +0100
Subject: [PATCH] [OMPIRBuilder] Fix use of uninitialized variable.

The code in OpenMPIRBuilder::getTargetEntryUniqueInfo calls
ID.getDevice() even when getUniqueID has failed and ID is
un-initialized. This caused a sanitizer fail for me in
https://github.com/llvm/llvm-project/pull/145026. Fix it by giving
a default value to ID. The value chosen is the same as used in
OpenMPToLLVMIRTranslation.cpp.
---
 llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
index d4f95be083a47..85451b1233f96 100644
--- a/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
+++ b/llvm/lib/Frontend/OpenMP/OMPIRBuilder.cpp
@@ -9846,7 +9846,7 @@ void OffloadEntriesInfoManager::getTargetRegionEntryFnName(
 TargetRegionEntryInfo
 OpenMPIRBuilder::getTargetEntryUniqueInfo(FileIdentifierInfoCallbackTy CallBack,
                                           StringRef ParentName) {
-  sys::fs::UniqueID ID;
+  sys::fs::UniqueID ID(0xdeadf17e, 0);
   auto FileIDInfo = CallBack();
   uint64_t FileID = 0;
   std::error_code EC = sys::fs::getUniqueID(std::get<0>(FileIDInfo), ID);



More information about the llvm-commits mailing list