[llvm] Boundary condition check hidden under assert (PR #122005)

via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 7 14:33:28 PST 2025


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-debuginfo

Author: Abhay Kanhere (AbhayKanhere)

<details>
<summary>Changes</summary>

if asserts are disabled this code can return corrupted memory

---
Full diff: https://github.com/llvm/llvm-project/pull/122005.diff


1 Files Affected:

- (modified) llvm/lib/CodeGen/LiveDebugValues/VarLocBasedImpl.cpp (+4-8) 


``````````diff
diff --git a/llvm/lib/CodeGen/LiveDebugValues/VarLocBasedImpl.cpp b/llvm/lib/CodeGen/LiveDebugValues/VarLocBasedImpl.cpp
index a5e6bebcd29c7f..6306476fac657f 100644
--- a/llvm/lib/CodeGen/LiveDebugValues/VarLocBasedImpl.cpp
+++ b/llvm/lib/CodeGen/LiveDebugValues/VarLocBasedImpl.cpp
@@ -997,13 +997,6 @@ class VarLocBasedLDV : public LDVImpl {
     return *VLS;
   }
 
-  const VarLocSet &getVarLocsInMBB(const MachineBasicBlock *MBB,
-                                   const VarLocInMBB &Locs) const {
-    auto It = Locs.find(MBB);
-    assert(It != Locs.end() && "MBB not in map");
-    return *It->second;
-  }
-
   /// Tests whether this instruction is a spill to a stack location.
   bool isSpillInstruction(const MachineInstr &MI, MachineFunction *MF);
 
@@ -1286,7 +1279,10 @@ void VarLocBasedLDV::printVarLocInMBB(const MachineFunction &MF,
   for (const MachineBasicBlock &BB : MF) {
     if (!V.count(&BB))
       continue;
-    const VarLocSet &L = getVarLocsInMBB(&BB, V);
+    auto It = V.find(&BB);
+    if (It == V.end())
+      continue;
+    const VarLocSet &L = *It->second;
     if (L.empty())
       continue;
     SmallVector<VarLoc, 32> VarLocs;

``````````

</details>


https://github.com/llvm/llvm-project/pull/122005


More information about the llvm-commits mailing list