forked from OSchip/llvm-project
reclaim my precious bit in FileInfo by ensuring that ContentCache objects
are 8-byte aligned. llvm-svn: 63630
This commit is contained in:
parent
ed8903e45a
commit
9be4f6d6c7
|
@ -144,7 +144,7 @@ namespace SrcMgr {
|
||||||
FileInfo X;
|
FileInfo X;
|
||||||
X.IncludeLoc = IL.getRawEncoding();
|
X.IncludeLoc = IL.getRawEncoding();
|
||||||
X.Data = (uintptr_t)Con;
|
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");
|
assert((unsigned)FileCharacter < 4 && "invalid file character");
|
||||||
X.Data |= (unsigned)FileCharacter;
|
X.Data |= (unsigned)FileCharacter;
|
||||||
return X;
|
return X;
|
||||||
|
@ -154,7 +154,7 @@ namespace SrcMgr {
|
||||||
return SourceLocation::getFromRawEncoding(IncludeLoc);
|
return SourceLocation::getFromRawEncoding(IncludeLoc);
|
||||||
}
|
}
|
||||||
const ContentCache* getContentCache() const {
|
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.
|
/// getCharacteristic - Return whether this is a system header or not.
|
||||||
|
|
|
@ -160,8 +160,12 @@ SourceManager::getOrCreateContentCache(const FileEntry *FileEnt) {
|
||||||
ContentCache *&Entry = FileInfos[FileEnt];
|
ContentCache *&Entry = FileInfos[FileEnt];
|
||||||
if (Entry) return Entry;
|
if (Entry) return Entry;
|
||||||
|
|
||||||
// Nope, create a new Cache entry.
|
// Nope, create a new Cache entry. Make sure it is at least 8-byte aligned
|
||||||
Entry = ContentCacheAlloc.Allocate<ContentCache>();
|
// 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);
|
new (Entry) ContentCache(FileEnt);
|
||||||
return Entry;
|
return Entry;
|
||||||
}
|
}
|
||||||
|
@ -171,11 +175,12 @@ SourceManager::getOrCreateContentCache(const FileEntry *FileEnt) {
|
||||||
/// memory buffer. This does no caching.
|
/// memory buffer. This does no caching.
|
||||||
const ContentCache*
|
const ContentCache*
|
||||||
SourceManager::createMemBufferContentCache(const MemoryBuffer *Buffer) {
|
SourceManager::createMemBufferContentCache(const MemoryBuffer *Buffer) {
|
||||||
// Add a new ContentCache to the MemBufferInfos list and return it. We
|
// Add a new ContentCache to the MemBufferInfos list and return it. Make sure
|
||||||
// must default construct the object first that the instance actually
|
// it is at least 8-byte aligned so that FileInfo can use the low 3 bits of
|
||||||
// stored within MemBufferInfos actually owns the Buffer, and not any
|
// the pointer for its own nefarious purposes.
|
||||||
// temporary we would use in the call to "push_back".
|
unsigned EntryAlign = llvm::AlignOf<ContentCache>::Alignment;
|
||||||
ContentCache *Entry = ContentCacheAlloc.Allocate<ContentCache>();
|
EntryAlign = std::max(8U, EntryAlign);
|
||||||
|
ContentCache *Entry = ContentCacheAlloc.Allocate<ContentCache>(1, EntryAlign);
|
||||||
new (Entry) ContentCache();
|
new (Entry) ContentCache();
|
||||||
MemBufferInfos.push_back(Entry);
|
MemBufferInfos.push_back(Entry);
|
||||||
Entry->setBuffer(Buffer);
|
Entry->setBuffer(Buffer);
|
||||||
|
|
Loading…
Reference in New Issue