[clang] 1d78e21 - clang/Basic: ContentCache::InvalidFlag => ContentCache::IsBufferInvalid, NFC
Duncan P. N. Exon Smith via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 20 16:28:37 PDT 2020
Author: Duncan P. N. Exon Smith
Date: 2020-10-20T19:28:17-04:00
New Revision: 1d78e2101ab75f01615a45467c44da7181cccedb
URL: https://github.com/llvm/llvm-project/commit/1d78e2101ab75f01615a45467c44da7181cccedb
DIFF: https://github.com/llvm/llvm-project/commit/1d78e2101ab75f01615a45467c44da7181cccedb.diff
LOG: clang/Basic: ContentCache::InvalidFlag => ContentCache::IsBufferInvalid, NFC
Move a flag out of the `MemoryBuffer*` to unblock changing it to a
`unique_ptr`. There are plenty of bits available in the bitfield below.
Differential Revision: https://reviews.llvm.org/D89431
Added:
Modified:
clang/include/clang/Basic/SourceManager.h
clang/lib/Basic/SourceManager.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/Basic/SourceManager.h b/clang/include/clang/Basic/SourceManager.h
index 480fa51d6889..569ef002d387 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -95,9 +95,6 @@ namespace SrcMgr {
/// This object owns the MemoryBuffer object.
class alignas(8) ContentCache {
enum CCFlags {
- /// Whether the buffer is invalid.
- InvalidFlag = 0x01,
-
/// Whether the buffer should not be freed on destruction.
DoNotFreeFlag = 0x02
};
@@ -151,18 +148,21 @@ namespace SrcMgr {
/// after serialization and deserialization.
unsigned IsTransient : 1;
+ mutable unsigned IsBufferInvalid : 1;
+
ContentCache(const FileEntry *Ent = nullptr) : ContentCache(Ent, Ent) {}
ContentCache(const FileEntry *Ent, const FileEntry *contentEnt)
: Buffer(nullptr, false), OrigEntry(Ent), ContentsEntry(contentEnt),
- BufferOverridden(false), IsFileVolatile(false), IsTransient(false) {}
+ BufferOverridden(false), IsFileVolatile(false), IsTransient(false),
+ IsBufferInvalid(false) {}
/// The copy ctor does not allow copies where source object has either
/// a non-NULL Buffer or SourceLineCache. Ownership of allocated memory
/// is not transferred, so this is a logical error.
ContentCache(const ContentCache &RHS)
: Buffer(nullptr, false), BufferOverridden(false),
- IsFileVolatile(false), IsTransient(false) {
+ IsFileVolatile(false), IsTransient(false), IsBufferInvalid(false) {
OrigEntry = RHS.OrigEntry;
ContentsEntry = RHS.ContentsEntry;
@@ -216,11 +216,6 @@ namespace SrcMgr {
/// with the given buffer.
void replaceBuffer(const llvm::MemoryBuffer *B, bool DoNotFree = false);
- /// Determine whether the buffer itself is invalid.
- bool isBufferInvalid() const {
- return Buffer.getInt() & InvalidFlag;
- }
-
/// Determine whether the buffer should be freed.
bool shouldFreeBuffer() const {
return (Buffer.getInt() & DoNotFreeFlag) == 0;
diff --git a/clang/lib/Basic/SourceManager.cpp b/clang/lib/Basic/SourceManager.cpp
index 27d2f398f3c6..c831d26c380c 100644
--- a/clang/lib/Basic/SourceManager.cpp
+++ b/clang/lib/Basic/SourceManager.cpp
@@ -123,7 +123,7 @@ ContentCache::getBufferOrNone(DiagnosticsEngine &Diag, FileManager &FM,
SourceLocation Loc) const {
// Lazily create the Buffer for ContentCaches that wrap files. If we already
// computed it, just return what we have.
- if (isBufferInvalid())
+ if (IsBufferInvalid)
return None;
if (auto *B = Buffer.getPointer())
return B->getMemBufferRef();
@@ -144,7 +144,7 @@ ContentCache::getBufferOrNone(DiagnosticsEngine &Diag, FileManager &FM,
Diag.Report(Loc, diag::err_file_too_large)
<< ContentsEntry->getName();
- Buffer.setInt(Buffer.getInt() | InvalidFlag);
+ IsBufferInvalid = true;
return None;
}
@@ -164,7 +164,7 @@ ContentCache::getBufferOrNone(DiagnosticsEngine &Diag, FileManager &FM,
Diag.Report(Loc, diag::err_cannot_open_file)
<< ContentsEntry->getName() << BufferOrError.getError().message();
- Buffer.setInt(Buffer.getInt() | InvalidFlag);
+ IsBufferInvalid = true;
return None;
}
@@ -180,7 +180,7 @@ ContentCache::getBufferOrNone(DiagnosticsEngine &Diag, FileManager &FM,
Diag.Report(Loc, diag::err_file_modified)
<< ContentsEntry->getName();
- Buffer.setInt(Buffer.getInt() | InvalidFlag);
+ IsBufferInvalid = true;
return None;
}
@@ -193,7 +193,7 @@ ContentCache::getBufferOrNone(DiagnosticsEngine &Diag, FileManager &FM,
if (InvalidBOM) {
Diag.Report(Loc, diag::err_unsupported_bom)
<< InvalidBOM << ContentsEntry->getName();
- Buffer.setInt(Buffer.getInt() | InvalidFlag);
+ IsBufferInvalid = true;
return None;
}
More information about the cfe-commits
mailing list