[cfe-commits] r99854 - in /cfe/trunk: include/clang/AST/DeclContextInternals.h include/clang/AST/DependentDiagnostic.h include/clang/Basic/PartialDiagnostic.h lib/AST/DeclBase.cpp

Douglas Gregor dgregor at apple.com
Mon Mar 29 16:56:53 PDT 2010


Author: dgregor
Date: Mon Mar 29 18:56:53 2010
New Revision: 99854

URL: http://llvm.org/viewvc/llvm-project?rev=99854&view=rev
Log:
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.

Modified:
    cfe/trunk/include/clang/AST/DeclContextInternals.h
    cfe/trunk/include/clang/AST/DependentDiagnostic.h
    cfe/trunk/include/clang/Basic/PartialDiagnostic.h
    cfe/trunk/lib/AST/DeclBase.cpp

Modified: cfe/trunk/include/clang/AST/DeclContextInternals.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DeclContextInternals.h?rev=99854&r1=99853&r2=99854&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DeclContextInternals.h (original)
+++ cfe/trunk/include/clang/AST/DeclContextInternals.h Mon Mar 29 18:56:53 2010
@@ -275,7 +275,6 @@
 class DependentStoredDeclsMap : public StoredDeclsMap {
 public:
   DependentStoredDeclsMap() : FirstDiagnostic(0) {}
-  ~DependentStoredDeclsMap();
 
 private:
   friend class DependentDiagnostic;

Modified: cfe/trunk/include/clang/AST/DependentDiagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/DependentDiagnostic.h?rev=99854&r1=99853&r2=99854&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/DependentDiagnostic.h (original)
+++ cfe/trunk/include/clang/AST/DependentDiagnostic.h Mon Mar 29 18:56:53 2010
@@ -86,7 +86,10 @@
   }
 
 private:
-  DependentDiagnostic(const PartialDiagnostic &PDiag) : Diag(PDiag) {}
+  DependentDiagnostic(const PartialDiagnostic &PDiag,
+                      PartialDiagnostic::Storage *Storage) 
+    : Diag(PDiag, Storage) {}
+  
   static DependentDiagnostic *Create(ASTContext &Context,
                                      DeclContext *Parent,
                                      const PartialDiagnostic &PDiag);

Modified: cfe/trunk/include/clang/Basic/PartialDiagnostic.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/PartialDiagnostic.h?rev=99854&r1=99853&r2=99854&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/PartialDiagnostic.h (original)
+++ cfe/trunk/include/clang/Basic/PartialDiagnostic.h Mon Mar 29 18:56:53 2010
@@ -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 @@
     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 @@
     
     if (Allocator)
       DiagStorage = Allocator->Allocate();
-    else
+    else {
+      assert(Allocator != reinterpret_cast<StorageAllocator *>(~uintptr_t(0)));
       DiagStorage = new Storage;
+    }
     return DiagStorage;
   }
   
@@ -137,7 +141,7 @@
     
     if (Allocator)
       Allocator->Deallocate(DiagStorage);
-    else
+    else if (Allocator != reinterpret_cast<StorageAllocator *>(~uintptr_t(0)))
       delete DiagStorage;
     DiagStorage = 0;
   }
@@ -189,6 +193,14 @@
     }
   }
 
+  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 @@
     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 @@
   
 
 }  // end namespace clang
-#endif 
+#endif

Modified: cfe/trunk/lib/AST/DeclBase.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/DeclBase.cpp?rev=99854&r1=99853&r2=99854&view=diff
==============================================================================
--- cfe/trunk/lib/AST/DeclBase.cpp (original)
+++ cfe/trunk/lib/AST/DeclBase.cpp Mon Mar 29 18:56:53 2010
@@ -994,17 +994,6 @@
   }
 }
 
-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,
                                                  DeclContext *Parent,
                                            const PartialDiagnostic &PDiag) {
@@ -1017,9 +1006,13 @@
   DependentStoredDeclsMap *Map
     = 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.
-  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.
   DD->NextDiagnostic = Map->FirstDiagnostic;





More information about the cfe-commits mailing list