summaryrefslogtreecommitdiffstats
path: root/include/clang/Basic/PartialDiagnostic.h
diff options
context:
space:
mode:
authorDouglas Gregor <dgregor@apple.com>2010-03-29 23:56:53 +0000
committerDouglas Gregor <dgregor@apple.com>2010-03-29 23:56:53 +0000
commitb836518bfc0a2ad5e22a670c82fa070ed83ea909 (patch)
tree1fbca9bc927901163328ad7b8f1e8a3c3d2ac151 /include/clang/Basic/PartialDiagnostic.h
parentfe6b2d481d91140923f4541f273b253291884214 (diff)
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
Diffstat (limited to 'include/clang/Basic/PartialDiagnostic.h')
-rw-r--r--include/clang/Basic/PartialDiagnostic.h22
1 files changed, 18 insertions, 4 deletions
diff --git a/include/clang/Basic/PartialDiagnostic.h b/include/clang/Basic/PartialDiagnostic.h
index 56082b7b09..d49e621d2f 100644
--- a/include/clang/Basic/PartialDiagnostic.h
+++ b/include/clang/Basic/PartialDiagnostic.h
@@ -19,12 +19,15 @@
#include "clang/Basic/Diagnostic.h"
#include "clang/Basic/SourceLocation.h"
#include "llvm/ADT/STLExtras.h"
+#include "llvm/System/DataTypes.h"
+#include <cassert>
namespace clang {
class DeclarationName;
class PartialDiagnostic {
+public:
struct Storage {
Storage() : NumDiagArgs(0), NumDiagRanges(0), NumCodeModificationHints(0) {
}
@@ -69,7 +72,6 @@ class PartialDiagnostic {
CodeModificationHint CodeModificationHints[MaxCodeModificationHints];
};
-public:
/// \brief An allocator for Storage objects, which uses a small cache to
/// objects, used to reduce malloc()/free() traffic for partial diagnostics.
class StorageAllocator {
@@ -126,8 +128,10 @@ private:
if (Allocator)
DiagStorage = Allocator->Allocate();
- else
+ else {
+ assert(Allocator != reinterpret_cast<StorageAllocator *>(~uintptr_t(0)));
DiagStorage = new Storage;
+ }
return DiagStorage;
}
@@ -137,7 +141,7 @@ private:
if (Allocator)
Allocator->Deallocate(DiagStorage);
- else
+ else if (Allocator != reinterpret_cast<StorageAllocator *>(~uintptr_t(0)))
delete DiagStorage;
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) {
DiagID = Other.DiagID;
if (Other.DiagStorage) {
@@ -235,6 +247,8 @@ public:
freeStorage();
}
+ bool hasStorage() const { return DiagStorage != 0; }
+
friend const PartialDiagnostic &operator<<(const PartialDiagnostic &PD,
QualType T) {
PD.AddTaggedVal(reinterpret_cast<intptr_t>(T.getAsOpaquePtr()),
@@ -285,4 +299,4 @@ inline const DiagnosticBuilder &operator<<(const DiagnosticBuilder &DB,
} // end namespace clang
-#endif
+#endif