[llvm] [PDB] Fix and simplify module index lookup (PR #179869)

Haohai Wen via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 4 22:01:02 PST 2026


https://github.com/HaohaiWen created https://github.com/llvm/llvm-project/pull/179869

The range returned by IntervalMap::find is only guranteed to end after
address queried. We have to check whether queried address is inside this
range.

>From 52654532e95fd02be89744066ea9134c10e7f423 Mon Sep 17 00:00:00 2001
From: Haohai Wen <haohai.wen at intel.com>
Date: Thu, 5 Feb 2026 13:54:18 +0800
Subject: [PATCH] [PDB] Fix and simplify module index lookup

The range returned by IntervalMap::find is only guaranteed to end after
queried address. We have to check whether the queried address is within
this range.
---
 llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp b/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp
index 49674b4c32de0..cfa3328f5f2d6 100644
--- a/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp
+++ b/llvm/lib/DebugInfo/PDB/Native/NativeSession.cpp
@@ -410,20 +410,16 @@ uint64_t NativeSession::getVAFromSectOffset(uint32_t Section,
 bool NativeSession::moduleIndexForVA(uint64_t VA, uint16_t &ModuleIndex) const {
   ModuleIndex = 0;
   auto Iter = AddrToModuleIndex.find(VA);
-  if (Iter == AddrToModuleIndex.end())
-    return false;
-  ModuleIndex = Iter.value();
-  return true;
+  if (Iter.valid() && !IMap::KeyTraits::startLess(VA, Iter.start())) {
+    ModuleIndex = Iter.value();
+    return true;
+  }
+  return false;
 }
 
 bool NativeSession::moduleIndexForSectOffset(uint32_t Sect, uint32_t Offset,
                                              uint16_t &ModuleIndex) const {
-  ModuleIndex = 0;
-  auto Iter = AddrToModuleIndex.find(getVAFromSectOffset(Sect, Offset));
-  if (Iter == AddrToModuleIndex.end())
-    return false;
-  ModuleIndex = Iter.value();
-  return true;
+  return moduleIndexForVA(getVAFromSectOffset(Sect, Offset), ModuleIndex);
 }
 
 void NativeSession::parseSectionContribs() {



More information about the llvm-commits mailing list