diff --git a/clang/include/clang/AST/DeclObjC.h b/clang/include/clang/AST/DeclObjC.h --- a/clang/include/clang/AST/DeclObjC.h +++ b/clang/include/clang/AST/DeclObjC.h @@ -190,13 +190,20 @@ return getSelLocsKind() != SelLoc_NonStandard; } + size_t getStoredSelLocsOffset() const { + return llvm::alignTo(sizeof(ParmVarDecl *) * + NumParams); + } + /// Get a pointer to the stored selector identifiers locations array. /// No locations will be stored if HasStandardSelLocs is true. SourceLocation *getStoredSelLocs() { - return reinterpret_cast(getParams() + NumParams); + return reinterpret_cast( + reinterpret_cast(ParamsAndSelLocs) + getStoredSelLocsOffset()); } const SourceLocation *getStoredSelLocs() const { - return reinterpret_cast(getParams() + NumParams); + return reinterpret_cast( + reinterpret_cast(ParamsAndSelLocs) + getStoredSelLocsOffset()); } /// Get a pointer to the stored selector identifiers locations array. diff --git a/clang/lib/AST/DeclObjC.cpp b/clang/lib/AST/DeclObjC.cpp --- a/clang/lib/AST/DeclObjC.cpp +++ b/clang/lib/AST/DeclObjC.cpp @@ -28,6 +28,7 @@ #include "llvm/ADT/SmallVector.h" #include "llvm/Support/Casting.h" #include "llvm/Support/ErrorHandling.h" +#include "llvm/Support/MathExtras.h" #include "llvm/Support/raw_ostream.h" #include #include @@ -874,11 +875,8 @@ if (Params.empty() && SelLocs.empty()) return; - static_assert(alignof(ParmVarDecl *) >= alignof(SourceLocation), - "Alignment not sufficient for SourceLocation"); - - unsigned Size = sizeof(ParmVarDecl *) * NumParams + - sizeof(SourceLocation) * SelLocs.size(); + unsigned Size = + getStoredSelLocsOffset() + sizeof(SourceLocation) * SelLocs.size(); ParamsAndSelLocs = C.Allocate(Size); std::copy(Params.begin(), Params.end(), getParams()); std::copy(SelLocs.begin(), SelLocs.end(), getStoredSelLocs());