diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-08-15 01:22:58 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-08-15 01:22:58 +0000 |
commit | 97f6026f460c3aaa250fc9dcd7c2b8b6c1f3ba69 (patch) | |
tree | ef775a3afd789e38aa1180dbd8d42afea6c8d072 | |
parent | 09647f28d7955d0c948ebbbb376a46844056f11a (diff) |
Fix overallocation and underalignment of ASTTemplateArgumentListInfo objects.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@161918 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | include/clang/AST/TemplateBase.h | 20 | ||||
-rw-r--r-- | lib/AST/TemplateBase.cpp | 6 |
2 files changed, 16 insertions, 10 deletions
diff --git a/include/clang/AST/TemplateBase.h b/include/clang/AST/TemplateBase.h index 54c9f2c534..5047028e5e 100644 --- a/include/clang/AST/TemplateBase.h +++ b/include/clang/AST/TemplateBase.h @@ -510,17 +510,23 @@ public: /// This is safe to be used inside an AST node, in contrast with /// TemplateArgumentListInfo. struct ASTTemplateArgumentListInfo { - /// \brief The source location of the left angle bracket ('<'); + /// \brief The source location of the left angle bracket ('<'). SourceLocation LAngleLoc; - /// \brief The source location of the right angle bracket ('>'); + /// \brief The source location of the right angle bracket ('>'). SourceLocation RAngleLoc; - /// \brief The number of template arguments in TemplateArgs. - /// The actual template arguments (if any) are stored after the - /// ExplicitTemplateArgumentList structure. - unsigned NumTemplateArgs; - + union { + /// \brief The number of template arguments in TemplateArgs. + /// The actual template arguments (if any) are stored after the + /// ExplicitTemplateArgumentList structure. + unsigned NumTemplateArgs; + + /// Force ASTTemplateArgumentListInfo to the right alignment + /// for the following array of TemplateArgumentLocs. + void *Aligner; + }; + /// \brief Retrieve the template arguments TemplateArgumentLoc *getTemplateArgs() { return reinterpret_cast<TemplateArgumentLoc *> (this + 1); diff --git a/lib/AST/TemplateBase.cpp b/lib/AST/TemplateBase.cpp index f8dd396d92..95ff4edf1d 100644 --- a/lib/AST/TemplateBase.cpp +++ b/lib/AST/TemplateBase.cpp @@ -556,8 +556,7 @@ const DiagnosticBuilder &clang::operator<<(const DiagnosticBuilder &DB, const ASTTemplateArgumentListInfo * ASTTemplateArgumentListInfo::Create(ASTContext &C, const TemplateArgumentListInfo &List) { - std::size_t size = sizeof(CXXDependentScopeMemberExpr) + - ASTTemplateArgumentListInfo::sizeFor(List.size()); + std::size_t size = ASTTemplateArgumentListInfo::sizeFor(List.size()); void *Mem = C.Allocate(size, llvm::alignOf<ASTTemplateArgumentListInfo>()); ASTTemplateArgumentListInfo *TAI = new (Mem) ASTTemplateArgumentListInfo(); TAI->initializeFrom(List); @@ -642,6 +641,7 @@ ASTTemplateKWAndArgsInfo::initializeFrom(SourceLocation TemplateKWLoc) { std::size_t ASTTemplateKWAndArgsInfo::sizeFor(unsigned NumTemplateArgs) { // Add space for the template keyword location. + // FIXME: There's room for this in the padding before the template args in + // 64-bit builds. return Base::sizeFor(NumTemplateArgs) + sizeof(SourceLocation); } - |