[PATCH] D89431: clang/Basic: ContentCache::InvalidFlag => ContentCache::IsBufferInvalid, NFC

Duncan P. N. Exon Smith via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Oct 14 15:25:33 PDT 2020


dexonsmith created this revision.
dexonsmith added a reviewer: arphaman.
Herald added a subscriber: ributzka.
dexonsmith requested review of this revision.

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.


https://reviews.llvm.org/D89431

Files:
  clang/include/clang/Basic/SourceManager.h
  clang/lib/Basic/SourceManager.cpp


Index: clang/lib/Basic/SourceManager.cpp
===================================================================
--- clang/lib/Basic/SourceManager.cpp
+++ clang/lib/Basic/SourceManager.cpp
@@ -123,7 +123,7 @@
                               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 @@
       Diag.Report(Loc, diag::err_file_too_large)
         << ContentsEntry->getName();
 
-    Buffer.setInt(Buffer.getInt() | InvalidFlag);
+    IsBufferInvalid = true;
     return None;
   }
 
@@ -164,7 +164,7 @@
       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 @@
       Diag.Report(Loc, diag::err_file_modified)
         << ContentsEntry->getName();
 
-    Buffer.setInt(Buffer.getInt() | InvalidFlag);
+    IsBufferInvalid = true;
     return None;
   }
 
@@ -193,7 +193,7 @@
   if (InvalidBOM) {
     Diag.Report(Loc, diag::err_unsupported_bom)
       << InvalidBOM << ContentsEntry->getName();
-    Buffer.setInt(Buffer.getInt() | InvalidFlag);
+    IsBufferInvalid = true;
     return None;
   }
 
Index: clang/include/clang/Basic/SourceManager.h
===================================================================
--- clang/include/clang/Basic/SourceManager.h
+++ clang/include/clang/Basic/SourceManager.h
@@ -95,9 +95,6 @@
   /// 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,6 +148,8 @@
     /// 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)
@@ -216,11 +215,6 @@
     /// 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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D89431.298250.patch
Type: text/x-patch
Size: 2688 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201014/9564cf91/attachment-0001.bin>


More information about the cfe-commits mailing list