Pārlūkot izejas kodu

[modules] Emit the type of the TypeSourceInfo for a DeclaratorDecl (but
not the corresponding location information) earlier.

We need the type as written in order to properly merge functions with
deduced return types, so we need to load that early. But we don't want
to load the location information early, because that contains
problematic things such as the function parameters.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@336016 91177308-0d34-0410-b5e6-96231b3b80d8

Richard Smith 7 gadi atpakaļ
vecāks
revīzija
0134501202

+ 9 - 0
include/clang/Serialization/ASTReader.h

@@ -1771,6 +1771,10 @@ public:
   TypeSourceInfo *GetTypeSourceInfo(ModuleFile &F,
   TypeSourceInfo *GetTypeSourceInfo(ModuleFile &F,
                                     const RecordData &Record, unsigned &Idx);
                                     const RecordData &Record, unsigned &Idx);
 
 
+  /// Raad the type locations for the given TInfo.
+  void ReadTypeLoc(ModuleFile &F, const RecordData &Record, unsigned &Idx,
+                   TypeLoc TL);
+
   /// Resolve a type ID into a type, potentially building a new
   /// Resolve a type ID into a type, potentially building a new
   /// type.
   /// type.
   QualType GetType(serialization::TypeID ID);
   QualType GetType(serialization::TypeID ID);
@@ -2460,6 +2464,11 @@ public:
     return Reader->GetTypeSourceInfo(*F, Record, Idx);
     return Reader->GetTypeSourceInfo(*F, Record, Idx);
   }
   }
 
 
+  /// Reads the location information for a type.
+  void readTypeLoc(TypeLoc TL) {
+    return Reader->ReadTypeLoc(*F, Record, Idx, TL);
+  }
+
   /// Map a local type ID within a given AST file to a global type ID.
   /// Map a local type ID within a given AST file to a global type ID.
   serialization::TypeID getGlobalTypeID(unsigned LocalID) const {
   serialization::TypeID getGlobalTypeID(unsigned LocalID) const {
     return Reader->getGlobalTypeID(*F, LocalID);
     return Reader->getGlobalTypeID(*F, LocalID);

+ 1 - 1
include/clang/Serialization/ASTWriter.h

@@ -886,7 +886,7 @@ public:
   /// Emits a reference to a declarator info.
   /// Emits a reference to a declarator info.
   void AddTypeSourceInfo(TypeSourceInfo *TInfo);
   void AddTypeSourceInfo(TypeSourceInfo *TInfo);
 
 
-  /// Emits a type with source-location information.
+  /// Emits source location information for a type. Does not emit the type.
   void AddTypeLoc(TypeLoc TL);
   void AddTypeLoc(TypeLoc TL);
 
 
   /// Emits a template argument location info.
   /// Emits a template argument location info.

+ 8 - 3
lib/Serialization/ASTReader.cpp

@@ -6733,6 +6733,13 @@ void TypeLocReader::VisitPipeTypeLoc(PipeTypeLoc TL) {
   TL.setKWLoc(ReadSourceLocation());
   TL.setKWLoc(ReadSourceLocation());
 }
 }
 
 
+void ASTReader::ReadTypeLoc(ModuleFile &F, const ASTReader::RecordData &Record,
+                            unsigned &Idx, TypeLoc TL) {
+  TypeLocReader TLR(F, *this, Record, Idx);
+  for (; !TL.isNull(); TL = TL.getNextTypeLoc())
+    TLR.Visit(TL);
+}
+
 TypeSourceInfo *
 TypeSourceInfo *
 ASTReader::GetTypeSourceInfo(ModuleFile &F, const ASTReader::RecordData &Record,
 ASTReader::GetTypeSourceInfo(ModuleFile &F, const ASTReader::RecordData &Record,
                              unsigned &Idx) {
                              unsigned &Idx) {
@@ -6741,9 +6748,7 @@ ASTReader::GetTypeSourceInfo(ModuleFile &F, const ASTReader::RecordData &Record,
     return nullptr;
     return nullptr;
 
 
   TypeSourceInfo *TInfo = getContext().CreateTypeSourceInfo(InfoTy);
   TypeSourceInfo *TInfo = getContext().CreateTypeSourceInfo(InfoTy);
-  TypeLocReader TLR(F, *this, Record, Idx);
-  for (TypeLoc TL = TInfo->getTypeLoc(); !TL.isNull(); TL = TL.getNextTypeLoc())
-    TLR.Visit(TL);
+  ReadTypeLoc(F, Record, Idx, TInfo->getTypeLoc());
   return TInfo;
   return TInfo;
 }
 }
 
 

+ 6 - 7
lib/Serialization/ASTReaderDecl.cpp

@@ -522,13 +522,8 @@ void ASTDeclReader::Visit(Decl *D) {
   IsDeclMarkedUsed = false;
   IsDeclMarkedUsed = false;
 
 
   if (auto *DD = dyn_cast<DeclaratorDecl>(D)) {
   if (auto *DD = dyn_cast<DeclaratorDecl>(D)) {
-    if (DD->DeclInfo) {
-      auto *Info = DD->DeclInfo.get<DeclaratorDecl::ExtInfo *>();
-      Info->TInfo = GetTypeSourceInfo();
-    }
-    else {
-      DD->DeclInfo = GetTypeSourceInfo();
-    }
+    if (auto *TInfo = DD->getTypeSourceInfo())
+      Record.readTypeLoc(TInfo->getTypeLoc());
   }
   }
 
 
   if (auto *TD = dyn_cast<TypeDecl>(D)) {
   if (auto *TD = dyn_cast<TypeDecl>(D)) {
@@ -815,6 +810,10 @@ void ASTDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
     ReadQualifierInfo(*Info);
     ReadQualifierInfo(*Info);
     DD->DeclInfo = Info;
     DD->DeclInfo = Info;
   }
   }
+  QualType TSIType = Record.readType();
+  DD->setTypeSourceInfo(
+      TSIType.isNull() ? nullptr
+                       : Reader.getContext().CreateTypeSourceInfo(TSIType));
 }
 }
 
 
 void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
 void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) {

+ 2 - 2
lib/Serialization/ASTWriter.cpp

@@ -5447,12 +5447,11 @@ void ASTRecordWriter::AddTypeSourceInfo(TypeSourceInfo *TInfo) {
     return;
     return;
   }
   }
 
 
+  AddTypeRef(TInfo->getType());
   AddTypeLoc(TInfo->getTypeLoc());
   AddTypeLoc(TInfo->getTypeLoc());
 }
 }
 
 
 void ASTRecordWriter::AddTypeLoc(TypeLoc TL) {
 void ASTRecordWriter::AddTypeLoc(TypeLoc TL) {
-  AddTypeRef(TL.getType());
-
   TypeLocWriter TLW(*this);
   TypeLocWriter TLW(*this);
   for (; !TL.isNull(); TL = TL.getNextTypeLoc())
   for (; !TL.isNull(); TL = TL.getNextTypeLoc())
     TLW.Visit(TL);
     TLW.Visit(TL);
@@ -5777,6 +5776,7 @@ void ASTRecordWriter::AddNestedNameSpecifierLoc(NestedNameSpecifierLoc NNS) {
     case NestedNameSpecifier::TypeSpec:
     case NestedNameSpecifier::TypeSpec:
     case NestedNameSpecifier::TypeSpecWithTemplate:
     case NestedNameSpecifier::TypeSpecWithTemplate:
       Record->push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate);
       Record->push_back(Kind == NestedNameSpecifier::TypeSpecWithTemplate);
+      AddTypeRef(NNS.getTypeLoc().getType());
       AddTypeLoc(NNS.getTypeLoc());
       AddTypeLoc(NNS.getTypeLoc());
       AddSourceLocation(NNS.getLocalSourceRange().getEnd());
       AddSourceLocation(NNS.getLocalSourceRange().getEnd());
       break;
       break;

+ 10 - 5
lib/Serialization/ASTWriterDecl.cpp

@@ -265,7 +265,8 @@ void ASTDeclWriter::Visit(Decl *D) {
   // abbreviation infrastructure requires that arrays are encoded last, so
   // abbreviation infrastructure requires that arrays are encoded last, so
   // we handle it here in the case of those classes derived from DeclaratorDecl
   // we handle it here in the case of those classes derived from DeclaratorDecl
   if (DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(D)) {
   if (DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(D)) {
-    Record.AddTypeSourceInfo(DD->getTypeSourceInfo());
+    if (auto *TInfo = DD->getTypeSourceInfo())
+      Record.AddTypeLoc(TInfo->getTypeLoc());
   }
   }
 
 
   // Handle FunctionDecl's body here and write it after all other Stmts/Exprs
   // Handle FunctionDecl's body here and write it after all other Stmts/Exprs
@@ -513,6 +514,9 @@ void ASTDeclWriter::VisitDeclaratorDecl(DeclaratorDecl *D) {
   Record.push_back(D->hasExtInfo());
   Record.push_back(D->hasExtInfo());
   if (D->hasExtInfo())
   if (D->hasExtInfo())
     Record.AddQualifierInfo(*D->getExtInfo());
     Record.AddQualifierInfo(*D->getExtInfo());
+  // The location information is deferred until the end of the record.
+  Record.AddTypeRef(D->getTypeSourceInfo() ? D->getTypeSourceInfo()->getType()
+                                           : QualType());
 }
 }
 
 
 void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) {
 void ASTDeclWriter::VisitFunctionDecl(FunctionDecl *D) {
@@ -1773,11 +1777,11 @@ void ASTWriter::WriteDeclAbbrevs() {
   // DeclaratorDecl
   // DeclaratorDecl
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
   Abv->Add(BitCodeAbbrevOp(0));                       // hasExtInfo
   Abv->Add(BitCodeAbbrevOp(0));                       // hasExtInfo
+  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType
   // FieldDecl
   // FieldDecl
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isMutable
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isMutable
   Abv->Add(BitCodeAbbrevOp(0));                       // InitStyle
   Abv->Add(BitCodeAbbrevOp(0));                       // InitStyle
   // Type Source Info
   // Type Source Info
-  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
   DeclFieldAbbrev = Stream.EmitAbbrev(std::move(Abv));
   DeclFieldAbbrev = Stream.EmitAbbrev(std::move(Abv));
@@ -1806,6 +1810,7 @@ void ASTWriter::WriteDeclAbbrevs() {
   // DeclaratorDecl
   // DeclaratorDecl
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
   Abv->Add(BitCodeAbbrevOp(0));                       // hasExtInfo
   Abv->Add(BitCodeAbbrevOp(0));                       // hasExtInfo
+  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType
   // FieldDecl
   // FieldDecl
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isMutable
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 1)); // isMutable
   Abv->Add(BitCodeAbbrevOp(0));                       // InitStyle
   Abv->Add(BitCodeAbbrevOp(0));                       // InitStyle
@@ -1813,7 +1818,6 @@ void ASTWriter::WriteDeclAbbrevs() {
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getAccessControl
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getAccessControl
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getSynthesize
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // getSynthesize
   // Type Source Info
   // Type Source Info
-  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
   DeclObjCIvarAbbrev = Stream.EmitAbbrev(std::move(Abv));
   DeclObjCIvarAbbrev = Stream.EmitAbbrev(std::move(Abv));
@@ -1949,6 +1953,7 @@ void ASTWriter::WriteDeclAbbrevs() {
   // DeclaratorDecl
   // DeclaratorDecl
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
   Abv->Add(BitCodeAbbrevOp(0));                       // hasExtInfo
   Abv->Add(BitCodeAbbrevOp(0));                       // hasExtInfo
+  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType
   // VarDecl
   // VarDecl
   Abv->Add(BitCodeAbbrevOp(0));                       // SClass
   Abv->Add(BitCodeAbbrevOp(0));                       // SClass
   Abv->Add(BitCodeAbbrevOp(0));                       // TSCSpec
   Abv->Add(BitCodeAbbrevOp(0));                       // TSCSpec
@@ -1965,7 +1970,6 @@ void ASTWriter::WriteDeclAbbrevs() {
   Abv->Add(BitCodeAbbrevOp(0));                       // HasInheritedDefaultArg
   Abv->Add(BitCodeAbbrevOp(0));                       // HasInheritedDefaultArg
   Abv->Add(BitCodeAbbrevOp(0));                   // HasUninstantiatedDefaultArg
   Abv->Add(BitCodeAbbrevOp(0));                   // HasUninstantiatedDefaultArg
   // Type Source Info
   // Type Source Info
-  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
   DeclParmVarAbbrev = Stream.EmitAbbrev(std::move(Abv));
   DeclParmVarAbbrev = Stream.EmitAbbrev(std::move(Abv));
@@ -2025,6 +2029,7 @@ void ASTWriter::WriteDeclAbbrevs() {
   // DeclaratorDecl
   // DeclaratorDecl
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // InnerStartLoc
   Abv->Add(BitCodeAbbrevOp(0));                       // hasExtInfo
   Abv->Add(BitCodeAbbrevOp(0));                       // hasExtInfo
+  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TSIType
   // VarDecl
   // VarDecl
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // SClass
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // SClass
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // TSCSpec
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // TSCSpec
@@ -2045,7 +2050,6 @@ void ASTWriter::WriteDeclAbbrevs() {
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // IsInitICE (local)
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // IsInitICE (local)
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // VarKind (local enum)
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 2)); // VarKind (local enum)
   // Type Source Info
   // Type Source Info
-  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Array));
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // TypeLoc
   DeclVarAbbrev = Stream.EmitAbbrev(std::move(Abv));
   DeclVarAbbrev = Stream.EmitAbbrev(std::move(Abv));
@@ -2076,6 +2080,7 @@ void ASTWriter::WriteDeclAbbrevs() {
   // DeclaratorDecl
   // DeclaratorDecl
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));   // InnerLocStart
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));   // InnerLocStart
   Abv->Add(BitCodeAbbrevOp(0));                         // HasExtInfo
   Abv->Add(BitCodeAbbrevOp(0));                         // HasExtInfo
+  Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6));   // TSIType
   // FunctionDecl
   // FunctionDecl
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 11)); // IDNS
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 11)); // IDNS
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // StorageClass
   Abv->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::Fixed, 3)); // StorageClass