From ce93d6f45215830eb0a6fb5de0b8ba56dac3b901 Mon Sep 17 00:00:00 2001 From: Benjamin Kramer Date: Thu, 2 Apr 2015 16:19:54 +0000 Subject: [PATCH] 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@233922 91177308-0d34-0410-b5e6-96231b3b80d8 --- include/clang/AST/Attr.h | 2 +- include/clang/AST/AttrIterator.h | 2 +- lib/AST/ASTContext.cpp | 9 +++++---- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/include/clang/AST/Attr.h b/include/clang/AST/Attr.h index c3e7f2a99f..a854168f01 100644 --- a/include/clang/AST/Attr.h +++ b/include/clang/AST/Attr.h @@ -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, diff --git a/include/clang/AST/AttrIterator.h b/include/clang/AST/AttrIterator.h index 39ee81f120..a0c803096a 100644 --- a/include/clang/AST/AttrIterator.h +++ b/include/clang/AST/AttrIterator.h @@ -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, diff --git a/lib/AST/ASTContext.cpp b/lib/AST/ASTContext.cpp index 57621a7b1f..899f8c5ff5 100644 --- a/lib/AST/ASTContext.cpp +++ b/lib/AST/ASTContext.cpp @@ -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); -- 2.40.0