diff options
author | Ilya Biryukov <ibiryukov@google.com> | 2017-12-21 14:04:39 +0000 |
---|---|---|
committer | Ilya Biryukov <ibiryukov@google.com> | 2017-12-21 14:04:39 +0000 |
commit | d3e23db50edaa6c2cdfb71757428d5e92295148a (patch) | |
tree | e92738ec539e73a11da32279588c61dd89f62807 /lib/Frontend | |
parent | 883f8a25f88623676f665db058361e06099b93dd (diff) |
Added helper to get size of PrecompiledPreamble
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@321266 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Frontend')
-rw-r--r-- | lib/Frontend/PrecompiledPreamble.cpp | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/lib/Frontend/PrecompiledPreamble.cpp b/lib/Frontend/PrecompiledPreamble.cpp index f933ba6cec..7e1323fd83 100644 --- a/lib/Frontend/PrecompiledPreamble.cpp +++ b/lib/Frontend/PrecompiledPreamble.cpp @@ -30,7 +30,7 @@ #include "llvm/Support/Mutex.h" #include "llvm/Support/MutexGuard.h" #include "llvm/Support/Process.h" - +#include <limits> #include <utility> using namespace clang; @@ -381,6 +381,27 @@ PreambleBounds PrecompiledPreamble::getBounds() const { return PreambleBounds(PreambleBytes.size(), PreambleEndsAtStartOfLine); } +std::size_t PrecompiledPreamble::getSize() const { + switch (Storage.getKind()) { + case PCHStorage::Kind::Empty: + assert(false && "Calling getSize() on invalid PrecompiledPreamble. " + "Was it std::moved?"); + return 0; + case PCHStorage::Kind::InMemory: + return Storage.asMemory().Data.size(); + case PCHStorage::Kind::TempFile: { + uint64_t Result; + if (llvm::sys::fs::file_size(Storage.asFile().getFilePath(), Result)) + return 0; + + assert(Result <= std::numeric_limits<std::size_t>::max() && + "file size did not fit into size_t"); + return Result; + } + } + llvm_unreachable("Unhandled storage kind"); +} + bool PrecompiledPreamble::CanReuse(const CompilerInvocation &Invocation, const llvm::MemoryBuffer *MainFileBuffer, PreambleBounds Bounds, @@ -506,8 +527,8 @@ PrecompiledPreamble::TempPCHFile::createInSystemTempDir(const Twine &Prefix, StringRef Suffix) { llvm::SmallString<64> File; // Using a version of createTemporaryFile with a file descriptor guarantees - // that we would never get a race condition in a multi-threaded setting (i.e., - // multiple threads getting the same temporary path). + // that we would never get a race condition in a multi-threaded setting + // (i.e., multiple threads getting the same temporary path). int FD; auto EC = llvm::sys::fs::createTemporaryFile(Prefix, Suffix, FD, File); if (EC) |