[PATCH] This phabricator revision is the merge of 4 patches that aim to provide resolving of AT_abstract_origin and AT_specification attributes.

Frederic Riss friss at apple.com
Fri Sep 5 04:10:06 PDT 2014


================
Comment at: lib/DebugInfo/DWARFContext.cpp:392-411
@@ -391,18 +391,22 @@
 
 namespace {
-  struct OffsetComparator {
-
-    bool operator()(const std::unique_ptr<DWARFCompileUnit> &LHS,
-                    const std::unique_ptr<DWARFCompileUnit> &RHS) const {
-      return LHS->getOffset() < RHS->getOffset();
-    }
-    bool operator()(const std::unique_ptr<DWARFCompileUnit> &LHS,
-                    uint32_t RHS) const {
-      return LHS->getOffset() < RHS;
-    }
-    bool operator()(uint32_t LHS,
-                    const std::unique_ptr<DWARFCompileUnit> &RHS) const {
-      return LHS < RHS->getOffset();
-    }
-  };
+template<typename UnitType>
+struct OffsetComparator {
+  // The beginning offset of a CU is the NextUnitOffset of the
+  // preceding one. When searching for this particular offset, the
+  // comparator has to return true so that lower_bound skips the
+  // CU. Thus the <= comparison.
+  bool operator()(const std::unique_ptr<UnitType> &LHS,
+                  const std::unique_ptr<UnitType> &RHS) const {
+    return LHS->getNextUnitOffset() <= RHS->getNextUnitOffset();
+  }
+  bool operator()(const std::unique_ptr<UnitType> &LHS,
+                  uint32_t RHS) const {
+    return LHS->getNextUnitOffset() <= RHS;
+  }
+  bool operator()(uint32_t LHS,
+                  const std::unique_ptr<UnitType> &RHS) const {
+    return LHS <= RHS->getNextUnitOffset();
+  }
+};
 }
----------------
This patch was meant to only fix the logic of the comparator, but by rebasing/reworking my patch queue, it got templatized along the way. It's not apparent in this patch series, but I have followups that introduce a similar lookup function for TypeUnits which will need the template form.

http://reviews.llvm.org/D5208






More information about the llvm-commits mailing list