diff options
author | Douglas Gregor <dgregor@apple.com> | 2010-03-16 22:53:51 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2010-03-16 22:53:51 +0000 |
commit | c815108d08b0417c6f1104e7df70dc5278839406 (patch) | |
tree | 42fa24ee20398728edde29352a3572051bc69f40 /include/clang/Basic/SourceManager.h | |
parent | 453091cc2082e207ea2c2dda645a9bc01b37fb0c (diff) |
Teach SourceManager's content cache to keep track of whether its
buffer was invalid when it was created, and use that bit to always set
the "Invalid" flag according to whether the buffer is invalid. This
ensures that all accesses to an invalid buffer are marked invalid,
improving recovery.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@98690 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/Basic/SourceManager.h')
-rw-r--r-- | include/clang/Basic/SourceManager.h | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/include/clang/Basic/SourceManager.h b/include/clang/Basic/SourceManager.h index ef51a58883..d1239694fc 100644 --- a/include/clang/Basic/SourceManager.h +++ b/include/clang/Basic/SourceManager.h @@ -17,6 +17,7 @@ #include "clang/Basic/SourceLocation.h" #include "llvm/Support/Allocator.h" #include "llvm/System/DataTypes.h" +#include "llvm/ADT/PointerIntPair.h" #include "llvm/ADT/PointerUnion.h" #include "llvm/ADT/DenseMap.h" #include <vector> @@ -54,7 +55,8 @@ namespace SrcMgr { class ContentCache { /// Buffer - The actual buffer containing the characters from the input /// file. This is owned by the ContentCache object. - mutable const llvm::MemoryBuffer *Buffer; + /// The bit indicates whether the buffer is invalid. + mutable llvm::PointerIntPair<const llvm::MemoryBuffer *, 1, bool> Buffer; public: /// Reference to the file entry. This reference does not own @@ -92,8 +94,9 @@ namespace SrcMgr { unsigned getSizeBytesMapped() const; void setBuffer(const llvm::MemoryBuffer *B) { - assert(!Buffer && "MemoryBuffer already set."); - Buffer = B; + assert(!Buffer.getPointer() && "MemoryBuffer already set."); + Buffer.setPointer(B); + Buffer.setInt(false); } /// \brief Replace the existing buffer (which will be deleted) @@ -101,17 +104,19 @@ namespace SrcMgr { void replaceBuffer(const llvm::MemoryBuffer *B); ContentCache(const FileEntry *Ent = 0) - : Buffer(0), Entry(Ent), SourceLineCache(0), NumLines(0) {} + : Buffer(0, false), Entry(Ent), SourceLineCache(0), NumLines(0) {} ~ContentCache(); /// The copy ctor does not allow copies where source object has either /// a non-NULL Buffer or SourceLineCache. Ownership of allocated memory /// is not transfered, so this is a logical error. - ContentCache(const ContentCache &RHS) : Buffer(0), SourceLineCache(0) { + ContentCache(const ContentCache &RHS) + : Buffer(0, false), SourceLineCache(0) + { Entry = RHS.Entry; - assert (RHS.Buffer == 0 && RHS.SourceLineCache == 0 + assert (RHS.Buffer.getPointer() == 0 && RHS.SourceLineCache == 0 && "Passed ContentCache object cannot own a buffer."); NumLines = RHS.NumLines; |