[llvm] [CodeGen][DebugValues] Fix unhandled error condition in VarLoc (PR #122019)

Abhay Kanhere via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 7 15:48:40 PST 2025


https://github.com/AbhayKanhere created https://github.com/llvm/llvm-project/pull/122019

  When assert() are disabled, this function can return corrupt data.

>From c377dddc43b18ff42bd79f5712524b89cffe548a Mon Sep 17 00:00:00 2001
From: Abhay Kanhere <abhay at kanhere.net>
Date: Tue, 7 Jan 2025 14:19:35 -0800
Subject: [PATCH] [CodeGen][DebugValues] Fix unhandled error condition in
 VarLoc   When assert() are disabled, this function can return corrupt data.

---
 llvm/lib/CodeGen/LiveDebugValues/VarLocBasedImpl.cpp | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/llvm/lib/CodeGen/LiveDebugValues/VarLocBasedImpl.cpp b/llvm/lib/CodeGen/LiveDebugValues/VarLocBasedImpl.cpp
index a5e6bebcd29c7f..cf8072e07dfe9a 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);
 
@@ -1284,9 +1277,10 @@ void VarLocBasedLDV::printVarLocInMBB(const MachineFunction &MF,
                                        raw_ostream &Out) const {
   Out << '\n' << msg << '\n';
   for (const MachineBasicBlock &BB : MF) {
-    if (!V.count(&BB))
+    auto It = V.find(&BB);
+    if (It == V.end())
       continue;
-    const VarLocSet &L = getVarLocsInMBB(&BB, V);
+    const VarLocSet &L = *It->second;
     if (L.empty())
       continue;
     SmallVector<VarLoc, 32> VarLocs;



More information about the llvm-commits mailing list