[clang] c1e08f0 - [clang][AST] Get rid of an alignment hack in DeclObjC.h [NFCI]
Mikhail Maltsev via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 12 02:22:49 PST 2021
Author: Mikhail Maltsev
Date: 2021-01-12T10:22:35Z
New Revision: c1e08f0073e35cf17c0a0343cf7efff914dbd66d
URL: https://github.com/llvm/llvm-project/commit/c1e08f0073e35cf17c0a0343cf7efff914dbd66d
DIFF: https://github.com/llvm/llvm-project/commit/c1e08f0073e35cf17c0a0343cf7efff914dbd66d.diff
LOG: [clang][AST] Get rid of an alignment hack in DeclObjC.h [NFCI]
This code currently uses a union object to increase the
alignment of the type ObjCTypeParamList. The original intent of this
trick was to be able to use the expression `this + 1` to access the
beginning of a tail-allocated array of `ObjCTypeParamDecl *` pointers.
The code has since been refactored and uses `llvm::TrailingObjects` to
manage the tail-allocated array. This template takes care of
alignment, so the hack is no longer necessary.
This patch removes the union so that the `SourceRange` class can be
used directly instead of being re-implemented with raw representations
of source locations.
Reviewed By: aprantl
Differential Revision: https://reviews.llvm.org/D94224
Added:
Modified:
clang/include/clang/AST/DeclObjC.h
clang/lib/AST/DeclObjC.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/AST/DeclObjC.h b/clang/include/clang/AST/DeclObjC.h
index 88cedbd91b6d..b1bce069920c 100644
--- a/clang/include/clang/AST/DeclObjC.h
+++ b/clang/include/clang/AST/DeclObjC.h
@@ -656,20 +656,8 @@ class ObjCTypeParamDecl : public TypedefNameDecl {
/// \endcode
class ObjCTypeParamList final
: private llvm::TrailingObjects<ObjCTypeParamList, ObjCTypeParamDecl *> {
- /// Stores the components of a SourceRange as a POD.
- struct PODSourceRange {
- unsigned Begin;
- unsigned End;
- };
-
- union {
- /// Location of the left and right angle brackets.
- PODSourceRange Brackets;
-
- // Used only for alignment.
- ObjCTypeParamDecl *AlignmentHack;
- };
-
+ /// Location of the left and right angle brackets.
+ SourceRange Brackets;
/// The number of parameters in the list, which are tail-allocated.
unsigned NumParams;
@@ -717,17 +705,9 @@ class ObjCTypeParamList final
return *(end() - 1);
}
- SourceLocation getLAngleLoc() const {
- return SourceLocation::getFromRawEncoding(Brackets.Begin);
- }
-
- SourceLocation getRAngleLoc() const {
- return SourceLocation::getFromRawEncoding(Brackets.End);
- }
-
- SourceRange getSourceRange() const {
- return SourceRange(getLAngleLoc(), getRAngleLoc());
- }
+ SourceLocation getLAngleLoc() const { return Brackets.getBegin(); }
+ SourceLocation getRAngleLoc() const { return Brackets.getEnd(); }
+ SourceRange getSourceRange() const { return Brackets; }
/// Gather the default set of type arguments to be substituted for
/// these type parameters when dealing with an unspecialized type.
diff --git a/clang/lib/AST/DeclObjC.cpp b/clang/lib/AST/DeclObjC.cpp
index 961230fb54ce..5f82fcec90e3 100644
--- a/clang/lib/AST/DeclObjC.cpp
+++ b/clang/lib/AST/DeclObjC.cpp
@@ -1461,9 +1461,7 @@ SourceRange ObjCTypeParamDecl::getSourceRange() const {
ObjCTypeParamList::ObjCTypeParamList(SourceLocation lAngleLoc,
ArrayRef<ObjCTypeParamDecl *> typeParams,
SourceLocation rAngleLoc)
- : NumParams(typeParams.size()) {
- Brackets.Begin = lAngleLoc.getRawEncoding();
- Brackets.End = rAngleLoc.getRawEncoding();
+ : Brackets(lAngleLoc, rAngleLoc), NumParams(typeParams.size()) {
std::copy(typeParams.begin(), typeParams.end(), begin());
}
More information about the cfe-commits
mailing list