Skip to content

Commit 1d78e21

Browse files
committed
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
1 parent 7175cff commit 1d78e21

File tree

2 files changed

+10
-15
lines changed

2 files changed

+10
-15
lines changed

clang/include/clang/Basic/SourceManager.h

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,6 @@ namespace SrcMgr {
9595
/// This object owns the MemoryBuffer object.
9696
class alignas(8) ContentCache {
9797
enum CCFlags {
98-
/// Whether the buffer is invalid.
99-
InvalidFlag = 0x01,
100-
10198
/// Whether the buffer should not be freed on destruction.
10299
DoNotFreeFlag = 0x02
103100
};
@@ -151,18 +148,21 @@ namespace SrcMgr {
151148
/// after serialization and deserialization.
152149
unsigned IsTransient : 1;
153150

151+
mutable unsigned IsBufferInvalid : 1;
152+
154153
ContentCache(const FileEntry *Ent = nullptr) : ContentCache(Ent, Ent) {}
155154

156155
ContentCache(const FileEntry *Ent, const FileEntry *contentEnt)
157156
: Buffer(nullptr, false), OrigEntry(Ent), ContentsEntry(contentEnt),
158-
BufferOverridden(false), IsFileVolatile(false), IsTransient(false) {}
157+
BufferOverridden(false), IsFileVolatile(false), IsTransient(false),
158+
IsBufferInvalid(false) {}
159159

160160
/// The copy ctor does not allow copies where source object has either
161161
/// a non-NULL Buffer or SourceLineCache. Ownership of allocated memory
162162
/// is not transferred, so this is a logical error.
163163
ContentCache(const ContentCache &RHS)
164164
: Buffer(nullptr, false), BufferOverridden(false),
165-
IsFileVolatile(false), IsTransient(false) {
165+
IsFileVolatile(false), IsTransient(false), IsBufferInvalid(false) {
166166
OrigEntry = RHS.OrigEntry;
167167
ContentsEntry = RHS.ContentsEntry;
168168

@@ -216,11 +216,6 @@ namespace SrcMgr {
216216
/// with the given buffer.
217217
void replaceBuffer(const llvm::MemoryBuffer *B, bool DoNotFree = false);
218218

219-
/// Determine whether the buffer itself is invalid.
220-
bool isBufferInvalid() const {
221-
return Buffer.getInt() & InvalidFlag;
222-
}
223-
224219
/// Determine whether the buffer should be freed.
225220
bool shouldFreeBuffer() const {
226221
return (Buffer.getInt() & DoNotFreeFlag) == 0;

clang/lib/Basic/SourceManager.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ ContentCache::getBufferOrNone(DiagnosticsEngine &Diag, FileManager &FM,
123123
SourceLocation Loc) const {
124124
// Lazily create the Buffer for ContentCaches that wrap files. If we already
125125
// computed it, just return what we have.
126-
if (isBufferInvalid())
126+
if (IsBufferInvalid)
127127
return None;
128128
if (auto *B = Buffer.getPointer())
129129
return B->getMemBufferRef();
@@ -144,7 +144,7 @@ ContentCache::getBufferOrNone(DiagnosticsEngine &Diag, FileManager &FM,
144144
Diag.Report(Loc, diag::err_file_too_large)
145145
<< ContentsEntry->getName();
146146

147-
Buffer.setInt(Buffer.getInt() | InvalidFlag);
147+
IsBufferInvalid = true;
148148
return None;
149149
}
150150

@@ -164,7 +164,7 @@ ContentCache::getBufferOrNone(DiagnosticsEngine &Diag, FileManager &FM,
164164
Diag.Report(Loc, diag::err_cannot_open_file)
165165
<< ContentsEntry->getName() << BufferOrError.getError().message();
166166

167-
Buffer.setInt(Buffer.getInt() | InvalidFlag);
167+
IsBufferInvalid = true;
168168
return None;
169169
}
170170

@@ -180,7 +180,7 @@ ContentCache::getBufferOrNone(DiagnosticsEngine &Diag, FileManager &FM,
180180
Diag.Report(Loc, diag::err_file_modified)
181181
<< ContentsEntry->getName();
182182

183-
Buffer.setInt(Buffer.getInt() | InvalidFlag);
183+
IsBufferInvalid = true;
184184
return None;
185185
}
186186

@@ -193,7 +193,7 @@ ContentCache::getBufferOrNone(DiagnosticsEngine &Diag, FileManager &FM,
193193
if (InvalidBOM) {
194194
Diag.Report(Loc, diag::err_unsupported_bom)
195195
<< InvalidBOM << ContentsEntry->getName();
196-
Buffer.setInt(Buffer.getInt() | InvalidFlag);
196+
IsBufferInvalid = true;
197197
return None;
198198
}
199199

0 commit comments

Comments
 (0)