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

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D94237

Files:
  clang/include/clang/AST/DependentDiagnostic.h
  clang/include/clang/AST/Expr.h
  clang/include/clang/AST/TemplateBase.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

Index: clang/lib/Sema/SemaType.cpp
===================================================================
--- clang/lib/Sema/SemaType.cpp
+++ clang/lib/Sema/SemaType.cpp
@@ -3125,11 +3125,11 @@
           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 @@
       }
 
       // Finally fill in MemberPointerLocInfo fields.
-      TL.setStarLoc(SourceLocation::getFromRawEncoding(Chunk.Mem.StarLoc));
+      TL.setStarLoc(Chunk.Mem.StarLoc);
       TL.setClassTInfo(ClsTInfo);
     }
     void VisitLValueReferenceTypeLoc(LValueReferenceTypeLoc TL) {
@@ -6152,7 +6152,7 @@
     llvm_unreachable("cannot be _Atomic qualified");
 
   case DeclaratorChunk::Pointer:
-    Loc = SourceLocation::getFromRawEncoding(Chunk.Ptr.AtomicQualLoc);
+    Loc = Chunk.Ptr.AtomicQualLoc;
     break;
 
   case DeclaratorChunk::BlockPointer:
Index: clang/lib/Sema/SemaExpr.cpp
===================================================================
--- clang/lib/Sema/SemaExpr.cpp
+++ clang/lib/Sema/SemaExpr.cpp
@@ -2851,8 +2851,7 @@
   // 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.setImplcitSelfParam(&II);
   CXXScopeSpec SelfScopeSpec;
   SourceLocation TemplateKWLoc;
   ExprResult SelfExpr =
Index: clang/lib/Sema/SemaDecl.cpp
===================================================================
--- clang/lib/Sema/SemaDecl.cpp
+++ clang/lib/Sema/SemaDecl.cpp
@@ -5342,8 +5342,8 @@
   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;
Index: clang/lib/Sema/DeclSpec.cpp
===================================================================
--- clang/lib/Sema/DeclSpec.cpp
+++ clang/lib/Sema/DeclSpec.cpp
@@ -191,28 +191,29 @@
   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 @@
   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];
Index: clang/lib/Parse/ParseDeclCXX.cpp
===================================================================
--- clang/lib/Parse/ParseDeclCXX.cpp
+++ clang/lib/Parse/ParseDeclCXX.cpp
@@ -2431,7 +2431,7 @@
       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 @@
       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);
Index: clang/lib/AST/TemplateBase.cpp
===================================================================
--- clang/lib/AST/TemplateBase.cpp
+++ clang/lib/AST/TemplateBase.cpp
@@ -524,8 +524,8 @@
   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;
 }
 
Index: clang/lib/AST/Expr.cpp
===================================================================
--- clang/lib/AST/Expr.cpp
+++ clang/lib/AST/Expr.cpp
@@ -4209,14 +4209,10 @@
   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;
 }
 
Index: clang/include/clang/Sema/Initialization.h
===================================================================
--- clang/include/clang/Sema/Initialization.h
+++ clang/include/clang/Sema/Initialization.h
@@ -148,7 +148,7 @@
     /// 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 @@
     IdentifierInfo *VarID;
 
     /// The source location at which the capture occurs.
-    unsigned Location;
+    SourceLocation Location;
   };
 
   union {
@@ -209,7 +209,7 @@
     struct C Capture;
   };
 
-  InitializedEntity() = default;
+  InitializedEntity() {};
 
   /// Create the initialization entity for a variable.
   InitializedEntity(VarDecl *Var, EntityKind EK = EK_Variable)
@@ -221,7 +221,8 @@
   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 @@
   /// 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 @@
   /// 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 @@
   /// 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() {
Index: clang/include/clang/Sema/Designator.h
===================================================================
--- clang/include/clang/Sema/Designator.h
+++ clang/include/clang/Sema/Designator.h
@@ -39,22 +39,24 @@
     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 @@
 
   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 @@
     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 @@
                              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 @@
                                   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 @@
     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
Index: clang/include/clang/Sema/DeclSpec.h
===================================================================
--- clang/include/clang/Sema/DeclSpec.h
+++ clang/include/clang/Sema/DeclSpec.h
@@ -967,7 +967,7 @@
     /// Different operators have different 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 @@
 
   /// 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 @@
     StartLocation = EndLocation = TemplateLoc;
   }
 
+  /// Specify that this unqualified-id is an implicit 'self'
+  /// parameter.
+  ///
+  /// \param Id the identifier.
+  void setImplcitSelfParam(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 @@
 ///
 /// 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 @@
     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 @@
     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 @@
     /// 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 @@
 
     /// 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 @@
     /// 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 @@
     }
 
     /// 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 @@
     }
 
     /// 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 @@
     /// 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 @@
     /// 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 @@
     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 @@
     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;
Index: clang/include/clang/AST/TemplateBase.h
===================================================================
--- clang/include/clang/AST/TemplateBase.h
+++ clang/include/clang/AST/TemplateBase.h
@@ -409,8 +409,8 @@
     // 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 @@
   }
 
   SourceLocation getTemplateNameLoc() const {
-    return SourceLocation::getFromRawEncoding(getTemplate()->TemplateNameLoc);
+    return getTemplate()->TemplateNameLoc;
   }
 
   SourceLocation getTemplateEllipsisLoc() const {
-    return SourceLocation::getFromRawEncoding(getTemplate()->EllipsisLoc);
+    return getTemplate()->EllipsisLoc;
   }
 };
 
Index: clang/include/clang/AST/Expr.h
===================================================================
--- clang/include/clang/AST/Expr.h
+++ clang/include/clang/AST/Expr.h
@@ -4994,10 +4994,10 @@
     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 @@
     /// 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 @@
     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 @@
 
     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 {
Index: clang/include/clang/AST/DependentDiagnostic.h
===================================================================
--- clang/include/clang/AST/DependentDiagnostic.h
+++ clang/include/clang/AST/DependentDiagnostic.h
@@ -48,7 +48,7 @@
                                      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 @@
 
   SourceLocation getAccessLoc() const {
     assert(getKind() == Access);
-    return SourceLocation::getFromRawEncoding(AccessData.Loc);
+    return AccessData.Loc;
   }
 
   NamedDecl *getAccessTarget() const {
@@ -112,7 +112,7 @@
   PartialDiagnostic Diag;
 
   struct {
-    unsigned Loc;
+    SourceLocation Loc;
     unsigned Access : 2;
     unsigned IsMember : 1;
     NamedDecl *TargetDecl;
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to