simon_tatham updated this revision to Diff 360101. simon_tatham edited the summary of this revision. simon_tatham added a comment.
Split up the allocations as suggested. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D105498/new/ https://reviews.llvm.org/D105498 Files: clang/include/clang/AST/DeclObjC.h clang/lib/AST/DeclObjC.cpp
Index: clang/lib/AST/DeclObjC.cpp =================================================================== --- clang/lib/AST/DeclObjC.cpp +++ 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 <algorithm> #include <cassert> @@ -867,21 +868,21 @@ } void ObjCMethodDecl::setParamsAndSelLocs(ASTContext &C, - ArrayRef<ParmVarDecl*> Params, - ArrayRef<SourceLocation> SelLocs) { - ParamsAndSelLocs = nullptr; - NumParams = Params.size(); - if (Params.empty() && SelLocs.empty()) - return; - - static_assert(alignof(ParmVarDecl *) >= alignof(SourceLocation), - "Alignment not sufficient for SourceLocation"); + ArrayRef<ParmVarDecl *> ParamsIn, + ArrayRef<SourceLocation> SelLocsIn) { + Params = nullptr; + NumParams = ParamsIn.size(); + SelLocs = nullptr; + + if (!ParamsIn.empty()) { + Params = C.Allocate<ParmVarDecl *>(ParamsIn.size()); + std::copy(ParamsIn.begin(), ParamsIn.end(), Params); + } - unsigned Size = sizeof(ParmVarDecl *) * NumParams + - sizeof(SourceLocation) * SelLocs.size(); - ParamsAndSelLocs = C.Allocate(Size); - std::copy(Params.begin(), Params.end(), getParams()); - std::copy(SelLocs.begin(), SelLocs.end(), getStoredSelLocs()); + if (!SelLocsIn.empty()) { + SelLocs = C.Allocate<SourceLocation>(SelLocsIn.size()); + std::copy(SelLocsIn.begin(), SelLocsIn.end(), SelLocs); + } } void ObjCMethodDecl::getSelectorLocs( Index: clang/include/clang/AST/DeclObjC.h =================================================================== --- clang/include/clang/AST/DeclObjC.h +++ clang/include/clang/AST/DeclObjC.h @@ -150,11 +150,13 @@ /// Type source information for the return type. TypeSourceInfo *ReturnTInfo; - /// Array of ParmVarDecls for the formal parameters of this method - /// and optionally followed by selector locations. - void *ParamsAndSelLocs = nullptr; + /// Array of the formal parameters of this method. + ParmVarDecl **Params = nullptr; unsigned NumParams = 0; + /// Source locations for the selector identifiers. + SourceLocation *SelLocs = nullptr; + /// List of attributes for this method declaration. SourceLocation DeclEndLoc; // the location of the ';' or '{'. @@ -190,22 +192,20 @@ return getSelLocsKind() != SelLoc_NonStandard; } - /// Get a pointer to the stored selector identifiers locations array. - /// No locations will be stored if HasStandardSelLocs is true. - SourceLocation *getStoredSelLocs() { - return reinterpret_cast<SourceLocation *>(getParams() + NumParams); - } - const SourceLocation *getStoredSelLocs() const { - return reinterpret_cast<const SourceLocation *>(getParams() + NumParams); + size_t getStoredSelLocsOffset() const { + return llvm::alignTo<alignof(SourceLocation)>(sizeof(ParmVarDecl *) * + NumParams); } /// Get a pointer to the stored selector identifiers locations array. /// No locations will be stored if HasStandardSelLocs is true. - ParmVarDecl **getParams() { - return reinterpret_cast<ParmVarDecl **>(ParamsAndSelLocs); - } + SourceLocation *getStoredSelLocs() { return SelLocs; } + const SourceLocation *getStoredSelLocs() const { return SelLocs; } + + /// Get a pointer to the parameter array. + ParmVarDecl **getParams() { return Params; } const ParmVarDecl *const *getParams() const { - return reinterpret_cast<const ParmVarDecl *const *>(ParamsAndSelLocs); + return const_cast<const ParmVarDecl *const *>(Params); } /// Get the number of stored selector identifiers locations.
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits