[llvm-branch-commits] [clang] 17f8c45 - [clang] Use SourceLocations in unions [NFCI]

Mikhail Maltsev via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Jan 14 03:02:07 PST 2021


Author: Mikhail Maltsev
Date: 2021-01-14T10:56:53Z
New Revision: 17f8c458de631c0311828931a5bdf72b1a13c29d

URL: https://github.com/llvm/llvm-project/commit/17f8c458de631c0311828931a5bdf72b1a13c29d
DIFF: https://github.com/llvm/llvm-project/commit/17f8c458de631c0311828931a5bdf72b1a13c29d.diff

LOG: [clang] Use SourceLocations in unions [NFCI]

Currently, there are many instances where `SourceLocation` objects are
converted to raw representation to be stored in structs that are
used as fields of tagged unions.

This is done to make the corresponding structs trivial.
Triviality allows avoiding undefined behavior when implicitly changing
the active member of the union.

However, in most cases, we can explicitly construct an active member
using placement new. This patch adds the required active member
selections and replaces `SourceLocation`-s represented as
`unsigned int` with proper `SourceLocation`-s.

One notable exception is `DeclarationNameLoc`: the objects of this class
are often not properly initialized (so the code currently relies on
its default constructor which uses memset). This class will be fixed
in a separate patch.

Reviewed By: dblaikie

Differential Revision: https://reviews.llvm.org/D94237

Added: 
    

Modified: 
    clang/include/clang/AST/DependentDiagnostic.h
    clang/include/clang/AST/Expr.h
    clang/include/clang/AST/TemplateBase.h
    clang/include/clang/Basic/SourceManager.h
    clang/include/clang/Sema/DeclSpec.h
    clang/include/clang/Sema/Designator.h
    clang/include/clang/Sema/Initialization.h
    clang/lib/AST/Expr.cpp
    clang/lib/AST/TemplateBase.cpp
    clang/lib/Parse/ParseDeclCXX.cpp
    clang/lib/Sema/DeclSpec.cpp
    clang/lib/Sema/SemaDecl.cpp
    clang/lib/Sema/SemaExpr.cpp
    clang/lib/Sema/SemaType.cpp

Removed: 
    


################################################################################
diff  --git a/clang/include/clang/AST/DependentDiagnostic.h b/clang/include/clang/AST/DependentDiagnostic.h
index 5a8624608e74..18276d54d540 100644
--- a/clang/include/clang/AST/DependentDiagnostic.h
+++ b/clang/include/clang/AST/DependentDiagnostic.h
@@ -48,7 +48,7 @@ class DependentDiagnostic {
                                      QualType BaseObjectType,
                                      const PartialDiagnostic &PDiag) {
     DependentDiagnostic *DD = Create(Context, Parent, PDiag);
-    DD->AccessData.Loc = Loc.getRawEncoding();
+    DD->AccessData.Loc = Loc;
     DD->AccessData.IsMember = IsMemberAccess;
     DD->AccessData.Access = AS;
     DD->AccessData.TargetDecl = TargetDecl;
@@ -73,7 +73,7 @@ class DependentDiagnostic {
 
   SourceLocation getAccessLoc() const {
     assert(getKind() == Access);
-    return SourceLocation::getFromRawEncoding(AccessData.Loc);
+    return AccessData.Loc;
   }
 
   NamedDecl *getAccessTarget() const {
@@ -112,7 +112,7 @@ class DependentDiagnostic {
   PartialDiagnostic Diag;
 
   struct {
-    unsigned Loc;
+    SourceLocation Loc;
     unsigned Access : 2;
     unsigned IsMember : 1;
     NamedDecl *TargetDecl;

diff  --git a/clang/include/clang/AST/Expr.h b/clang/include/clang/AST/Expr.h
index c8d87ec48a3f..a44d06967431 100644
--- a/clang/include/clang/AST/Expr.h
+++ b/clang/include/clang/AST/Expr.h
@@ -4994,10 +4994,10 @@ class DesignatedInitExpr final
     uintptr_t NameOrField;
 
     /// The location of the '.' in the designated initializer.
-    unsigned DotLoc;
+    SourceLocation DotLoc;
 
     /// The location of the field name in the designated initializer.
-    unsigned FieldLoc;
+    SourceLocation FieldLoc;
   };
 
   /// An array or GNU array-range designator, e.g., "[9]" or "[10..15]".
@@ -5006,12 +5006,12 @@ class DesignatedInitExpr final
     /// initializer expression's list of subexpressions.
     unsigned Index;
     /// The location of the '[' starting the array range designator.
-    unsigned LBracketLoc;
+    SourceLocation LBracketLoc;
     /// The location of the ellipsis separating the start and end
     /// indices. Only valid for GNU array-range designators.
-    unsigned EllipsisLoc;
+    SourceLocation EllipsisLoc;
     /// The location of the ']' terminating the array range designator.
-    unsigned RBracketLoc;
+    SourceLocation RBracketLoc;
   };
 
   /// Represents a single C99 designator.
@@ -5043,29 +5043,32 @@ class DesignatedInitExpr final
     Designator(const IdentifierInfo *FieldName, SourceLocation DotLoc,
                SourceLocation FieldLoc)
       : Kind(FieldDesignator) {
+      new (&Field) DesignatedInitExpr::FieldDesignator;
       Field.NameOrField = reinterpret_cast<uintptr_t>(FieldName) | 0x01;
-      Field.DotLoc = DotLoc.getRawEncoding();
-      Field.FieldLoc = FieldLoc.getRawEncoding();
+      Field.DotLoc = DotLoc;
+      Field.FieldLoc = FieldLoc;
     }
 
     /// Initializes an array designator.
     Designator(unsigned Index, SourceLocation LBracketLoc,
                SourceLocation RBracketLoc)
       : Kind(ArrayDesignator) {
+      new (&ArrayOrRange) DesignatedInitExpr::ArrayOrRangeDesignator;
       ArrayOrRange.Index = Index;
-      ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
-      ArrayOrRange.EllipsisLoc = SourceLocation().getRawEncoding();
-      ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
+      ArrayOrRange.LBracketLoc = LBracketLoc;
+      ArrayOrRange.EllipsisLoc = SourceLocation();
+      ArrayOrRange.RBracketLoc = RBracketLoc;
     }
 
     /// Initializes a GNU array-range designator.
     Designator(unsigned Index, SourceLocation LBracketLoc,
                SourceLocation EllipsisLoc, SourceLocation RBracketLoc)
       : Kind(ArrayRangeDesignator) {
+      new (&ArrayOrRange) DesignatedInitExpr::ArrayOrRangeDesignator;
       ArrayOrRange.Index = Index;
-      ArrayOrRange.LBracketLoc = LBracketLoc.getRawEncoding();
-      ArrayOrRange.EllipsisLoc = EllipsisLoc.getRawEncoding();
-      ArrayOrRange.RBracketLoc = RBracketLoc.getRawEncoding();
+      ArrayOrRange.LBracketLoc = LBracketLoc;
+      ArrayOrRange.EllipsisLoc = EllipsisLoc;
+      ArrayOrRange.RBracketLoc = RBracketLoc;
     }
 
     bool isFieldDesignator() const { return Kind == FieldDesignator; }
@@ -5089,30 +5092,30 @@ class DesignatedInitExpr final
 
     SourceLocation getDotLoc() const {
       assert(Kind == FieldDesignator && "Only valid on a field designator");
-      return SourceLocation::getFromRawEncoding(Field.DotLoc);
+      return Field.DotLoc;
     }
 
     SourceLocation getFieldLoc() const {
       assert(Kind == FieldDesignator && "Only valid on a field designator");
-      return SourceLocation::getFromRawEncoding(Field.FieldLoc);
+      return Field.FieldLoc;
     }
 
     SourceLocation getLBracketLoc() const {
       assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
              "Only valid on an array or array-range designator");
-      return SourceLocation::getFromRawEncoding(ArrayOrRange.LBracketLoc);
+      return ArrayOrRange.LBracketLoc;
     }
 
     SourceLocation getRBracketLoc() const {
       assert((Kind == ArrayDesignator || Kind == ArrayRangeDesignator) &&
              "Only valid on an array or array-range designator");
-      return SourceLocation::getFromRawEncoding(ArrayOrRange.RBracketLoc);
+      return ArrayOrRange.RBracketLoc;
     }
 
     SourceLocation getEllipsisLoc() const {
       assert(Kind == ArrayRangeDesignator &&
              "Only valid on an array-range designator");
-      return SourceLocation::getFromRawEncoding(ArrayOrRange.EllipsisLoc);
+      return ArrayOrRange.EllipsisLoc;
     }
 
     unsigned getFirstExprIndex() const {

diff  --git a/clang/include/clang/AST/TemplateBase.h b/clang/include/clang/AST/TemplateBase.h
index 7967f8a91214..1671637521e2 100644
--- a/clang/include/clang/AST/TemplateBase.h
+++ b/clang/include/clang/AST/TemplateBase.h
@@ -409,8 +409,8 @@ struct TemplateArgumentLocInfo {
     // but template arguments get canonicalized too quickly.
     NestedNameSpecifier *Qualifier;
     void *QualifierLocData;
-    unsigned TemplateNameLoc;
-    unsigned EllipsisLoc;
+    SourceLocation TemplateNameLoc;
+    SourceLocation EllipsisLoc;
   };
 
   llvm::PointerUnion<TemplateTemplateArgLocInfo *, Expr *, TypeSourceInfo *>
@@ -444,11 +444,11 @@ struct TemplateArgumentLocInfo {
   }
 
   SourceLocation getTemplateNameLoc() const {
-    return SourceLocation::getFromRawEncoding(getTemplate()->TemplateNameLoc);
+    return getTemplate()->TemplateNameLoc;
   }
 
   SourceLocation getTemplateEllipsisLoc() const {
-    return SourceLocation::getFromRawEncoding(getTemplate()->EllipsisLoc);
+    return getTemplate()->EllipsisLoc;
   }
 };
 

diff  --git a/clang/include/clang/Basic/SourceManager.h b/clang/include/clang/Basic/SourceManager.h
index a43b47662180..af3714b929f8 100644
--- a/clang/include/clang/Basic/SourceManager.h
+++ b/clang/include/clang/Basic/SourceManager.h
@@ -287,7 +287,7 @@ class FileInfo {
   /// The location of the \#include that brought in this file.
   ///
   /// This is an invalid SLOC for the main file (top of the \#include chain).
-  unsigned IncludeLoc; // Really a SourceLocation
+  SourceLocation IncludeLoc;
 
   /// Number of FileIDs (files and macros) that were created during
   /// preprocessing of this \#include, including this SLocEntry.
@@ -307,7 +307,7 @@ class FileInfo {
   static FileInfo get(SourceLocation IL, ContentCache &Con,
                       CharacteristicKind FileCharacter, StringRef Filename) {
     FileInfo X;
-    X.IncludeLoc = IL.getRawEncoding();
+    X.IncludeLoc = IL;
     X.NumCreatedFIDs = 0;
     X.HasLineDirectives = false;
     X.ContentAndKind.setPointer(&Con);
@@ -317,7 +317,7 @@ class FileInfo {
   }
 
   SourceLocation getIncludeLoc() const {
-    return SourceLocation::getFromRawEncoding(IncludeLoc);
+    return IncludeLoc;
   }
 
   const ContentCache &getContentCache() const {
@@ -348,7 +348,7 @@ class ExpansionInfo {
   // Really these are all SourceLocations.
 
   /// Where the spelling for the token can be found.
-  unsigned SpellingLoc;
+  SourceLocation SpellingLoc;
 
   /// In a macro expansion, ExpansionLocStart and ExpansionLocEnd
   /// indicate the start and end of the expansion. In object-like macros,
@@ -356,24 +356,23 @@ class ExpansionInfo {
   /// will be the identifier and the end will be the ')'. Finally, in
   /// macro-argument instantiations, the end will be 'SourceLocation()', an
   /// invalid location.
-  unsigned ExpansionLocStart, ExpansionLocEnd;
+  SourceLocation ExpansionLocStart, ExpansionLocEnd;
 
   /// Whether the expansion range is a token range.
   bool ExpansionIsTokenRange;
 
 public:
   SourceLocation getSpellingLoc() const {
-    SourceLocation SpellLoc = SourceLocation::getFromRawEncoding(SpellingLoc);
-    return SpellLoc.isInvalid() ? getExpansionLocStart() : SpellLoc;
+    return SpellingLoc.isInvalid() ? getExpansionLocStart() : SpellingLoc;
   }
 
   SourceLocation getExpansionLocStart() const {
-    return SourceLocation::getFromRawEncoding(ExpansionLocStart);
+    return ExpansionLocStart;
   }
 
   SourceLocation getExpansionLocEnd() const {
-    SourceLocation EndLoc = SourceLocation::getFromRawEncoding(ExpansionLocEnd);
-    return EndLoc.isInvalid() ? getExpansionLocStart() : EndLoc;
+    return ExpansionLocEnd.isInvalid() ? getExpansionLocStart()
+                                       : ExpansionLocEnd;
   }
 
   bool isExpansionTokenRange() const { return ExpansionIsTokenRange; }
@@ -386,13 +385,11 @@ class ExpansionInfo {
 
   bool isMacroArgExpansion() const {
     // Note that this needs to return false for default constructed objects.
-    return getExpansionLocStart().isValid() &&
-           SourceLocation::getFromRawEncoding(ExpansionLocEnd).isInvalid();
+    return getExpansionLocStart().isValid() && ExpansionLocEnd.isInvalid();
   }
 
   bool isMacroBodyExpansion() const {
-    return getExpansionLocStart().isValid() &&
-           SourceLocation::getFromRawEncoding(ExpansionLocEnd).isValid();
+    return getExpansionLocStart().isValid() && ExpansionLocEnd.isValid();
   }
 
   bool isFunctionMacroExpansion() const {
@@ -410,9 +407,9 @@ class ExpansionInfo {
                               SourceLocation End,
                               bool ExpansionIsTokenRange = true) {
     ExpansionInfo X;
-    X.SpellingLoc = SpellingLoc.getRawEncoding();
-    X.ExpansionLocStart = Start.getRawEncoding();
-    X.ExpansionLocEnd = End.getRawEncoding();
+    X.SpellingLoc = SpellingLoc;
+    X.ExpansionLocStart = Start;
+    X.ExpansionLocEnd = End;
     X.ExpansionIsTokenRange = ExpansionIsTokenRange;
     return X;
   }
@@ -507,7 +504,7 @@ class SLocEntry {
     SLocEntry E;
     E.Offset = Offset;
     E.IsExpansion = true;
-    E.Expansion = Expansion;
+    new (&E.Expansion) ExpansionInfo(Expansion);
     return E;
   }
 };

diff  --git a/clang/include/clang/Sema/DeclSpec.h b/clang/include/clang/Sema/DeclSpec.h
index fb30f95f5914..3b16295941e4 100644
--- a/clang/include/clang/Sema/DeclSpec.h
+++ b/clang/include/clang/Sema/DeclSpec.h
@@ -967,7 +967,7 @@ class UnqualifiedId {
     /// Different operators have 
diff erent numbers of tokens in their name,
     /// up to three. Any remaining source locations in this array will be
     /// set to an invalid value for operators with fewer than three tokens.
-    unsigned SymbolLocations[3];
+    SourceLocation SymbolLocations[3];
   };
 
   /// Anonymous union that holds extra data associated with the
@@ -1030,7 +1030,6 @@ class UnqualifiedId {
 
   /// Determine what kind of name we have.
   UnqualifiedIdKind getKind() const { return Kind; }
-  void setKind(UnqualifiedIdKind kind) { Kind = kind; }
 
   /// Specify that this unqualified-id was parsed as an identifier.
   ///
@@ -1146,6 +1145,16 @@ class UnqualifiedId {
     StartLocation = EndLocation = TemplateLoc;
   }
 
+  /// Specify that this unqualified-id is an implicit 'self'
+  /// parameter.
+  ///
+  /// \param Id the identifier.
+  void setImplicitSelfParam(const IdentifierInfo *Id) {
+    Kind = UnqualifiedIdKind::IK_ImplicitSelfParam;
+    Identifier = const_cast<IdentifierInfo *>(Id);
+    StartLocation = EndLocation = SourceLocation();
+  }
+
   /// Return the source range that covers this unqualified-id.
   SourceRange getSourceRange() const LLVM_READONLY {
     return SourceRange(StartLocation, EndLocation);
@@ -1162,6 +1171,8 @@ typedef SmallVector<Token, 4> CachedTokens;
 ///
 /// This is intended to be a small value object.
 struct DeclaratorChunk {
+  DeclaratorChunk() {};
+
   enum {
     Pointer, Reference, Array, Function, BlockPointer, MemberPointer, Paren, Pipe
   } Kind;
@@ -1184,19 +1195,19 @@ struct DeclaratorChunk {
     unsigned TypeQuals : 5;
 
     /// The location of the const-qualifier, if any.
-    unsigned ConstQualLoc;
+    SourceLocation ConstQualLoc;
 
     /// The location of the volatile-qualifier, if any.
-    unsigned VolatileQualLoc;
+    SourceLocation VolatileQualLoc;
 
     /// The location of the restrict-qualifier, if any.
-    unsigned RestrictQualLoc;
+    SourceLocation RestrictQualLoc;
 
     /// The location of the _Atomic-qualifier, if any.
-    unsigned AtomicQualLoc;
+    SourceLocation AtomicQualLoc;
 
     /// The location of the __unaligned-qualifier, if any.
-    unsigned UnalignedQualLoc;
+    SourceLocation UnalignedQualLoc;
 
     void destroy() {
     }
@@ -1291,13 +1302,13 @@ struct DeclaratorChunk {
     unsigned HasTrailingReturnType : 1;
 
     /// The location of the left parenthesis in the source.
-    unsigned LParenLoc;
+    SourceLocation LParenLoc;
 
     /// When isVariadic is true, the location of the ellipsis in the source.
-    unsigned EllipsisLoc;
+    SourceLocation EllipsisLoc;
 
     /// The location of the right parenthesis in the source.
-    unsigned RParenLoc;
+    SourceLocation RParenLoc;
 
     /// NumParams - This is the number of formal parameters specified by the
     /// declarator.
@@ -1311,17 +1322,17 @@ struct DeclaratorChunk {
     /// The location of the ref-qualifier, if any.
     ///
     /// If this is an invalid location, there is no ref-qualifier.
-    unsigned RefQualifierLoc;
+    SourceLocation RefQualifierLoc;
 
     /// The location of the 'mutable' qualifer in a lambda-declarator, if
     /// any.
-    unsigned MutableLoc;
+    SourceLocation MutableLoc;
 
     /// The beginning location of the exception specification, if any.
-    unsigned ExceptionSpecLocBeg;
+    SourceLocation ExceptionSpecLocBeg;
 
     /// The end location of the exception specification, if any.
-    unsigned ExceptionSpecLocEnd;
+    SourceLocation ExceptionSpecLocEnd;
 
     /// Params - This is a pointer to a new[]'d array of ParamInfo objects that
     /// describe the parameters specified by this function declarator.  null if
@@ -1360,7 +1371,7 @@ struct DeclaratorChunk {
 
     /// If HasTrailingReturnType is true, this is the location of the trailing
     /// return type.
-    unsigned TrailingReturnTypeLoc;
+    SourceLocation TrailingReturnTypeLoc;
 
     /// Reset the parameter list to having zero parameters.
     ///
@@ -1408,24 +1419,18 @@ struct DeclaratorChunk {
     /// by the parameter type definitions.
     bool isKNRPrototype() const { return !hasPrototype && NumParams != 0; }
 
-    SourceLocation getLParenLoc() const {
-      return SourceLocation::getFromRawEncoding(LParenLoc);
-    }
+    SourceLocation getLParenLoc() const { return LParenLoc; }
 
-    SourceLocation getEllipsisLoc() const {
-      return SourceLocation::getFromRawEncoding(EllipsisLoc);
-    }
+    SourceLocation getEllipsisLoc() const { return EllipsisLoc; }
 
-    SourceLocation getRParenLoc() const {
-      return SourceLocation::getFromRawEncoding(RParenLoc);
-    }
+    SourceLocation getRParenLoc() const { return RParenLoc; }
 
     SourceLocation getExceptionSpecLocBeg() const {
-      return SourceLocation::getFromRawEncoding(ExceptionSpecLocBeg);
+      return ExceptionSpecLocBeg;
     }
 
     SourceLocation getExceptionSpecLocEnd() const {
-      return SourceLocation::getFromRawEncoding(ExceptionSpecLocEnd);
+      return ExceptionSpecLocEnd;
     }
 
     SourceRange getExceptionSpecRange() const {
@@ -1433,9 +1438,7 @@ struct DeclaratorChunk {
     }
 
     /// Retrieve the location of the ref-qualifier, if any.
-    SourceLocation getRefQualifierLoc() const {
-      return SourceLocation::getFromRawEncoding(RefQualifierLoc);
-    }
+    SourceLocation getRefQualifierLoc() const { return RefQualifierLoc; }
 
     /// Retrieve the location of the 'const' qualifier.
     SourceLocation getConstQualifierLoc() const {
@@ -1456,9 +1459,7 @@ struct DeclaratorChunk {
     }
 
     /// Retrieve the location of the 'mutable' qualifier, if any.
-    SourceLocation getMutableLoc() const {
-      return SourceLocation::getFromRawEncoding(MutableLoc);
-    }
+    SourceLocation getMutableLoc() const { return MutableLoc; }
 
     /// Determine whether this function declaration contains a
     /// ref-qualifier.
@@ -1505,7 +1506,7 @@ struct DeclaratorChunk {
     /// Get the trailing-return-type location for this function declarator.
     SourceLocation getTrailingReturnTypeLoc() const {
       assert(HasTrailingReturnType);
-      return SourceLocation::getFromRawEncoding(TrailingReturnTypeLoc);
+      return TrailingReturnTypeLoc;
     }
   };
 
@@ -1522,7 +1523,7 @@ struct DeclaratorChunk {
     /// The type qualifiers: const/volatile/restrict/__unaligned/_Atomic.
     unsigned TypeQuals : 5;
     /// Location of the '*' token.
-    unsigned StarLoc;
+    SourceLocation StarLoc;
     // CXXScopeSpec has a constructor, so it can't be a direct member.
     // So we need some pointer-aligned storage and a bit of trickery.
     alignas(CXXScopeSpec) char ScopeMem[sizeof(CXXScopeSpec)];
@@ -1582,12 +1583,13 @@ struct DeclaratorChunk {
     DeclaratorChunk I;
     I.Kind                = Pointer;
     I.Loc                 = Loc;
+    new (&I.Ptr) PointerTypeInfo;
     I.Ptr.TypeQuals       = TypeQuals;
-    I.Ptr.ConstQualLoc    = ConstQualLoc.getRawEncoding();
-    I.Ptr.VolatileQualLoc = VolatileQualLoc.getRawEncoding();
-    I.Ptr.RestrictQualLoc = RestrictQualLoc.getRawEncoding();
-    I.Ptr.AtomicQualLoc   = AtomicQualLoc.getRawEncoding();
-    I.Ptr.UnalignedQualLoc = UnalignedQualLoc.getRawEncoding();
+    I.Ptr.ConstQualLoc    = ConstQualLoc;
+    I.Ptr.VolatileQualLoc = VolatileQualLoc;
+    I.Ptr.RestrictQualLoc = RestrictQualLoc;
+    I.Ptr.AtomicQualLoc   = AtomicQualLoc;
+    I.Ptr.UnalignedQualLoc = UnalignedQualLoc;
     return I;
   }
 
@@ -1673,7 +1675,8 @@ struct DeclaratorChunk {
     I.Kind          = MemberPointer;
     I.Loc           = SS.getBeginLoc();
     I.EndLoc = EndLoc;
-    I.Mem.StarLoc = StarLoc.getRawEncoding();
+    new (&I.Mem) MemberPointerTypeInfo;
+    I.Mem.StarLoc = StarLoc;
     I.Mem.TypeQuals = TypeQuals;
     new (I.Mem.ScopeMem) CXXScopeSpec(SS);
     return I;

diff  --git a/clang/include/clang/Sema/Designator.h b/clang/include/clang/Sema/Designator.h
index 05f661151263..84837bfeba5b 100644
--- a/clang/include/clang/Sema/Designator.h
+++ b/clang/include/clang/Sema/Designator.h
@@ -39,22 +39,24 @@ class Designator {
     FieldDesignator, ArrayDesignator, ArrayRangeDesignator
   };
 private:
+  Designator() {};
+
   DesignatorKind Kind;
 
   struct FieldDesignatorInfo {
     const IdentifierInfo *II;
-    unsigned DotLoc;
-    unsigned NameLoc;
+    SourceLocation DotLoc;
+    SourceLocation NameLoc;
   };
   struct ArrayDesignatorInfo {
     Expr *Index;
-    unsigned LBracketLoc;
-    mutable unsigned  RBracketLoc;
+    SourceLocation LBracketLoc;
+    mutable SourceLocation RBracketLoc;
   };
   struct ArrayRangeDesignatorInfo {
     Expr *Start, *End;
-    unsigned LBracketLoc, EllipsisLoc;
-    mutable unsigned RBracketLoc;
+    SourceLocation LBracketLoc, EllipsisLoc;
+    mutable SourceLocation RBracketLoc;
   };
 
   union {
@@ -77,12 +79,12 @@ class Designator {
 
   SourceLocation getDotLoc() const {
     assert(isFieldDesignator() && "Invalid accessor");
-    return SourceLocation::getFromRawEncoding(FieldInfo.DotLoc);
+    return FieldInfo.DotLoc;
   }
 
   SourceLocation getFieldLoc() const {
     assert(isFieldDesignator() && "Invalid accessor");
-    return SourceLocation::getFromRawEncoding(FieldInfo.NameLoc);
+    return FieldInfo.NameLoc;
   }
 
   Expr *getArrayIndex() const {
@@ -103,32 +105,33 @@ class Designator {
     assert((isArrayDesignator() || isArrayRangeDesignator()) &&
            "Invalid accessor");
     if (isArrayDesignator())
-      return SourceLocation::getFromRawEncoding(ArrayInfo.LBracketLoc);
+      return ArrayInfo.LBracketLoc;
     else
-      return SourceLocation::getFromRawEncoding(ArrayRangeInfo.LBracketLoc);
+      return ArrayRangeInfo.LBracketLoc;
   }
 
   SourceLocation getRBracketLoc() const {
     assert((isArrayDesignator() || isArrayRangeDesignator()) &&
            "Invalid accessor");
     if (isArrayDesignator())
-      return SourceLocation::getFromRawEncoding(ArrayInfo.RBracketLoc);
+      return ArrayInfo.RBracketLoc;
     else
-      return SourceLocation::getFromRawEncoding(ArrayRangeInfo.RBracketLoc);
+      return ArrayRangeInfo.RBracketLoc;
   }
 
   SourceLocation getEllipsisLoc() const {
     assert(isArrayRangeDesignator() && "Invalid accessor");
-    return SourceLocation::getFromRawEncoding(ArrayRangeInfo.EllipsisLoc);
+    return ArrayRangeInfo.EllipsisLoc;
   }
 
   static Designator getField(const IdentifierInfo *II, SourceLocation DotLoc,
                              SourceLocation NameLoc) {
     Designator D;
     D.Kind = FieldDesignator;
+    new (&D.FieldInfo) FieldDesignatorInfo;
     D.FieldInfo.II = II;
-    D.FieldInfo.DotLoc = DotLoc.getRawEncoding();
-    D.FieldInfo.NameLoc = NameLoc.getRawEncoding();
+    D.FieldInfo.DotLoc = DotLoc;
+    D.FieldInfo.NameLoc = NameLoc;
     return D;
   }
 
@@ -136,9 +139,10 @@ class Designator {
                              SourceLocation LBracketLoc) {
     Designator D;
     D.Kind = ArrayDesignator;
+    new (&D.ArrayInfo) ArrayDesignatorInfo;
     D.ArrayInfo.Index = Index;
-    D.ArrayInfo.LBracketLoc = LBracketLoc.getRawEncoding();
-    D.ArrayInfo.RBracketLoc = 0;
+    D.ArrayInfo.LBracketLoc = LBracketLoc;
+    D.ArrayInfo.RBracketLoc = SourceLocation();
     return D;
   }
 
@@ -148,11 +152,12 @@ class Designator {
                                   SourceLocation EllipsisLoc) {
     Designator D;
     D.Kind = ArrayRangeDesignator;
+    new (&D.ArrayRangeInfo) ArrayRangeDesignatorInfo;
     D.ArrayRangeInfo.Start = Start;
     D.ArrayRangeInfo.End = End;
-    D.ArrayRangeInfo.LBracketLoc = LBracketLoc.getRawEncoding();
-    D.ArrayRangeInfo.EllipsisLoc = EllipsisLoc.getRawEncoding();
-    D.ArrayRangeInfo.RBracketLoc = 0;
+    D.ArrayRangeInfo.LBracketLoc = LBracketLoc;
+    D.ArrayRangeInfo.EllipsisLoc = EllipsisLoc;
+    D.ArrayRangeInfo.RBracketLoc = SourceLocation();
     return D;
   }
 
@@ -160,9 +165,9 @@ class Designator {
     assert((isArrayDesignator() || isArrayRangeDesignator()) &&
            "Invalid accessor");
     if (isArrayDesignator())
-      ArrayInfo.RBracketLoc = RBracketLoc.getRawEncoding();
+      ArrayInfo.RBracketLoc = RBracketLoc;
     else
-      ArrayRangeInfo.RBracketLoc = RBracketLoc.getRawEncoding();
+      ArrayRangeInfo.RBracketLoc = RBracketLoc;
   }
 
   /// ClearExprs - Null out any expression references, which prevents

diff  --git a/clang/include/clang/Sema/Initialization.h b/clang/include/clang/Sema/Initialization.h
index 8115f69f4df3..dcdfa3c3cf64 100644
--- a/clang/include/clang/Sema/Initialization.h
+++ b/clang/include/clang/Sema/Initialization.h
@@ -148,7 +148,7 @@ class alignas(8) InitializedEntity {
     /// location of the 'return', 'throw', or 'new' keyword,
     /// respectively. When Kind == EK_Temporary, the location where
     /// the temporary is being created.
-    unsigned Location;
+    SourceLocation Location;
 
     /// Whether the entity being initialized may end up using the
     /// named return value optimization (NRVO).
@@ -174,7 +174,7 @@ class alignas(8) InitializedEntity {
     IdentifierInfo *VarID;
 
     /// The source location at which the capture occurs.
-    unsigned Location;
+    SourceLocation Location;
   };
 
   union {
@@ -209,7 +209,7 @@ class alignas(8) InitializedEntity {
     struct C Capture;
   };
 
-  InitializedEntity() = default;
+  InitializedEntity() {};
 
   /// Create the initialization entity for a variable.
   InitializedEntity(VarDecl *Var, EntityKind EK = EK_Variable)
@@ -221,7 +221,8 @@ class alignas(8) InitializedEntity {
   InitializedEntity(EntityKind Kind, SourceLocation Loc, QualType Type,
                     bool NRVO = false)
       : Kind(Kind), Type(Type) {
-    LocAndNRVO.Location = Loc.getRawEncoding();
+    new (&LocAndNRVO) LN;
+    LocAndNRVO.Location = Loc;
     LocAndNRVO.NRVO = NRVO;
   }
 
@@ -238,8 +239,9 @@ class alignas(8) InitializedEntity {
   /// Create the initialization entity for a lambda capture.
   InitializedEntity(IdentifierInfo *VarID, QualType FieldType, SourceLocation Loc)
       : Kind(EK_LambdaCapture), Type(FieldType) {
+    new (&Capture) C;
     Capture.VarID = VarID;
-    Capture.Location = Loc.getRawEncoding();
+    Capture.Location = Loc;
   }
 
 public:
@@ -501,14 +503,14 @@ class alignas(8) InitializedEntity {
   /// the result of a function call.
   SourceLocation getReturnLoc() const {
     assert(getKind() == EK_Result && "No 'return' location!");
-    return SourceLocation::getFromRawEncoding(LocAndNRVO.Location);
+    return LocAndNRVO.Location;
   }
 
   /// Determine the location of the 'throw' keyword when initializing
   /// an exception object.
   SourceLocation getThrowLoc() const {
     assert(getKind() == EK_Exception && "No 'throw' location!");
-    return SourceLocation::getFromRawEncoding(LocAndNRVO.Location);
+    return LocAndNRVO.Location;
   }
 
   /// If this is an array, vector, or complex number element, get the
@@ -537,7 +539,7 @@ class alignas(8) InitializedEntity {
   /// field from a captured variable in a lambda.
   SourceLocation getCaptureLoc() const {
     assert(getKind() == EK_LambdaCapture && "Not a lambda capture!");
-    return SourceLocation::getFromRawEncoding(Capture.Location);
+    return Capture.Location;
   }
 
   void setParameterCFAudited() {

diff  --git a/clang/lib/AST/Expr.cpp b/clang/lib/AST/Expr.cpp
index 94b6adf489fe..5d7066cc2699 100644
--- a/clang/lib/AST/Expr.cpp
+++ b/clang/lib/AST/Expr.cpp
@@ -4209,14 +4209,10 @@ SourceLocation DesignatedInitExpr::getBeginLoc() const {
   SourceLocation StartLoc;
   auto *DIE = const_cast<DesignatedInitExpr *>(this);
   Designator &First = *DIE->getDesignator(0);
-  if (First.isFieldDesignator()) {
-    if (GNUSyntax)
-      StartLoc = SourceLocation::getFromRawEncoding(First.Field.FieldLoc);
-    else
-      StartLoc = SourceLocation::getFromRawEncoding(First.Field.DotLoc);
-  } else
-    StartLoc =
-      SourceLocation::getFromRawEncoding(First.ArrayOrRange.LBracketLoc);
+  if (First.isFieldDesignator())
+    StartLoc = GNUSyntax ? First.Field.FieldLoc : First.Field.DotLoc;
+  else
+    StartLoc = First.ArrayOrRange.LBracketLoc;
   return StartLoc;
 }
 

diff  --git a/clang/lib/AST/TemplateBase.cpp b/clang/lib/AST/TemplateBase.cpp
index b6af655deff0..baf62bd115a8 100644
--- a/clang/lib/AST/TemplateBase.cpp
+++ b/clang/lib/AST/TemplateBase.cpp
@@ -524,8 +524,8 @@ clang::TemplateArgumentLocInfo::TemplateArgumentLocInfo(
   TemplateTemplateArgLocInfo *Template = new (Ctx) TemplateTemplateArgLocInfo;
   Template->Qualifier = QualifierLoc.getNestedNameSpecifier();
   Template->QualifierLocData = QualifierLoc.getOpaqueData();
-  Template->TemplateNameLoc = TemplateNameLoc.getRawEncoding();
-  Template->EllipsisLoc = EllipsisLoc.getRawEncoding();
+  Template->TemplateNameLoc = TemplateNameLoc;
+  Template->EllipsisLoc = EllipsisLoc;
   Pointer = Template;
 }
 

diff  --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp
index 9525c0222b9f..88ebb59f9a60 100644
--- a/clang/lib/Parse/ParseDeclCXX.cpp
+++ b/clang/lib/Parse/ParseDeclCXX.cpp
@@ -2431,7 +2431,7 @@ void Parser::MaybeParseAndDiagnoseDeclSpecAfterCXX11VirtSpecifierSeq(
       const char *Name = (RefQualifierIsLValueRef ? "& " : "&& ");
       FixItHint Insertion = FixItHint::CreateInsertion(VS.getFirstLocation(), Name);
       Function.RefQualifierIsLValueRef = RefQualifierIsLValueRef;
-      Function.RefQualifierLoc = RefQualifierLoc.getRawEncoding();
+      Function.RefQualifierLoc = RefQualifierLoc;
 
       Diag(RefQualifierLoc, diag::err_declspec_after_virtspec)
         << (RefQualifierIsLValueRef ? "&" : "&&")
@@ -3906,7 +3906,7 @@ void Parser::ParseTrailingRequiresClause(Declarator &D) {
       auto &FunctionChunk = D.getFunctionTypeInfo();
       FunctionChunk.HasTrailingReturnType = TrailingReturnType.isUsable();
       FunctionChunk.TrailingReturnType = TrailingReturnType.get();
-      FunctionChunk.TrailingReturnTypeLoc = Range.getBegin().getRawEncoding();
+      FunctionChunk.TrailingReturnTypeLoc = Range.getBegin();
     } else
       SkipUntil({tok::equal, tok::l_brace, tok::arrow, tok::kw_try, tok::comma},
                 StopAtSemi | StopBeforeMatch);

diff  --git a/clang/lib/Sema/DeclSpec.cpp b/clang/lib/Sema/DeclSpec.cpp
index 93685172b2b6..da42db3e8f7b 100644
--- a/clang/lib/Sema/DeclSpec.cpp
+++ b/clang/lib/Sema/DeclSpec.cpp
@@ -191,28 +191,29 @@ DeclaratorChunk DeclaratorChunk::getFunction(bool hasProto,
   I.Kind                        = Function;
   I.Loc                         = LocalRangeBegin;
   I.EndLoc                      = LocalRangeEnd;
+  new (&I.Fun) FunctionTypeInfo;
   I.Fun.hasPrototype            = hasProto;
   I.Fun.isVariadic              = EllipsisLoc.isValid();
   I.Fun.isAmbiguous             = isAmbiguous;
-  I.Fun.LParenLoc               = LParenLoc.getRawEncoding();
-  I.Fun.EllipsisLoc             = EllipsisLoc.getRawEncoding();
-  I.Fun.RParenLoc               = RParenLoc.getRawEncoding();
+  I.Fun.LParenLoc               = LParenLoc;
+  I.Fun.EllipsisLoc             = EllipsisLoc;
+  I.Fun.RParenLoc               = RParenLoc;
   I.Fun.DeleteParams            = false;
   I.Fun.NumParams               = NumParams;
   I.Fun.Params                  = nullptr;
   I.Fun.RefQualifierIsLValueRef = RefQualifierIsLvalueRef;
-  I.Fun.RefQualifierLoc         = RefQualifierLoc.getRawEncoding();
-  I.Fun.MutableLoc              = MutableLoc.getRawEncoding();
+  I.Fun.RefQualifierLoc         = RefQualifierLoc;
+  I.Fun.MutableLoc              = MutableLoc;
   I.Fun.ExceptionSpecType       = ESpecType;
-  I.Fun.ExceptionSpecLocBeg     = ESpecRange.getBegin().getRawEncoding();
-  I.Fun.ExceptionSpecLocEnd     = ESpecRange.getEnd().getRawEncoding();
+  I.Fun.ExceptionSpecLocBeg     = ESpecRange.getBegin();
+  I.Fun.ExceptionSpecLocEnd     = ESpecRange.getEnd();
   I.Fun.NumExceptionsOrDecls    = 0;
   I.Fun.Exceptions              = nullptr;
   I.Fun.NoexceptExpr            = nullptr;
   I.Fun.HasTrailingReturnType   = TrailingReturnType.isUsable() ||
                                   TrailingReturnType.isInvalid();
   I.Fun.TrailingReturnType      = TrailingReturnType.get();
-  I.Fun.TrailingReturnTypeLoc   = TrailingReturnTypeLoc.getRawEncoding();
+  I.Fun.TrailingReturnTypeLoc   = TrailingReturnTypeLoc;
   I.Fun.MethodQualifiers        = nullptr;
   I.Fun.QualAttrFactory         = nullptr;
 
@@ -1443,9 +1444,10 @@ void UnqualifiedId::setOperatorFunctionId(SourceLocation OperatorLoc,
   Kind = UnqualifiedIdKind::IK_OperatorFunctionId;
   StartLocation = OperatorLoc;
   EndLocation = OperatorLoc;
+  new (&OperatorFunctionId) struct OFI;
   OperatorFunctionId.Operator = Op;
   for (unsigned I = 0; I != 3; ++I) {
-    OperatorFunctionId.SymbolLocations[I] = SymbolLocations[I].getRawEncoding();
+    OperatorFunctionId.SymbolLocations[I] = SymbolLocations[I];
 
     if (SymbolLocations[I].isValid())
       EndLocation = SymbolLocations[I];

diff  --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index 3cd32f894bd1..832fd8384ba8 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -5344,8 +5344,8 @@ Sema::GetNameFromUnqualifiedId(const UnqualifiedId &Name) {
   case UnqualifiedIdKind::IK_OperatorFunctionId:
     NameInfo.setName(Context.DeclarationNames.getCXXOperatorName(
                                            Name.OperatorFunctionId.Operator));
-    NameInfo.getInfo().CXXOperatorName.BeginOpNameLoc
-      = Name.OperatorFunctionId.SymbolLocations[0];
+    NameInfo.getInfo().CXXOperatorName.BeginOpNameLoc =
+        Name.OperatorFunctionId.SymbolLocations[0].getRawEncoding();
     NameInfo.getInfo().CXXOperatorName.EndOpNameLoc
       = Name.EndLocation.getRawEncoding();
     return NameInfo;

diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 571c4fb091ab..45616dadcbee 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -2851,8 +2851,7 @@ ExprResult Sema::BuildIvarRefExpr(Scope *S, SourceLocation Loc,
   // turn this into Self->ivar, just return a BareIVarExpr or something.
   IdentifierInfo &II = Context.Idents.get("self");
   UnqualifiedId SelfName;
-  SelfName.setIdentifier(&II, SourceLocation());
-  SelfName.setKind(UnqualifiedIdKind::IK_ImplicitSelfParam);
+  SelfName.setImplicitSelfParam(&II);
   CXXScopeSpec SelfScopeSpec;
   SourceLocation TemplateKWLoc;
   ExprResult SelfExpr =

diff  --git a/clang/lib/Sema/SemaType.cpp b/clang/lib/Sema/SemaType.cpp
index 8f2dd384b43b..4178024d1264 100644
--- a/clang/lib/Sema/SemaType.cpp
+++ b/clang/lib/Sema/SemaType.cpp
@@ -3125,11 +3125,11 @@ static void diagnoseRedundantReturnTypeQualifiers(Sema &S, QualType RetTy,
           diag::warn_qual_return_type,
           PTI.TypeQuals,
           SourceLocation(),
-          SourceLocation::getFromRawEncoding(PTI.ConstQualLoc),
-          SourceLocation::getFromRawEncoding(PTI.VolatileQualLoc),
-          SourceLocation::getFromRawEncoding(PTI.RestrictQualLoc),
-          SourceLocation::getFromRawEncoding(PTI.AtomicQualLoc),
-          SourceLocation::getFromRawEncoding(PTI.UnalignedQualLoc));
+          PTI.ConstQualLoc,
+          PTI.VolatileQualLoc,
+          PTI.RestrictQualLoc,
+          PTI.AtomicQualLoc,
+          PTI.UnalignedQualLoc);
       return;
     }
 
@@ -6086,7 +6086,7 @@ namespace {
       }
 
       // Finally fill in MemberPointerLocInfo fields.
-      TL.setStarLoc(SourceLocation::getFromRawEncoding(Chunk.Mem.StarLoc));
+      TL.setStarLoc(Chunk.Mem.StarLoc);
       TL.setClassTInfo(ClsTInfo);
     }
     void VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) {
@@ -6163,7 +6163,7 @@ static void fillAtomicQualLoc(AtomicTypeLoc ATL, const DeclaratorChunk &Chunk) {
     llvm_unreachable("cannot be _Atomic qualified");
 
   case DeclaratorChunk::Pointer:
-    Loc = SourceLocation::getFromRawEncoding(Chunk.Ptr.AtomicQualLoc);
+    Loc = Chunk.Ptr.AtomicQualLoc;
     break;
 
   case DeclaratorChunk::BlockPointer:


        


More information about the llvm-branch-commits mailing list