diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2012-07-11 20:59:04 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2012-07-11 20:59:04 +0000 |
commit | ff398965a5abfaf5bc47bc022876f56a28e5b9a7 (patch) | |
tree | ae3e8d01cc8359f810150ccf2ad37075a40165c8 /include/clang/Basic/SourceManager.h | |
parent | 4b49756fdc066688e30f6ca69feffd5f7686cb1b (diff) |
Introduce a flag in SourceManager to treat non-system source files
as "volatile", meaning there's a high enough chance that they may
change while we are trying to use them.
This flag is only enabled by libclang.
Currently "volatile" source files will be stat'ed immediately
before opening them, because the file size stat info
may not be accurate since when we got it (e.g. from the PCH).
This avoids crashes when trying to reference mmap'ed memory
from a file whose size is not what we expect.
Note that there's still a window for a racing issue to occur
but the window for it should be way smaller than before.
We can consider later on to avoid mmap completely on such files.
rdar://11612916
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@160074 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Basic/SourceManager.h')
-rw-r--r-- | include/clang/Basic/SourceManager.h | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h index 415b017b73..082cbb1fb1 100644 --- a/include/clang/Basic/SourceManager.h +++ b/include/clang/Basic/SourceManager.h @@ -128,14 +128,20 @@ namespace SrcMgr { /// When true, the original entry may be a virtual file that does not /// exist. unsigned BufferOverridden : 1; + + /// \brief True if this content cache was initially created for a source + /// file considered as a system one. + unsigned IsSystemFile : 1; ContentCache(const FileEntry *Ent = 0) : Buffer(0, false), OrigEntry(Ent), ContentsEntry(Ent), - SourceLineCache(0), NumLines(0), BufferOverridden(false) {} + SourceLineCache(0), NumLines(0), BufferOverridden(false), + IsSystemFile(false) {} ContentCache(const FileEntry *Ent, const FileEntry *contentEnt) : Buffer(0, false), OrigEntry(Ent), ContentsEntry(contentEnt), - SourceLineCache(0), NumLines(0), BufferOverridden(false) {} + SourceLineCache(0), NumLines(0), BufferOverridden(false), + IsSystemFile(false) {} ~ContentCache(); @@ -143,7 +149,8 @@ namespace SrcMgr { /// a non-NULL Buffer or SourceLineCache. Ownership of allocated memory /// is not transferred, so this is a logical error. ContentCache(const ContentCache &RHS) - : Buffer(0, false), SourceLineCache(0), BufferOverridden(false) + : Buffer(0, false), SourceLineCache(0), BufferOverridden(false), + IsSystemFile(false) { OrigEntry = RHS.OrigEntry; ContentsEntry = RHS.ContentsEntry; @@ -534,6 +541,10 @@ class SourceManager : public RefCountedBase<SourceManager> { /// files, should report the original file name. Defaults to true. bool OverridenFilesKeepOriginalName; + /// \brief True if non-system source files should be treated as volatile + /// (likely to change while trying to use them). Defaults to false. + bool UserFilesAreVolatile; + struct OverriddenFilesInfoTy { /// \brief Files that have been overriden with the contents from another /// file. @@ -639,7 +650,8 @@ class SourceManager : public RefCountedBase<SourceManager> { explicit SourceManager(const SourceManager&); void operator=(const SourceManager&); public: - SourceManager(DiagnosticsEngine &Diag, FileManager &FileMgr); + SourceManager(DiagnosticsEngine &Diag, FileManager &FileMgr, + bool UserFilesAreVolatile = false); ~SourceManager(); void clearIDTables(); @@ -654,6 +666,10 @@ public: OverridenFilesKeepOriginalName = value; } + /// \brief True if non-system source files should be treated as volatile + /// (likely to change while trying to use them). + bool userFilesAreVolatile() const { return UserFilesAreVolatile; } + /// \brief Create the FileID for a memory buffer that will represent the /// FileID for the main source. /// @@ -706,7 +722,9 @@ public: FileID createFileID(const FileEntry *SourceFile, SourceLocation IncludePos, SrcMgr::CharacteristicKind FileCharacter, int LoadedID = 0, unsigned LoadedOffset = 0) { - const SrcMgr::ContentCache *IR = getOrCreateContentCache(SourceFile); + const SrcMgr::ContentCache * + IR = getOrCreateContentCache(SourceFile, + /*isSystemFile=*/FileCharacter != SrcMgr::C_User); assert(IR && "getOrCreateContentCache() cannot return NULL"); return createFileID(IR, IncludePos, FileCharacter, LoadedID, LoadedOffset); } @@ -1519,7 +1537,8 @@ private: int LoadedID, unsigned LoadedOffset); const SrcMgr::ContentCache * - getOrCreateContentCache(const FileEntry *SourceFile); + getOrCreateContentCache(const FileEntry *SourceFile, + bool isSystemFile = false); /// \brief Create a new ContentCache for the specified memory buffer. const SrcMgr::ContentCache* |