From: Nico Weber Date: Mon, 15 Jul 2019 17:27:46 +0000 (+0000) Subject: Use a unique_ptr instead of manual memory management for LineTable X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=18638574119e6afbc124ebb439564db903ff4086;p=clang Use a unique_ptr instead of manual memory management for LineTable git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@366088 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h index 388fc1c1f8..e32f749ae6 100644 --- a/include/clang/Basic/SourceManager.h +++ b/include/clang/Basic/SourceManager.h @@ -679,7 +679,7 @@ class SourceManager : public RefCountedBase { /// Holds information for \#line directives. /// /// This is referenced by indices from SLocEntryTable. - LineTableInfo *LineTable = nullptr; + std::unique_ptr LineTable; /// These ivars serve as a cache used in the getLineNumber /// method which is used to speedup getLineNumber calls to nearby locations. diff --git a/lib/Basic/SourceManager.cpp b/lib/Basic/SourceManager.cpp index c7588aa796..12b0305e70 100644 --- a/lib/Basic/SourceManager.cpp +++ b/lib/Basic/SourceManager.cpp @@ -329,7 +329,7 @@ void SourceManager::AddLineNote(SourceLocation Loc, unsigned LineNo, LineTableInfo &SourceManager::getLineTable() { if (!LineTable) - LineTable = new LineTableInfo(); + LineTable.reset(new LineTableInfo()); return *LineTable; } @@ -345,8 +345,6 @@ SourceManager::SourceManager(DiagnosticsEngine &Diag, FileManager &FileMgr, } 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.