Sfoglia il codice sorgente

Add class-specific operator new to Decl hierarchy. This guarantees that Decls
can't accidentally be allocated the wrong way (missing prefix data for decls
from AST files, for instance) and simplifies the CreateDeserialized functions a
little. An extra DeclContext* parameter to the not-from-AST-file operator new
allows us to ensure that we don't accidentally call the wrong one when
deserializing (when we don't have a DeclContext), allows some extra checks, and
prepares for some planned modules-related changes to Decl allocation.

No functionality change intended.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@195426 91177308-0d34-0410-b5e6-96231b3b80d8

Richard Smith 11 anni fa
parent
commit
4903ea2c65

+ 16 - 12
include/clang/AST/DeclBase.h

@@ -302,6 +302,22 @@ protected:
 
 
   template<typename decl_type> friend class Redeclarable;
   template<typename decl_type> friend class Redeclarable;
 
 
+  /// \brief Allocate memory for a deserialized declaration.
+  ///
+  /// This routine must be used to allocate memory for any declaration that is
+  /// deserialized from a module file.
+  ///
+  /// \param Size The size of the allocated object.
+  /// \param Context The context in which we will allocate memory.
+  /// \param ID The global ID of the deserialized declaration.
+  /// \param Extra The amount of extra space to allocate after the object.
+  void *operator new(std::size_t Size, const ASTContext &Ctx, unsigned ID,
+                     std::size_t Extra = 0);
+
+  /// \brief Allocate memory for a non-deserialized declaration.
+  void *operator new(std::size_t Size, const ASTContext &Ctx,
+                     DeclContext *Parent, std::size_t Extra = 0);
+
 private:
 private:
   void CheckAccessDeclContext() const;
   void CheckAccessDeclContext() const;
 
 
@@ -330,18 +346,6 @@ protected:
 
 
   virtual ~Decl();
   virtual ~Decl();
 
 
-  /// \brief Allocate memory for a deserialized declaration.
-  ///
-  /// This routine must be used to allocate memory for any declaration that is
-  /// deserialized from a module file.
-  ///
-  /// \param Context The context in which we will allocate memory.
-  /// \param ID The global ID of the deserialized declaration.
-  /// \param Size The size of the allocated object.
-  static void *AllocateDeserializedDecl(const ASTContext &Context,
-                                        unsigned ID,
-                                        unsigned Size);
-
   /// \brief Update a potentially out-of-date declaration.
   /// \brief Update a potentially out-of-date declaration.
   void updateOutOfDate(IdentifierInfo &II) const;
   void updateOutOfDate(IdentifierInfo &II) const;
 
 

+ 12 - 9
include/clang/AST/DeclCXX.h

@@ -129,7 +129,7 @@ public:
   static AccessSpecDecl *Create(ASTContext &C, AccessSpecifier AS,
   static AccessSpecDecl *Create(ASTContext &C, AccessSpecifier AS,
                                 DeclContext *DC, SourceLocation ASLoc,
                                 DeclContext *DC, SourceLocation ASLoc,
                                 SourceLocation ColonLoc) {
                                 SourceLocation ColonLoc) {
-    return new (C) AccessSpecDecl(AS, DC, ASLoc, ColonLoc);
+    return new (C, DC) AccessSpecDecl(AS, DC, ASLoc, ColonLoc);
   }
   }
   static AccessSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID);
   static AccessSpecDecl *CreateDeserialized(ASTContext &C, unsigned ID);
 
 
@@ -2701,7 +2701,7 @@ public:
   static UsingShadowDecl *Create(ASTContext &C, DeclContext *DC,
   static UsingShadowDecl *Create(ASTContext &C, DeclContext *DC,
                                  SourceLocation Loc, UsingDecl *Using,
                                  SourceLocation Loc, UsingDecl *Using,
                                  NamedDecl *Target) {
                                  NamedDecl *Target) {
-    return new (C) UsingShadowDecl(DC, Loc, Using, Target);
+    return new (C, DC) UsingShadowDecl(DC, Loc, Using, Target);
   }
   }
 
 
   static UsingShadowDecl *CreateDeserialized(ASTContext &C, unsigned ID);
   static UsingShadowDecl *CreateDeserialized(ASTContext &C, unsigned ID);
@@ -3083,14 +3083,17 @@ public:
 class MSPropertyDecl : public DeclaratorDecl {
 class MSPropertyDecl : public DeclaratorDecl {
   IdentifierInfo *GetterId, *SetterId;
   IdentifierInfo *GetterId, *SetterId;
 
 
-public:
-  MSPropertyDecl(DeclContext *DC, SourceLocation L,
-                 DeclarationName N, QualType T, TypeSourceInfo *TInfo,
-                 SourceLocation StartL, IdentifierInfo *Getter,
-                 IdentifierInfo *Setter):
-  DeclaratorDecl(MSProperty, DC, L, N, T, TInfo, StartL), GetterId(Getter),
-  SetterId(Setter) {}
+  MSPropertyDecl(DeclContext *DC, SourceLocation L, DeclarationName N,
+                 QualType T, TypeSourceInfo *TInfo, SourceLocation StartL,
+                 IdentifierInfo *Getter, IdentifierInfo *Setter)
+      : DeclaratorDecl(MSProperty, DC, L, N, T, TInfo, StartL),
+        GetterId(Getter), SetterId(Setter) {}
 
 
+public:
+  static MSPropertyDecl *Create(ASTContext &C, DeclContext *DC,
+                                SourceLocation L, DeclarationName N, QualType T,
+                                TypeSourceInfo *TInfo, SourceLocation StartL,
+                                IdentifierInfo *Getter, IdentifierInfo *Setter);
   static MSPropertyDecl *CreateDeserialized(ASTContext &C, unsigned ID);
   static MSPropertyDecl *CreateDeserialized(ASTContext &C, unsigned ID);
 
 
   static bool classof(const Decl *D) { return D->getKind() == MSProperty; }
   static bool classof(const Decl *D) { return D->getKind() == MSProperty; }

+ 2 - 3
include/clang/AST/DeclTemplate.h

@@ -2214,9 +2214,8 @@ public:
                                                       CXXMethodDecl *FD,
                                                       CXXMethodDecl *FD,
                                                    bool HasExplicitTemplateArgs,
                                                    bool HasExplicitTemplateArgs,
                                         TemplateArgumentListInfo TemplateArgs) {
                                         TemplateArgumentListInfo TemplateArgs) {
-    return new (C) ClassScopeFunctionSpecializationDecl(DC , Loc, FD,
-                                                        HasExplicitTemplateArgs,
-                                                        TemplateArgs);
+    return new (C, DC) ClassScopeFunctionSpecializationDecl(
+        DC, Loc, FD, HasExplicitTemplateArgs, TemplateArgs);
   }
   }
 
 
   static ClassScopeFunctionSpecializationDecl *
   static ClassScopeFunctionSpecializationDecl *

+ 66 - 92
lib/AST/Decl.cpp

@@ -1624,13 +1624,12 @@ VarDecl *VarDecl::Create(ASTContext &C, DeclContext *DC,
                          SourceLocation StartL, SourceLocation IdL,
                          SourceLocation StartL, SourceLocation IdL,
                          IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo,
                          IdentifierInfo *Id, QualType T, TypeSourceInfo *TInfo,
                          StorageClass S) {
                          StorageClass S) {
-  return new (C) VarDecl(Var, DC, StartL, IdL, Id, T, TInfo, S);
+  return new (C, DC) VarDecl(Var, DC, StartL, IdL, Id, T, TInfo, S);
 }
 }
 
 
 VarDecl *VarDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
 VarDecl *VarDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(VarDecl));
-  return new (Mem) VarDecl(Var, 0, SourceLocation(), SourceLocation(), 0, 
-                           QualType(), 0, SC_None);
+  return new (C, ID) VarDecl(Var, 0, SourceLocation(), SourceLocation(), 0,
+                             QualType(), 0, SC_None);
 }
 }
 
 
 void VarDecl::setStorageClass(StorageClass SC) {
 void VarDecl::setStorageClass(StorageClass SC) {
@@ -2097,8 +2096,8 @@ ParmVarDecl *ParmVarDecl::Create(ASTContext &C, DeclContext *DC,
                                  SourceLocation IdLoc, IdentifierInfo *Id,
                                  SourceLocation IdLoc, IdentifierInfo *Id,
                                  QualType T, TypeSourceInfo *TInfo,
                                  QualType T, TypeSourceInfo *TInfo,
                                  StorageClass S, Expr *DefArg) {
                                  StorageClass S, Expr *DefArg) {
-  return new (C) ParmVarDecl(ParmVar, DC, StartLoc, IdLoc, Id, T, TInfo,
-                             S, DefArg);
+  return new (C, DC) ParmVarDecl(ParmVar, DC, StartLoc, IdLoc, Id, T, TInfo,
+                                 S, DefArg);
 }
 }
 
 
 QualType ParmVarDecl::getOriginalType() const {
 QualType ParmVarDecl::getOriginalType() const {
@@ -2110,9 +2109,8 @@ QualType ParmVarDecl::getOriginalType() const {
 }
 }
 
 
 ParmVarDecl *ParmVarDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
 ParmVarDecl *ParmVarDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ParmVarDecl));
-  return new (Mem) ParmVarDecl(ParmVar, 0, SourceLocation(), SourceLocation(),
-                               0, QualType(), 0, SC_None, 0);
+  return new (C, ID) ParmVarDecl(ParmVar, 0, SourceLocation(), SourceLocation(),
+                                 0, QualType(), 0, SC_None, 0);
 }
 }
 
 
 SourceRange ParmVarDecl::getSourceRange() const {
 SourceRange ParmVarDecl::getSourceRange() const {
@@ -3090,14 +3088,13 @@ FieldDecl *FieldDecl::Create(const ASTContext &C, DeclContext *DC,
                              IdentifierInfo *Id, QualType T,
                              IdentifierInfo *Id, QualType T,
                              TypeSourceInfo *TInfo, Expr *BW, bool Mutable,
                              TypeSourceInfo *TInfo, Expr *BW, bool Mutable,
                              InClassInitStyle InitStyle) {
                              InClassInitStyle InitStyle) {
-  return new (C) FieldDecl(Decl::Field, DC, StartLoc, IdLoc, Id, T, TInfo,
-                           BW, Mutable, InitStyle);
+  return new (C, DC) FieldDecl(Decl::Field, DC, StartLoc, IdLoc, Id, T, TInfo,
+                               BW, Mutable, InitStyle);
 }
 }
 
 
 FieldDecl *FieldDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
 FieldDecl *FieldDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(FieldDecl));
-  return new (Mem) FieldDecl(Field, 0, SourceLocation(), SourceLocation(),
-                             0, QualType(), 0, 0, false, ICIS_NoInit);
+  return new (C, ID) FieldDecl(Field, 0, SourceLocation(), SourceLocation(),
+                               0, QualType(), 0, 0, false, ICIS_NoInit);
 }
 }
 
 
 bool FieldDecl::isAnonymousStructOrUnion() const {
 bool FieldDecl::isAnonymousStructOrUnion() const {
@@ -3264,17 +3261,17 @@ EnumDecl *EnumDecl::Create(ASTContext &C, DeclContext *DC,
                            IdentifierInfo *Id,
                            IdentifierInfo *Id,
                            EnumDecl *PrevDecl, bool IsScoped,
                            EnumDecl *PrevDecl, bool IsScoped,
                            bool IsScopedUsingClassTag, bool IsFixed) {
                            bool IsScopedUsingClassTag, bool IsFixed) {
-  EnumDecl *Enum = new (C) EnumDecl(DC, StartLoc, IdLoc, Id, PrevDecl,
-                                    IsScoped, IsScopedUsingClassTag, IsFixed);
+  EnumDecl *Enum = new (C, DC) EnumDecl(DC, StartLoc, IdLoc, Id, PrevDecl,
+                                        IsScoped, IsScopedUsingClassTag,
+                                        IsFixed);
   Enum->MayHaveOutOfDateDef = C.getLangOpts().Modules;
   Enum->MayHaveOutOfDateDef = C.getLangOpts().Modules;
   C.getTypeDeclType(Enum, PrevDecl);
   C.getTypeDeclType(Enum, PrevDecl);
   return Enum;
   return Enum;
 }
 }
 
 
 EnumDecl *EnumDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
 EnumDecl *EnumDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(EnumDecl));
-  EnumDecl *Enum = new (Mem) EnumDecl(0, SourceLocation(), SourceLocation(),
-                                      0, 0, false, false, false);
+  EnumDecl *Enum = new (C, ID) EnumDecl(0, SourceLocation(), SourceLocation(),
+                                        0, 0, false, false, false);
   Enum->MayHaveOutOfDateDef = C.getLangOpts().Modules;
   Enum->MayHaveOutOfDateDef = C.getLangOpts().Modules;
   return Enum;
   return Enum;
 }
 }
@@ -3342,8 +3339,8 @@ RecordDecl::RecordDecl(Kind DK, TagKind TK, DeclContext *DC,
 RecordDecl *RecordDecl::Create(const ASTContext &C, TagKind TK, DeclContext *DC,
 RecordDecl *RecordDecl::Create(const ASTContext &C, TagKind TK, DeclContext *DC,
                                SourceLocation StartLoc, SourceLocation IdLoc,
                                SourceLocation StartLoc, SourceLocation IdLoc,
                                IdentifierInfo *Id, RecordDecl* PrevDecl) {
                                IdentifierInfo *Id, RecordDecl* PrevDecl) {
-  RecordDecl* R = new (C) RecordDecl(Record, TK, DC, StartLoc, IdLoc, Id,
-                                     PrevDecl);
+  RecordDecl* R = new (C, DC) RecordDecl(Record, TK, DC, StartLoc, IdLoc, Id,
+                                         PrevDecl);
   R->MayHaveOutOfDateDef = C.getLangOpts().Modules;
   R->MayHaveOutOfDateDef = C.getLangOpts().Modules;
 
 
   C.getTypeDeclType(R, PrevDecl);
   C.getTypeDeclType(R, PrevDecl);
@@ -3351,9 +3348,8 @@ RecordDecl *RecordDecl::Create(const ASTContext &C, TagKind TK, DeclContext *DC,
 }
 }
 
 
 RecordDecl *RecordDecl::CreateDeserialized(const ASTContext &C, unsigned ID) {
 RecordDecl *RecordDecl::CreateDeserialized(const ASTContext &C, unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(RecordDecl));
-  RecordDecl *R = new (Mem) RecordDecl(Record, TTK_Struct, 0, SourceLocation(),
-                                       SourceLocation(), 0, 0);
+  RecordDecl *R = new (C, ID) RecordDecl(Record, TTK_Struct, 0, SourceLocation(),
+                                         SourceLocation(), 0, 0);
   R->MayHaveOutOfDateDef = C.getLangOpts().Modules;
   R->MayHaveOutOfDateDef = C.getLangOpts().Modules;
   return R;
   return R;
 }
 }
@@ -3478,26 +3474,25 @@ SourceRange BlockDecl::getSourceRange() const {
 void TranslationUnitDecl::anchor() { }
 void TranslationUnitDecl::anchor() { }
 
 
 TranslationUnitDecl *TranslationUnitDecl::Create(ASTContext &C) {
 TranslationUnitDecl *TranslationUnitDecl::Create(ASTContext &C) {
-  return new (C) TranslationUnitDecl(C);
+  return new (C, (DeclContext*)0) TranslationUnitDecl(C);
 }
 }
 
 
 void LabelDecl::anchor() { }
 void LabelDecl::anchor() { }
 
 
 LabelDecl *LabelDecl::Create(ASTContext &C, DeclContext *DC,
 LabelDecl *LabelDecl::Create(ASTContext &C, DeclContext *DC,
                              SourceLocation IdentL, IdentifierInfo *II) {
                              SourceLocation IdentL, IdentifierInfo *II) {
-  return new (C) LabelDecl(DC, IdentL, II, 0, IdentL);
+  return new (C, DC) LabelDecl(DC, IdentL, II, 0, IdentL);
 }
 }
 
 
 LabelDecl *LabelDecl::Create(ASTContext &C, DeclContext *DC,
 LabelDecl *LabelDecl::Create(ASTContext &C, DeclContext *DC,
                              SourceLocation IdentL, IdentifierInfo *II,
                              SourceLocation IdentL, IdentifierInfo *II,
                              SourceLocation GnuLabelL) {
                              SourceLocation GnuLabelL) {
   assert(GnuLabelL != IdentL && "Use this only for GNU local labels");
   assert(GnuLabelL != IdentL && "Use this only for GNU local labels");
-  return new (C) LabelDecl(DC, IdentL, II, 0, GnuLabelL);
+  return new (C, DC) LabelDecl(DC, IdentL, II, 0, GnuLabelL);
 }
 }
 
 
 LabelDecl *LabelDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
 LabelDecl *LabelDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(LabelDecl));
-  return new (Mem) LabelDecl(0, SourceLocation(), 0, 0, SourceLocation());
+  return new (C, ID) LabelDecl(0, SourceLocation(), 0, 0, SourceLocation());
 }
 }
 
 
 void ValueDecl::anchor() { }
 void ValueDecl::anchor() { }
@@ -3516,13 +3511,12 @@ ImplicitParamDecl *ImplicitParamDecl::Create(ASTContext &C, DeclContext *DC,
                                              SourceLocation IdLoc,
                                              SourceLocation IdLoc,
                                              IdentifierInfo *Id,
                                              IdentifierInfo *Id,
                                              QualType Type) {
                                              QualType Type) {
-  return new (C) ImplicitParamDecl(DC, IdLoc, Id, Type);
+  return new (C, DC) ImplicitParamDecl(DC, IdLoc, Id, Type);
 }
 }
 
 
-ImplicitParamDecl *ImplicitParamDecl::CreateDeserialized(ASTContext &C, 
+ImplicitParamDecl *ImplicitParamDecl::CreateDeserialized(ASTContext &C,
                                                          unsigned ID) {
                                                          unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ImplicitParamDecl));
-  return new (Mem) ImplicitParamDecl(0, SourceLocation(), 0, QualType());
+  return new (C, ID) ImplicitParamDecl(0, SourceLocation(), 0, QualType());
 }
 }
 
 
 FunctionDecl *FunctionDecl::Create(ASTContext &C, DeclContext *DC,
 FunctionDecl *FunctionDecl::Create(ASTContext &C, DeclContext *DC,
@@ -3530,66 +3524,53 @@ FunctionDecl *FunctionDecl::Create(ASTContext &C, DeclContext *DC,
                                    const DeclarationNameInfo &NameInfo,
                                    const DeclarationNameInfo &NameInfo,
                                    QualType T, TypeSourceInfo *TInfo,
                                    QualType T, TypeSourceInfo *TInfo,
                                    StorageClass SC,
                                    StorageClass SC,
-                                   bool isInlineSpecified, 
+                                   bool isInlineSpecified,
                                    bool hasWrittenPrototype,
                                    bool hasWrittenPrototype,
                                    bool isConstexprSpecified) {
                                    bool isConstexprSpecified) {
-  FunctionDecl *New = new (C) FunctionDecl(Function, DC, StartLoc, NameInfo,
-                                           T, TInfo, SC,
-                                           isInlineSpecified,
-                                           isConstexprSpecified);
+  FunctionDecl *New =
+      new (C, DC) FunctionDecl(Function, DC, StartLoc, NameInfo, T, TInfo, SC,
+                               isInlineSpecified, isConstexprSpecified);
   New->HasWrittenPrototype = hasWrittenPrototype;
   New->HasWrittenPrototype = hasWrittenPrototype;
   return New;
   return New;
 }
 }
 
 
 FunctionDecl *FunctionDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
 FunctionDecl *FunctionDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(FunctionDecl));
-  return new (Mem) FunctionDecl(Function, 0, SourceLocation(), 
-                                DeclarationNameInfo(), QualType(), 0,
-                                SC_None, false, false);
+  return new (C, ID) FunctionDecl(Function, 0, SourceLocation(),
+                                  DeclarationNameInfo(), QualType(), 0,
+                                  SC_None, false, false);
 }
 }
 
 
 BlockDecl *BlockDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L) {
 BlockDecl *BlockDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L) {
-  return new (C) BlockDecl(DC, L);
+  return new (C, DC) BlockDecl(DC, L);
 }
 }
 
 
 BlockDecl *BlockDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
 BlockDecl *BlockDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(BlockDecl));
-  return new (Mem) BlockDecl(0, SourceLocation());
-}
-
-MSPropertyDecl *MSPropertyDecl::CreateDeserialized(ASTContext &C,
-                                                   unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(MSPropertyDecl));
-  return new (Mem) MSPropertyDecl(0, SourceLocation(), DeclarationName(),
-                                  QualType(), 0, SourceLocation(),
-                                  0, 0);
+  return new (C, ID) BlockDecl(0, SourceLocation());
 }
 }
 
 
 CapturedDecl *CapturedDecl::Create(ASTContext &C, DeclContext *DC,
 CapturedDecl *CapturedDecl::Create(ASTContext &C, DeclContext *DC,
                                    unsigned NumParams) {
                                    unsigned NumParams) {
-  unsigned Size = sizeof(CapturedDecl) + NumParams * sizeof(ImplicitParamDecl*);
-  return new (C.Allocate(Size)) CapturedDecl(DC, NumParams);
+  return new (C, DC, NumParams * sizeof(ImplicitParamDecl *))
+      CapturedDecl(DC, NumParams);
 }
 }
 
 
 CapturedDecl *CapturedDecl::CreateDeserialized(ASTContext &C, unsigned ID,
 CapturedDecl *CapturedDecl::CreateDeserialized(ASTContext &C, unsigned ID,
-                                   unsigned NumParams) {
-  unsigned Size = sizeof(CapturedDecl) + NumParams * sizeof(ImplicitParamDecl*);
-  void *Mem = AllocateDeserializedDecl(C, ID, Size);
-  return new (Mem) CapturedDecl(0, NumParams);
+                                               unsigned NumParams) {
+  return new (C, ID, NumParams * sizeof(ImplicitParamDecl *))
+      CapturedDecl(0, NumParams);
 }
 }
 
 
 EnumConstantDecl *EnumConstantDecl::Create(ASTContext &C, EnumDecl *CD,
 EnumConstantDecl *EnumConstantDecl::Create(ASTContext &C, EnumDecl *CD,
                                            SourceLocation L,
                                            SourceLocation L,
                                            IdentifierInfo *Id, QualType T,
                                            IdentifierInfo *Id, QualType T,
                                            Expr *E, const llvm::APSInt &V) {
                                            Expr *E, const llvm::APSInt &V) {
-  return new (C) EnumConstantDecl(CD, L, Id, T, E, V);
+  return new (C, CD) EnumConstantDecl(CD, L, Id, T, E, V);
 }
 }
 
 
 EnumConstantDecl *
 EnumConstantDecl *
 EnumConstantDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
 EnumConstantDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(EnumConstantDecl));
-  return new (Mem) EnumConstantDecl(0, SourceLocation(), 0, QualType(), 0, 
-                                    llvm::APSInt());
+  return new (C, ID) EnumConstantDecl(0, SourceLocation(), 0, QualType(), 0,
+                                      llvm::APSInt());
 }
 }
 
 
 void IndirectFieldDecl::anchor() { }
 void IndirectFieldDecl::anchor() { }
@@ -3598,14 +3579,13 @@ IndirectFieldDecl *
 IndirectFieldDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L,
 IndirectFieldDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L,
                           IdentifierInfo *Id, QualType T, NamedDecl **CH,
                           IdentifierInfo *Id, QualType T, NamedDecl **CH,
                           unsigned CHS) {
                           unsigned CHS) {
-  return new (C) IndirectFieldDecl(DC, L, Id, T, CH, CHS);
+  return new (C, DC) IndirectFieldDecl(DC, L, Id, T, CH, CHS);
 }
 }
 
 
 IndirectFieldDecl *IndirectFieldDecl::CreateDeserialized(ASTContext &C,
 IndirectFieldDecl *IndirectFieldDecl::CreateDeserialized(ASTContext &C,
                                                          unsigned ID) {
                                                          unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(IndirectFieldDecl));
-  return new (Mem) IndirectFieldDecl(0, SourceLocation(), DeclarationName(),
-                                     QualType(), 0, 0);
+  return new (C, ID) IndirectFieldDecl(0, SourceLocation(), DeclarationName(),
+                                       QualType(), 0, 0);
 }
 }
 
 
 SourceRange EnumConstantDecl::getSourceRange() const {
 SourceRange EnumConstantDecl::getSourceRange() const {
@@ -3620,26 +3600,24 @@ void TypeDecl::anchor() { }
 TypedefDecl *TypedefDecl::Create(ASTContext &C, DeclContext *DC,
 TypedefDecl *TypedefDecl::Create(ASTContext &C, DeclContext *DC,
                                  SourceLocation StartLoc, SourceLocation IdLoc,
                                  SourceLocation StartLoc, SourceLocation IdLoc,
                                  IdentifierInfo *Id, TypeSourceInfo *TInfo) {
                                  IdentifierInfo *Id, TypeSourceInfo *TInfo) {
-  return new (C) TypedefDecl(DC, StartLoc, IdLoc, Id, TInfo);
+  return new (C, DC) TypedefDecl(DC, StartLoc, IdLoc, Id, TInfo);
 }
 }
 
 
 void TypedefNameDecl::anchor() { }
 void TypedefNameDecl::anchor() { }
 
 
 TypedefDecl *TypedefDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
 TypedefDecl *TypedefDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(TypedefDecl));
-  return new (Mem) TypedefDecl(0, SourceLocation(), SourceLocation(), 0, 0);
+  return new (C, ID) TypedefDecl(0, SourceLocation(), SourceLocation(), 0, 0);
 }
 }
 
 
 TypeAliasDecl *TypeAliasDecl::Create(ASTContext &C, DeclContext *DC,
 TypeAliasDecl *TypeAliasDecl::Create(ASTContext &C, DeclContext *DC,
                                      SourceLocation StartLoc,
                                      SourceLocation StartLoc,
                                      SourceLocation IdLoc, IdentifierInfo *Id,
                                      SourceLocation IdLoc, IdentifierInfo *Id,
                                      TypeSourceInfo *TInfo) {
                                      TypeSourceInfo *TInfo) {
-  return new (C) TypeAliasDecl(DC, StartLoc, IdLoc, Id, TInfo);
+  return new (C, DC) TypeAliasDecl(DC, StartLoc, IdLoc, Id, TInfo);
 }
 }
 
 
 TypeAliasDecl *TypeAliasDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
 TypeAliasDecl *TypeAliasDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(TypeAliasDecl));
-  return new (Mem) TypeAliasDecl(0, SourceLocation(), SourceLocation(), 0, 0);
+  return new (C, ID) TypeAliasDecl(0, SourceLocation(), SourceLocation(), 0, 0);
 }
 }
 
 
 SourceRange TypedefDecl::getSourceRange() const {
 SourceRange TypedefDecl::getSourceRange() const {
@@ -3664,24 +3642,22 @@ FileScopeAsmDecl *FileScopeAsmDecl::Create(ASTContext &C, DeclContext *DC,
                                            StringLiteral *Str,
                                            StringLiteral *Str,
                                            SourceLocation AsmLoc,
                                            SourceLocation AsmLoc,
                                            SourceLocation RParenLoc) {
                                            SourceLocation RParenLoc) {
-  return new (C) FileScopeAsmDecl(DC, Str, AsmLoc, RParenLoc);
+  return new (C, DC) FileScopeAsmDecl(DC, Str, AsmLoc, RParenLoc);
 }
 }
 
 
-FileScopeAsmDecl *FileScopeAsmDecl::CreateDeserialized(ASTContext &C, 
+FileScopeAsmDecl *FileScopeAsmDecl::CreateDeserialized(ASTContext &C,
                                                        unsigned ID) {
                                                        unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(FileScopeAsmDecl));
-  return new (Mem) FileScopeAsmDecl(0, 0, SourceLocation(), SourceLocation());
+  return new (C, ID) FileScopeAsmDecl(0, 0, SourceLocation(), SourceLocation());
 }
 }
 
 
 void EmptyDecl::anchor() {}
 void EmptyDecl::anchor() {}
 
 
 EmptyDecl *EmptyDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L) {
 EmptyDecl *EmptyDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation L) {
-  return new (C) EmptyDecl(DC, L);
+  return new (C, DC) EmptyDecl(DC, L);
 }
 }
 
 
 EmptyDecl *EmptyDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
 EmptyDecl *EmptyDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(EmptyDecl));
-  return new (Mem) EmptyDecl(0, SourceLocation());
+  return new (C, ID) EmptyDecl(0, SourceLocation());
 }
 }
 
 
 //===----------------------------------------------------------------------===//
 //===----------------------------------------------------------------------===//
@@ -3719,30 +3695,28 @@ ImportDecl::ImportDecl(DeclContext *DC, SourceLocation StartLoc,
   *reinterpret_cast<SourceLocation *>(this + 1) = EndLoc;
   *reinterpret_cast<SourceLocation *>(this + 1) = EndLoc;
 }
 }
 
 
-ImportDecl *ImportDecl::Create(ASTContext &C, DeclContext *DC, 
+ImportDecl *ImportDecl::Create(ASTContext &C, DeclContext *DC,
                                SourceLocation StartLoc, Module *Imported,
                                SourceLocation StartLoc, Module *Imported,
                                ArrayRef<SourceLocation> IdentifierLocs) {
                                ArrayRef<SourceLocation> IdentifierLocs) {
-  void *Mem = C.Allocate(sizeof(ImportDecl) + 
-                         IdentifierLocs.size() * sizeof(SourceLocation));
-  return new (Mem) ImportDecl(DC, StartLoc, Imported, IdentifierLocs);
+  return new (C, DC, IdentifierLocs.size() * sizeof(SourceLocation))
+      ImportDecl(DC, StartLoc, Imported, IdentifierLocs);
 }
 }
 
 
-ImportDecl *ImportDecl::CreateImplicit(ASTContext &C, DeclContext *DC, 
+ImportDecl *ImportDecl::CreateImplicit(ASTContext &C, DeclContext *DC,
                                        SourceLocation StartLoc,
                                        SourceLocation StartLoc,
-                                       Module *Imported, 
+                                       Module *Imported,
                                        SourceLocation EndLoc) {
                                        SourceLocation EndLoc) {
-  void *Mem = C.Allocate(sizeof(ImportDecl) + sizeof(SourceLocation));
-  ImportDecl *Import = new (Mem) ImportDecl(DC, StartLoc, Imported, EndLoc);
+  ImportDecl *Import =
+      new (C, DC, sizeof(SourceLocation)) ImportDecl(DC, StartLoc,
+                                                     Imported, EndLoc);
   Import->setImplicit();
   Import->setImplicit();
   return Import;
   return Import;
 }
 }
 
 
 ImportDecl *ImportDecl::CreateDeserialized(ASTContext &C, unsigned ID,
 ImportDecl *ImportDecl::CreateDeserialized(ASTContext &C, unsigned ID,
                                            unsigned NumLocations) {
                                            unsigned NumLocations) {
-  void *Mem = AllocateDeserializedDecl(C, ID, 
-                                       (sizeof(ImportDecl) + 
-                                        NumLocations * sizeof(SourceLocation)));
-  return new (Mem) ImportDecl(EmptyShell());  
+  return new (C, ID, NumLocations * sizeof(SourceLocation))
+      ImportDecl(EmptyShell());
 }
 }
 
 
 ArrayRef<SourceLocation> ImportDecl::getIdentifierLocs() const {
 ArrayRef<SourceLocation> ImportDecl::getIdentifierLocs() const {

+ 13 - 8
lib/AST/DeclBase.cpp

@@ -45,25 +45,30 @@ void Decl::updateOutOfDate(IdentifierInfo &II) const {
   getASTContext().getExternalSource()->updateOutOfDateIdentifier(II);
   getASTContext().getExternalSource()->updateOutOfDateIdentifier(II);
 }
 }
 
 
-void *Decl::AllocateDeserializedDecl(const ASTContext &Context, 
-                                     unsigned ID,
-                                     unsigned Size) {
+void *Decl::operator new(std::size_t Size, const ASTContext &Context,
+                         unsigned ID, std::size_t Extra) {
   // Allocate an extra 8 bytes worth of storage, which ensures that the
   // Allocate an extra 8 bytes worth of storage, which ensures that the
   // resulting pointer will still be 8-byte aligned. 
   // resulting pointer will still be 8-byte aligned. 
-  void *Start = Context.Allocate(Size + 8);
+  void *Start = Context.Allocate(Size + Extra + 8);
   void *Result = (char*)Start + 8;
   void *Result = (char*)Start + 8;
-  
+
   unsigned *PrefixPtr = (unsigned *)Result - 2;
   unsigned *PrefixPtr = (unsigned *)Result - 2;
-  
+
   // Zero out the first 4 bytes; this is used to store the owning module ID.
   // Zero out the first 4 bytes; this is used to store the owning module ID.
   PrefixPtr[0] = 0;
   PrefixPtr[0] = 0;
-  
+
   // Store the global declaration ID in the second 4 bytes.
   // Store the global declaration ID in the second 4 bytes.
   PrefixPtr[1] = ID;
   PrefixPtr[1] = ID;
-  
+
   return Result;
   return Result;
 }
 }
 
 
+void *Decl::operator new(std::size_t Size, const ASTContext &Ctx,
+                         DeclContext *Parent, std::size_t Extra) {
+  assert(!Parent || &Parent->getParentASTContext() == &Ctx);
+  return ::operator new(Size + Extra, Ctx);
+}
+
 Module *Decl::getOwningModuleSlow() const {
 Module *Decl::getOwningModuleSlow() const {
   assert(isFromASTFile() && "Not from AST file?");
   assert(isFromASTFile() && "Not from AST file?");
   return getASTContext().getExternalSource()->getModule(getOwningModuleID());
   return getASTContext().getExternalSource()->getModule(getOwningModuleID());

+ 83 - 86
lib/AST/DeclCXX.cpp

@@ -31,8 +31,7 @@ using namespace clang;
 void AccessSpecDecl::anchor() { }
 void AccessSpecDecl::anchor() { }
 
 
 AccessSpecDecl *AccessSpecDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
 AccessSpecDecl *AccessSpecDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(AccessSpecDecl));
-  return new (Mem) AccessSpecDecl(EmptyShell());
+  return new (C, ID) AccessSpecDecl(EmptyShell());
 }
 }
 
 
 void LazyASTUnresolvedSet::getFromExternalSource(ASTContext &C) const {
 void LazyASTUnresolvedSet::getFromExternalSource(ASTContext &C) const {
@@ -95,8 +94,8 @@ CXXRecordDecl *CXXRecordDecl::Create(const ASTContext &C, TagKind TK,
                                      SourceLocation IdLoc, IdentifierInfo *Id,
                                      SourceLocation IdLoc, IdentifierInfo *Id,
                                      CXXRecordDecl* PrevDecl,
                                      CXXRecordDecl* PrevDecl,
                                      bool DelayTypeCreation) {
                                      bool DelayTypeCreation) {
-  CXXRecordDecl* R = new (C) CXXRecordDecl(CXXRecord, TK, DC, StartLoc, IdLoc,
-                                           Id, PrevDecl);
+  CXXRecordDecl *R = new (C, DC) CXXRecordDecl(CXXRecord, TK, DC, StartLoc,
+                                               IdLoc, Id, PrevDecl);
   R->MayHaveOutOfDateDef = C.getLangOpts().Modules;
   R->MayHaveOutOfDateDef = C.getLangOpts().Modules;
 
 
   // FIXME: DelayTypeCreation seems like such a hack
   // FIXME: DelayTypeCreation seems like such a hack
@@ -109,8 +108,8 @@ CXXRecordDecl *CXXRecordDecl::CreateLambda(const ASTContext &C, DeclContext *DC,
                                            TypeSourceInfo *Info, SourceLocation Loc,
                                            TypeSourceInfo *Info, SourceLocation Loc,
                                            bool Dependent, bool IsGeneric, 
                                            bool Dependent, bool IsGeneric, 
                                            LambdaCaptureDefault CaptureDefault) {
                                            LambdaCaptureDefault CaptureDefault) {
-  CXXRecordDecl* R = new (C) CXXRecordDecl(CXXRecord, TTK_Class, DC, Loc, Loc,
-                                           0, 0);
+  CXXRecordDecl *R =
+      new (C, DC) CXXRecordDecl(CXXRecord, TTK_Class, DC, Loc, Loc, 0, 0);
   R->IsBeingDefined = true;
   R->IsBeingDefined = true;
   R->DefinitionData = new (C) struct LambdaDefinitionData(R, Info, 
   R->DefinitionData = new (C) struct LambdaDefinitionData(R, Info, 
                                                           Dependent, 
                                                           Dependent, 
@@ -124,10 +123,8 @@ CXXRecordDecl *CXXRecordDecl::CreateLambda(const ASTContext &C, DeclContext *DC,
 
 
 CXXRecordDecl *
 CXXRecordDecl *
 CXXRecordDecl::CreateDeserialized(const ASTContext &C, unsigned ID) {
 CXXRecordDecl::CreateDeserialized(const ASTContext &C, unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(CXXRecordDecl));
-  CXXRecordDecl *R = new (Mem) CXXRecordDecl(CXXRecord, TTK_Struct, 0,
-                                             SourceLocation(), SourceLocation(),
-                                             0, 0);
+  CXXRecordDecl *R = new (C, ID) CXXRecordDecl(
+      CXXRecord, TTK_Struct, 0, SourceLocation(), SourceLocation(), 0, 0);
   R->MayHaveOutOfDateDef = false;
   R->MayHaveOutOfDateDef = false;
   return R;
   return R;
 }
 }
@@ -1397,17 +1394,14 @@ CXXMethodDecl::Create(ASTContext &C, CXXRecordDecl *RD,
                       QualType T, TypeSourceInfo *TInfo,
                       QualType T, TypeSourceInfo *TInfo,
                       StorageClass SC, bool isInline,
                       StorageClass SC, bool isInline,
                       bool isConstexpr, SourceLocation EndLocation) {
                       bool isConstexpr, SourceLocation EndLocation) {
-  return new (C) CXXMethodDecl(CXXMethod, RD, StartLoc, NameInfo, T, TInfo,
-                               SC, isInline, isConstexpr,
-                               EndLocation);
+  return new (C, RD) CXXMethodDecl(CXXMethod, RD, StartLoc, NameInfo, T, TInfo,
+                                   SC, isInline, isConstexpr, EndLocation);
 }
 }
 
 
 CXXMethodDecl *CXXMethodDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
 CXXMethodDecl *CXXMethodDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(CXXMethodDecl));
-  return new (Mem) CXXMethodDecl(CXXMethod, 0, SourceLocation(), 
-                                 DeclarationNameInfo(), QualType(),
-                                 0, SC_None, false, false,
-                                 SourceLocation());
+  return new (C, ID) CXXMethodDecl(CXXMethod, 0, SourceLocation(),
+                                   DeclarationNameInfo(), QualType(), 0,
+                                   SC_None, false, false, SourceLocation());
 }
 }
 
 
 bool CXXMethodDecl::isUsualDeallocationFunction() const {
 bool CXXMethodDecl::isUsualDeallocationFunction() const {
@@ -1670,9 +1664,9 @@ void CXXConstructorDecl::anchor() { }
 
 
 CXXConstructorDecl *
 CXXConstructorDecl *
 CXXConstructorDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
 CXXConstructorDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(CXXConstructorDecl));
-  return new (Mem) CXXConstructorDecl(0, SourceLocation(),DeclarationNameInfo(),
-                                      QualType(), 0, false, false, false,false);
+  return new (C, ID) CXXConstructorDecl(0, SourceLocation(),
+                                        DeclarationNameInfo(), QualType(),
+                                        0, false, false, false, false);
 }
 }
 
 
 CXXConstructorDecl *
 CXXConstructorDecl *
@@ -1685,9 +1679,9 @@ CXXConstructorDecl::Create(ASTContext &C, CXXRecordDecl *RD,
   assert(NameInfo.getName().getNameKind()
   assert(NameInfo.getName().getNameKind()
          == DeclarationName::CXXConstructorName &&
          == DeclarationName::CXXConstructorName &&
          "Name must refer to a constructor");
          "Name must refer to a constructor");
-  return new (C) CXXConstructorDecl(RD, StartLoc, NameInfo, T, TInfo,
-                                    isExplicit, isInline, isImplicitlyDeclared,
-                                    isConstexpr);
+  return new (C, RD) CXXConstructorDecl(RD, StartLoc, NameInfo, T, TInfo,
+                                        isExplicit, isInline,
+                                        isImplicitlyDeclared, isConstexpr);
 }
 }
 
 
 CXXConstructorDecl *CXXConstructorDecl::getTargetConstructor() const {
 CXXConstructorDecl *CXXConstructorDecl::getTargetConstructor() const {
@@ -1820,9 +1814,8 @@ void CXXDestructorDecl::anchor() { }
 
 
 CXXDestructorDecl *
 CXXDestructorDecl *
 CXXDestructorDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
 CXXDestructorDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(CXXDestructorDecl));
-  return new (Mem) CXXDestructorDecl(0, SourceLocation(), DeclarationNameInfo(),
-                                   QualType(), 0, false, false);
+  return new (C, ID) CXXDestructorDecl(
+      0, SourceLocation(), DeclarationNameInfo(), QualType(), 0, false, false);
 }
 }
 
 
 CXXDestructorDecl *
 CXXDestructorDecl *
@@ -1834,18 +1827,18 @@ CXXDestructorDecl::Create(ASTContext &C, CXXRecordDecl *RD,
   assert(NameInfo.getName().getNameKind()
   assert(NameInfo.getName().getNameKind()
          == DeclarationName::CXXDestructorName &&
          == DeclarationName::CXXDestructorName &&
          "Name must refer to a destructor");
          "Name must refer to a destructor");
-  return new (C) CXXDestructorDecl(RD, StartLoc, NameInfo, T, TInfo, isInline,
-                                   isImplicitlyDeclared);
+  return new (C, RD) CXXDestructorDecl(RD, StartLoc, NameInfo, T, TInfo,
+                                       isInline, isImplicitlyDeclared);
 }
 }
 
 
 void CXXConversionDecl::anchor() { }
 void CXXConversionDecl::anchor() { }
 
 
 CXXConversionDecl *
 CXXConversionDecl *
 CXXConversionDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
 CXXConversionDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(CXXConversionDecl));
-  return new (Mem) CXXConversionDecl(0, SourceLocation(), DeclarationNameInfo(),
-                                     QualType(), 0, false, false, false,
-                                     SourceLocation());
+  return new (C, ID) CXXConversionDecl(0, SourceLocation(),
+                                       DeclarationNameInfo(), QualType(),
+                                       0, false, false, false,
+                                       SourceLocation());
 }
 }
 
 
 CXXConversionDecl *
 CXXConversionDecl *
@@ -1858,9 +1851,9 @@ CXXConversionDecl::Create(ASTContext &C, CXXRecordDecl *RD,
   assert(NameInfo.getName().getNameKind()
   assert(NameInfo.getName().getNameKind()
          == DeclarationName::CXXConversionFunctionName &&
          == DeclarationName::CXXConversionFunctionName &&
          "Name must refer to a conversion function");
          "Name must refer to a conversion function");
-  return new (C) CXXConversionDecl(RD, StartLoc, NameInfo, T, TInfo,
-                                   isInline, isExplicit, isConstexpr,
-                                   EndLocation);
+  return new (C, RD) CXXConversionDecl(RD, StartLoc, NameInfo, T, TInfo,
+                                       isInline, isExplicit, isConstexpr,
+                                       EndLocation);
 }
 }
 
 
 bool CXXConversionDecl::isLambdaToBlockPointerConversion() const {
 bool CXXConversionDecl::isLambdaToBlockPointerConversion() const {
@@ -1876,13 +1869,13 @@ LinkageSpecDecl *LinkageSpecDecl::Create(ASTContext &C,
                                          SourceLocation LangLoc,
                                          SourceLocation LangLoc,
                                          LanguageIDs Lang,
                                          LanguageIDs Lang,
                                          bool HasBraces) {
                                          bool HasBraces) {
-  return new (C) LinkageSpecDecl(DC, ExternLoc, LangLoc, Lang, HasBraces);
+  return new (C, DC) LinkageSpecDecl(DC, ExternLoc, LangLoc, Lang, HasBraces);
 }
 }
 
 
-LinkageSpecDecl *LinkageSpecDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(LinkageSpecDecl));
-  return new (Mem) LinkageSpecDecl(0, SourceLocation(), SourceLocation(),
-                                   lang_c, false);
+LinkageSpecDecl *LinkageSpecDecl::CreateDeserialized(ASTContext &C,
+                                                     unsigned ID) {
+  return new (C, ID) LinkageSpecDecl(0, SourceLocation(), SourceLocation(),
+                                     lang_c, false);
 }
 }
 
 
 void UsingDirectiveDecl::anchor() { }
 void UsingDirectiveDecl::anchor() { }
@@ -1896,16 +1889,15 @@ UsingDirectiveDecl *UsingDirectiveDecl::Create(ASTContext &C, DeclContext *DC,
                                                DeclContext *CommonAncestor) {
                                                DeclContext *CommonAncestor) {
   if (NamespaceDecl *NS = dyn_cast_or_null<NamespaceDecl>(Used))
   if (NamespaceDecl *NS = dyn_cast_or_null<NamespaceDecl>(Used))
     Used = NS->getOriginalNamespace();
     Used = NS->getOriginalNamespace();
-  return new (C) UsingDirectiveDecl(DC, L, NamespaceLoc, QualifierLoc,
-                                    IdentLoc, Used, CommonAncestor);
+  return new (C, DC) UsingDirectiveDecl(DC, L, NamespaceLoc, QualifierLoc,
+                                        IdentLoc, Used, CommonAncestor);
 }
 }
 
 
-UsingDirectiveDecl *
-UsingDirectiveDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(UsingDirectiveDecl));
-  return new (Mem) UsingDirectiveDecl(0, SourceLocation(), SourceLocation(),
-                                      NestedNameSpecifierLoc(),
-                                      SourceLocation(), 0, 0);
+UsingDirectiveDecl *UsingDirectiveDecl::CreateDeserialized(ASTContext &C,
+                                                           unsigned ID) {
+  return new (C, ID) UsingDirectiveDecl(0, SourceLocation(), SourceLocation(),
+                                        NestedNameSpecifierLoc(),
+                                        SourceLocation(), 0, 0);
 }
 }
 
 
 NamespaceDecl *UsingDirectiveDecl::getNominatedNamespace() {
 NamespaceDecl *UsingDirectiveDecl::getNominatedNamespace() {
@@ -1934,13 +1926,12 @@ NamespaceDecl *NamespaceDecl::Create(ASTContext &C, DeclContext *DC,
                                      bool Inline, SourceLocation StartLoc,
                                      bool Inline, SourceLocation StartLoc,
                                      SourceLocation IdLoc, IdentifierInfo *Id,
                                      SourceLocation IdLoc, IdentifierInfo *Id,
                                      NamespaceDecl *PrevDecl) {
                                      NamespaceDecl *PrevDecl) {
-  return new (C) NamespaceDecl(DC, Inline, StartLoc, IdLoc, Id, PrevDecl);
+  return new (C, DC) NamespaceDecl(DC, Inline, StartLoc, IdLoc, Id, PrevDecl);
 }
 }
 
 
 NamespaceDecl *NamespaceDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
 NamespaceDecl *NamespaceDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(NamespaceDecl));
-  return new (Mem) NamespaceDecl(0, false, SourceLocation(), SourceLocation(), 
-                                 0, 0);
+  return new (C, ID) NamespaceDecl(0, false, SourceLocation(), SourceLocation(),
+                                   0, 0);
 }
 }
 
 
 void NamespaceAliasDecl::anchor() { }
 void NamespaceAliasDecl::anchor() { }
@@ -1954,24 +1945,22 @@ NamespaceAliasDecl *NamespaceAliasDecl::Create(ASTContext &C, DeclContext *DC,
                                                NamedDecl *Namespace) {
                                                NamedDecl *Namespace) {
   if (NamespaceDecl *NS = dyn_cast_or_null<NamespaceDecl>(Namespace))
   if (NamespaceDecl *NS = dyn_cast_or_null<NamespaceDecl>(Namespace))
     Namespace = NS->getOriginalNamespace();
     Namespace = NS->getOriginalNamespace();
-  return new (C) NamespaceAliasDecl(DC, UsingLoc, AliasLoc, Alias, 
-                                    QualifierLoc, IdentLoc, Namespace);
+  return new (C, DC) NamespaceAliasDecl(DC, UsingLoc, AliasLoc, Alias,
+                                        QualifierLoc, IdentLoc, Namespace);
 }
 }
 
 
 NamespaceAliasDecl *
 NamespaceAliasDecl *
 NamespaceAliasDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
 NamespaceAliasDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(NamespaceAliasDecl));
-  return new (Mem) NamespaceAliasDecl(0, SourceLocation(), SourceLocation(), 0,
-                                      NestedNameSpecifierLoc(), 
-                                      SourceLocation(), 0);
+  return new (C, ID) NamespaceAliasDecl(0, SourceLocation(), SourceLocation(),
+                                        0, NestedNameSpecifierLoc(),
+                                        SourceLocation(), 0);
 }
 }
 
 
 void UsingShadowDecl::anchor() { }
 void UsingShadowDecl::anchor() { }
 
 
 UsingShadowDecl *
 UsingShadowDecl *
 UsingShadowDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
 UsingShadowDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(UsingShadowDecl));
-  return new (Mem) UsingShadowDecl(0, SourceLocation(), 0, 0);
+  return new (C, ID) UsingShadowDecl(0, SourceLocation(), 0, 0);
 }
 }
 
 
 UsingDecl *UsingShadowDecl::getUsingDecl() const {
 UsingDecl *UsingShadowDecl::getUsingDecl() const {
@@ -2019,13 +2008,12 @@ UsingDecl *UsingDecl::Create(ASTContext &C, DeclContext *DC, SourceLocation UL,
                              NestedNameSpecifierLoc QualifierLoc,
                              NestedNameSpecifierLoc QualifierLoc,
                              const DeclarationNameInfo &NameInfo,
                              const DeclarationNameInfo &NameInfo,
                              bool HasTypename) {
                              bool HasTypename) {
-  return new (C) UsingDecl(DC, UL, QualifierLoc, NameInfo, HasTypename);
+  return new (C, DC) UsingDecl(DC, UL, QualifierLoc, NameInfo, HasTypename);
 }
 }
 
 
 UsingDecl *UsingDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
 UsingDecl *UsingDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(UsingDecl));
-  return new (Mem) UsingDecl(0, SourceLocation(), NestedNameSpecifierLoc(),
-                             DeclarationNameInfo(), false);
+  return new (C, ID) UsingDecl(0, SourceLocation(), NestedNameSpecifierLoc(),
+                               DeclarationNameInfo(), false);
 }
 }
 
 
 SourceRange UsingDecl::getSourceRange() const {
 SourceRange UsingDecl::getSourceRange() const {
@@ -2041,15 +2029,14 @@ UnresolvedUsingValueDecl::Create(ASTContext &C, DeclContext *DC,
                                  SourceLocation UsingLoc,
                                  SourceLocation UsingLoc,
                                  NestedNameSpecifierLoc QualifierLoc,
                                  NestedNameSpecifierLoc QualifierLoc,
                                  const DeclarationNameInfo &NameInfo) {
                                  const DeclarationNameInfo &NameInfo) {
-  return new (C) UnresolvedUsingValueDecl(DC, C.DependentTy, UsingLoc,
-                                          QualifierLoc, NameInfo);
+  return new (C, DC) UnresolvedUsingValueDecl(DC, C.DependentTy, UsingLoc,
+                                              QualifierLoc, NameInfo);
 }
 }
 
 
 UnresolvedUsingValueDecl *
 UnresolvedUsingValueDecl *
 UnresolvedUsingValueDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
 UnresolvedUsingValueDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(UnresolvedUsingValueDecl));
-  return new (Mem) UnresolvedUsingValueDecl(0, QualType(), SourceLocation(),
-                                            NestedNameSpecifierLoc(),
+  return new (C, ID) UnresolvedUsingValueDecl(0, QualType(), SourceLocation(),
+                                              NestedNameSpecifierLoc(),
                                             DeclarationNameInfo());
                                             DeclarationNameInfo());
 }
 }
 
 
@@ -2068,20 +2055,16 @@ UnresolvedUsingTypenameDecl::Create(ASTContext &C, DeclContext *DC,
                                     NestedNameSpecifierLoc QualifierLoc,
                                     NestedNameSpecifierLoc QualifierLoc,
                                     SourceLocation TargetNameLoc,
                                     SourceLocation TargetNameLoc,
                                     DeclarationName TargetName) {
                                     DeclarationName TargetName) {
-  return new (C) UnresolvedUsingTypenameDecl(DC, UsingLoc, TypenameLoc,
-                                             QualifierLoc, TargetNameLoc,
-                                             TargetName.getAsIdentifierInfo());
+  return new (C, DC) UnresolvedUsingTypenameDecl(
+      DC, UsingLoc, TypenameLoc, QualifierLoc, TargetNameLoc,
+      TargetName.getAsIdentifierInfo());
 }
 }
 
 
 UnresolvedUsingTypenameDecl *
 UnresolvedUsingTypenameDecl *
 UnresolvedUsingTypenameDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
 UnresolvedUsingTypenameDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, 
-                                       sizeof(UnresolvedUsingTypenameDecl));
-  return new (Mem) UnresolvedUsingTypenameDecl(0, SourceLocation(),
-                                               SourceLocation(),
-                                               NestedNameSpecifierLoc(),
-                                               SourceLocation(),
-                                               0);
+  return new (C, ID) UnresolvedUsingTypenameDecl(
+      0, SourceLocation(), SourceLocation(), NestedNameSpecifierLoc(),
+      SourceLocation(), 0);
 }
 }
 
 
 void StaticAssertDecl::anchor() { }
 void StaticAssertDecl::anchor() { }
@@ -2092,15 +2075,29 @@ StaticAssertDecl *StaticAssertDecl::Create(ASTContext &C, DeclContext *DC,
                                            StringLiteral *Message,
                                            StringLiteral *Message,
                                            SourceLocation RParenLoc,
                                            SourceLocation RParenLoc,
                                            bool Failed) {
                                            bool Failed) {
-  return new (C) StaticAssertDecl(DC, StaticAssertLoc, AssertExpr, Message,
-                                  RParenLoc, Failed);
+  return new (C, DC) StaticAssertDecl(DC, StaticAssertLoc, AssertExpr, Message,
+                                      RParenLoc, Failed);
 }
 }
 
 
-StaticAssertDecl *StaticAssertDecl::CreateDeserialized(ASTContext &C, 
+StaticAssertDecl *StaticAssertDecl::CreateDeserialized(ASTContext &C,
                                                        unsigned ID) {
                                                        unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(StaticAssertDecl));
-  return new (Mem) StaticAssertDecl(0, SourceLocation(), 0, 0,
-                                    SourceLocation(), false);
+  return new (C, ID) StaticAssertDecl(0, SourceLocation(), 0, 0,
+                                      SourceLocation(), false);
+}
+
+MSPropertyDecl *MSPropertyDecl::Create(ASTContext &C, DeclContext *DC,
+                                       SourceLocation L, DeclarationName N,
+                                       QualType T, TypeSourceInfo *TInfo,
+                                       SourceLocation StartL,
+                                       IdentifierInfo *Getter,
+                                       IdentifierInfo *Setter) {
+  return new (C, DC) MSPropertyDecl(DC, L, N, T, TInfo, StartL, Getter, Setter);
+}
+
+MSPropertyDecl *MSPropertyDecl::CreateDeserialized(ASTContext &C,
+                                                   unsigned ID) {
+  return new (C, ID) MSPropertyDecl(0, SourceLocation(), DeclarationName(),
+                                    QualType(), 0, SourceLocation(), 0, 0);
 }
 }
 
 
 static const char *getAccessName(AccessSpecifier AS) {
 static const char *getAccessName(AccessSpecifier AS) {

+ 5 - 9
lib/AST/DeclFriend.cpp

@@ -46,21 +46,17 @@ FriendDecl *FriendDecl::Create(ASTContext &C, DeclContext *DC,
   }
   }
 #endif
 #endif
 
 
-  std::size_t Size = sizeof(FriendDecl)
-    + FriendTypeTPLists.size() * sizeof(TemplateParameterList*);
-  void *Mem = C.Allocate(Size);
-  FriendDecl *FD = new (Mem) FriendDecl(DC, L, Friend, FriendL,
-                                        FriendTypeTPLists);
+  std::size_t Extra = FriendTypeTPLists.size() * sizeof(TemplateParameterList*);
+  FriendDecl *FD = new (C, DC, Extra) FriendDecl(DC, L, Friend, FriendL,
+                                                 FriendTypeTPLists);
   cast<CXXRecordDecl>(DC)->pushFriendDecl(FD);
   cast<CXXRecordDecl>(DC)->pushFriendDecl(FD);
   return FD;
   return FD;
 }
 }
 
 
 FriendDecl *FriendDecl::CreateDeserialized(ASTContext &C, unsigned ID,
 FriendDecl *FriendDecl::CreateDeserialized(ASTContext &C, unsigned ID,
                                            unsigned FriendTypeNumTPLists) {
                                            unsigned FriendTypeNumTPLists) {
-  std::size_t Size = sizeof(FriendDecl)
-    + FriendTypeNumTPLists * sizeof(TemplateParameterList*);
-  void *Mem = AllocateDeserializedDecl(C, ID, Size);
-  return new (Mem) FriendDecl(EmptyShell(), FriendTypeNumTPLists);
+  std::size_t Extra = FriendTypeNumTPLists * sizeof(TemplateParameterList*);
+  return new (C, ID, Extra) FriendDecl(EmptyShell(), FriendTypeNumTPLists);
 }
 }
 
 
 FriendDecl *CXXRecordDecl::getFirstFriend() const {
 FriendDecl *CXXRecordDecl::getFirstFriend() const {

+ 53 - 67
lib/AST/DeclObjC.cpp

@@ -563,18 +563,15 @@ ObjCMethodDecl *ObjCMethodDecl::Create(ASTContext &C,
                                        bool isDefined,
                                        bool isDefined,
                                        ImplementationControl impControl,
                                        ImplementationControl impControl,
                                        bool HasRelatedResultType) {
                                        bool HasRelatedResultType) {
-  return new (C) ObjCMethodDecl(beginLoc, endLoc,
-                                SelInfo, T, ResultTInfo, contextDecl,
-                                isInstance, isVariadic, isPropertyAccessor,
-                                isImplicitlyDeclared, isDefined,
-                                impControl,
-                                HasRelatedResultType);
+  return new (C, contextDecl) ObjCMethodDecl(
+      beginLoc, endLoc, SelInfo, T, ResultTInfo, contextDecl, isInstance,
+      isVariadic, isPropertyAccessor, isImplicitlyDeclared, isDefined,
+      impControl, HasRelatedResultType);
 }
 }
 
 
 ObjCMethodDecl *ObjCMethodDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
 ObjCMethodDecl *ObjCMethodDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ObjCMethodDecl));
-  return new (Mem) ObjCMethodDecl(SourceLocation(), SourceLocation(), 
-                                  Selector(), QualType(), 0, 0);
+  return new (C, ID) ObjCMethodDecl(SourceLocation(), SourceLocation(),
+                                    Selector(), QualType(), 0, 0);
 }
 }
 
 
 Stmt *ObjCMethodDecl::getBody() const {
 Stmt *ObjCMethodDecl::getBody() const {
@@ -1055,19 +1052,18 @@ ObjCInterfaceDecl *ObjCInterfaceDecl::Create(const ASTContext &C,
                                              ObjCInterfaceDecl *PrevDecl,
                                              ObjCInterfaceDecl *PrevDecl,
                                              SourceLocation ClassLoc,
                                              SourceLocation ClassLoc,
                                              bool isInternal){
                                              bool isInternal){
-  ObjCInterfaceDecl *Result = new (C) ObjCInterfaceDecl(DC, atLoc, Id, ClassLoc, 
-                                                        PrevDecl, isInternal);
+  ObjCInterfaceDecl *Result = new (C, DC)
+      ObjCInterfaceDecl(DC, atLoc, Id, ClassLoc, PrevDecl, isInternal);
   Result->Data.setInt(!C.getLangOpts().Modules);
   Result->Data.setInt(!C.getLangOpts().Modules);
   C.getObjCInterfaceType(Result, PrevDecl);
   C.getObjCInterfaceType(Result, PrevDecl);
   return Result;
   return Result;
 }
 }
 
 
-ObjCInterfaceDecl *ObjCInterfaceDecl::CreateDeserialized(ASTContext &C, 
+ObjCInterfaceDecl *ObjCInterfaceDecl::CreateDeserialized(ASTContext &C,
                                                          unsigned ID) {
                                                          unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ObjCInterfaceDecl));
-  ObjCInterfaceDecl *Result = new (Mem) ObjCInterfaceDecl(0, SourceLocation(),
-                                                          0, SourceLocation(),
-                                                          0, false);
+  ObjCInterfaceDecl *Result = new (C, ID) ObjCInterfaceDecl(0, SourceLocation(),
+                                                            0, SourceLocation(),
+                                                            0, false);
   Result->Data.setInt(!C.getLangOpts().Modules);
   Result->Data.setInt(!C.getLangOpts().Modules);
   return Result;
   return Result;
 }
 }
@@ -1353,14 +1349,14 @@ ObjCIvarDecl *ObjCIvarDecl::Create(ASTContext &C, ObjCContainerDecl *DC,
     ID->setIvarList(0);
     ID->setIvarList(0);
   }
   }
 
 
-  return new (C) ObjCIvarDecl(DC, StartLoc, IdLoc, Id, T, TInfo,
-                              ac, BW, synthesized, backingIvarReferencedInAccessor);
+  return new (C, DC) ObjCIvarDecl(DC, StartLoc, IdLoc, Id, T, TInfo, ac, BW,
+                                  synthesized, backingIvarReferencedInAccessor);
 }
 }
 
 
 ObjCIvarDecl *ObjCIvarDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
 ObjCIvarDecl *ObjCIvarDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ObjCIvarDecl));
-  return new (Mem) ObjCIvarDecl(0, SourceLocation(), SourceLocation(), 0,
-                                QualType(), 0, ObjCIvarDecl::None, 0, false, false);
+  return new (C, ID) ObjCIvarDecl(0, SourceLocation(), SourceLocation(), 0,
+                                  QualType(), 0, ObjCIvarDecl::None, 0, false,
+                                  false);
 }
 }
 
 
 const ObjCInterfaceDecl *ObjCIvarDecl::getContainingInterface() const {
 const ObjCInterfaceDecl *ObjCIvarDecl::getContainingInterface() const {
@@ -1397,14 +1393,13 @@ ObjCAtDefsFieldDecl
 *ObjCAtDefsFieldDecl::Create(ASTContext &C, DeclContext *DC,
 *ObjCAtDefsFieldDecl::Create(ASTContext &C, DeclContext *DC,
                              SourceLocation StartLoc,  SourceLocation IdLoc,
                              SourceLocation StartLoc,  SourceLocation IdLoc,
                              IdentifierInfo *Id, QualType T, Expr *BW) {
                              IdentifierInfo *Id, QualType T, Expr *BW) {
-  return new (C) ObjCAtDefsFieldDecl(DC, StartLoc, IdLoc, Id, T, BW);
+  return new (C, DC) ObjCAtDefsFieldDecl(DC, StartLoc, IdLoc, Id, T, BW);
 }
 }
 
 
-ObjCAtDefsFieldDecl *ObjCAtDefsFieldDecl::CreateDeserialized(ASTContext &C, 
+ObjCAtDefsFieldDecl *ObjCAtDefsFieldDecl::CreateDeserialized(ASTContext &C,
                                                              unsigned ID) {
                                                              unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ObjCAtDefsFieldDecl));
-  return new (Mem) ObjCAtDefsFieldDecl(0, SourceLocation(), SourceLocation(),
-                                       0, QualType(), 0);
+  return new (C, ID) ObjCAtDefsFieldDecl(0, SourceLocation(), SourceLocation(),
+                                         0, QualType(), 0);
 }
 }
 
 
 //===----------------------------------------------------------------------===//
 //===----------------------------------------------------------------------===//
@@ -1429,17 +1424,16 @@ ObjCProtocolDecl *ObjCProtocolDecl::Create(ASTContext &C, DeclContext *DC,
                                            SourceLocation nameLoc,
                                            SourceLocation nameLoc,
                                            SourceLocation atStartLoc,
                                            SourceLocation atStartLoc,
                                            ObjCProtocolDecl *PrevDecl) {
                                            ObjCProtocolDecl *PrevDecl) {
-  ObjCProtocolDecl *Result 
-    = new (C) ObjCProtocolDecl(DC, Id, nameLoc, atStartLoc, PrevDecl);
+  ObjCProtocolDecl *Result =
+      new (C, DC) ObjCProtocolDecl(DC, Id, nameLoc, atStartLoc, PrevDecl);
   Result->Data.setInt(!C.getLangOpts().Modules);
   Result->Data.setInt(!C.getLangOpts().Modules);
   return Result;
   return Result;
 }
 }
 
 
-ObjCProtocolDecl *ObjCProtocolDecl::CreateDeserialized(ASTContext &C, 
+ObjCProtocolDecl *ObjCProtocolDecl::CreateDeserialized(ASTContext &C,
                                                        unsigned ID) {
                                                        unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ObjCProtocolDecl));
-  ObjCProtocolDecl *Result = new (Mem) ObjCProtocolDecl(0, 0, SourceLocation(),
-                                                        SourceLocation(), 0);
+  ObjCProtocolDecl *Result =
+      new (C, ID) ObjCProtocolDecl(0, 0, SourceLocation(), SourceLocation(), 0);
   Result->Data.setInt(!C.getLangOpts().Modules);
   Result->Data.setInt(!C.getLangOpts().Modules);
   return Result;
   return Result;
 }
 }
@@ -1543,17 +1537,16 @@ void ObjCProtocolDecl::collectInheritedProtocolProperties(
 void ObjCCategoryDecl::anchor() { }
 void ObjCCategoryDecl::anchor() { }
 
 
 ObjCCategoryDecl *ObjCCategoryDecl::Create(ASTContext &C, DeclContext *DC,
 ObjCCategoryDecl *ObjCCategoryDecl::Create(ASTContext &C, DeclContext *DC,
-                                           SourceLocation AtLoc, 
+                                           SourceLocation AtLoc,
                                            SourceLocation ClassNameLoc,
                                            SourceLocation ClassNameLoc,
                                            SourceLocation CategoryNameLoc,
                                            SourceLocation CategoryNameLoc,
                                            IdentifierInfo *Id,
                                            IdentifierInfo *Id,
                                            ObjCInterfaceDecl *IDecl,
                                            ObjCInterfaceDecl *IDecl,
                                            SourceLocation IvarLBraceLoc,
                                            SourceLocation IvarLBraceLoc,
                                            SourceLocation IvarRBraceLoc) {
                                            SourceLocation IvarRBraceLoc) {
-  ObjCCategoryDecl *CatDecl = new (C) ObjCCategoryDecl(DC, AtLoc, ClassNameLoc,
-                                                       CategoryNameLoc, Id,
-                                                       IDecl,
-                                                       IvarLBraceLoc, IvarRBraceLoc);
+  ObjCCategoryDecl *CatDecl =
+      new (C, DC) ObjCCategoryDecl(DC, AtLoc, ClassNameLoc, CategoryNameLoc, Id,
+                                   IDecl, IvarLBraceLoc, IvarRBraceLoc);
   if (IDecl) {
   if (IDecl) {
     // Link this category into its class's category list.
     // Link this category into its class's category list.
     CatDecl->NextClassCategory = IDecl->getCategoryListRaw();
     CatDecl->NextClassCategory = IDecl->getCategoryListRaw();
@@ -1567,11 +1560,10 @@ ObjCCategoryDecl *ObjCCategoryDecl::Create(ASTContext &C, DeclContext *DC,
   return CatDecl;
   return CatDecl;
 }
 }
 
 
-ObjCCategoryDecl *ObjCCategoryDecl::CreateDeserialized(ASTContext &C, 
+ObjCCategoryDecl *ObjCCategoryDecl::CreateDeserialized(ASTContext &C,
                                                        unsigned ID) {
                                                        unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ObjCCategoryDecl));
-  return new (Mem) ObjCCategoryDecl(0, SourceLocation(), SourceLocation(),
-                                    SourceLocation(), 0, 0);
+  return new (C, ID) ObjCCategoryDecl(0, SourceLocation(), SourceLocation(),
+                                      SourceLocation(), 0, 0);
 }
 }
 
 
 ObjCCategoryImplDecl *ObjCCategoryDecl::getImplementation() const {
 ObjCCategoryImplDecl *ObjCCategoryDecl::getImplementation() const {
@@ -1599,15 +1591,14 @@ ObjCCategoryImplDecl::Create(ASTContext &C, DeclContext *DC,
                              SourceLocation CategoryNameLoc) {
                              SourceLocation CategoryNameLoc) {
   if (ClassInterface && ClassInterface->hasDefinition())
   if (ClassInterface && ClassInterface->hasDefinition())
     ClassInterface = ClassInterface->getDefinition();
     ClassInterface = ClassInterface->getDefinition();
-  return new (C) ObjCCategoryImplDecl(DC, Id, ClassInterface,
-                                      nameLoc, atStartLoc, CategoryNameLoc);
+  return new (C, DC) ObjCCategoryImplDecl(DC, Id, ClassInterface, nameLoc,
+                                          atStartLoc, CategoryNameLoc);
 }
 }
 
 
 ObjCCategoryImplDecl *ObjCCategoryImplDecl::CreateDeserialized(ASTContext &C, 
 ObjCCategoryImplDecl *ObjCCategoryImplDecl::CreateDeserialized(ASTContext &C, 
                                                                unsigned ID) {
                                                                unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ObjCCategoryImplDecl));
-  return new (Mem) ObjCCategoryImplDecl(0, 0, 0, SourceLocation(), 
-                                        SourceLocation(), SourceLocation());
+  return new (C, ID) ObjCCategoryImplDecl(0, 0, 0, SourceLocation(),
+                                          SourceLocation(), SourceLocation());
 }
 }
 
 
 ObjCCategoryDecl *ObjCCategoryImplDecl::getCategoryDecl() const {
 ObjCCategoryDecl *ObjCCategoryImplDecl::getCategoryDecl() const {
@@ -1695,16 +1686,15 @@ ObjCImplementationDecl::Create(ASTContext &C, DeclContext *DC,
                                SourceLocation IvarRBraceLoc) {
                                SourceLocation IvarRBraceLoc) {
   if (ClassInterface && ClassInterface->hasDefinition())
   if (ClassInterface && ClassInterface->hasDefinition())
     ClassInterface = ClassInterface->getDefinition();
     ClassInterface = ClassInterface->getDefinition();
-  return new (C) ObjCImplementationDecl(DC, ClassInterface, SuperDecl,
-                                        nameLoc, atStartLoc, superLoc,
-                                        IvarLBraceLoc, IvarRBraceLoc);
+  return new (C, DC) ObjCImplementationDecl(DC, ClassInterface, SuperDecl,
+                                            nameLoc, atStartLoc, superLoc,
+                                            IvarLBraceLoc, IvarRBraceLoc);
 }
 }
 
 
 ObjCImplementationDecl *
 ObjCImplementationDecl *
 ObjCImplementationDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
 ObjCImplementationDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ObjCImplementationDecl));
-  return new (Mem) ObjCImplementationDecl(0, 0, 0, SourceLocation(), 
-                                          SourceLocation());
+  return new (C, ID) ObjCImplementationDecl(0, 0, 0, SourceLocation(),
+                                            SourceLocation());
 }
 }
 
 
 void ObjCImplementationDecl::setIvarInitializers(ASTContext &C,
 void ObjCImplementationDecl::setIvarInitializers(ASTContext &C,
@@ -1737,13 +1727,12 @@ ObjCCompatibleAliasDecl::Create(ASTContext &C, DeclContext *DC,
                                 SourceLocation L,
                                 SourceLocation L,
                                 IdentifierInfo *Id,
                                 IdentifierInfo *Id,
                                 ObjCInterfaceDecl* AliasedClass) {
                                 ObjCInterfaceDecl* AliasedClass) {
-  return new (C) ObjCCompatibleAliasDecl(DC, L, Id, AliasedClass);
+  return new (C, DC) ObjCCompatibleAliasDecl(DC, L, Id, AliasedClass);
 }
 }
 
 
 ObjCCompatibleAliasDecl *
 ObjCCompatibleAliasDecl *
 ObjCCompatibleAliasDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
 ObjCCompatibleAliasDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ObjCCompatibleAliasDecl));
-  return new (Mem) ObjCCompatibleAliasDecl(0, SourceLocation(), 0, 0);
+  return new (C, ID) ObjCCompatibleAliasDecl(0, SourceLocation(), 0, 0);
 }
 }
 
 
 //===----------------------------------------------------------------------===//
 //===----------------------------------------------------------------------===//
@@ -1759,15 +1748,13 @@ ObjCPropertyDecl *ObjCPropertyDecl::Create(ASTContext &C, DeclContext *DC,
                                            SourceLocation LParenLoc,
                                            SourceLocation LParenLoc,
                                            TypeSourceInfo *T,
                                            TypeSourceInfo *T,
                                            PropertyControl propControl) {
                                            PropertyControl propControl) {
-  return new (C) ObjCPropertyDecl(DC, L, Id, AtLoc, LParenLoc, T);
+  return new (C, DC) ObjCPropertyDecl(DC, L, Id, AtLoc, LParenLoc, T);
 }
 }
 
 
-ObjCPropertyDecl *ObjCPropertyDecl::CreateDeserialized(ASTContext &C, 
+ObjCPropertyDecl *ObjCPropertyDecl::CreateDeserialized(ASTContext &C,
                                                        unsigned ID) {
                                                        unsigned ID) {
-  void * Mem = AllocateDeserializedDecl(C, ID, sizeof(ObjCPropertyDecl));
-  return new (Mem) ObjCPropertyDecl(0, SourceLocation(), 0, SourceLocation(),
-                                    SourceLocation(),
-                                    0);
+  return new (C, ID) ObjCPropertyDecl(0, SourceLocation(), 0, SourceLocation(),
+                                      SourceLocation(), 0);
 }
 }
 
 
 //===----------------------------------------------------------------------===//
 //===----------------------------------------------------------------------===//
@@ -1782,15 +1769,14 @@ ObjCPropertyImplDecl *ObjCPropertyImplDecl::Create(ASTContext &C,
                                                    Kind PK,
                                                    Kind PK,
                                                    ObjCIvarDecl *ivar,
                                                    ObjCIvarDecl *ivar,
                                                    SourceLocation ivarLoc) {
                                                    SourceLocation ivarLoc) {
-  return new (C) ObjCPropertyImplDecl(DC, atLoc, L, property, PK, ivar,
-                                      ivarLoc);
+  return new (C, DC) ObjCPropertyImplDecl(DC, atLoc, L, property, PK, ivar,
+                                          ivarLoc);
 }
 }
 
 
-ObjCPropertyImplDecl *ObjCPropertyImplDecl::CreateDeserialized(ASTContext &C, 
+ObjCPropertyImplDecl *ObjCPropertyImplDecl::CreateDeserialized(ASTContext &C,
                                                                unsigned ID) {
                                                                unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ObjCPropertyImplDecl));
-  return new (Mem) ObjCPropertyImplDecl(0, SourceLocation(), SourceLocation(),
-                                        0, Dynamic, 0, SourceLocation());
+  return new (C, ID) ObjCPropertyImplDecl(0, SourceLocation(), SourceLocation(),
+                                          0, Dynamic, 0, SourceLocation());
 }
 }
 
 
 SourceRange ObjCPropertyImplDecl::getSourceRange() const {
 SourceRange ObjCPropertyImplDecl::getSourceRange() const {

+ 4 - 11
lib/AST/DeclOpenMP.cpp

@@ -29,12 +29,8 @@ OMPThreadPrivateDecl *OMPThreadPrivateDecl::Create(ASTContext &C,
                                                    DeclContext *DC,
                                                    DeclContext *DC,
                                                    SourceLocation L,
                                                    SourceLocation L,
                                                    ArrayRef<Expr *> VL) {
                                                    ArrayRef<Expr *> VL) {
-  unsigned Size = sizeof(OMPThreadPrivateDecl) +
-                  (VL.size() * sizeof(Expr *));
-
-  void *Mem = C.Allocate(Size, llvm::alignOf<OMPThreadPrivateDecl>());
-  OMPThreadPrivateDecl *D = new (Mem) OMPThreadPrivateDecl(OMPThreadPrivate,
-                                                           DC, L);
+  OMPThreadPrivateDecl *D = new (C, DC, VL.size() * sizeof(Expr *))
+      OMPThreadPrivateDecl(OMPThreadPrivate, DC, L);
   D->NumVars = VL.size();
   D->NumVars = VL.size();
   D->setVars(VL);
   D->setVars(VL);
   return D;
   return D;
@@ -43,11 +39,8 @@ OMPThreadPrivateDecl *OMPThreadPrivateDecl::Create(ASTContext &C,
 OMPThreadPrivateDecl *OMPThreadPrivateDecl::CreateDeserialized(ASTContext &C,
 OMPThreadPrivateDecl *OMPThreadPrivateDecl::CreateDeserialized(ASTContext &C,
                                                                unsigned ID,
                                                                unsigned ID,
                                                                unsigned N) {
                                                                unsigned N) {
-  unsigned Size = sizeof(OMPThreadPrivateDecl) + (N * sizeof(Expr *));
-
-  void *Mem = AllocateDeserializedDecl(C, ID, Size);
-  OMPThreadPrivateDecl *D = new (Mem) OMPThreadPrivateDecl(OMPThreadPrivate,
-                                                           0, SourceLocation());
+  OMPThreadPrivateDecl *D = new (C, ID, N * sizeof(Expr *))
+      OMPThreadPrivateDecl(OMPThreadPrivate, 0, SourceLocation());
   D->NumVars = N;
   D->NumVars = N;
   return D;
   return D;
 }
 }

+ 60 - 102
lib/AST/DeclTemplate.cpp

@@ -229,14 +229,13 @@ FunctionTemplateDecl *FunctionTemplateDecl::Create(ASTContext &C,
                                                TemplateParameterList *Params,
                                                TemplateParameterList *Params,
                                                    NamedDecl *Decl) {
                                                    NamedDecl *Decl) {
   AdoptTemplateParameterList(Params, cast<DeclContext>(Decl));
   AdoptTemplateParameterList(Params, cast<DeclContext>(Decl));
-  return new (C) FunctionTemplateDecl(DC, L, Name, Params, Decl);
+  return new (C, DC) FunctionTemplateDecl(DC, L, Name, Params, Decl);
 }
 }
 
 
 FunctionTemplateDecl *FunctionTemplateDecl::CreateDeserialized(ASTContext &C,
 FunctionTemplateDecl *FunctionTemplateDecl::CreateDeserialized(ASTContext &C,
                                                                unsigned ID) {
                                                                unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(FunctionTemplateDecl));
-  return new (Mem) FunctionTemplateDecl(0, SourceLocation(), DeclarationName(),
-                                        0, 0);
+  return new (C, ID) FunctionTemplateDecl(0, SourceLocation(), DeclarationName(),
+                                          0, 0);
 }
 }
 
 
 RedeclarableTemplateDecl::CommonBase *
 RedeclarableTemplateDecl::CommonBase *
@@ -308,15 +307,15 @@ ClassTemplateDecl *ClassTemplateDecl::Create(ASTContext &C,
                                              NamedDecl *Decl,
                                              NamedDecl *Decl,
                                              ClassTemplateDecl *PrevDecl) {
                                              ClassTemplateDecl *PrevDecl) {
   AdoptTemplateParameterList(Params, cast<DeclContext>(Decl));
   AdoptTemplateParameterList(Params, cast<DeclContext>(Decl));
-  ClassTemplateDecl *New = new (C) ClassTemplateDecl(DC, L, Name, Params, Decl);
+  ClassTemplateDecl *New =
+      new (C, DC) ClassTemplateDecl(DC, L, Name, Params, Decl);
   New->setPreviousDecl(PrevDecl);
   New->setPreviousDecl(PrevDecl);
   return New;
   return New;
 }
 }
 
 
 ClassTemplateDecl *ClassTemplateDecl::CreateDeserialized(ASTContext &C, 
 ClassTemplateDecl *ClassTemplateDecl::CreateDeserialized(ASTContext &C, 
                                                          unsigned ID) {
                                                          unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(ClassTemplateDecl));
-  return new (Mem) ClassTemplateDecl(EmptyShell());
+  return new (C, ID) ClassTemplateDecl(EmptyShell());
 }
 }
 
 
 void ClassTemplateDecl::LoadLazySpecializations() const {
 void ClassTemplateDecl::LoadLazySpecializations() const {
@@ -471,7 +470,7 @@ TemplateTypeParmDecl::Create(const ASTContext &C, DeclContext *DC,
                              unsigned D, unsigned P, IdentifierInfo *Id,
                              unsigned D, unsigned P, IdentifierInfo *Id,
                              bool Typename, bool ParameterPack) {
                              bool Typename, bool ParameterPack) {
   TemplateTypeParmDecl *TTPDecl =
   TemplateTypeParmDecl *TTPDecl =
-    new (C) TemplateTypeParmDecl(DC, KeyLoc, NameLoc, Id, Typename);
+    new (C, DC) TemplateTypeParmDecl(DC, KeyLoc, NameLoc, Id, Typename);
   QualType TTPType = C.getTemplateTypeParmType(D, P, ParameterPack, TTPDecl);
   QualType TTPType = C.getTemplateTypeParmType(D, P, ParameterPack, TTPDecl);
   TTPDecl->TypeForDecl = TTPType.getTypePtr();
   TTPDecl->TypeForDecl = TTPType.getTypePtr();
   return TTPDecl;
   return TTPDecl;
@@ -479,9 +478,8 @@ TemplateTypeParmDecl::Create(const ASTContext &C, DeclContext *DC,
 
 
 TemplateTypeParmDecl *
 TemplateTypeParmDecl *
 TemplateTypeParmDecl::CreateDeserialized(const ASTContext &C, unsigned ID) {
 TemplateTypeParmDecl::CreateDeserialized(const ASTContext &C, unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(TemplateTypeParmDecl));
-  return new (Mem) TemplateTypeParmDecl(0, SourceLocation(), SourceLocation(),
-                                        0, false);
+  return new (C, ID) TemplateTypeParmDecl(0, SourceLocation(), SourceLocation(),
+                                          0, false);
 }
 }
 
 
 SourceLocation TemplateTypeParmDecl::getDefaultArgumentLoc() const {
 SourceLocation TemplateTypeParmDecl::getDefaultArgumentLoc() const {
@@ -544,8 +542,8 @@ NonTypeTemplateParmDecl::Create(const ASTContext &C, DeclContext *DC,
                                 unsigned D, unsigned P, IdentifierInfo *Id,
                                 unsigned D, unsigned P, IdentifierInfo *Id,
                                 QualType T, bool ParameterPack,
                                 QualType T, bool ParameterPack,
                                 TypeSourceInfo *TInfo) {
                                 TypeSourceInfo *TInfo) {
-  return new (C) NonTypeTemplateParmDecl(DC, StartLoc, IdLoc, D, P, Id,
-                                         T, ParameterPack, TInfo);
+  return new (C, DC) NonTypeTemplateParmDecl(DC, StartLoc, IdLoc, D, P, Id,
+                                             T, ParameterPack, TInfo);
 }
 }
 
 
 NonTypeTemplateParmDecl *
 NonTypeTemplateParmDecl *
@@ -557,34 +555,26 @@ NonTypeTemplateParmDecl::Create(const ASTContext &C, DeclContext *DC,
                                 const QualType *ExpandedTypes, 
                                 const QualType *ExpandedTypes, 
                                 unsigned NumExpandedTypes,
                                 unsigned NumExpandedTypes,
                                 TypeSourceInfo **ExpandedTInfos) {
                                 TypeSourceInfo **ExpandedTInfos) {
-  unsigned Size = sizeof(NonTypeTemplateParmDecl) 
-                + NumExpandedTypes * 2 * sizeof(void*);
-  void *Mem = C.Allocate(Size);
-  return new (Mem) NonTypeTemplateParmDecl(DC, StartLoc, IdLoc,
-                                           D, P, Id, T, TInfo,
-                                           ExpandedTypes, NumExpandedTypes, 
-                                           ExpandedTInfos);
+  unsigned Extra = NumExpandedTypes * 2 * sizeof(void*);
+  return new (C, DC, Extra) NonTypeTemplateParmDecl(
+      DC, StartLoc, IdLoc, D, P, Id, T, TInfo,
+      ExpandedTypes, NumExpandedTypes, ExpandedTInfos);
 }
 }
 
 
 NonTypeTemplateParmDecl *
 NonTypeTemplateParmDecl *
 NonTypeTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
 NonTypeTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(NonTypeTemplateParmDecl));
-  return new (Mem) NonTypeTemplateParmDecl(0, SourceLocation(), 
-                                           SourceLocation(), 0, 0, 0, 
-                                           QualType(), false, 0);
+  return new (C, ID) NonTypeTemplateParmDecl(0, SourceLocation(),
+                                             SourceLocation(), 0, 0, 0,
+                                             QualType(), false, 0);
 }
 }
 
 
 NonTypeTemplateParmDecl *
 NonTypeTemplateParmDecl *
 NonTypeTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID,
 NonTypeTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID,
                                             unsigned NumExpandedTypes) {
                                             unsigned NumExpandedTypes) {
-  unsigned Size = sizeof(NonTypeTemplateParmDecl) 
-                + NumExpandedTypes * 2 * sizeof(void*);
-  
-  void *Mem = AllocateDeserializedDecl(C, ID, Size);
-  return new (Mem) NonTypeTemplateParmDecl(0, SourceLocation(), 
-                                           SourceLocation(), 0, 0, 0,
-                                           QualType(), 0, 0, NumExpandedTypes,
-                                           0);
+  unsigned Extra = NumExpandedTypes * 2 * sizeof(void*);
+  return new (C, ID, Extra) NonTypeTemplateParmDecl(
+      0, SourceLocation(), SourceLocation(), 0, 0, 0, QualType(), 0,
+      0, NumExpandedTypes, 0);
 }
 }
 
 
 SourceRange NonTypeTemplateParmDecl::getSourceRange() const {
 SourceRange NonTypeTemplateParmDecl::getSourceRange() const {
@@ -624,8 +614,8 @@ TemplateTemplateParmDecl::Create(const ASTContext &C, DeclContext *DC,
                                  SourceLocation L, unsigned D, unsigned P,
                                  SourceLocation L, unsigned D, unsigned P,
                                  bool ParameterPack, IdentifierInfo *Id,
                                  bool ParameterPack, IdentifierInfo *Id,
                                  TemplateParameterList *Params) {
                                  TemplateParameterList *Params) {
-  return new (C) TemplateTemplateParmDecl(DC, L, D, P, ParameterPack, Id, 
-                                          Params);
+  return new (C, DC) TemplateTemplateParmDecl(DC, L, D, P, ParameterPack, Id,
+                                              Params);
 }
 }
 
 
 TemplateTemplateParmDecl *
 TemplateTemplateParmDecl *
@@ -634,28 +624,23 @@ TemplateTemplateParmDecl::Create(const ASTContext &C, DeclContext *DC,
                                  IdentifierInfo *Id,
                                  IdentifierInfo *Id,
                                  TemplateParameterList *Params,
                                  TemplateParameterList *Params,
                                  ArrayRef<TemplateParameterList *> Expansions) {
                                  ArrayRef<TemplateParameterList *> Expansions) {
-  void *Mem = C.Allocate(sizeof(TemplateTemplateParmDecl) +
-                         sizeof(TemplateParameterList*) * Expansions.size());
-  return new (Mem) TemplateTemplateParmDecl(DC, L, D, P, Id, Params,
-                                            Expansions.size(),
-                                            Expansions.data());
+  return new (C, DC, sizeof(TemplateParameterList*) * Expansions.size())
+      TemplateTemplateParmDecl(DC, L, D, P, Id, Params,
+                               Expansions.size(), Expansions.data());
 }
 }
 
 
 TemplateTemplateParmDecl *
 TemplateTemplateParmDecl *
 TemplateTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
 TemplateTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(TemplateTemplateParmDecl));
-  return new (Mem) TemplateTemplateParmDecl(0, SourceLocation(), 0, 0, false,
-                                            0, 0);
+  return new (C, ID) TemplateTemplateParmDecl(0, SourceLocation(), 0, 0, false,
+                                              0, 0);
 }
 }
 
 
 TemplateTemplateParmDecl *
 TemplateTemplateParmDecl *
 TemplateTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID,
 TemplateTemplateParmDecl::CreateDeserialized(ASTContext &C, unsigned ID,
                                              unsigned NumExpansions) {
                                              unsigned NumExpansions) {
-  unsigned Size = sizeof(TemplateTemplateParmDecl) +
-                  sizeof(TemplateParameterList*) * NumExpansions;
-  void *Mem = AllocateDeserializedDecl(C, ID, Size);
-  return new (Mem) TemplateTemplateParmDecl(0, SourceLocation(), 0, 0, 0, 0,
-                                            NumExpansions, 0);
+  return new (C, ID, sizeof(TemplateParameterList*) * NumExpansions)
+      TemplateTemplateParmDecl(0, SourceLocation(), 0, 0, 0, 0,
+                               NumExpansions, 0);
 }
 }
 
 
 //===----------------------------------------------------------------------===//
 //===----------------------------------------------------------------------===//
@@ -734,13 +719,10 @@ ClassTemplateSpecializationDecl::Create(ASTContext &Context, TagKind TK,
                                         const TemplateArgument *Args,
                                         const TemplateArgument *Args,
                                         unsigned NumArgs,
                                         unsigned NumArgs,
                                    ClassTemplateSpecializationDecl *PrevDecl) {
                                    ClassTemplateSpecializationDecl *PrevDecl) {
-  ClassTemplateSpecializationDecl *Result
-    = new (Context)ClassTemplateSpecializationDecl(Context,
-                                                   ClassTemplateSpecialization,
-                                                   TK, DC, StartLoc, IdLoc,
-                                                   SpecializedTemplate,
-                                                   Args, NumArgs,
-                                                   PrevDecl);
+  ClassTemplateSpecializationDecl *Result =
+      new (Context, DC) ClassTemplateSpecializationDecl(
+          Context, ClassTemplateSpecialization, TK, DC, StartLoc, IdLoc,
+          SpecializedTemplate, Args, NumArgs, PrevDecl);
   Result->MayHaveOutOfDateDef = false;
   Result->MayHaveOutOfDateDef = false;
 
 
   Context.getTypeDeclType(Result, PrevDecl);
   Context.getTypeDeclType(Result, PrevDecl);
@@ -748,12 +730,10 @@ ClassTemplateSpecializationDecl::Create(ASTContext &Context, TagKind TK,
 }
 }
 
 
 ClassTemplateSpecializationDecl *
 ClassTemplateSpecializationDecl *
-ClassTemplateSpecializationDecl::CreateDeserialized(ASTContext &C, 
+ClassTemplateSpecializationDecl::CreateDeserialized(ASTContext &C,
                                                     unsigned ID) {
                                                     unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, 
-                                       sizeof(ClassTemplateSpecializationDecl));
   ClassTemplateSpecializationDecl *Result =
   ClassTemplateSpecializationDecl *Result =
-    new (Mem) ClassTemplateSpecializationDecl(ClassTemplateSpecialization);
+    new (C, ID) ClassTemplateSpecializationDecl(ClassTemplateSpecialization);
   Result->MayHaveOutOfDateDef = false;
   Result->MayHaveOutOfDateDef = false;
   return Result;
   return Result;
 }
 }
@@ -855,14 +835,10 @@ Create(ASTContext &Context, TagKind TK,DeclContext *DC,
   const ASTTemplateArgumentListInfo *ASTArgInfos =
   const ASTTemplateArgumentListInfo *ASTArgInfos =
     ASTTemplateArgumentListInfo::Create(Context, ArgInfos);
     ASTTemplateArgumentListInfo::Create(Context, ArgInfos);
 
 
-  ClassTemplatePartialSpecializationDecl *Result
-    = new (Context)ClassTemplatePartialSpecializationDecl(Context, TK, DC,
-                                                          StartLoc, IdLoc,
-                                                          Params,
-                                                          SpecializedTemplate,
-                                                          Args, NumArgs,
-                                                          ASTArgInfos,
-                                                          PrevDecl);
+  ClassTemplatePartialSpecializationDecl *Result = new (Context, DC)
+      ClassTemplatePartialSpecializationDecl(Context, TK, DC, StartLoc, IdLoc,
+                                             Params, SpecializedTemplate, Args,
+                                             NumArgs, ASTArgInfos, PrevDecl);
   Result->setSpecializationKind(TSK_ExplicitSpecialization);
   Result->setSpecializationKind(TSK_ExplicitSpecialization);
   Result->MayHaveOutOfDateDef = false;
   Result->MayHaveOutOfDateDef = false;
 
 
@@ -873,10 +849,8 @@ Create(ASTContext &Context, TagKind TK,DeclContext *DC,
 ClassTemplatePartialSpecializationDecl *
 ClassTemplatePartialSpecializationDecl *
 ClassTemplatePartialSpecializationDecl::CreateDeserialized(ASTContext &C,
 ClassTemplatePartialSpecializationDecl::CreateDeserialized(ASTContext &C,
                                                            unsigned ID) {
                                                            unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, 
-                sizeof(ClassTemplatePartialSpecializationDecl));
-  ClassTemplatePartialSpecializationDecl *Result
-    = new (Mem) ClassTemplatePartialSpecializationDecl();
+  ClassTemplatePartialSpecializationDecl *Result =
+      new (C, ID) ClassTemplatePartialSpecializationDecl();
   Result->MayHaveOutOfDateDef = false;
   Result->MayHaveOutOfDateDef = false;
   return Result;
   return Result;
 }
 }
@@ -894,15 +868,13 @@ FriendTemplateDecl *FriendTemplateDecl::Create(ASTContext &Context,
                                                TemplateParameterList **Params,
                                                TemplateParameterList **Params,
                                                FriendUnion Friend,
                                                FriendUnion Friend,
                                                SourceLocation FLoc) {
                                                SourceLocation FLoc) {
-  FriendTemplateDecl *Result
-    = new (Context) FriendTemplateDecl(DC, L, NParams, Params, Friend, FLoc);
-  return Result;
+  return new (Context, DC) FriendTemplateDecl(DC, L, NParams, Params,
+                                              Friend, FLoc);
 }
 }
 
 
 FriendTemplateDecl *FriendTemplateDecl::CreateDeserialized(ASTContext &C,
 FriendTemplateDecl *FriendTemplateDecl::CreateDeserialized(ASTContext &C,
                                                            unsigned ID) {
                                                            unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(FriendTemplateDecl));
-  return new (Mem) FriendTemplateDecl(EmptyShell());
+  return new (C, ID) FriendTemplateDecl(EmptyShell());
 }
 }
 
 
 //===----------------------------------------------------------------------===//
 //===----------------------------------------------------------------------===//
@@ -916,14 +888,13 @@ TypeAliasTemplateDecl *TypeAliasTemplateDecl::Create(ASTContext &C,
                                                   TemplateParameterList *Params,
                                                   TemplateParameterList *Params,
                                                      NamedDecl *Decl) {
                                                      NamedDecl *Decl) {
   AdoptTemplateParameterList(Params, DC);
   AdoptTemplateParameterList(Params, DC);
-  return new (C) TypeAliasTemplateDecl(DC, L, Name, Params, Decl);
+  return new (C, DC) TypeAliasTemplateDecl(DC, L, Name, Params, Decl);
 }
 }
 
 
 TypeAliasTemplateDecl *TypeAliasTemplateDecl::CreateDeserialized(ASTContext &C,
 TypeAliasTemplateDecl *TypeAliasTemplateDecl::CreateDeserialized(ASTContext &C,
                                                                  unsigned ID) {
                                                                  unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(TypeAliasTemplateDecl));
-  return new (Mem) TypeAliasTemplateDecl(0, SourceLocation(), DeclarationName(),
-                                         0, 0);
+  return new (C, ID) TypeAliasTemplateDecl(0, SourceLocation(), DeclarationName(),
+                                           0, 0);
 }
 }
 
 
 void TypeAliasTemplateDecl::DeallocateCommon(void *Ptr) {
 void TypeAliasTemplateDecl::DeallocateCommon(void *Ptr) {
@@ -945,10 +916,8 @@ void ClassScopeFunctionSpecializationDecl::anchor() { }
 ClassScopeFunctionSpecializationDecl *
 ClassScopeFunctionSpecializationDecl *
 ClassScopeFunctionSpecializationDecl::CreateDeserialized(ASTContext &C,
 ClassScopeFunctionSpecializationDecl::CreateDeserialized(ASTContext &C,
                                                          unsigned ID) {
                                                          unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, 
-                sizeof(ClassScopeFunctionSpecializationDecl));
-  return new (Mem) ClassScopeFunctionSpecializationDecl(0, SourceLocation(), 0,
-                                             false, TemplateArgumentListInfo());
+  return new (C, ID) ClassScopeFunctionSpecializationDecl(
+      0, SourceLocation(), 0, false, TemplateArgumentListInfo());
 }
 }
 
 
 //===----------------------------------------------------------------------===//
 //===----------------------------------------------------------------------===//
@@ -974,15 +943,14 @@ VarTemplateDecl *VarTemplateDecl::Create(ASTContext &C, DeclContext *DC,
                                          TemplateParameterList *Params,
                                          TemplateParameterList *Params,
                                          NamedDecl *Decl,
                                          NamedDecl *Decl,
                                          VarTemplateDecl *PrevDecl) {
                                          VarTemplateDecl *PrevDecl) {
-  VarTemplateDecl *New = new (C) VarTemplateDecl(DC, L, Name, Params, Decl);
+  VarTemplateDecl *New = new (C, DC) VarTemplateDecl(DC, L, Name, Params, Decl);
   New->setPreviousDecl(PrevDecl);
   New->setPreviousDecl(PrevDecl);
   return New;
   return New;
 }
 }
 
 
 VarTemplateDecl *VarTemplateDecl::CreateDeserialized(ASTContext &C,
 VarTemplateDecl *VarTemplateDecl::CreateDeserialized(ASTContext &C,
                                                      unsigned ID) {
                                                      unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(C, ID, sizeof(VarTemplateDecl));
-  return new (Mem) VarTemplateDecl(EmptyShell());
+  return new (C, ID) VarTemplateDecl(EmptyShell());
 }
 }
 
 
 // TODO: Unify accross class, function and variable templates?
 // TODO: Unify accross class, function and variable templates?
@@ -1111,20 +1079,14 @@ VarTemplateSpecializationDecl *VarTemplateSpecializationDecl::Create(
     SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T,
     SourceLocation IdLoc, VarTemplateDecl *SpecializedTemplate, QualType T,
     TypeSourceInfo *TInfo, StorageClass S, const TemplateArgument *Args,
     TypeSourceInfo *TInfo, StorageClass S, const TemplateArgument *Args,
     unsigned NumArgs) {
     unsigned NumArgs) {
-  VarTemplateSpecializationDecl *Result = new (Context)
-      VarTemplateSpecializationDecl(Context, VarTemplateSpecialization, DC,
-                                    StartLoc, IdLoc, SpecializedTemplate, T,
-                                    TInfo, S, Args, NumArgs);
-  return Result;
+  return new (Context, DC) VarTemplateSpecializationDecl(
+      Context, VarTemplateSpecialization, DC, StartLoc, IdLoc,
+      SpecializedTemplate, T, TInfo, S, Args, NumArgs);
 }
 }
 
 
 VarTemplateSpecializationDecl *
 VarTemplateSpecializationDecl *
 VarTemplateSpecializationDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
 VarTemplateSpecializationDecl::CreateDeserialized(ASTContext &C, unsigned ID) {
-  void *Mem =
-      AllocateDeserializedDecl(C, ID, sizeof(VarTemplateSpecializationDecl));
-  VarTemplateSpecializationDecl *Result =
-      new (Mem) VarTemplateSpecializationDecl(VarTemplateSpecialization);
-  return Result;
+  return new (C, ID) VarTemplateSpecializationDecl(VarTemplateSpecialization);
 }
 }
 
 
 void VarTemplateSpecializationDecl::getNameForDiagnostic(
 void VarTemplateSpecializationDecl::getNameForDiagnostic(
@@ -1183,7 +1145,7 @@ VarTemplatePartialSpecializationDecl::Create(
     = ASTTemplateArgumentListInfo::Create(Context, ArgInfos);
     = ASTTemplateArgumentListInfo::Create(Context, ArgInfos);
 
 
   VarTemplatePartialSpecializationDecl *Result =
   VarTemplatePartialSpecializationDecl *Result =
-      new (Context) VarTemplatePartialSpecializationDecl(
+      new (Context, DC) VarTemplatePartialSpecializationDecl(
           Context, DC, StartLoc, IdLoc, Params, SpecializedTemplate, T, TInfo,
           Context, DC, StartLoc, IdLoc, Params, SpecializedTemplate, T, TInfo,
           S, Args, NumArgs, ASTArgInfos);
           S, Args, NumArgs, ASTArgInfos);
   Result->setSpecializationKind(TSK_ExplicitSpecialization);
   Result->setSpecializationKind(TSK_ExplicitSpecialization);
@@ -1193,9 +1155,5 @@ VarTemplatePartialSpecializationDecl::Create(
 VarTemplatePartialSpecializationDecl *
 VarTemplatePartialSpecializationDecl *
 VarTemplatePartialSpecializationDecl::CreateDeserialized(ASTContext &C,
 VarTemplatePartialSpecializationDecl::CreateDeserialized(ASTContext &C,
                                                          unsigned ID) {
                                                          unsigned ID) {
-  void *Mem = AllocateDeserializedDecl(
-      C, ID, sizeof(VarTemplatePartialSpecializationDecl));
-  VarTemplatePartialSpecializationDecl *Result =
-      new (Mem) VarTemplatePartialSpecializationDecl();
-  return Result;
+  return new (C, ID) VarTemplatePartialSpecializationDecl();
 }
 }

+ 2 - 4
lib/Sema/SemaDeclCXX.cpp

@@ -12793,11 +12793,9 @@ MSPropertyDecl *Sema::HandleMSProperty(Scope *S, RecordDecl *Record,
     PrevDecl = 0;
     PrevDecl = 0;
 
 
   SourceLocation TSSL = D.getLocStart();
   SourceLocation TSSL = D.getLocStart();
-  MSPropertyDecl *NewPD;
   const AttributeList::PropertyData &Data = MSPropertyAttr->getPropertyData();
   const AttributeList::PropertyData &Data = MSPropertyAttr->getPropertyData();
-  NewPD = new (Context) MSPropertyDecl(Record, Loc,
-                                       II, T, TInfo, TSSL,
-                                       Data.GetterId, Data.SetterId);
+  MSPropertyDecl *NewPD = MSPropertyDecl::Create(
+      Context, Record, Loc, II, T, TInfo, TSSL, Data.GetterId, Data.SetterId);
   ProcessDeclAttributes(TUScope, NewPD, D);
   ProcessDeclAttributes(TUScope, NewPD, D);
   NewPD->setAccess(AS);
   NewPD->setAccess(AS);
 
 

+ 3 - 5
lib/Sema/SemaTemplateInstantiateDecl.cpp

@@ -488,11 +488,9 @@ Decl *TemplateDeclInstantiator::VisitMSPropertyDecl(MSPropertyDecl *D) {
     SemaRef.MarkDeclarationsReferencedInType(D->getLocation(), DI->getType());
     SemaRef.MarkDeclarationsReferencedInType(D->getLocation(), DI->getType());
   }
   }
 
 
-  MSPropertyDecl *Property = new (SemaRef.Context)
-      MSPropertyDecl(Owner, D->getLocation(),
-                     D->getDeclName(), DI->getType(), DI,
-                     D->getLocStart(),
-                     D->getGetterId(), D->getSetterId());
+  MSPropertyDecl *Property = MSPropertyDecl::Create(
+      SemaRef.Context, Owner, D->getLocation(), D->getDeclName(), DI->getType(),
+      DI, D->getLocStart(), D->getGetterId(), D->getSetterId());
 
 
   SemaRef.InstantiateAttrs(TemplateArgs, D, Property, LateAttrs,
   SemaRef.InstantiateAttrs(TemplateArgs, D, Property, LateAttrs,
                            StartingScope);
                            StartingScope);