diff options
author | James Y Knight <jyknight@google.com> | 2015-07-17 18:21:37 +0000 |
---|---|---|
committer | James Y Knight <jyknight@google.com> | 2015-07-17 18:21:37 +0000 |
commit | f9ae22bbac6c066418741e45afc8ea217aab952e (patch) | |
tree | da0adc3b9bc7c43d76a875d1757825097d1ed98a /include/clang/AST/DeclTemplate.h | |
parent | d6a363a733682e145306fc1e42152e8519166b48 (diff) |
Fix alignment issues in Clang.
Some const-correctness changes snuck in here too, since they were in the
area of code I was modifying.
This seems to make Clang actually work without Bus Error on
32bit-sparc.
Follow-up patches will factor out a trailing-object helper class, to
make classes using the idiom of appending objects to other objects
easier to understand, and to ensure (with static_assert) that required
alignment guarantees continue to hold.
Differential Revision: http://reviews.llvm.org/D10272
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@242554 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'include/clang/AST/DeclTemplate.h')
-rw-r--r-- | include/clang/AST/DeclTemplate.h | 36 |
1 files changed, 12 insertions, 24 deletions
diff --git a/include/clang/AST/DeclTemplate.h b/include/clang/AST/DeclTemplate.h index 0fc9b4947d..44b907f749 100644 --- a/include/clang/AST/DeclTemplate.h +++ b/include/clang/AST/DeclTemplate.h @@ -43,7 +43,7 @@ typedef llvm::PointerUnion3<TemplateTypeParmDecl*, NonTypeTemplateParmDecl*, /// \brief Stores a list of template parameters for a TemplateDecl and its /// derived classes. -class TemplateParameterList { +class LLVM_ALIGNAS(/*alignof(void*)*/ LLVM_PTR_SIZE) TemplateParameterList { /// The location of the 'template' keyword. SourceLocation TemplateLoc; @@ -542,27 +542,20 @@ public: /// friend void foo<>(T); /// }; /// \endcode -class DependentFunctionTemplateSpecializationInfo { - struct CA { - /// The number of potential template candidates. - unsigned NumTemplates; +class LLVM_ALIGNAS(/*alignof(uint64_t)*/ 8) + DependentFunctionTemplateSpecializationInfo { + /// The number of potential template candidates. + unsigned NumTemplates; - /// The number of template arguments. - unsigned NumArgs; - }; - - union { - // Force sizeof to be a multiple of sizeof(void*) so that the - // trailing data is aligned. - void *Aligner; - struct CA d; - }; + /// The number of template arguments. + unsigned NumArgs; /// The locations of the left and right angle brackets. SourceRange AngleLocs; FunctionTemplateDecl * const *getTemplates() const { - return reinterpret_cast<FunctionTemplateDecl*const*>(this+1); + return reinterpret_cast<FunctionTemplateDecl *const *>( + &getTemplateArgs()[NumArgs]); } public: @@ -572,9 +565,7 @@ public: /// \brief Returns the number of function templates that this might /// be a specialization of. - unsigned getNumTemplates() const { - return d.NumTemplates; - } + unsigned getNumTemplates() const { return NumTemplates; } /// \brief Returns the i'th template candidate. FunctionTemplateDecl *getTemplate(unsigned I) const { @@ -584,14 +575,11 @@ public: /// \brief Returns the explicit template arguments that were given. const TemplateArgumentLoc *getTemplateArgs() const { - return reinterpret_cast<const TemplateArgumentLoc*>( - &getTemplates()[getNumTemplates()]); + return reinterpret_cast<const TemplateArgumentLoc *>(this + 1); } /// \brief Returns the number of explicit template arguments that were given. - unsigned getNumTemplateArgs() const { - return d.NumArgs; - } + unsigned getNumTemplateArgs() const { return NumArgs; } /// \brief Returns the nth template argument. const TemplateArgumentLoc &getTemplateArg(unsigned I) const { |