Hexagon: Avoid dereferencing end() in HexagonCopyToCombine::findPairable
authorDuncan P. N. Exon Smith <dexonsmith@apple.com>
Thu, 11 Aug 2016 16:40:03 +0000 (16:40 +0000)
committerDuncan P. N. Exon Smith <dexonsmith@apple.com>
Thu, 11 Aug 2016 16:40:03 +0000 (16:40 +0000)
Check for end() before skipping through debug values.  This avoids
dereferencing end() when the instruction is the final one in the basic
block.  (It still assumes that a debug value will not be the final
instruction in the basic block.  No tests seemed to violate that.)

Many Hexagon tests trigger this, but they happen to magically pass right
now.  I found this because WIP patches for PR26753 convert them into
crashes.

llvm-svn: 278355

llvm/lib/Target/Hexagon/HexagonCopyToCombine.cpp

index a472443..bcebf5d 100644 (file)
@@ -505,8 +505,9 @@ MachineInstr *HexagonCopyToCombine::findPairable(MachineInstr &I1,
                                                  bool AllowC64) {
   MachineBasicBlock::iterator I2 = std::next(MachineBasicBlock::iterator(I1));
 
-  while (I2->isDebugValue())
-    ++I2;
+  if (I2 != I1.getParent()->end())
+    while (I2->isDebugValue())
+      ++I2;
 
   unsigned I1DestReg = I1.getOperand(0).getReg();