[PATCH] D150577: [CodeGen] Fix for MachineBasicBlock::rfindDebugLoc(instr_rend())

Bjorn Pettersson via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 25 05:50:57 PDT 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rG63c9fe2db5cb: [CodeGen] Fix for MachineBasicBlock::rfindDebugLoc(instr_rend()) (authored by bjope).

Changed prior to commit:
  https://reviews.llvm.org/D150577?vs=523040&id=525564#toc

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D150577/new/

https://reviews.llvm.org/D150577

Files:
  llvm/lib/CodeGen/MachineBasicBlock.cpp
  llvm/unittests/CodeGen/MachineBasicBlockTest.cpp


Index: llvm/unittests/CodeGen/MachineBasicBlockTest.cpp
===================================================================
--- llvm/unittests/CodeGen/MachineBasicBlockTest.cpp
+++ llvm/unittests/CodeGen/MachineBasicBlockTest.cpp
@@ -56,9 +56,8 @@
   EXPECT_EQ(DL0, MBB.findDebugLoc(MBB.instr_begin()));
   EXPECT_EQ(DL0, MBB.findDebugLoc(MBB.instr_end()));
 
-  // FIXME: This would crash (see https://reviews.llvm.org/D150577).
-  //EXPECT_EQ(DL0, MBB.rfindDebugLoc(MBB.instr_rbegin()));
-  //EXPECT_EQ(DL0, MBB.rfindDebugLoc(MBB.instr_rend()));
+  EXPECT_EQ(DL0, MBB.rfindDebugLoc(MBB.instr_rbegin()));
+  EXPECT_EQ(DL0, MBB.rfindDebugLoc(MBB.instr_rend()));
 
   EXPECT_EQ(DL0, MBB.findPrevDebugLoc(MBB.instr_begin()));
   EXPECT_EQ(DL0, MBB.findPrevDebugLoc(MBB.instr_end()));
@@ -84,8 +83,7 @@
   EXPECT_EQ(DL3, MBB.findDebugLoc(MI3));
   EXPECT_EQ(DL0, MBB.findDebugLoc(MBB.instr_end()));
 
-  // FIXME: This would crash (see https://reviews.llvm.org/D150577).
-  //EXPECT_EQ(DL1, MBB.rfindDebugLoc(MBB.instr_rend()));
+  EXPECT_EQ(DL1, MBB.rfindDebugLoc(MBB.instr_rend()));
   EXPECT_EQ(DL1, MBB.rfindDebugLoc(MI1));
   EXPECT_EQ(DL3, MBB.rfindDebugLoc(MI2));
   EXPECT_EQ(DL3, MBB.rfindDebugLoc(MI3));
Index: llvm/lib/CodeGen/MachineBasicBlock.cpp
===================================================================
--- llvm/lib/CodeGen/MachineBasicBlock.cpp
+++ llvm/lib/CodeGen/MachineBasicBlock.cpp
@@ -1474,6 +1474,8 @@
 }
 
 DebugLoc MachineBasicBlock::rfindDebugLoc(reverse_instr_iterator MBBI) {
+  if (MBBI == instr_rend())
+    return findDebugLoc(instr_begin());
   // Skip debug declarations, we don't want a DebugLoc from them.
   MBBI = skipDebugInstructionsBackward(MBBI, instr_rbegin());
   if (!MBBI->isDebugInstr())


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150577.525564.patch
Type: text/x-patch
Size: 1742 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230525/982e43d0/attachment.bin>


More information about the llvm-commits mailing list