]> granicus.if.org Git - llvm/commitdiff
[DWARF] Fix DWARFVerifier::DieRangeInfo::intersects
authorFangrui Song <maskray@google.com>
Mon, 15 Apr 2019 08:30:10 +0000 (08:30 +0000)
committerFangrui Song <maskray@google.com>
Mon, 15 Apr 2019 08:30:10 +0000 (08:30 +0000)
It was incorrect if RHS had more than 1 ranges and one of the ranges interacted with *this

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@358376 91177308-0d34-0410-b5e6-96231b3b80d8

lib/DebugInfo/DWARF/DWARFVerifier.cpp
unittests/DebugInfo/DWARF/DWARFDebugInfoTest.cpp

index 6f68553bb7b6429cf7123aec4ce98c68985ddc7b..43e83c83fd9016699c4ac600f71f79dbc482a7e5 100644 (file)
@@ -85,23 +85,16 @@ bool DWARFVerifier::DieRangeInfo::contains(const DieRangeInfo &RHS) const {
 }
 
 bool DWARFVerifier::DieRangeInfo::intersects(const DieRangeInfo &RHS) const {
-  if (Ranges.empty() || RHS.Ranges.empty())
-    return false;
-
-  auto End = Ranges.end();
-  auto Iter = findRange(RHS.Ranges.front());
-  for (const auto &R : RHS.Ranges) {
-    if (Iter == End)
-      return false;
-    if (R.HighPC <= Iter->LowPC)
-      continue;
-    while (Iter != End) {
-      if (Iter->intersects(R))
-        return true;
-      ++Iter;
-    }
+  auto I1 = Ranges.begin(), E1 = Ranges.end();
+  auto I2 = RHS.Ranges.begin(), E2 = RHS.Ranges.end();
+  while (I1 != E1 && I2 != E2) {
+    if (I1->intersects(*I2))
+      return true;
+    if (I1->LowPC < I2->LowPC)
+      ++I1;
+    else
+      ++I2;
   }
-
   return false;
 }
 
index bd5197671056861cdf7851d044e0e0f4da3575e2..d3643ca4bb7d722caf91275a43b587a1f98faf60 100644 (file)
@@ -3188,6 +3188,9 @@ TEST(DWARFDebugInfo, TestDWARFDieRangeInfoIntersects) {
   AssertRangesIntersect(Ranges, {{0x3f, 0x40}});
   // Test range that starts at end of second range
   AssertRangesDontIntersect(Ranges, {{0x40, 0x41}});
+
+  AssertRangesDontIntersect(Ranges, {{0x20, 0x21}, {0x2f, 0x30}});
+  AssertRangesIntersect(Ranges, {{0x20, 0x21}, {0x2f, 0x31}});
 }
 
 } // end anonymous namespace