[PATCH] D23407: CodeGen: Avoid dereferencing end() in MachineScheduler

Duncan P. N. Exon Smith via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 11 09:08:00 PDT 2016


dexonsmith created this revision.
dexonsmith added a reviewer: MatzeB.
dexonsmith added a subscriber: llvm-commits.
Herald added a subscriber: MatzeB.

Check MachineInstr::isDebugValue for the same instruction as we're
calling isSchedBoundary, avoiding the possibility of dereferencing
end().

It's possible that instead the loop here should check for I==RegionEnd
and continue to use I->isDebugValue() (instead of std::prev(I)), but I
doubt it.

This is trigged by a huge number of tests, but they happen to magically
pass right now.  I found this because WIP patches for PR26753 convert
them into crashes.

https://reviews.llvm.org/D23407

Files:
  lib/CodeGen/MachineScheduler.cpp

Index: lib/CodeGen/MachineScheduler.cpp
===================================================================
--- lib/CodeGen/MachineScheduler.cpp
+++ lib/CodeGen/MachineScheduler.cpp
@@ -458,9 +458,10 @@
       unsigned NumRegionInstrs = 0;
       MachineBasicBlock::iterator I = RegionEnd;
       for (;I != MBB->begin(); --I) {
-        if (isSchedBoundary(&*std::prev(I), &*MBB, MF, TII))
+        MachineInstr &MI = *std::prev(I);
+        if (isSchedBoundary(&MI, &*MBB, MF, TII))
           break;
-        if (!I->isDebugValue())
+        if (!MI.isDebugValue())
           ++NumRegionInstrs;
       }
       // Notify the scheduler of the region, even if we may skip scheduling


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D23407.67693.patch
Type: text/x-patch
Size: 685 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160811/69671f9d/attachment.bin>


More information about the llvm-commits mailing list