diff options
author | David Blaikie <dblaikie@gmail.com> | 2014-08-11 21:29:24 +0000 |
---|---|---|
committer | David Blaikie <dblaikie@gmail.com> | 2014-08-11 21:29:24 +0000 |
commit | 23430ccb042f11eda205c390d4c2a0d07d08b2e6 (patch) | |
tree | 8753c0e6cd148fe8b0bd60064a55ff3d6da6893f /clang/lib | |
parent | be4b5171d3663eaee01823c33148de081ffe9e80 (diff) | |
download | bcm5719-llvm-23430ccb042f11eda205c390d4c2a0d07d08b2e6.tar.gz bcm5719-llvm-23430ccb042f11eda205c390d4c2a0d07d08b2e6.zip |
unique_ptr-ify FileSystemStatCache::setNextStatCache
And in the process, discover that FileManager::removeStatCache had a
double-delete when removing an element from the middle of the list (at
the beginning or the end of the list, there was no problem) and add a
unit test to exercise the code path (which successfully crashed when run
(with modifications to match the old API) without this patch applied)
llvm-svn: 215388
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Basic/FileManager.cpp | 12 | ||||
-rw-r--r-- | clang/lib/Frontend/CacheTokens.cpp | 6 | ||||
-rw-r--r-- | clang/lib/Lex/PTHLexer.cpp | 4 | ||||
-rw-r--r-- | clang/lib/Lex/Preprocessor.cpp | 1 |
4 files changed, 13 insertions, 10 deletions
diff --git a/clang/lib/Basic/FileManager.cpp b/clang/lib/Basic/FileManager.cpp index 94bd3f8ccfd..e4a7f1e2575 100644 --- a/clang/lib/Basic/FileManager.cpp +++ b/clang/lib/Basic/FileManager.cpp @@ -64,20 +64,20 @@ FileManager::~FileManager() { delete VirtualDirectoryEntries[i]; } -void FileManager::addStatCache(FileSystemStatCache *statCache, +void FileManager::addStatCache(std::unique_ptr<FileSystemStatCache> statCache, bool AtBeginning) { assert(statCache && "No stat cache provided?"); if (AtBeginning || !StatCache.get()) { - statCache->setNextStatCache(StatCache.release()); - StatCache.reset(statCache); + statCache->setNextStatCache(std::move(StatCache)); + StatCache = std::move(statCache); return; } FileSystemStatCache *LastCache = StatCache.get(); while (LastCache->getNextStatCache()) LastCache = LastCache->getNextStatCache(); - - LastCache->setNextStatCache(statCache); + + LastCache->setNextStatCache(std::move(statCache)); } void FileManager::removeStatCache(FileSystemStatCache *statCache) { @@ -96,7 +96,7 @@ void FileManager::removeStatCache(FileSystemStatCache *statCache) { PrevCache = PrevCache->getNextStatCache(); assert(PrevCache && "Stat cache not found for removal"); - PrevCache->setNextStatCache(statCache->getNextStatCache()); + PrevCache->setNextStatCache(statCache->takeNextStatCache()); } void FileManager::clearStatCaches() { diff --git a/clang/lib/Frontend/CacheTokens.cpp b/clang/lib/Frontend/CacheTokens.cpp index 14f7027e468..23f22ada7fc 100644 --- a/clang/lib/Frontend/CacheTokens.cpp +++ b/clang/lib/Frontend/CacheTokens.cpp @@ -572,8 +572,10 @@ void clang::CacheTokens(Preprocessor &PP, llvm::raw_fd_ostream* OS) { PTHWriter PW(*OS, PP); // Install the 'stat' system call listener in the FileManager. - StatListener *StatCache = new StatListener(PW.getPM()); - PP.getFileManager().addStatCache(StatCache, /*AtBeginning=*/true); + auto StatCacheOwner = llvm::make_unique<StatListener>(PW.getPM()); + StatListener *StatCache = StatCacheOwner.get(); + PP.getFileManager().addStatCache(std::move(StatCacheOwner), + /*AtBeginning=*/true); // Lex through the entire file. This will populate SourceManager with // all of the header information. diff --git a/clang/lib/Lex/PTHLexer.cpp b/clang/lib/Lex/PTHLexer.cpp index fce31c4be29..4e2a755f8c6 100644 --- a/clang/lib/Lex/PTHLexer.cpp +++ b/clang/lib/Lex/PTHLexer.cpp @@ -732,6 +732,6 @@ public: }; } // end anonymous namespace -FileSystemStatCache *PTHManager::createStatCache() { - return new PTHStatCache(*((PTHFileLookup*) FileLookup)); +std::unique_ptr<FileSystemStatCache> PTHManager::createStatCache() { + return llvm::make_unique<PTHStatCache>(*((PTHFileLookup *)FileLookup)); } diff --git a/clang/lib/Lex/Preprocessor.cpp b/clang/lib/Lex/Preprocessor.cpp index ab11fabbbce..fd0e48c66c8 100644 --- a/clang/lib/Lex/Preprocessor.cpp +++ b/clang/lib/Lex/Preprocessor.cpp @@ -27,6 +27,7 @@ #include "clang/Lex/Preprocessor.h" #include "clang/Basic/FileManager.h" +#include "clang/Basic/FileSystemStatCache.h" #include "clang/Basic/SourceManager.h" #include "clang/Basic/TargetInfo.h" #include "clang/Lex/CodeCompletionHandler.h" |