diff options
author | Ivan Donchevskii <ivan.donchevskii@qt.io> | 2018-05-30 14:00:57 +0200 |
---|---|---|
committer | Ivan Donchevskii <ivan.donchevskii@qt.io> | 2018-06-08 06:02:55 +0000 |
commit | 74dff2b4165421e67427db09f02d6a52ae1fa96d (patch) | |
tree | 2e8fd73c7b94e1859da9f8abb4c72273113bed2c /lib | |
parent | 12ff64e073489179762152cef695b795eb2fcb16 (diff) |
[backported/clang-7][Frontend] Honor UserFilesAreVolatile flag getting file buffer in ASTUnit
--------------------------------------------------------------------------
* https://reviews.llvm.org/D47460
--------------------------------------------------------------------------
Do not memory map the main file if the flag UserFilesAreVolatile
is set to true in ASTUnit when calling FileSystem::getBufferForFile.
Task-number: QTCREATORBUG-15449
Change-Id: I283d684f4c1ca38a4689ce09bd594700678679c1
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Basic/FileManager.cpp | 6 | ||||
-rw-r--r-- | lib/Frontend/ASTUnit.cpp | 13 |
2 files changed, 11 insertions, 8 deletions
diff --git a/lib/Basic/FileManager.cpp b/lib/Basic/FileManager.cpp index a3e226d6cc..c1b9693ee8 100644 --- a/lib/Basic/FileManager.cpp +++ b/lib/Basic/FileManager.cpp @@ -450,13 +450,13 @@ FileManager::getBufferForFile(const FileEntry *Entry, bool isVolatile, } llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> -FileManager::getBufferForFile(StringRef Filename) { +FileManager::getBufferForFile(StringRef Filename, bool isVolatile) { if (FileSystemOpts.WorkingDir.empty()) - return FS->getBufferForFile(Filename); + return FS->getBufferForFile(Filename, -1, true, isVolatile); SmallString<128> FilePath(Filename); FixupRelativePath(FilePath); - return FS->getBufferForFile(FilePath.c_str()); + return FS->getBufferForFile(FilePath.c_str(), -1, true, isVolatile); } /// getStatValue - Get the 'stat' information for the specified path, diff --git a/lib/Frontend/ASTUnit.cpp b/lib/Frontend/ASTUnit.cpp index c334e3e6db..1ec4502ba5 100644 --- a/lib/Frontend/ASTUnit.cpp +++ b/lib/Frontend/ASTUnit.cpp @@ -100,7 +100,8 @@ namespace { static std::unique_ptr<llvm::MemoryBuffer> getBufferForFileHandlingRemapping(const CompilerInvocation &Invocation, vfs::FileSystem *VFS, - StringRef FilePath) { + StringRef FilePath, + bool isVolatile) { const auto &PreprocessorOpts = Invocation.getPreprocessorOpts(); // Try to determine if the main file has been remapped, either from the @@ -120,7 +121,8 @@ getBufferForFileHandlingRemapping(const CompilerInvocation &Invocation, llvm::sys::fs::UniqueID MID = MPathStatus->getUniqueID(); if (MainFileID == MID) { // We found a remapping. Try to load the resulting, remapped source. - BufferOwner = valueOrNull(VFS->getBufferForFile(RF.second)); + BufferOwner = valueOrNull( + VFS->getBufferForFile(RF.second, -1, true, isVolatile)); if (!BufferOwner) return nullptr; } @@ -145,7 +147,8 @@ getBufferForFileHandlingRemapping(const CompilerInvocation &Invocation, // If the main source file was not remapped, load it now. if (!Buffer && !BufferOwner) { - BufferOwner = valueOrNull(VFS->getBufferForFile(FilePath)); + BufferOwner = + valueOrNull(VFS->getBufferForFile(FilePath, -1, true, isVolatile)); if (!BufferOwner) return nullptr; } @@ -664,7 +667,7 @@ ASTDeserializationListener *ASTUnit::getDeserializationListener() { std::unique_ptr<llvm::MemoryBuffer> ASTUnit::getBufferForFile(StringRef Filename, std::string *ErrorStr) { assert(FileMgr); - auto Buffer = FileMgr->getBufferForFile(Filename); + auto Buffer = FileMgr->getBufferForFile(Filename, UserFilesAreVolatile); if (Buffer) return std::move(*Buffer); if (ErrorStr) @@ -1231,7 +1234,7 @@ ASTUnit::getMainBufferWithPrecompiledPreamble( PreambleInvocationIn.getFrontendOpts().Inputs[0].getFile(); std::unique_ptr<llvm::MemoryBuffer> MainFileBuffer = getBufferForFileHandlingRemapping(PreambleInvocationIn, VFS.get(), - MainFilePath); + MainFilePath, UserFilesAreVolatile); if (!MainFileBuffer) return nullptr; |