diff options
author | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2012-05-03 21:50:39 +0000 |
---|---|---|
committer | Argyrios Kyrtzidis <akyrtzi@gmail.com> | 2012-05-03 21:50:39 +0000 |
commit | d54dff026b02303a35147224de72bb44cbb53c79 (patch) | |
tree | ad4e52eb5d1269f16c3445e34d59475abff01880 /include/clang/Basic/SourceManager.h | |
parent | 8b08adb279e7db69c65461f7c0029344dc3e4e5f (diff) |
[PCH] When validating that the files coming from PCH did not change, also
validate that we didn't override the contents of any of such files.
If this is detected, emit a diagnostic error and recover gracefully
by using the contents of the original file that the PCH was built from.
Part of rdar://11305263
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@156107 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Basic/SourceManager.h')
-rw-r--r-- | include/clang/Basic/SourceManager.h | 38 |
1 files changed, 36 insertions, 2 deletions
diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h index bcb2d561a4..3164f874f1 100644 --- a/include/clang/Basic/SourceManager.h +++ b/include/clang/Basic/SourceManager.h @@ -21,7 +21,9 @@ #include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/PointerUnion.h" #include "llvm/ADT/IntrusiveRefCntPtr.h" +#include "llvm/ADT/OwningPtr.h" #include "llvm/ADT/DenseMap.h" +#include "llvm/ADT/DenseSet.h" #include "llvm/Support/MemoryBuffer.h" #include <map> #include <vector> @@ -501,9 +503,24 @@ class SourceManager : public RefCountedBase<SourceManager> { /// files, should report the original file name. Defaults to true. bool OverridenFilesKeepOriginalName; - /// \brief Files that have been overriden with the contents from another file. - llvm::DenseMap<const FileEntry *, const FileEntry *> OverriddenFiles; + struct OverriddenFilesInfoTy { + /// \brief Files that have been overriden with the contents from another + /// file. + llvm::DenseMap<const FileEntry *, const FileEntry *> OverriddenFiles; + /// \brief Files that were overridden with a memory buffer. + llvm::DenseSet<const FileEntry *> OverriddenFilesWithBuffer; + }; + + /// \brief Lazily create the object keeping overridden files info, since + /// it is uncommonly used. + OwningPtr<OverriddenFilesInfoTy> OverriddenFilesInfo; + OverriddenFilesInfoTy &getOverriddenFilesInfo() { + if (!OverriddenFilesInfo) + OverriddenFilesInfo.reset(new OverriddenFilesInfoTy); + return *OverriddenFilesInfo; + } + /// MemBufferInfos - Information about various memory buffers that we have /// read in. All FileEntry* within the stored ContentCache objects are NULL, /// as they do not refer to a file. @@ -715,6 +732,23 @@ public: void overrideFileContents(const FileEntry *SourceFile, const FileEntry *NewFile); + /// \brief Returns true if the file contents have been overridden. + bool isFileOverridden(const FileEntry *File) { + if (OverriddenFilesInfo) { + if (OverriddenFilesInfo->OverriddenFilesWithBuffer.count(File)) + return true; + if (OverriddenFilesInfo->OverriddenFiles.find(File) != + OverriddenFilesInfo->OverriddenFiles.end()) + return true; + } + return false; + } + + /// \brief Disable overridding the contents of a file, previously enabled + /// with \see overrideFileContents. + /// This should be called before parsing has begun. + void disableFileContentsOverride(const FileEntry *File); + //===--------------------------------------------------------------------===// // FileID manipulation methods. //===--------------------------------------------------------------------===// |