When copying a partial diagnostic into a DependentDiagnostic, allocate

storage for that partial diagnostic via the ASTContext's
BumpPtrAllocator rather than using up slots in the ASTContext's
cache. Now that we do this, we don't have to worry about destroying
dependent diagnostics when destroying a DependentStoredDeclsMap.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@99854 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Douglas Gregor 2010-03-29 23:56:53 +00:00
Родитель fe6b2d481d
Коммит b836518bfc
4 изменённых файлов: 28 добавлений и 19 удалений

Просмотреть файл

@ -275,7 +275,6 @@ private:
class DependentStoredDeclsMap : public StoredDeclsMap { class DependentStoredDeclsMap : public StoredDeclsMap {
public: public:
DependentStoredDeclsMap() : FirstDiagnostic(0) {} DependentStoredDeclsMap() : FirstDiagnostic(0) {}
~DependentStoredDeclsMap();
private: private:
friend class DependentDiagnostic; friend class DependentDiagnostic;

Просмотреть файл

@ -86,7 +86,10 @@ public:
} }
private: private:
DependentDiagnostic(const PartialDiagnostic &PDiag) : Diag(PDiag) {} DependentDiagnostic(const PartialDiagnostic &PDiag,
PartialDiagnostic::Storage *Storage)
: Diag(PDiag, Storage) {}
static DependentDiagnostic *Create(ASTContext &Context, static DependentDiagnostic *Create(ASTContext &Context,
DeclContext *Parent, DeclContext *Parent,
const PartialDiagnostic &PDiag); const PartialDiagnostic &PDiag);

Просмотреть файл

@ -19,12 +19,15 @@
#include "clang/Basic/Diagnostic.h" #include "clang/Basic/Diagnostic.h"
#include "clang/Basic/SourceLocation.h" #include "clang/Basic/SourceLocation.h"
#include "llvm/ADT/STLExtras.h" #include "llvm/ADT/STLExtras.h"
#include "llvm/System/DataTypes.h"
#include <cassert>
namespace clang { namespace clang {
class DeclarationName; class DeclarationName;
class PartialDiagnostic { class PartialDiagnostic {
public:
struct Storage { struct Storage {
Storage() : NumDiagArgs(0), NumDiagRanges(0), NumCodeModificationHints(0) { Storage() : NumDiagArgs(0), NumDiagRanges(0), NumCodeModificationHints(0) {
} }
@ -69,7 +72,6 @@ class PartialDiagnostic {
CodeModificationHint CodeModificationHints[MaxCodeModificationHints]; CodeModificationHint CodeModificationHints[MaxCodeModificationHints];
}; };
public:
/// \brief An allocator for Storage objects, which uses a small cache to /// \brief An allocator for Storage objects, which uses a small cache to
/// objects, used to reduce malloc()/free() traffic for partial diagnostics. /// objects, used to reduce malloc()/free() traffic for partial diagnostics.
class StorageAllocator { class StorageAllocator {
@ -126,8 +128,10 @@ private:
if (Allocator) if (Allocator)
DiagStorage = Allocator->Allocate(); DiagStorage = Allocator->Allocate();
else else {
assert(Allocator != reinterpret_cast<StorageAllocator *>(~uintptr_t(0)));
DiagStorage = new Storage; DiagStorage = new Storage;
}
return DiagStorage; return DiagStorage;
} }
@ -137,7 +141,7 @@ private:
if (Allocator) if (Allocator)
Allocator->Deallocate(DiagStorage); Allocator->Deallocate(DiagStorage);
else else if (Allocator != reinterpret_cast<StorageAllocator *>(~uintptr_t(0)))
delete DiagStorage; delete DiagStorage;
DiagStorage = 0; DiagStorage = 0;
} }
@ -189,6 +193,14 @@ public:
} }
} }
PartialDiagnostic(const PartialDiagnostic &Other, Storage *DiagStorage)
: DiagID(Other.DiagID), DiagStorage(DiagStorage),
Allocator(reinterpret_cast<StorageAllocator *>(~uintptr_t(0)))
{
if (Other.DiagStorage)
*this->DiagStorage = *Other.DiagStorage;
}
PartialDiagnostic &operator=(const PartialDiagnostic &Other) { PartialDiagnostic &operator=(const PartialDiagnostic &Other) {
DiagID = Other.DiagID; DiagID = Other.DiagID;
if (Other.DiagStorage) { if (Other.DiagStorage) {
@ -235,6 +247,8 @@ public:
freeStorage(); freeStorage();
} }
bool hasStorage() const { return DiagStorage != 0; }
friend const PartialDiagnostic &operator<<(const PartialDiagnostic &PD, friend const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
QualType T) { QualType T) {
PD.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()), PD.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()),

Просмотреть файл

@ -994,17 +994,6 @@ void StoredDeclsMap::DestroyAll(StoredDeclsMap *Map, bool Dependent) {
} }
} }
DependentStoredDeclsMap::~DependentStoredDeclsMap() {
// Kill off the dependent diagnostics. They don't need to be
// deleted, but they do need to be destructed.
DependentDiagnostic *CurD = FirstDiagnostic;
while (CurD) {
DependentDiagnostic *NextD = CurD->NextDiagnostic;
CurD->~DependentDiagnostic();
CurD = NextD;
}
}
DependentDiagnostic *DependentDiagnostic::Create(ASTContext &C, DependentDiagnostic *DependentDiagnostic::Create(ASTContext &C,
DeclContext *Parent, DeclContext *Parent,
const PartialDiagnostic &PDiag) { const PartialDiagnostic &PDiag) {
@ -1017,9 +1006,13 @@ DependentDiagnostic *DependentDiagnostic::Create(ASTContext &C,
DependentStoredDeclsMap *Map DependentStoredDeclsMap *Map
= static_cast<DependentStoredDeclsMap*>(Parent->LookupPtr); = static_cast<DependentStoredDeclsMap*>(Parent->LookupPtr);
// FIXME: Allocate the copy of the PartialDiagnostic via the ASTContext's // Allocate the copy of the PartialDiagnostic via the ASTContext's
// BumpPtrAllocator, rather than the ASTContext itself. // BumpPtrAllocator, rather than the ASTContext itself.
DependentDiagnostic *DD = new (C) DependentDiagnostic(PDiag); PartialDiagnostic::Storage *DiagStorage = 0;
if (PDiag.hasStorage())
DiagStorage = new (C) PartialDiagnostic::Storage;
DependentDiagnostic *DD = new (C) DependentDiagnostic(PDiag, DiagStorage);
// TODO: Maybe we shouldn't reverse the order during insertion. // TODO: Maybe we shouldn't reverse the order during insertion.
DD->NextDiagnostic = Map->FirstDiagnostic; DD->NextDiagnostic = Map->FirstDiagnostic;