[PATCH] D94224: [clang][AST] Get rid of an alignment hack in DeclObjC.h [NFCI]

Mikhail Maltsev via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 7 04:00:23 PST 2021


miyuki created this revision.
miyuki added reviewers: dexonsmith, aprantl.
miyuki requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

This patch utilizes the `alignas` specifier and removes the workaround
which used a union object for the same purpose. Removing the union
allows using the SourceRange class directly instead of re-implementing
it with raw representations of source locations.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D94224

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
@@ -1461,9 +1461,8 @@
 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());
 }
 
Index: clang/include/clang/AST/DeclObjC.h
===================================================================
--- clang/include/clang/AST/DeclObjC.h
+++ clang/include/clang/AST/DeclObjC.h
@@ -656,20 +656,8 @@
 /// \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.
+  alignas(ObjCTypeParamDecl *) SourceRange Brackets;
   /// The number of parameters in the list, which are tail-allocated.
   unsigned NumParams;
 
@@ -718,15 +706,15 @@
   }
 
   SourceLocation getLAngleLoc() const {
-    return SourceLocation::getFromRawEncoding(Brackets.Begin);
+    return Brackets.getBegin();
   }
 
   SourceLocation getRAngleLoc() const {
-    return SourceLocation::getFromRawEncoding(Brackets.End);
+    return Brackets.getEnd();
   }
 
   SourceRange getSourceRange() const {
-    return SourceRange(getLAngleLoc(), getRAngleLoc());
+    return Brackets;
   }
 
   /// Gather the default set of type arguments to be substituted for


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D94224.315086.patch
Type: text/x-patch
Size: 2027 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210107/3e93b3f9/attachment.bin>


More information about the cfe-commits mailing list