Lower the default alignment on ASTContext's operator new.
authorBenjamin Kramer <benny.kra@googlemail.com>
Thu, 2 Apr 2015 16:19:54 +0000 (16:19 +0000)
committerBenjamin Kramer <benny.kra@googlemail.com>
Thu, 2 Apr 2015 16:19:54 +0000 (16:19 +0000)
It was documented as 8 and operator new[] defaults to 8, but the normal
operator new was never updated and happily wasted bytes on every other
allocation.

We still have to allocate all Types with 16 byte alignment, update the
allocation calls for Types that were missing explicit alignment.

llvm-svn: 233922

clang/include/clang/AST/Attr.h
clang/include/clang/AST/AttrIterator.h
clang/lib/AST/ASTContext.cpp

index c3e7f2a99f51b5f10cd93ac2d7f02b1f98506eda..a854168f01dc919e368fc268f276562a28520614 100644 (file)
@@ -65,7 +65,7 @@ protected:
 public:
   // Forward so that the regular new and delete do not hide global ones.
   void* operator new(size_t Bytes, ASTContext &C,
-                     size_t Alignment = 16) throw() {
+                     size_t Alignment = 8) throw() {
     return ::operator new(Bytes, C, Alignment);
   }
   void operator delete(void *Ptr, ASTContext &C,
index 39ee81f1201ca2650612581cc9fc48e8dee1233c..a0c803096af86fa9bf25c21796d4eecfedf33292 100644 (file)
@@ -24,7 +24,7 @@ namespace clang {
 
 // Defined in ASTContext.h
 void *operator new(size_t Bytes, const clang::ASTContext &C,
-                   size_t Alignment = 16);
+                   size_t Alignment = 8);
 // FIXME: Being forced to not have a default argument here due to redeclaration
 //        rules on default arguments sucks
 void *operator new[](size_t Bytes, const clang::ASTContext &C,
index 57621a7b1f647d5158d2b20bcb52ba88613b2ec8..899f8c5ff5246274aa138ea81e88c0c8c14e85f7 100644 (file)
@@ -3358,7 +3358,7 @@ ASTContext::getElaboratedType(ElaboratedTypeKeyword Keyword,
     (void)CheckT;
   }
 
-  T = new (*this) ElaboratedType(Keyword, NNS, NamedType, Canon);
+  T = new (*this, TypeAlignment) ElaboratedType(Keyword, NNS, NamedType, Canon);
   Types.push_back(T);
   ElaboratedTypes.InsertNode(T, InsertPos);
   return QualType(T, 0);
@@ -3382,7 +3382,7 @@ ASTContext::getParenType(QualType InnerType) const {
     (void)CheckT;
   }
 
-  T = new (*this) ParenType(InnerType, Canon);
+  T = new (*this, TypeAlignment) ParenType(InnerType, Canon);
   Types.push_back(T);
   ParenTypes.InsertNode(T, InsertPos);
   return QualType(T, 0);
@@ -3411,7 +3411,7 @@ QualType ASTContext::getDependentNameType(ElaboratedTypeKeyword Keyword,
   if (T)
     return QualType(T, 0);
 
-  T = new (*this) DependentNameType(Keyword, NNS, Name, Canon);
+  T = new (*this, TypeAlignment) DependentNameType(Keyword, NNS, Name, Canon);
   Types.push_back(T);
   DependentNameTypes.InsertNode(T, InsertPos);
   return QualType(T, 0);
@@ -3513,7 +3513,8 @@ QualType ASTContext::getPackExpansionType(QualType Pattern,
     }
   }
 
-  T = new (*this) PackExpansionType(Pattern, Canon, NumExpansions);
+  T = new (*this, TypeAlignment)
+      PackExpansionType(Pattern, Canon, NumExpansions);
   Types.push_back(T);
   PackExpansionTypes.InsertNode(T, InsertPos);
   return QualType(T, 0);