[PATCH] D105498: [clang] Remove assumption about SourceLocation alignment.
Simon Tatham via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Jul 20 07:23:48 PDT 2021
simon_tatham updated this revision to Diff 360123.
simon_tatham added a comment.
Addressed two nits.
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
@@ -867,21 +867,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 '{'.
@@ -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<SourceLocation *>(getParams() + NumParams);
- }
- const SourceLocation *getStoredSelLocs() const {
- return reinterpret_cast<const SourceLocation *>(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<ParmVarDecl **>(ParamsAndSelLocs);
- }
- const ParmVarDecl *const *getParams() const {
- return reinterpret_cast<const ParmVarDecl *const *>(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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D105498.360123.patch
Type: text/x-patch
Size: 3510 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210720/3530f167/attachment.bin>
More information about the cfe-commits
mailing list