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 @@ -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 '{'. @@ -192,21 +194,12 @@ /// 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); - } - const SourceLocation *getStoredSelLocs() const { - return reinterpret_cast(getParams() + NumParams); - } + SourceLocation *getStoredSelLocs() { return SelLocs; } + const SourceLocation *getStoredSelLocs() const { return SelLocs; } - /// Get a pointer to the stored selector identifiers locations array. - /// No locations will be stored if HasStandardSelLocs is true. - ParmVarDecl **getParams() { - return reinterpret_cast(ParamsAndSelLocs); - } - const ParmVarDecl *const *getParams() const { - return reinterpret_cast(ParamsAndSelLocs); - } + /// Get a pointer to the parameter array. + ParmVarDecl **getParams() { return Params; } + const ParmVarDecl *const *getParams() const { return Params; } /// Get the number of stored selector identifiers locations. /// No locations will be stored if HasStandardSelLocs is true. 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 @@ -867,21 +867,21 @@ } void ObjCMethodDecl::setParamsAndSelLocs(ASTContext &C, - ArrayRef Params, - ArrayRef SelLocs) { - ParamsAndSelLocs = nullptr; - NumParams = Params.size(); - if (Params.empty() && SelLocs.empty()) - return; - - static_assert(alignof(ParmVarDecl *) >= alignof(SourceLocation), - "Alignment not sufficient for SourceLocation"); + ArrayRef ParamsIn, + ArrayRef SelLocsIn) { + Params = nullptr; + NumParams = ParamsIn.size(); + SelLocs = nullptr; + + if (!ParamsIn.empty()) { + Params = C.Allocate(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(SelLocsIn.size()); + std::copy(SelLocsIn.begin(), SelLocsIn.end(), SelLocs); + } } void ObjCMethodDecl::getSelectorLocs(