[cfe-commits] r63630 - in /cfe/trunk: include/clang/Basic/SourceManager.h lib/Basic/SourceManager.cpp

Chris Lattner sabre at nondot.org
Mon Feb 2 23:41:46 PST 2009


Author: lattner
Date: Tue Feb  3 01:41:46 2009
New Revision: 63630

URL: http://llvm.org/viewvc/llvm-project?rev=63630&view=rev
Log:
reclaim my precious bit in FileInfo by ensuring that ContentCache objects
are 8-byte aligned.

Modified:
    cfe/trunk/include/clang/Basic/SourceManager.h
    cfe/trunk/lib/Basic/SourceManager.cpp

Modified: cfe/trunk/include/clang/Basic/SourceManager.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/SourceManager.h?rev=63630&r1=63629&r2=63630&view=diff

==============================================================================
--- cfe/trunk/include/clang/Basic/SourceManager.h (original)
+++ cfe/trunk/include/clang/Basic/SourceManager.h Tue Feb  3 01:41:46 2009
@@ -144,7 +144,7 @@
       FileInfo X;
       X.IncludeLoc = IL.getRawEncoding();
       X.Data = (uintptr_t)Con;
-      assert((X.Data & 3) == 0 &&"ContentCache pointer insufficiently aligned");
+      assert((X.Data & 7) == 0 &&"ContentCache pointer insufficiently aligned");
       assert((unsigned)FileCharacter < 4 && "invalid file character");
       X.Data |= (unsigned)FileCharacter;
       return X;
@@ -154,7 +154,7 @@
       return SourceLocation::getFromRawEncoding(IncludeLoc);
     }
     const ContentCache* getContentCache() const {
-      return reinterpret_cast<const ContentCache*>(Data & ~3UL);
+      return reinterpret_cast<const ContentCache*>(Data & ~7UL);
     }
     
     /// getCharacteristic - Return whether this is a system header or not.

Modified: cfe/trunk/lib/Basic/SourceManager.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Basic/SourceManager.cpp?rev=63630&r1=63629&r2=63630&view=diff

==============================================================================
--- cfe/trunk/lib/Basic/SourceManager.cpp (original)
+++ cfe/trunk/lib/Basic/SourceManager.cpp Tue Feb  3 01:41:46 2009
@@ -160,8 +160,12 @@
   ContentCache *&Entry = FileInfos[FileEnt];
   if (Entry) return Entry;
   
-  // Nope, create a new Cache entry.
-  Entry = ContentCacheAlloc.Allocate<ContentCache>();
+  // Nope, create a new Cache entry.  Make sure it is at least 8-byte aligned
+  // so that FileInfo can use the low 3 bits of the pointer for its own
+  // nefarious purposes.
+  unsigned EntryAlign = llvm::AlignOf<ContentCache>::Alignment;
+  EntryAlign = std::max(8U, EntryAlign);
+  Entry = ContentCacheAlloc.Allocate<ContentCache>(1, EntryAlign);
   new (Entry) ContentCache(FileEnt);
   return Entry;
 }
@@ -171,11 +175,12 @@
 ///  memory buffer.  This does no caching.
 const ContentCache*
 SourceManager::createMemBufferContentCache(const MemoryBuffer *Buffer) {
-  // Add a new ContentCache to the MemBufferInfos list and return it.  We
-  // must default construct the object first that the instance actually
-  // stored within MemBufferInfos actually owns the Buffer, and not any
-  // temporary we would use in the call to "push_back".
-  ContentCache *Entry = ContentCacheAlloc.Allocate<ContentCache>();
+  // Add a new ContentCache to the MemBufferInfos list and return it.  Make sure
+  // it is at least 8-byte aligned so that FileInfo can use the low 3 bits of
+  // the pointer for its own nefarious purposes.
+  unsigned EntryAlign = llvm::AlignOf<ContentCache>::Alignment;
+  EntryAlign = std::max(8U, EntryAlign);
+  ContentCache *Entry = ContentCacheAlloc.Allocate<ContentCache>(1, EntryAlign);
   new (Entry) ContentCache();
   MemBufferInfos.push_back(Entry);
   Entry->setBuffer(Buffer);





More information about the cfe-commits mailing list