r366088 - Use a unique_ptr instead of manual memory management for LineTable

Nico Weber via cfe-commits cfe-commits at lists.llvm.org
Mon Jul 15 10:27:46 PDT 2019


Author: nico
Date: Mon Jul 15 10:27:46 2019
New Revision: 366088

URL: http://llvm.org/viewvc/llvm-project?rev=366088&view=rev
Log:
Use a unique_ptr instead of manual memory management for LineTable

Modified:
    cfe/trunk/include/clang/Basic/SourceManager.h
    cfe/trunk/lib/Basic/SourceManager.cpp

Modified: cfe/trunk/include/clang/Basic/SourceManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SourceManager.h?rev=366088&r1=366087&r2=366088&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/SourceManager.h (original)
+++ cfe/trunk/include/clang/Basic/SourceManager.h Mon Jul 15 10:27:46 2019
@@ -679,7 +679,7 @@ class SourceManager : public RefCountedB
   /// Holds information for \#line directives.
   ///
   /// This is referenced by indices from SLocEntryTable.
-  LineTableInfo *LineTable = nullptr;
+  std::unique_ptr<LineTableInfo> LineTable;
 
   /// These ivars serve as a cache used in the getLineNumber
   /// method which is used to speedup getLineNumber calls to nearby locations.

Modified: cfe/trunk/lib/Basic/SourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/SourceManager.cpp?rev=366088&r1=366087&r2=366088&view=diff
==============================================================================
--- cfe/trunk/lib/Basic/SourceManager.cpp (original)
+++ cfe/trunk/lib/Basic/SourceManager.cpp Mon Jul 15 10:27:46 2019
@@ -329,7 +329,7 @@ void SourceManager::AddLineNote(SourceLo
 
 LineTableInfo &SourceManager::getLineTable() {
   if (!LineTable)
-    LineTable = new LineTableInfo();
+    LineTable.reset(new LineTableInfo());
   return *LineTable;
 }
 
@@ -345,8 +345,6 @@ SourceManager::SourceManager(Diagnostics
 }
 
 SourceManager::~SourceManager() {
-  delete LineTable;
-
   // Delete FileEntry objects corresponding to content caches.  Since the actual
   // content cache objects are bump pointer allocated, we just have to run the
   // dtors, but we call the deallocate method for completeness.




More information about the cfe-commits mailing list