r233922 - Lower the default alignment on ASTContext's operator new.

Benjamin Kramer benny.kra at googlemail.com
Thu Apr 2 09:19:54 PDT 2015


Author: d0k
Date: Thu Apr  2 11:19:54 2015
New Revision: 233922

URL: http://llvm.org/viewvc/llvm-project?rev=233922&view=rev
Log:
Lower the default alignment on ASTContext's operator new.

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.

Modified:
    cfe/trunk/include/clang/AST/Attr.h
    cfe/trunk/include/clang/AST/AttrIterator.h
    cfe/trunk/lib/AST/ASTContext.cpp

Modified: cfe/trunk/include/clang/AST/Attr.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Attr.h?rev=233922&r1=233921&r2=233922&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Attr.h (original)
+++ cfe/trunk/include/clang/AST/Attr.h Thu Apr  2 11:19:54 2015
@@ -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,

Modified: cfe/trunk/include/clang/AST/AttrIterator.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/AttrIterator.h?rev=233922&r1=233921&r2=233922&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/AttrIterator.h (original)
+++ cfe/trunk/include/clang/AST/AttrIterator.h Thu Apr  2 11:19:54 2015
@@ -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,

Modified: cfe/trunk/lib/AST/ASTContext.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/AST/ASTContext.cpp?rev=233922&r1=233921&r2=233922&view=diff
==============================================================================
--- cfe/trunk/lib/AST/ASTContext.cpp (original)
+++ cfe/trunk/lib/AST/ASTContext.cpp Thu Apr  2 11:19:54 2015
@@ -3358,7 +3358,7 @@ ASTContext::getElaboratedType(Elaborated
     (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 InnerT
     (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::getDependentNameTyp
   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::getPackExpansionTyp
     }
   }
 
-  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);





More information about the cfe-commits mailing list