Stop the iterator in ValueLiveAt from potentially running off the end of the interval.
authorLang Hames <lhames@gmail.com>
Fri, 30 Oct 2009 18:12:09 +0000 (18:12 +0000)
committerLang Hames <lhames@gmail.com>
Fri, 30 Oct 2009 18:12:09 +0000 (18:12 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@85599 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/SimpleRegisterCoalescing.cpp
lib/CodeGen/SimpleRegisterCoalescing.h

index 430df54081e0c888f9adf74ce09c5e9c23f2c166..2aa63075024289216f6dafdfa94e2fee85cd02b2 100644 (file)
@@ -1866,8 +1866,10 @@ bool SimpleRegisterCoalescing::RangeIsDefinedByCopyFromReg(LiveInterval &li,
 /// iterator, or any subsequent range with the same value number,
 /// is live at the given point.
 bool SimpleRegisterCoalescing::ValueLiveAt(LiveInterval::iterator LRItr,
+                                           LiveInterval::iterator LREnd,
                                            LiveIndex defPoint) const {
-  for (const VNInfo *valno = LRItr->valno; LRItr->valno == valno; ++LRItr) {
+  for (const VNInfo *valno = LRItr->valno;
+       (LRItr != LREnd) && (LRItr->valno == valno); ++LRItr) {
     if (LRItr->contains(defPoint))
       return true;
   }
@@ -1922,7 +1924,7 @@ bool SimpleRegisterCoalescing::SimpleJoin(LiveInterval &LHS, LiveInterval &RHS){
         if (!RangeIsDefinedByCopyFromReg(LHS, LHSIt, RHS.reg))
           return false;    // Nope, bail out.
 
-        if (ValueLiveAt(LHSIt, RHSIt->valno->def))
+        if (ValueLiveAt(LHSIt, LHS.end(), RHSIt->valno->def))
           // Here is an interesting situation:
           // BB1:
           //   vr1025 = copy vr1024
@@ -1960,7 +1962,7 @@ bool SimpleRegisterCoalescing::SimpleJoin(LiveInterval &LHS, LiveInterval &RHS){
           // Otherwise, if this is a copy from the RHS, mark it as being merged
           // in.
           if (RangeIsDefinedByCopyFromReg(LHS, LHSIt, RHS.reg)) {
-            if (ValueLiveAt(LHSIt, RHSIt->valno->def))
+            if (ValueLiveAt(LHSIt, LHS.end(), RHSIt->valno->def))
               // Here is an interesting situation:
               // BB1:
               //   vr1025 = copy vr1024
index a381ae78afe0c7c61ea6a2df32e36528a00aa25d..7f282a43dd71e0dd593f29c1cb304fde79178b7b 100644 (file)
@@ -204,7 +204,8 @@ namespace llvm {
     /// ValueLiveAt - Return true if the LiveRange pointed to by the given
     /// iterator, or any subsequent range with the same value number,
     /// is live at the given point.
-    bool ValueLiveAt(LiveInterval::iterator LRItr, LiveIndex defPoint) const;
+    bool ValueLiveAt(LiveInterval::iterator LRItr, LiveInterval::iterator LREnd, 
+                     LiveIndex defPoint) const;                                  
 
     /// RangeIsDefinedByCopyFromReg - Return true if the specified live range of
     /// the specified live interval is defined by a copy from the specified