[llvm] r203770 - [C++11] DWARF parser: use SmallVector<std::unique_ptr> for parsed units in DWARFContext, and delete custom destructors

Alexey Samsonov samsonov at google.com
Thu Mar 13 01:20:00 PDT 2014


Author: samsonov
Date: Thu Mar 13 03:19:59 2014
New Revision: 203770

URL: http://llvm.org/viewvc/llvm-project?rev=203770&view=rev
Log:
[C++11] DWARF parser: use SmallVector<std::unique_ptr> for parsed units in DWARFContext, and delete custom destructors

Modified:
    llvm/trunk/lib/DebugInfo/DWARFContext.cpp
    llvm/trunk/lib/DebugInfo/DWARFContext.h

Modified: llvm/trunk/lib/DebugInfo/DWARFContext.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARFContext.cpp?rev=203770&r1=203769&r2=203770&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARFContext.cpp (original)
+++ llvm/trunk/lib/DebugInfo/DWARFContext.cpp Thu Mar 13 03:19:59 2014
@@ -8,7 +8,6 @@
 //===----------------------------------------------------------------------===//
 
 #include "DWARFContext.h"
-#include "llvm/ADT/STLExtras.h"
 #include "llvm/ADT/SmallString.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Support/Compression.h"
@@ -23,13 +22,6 @@ using namespace object;
 
 typedef DWARFDebugLine::LineTable DWARFLineTable;
 
-DWARFContext::~DWARFContext() {
-  DeleteContainerPointers(CUs);
-  DeleteContainerPointers(TUs);
-  DeleteContainerPointers(DWOCUs);
-  DeleteContainerPointers(DWOTUs);
-}
-
 static void dumpPubSection(raw_ostream &OS, StringRef Name, StringRef Data,
                            bool LittleEndian, bool GnuStyle) {
   OS << "\n." << Name << " contents:\n";
@@ -125,7 +117,7 @@ void DWARFContext::dump(raw_ostream &OS,
       savedAddressByteSize = CU->getAddressByteSize();
       unsigned stmtOffset =
           CU->getCompileUnitDIE()->getAttributeValueAsSectionOffset(
-              CU, DW_AT_stmt_list, -1U);
+              CU.get(), DW_AT_stmt_list, -1U);
       if (stmtOffset != -1U) {
         DataExtractor lineData(getLineSection().Data, isLittleEndian(),
                                savedAddressByteSize);
@@ -309,7 +301,7 @@ void DWARFContext::parseCompileUnits() {
     if (!CU->extract(DIData, &offset)) {
       break;
     }
-    CUs.push_back(CU.release());
+    CUs.push_back(std::move(CU));
     offset = CUs.back()->getNextUnitOffset();
   }
 }
@@ -328,7 +320,7 @@ void DWARFContext::parseTypeUnits() {
           &I.second.Relocs, isLittleEndian()));
       if (!TU->extract(DIData, &offset))
         break;
-      TUs.push_back(TU.release());
+      TUs.push_back(std::move(TU));
       offset = TUs.back()->getNextUnitOffset();
     }
   }
@@ -349,7 +341,7 @@ void DWARFContext::parseDWOCompileUnits(
     if (!DWOCU->extract(DIData, &offset)) {
       break;
     }
-    DWOCUs.push_back(DWOCU.release());
+    DWOCUs.push_back(std::move(DWOCU));
     offset = DWOCUs.back()->getNextUnitOffset();
   }
 }
@@ -369,7 +361,7 @@ void DWARFContext::parseDWOTypeUnits() {
           isLittleEndian()));
       if (!TU->extract(DIData, &offset))
         break;
-      DWOTUs.push_back(TU.release());
+      DWOTUs.push_back(std::move(TU));
       offset = DWOTUs.back()->getNextUnitOffset();
     }
   }
@@ -377,14 +369,17 @@ void DWARFContext::parseDWOTypeUnits() {
 
 namespace {
   struct OffsetComparator {
-    bool operator()(const DWARFCompileUnit *LHS,
-                    const DWARFCompileUnit *RHS) const {
+
+    bool operator()(const std::unique_ptr<DWARFCompileUnit> &LHS,
+                    const std::unique_ptr<DWARFCompileUnit> &RHS) const {
       return LHS->getOffset() < RHS->getOffset();
     }
-    bool operator()(const DWARFCompileUnit *LHS, uint32_t RHS) const {
+    bool operator()(const std::unique_ptr<DWARFCompileUnit> &LHS,
+                    uint32_t RHS) const {
       return LHS->getOffset() < RHS;
     }
-    bool operator()(uint32_t LHS, const DWARFCompileUnit *RHS) const {
+    bool operator()(uint32_t LHS,
+                    const std::unique_ptr<DWARFCompileUnit> &RHS) const {
       return LHS < RHS->getOffset();
     }
   };
@@ -393,10 +388,10 @@ namespace {
 DWARFCompileUnit *DWARFContext::getCompileUnitForOffset(uint32_t Offset) {
   parseCompileUnits();
 
-  DWARFCompileUnit **CU =
+  std::unique_ptr<DWARFCompileUnit> *CU =
       std::lower_bound(CUs.begin(), CUs.end(), Offset, OffsetComparator());
   if (CU != CUs.end()) {
-    return *CU;
+    return CU->get();
   }
   return 0;
 }
@@ -636,7 +631,7 @@ DWARFContextInMemory::DWARFContextInMemo
       // Make data point to uncompressed section contents and save its contents.
       name = name.substr(1);
       data = UncompressedSection->getBuffer();
-      UncompressedSections.push_back(UncompressedSection.release());
+      UncompressedSections.push_back(std::move(UncompressedSection));
     }
 
     StringRef *Section =
@@ -755,8 +750,4 @@ DWARFContextInMemory::DWARFContextInMemo
   }
 }
 
-DWARFContextInMemory::~DWARFContextInMemory() {
-  DeleteContainerPointers(UncompressedSections);
-}
-
 void DWARFContextInMemory::anchor() { }

Modified: llvm/trunk/lib/DebugInfo/DWARFContext.h
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/DebugInfo/DWARFContext.h?rev=203770&r1=203769&r2=203770&view=diff
==============================================================================
--- llvm/trunk/lib/DebugInfo/DWARFContext.h (original)
+++ llvm/trunk/lib/DebugInfo/DWARFContext.h Thu Mar 13 03:19:59 2014
@@ -28,8 +28,8 @@ namespace llvm {
 /// information parsing. The actual data is supplied through pure virtual
 /// methods that a concrete implementation provides.
 class DWARFContext : public DIContext {
-  typedef SmallVector<DWARFCompileUnit *, 1> CUVector;
-  typedef SmallVector<DWARFTypeUnit *, 1> TUVector;
+  typedef SmallVector<std::unique_ptr<DWARFCompileUnit>, 1> CUVector;
+  typedef SmallVector<std::unique_ptr<DWARFTypeUnit>, 1> TUVector;
 
   CUVector CUs;
   TUVector TUs;
@@ -69,7 +69,6 @@ public:
   };
 
   DWARFContext() : DIContext(CK_DWARF) {}
-  virtual ~DWARFContext();
 
   static bool classof(const DIContext *DICtx) {
     return DICtx->getKind() == CK_DWARF;
@@ -131,13 +130,13 @@ public:
   /// Get the compile unit at the specified index for this compile unit.
   DWARFCompileUnit *getCompileUnitAtIndex(unsigned index) {
     parseCompileUnits();
-    return CUs[index];
+    return CUs[index].get();
   }
 
   /// Get the compile unit at the specified index for the DWO compile units.
   DWARFCompileUnit *getDWOCompileUnitAtIndex(unsigned index) {
     parseDWOCompileUnits();
-    return DWOCUs[index];
+    return DWOCUs[index].get();
   }
 
   /// Get a pointer to the parsed DebugAbbrev object.
@@ -237,11 +236,10 @@ class DWARFContextInMemory : public DWAR
   StringRef RangeDWOSection;
   StringRef AddrSection;
 
-  SmallVector<MemoryBuffer*, 4> UncompressedSections;
+  SmallVector<std::unique_ptr<MemoryBuffer>, 4> UncompressedSections;
 
 public:
   DWARFContextInMemory(object::ObjectFile *);
-  ~DWARFContextInMemory();
   bool isLittleEndian() const override { return IsLittleEndian; }
   uint8_t getAddressSize() const override { return AddressSize; }
   const Section &getInfoSection() override { return InfoSection; }





More information about the llvm-commits mailing list