Eliminate a pointer of storage in each ObjCInterfaceType and
ObjCObjectPointerType AST node by allocating the list of protocols
after the type node itself. No functionality change.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@95597 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp
index 386a5f3..c9d85c8 100644
--- a/lib/AST/ASTContext.cpp
+++ b/lib/AST/ASTContext.cpp
@@ -2163,10 +2163,14 @@
     ObjCObjectPointerTypes.FindNodeOrInsertPos(ID, InsertPos);
   }
 
-  // No Match;
-  ObjCObjectPointerType *QType = new (*this, TypeAlignment)
-    ObjCObjectPointerType(*this, Canonical, InterfaceT, Protocols,
-                          NumProtocols);
+  // No match.
+  unsigned Size = sizeof(ObjCObjectPointerType) 
+                + NumProtocols * sizeof(ObjCProtocolDecl *);
+  void *Mem = Allocate(Size, TypeAlignment);
+  ObjCObjectPointerType *QType = new (Mem) ObjCObjectPointerType(Canonical, 
+                                                                 InterfaceT, 
+                                                                 Protocols,
+                                                                 NumProtocols);
 
   Types.push_back(QType);
   ObjCObjectPointerTypes.InsertNode(QType, InsertPos);
@@ -2199,9 +2203,13 @@
     ObjCInterfaceTypes.FindNodeOrInsertPos(ID, InsertPos);
   }
 
-  ObjCInterfaceType *QType = new (*this, TypeAlignment)
-    ObjCInterfaceType(*this, Canonical, const_cast<ObjCInterfaceDecl*>(Decl),
-                      Protocols, NumProtocols);
+  unsigned Size = sizeof(ObjCInterfaceType) 
+    + NumProtocols * sizeof(ObjCProtocolDecl *);
+  void *Mem = Allocate(Size, TypeAlignment);
+  ObjCInterfaceType *QType = new (Mem) ObjCInterfaceType(Canonical, 
+                                        const_cast<ObjCInterfaceDecl*>(Decl),
+                                                         Protocols, 
+                                                         NumProtocols);
 
   Types.push_back(QType);
   ObjCInterfaceTypes.InsertNode(QType, InsertPos);
diff --git a/lib/AST/Type.cpp b/lib/AST/Type.cpp
index 92498be..52d734c 100644
--- a/lib/AST/Type.cpp
+++ b/lib/AST/Type.cpp
@@ -339,21 +339,18 @@
   return 0;
 }
 
-ObjCInterfaceType::ObjCInterfaceType(ASTContext &Ctx, QualType Canonical,
+ObjCInterfaceType::ObjCInterfaceType(QualType Canonical,
                                      ObjCInterfaceDecl *D,
                                      ObjCProtocolDecl **Protos, unsigned NumP) :
   Type(ObjCInterface, Canonical, /*Dependent=*/false),
-  Decl(D), Protocols(0), NumProtocols(NumP)
+  Decl(D), NumProtocols(NumP)
 {
-  if (NumProtocols) {
-    Protocols = new (Ctx) ObjCProtocolDecl*[NumProtocols];
-    memcpy(Protocols, Protos, NumProtocols * sizeof(*Protocols));
-  }
+  if (NumProtocols)
+    memcpy(reinterpret_cast<ObjCProtocolDecl**>(this + 1), Protos, 
+           NumProtocols * sizeof(*Protos));
 }
 
 void ObjCInterfaceType::Destroy(ASTContext& C) {
-  if (Protocols)
-    C.Deallocate(Protocols);
   this->~ObjCInterfaceType();
   C.Deallocate(this);
 }
@@ -372,22 +369,18 @@
   return getAsObjCQualifiedInterfaceType() != 0;
 }
 
-ObjCObjectPointerType::ObjCObjectPointerType(ASTContext &Ctx,
-                                             QualType Canonical, QualType T,
+ObjCObjectPointerType::ObjCObjectPointerType(QualType Canonical, QualType T,
                                              ObjCProtocolDecl **Protos,
                                              unsigned NumP) :
   Type(ObjCObjectPointer, Canonical, /*Dependent=*/false),
-  PointeeType(T), Protocols(NULL), NumProtocols(NumP)
+  PointeeType(T), NumProtocols(NumP)
 {
-  if (NumProtocols) {
-    Protocols = new (Ctx) ObjCProtocolDecl*[NumProtocols];
-    memcpy(Protocols, Protos, NumProtocols * sizeof(*Protocols));
-  }
+  if (NumProtocols)
+    memcpy(reinterpret_cast<ObjCProtocolDecl **>(this + 1), Protos, 
+           NumProtocols * sizeof(*Protos));
 }
 
 void ObjCObjectPointerType::Destroy(ASTContext& C) {
-  if (Protocols)
-    C.Deallocate(Protocols);
   this->~ObjCObjectPointerType();
   C.Deallocate(this);
 }
@@ -851,7 +844,8 @@
 }
 
 void ObjCObjectPointerType::Profile(llvm::FoldingSetNodeID &ID,
-                                    QualType OIT, ObjCProtocolDecl **protocols,
+                                    QualType OIT, 
+                                    ObjCProtocolDecl * const *protocols,
                                     unsigned NumProtocols) {
   ID.AddPointer(OIT.getAsOpaquePtr());
   for (unsigned i = 0; i != NumProtocols; i++)
@@ -859,10 +853,7 @@
 }
 
 void ObjCObjectPointerType::Profile(llvm::FoldingSetNodeID &ID) {
-  if (getNumProtocols())
-    Profile(ID, getPointeeType(), &Protocols[0], getNumProtocols());
-  else
-    Profile(ID, getPointeeType(), 0, 0);
+  Profile(ID, getPointeeType(), qual_begin(), getNumProtocols());
 }
 
 /// LookThroughTypedefs - Return the ultimate type this typedef corresponds to
@@ -1050,7 +1041,7 @@
 
 void ObjCInterfaceType::Profile(llvm::FoldingSetNodeID &ID,
                                          const ObjCInterfaceDecl *Decl,
-                                         ObjCProtocolDecl **protocols,
+                                         ObjCProtocolDecl * const *protocols,
                                          unsigned NumProtocols) {
   ID.AddPointer(Decl);
   for (unsigned i = 0; i != NumProtocols; i++)
@@ -1058,10 +1049,7 @@
 }
 
 void ObjCInterfaceType::Profile(llvm::FoldingSetNodeID &ID) {
-  if (getNumProtocols())
-    Profile(ID, getDecl(), &Protocols[0], getNumProtocols());
-  else
-    Profile(ID, getDecl(), 0, 0);
+  Profile(ID, getDecl(), qual_begin(), getNumProtocols());
 }
 
 Linkage Type::getLinkage() const {