blob: 913a1419b3f105a290a312f7a9234d893b38d14f [file] [log] [blame]
Sebastian Redl3b3c8742010-08-18 23:57:11 +00001//===--- ASTReaderDecl.cpp - Decl Deserialization ---------------*- C++ -*-===//
Chris Lattner487412d2009-04-27 05:27:42 +00002//
3// The LLVM Compiler Infrastructure
4//
5// This file is distributed under the University of Illinois Open Source
6// License. See LICENSE.TXT for details.
7//
8//===----------------------------------------------------------------------===//
9//
Sebastian Redl2c499f62010-08-18 23:56:43 +000010// This file implements the ASTReader::ReadDeclRecord method, which is the
Chris Lattner487412d2009-04-27 05:27:42 +000011// entrypoint for loading a decl.
12//
13//===----------------------------------------------------------------------===//
14
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +000015#include "ASTCommon.h"
Benjamin Kramer89f0b2d2012-04-15 12:36:49 +000016#include "ASTReaderInternals.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000017#include "clang/AST/ASTContext.h"
18#include "clang/AST/DeclCXX.h"
19#include "clang/AST/DeclGroup.h"
20#include "clang/AST/DeclTemplate.h"
21#include "clang/AST/DeclVisitor.h"
22#include "clang/AST/Expr.h"
Douglas Gregor022857e2011-12-22 01:48:48 +000023#include "clang/Sema/IdentifierResolver.h"
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +000024#include "clang/Sema/SemaDiagnostic.h"
Mehdi Amini9670f842016-07-18 19:02:11 +000025#include "clang/Serialization/ASTReader.h"
Argyrios Kyrtzidis0f7d7ab2012-05-04 01:49:36 +000026#include "llvm/Support/SaveAndRestore.h"
Hans Wennborgdcfba332015-10-06 23:40:43 +000027
Chris Lattner487412d2009-04-27 05:27:42 +000028using namespace clang;
Sebastian Redl539c5062010-08-18 23:57:32 +000029using namespace clang::serialization;
Chris Lattner487412d2009-04-27 05:27:42 +000030
31//===----------------------------------------------------------------------===//
32// Declaration deserialization
33//===----------------------------------------------------------------------===//
34
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +000035namespace clang {
Sebastian Redlb3298c32010-08-18 23:56:48 +000036 class ASTDeclReader : public DeclVisitor<ASTDeclReader, void> {
Sebastian Redl2c499f62010-08-18 23:56:43 +000037 ASTReader &Reader;
David L. Jonesc4808b9e2016-12-15 20:53:26 +000038 ASTRecordReader Record;
39 ASTReader::RecordLocation Loc;
Sebastian Redl539c5062010-08-18 23:57:32 +000040 const DeclID ThisDeclID;
Richard Smithcb34bd32016-03-27 07:28:06 +000041 const SourceLocation ThisDeclLoc;
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +000042 typedef ASTReader::RecordData RecordData;
Chris Lattner487412d2009-04-27 05:27:42 +000043 unsigned &Idx;
Sebastian Redl539c5062010-08-18 23:57:32 +000044 TypeID TypeIDForTypeDecl;
Richard Smithd08aeb62014-08-28 01:33:39 +000045 unsigned AnonymousDeclNumber;
Richard Smith70d58502014-08-30 00:04:23 +000046 GlobalDeclID NamedDeclForTagDecl;
47 IdentifierInfo *TypedefNameForLinkage;
Vassil Vassilev6565dfc2016-02-26 10:43:34 +000048
Douglas Gregora6017bb2012-10-09 17:21:28 +000049 bool HasPendingBody;
50
Vassil Vassilev928c8252016-04-28 14:13:28 +000051 ///\brief A flag to carry the information for a decl from the entity is
52 /// used. We use it to delay the marking of the canonical decl as used until
53 /// the entire declaration is deserialized and merged.
54 bool IsDeclMarkedUsed;
55
Sebastian Redlc67764e2010-07-22 22:43:28 +000056 uint64_t GetCurrentCursorOffset();
Vassil Vassilev6565dfc2016-02-26 10:43:34 +000057
David L. Jonesc4808b9e2016-12-15 20:53:26 +000058 uint64_t ReadLocalOffset() {
59 uint64_t LocalOffset = Record[Idx++];
60 assert(LocalOffset < Loc.Offset && "offset point after current record");
61 return LocalOffset ? Loc.Offset - LocalOffset : 0;
Richard Smithe37e9f42016-03-25 01:17:43 +000062 }
63
David L. Jonesc4808b9e2016-12-15 20:53:26 +000064 uint64_t ReadGlobalOffset() {
65 uint64_t Local = ReadLocalOffset();
66 return Local ? Record.getGlobalBitOffset(Local) : 0;
Richard Smithaa165cf2016-04-13 21:57:08 +000067 }
68
David L. Jonesc4808b9e2016-12-15 20:53:26 +000069 SourceLocation ReadSourceLocation() {
70 return Record.ReadSourceLocation(Idx);
Sebastian Redl2c373b92010-10-05 15:59:54 +000071 }
Vassil Vassilev6565dfc2016-02-26 10:43:34 +000072
David L. Jonesc4808b9e2016-12-15 20:53:26 +000073 SourceRange ReadSourceRange() {
74 return Record.ReadSourceRange(Idx);
Sebastian Redl2c373b92010-10-05 15:59:54 +000075 }
Vassil Vassilev6565dfc2016-02-26 10:43:34 +000076
David L. Jonesc4808b9e2016-12-15 20:53:26 +000077 TypeSourceInfo *GetTypeSourceInfo() {
78 return Record.GetTypeSourceInfo(Idx);
Sebastian Redl2c373b92010-10-05 15:59:54 +000079 }
Vassil Vassilev6565dfc2016-02-26 10:43:34 +000080
David L. Jonesc4808b9e2016-12-15 20:53:26 +000081 serialization::DeclID ReadDeclID() {
82 return Record.ReadDeclID(Idx);
Douglas Gregor7fb09192011-07-21 22:35:25 +000083 }
Richard Smith0b884372015-02-27 00:25:58 +000084
David L. Jonesc4808b9e2016-12-15 20:53:26 +000085 std::string ReadString() {
86 return Record.ReadString(Idx);
Nico Weber66220292016-03-02 17:28:48 +000087 }
88
Richard Smith0b884372015-02-27 00:25:58 +000089 void ReadDeclIDList(SmallVectorImpl<DeclID> &IDs) {
90 for (unsigned I = 0, Size = Record[Idx++]; I != Size; ++I)
David L. Jonesc4808b9e2016-12-15 20:53:26 +000091 IDs.push_back(ReadDeclID());
Richard Smith0b884372015-02-27 00:25:58 +000092 }
93
David L. Jonesc4808b9e2016-12-15 20:53:26 +000094 Decl *ReadDecl() {
95 return Record.ReadDecl(Idx);
Douglas Gregor7fb09192011-07-21 22:35:25 +000096 }
97
98 template<typename T>
David L. Jonesc4808b9e2016-12-15 20:53:26 +000099 T *ReadDeclAs() {
100 return Record.ReadDeclAs<T>(Idx);
Douglas Gregor7fb09192011-07-21 22:35:25 +0000101 }
102
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000103 void ReadQualifierInfo(QualifierInfo &Info) {
104 Record.ReadQualifierInfo(Info, Idx);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000105 }
Sebastian Redlc67764e2010-07-22 22:43:28 +0000106
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000107 void ReadDeclarationNameLoc(DeclarationNameLoc &DNLoc, DeclarationName Name) {
108 Record.ReadDeclarationNameLoc(DNLoc, Name, Idx);
109 }
110
111 void ReadDeclarationNameInfo(DeclarationNameInfo &NameInfo, unsigned &I) {
112 Record.ReadDeclarationNameInfo(NameInfo, I);
113 }
114
115 serialization::SubmoduleID readSubmoduleID() {
116 if (Idx >= Record.size())
Douglas Gregorcf68c582011-12-01 22:20:10 +0000117 return 0;
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000118
119 return Record.getGlobalSubmoduleID(Record[Idx++]);
Douglas Gregorcf68c582011-12-01 22:20:10 +0000120 }
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000121
122 Module *readModule() {
123 return Record.getSubmodule(readSubmoduleID());
Douglas Gregorba345522011-12-02 23:23:56 +0000124 }
Richard Smithcd45dbc2014-04-19 03:48:30 +0000125
Richard Smith2a9e5c52015-02-03 03:32:14 +0000126 void ReadCXXRecordDefinition(CXXRecordDecl *D, bool Update);
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +0000127 void ReadCXXDefinitionData(struct CXXRecordDecl::DefinitionData &Data,
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000128 unsigned &I);
Richard Smithcd45dbc2014-04-19 03:48:30 +0000129 void MergeDefinitionData(CXXRecordDecl *D,
Richard Smith8a639892015-01-24 01:07:20 +0000130 struct CXXRecordDecl::DefinitionData &&NewDD);
Manman Renec315f12016-09-09 23:48:27 +0000131 void ReadObjCDefinitionData(struct ObjCInterfaceDecl::DefinitionData &Data,
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000132 unsigned &I);
Manman Renec315f12016-09-09 23:48:27 +0000133 void MergeDefinitionData(ObjCInterfaceDecl *D,
134 struct ObjCInterfaceDecl::DefinitionData &&NewDD);
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +0000135
Richard Smithd08aeb62014-08-28 01:33:39 +0000136 static NamedDecl *getAnonymousDeclForMerging(ASTReader &Reader,
137 DeclContext *DC,
138 unsigned Index);
139 static void setAnonymousDeclForMerging(ASTReader &Reader, DeclContext *DC,
140 unsigned Index, NamedDecl *D);
141
Richard Smith0144f512015-08-22 02:09:38 +0000142 /// Results from loading a RedeclarableDecl.
Douglas Gregor022857e2011-12-22 01:48:48 +0000143 class RedeclarableResult {
Richard Smith5a4737c2015-02-06 02:42:59 +0000144 Decl *MergeWith;
Alexander Shaposhnikovfbc4d682016-09-24 04:21:53 +0000145 GlobalDeclID FirstID;
Richard Smith5fc18a92015-07-12 23:43:21 +0000146 bool IsKeyDecl;
Richard Smithc89bb9d2015-02-25 01:11:29 +0000147
Douglas Gregor022857e2011-12-22 01:48:48 +0000148 public:
Alexander Shaposhnikovfbc4d682016-09-24 04:21:53 +0000149 RedeclarableResult(Decl *MergeWith, GlobalDeclID FirstID, bool IsKeyDecl)
150 : MergeWith(MergeWith), FirstID(FirstID), IsKeyDecl(IsKeyDecl) {}
Richard Smith9b88a4c2015-07-27 05:40:23 +0000151
Douglas Gregor022857e2011-12-22 01:48:48 +0000152 /// \brief Retrieve the first ID.
153 GlobalDeclID getFirstID() const { return FirstID; }
Richard Smith5a4737c2015-02-06 02:42:59 +0000154
Richard Smith0144f512015-08-22 02:09:38 +0000155 /// \brief Is this declaration a key declaration?
Richard Smith5fc18a92015-07-12 23:43:21 +0000156 bool isKeyDecl() const { return IsKeyDecl; }
157
Richard Smith5a4737c2015-02-06 02:42:59 +0000158 /// \brief Get a known declaration that this should be merged with, if
159 /// any.
160 Decl *getKnownMergeTarget() const { return MergeWith; }
Douglas Gregor022857e2011-12-22 01:48:48 +0000161 };
Douglas Gregorfe732d52013-01-21 16:16:40 +0000162
Douglas Gregor022857e2011-12-22 01:48:48 +0000163 /// \brief Class used to capture the result of searching for an existing
164 /// declaration of a specific kind and name, along with the ability
165 /// to update the place where this result was found (the declaration
166 /// chain hanging off an identifier or the DeclContext we searched in)
167 /// if requested.
168 class FindExistingResult {
169 ASTReader &Reader;
170 NamedDecl *New;
171 NamedDecl *Existing;
Benjamin Kramerb6aadc12016-08-06 12:45:16 +0000172 bool AddResult;
Richard Smith70d58502014-08-30 00:04:23 +0000173
Richard Smithd08aeb62014-08-28 01:33:39 +0000174 unsigned AnonymousDeclNumber;
Richard Smith70d58502014-08-30 00:04:23 +0000175 IdentifierInfo *TypedefNameForLinkage;
Richard Smithd08aeb62014-08-28 01:33:39 +0000176
Benjamin Kramerb6aadc12016-08-06 12:45:16 +0000177 void operator=(FindExistingResult &&) = delete;
Richard Smithd08aeb62014-08-28 01:33:39 +0000178
Douglas Gregor022857e2011-12-22 01:48:48 +0000179 public:
180 FindExistingResult(ASTReader &Reader)
Richard Smithd08aeb62014-08-28 01:33:39 +0000181 : Reader(Reader), New(nullptr), Existing(nullptr), AddResult(false),
Hans Wennborgdcfba332015-10-06 23:40:43 +0000182 AnonymousDeclNumber(0), TypedefNameForLinkage(nullptr) {}
Craig Toppera13603a2014-05-22 05:54:18 +0000183
Richard Smithd08aeb62014-08-28 01:33:39 +0000184 FindExistingResult(ASTReader &Reader, NamedDecl *New, NamedDecl *Existing,
Richard Smith70d58502014-08-30 00:04:23 +0000185 unsigned AnonymousDeclNumber,
186 IdentifierInfo *TypedefNameForLinkage)
Richard Smithd08aeb62014-08-28 01:33:39 +0000187 : Reader(Reader), New(New), Existing(Existing), AddResult(true),
Richard Smith70d58502014-08-30 00:04:23 +0000188 AnonymousDeclNumber(AnonymousDeclNumber),
189 TypedefNameForLinkage(TypedefNameForLinkage) {}
Richard Smithd08aeb62014-08-28 01:33:39 +0000190
Benjamin Kramerb6aadc12016-08-06 12:45:16 +0000191 FindExistingResult(FindExistingResult &&Other)
Richard Smithd08aeb62014-08-28 01:33:39 +0000192 : Reader(Other.Reader), New(Other.New), Existing(Other.Existing),
193 AddResult(Other.AddResult),
Richard Smith70d58502014-08-30 00:04:23 +0000194 AnonymousDeclNumber(Other.AnonymousDeclNumber),
195 TypedefNameForLinkage(Other.TypedefNameForLinkage) {
Douglas Gregor022857e2011-12-22 01:48:48 +0000196 Other.AddResult = false;
197 }
Richard Smithd08aeb62014-08-28 01:33:39 +0000198
Douglas Gregor022857e2011-12-22 01:48:48 +0000199 ~FindExistingResult();
Richard Smithd08aeb62014-08-28 01:33:39 +0000200
Douglas Gregor2009cee2012-01-03 22:46:00 +0000201 /// \brief Suppress the addition of this result into the known set of
202 /// names.
203 void suppress() { AddResult = false; }
Richard Smithd08aeb62014-08-28 01:33:39 +0000204
Douglas Gregor022857e2011-12-22 01:48:48 +0000205 operator NamedDecl*() const { return Existing; }
Richard Smithd08aeb62014-08-28 01:33:39 +0000206
Douglas Gregor022857e2011-12-22 01:48:48 +0000207 template<typename T>
208 operator T*() const { return dyn_cast_or_null<T>(Existing); }
209 };
Richard Smithd08aeb62014-08-28 01:33:39 +0000210
Richard Smith8a639892015-01-24 01:07:20 +0000211 static DeclContext *getPrimaryContextForMerging(ASTReader &Reader,
212 DeclContext *DC);
Douglas Gregor022857e2011-12-22 01:48:48 +0000213 FindExistingResult findExisting(NamedDecl *D);
Richard Smithd08aeb62014-08-28 01:33:39 +0000214
Chris Lattner487412d2009-04-27 05:27:42 +0000215 public:
Richard Smithd07268c2016-03-24 23:41:14 +0000216 ASTDeclReader(ASTReader &Reader, ASTReader::RecordLocation Loc,
Richard Smithcb34bd32016-03-27 07:28:06 +0000217 DeclID thisDeclID, SourceLocation ThisDeclLoc,
Richard Smithd07268c2016-03-24 23:41:14 +0000218 const RecordData &Record, unsigned &Idx)
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000219 : Reader(Reader), Record(Reader, Record, *Loc.F), Loc(Loc),
220 ThisDeclID(thisDeclID), ThisDeclLoc(ThisDeclLoc),
221 Idx(Idx), TypeIDForTypeDecl(0), NamedDeclForTagDecl(0),
Vassil Vassilev928c8252016-04-28 14:13:28 +0000222 TypedefNameForLinkage(nullptr), HasPendingBody(false),
223 IsDeclMarkedUsed(false) {}
Chris Lattner487412d2009-04-27 05:27:42 +0000224
Richard Smithb321ecb2014-05-13 01:15:00 +0000225 template <typename DeclT>
Richard Smithc3a53252015-02-28 05:57:02 +0000226 static Decl *getMostRecentDeclImpl(Redeclarable<DeclT> *D);
227 static Decl *getMostRecentDeclImpl(...);
228 static Decl *getMostRecentDecl(Decl *D);
229
230 template <typename DeclT>
Richard Smith6de7a242014-07-31 23:46:44 +0000231 static void attachPreviousDeclImpl(ASTReader &Reader,
Richard Smith9e2341d2015-03-23 03:25:59 +0000232 Redeclarable<DeclT> *D, Decl *Previous,
233 Decl *Canon);
Richard Smith6de7a242014-07-31 23:46:44 +0000234 static void attachPreviousDeclImpl(ASTReader &Reader, ...);
Richard Smith9e2341d2015-03-23 03:25:59 +0000235 static void attachPreviousDecl(ASTReader &Reader, Decl *D, Decl *Previous,
236 Decl *Canon);
Richard Smithb321ecb2014-05-13 01:15:00 +0000237
238 template <typename DeclT>
239 static void attachLatestDeclImpl(Redeclarable<DeclT> *D, Decl *Latest);
240 static void attachLatestDeclImpl(...);
Douglas Gregor05f10352011-12-17 23:38:30 +0000241 static void attachLatestDecl(Decl *D, Decl *latest);
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +0000242
Richard Smith851072e2014-05-19 20:59:20 +0000243 template <typename DeclT>
244 static void markIncompleteDeclChainImpl(Redeclarable<DeclT> *D);
245 static void markIncompleteDeclChainImpl(...);
246
Douglas Gregora6017bb2012-10-09 17:21:28 +0000247 /// \brief Determine whether this declaration has a pending body.
248 bool hasPendingBody() const { return HasPendingBody; }
249
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000250 void Visit(Decl *D);
251
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000252 void UpdateDecl(Decl *D);
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +0000253
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +0000254 static void setNextObjCCategory(ObjCCategoryDecl *Cat,
255 ObjCCategoryDecl *Next) {
256 Cat->NextClassCategory = Next;
257 }
258
Chris Lattner487412d2009-04-27 05:27:42 +0000259 void VisitDecl(Decl *D);
Nico Weber66220292016-03-02 17:28:48 +0000260 void VisitPragmaCommentDecl(PragmaCommentDecl *D);
Nico Webercbbaeb12016-03-02 19:28:54 +0000261 void VisitPragmaDetectMismatchDecl(PragmaDetectMismatchDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000262 void VisitTranslationUnitDecl(TranslationUnitDecl *TU);
263 void VisitNamedDecl(NamedDecl *ND);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000264 void VisitLabelDecl(LabelDecl *LD);
Douglas Gregore31bbd92010-02-21 18:22:14 +0000265 void VisitNamespaceDecl(NamespaceDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000266 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
267 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000268 void VisitTypeDecl(TypeDecl *TD);
Richard Smith43ccec8e2014-08-26 03:52:16 +0000269 RedeclarableResult VisitTypedefNameDecl(TypedefNameDecl *TD);
Chris Lattner487412d2009-04-27 05:27:42 +0000270 void VisitTypedefDecl(TypedefDecl *TD);
Richard Smithdda56e42011-04-15 14:24:37 +0000271 void VisitTypeAliasDecl(TypeAliasDecl *TD);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +0000272 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
Richard Smith1d209d02013-05-23 01:49:11 +0000273 RedeclarableResult VisitTagDecl(TagDecl *TD);
Chris Lattner487412d2009-04-27 05:27:42 +0000274 void VisitEnumDecl(EnumDecl *ED);
Richard Smith1d209d02013-05-23 01:49:11 +0000275 RedeclarableResult VisitRecordDeclImpl(RecordDecl *RD);
276 void VisitRecordDecl(RecordDecl *RD) { VisitRecordDeclImpl(RD); }
277 RedeclarableResult VisitCXXRecordDeclImpl(CXXRecordDecl *D);
278 void VisitCXXRecordDecl(CXXRecordDecl *D) { VisitCXXRecordDeclImpl(D); }
279 RedeclarableResult VisitClassTemplateSpecializationDeclImpl(
Chris Lattnerca025db2010-05-07 21:43:38 +0000280 ClassTemplateSpecializationDecl *D);
Richard Smith1d209d02013-05-23 01:49:11 +0000281 void VisitClassTemplateSpecializationDecl(
282 ClassTemplateSpecializationDecl *D) {
283 VisitClassTemplateSpecializationDeclImpl(D);
284 }
Chris Lattnerca025db2010-05-07 21:43:38 +0000285 void VisitClassTemplatePartialSpecializationDecl(
286 ClassTemplatePartialSpecializationDecl *D);
Sebastian Redlb7448632011-08-31 13:59:56 +0000287 void VisitClassScopeFunctionSpecializationDecl(
288 ClassScopeFunctionSpecializationDecl *D);
Larisse Voufo39a1e502013-08-06 01:03:05 +0000289 RedeclarableResult
290 VisitVarTemplateSpecializationDeclImpl(VarTemplateSpecializationDecl *D);
291 void VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D) {
292 VisitVarTemplateSpecializationDeclImpl(D);
293 }
294 void VisitVarTemplatePartialSpecializationDecl(
295 VarTemplatePartialSpecializationDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000296 void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000297 void VisitValueDecl(ValueDecl *VD);
298 void VisitEnumConstantDecl(EnumConstantDecl *ECD);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +0000299 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000300 void VisitDeclaratorDecl(DeclaratorDecl *DD);
Chris Lattner487412d2009-04-27 05:27:42 +0000301 void VisitFunctionDecl(FunctionDecl *FD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000302 void VisitCXXMethodDecl(CXXMethodDecl *D);
303 void VisitCXXConstructorDecl(CXXConstructorDecl *D);
304 void VisitCXXDestructorDecl(CXXDestructorDecl *D);
305 void VisitCXXConversionDecl(CXXConversionDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000306 void VisitFieldDecl(FieldDecl *FD);
John McCall5e77d762013-04-16 07:28:30 +0000307 void VisitMSPropertyDecl(MSPropertyDecl *FD);
Francois Pichet783dd6e2010-11-21 06:08:52 +0000308 void VisitIndirectFieldDecl(IndirectFieldDecl *FD);
Larisse Voufo39a1e502013-08-06 01:03:05 +0000309 RedeclarableResult VisitVarDeclImpl(VarDecl *D);
310 void VisitVarDecl(VarDecl *VD) { VisitVarDeclImpl(VD); }
Chris Lattner487412d2009-04-27 05:27:42 +0000311 void VisitImplicitParamDecl(ImplicitParamDecl *PD);
312 void VisitParmVarDecl(ParmVarDecl *PD);
Richard Smith7b76d812016-08-12 02:21:25 +0000313 void VisitDecompositionDecl(DecompositionDecl *DD);
314 void VisitBindingDecl(BindingDecl *BD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000315 void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
Richard Smithf17fdbd2014-04-24 02:25:27 +0000316 DeclID VisitTemplateDecl(TemplateDecl *D);
Douglas Gregor54079202012-01-06 22:05:37 +0000317 RedeclarableResult VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000318 void VisitClassTemplateDecl(ClassTemplateDecl *D);
David Majnemerd9b1a4f2015-11-04 03:40:30 +0000319 void VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D);
Larisse Voufo39a1e502013-08-06 01:03:05 +0000320 void VisitVarTemplateDecl(VarTemplateDecl *D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000321 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000322 void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
Richard Smith3f1b5d02011-05-05 21:57:07 +0000323 void VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D);
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +0000324 void VisitUsingDecl(UsingDecl *D);
325 void VisitUsingShadowDecl(UsingShadowDecl *D);
Richard Smith5179eb72016-06-28 19:03:57 +0000326 void VisitConstructorUsingShadowDecl(ConstructorUsingShadowDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000327 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
Richard Smith8df390f2016-09-08 23:14:54 +0000328 void VisitExportDecl(ExportDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000329 void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD);
Douglas Gregorba345522011-12-02 23:23:56 +0000330 void VisitImportDecl(ImportDecl *D);
Abramo Bagnarad7340582010-06-05 05:09:32 +0000331 void VisitAccessSpecDecl(AccessSpecDecl *D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000332 void VisitFriendDecl(FriendDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000333 void VisitFriendTemplateDecl(FriendTemplateDecl *D);
334 void VisitStaticAssertDecl(StaticAssertDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000335 void VisitBlockDecl(BlockDecl *BD);
Tareq A. Siraj6dfa25a2013-04-16 19:37:38 +0000336 void VisitCapturedDecl(CapturedDecl *CD);
Michael Han84324352013-02-22 17:15:32 +0000337 void VisitEmptyDecl(EmptyDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000338
Chris Lattner487412d2009-04-27 05:27:42 +0000339 std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC);
Richard Smithf17fdbd2014-04-24 02:25:27 +0000340
341 template<typename T>
Douglas Gregor022857e2011-12-22 01:48:48 +0000342 RedeclarableResult VisitRedeclarable(Redeclarable<T> *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000343
Douglas Gregor2c46b5b2012-01-03 17:27:13 +0000344 template<typename T>
Richard Smithf17fdbd2014-04-24 02:25:27 +0000345 void mergeRedeclarable(Redeclarable<T> *D, RedeclarableResult &Redecl,
346 DeclID TemplatePatternID = 0);
Richard Smithd55889a2013-09-09 16:55:27 +0000347
348 template<typename T>
349 void mergeRedeclarable(Redeclarable<T> *D, T *Existing,
Richard Smithf17fdbd2014-04-24 02:25:27 +0000350 RedeclarableResult &Redecl,
351 DeclID TemplatePatternID = 0);
Richard Smithd55889a2013-09-09 16:55:27 +0000352
Richard Smith0b87e072013-10-07 08:02:11 +0000353 template<typename T>
354 void mergeMergeable(Mergeable<T> *D);
355
Richard Smithf17fdbd2014-04-24 02:25:27 +0000356 void mergeTemplatePattern(RedeclarableTemplateDecl *D,
357 RedeclarableTemplateDecl *Existing,
Richard Smith5fc18a92015-07-12 23:43:21 +0000358 DeclID DsID, bool IsKeyDecl);
Richard Smithf17fdbd2014-04-24 02:25:27 +0000359
Douglas Gregor85f3f952015-07-07 03:57:15 +0000360 ObjCTypeParamList *ReadObjCTypeParamList();
361
Alexis Hunted053252010-05-30 07:21:58 +0000362 // FIXME: Reorder according to DeclNodes.td?
Chris Lattner487412d2009-04-27 05:27:42 +0000363 void VisitObjCMethodDecl(ObjCMethodDecl *D);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000364 void VisitObjCTypeParamDecl(ObjCTypeParamDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000365 void VisitObjCContainerDecl(ObjCContainerDecl *D);
366 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
367 void VisitObjCIvarDecl(ObjCIvarDecl *D);
368 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
369 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000370 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
371 void VisitObjCImplDecl(ObjCImplDecl *D);
372 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
373 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
374 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
375 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
376 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
Alexey Bataeva769e072013-03-22 06:34:35 +0000377 void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D);
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000378 void VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D);
Alexey Bataev4244be22016-02-11 05:35:55 +0000379 void VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000380 };
Hans Wennborgdcfba332015-10-06 23:40:43 +0000381} // end namespace clang
Chris Lattner487412d2009-04-27 05:27:42 +0000382
Richard Smith86dfc1e2015-06-18 22:07:00 +0000383namespace {
384/// Iterator over the redeclarations of a declaration that have already
385/// been merged into the same redeclaration chain.
386template<typename DeclT>
387class MergedRedeclIterator {
388 DeclT *Start, *Canonical, *Current;
389public:
390 MergedRedeclIterator() : Current(nullptr) {}
391 MergedRedeclIterator(DeclT *Start)
392 : Start(Start), Canonical(nullptr), Current(Start) {}
393
394 DeclT *operator*() { return Current; }
395
396 MergedRedeclIterator &operator++() {
397 if (Current->isFirstDecl()) {
398 Canonical = Current;
399 Current = Current->getMostRecentDecl();
400 } else
401 Current = Current->getPreviousDecl();
402
403 // If we started in the merged portion, we'll reach our start position
404 // eventually. Otherwise, we'll never reach it, but the second declaration
405 // we reached was the canonical declaration, so stop when we see that one
406 // again.
407 if (Current == Start || Current == Canonical)
408 Current = nullptr;
409 return *this;
410 }
411
412 friend bool operator!=(const MergedRedeclIterator &A,
413 const MergedRedeclIterator &B) {
414 return A.Current != B.Current;
415 }
416};
Hans Wennborgdcfba332015-10-06 23:40:43 +0000417} // end anonymous namespace
418
Benjamin Kramera0a13c32016-08-06 11:21:04 +0000419template <typename DeclT>
420static llvm::iterator_range<MergedRedeclIterator<DeclT>>
421merged_redecls(DeclT *D) {
Craig Topper59c2ada2015-12-06 05:07:12 +0000422 return llvm::make_range(MergedRedeclIterator<DeclT>(D),
423 MergedRedeclIterator<DeclT>());
Richard Smith86dfc1e2015-06-18 22:07:00 +0000424}
425
Sebastian Redlb3298c32010-08-18 23:56:48 +0000426uint64_t ASTDeclReader::GetCurrentCursorOffset() {
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000427 return Loc.F->DeclsCursor.GetCurrentBitNo() + Loc.F->GlobalBitOffset;
Sebastian Redlc67764e2010-07-22 22:43:28 +0000428}
429
Sebastian Redlb3298c32010-08-18 23:56:48 +0000430void ASTDeclReader::Visit(Decl *D) {
431 DeclVisitor<ASTDeclReader, void>::Visit(D);
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000432
Vassil Vassilev928c8252016-04-28 14:13:28 +0000433 // At this point we have deserialized and merged the decl and it is safe to
434 // update its canonical decl to signal that the entire entity is used.
435 D->getCanonicalDecl()->Used |= IsDeclMarkedUsed;
436 IsDeclMarkedUsed = false;
437
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000438 if (DeclaratorDecl *DD = dyn_cast<DeclaratorDecl>(D)) {
439 if (DD->DeclInfo) {
440 DeclaratorDecl::ExtInfo *Info =
441 DD->DeclInfo.get<DeclaratorDecl::ExtInfo *>();
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000442 Info->TInfo = GetTypeSourceInfo();
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000443 }
444 else {
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000445 DD->DeclInfo = GetTypeSourceInfo();
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000446 }
447 }
448
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000449 if (TypeDecl *TD = dyn_cast<TypeDecl>(D)) {
Richard Smithf17fdbd2014-04-24 02:25:27 +0000450 // We have a fully initialized TypeDecl. Read its type now.
Douglas Gregor0cdc8322010-12-10 17:03:06 +0000451 TD->setTypeForDecl(Reader.GetType(TypeIDForTypeDecl).getTypePtrOrNull());
Richard Smith70d58502014-08-30 00:04:23 +0000452
453 // If this is a tag declaration with a typedef name for linkage, it's safe
454 // to load that typedef now.
455 if (NamedDeclForTagDecl)
David Majnemer00350522015-08-31 18:48:39 +0000456 cast<TagDecl>(D)->TypedefNameDeclOrQualifier =
457 cast<TypedefNameDecl>(Reader.GetDecl(NamedDeclForTagDecl));
Douglas Gregorab1ec82e2011-12-16 03:12:41 +0000458 } else if (ObjCInterfaceDecl *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
459 // if we have a fully initialized TypeDecl, we can safely read its type now.
460 ID->TypeForDecl = Reader.GetType(TypeIDForTypeDecl).getTypePtrOrNull();
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000461 } else if (FunctionDecl *FD = dyn_cast<FunctionDecl>(D)) {
462 // FunctionDecl's body was written last after all other Stmts/Exprs.
Douglas Gregor559458c2012-10-03 18:34:48 +0000463 // We only read it if FD doesn't already have a body (e.g., from another
464 // module).
Douglas Gregore4a838a2012-10-03 18:36:10 +0000465 // FIXME: Can we diagnose ODR violations somehow?
Douglas Gregora6017bb2012-10-09 17:21:28 +0000466 if (Record[Idx++]) {
Richard Smithc2bb8182015-03-24 06:36:48 +0000467 if (auto *CD = dyn_cast<CXXConstructorDecl>(FD)) {
468 CD->NumCtorInitializers = Record[Idx++];
469 if (CD->NumCtorInitializers)
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000470 CD->CtorInitializers = ReadGlobalOffset();
Richard Smithc2bb8182015-03-24 06:36:48 +0000471 }
Douglas Gregora6017bb2012-10-09 17:21:28 +0000472 Reader.PendingBodies[FD] = GetCurrentCursorOffset();
473 HasPendingBody = true;
474 }
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000475 }
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000476}
477
Sebastian Redlb3298c32010-08-18 23:56:48 +0000478void ASTDeclReader::VisitDecl(Decl *D) {
Dmitri Gribenkob353ee12013-12-19 02:05:20 +0000479 if (D->isTemplateParameter() || D->isTemplateParameterPack() ||
480 isa<ParmVarDecl>(D)) {
Douglas Gregor250ffb12011-03-05 01:35:54 +0000481 // We don't want to deserialize the DeclContext of a template
Dmitri Gribenkob353ee12013-12-19 02:05:20 +0000482 // parameter or of a parameter of a function template immediately. These
483 // entities might be used in the formulation of its DeclContext (for
484 // example, a function parameter can be used in decltype() in trailing
485 // return type of the function). Use the translation unit DeclContext as a
486 // placeholder.
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000487 GlobalDeclID SemaDCIDForTemplateParmDecl = ReadDeclID();
488 GlobalDeclID LexicalDCIDForTemplateParmDecl = ReadDeclID();
Richard Smith8aed4222015-12-11 22:41:00 +0000489 if (!LexicalDCIDForTemplateParmDecl)
490 LexicalDCIDForTemplateParmDecl = SemaDCIDForTemplateParmDecl;
Argyrios Kyrtzidis83a6e3b2013-02-16 00:48:59 +0000491 Reader.addPendingDeclContextInfo(D,
492 SemaDCIDForTemplateParmDecl,
493 LexicalDCIDForTemplateParmDecl);
Douglas Gregor4163aca2011-09-09 21:34:22 +0000494 D->setDeclContext(Reader.getContext().getTranslationUnitDecl());
Douglas Gregor250ffb12011-03-05 01:35:54 +0000495 } else {
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000496 DeclContext *SemaDC = ReadDeclAs<DeclContext>();
497 DeclContext *LexicalDC = ReadDeclAs<DeclContext>();
Richard Smith8aed4222015-12-11 22:41:00 +0000498 if (!LexicalDC)
499 LexicalDC = SemaDC;
Richard Smithd55889a2013-09-09 16:55:27 +0000500 DeclContext *MergedSemaDC = Reader.MergedDeclContexts.lookup(SemaDC);
Argyrios Kyrtzidis7456ac42012-02-09 07:46:54 +0000501 // Avoid calling setLexicalDeclContext() directly because it uses
502 // Decl::getASTContext() internally which is unsafe during derialization.
Richard Smithd55889a2013-09-09 16:55:27 +0000503 D->setDeclContextsImpl(MergedSemaDC ? MergedSemaDC : SemaDC, LexicalDC,
504 Reader.getContext());
Douglas Gregor250ffb12011-03-05 01:35:54 +0000505 }
Richard Smithcb34bd32016-03-27 07:28:06 +0000506 D->setLocation(ThisDeclLoc);
Chris Lattner487412d2009-04-27 05:27:42 +0000507 D->setInvalidDecl(Record[Idx++]);
Argyrios Kyrtzidis9beef8e2010-10-18 19:20:11 +0000508 if (Record[Idx++]) { // hasAttrs
Alexis Huntdcfba7b2010-08-18 23:23:40 +0000509 AttrVec Attrs;
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000510 Record.ReadAttributes(Attrs, Idx);
Argyrios Kyrtzidis7456ac42012-02-09 07:46:54 +0000511 // Avoid calling setAttrs() directly because it uses Decl::getASTContext()
512 // internally which is unsafe during derialization.
Argyrios Kyrtzidis6f40eb72012-02-09 02:44:08 +0000513 D->setAttrsImpl(Attrs, Reader.getContext());
Alexis Huntdcfba7b2010-08-18 23:23:40 +0000514 }
Chris Lattner487412d2009-04-27 05:27:42 +0000515 D->setImplicit(Record[Idx++]);
Rafael Espindolae4865d22013-10-23 16:46:34 +0000516 D->Used = Record[Idx++];
Vassil Vassilev928c8252016-04-28 14:13:28 +0000517 IsDeclMarkedUsed |= D->Used;
Argyrios Kyrtzidis16180232011-04-19 19:51:10 +0000518 D->setReferenced(Record[Idx++]);
Douglas Gregor781f7132012-01-06 16:59:53 +0000519 D->setTopLevelDeclInObjCContainer(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000520 D->setAccess((AccessSpecifier)Record[Idx++]);
Douglas Gregor98c05b22011-09-10 00:09:20 +0000521 D->FromASTFile = true;
Douglas Gregor781f7132012-01-06 16:59:53 +0000522 D->setModulePrivate(Record[Idx++]);
523 D->Hidden = D->isModulePrivate();
Richard Smith42413142015-05-15 20:05:43 +0000524
Douglas Gregorcf68c582011-12-01 22:20:10 +0000525 // Determine whether this declaration is part of a (sub)module. If so, it
526 // may not yet be visible.
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000527 if (unsigned SubmoduleID = readSubmoduleID()) {
Douglas Gregorcfe7dc62012-01-09 17:30:44 +0000528 // Store the owning submodule ID in the declaration.
529 D->setOwningModuleID(SubmoduleID);
Richard Smith42413142015-05-15 20:05:43 +0000530
531 if (D->Hidden) {
532 // Module-private declarations are never visible, so there is no work to do.
533 } else if (Reader.getContext().getLangOpts().ModulesLocalVisibility) {
534 // If local visibility is being tracked, this declaration will become
535 // hidden and visible as the owning module does. Inform Sema that this
536 // declaration might not be visible.
537 D->Hidden = true;
538 } else if (Module *Owner = Reader.getSubmodule(SubmoduleID)) {
539 if (Owner->NameVisibility != Module::AllVisible) {
540 // The owning module is not visible. Mark this declaration as hidden.
541 D->Hidden = true;
Vassil Vassilev928c8252016-04-28 14:13:28 +0000542
Richard Smith42413142015-05-15 20:05:43 +0000543 // Note that this declaration was hidden because its owning module is
544 // not yet visible.
545 Reader.HiddenNamesMap[Owner].push_back(D);
Douglas Gregorcf68c582011-12-01 22:20:10 +0000546 }
547 }
548 }
Chris Lattner487412d2009-04-27 05:27:42 +0000549}
550
Nico Weber66220292016-03-02 17:28:48 +0000551void ASTDeclReader::VisitPragmaCommentDecl(PragmaCommentDecl *D) {
552 VisitDecl(D);
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000553 D->setLocation(ReadSourceLocation());
Nico Weber66220292016-03-02 17:28:48 +0000554 D->CommentKind = (PragmaMSCommentKind)Record[Idx++];
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000555 std::string Arg = ReadString();
Nico Weber66220292016-03-02 17:28:48 +0000556 memcpy(D->getTrailingObjects<char>(), Arg.data(), Arg.size());
557 D->getTrailingObjects<char>()[Arg.size()] = '\0';
558}
559
Nico Webercbbaeb12016-03-02 19:28:54 +0000560void ASTDeclReader::VisitPragmaDetectMismatchDecl(PragmaDetectMismatchDecl *D) {
561 VisitDecl(D);
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000562 D->setLocation(ReadSourceLocation());
563 std::string Name = ReadString();
Nico Webercbbaeb12016-03-02 19:28:54 +0000564 memcpy(D->getTrailingObjects<char>(), Name.data(), Name.size());
565 D->getTrailingObjects<char>()[Name.size()] = '\0';
566
567 D->ValueStart = Name.size() + 1;
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000568 std::string Value = ReadString();
Nico Webercbbaeb12016-03-02 19:28:54 +0000569 memcpy(D->getTrailingObjects<char>() + D->ValueStart, Value.data(),
570 Value.size());
571 D->getTrailingObjects<char>()[D->ValueStart + Value.size()] = '\0';
572}
573
Sebastian Redlb3298c32010-08-18 23:56:48 +0000574void ASTDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) {
Douglas Gregordab42432011-08-12 00:15:20 +0000575 llvm_unreachable("Translation units are not serialized");
Chris Lattner487412d2009-04-27 05:27:42 +0000576}
577
Sebastian Redlb3298c32010-08-18 23:56:48 +0000578void ASTDeclReader::VisitNamedDecl(NamedDecl *ND) {
Chris Lattner487412d2009-04-27 05:27:42 +0000579 VisitDecl(ND);
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000580 ND->setDeclName(Record.ReadDeclarationName(Idx));
Richard Smith2b560572015-02-07 03:11:11 +0000581 AnonymousDeclNumber = Record[Idx++];
Chris Lattner487412d2009-04-27 05:27:42 +0000582}
583
Sebastian Redlb3298c32010-08-18 23:56:48 +0000584void ASTDeclReader::VisitTypeDecl(TypeDecl *TD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000585 VisitNamedDecl(TD);
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000586 TD->setLocStart(ReadSourceLocation());
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000587 // Delay type reading until after we have fully initialized the decl.
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000588 TypeIDForTypeDecl = Record.getGlobalTypeID(Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +0000589}
590
Richard Smith43ccec8e2014-08-26 03:52:16 +0000591ASTDeclReader::RedeclarableResult
592ASTDeclReader::VisitTypedefNameDecl(TypedefNameDecl *TD) {
Douglas Gregor9b7b3912012-01-04 16:44:10 +0000593 RedeclarableResult Redecl = VisitRedeclarable(TD);
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000594 VisitTypeDecl(TD);
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000595 TypeSourceInfo *TInfo = GetTypeSourceInfo();
Enea Zaffanellaa86d88c2013-06-20 12:46:19 +0000596 if (Record[Idx++]) { // isModed
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000597 QualType modedT = Record.readType(Idx);
Enea Zaffanellaa86d88c2013-06-20 12:46:19 +0000598 TD->setModedTypeSourceInfo(TInfo, modedT);
599 } else
600 TD->setTypeSourceInfo(TInfo);
Richard Smith43ccec8e2014-08-26 03:52:16 +0000601 return Redecl;
Douglas Gregor1f179062011-12-19 14:40:25 +0000602}
603
604void ASTDeclReader::VisitTypedefDecl(TypedefDecl *TD) {
Richard Smith43ccec8e2014-08-26 03:52:16 +0000605 RedeclarableResult Redecl = VisitTypedefNameDecl(TD);
606 mergeRedeclarable(TD, Redecl);
Chris Lattner487412d2009-04-27 05:27:42 +0000607}
608
Richard Smithdda56e42011-04-15 14:24:37 +0000609void ASTDeclReader::VisitTypeAliasDecl(TypeAliasDecl *TD) {
Richard Smith43ccec8e2014-08-26 03:52:16 +0000610 RedeclarableResult Redecl = VisitTypedefNameDecl(TD);
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000611 if (auto *Template = ReadDeclAs<TypeAliasTemplateDecl>())
Richard Smith43ccec8e2014-08-26 03:52:16 +0000612 // Merged when we merge the template.
613 TD->setDescribedAliasTemplate(Template);
614 else
615 mergeRedeclarable(TD, Redecl);
Richard Smithdda56e42011-04-15 14:24:37 +0000616}
617
Richard Smith1d209d02013-05-23 01:49:11 +0000618ASTDeclReader::RedeclarableResult ASTDeclReader::VisitTagDecl(TagDecl *TD) {
Douglas Gregor2009cee2012-01-03 22:46:00 +0000619 RedeclarableResult Redecl = VisitRedeclarable(TD);
Douglas Gregor3e300102011-10-26 17:53:41 +0000620 VisitTypeDecl(TD);
Douglas Gregor2009cee2012-01-03 22:46:00 +0000621
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000622 TD->IdentifierNamespace = Record[Idx++];
Chris Lattner487412d2009-04-27 05:27:42 +0000623 TD->setTagKind((TagDecl::TagKind)Record[Idx++]);
Richard Smith2c381642014-08-27 23:11:59 +0000624 if (!isa<CXXRecordDecl>(TD))
625 TD->setCompleteDefinition(Record[Idx++]);
Douglas Gregor5089c762010-02-12 17:40:34 +0000626 TD->setEmbeddedInDeclarator(Record[Idx++]);
Argyrios Kyrtzidis201d3772011-09-30 22:11:31 +0000627 TD->setFreeStanding(Record[Idx++]);
David Blaikiea8d23ce2013-07-14 01:07:41 +0000628 TD->setCompleteDefinitionRequired(Record[Idx++]);
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000629 TD->setBraceRange(ReadSourceRange());
Douglas Gregor2009cee2012-01-03 22:46:00 +0000630
Richard Smith70d58502014-08-30 00:04:23 +0000631 switch (Record[Idx++]) {
632 case 0:
633 break;
634 case 1: { // ExtInfo
Douglas Gregor4163aca2011-09-09 21:34:22 +0000635 TagDecl::ExtInfo *Info = new (Reader.getContext()) TagDecl::ExtInfo();
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000636 ReadQualifierInfo(*Info);
David Majnemer00350522015-08-31 18:48:39 +0000637 TD->TypedefNameDeclOrQualifier = Info;
Richard Smith70d58502014-08-30 00:04:23 +0000638 break;
639 }
640 case 2: // TypedefNameForAnonDecl
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000641 NamedDeclForTagDecl = ReadDeclID();
642 TypedefNameForLinkage = Record.GetIdentifierInfo(Idx);
Richard Smith70d58502014-08-30 00:04:23 +0000643 break;
Richard Smith70d58502014-08-30 00:04:23 +0000644 default:
645 llvm_unreachable("unexpected tag info kind");
646 }
Douglas Gregor2009cee2012-01-03 22:46:00 +0000647
Richard Smithcd45dbc2014-04-19 03:48:30 +0000648 if (!isa<CXXRecordDecl>(TD))
649 mergeRedeclarable(TD, Redecl);
Richard Smith1d209d02013-05-23 01:49:11 +0000650 return Redecl;
Chris Lattner487412d2009-04-27 05:27:42 +0000651}
652
Sebastian Redlb3298c32010-08-18 23:56:48 +0000653void ASTDeclReader::VisitEnumDecl(EnumDecl *ED) {
Chris Lattner487412d2009-04-27 05:27:42 +0000654 VisitTagDecl(ED);
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000655 if (TypeSourceInfo *TI = GetTypeSourceInfo())
Douglas Gregor0bf31402010-10-08 23:50:27 +0000656 ED->setIntegerTypeSourceInfo(TI);
657 else
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000658 ED->setIntegerType(Record.readType(Idx));
659 ED->setPromotionType(Record.readType(Idx));
John McCall9aa35be2010-05-06 08:49:23 +0000660 ED->setNumPositiveBits(Record[Idx++]);
661 ED->setNumNegativeBits(Record[Idx++]);
Douglas Gregor0bf31402010-10-08 23:50:27 +0000662 ED->IsScoped = Record[Idx++];
Abramo Bagnara0e05e242010-12-03 18:54:17 +0000663 ED->IsScopedUsingClassTag = Record[Idx++];
Douglas Gregor0bf31402010-10-08 23:50:27 +0000664 ED->IsFixed = Record[Idx++];
Richard Smith4b38ded2012-03-14 23:13:10 +0000665
Richard Smith01a73372013-10-15 22:02:41 +0000666 // If this is a definition subject to the ODR, and we already have a
667 // definition, merge this one into it.
668 if (ED->IsCompleteDefinition &&
669 Reader.getContext().getLangOpts().Modules &&
670 Reader.getContext().getLangOpts().CPlusPlus) {
Richard Smith86dfc1e2015-06-18 22:07:00 +0000671 EnumDecl *&OldDef = Reader.EnumDefinitions[ED->getCanonicalDecl()];
672 if (!OldDef) {
673 // This is the first time we've seen an imported definition. Look for a
674 // local definition before deciding that we are the first definition.
675 for (auto *D : merged_redecls(ED->getCanonicalDecl())) {
676 if (!D->isFromASTFile() && D->isCompleteDefinition()) {
677 OldDef = D;
678 break;
679 }
680 }
681 }
682 if (OldDef) {
Richard Smith01a73372013-10-15 22:02:41 +0000683 Reader.MergedDeclContexts.insert(std::make_pair(ED, OldDef));
684 ED->IsCompleteDefinition = false;
Richard Smith6561f922016-09-12 21:06:40 +0000685 Reader.mergeDefinitionVisibility(OldDef, ED);
Richard Smith01a73372013-10-15 22:02:41 +0000686 } else {
687 OldDef = ED;
688 }
689 }
690
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000691 if (EnumDecl *InstED = ReadDeclAs<EnumDecl>()) {
Richard Smith4b38ded2012-03-14 23:13:10 +0000692 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000693 SourceLocation POI = ReadSourceLocation();
Richard Smith4b38ded2012-03-14 23:13:10 +0000694 ED->setInstantiationOfMemberEnum(Reader.getContext(), InstED, TSK);
695 ED->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
696 }
Chris Lattner487412d2009-04-27 05:27:42 +0000697}
698
Richard Smith1d209d02013-05-23 01:49:11 +0000699ASTDeclReader::RedeclarableResult
700ASTDeclReader::VisitRecordDeclImpl(RecordDecl *RD) {
701 RedeclarableResult Redecl = VisitTagDecl(RD);
Chris Lattner487412d2009-04-27 05:27:42 +0000702 RD->setHasFlexibleArrayMember(Record[Idx++]);
703 RD->setAnonymousStructOrUnion(Record[Idx++]);
Fariborz Jahanian8e0d0422009-07-08 16:37:44 +0000704 RD->setHasObjectMember(Record[Idx++]);
Fariborz Jahanian78652202013-01-25 23:57:05 +0000705 RD->setHasVolatileMember(Record[Idx++]);
Richard Smith1d209d02013-05-23 01:49:11 +0000706 return Redecl;
Chris Lattner487412d2009-04-27 05:27:42 +0000707}
708
Sebastian Redlb3298c32010-08-18 23:56:48 +0000709void ASTDeclReader::VisitValueDecl(ValueDecl *VD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000710 VisitNamedDecl(VD);
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000711 VD->setType(Record.readType(Idx));
Chris Lattner487412d2009-04-27 05:27:42 +0000712}
713
Sebastian Redlb3298c32010-08-18 23:56:48 +0000714void ASTDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000715 VisitValueDecl(ECD);
716 if (Record[Idx++])
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000717 ECD->setInitExpr(Record.ReadExpr());
718 ECD->setInitVal(Record.ReadAPSInt(Idx));
Richard Smith01a73372013-10-15 22:02:41 +0000719 mergeMergeable(ECD);
Chris Lattner487412d2009-04-27 05:27:42 +0000720}
721
Sebastian Redlb3298c32010-08-18 23:56:48 +0000722void ASTDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000723 VisitValueDecl(DD);
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000724 DD->setInnerLocStart(ReadSourceLocation());
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000725 if (Record[Idx++]) { // hasExtInfo
726 DeclaratorDecl::ExtInfo *Info
Douglas Gregor4163aca2011-09-09 21:34:22 +0000727 = new (Reader.getContext()) DeclaratorDecl::ExtInfo();
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000728 ReadQualifierInfo(*Info);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000729 DD->DeclInfo = Info;
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000730 }
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000731}
732
Sebastian Redlb3298c32010-08-18 23:56:48 +0000733void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
Douglas Gregorb2585692012-01-04 17:13:46 +0000734 RedeclarableResult Redecl = VisitRedeclarable(FD);
Douglas Gregor3e300102011-10-26 17:53:41 +0000735 VisitDeclaratorDecl(FD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000736
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000737 ReadDeclarationNameLoc(FD->DNLoc, FD->getDeclName());
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +0000738 FD->IdentifierNamespace = Record[Idx++];
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000739
Douglas Gregorb2585692012-01-04 17:13:46 +0000740 // FunctionDecl's body is handled last at ASTDeclReader::Visit,
741 // after everything else is read.
Rafael Espindola6ae7e502013-04-03 19:27:57 +0000742
Douglas Gregorb2585692012-01-04 17:13:46 +0000743 FD->SClass = (StorageClass)Record[Idx++];
Douglas Gregorb2585692012-01-04 17:13:46 +0000744 FD->IsInline = Record[Idx++];
745 FD->IsInlineSpecified = Record[Idx++];
746 FD->IsVirtualAsWritten = Record[Idx++];
747 FD->IsPure = Record[Idx++];
748 FD->HasInheritedPrototype = Record[Idx++];
749 FD->HasWrittenPrototype = Record[Idx++];
750 FD->IsDeleted = Record[Idx++];
751 FD->IsTrivial = Record[Idx++];
752 FD->IsDefaulted = Record[Idx++];
753 FD->IsExplicitlyDefaulted = Record[Idx++];
754 FD->HasImplicitReturnZero = Record[Idx++];
755 FD->IsConstexpr = Record[Idx++];
Argyrios Kyrtzidis1eb71a12012-12-06 18:59:10 +0000756 FD->HasSkippedBody = Record[Idx++];
Richard Smithe40f2ba2013-08-07 21:41:30 +0000757 FD->IsLateTemplateParsed = Record[Idx++];
Rafael Espindola50df3a02013-05-25 17:16:20 +0000758 FD->setCachedLinkage(Linkage(Record[Idx++]));
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000759 FD->EndRangeLoc = ReadSourceLocation();
Douglas Gregorb2585692012-01-04 17:13:46 +0000760
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000761 switch ((FunctionDecl::TemplatedKind)Record[Idx++]) {
762 case FunctionDecl::TK_NonTemplate:
Richard Smithcd45dbc2014-04-19 03:48:30 +0000763 mergeRedeclarable(FD, Redecl);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000764 break;
765 case FunctionDecl::TK_FunctionTemplate:
Richard Smithcd45dbc2014-04-19 03:48:30 +0000766 // Merged when we merge the template.
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000767 FD->setDescribedFunctionTemplate(ReadDeclAs<FunctionTemplateDecl>());
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000768 break;
769 case FunctionDecl::TK_MemberSpecialization: {
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000770 FunctionDecl *InstFD = ReadDeclAs<FunctionDecl>();
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000771 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000772 SourceLocation POI = ReadSourceLocation();
Douglas Gregor4163aca2011-09-09 21:34:22 +0000773 FD->setInstantiationOfMemberFunction(Reader.getContext(), InstFD, TSK);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000774 FD->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
Richard Smithcd45dbc2014-04-19 03:48:30 +0000775 mergeRedeclarable(FD, Redecl);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000776 break;
777 }
778 case FunctionDecl::TK_FunctionTemplateSpecialization: {
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000779 FunctionTemplateDecl *Template = ReadDeclAs<FunctionTemplateDecl>();
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000780 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000781
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000782 // Template arguments.
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000783 SmallVector<TemplateArgument, 8> TemplArgs;
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000784 Record.ReadTemplateArgumentList(TemplArgs, Idx,
Richard Smith2bb3c342015-08-09 01:05:31 +0000785 /*Canonicalize*/ true);
786
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000787 // Template args as written.
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000788 SmallVector<TemplateArgumentLoc, 8> TemplArgLocs;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000789 SourceLocation LAngleLoc, RAngleLoc;
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000790 bool HasTemplateArgumentsAsWritten = Record[Idx++];
791 if (HasTemplateArgumentsAsWritten) {
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000792 unsigned NumTemplateArgLocs = Record[Idx++];
793 TemplArgLocs.reserve(NumTemplateArgLocs);
794 for (unsigned i=0; i != NumTemplateArgLocs; ++i)
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000795 TemplArgLocs.push_back(Record.ReadTemplateArgumentLoc(Idx));
796
797 LAngleLoc = ReadSourceLocation();
798 RAngleLoc = ReadSourceLocation();
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000799 }
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000800
801 SourceLocation POI = ReadSourceLocation();
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000802
Douglas Gregor4163aca2011-09-09 21:34:22 +0000803 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000804 TemplateArgumentList *TemplArgList
David Majnemer8b622692016-07-03 21:17:51 +0000805 = TemplateArgumentList::CreateCopy(C, TemplArgs);
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000806 TemplateArgumentListInfo TemplArgsInfo(LAngleLoc, RAngleLoc);
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000807 for (unsigned i=0, e = TemplArgLocs.size(); i != e; ++i)
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000808 TemplArgsInfo.addArgument(TemplArgLocs[i]);
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000809 FunctionTemplateSpecializationInfo *FTInfo
810 = FunctionTemplateSpecializationInfo::Create(C, FD, Template, TSK,
811 TemplArgList,
Craig Toppera13603a2014-05-22 05:54:18 +0000812 HasTemplateArgumentsAsWritten ? &TemplArgsInfo
813 : nullptr,
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000814 POI);
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000815 FD->TemplateOrSpecialization = FTInfo;
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000816
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000817 if (FD->isCanonicalDecl()) { // if canonical add to template's set.
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +0000818 // The template that contains the specializations set. It's not safe to
819 // use getCanonicalDecl on Template since it may still be initializing.
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000820 FunctionTemplateDecl *CanonTemplate = ReadDeclAs<FunctionTemplateDecl>();
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000821 // Get the InsertPos by FindNodeOrInsertPos() instead of calling
822 // InsertNode(FTInfo) directly to avoid the getASTContext() call in
823 // FunctionTemplateSpecializationInfo's Profile().
824 // We avoid getASTContext because a decl in the parent hierarchy may
825 // be initializing.
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000826 llvm::FoldingSetNodeID ID;
Craig Topper7e0daca2014-06-26 04:58:53 +0000827 FunctionTemplateSpecializationInfo::Profile(ID, TemplArgs, C);
Craig Toppera13603a2014-05-22 05:54:18 +0000828 void *InsertPos = nullptr;
Richard Smithfeb3e1a2013-06-28 04:37:53 +0000829 FunctionTemplateDecl::Common *CommonPtr = CanonTemplate->getCommonPtr();
Richard Smithda6c2342015-07-01 23:19:58 +0000830 FunctionTemplateSpecializationInfo *ExistingInfo =
831 CommonPtr->Specializations.FindNodeOrInsertPos(ID, InsertPos);
Argyrios Kyrtzidise60e4082012-09-10 23:28:22 +0000832 if (InsertPos)
Richard Smithfeb3e1a2013-06-28 04:37:53 +0000833 CommonPtr->Specializations.InsertNode(FTInfo, InsertPos);
834 else {
835 assert(Reader.getContext().getLangOpts().Modules &&
836 "already deserialized this template specialization");
Richard Smithda6c2342015-07-01 23:19:58 +0000837 mergeRedeclarable(FD, ExistingInfo->Function, Redecl);
Richard Smithfeb3e1a2013-06-28 04:37:53 +0000838 }
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000839 }
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000840 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000841 }
842 case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
843 // Templates.
844 UnresolvedSet<8> TemplDecls;
845 unsigned NumTemplates = Record[Idx++];
846 while (NumTemplates--)
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000847 TemplDecls.addDecl(ReadDeclAs<NamedDecl>());
848
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000849 // Templates args.
850 TemplateArgumentListInfo TemplArgs;
851 unsigned NumArgs = Record[Idx++];
852 while (NumArgs--)
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000853 TemplArgs.addArgument(Record.ReadTemplateArgumentLoc(Idx));
854 TemplArgs.setLAngleLoc(ReadSourceLocation());
855 TemplArgs.setRAngleLoc(ReadSourceLocation());
856
Douglas Gregor4163aca2011-09-09 21:34:22 +0000857 FD->setDependentTemplateSpecialization(Reader.getContext(),
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000858 TemplDecls, TemplArgs);
Richard Smithda6c2342015-07-01 23:19:58 +0000859 // These are not merged; we don't need to merge redeclarations of dependent
860 // template friends.
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000861 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000862 }
863 }
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000864
Chris Lattnerca025db2010-05-07 21:43:38 +0000865 // Read in the parameters.
Chris Lattner487412d2009-04-27 05:27:42 +0000866 unsigned NumParams = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000867 SmallVector<ParmVarDecl *, 16> Params;
Chris Lattner487412d2009-04-27 05:27:42 +0000868 Params.reserve(NumParams);
869 for (unsigned I = 0; I != NumParams; ++I)
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000870 Params.push_back(ReadDeclAs<ParmVarDecl>());
David Blaikie9c70e042011-09-21 18:16:56 +0000871 FD->setParams(Reader.getContext(), Params);
Chris Lattner487412d2009-04-27 05:27:42 +0000872}
873
Sebastian Redlb3298c32010-08-18 23:56:48 +0000874void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000875 VisitNamedDecl(MD);
876 if (Record[Idx++]) {
Douglas Gregora6017bb2012-10-09 17:21:28 +0000877 // Load the body on-demand. Most clients won't care, because method
878 // definitions rarely show up in headers.
879 Reader.PendingBodies[MD] = GetCurrentCursorOffset();
880 HasPendingBody = true;
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000881 MD->setSelfDecl(ReadDeclAs<ImplicitParamDecl>());
882 MD->setCmdDecl(ReadDeclAs<ImplicitParamDecl>());
Chris Lattner487412d2009-04-27 05:27:42 +0000883 }
884 MD->setInstanceMethod(Record[Idx++]);
885 MD->setVariadic(Record[Idx++]);
Jordan Rosed01e83a2012-10-10 16:42:25 +0000886 MD->setPropertyAccessor(Record[Idx++]);
Fariborz Jahanian6e7e8cc2010-07-22 18:24:20 +0000887 MD->setDefined(Record[Idx++]);
Argyrios Kyrtzidis08f96a92012-05-09 16:12:57 +0000888 MD->IsOverriding = Record[Idx++];
Argyrios Kyrtzidis1eb71a12012-12-06 18:59:10 +0000889 MD->HasSkippedBody = Record[Idx++];
Argyrios Kyrtzidisdb215962011-10-14 17:41:52 +0000890
891 MD->IsRedeclaration = Record[Idx++];
892 MD->HasRedeclaration = Record[Idx++];
893 if (MD->HasRedeclaration)
894 Reader.getContext().setObjCMethodRedeclaration(MD,
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000895 ReadDeclAs<ObjCMethodDecl>());
Argyrios Kyrtzidisdb215962011-10-14 17:41:52 +0000896
Chris Lattner487412d2009-04-27 05:27:42 +0000897 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record[Idx++]);
898 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record[Idx++]);
Douglas Gregor33823722011-06-11 01:09:30 +0000899 MD->SetRelatedResultType(Record[Idx++]);
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000900 MD->setReturnType(Record.readType(Idx));
901 MD->setReturnTypeSourceInfo(GetTypeSourceInfo());
902 MD->DeclEndLoc = ReadSourceLocation();
Chris Lattner487412d2009-04-27 05:27:42 +0000903 unsigned NumParams = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000904 SmallVector<ParmVarDecl *, 16> Params;
Chris Lattner487412d2009-04-27 05:27:42 +0000905 Params.reserve(NumParams);
906 for (unsigned I = 0; I != NumParams; ++I)
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000907 Params.push_back(ReadDeclAs<ParmVarDecl>());
Argyrios Kyrtzidisb8c3aaf2011-10-03 06:37:04 +0000908
909 MD->SelLocsKind = Record[Idx++];
910 unsigned NumStoredSelLocs = Record[Idx++];
911 SmallVector<SourceLocation, 16> SelLocs;
912 SelLocs.reserve(NumStoredSelLocs);
913 for (unsigned i = 0; i != NumStoredSelLocs; ++i)
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000914 SelLocs.push_back(ReadSourceLocation());
Argyrios Kyrtzidisb8c3aaf2011-10-03 06:37:04 +0000915
916 MD->setParamsAndSelLocs(Reader.getContext(), Params, SelLocs);
Chris Lattner487412d2009-04-27 05:27:42 +0000917}
918
Douglas Gregor85f3f952015-07-07 03:57:15 +0000919void ASTDeclReader::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) {
David Blaikie27a1bc02015-09-28 23:48:49 +0000920 VisitTypedefNameDecl(D);
Richard Smith9b88a4c2015-07-27 05:40:23 +0000921
Douglas Gregor1ac1b632015-07-07 03:58:54 +0000922 D->Variance = Record[Idx++];
Douglas Gregore83b9562015-07-07 03:57:53 +0000923 D->Index = Record[Idx++];
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000924 D->VarianceLoc = ReadSourceLocation();
925 D->ColonLoc = ReadSourceLocation();
Douglas Gregor85f3f952015-07-07 03:57:15 +0000926}
927
Sebastian Redlb3298c32010-08-18 23:56:48 +0000928void ASTDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000929 VisitNamedDecl(CD);
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000930 CD->setAtStartLoc(ReadSourceLocation());
931 CD->setAtEndRange(ReadSourceRange());
Chris Lattner487412d2009-04-27 05:27:42 +0000932}
933
Douglas Gregor85f3f952015-07-07 03:57:15 +0000934ObjCTypeParamList *ASTDeclReader::ReadObjCTypeParamList() {
935 unsigned numParams = Record[Idx++];
936 if (numParams == 0)
937 return nullptr;
938
939 SmallVector<ObjCTypeParamDecl *, 4> typeParams;
940 typeParams.reserve(numParams);
941 for (unsigned i = 0; i != numParams; ++i) {
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000942 auto typeParam = ReadDeclAs<ObjCTypeParamDecl>();
Douglas Gregor85f3f952015-07-07 03:57:15 +0000943 if (!typeParam)
944 return nullptr;
945
946 typeParams.push_back(typeParam);
947 }
948
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000949 SourceLocation lAngleLoc = ReadSourceLocation();
950 SourceLocation rAngleLoc = ReadSourceLocation();
Douglas Gregor85f3f952015-07-07 03:57:15 +0000951
952 return ObjCTypeParamList::create(Reader.getContext(), lAngleLoc,
953 typeParams, rAngleLoc);
954}
955
Manman Renec315f12016-09-09 23:48:27 +0000956void ASTDeclReader::ReadObjCDefinitionData(
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000957 struct ObjCInterfaceDecl::DefinitionData &Data, unsigned &I) {
Manman Renec315f12016-09-09 23:48:27 +0000958 // Read the superclass.
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000959 Data.SuperClassTInfo = GetTypeSourceInfo();
Manman Renec315f12016-09-09 23:48:27 +0000960
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000961 Data.EndLoc = ReadSourceLocation();
Manman Renec315f12016-09-09 23:48:27 +0000962 Data.HasDesignatedInitializers = Record[Idx++];
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000963
Manman Renec315f12016-09-09 23:48:27 +0000964 // Read the directly referenced protocols and their SourceLocations.
965 unsigned NumProtocols = Record[Idx++];
966 SmallVector<ObjCProtocolDecl *, 16> Protocols;
967 Protocols.reserve(NumProtocols);
968 for (unsigned I = 0; I != NumProtocols; ++I)
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000969 Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>());
Manman Renec315f12016-09-09 23:48:27 +0000970 SmallVector<SourceLocation, 16> ProtoLocs;
971 ProtoLocs.reserve(NumProtocols);
972 for (unsigned I = 0; I != NumProtocols; ++I)
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000973 ProtoLocs.push_back(ReadSourceLocation());
Manman Renec315f12016-09-09 23:48:27 +0000974 Data.ReferencedProtocols.set(Protocols.data(), NumProtocols, ProtoLocs.data(),
975 Reader.getContext());
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000976
Manman Renec315f12016-09-09 23:48:27 +0000977 // Read the transitive closure of protocols referenced by this class.
978 NumProtocols = Record[Idx++];
979 Protocols.clear();
980 Protocols.reserve(NumProtocols);
981 for (unsigned I = 0; I != NumProtocols; ++I)
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000982 Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>());
Manman Renec315f12016-09-09 23:48:27 +0000983 Data.AllReferencedProtocols.set(Protocols.data(), NumProtocols,
984 Reader.getContext());
985}
986
987void ASTDeclReader::MergeDefinitionData(ObjCInterfaceDecl *D,
988 struct ObjCInterfaceDecl::DefinitionData &&NewDD) {
989 // FIXME: odr checking?
990}
991
Sebastian Redlb3298c32010-08-18 23:56:48 +0000992void ASTDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
Douglas Gregor022857e2011-12-22 01:48:48 +0000993 RedeclarableResult Redecl = VisitRedeclarable(ID);
Chris Lattner487412d2009-04-27 05:27:42 +0000994 VisitObjCContainerDecl(ID);
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000995 TypeIDForTypeDecl = Record.getGlobalTypeID(Record[Idx++]);
Douglas Gregor2c46b5b2012-01-03 17:27:13 +0000996 mergeRedeclarable(ID, Redecl);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000997
998 ID->TypeParamList = ReadObjCTypeParamList();
Douglas Gregor3a5ae562012-01-15 18:17:48 +0000999 if (Record[Idx++]) {
Douglas Gregorc0ac7d62011-12-15 05:27:12 +00001000 // Read the definition.
1001 ID->allocateDefinitionData();
Douglas Gregorc0ac7d62011-12-15 05:27:12 +00001002
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001003 ReadObjCDefinitionData(ID->data(), Idx);
Manman Renec315f12016-09-09 23:48:27 +00001004 ObjCInterfaceDecl *Canon = ID->getCanonicalDecl();
1005 if (Canon->Data.getPointer()) {
1006 // If we already have a definition, keep the definition invariant and
1007 // merge the data.
1008 MergeDefinitionData(Canon, std::move(ID->data()));
1009 ID->Data = Canon->Data;
1010 } else {
1011 // Set the definition data of the canonical declaration, so other
1012 // redeclarations will see it.
1013 ID->getCanonicalDecl()->Data = ID->Data;
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001014
Manman Renec315f12016-09-09 23:48:27 +00001015 // We will rebuild this list lazily.
1016 ID->setIvarList(nullptr);
1017 }
Craig Toppera13603a2014-05-22 05:54:18 +00001018
Douglas Gregorc1a61fe2011-12-19 20:51:16 +00001019 // Note that we have deserialized a definition.
1020 Reader.PendingDefinitions.insert(ID);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001021
Douglas Gregor404cdde2012-01-27 01:47:08 +00001022 // Note that we've loaded this Objective-C class.
1023 Reader.ObjCClassesLoaded.push_back(ID);
Douglas Gregorc03c52e2012-01-15 18:08:05 +00001024 } else {
1025 ID->Data = ID->getCanonicalDecl()->Data;
Douglas Gregorc0ac7d62011-12-15 05:27:12 +00001026 }
Chris Lattner487412d2009-04-27 05:27:42 +00001027}
1028
Sebastian Redlb3298c32010-08-18 23:56:48 +00001029void ASTDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
Chris Lattner487412d2009-04-27 05:27:42 +00001030 VisitFieldDecl(IVD);
1031 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record[Idx++]);
Fariborz Jahaniana50b3a22010-08-20 21:21:08 +00001032 // This field will be built lazily.
Craig Toppera13603a2014-05-22 05:54:18 +00001033 IVD->setNextIvar(nullptr);
Fariborz Jahanianaea8e1e2010-07-17 18:35:47 +00001034 bool synth = Record[Idx++];
1035 IVD->setSynthesize(synth);
Chris Lattner487412d2009-04-27 05:27:42 +00001036}
1037
Sebastian Redlb3298c32010-08-18 23:56:48 +00001038void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
Douglas Gregorda389302012-01-01 21:47:52 +00001039 RedeclarableResult Redecl = VisitRedeclarable(PD);
Chris Lattner487412d2009-04-27 05:27:42 +00001040 VisitObjCContainerDecl(PD);
Douglas Gregor2c46b5b2012-01-03 17:27:13 +00001041 mergeRedeclarable(PD, Redecl);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001042
Douglas Gregor3a5ae562012-01-15 18:17:48 +00001043 if (Record[Idx++]) {
Douglas Gregore6e48b12012-01-01 19:29:29 +00001044 // Read the definition.
1045 PD->allocateDefinitionData();
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001046
Douglas Gregorc03c52e2012-01-15 18:08:05 +00001047 // Set the definition data of the canonical declaration, so other
1048 // redeclarations will see it.
1049 PD->getCanonicalDecl()->Data = PD->Data;
1050
Douglas Gregore6e48b12012-01-01 19:29:29 +00001051 unsigned NumProtoRefs = Record[Idx++];
1052 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
1053 ProtoRefs.reserve(NumProtoRefs);
1054 for (unsigned I = 0; I != NumProtoRefs; ++I)
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001055 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>());
Douglas Gregore6e48b12012-01-01 19:29:29 +00001056 SmallVector<SourceLocation, 16> ProtoLocs;
1057 ProtoLocs.reserve(NumProtoRefs);
1058 for (unsigned I = 0; I != NumProtoRefs; ++I)
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001059 ProtoLocs.push_back(ReadSourceLocation());
Douglas Gregore6e48b12012-01-01 19:29:29 +00001060 PD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
1061 Reader.getContext());
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001062
Douglas Gregora715bff2012-01-01 19:51:50 +00001063 // Note that we have deserialized a definition.
1064 Reader.PendingDefinitions.insert(PD);
Douglas Gregorc03c52e2012-01-15 18:08:05 +00001065 } else {
1066 PD->Data = PD->getCanonicalDecl()->Data;
Douglas Gregore6e48b12012-01-01 19:29:29 +00001067 }
Chris Lattner487412d2009-04-27 05:27:42 +00001068}
1069
Sebastian Redlb3298c32010-08-18 23:56:48 +00001070void ASTDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
Chris Lattner487412d2009-04-27 05:27:42 +00001071 VisitFieldDecl(FD);
1072}
1073
Sebastian Redlb3298c32010-08-18 23:56:48 +00001074void ASTDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
Chris Lattner487412d2009-04-27 05:27:42 +00001075 VisitObjCContainerDecl(CD);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001076 CD->setCategoryNameLoc(ReadSourceLocation());
1077 CD->setIvarLBraceLoc(ReadSourceLocation());
1078 CD->setIvarRBraceLoc(ReadSourceLocation());
1079
Douglas Gregor404cdde2012-01-27 01:47:08 +00001080 // Note that this category has been deserialized. We do this before
1081 // deserializing the interface declaration, so that it will consider this
1082 /// category.
1083 Reader.CategoriesDeserialized.insert(CD);
1084
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001085 CD->ClassInterface = ReadDeclAs<ObjCInterfaceDecl>();
Douglas Gregor85f3f952015-07-07 03:57:15 +00001086 CD->TypeParamList = ReadObjCTypeParamList();
Chris Lattner487412d2009-04-27 05:27:42 +00001087 unsigned NumProtoRefs = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +00001088 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner487412d2009-04-27 05:27:42 +00001089 ProtoRefs.reserve(NumProtoRefs);
1090 for (unsigned I = 0; I != NumProtoRefs; ++I)
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001091 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>());
Chris Lattner0e62c1c2011-07-23 10:55:15 +00001092 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor002b6712010-01-16 15:02:53 +00001093 ProtoLocs.reserve(NumProtoRefs);
1094 for (unsigned I = 0; I != NumProtoRefs; ++I)
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001095 ProtoLocs.push_back(ReadSourceLocation());
Douglas Gregor002b6712010-01-16 15:02:53 +00001096 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor4163aca2011-09-09 21:34:22 +00001097 Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +00001098}
1099
Sebastian Redlb3298c32010-08-18 23:56:48 +00001100void ASTDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
Chris Lattner487412d2009-04-27 05:27:42 +00001101 VisitNamedDecl(CAD);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001102 CAD->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>());
Chris Lattner487412d2009-04-27 05:27:42 +00001103}
1104
Sebastian Redlb3298c32010-08-18 23:56:48 +00001105void ASTDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +00001106 VisitNamedDecl(D);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001107 D->setAtLoc(ReadSourceLocation());
1108 D->setLParenLoc(ReadSourceLocation());
1109 QualType T = Record.readType(Idx);
1110 TypeSourceInfo *TSI = GetTypeSourceInfo();
Douglas Gregor813a0662015-06-19 18:14:38 +00001111 D->setType(T, TSI);
Chris Lattner487412d2009-04-27 05:27:42 +00001112 D->setPropertyAttributes(
1113 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Fariborz Jahanian3bf0ded2010-06-22 23:20:40 +00001114 D->setPropertyAttributesAsWritten(
1115 (ObjCPropertyDecl::PropertyAttributeKind)Record[Idx++]);
Chris Lattner487412d2009-04-27 05:27:42 +00001116 D->setPropertyImplementation(
1117 (ObjCPropertyDecl::PropertyControl)Record[Idx++]);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001118 D->setGetterName(Record.ReadDeclarationName(Idx).getObjCSelector());
1119 D->setSetterName(Record.ReadDeclarationName(Idx).getObjCSelector());
1120 D->setGetterMethodDecl(ReadDeclAs<ObjCMethodDecl>());
1121 D->setSetterMethodDecl(ReadDeclAs<ObjCMethodDecl>());
1122 D->setPropertyIvarDecl(ReadDeclAs<ObjCIvarDecl>());
Chris Lattner487412d2009-04-27 05:27:42 +00001123}
1124
Sebastian Redlb3298c32010-08-18 23:56:48 +00001125void ASTDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidis067c4072009-07-27 19:04:32 +00001126 VisitObjCContainerDecl(D);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001127 D->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>());
Chris Lattner487412d2009-04-27 05:27:42 +00001128}
1129
Sebastian Redlb3298c32010-08-18 23:56:48 +00001130void ASTDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +00001131 VisitObjCImplDecl(D);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001132 D->setIdentifier(Record.GetIdentifierInfo(Idx));
1133 D->CategoryNameLoc = ReadSourceLocation();
Chris Lattner487412d2009-04-27 05:27:42 +00001134}
1135
Sebastian Redlb3298c32010-08-18 23:56:48 +00001136void ASTDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +00001137 VisitObjCImplDecl(D);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001138 D->setSuperClass(ReadDeclAs<ObjCInterfaceDecl>());
1139 D->SuperLoc = ReadSourceLocation();
1140 D->setIvarLBraceLoc(ReadSourceLocation());
1141 D->setIvarRBraceLoc(ReadSourceLocation());
John McCall0d54a172012-10-17 04:53:31 +00001142 D->setHasNonZeroConstructors(Record[Idx++]);
1143 D->setHasDestructors(Record[Idx++]);
Richard Smithc2bb8182015-03-24 06:36:48 +00001144 D->NumIvarInitializers = Record[Idx++];
1145 if (D->NumIvarInitializers)
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001146 D->IvarInitializers = ReadGlobalOffset();
Chris Lattner487412d2009-04-27 05:27:42 +00001147}
1148
Sebastian Redlb3298c32010-08-18 23:56:48 +00001149void ASTDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +00001150 VisitDecl(D);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001151 D->setAtLoc(ReadSourceLocation());
1152 D->setPropertyDecl(ReadDeclAs<ObjCPropertyDecl>());
1153 D->PropertyIvarDecl = ReadDeclAs<ObjCIvarDecl>();
1154 D->IvarLoc = ReadSourceLocation();
1155 D->setGetterCXXConstructor(Record.ReadExpr());
1156 D->setSetterCXXAssignment(Record.ReadExpr());
Chris Lattner487412d2009-04-27 05:27:42 +00001157}
1158
Sebastian Redlb3298c32010-08-18 23:56:48 +00001159void ASTDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +00001160 VisitDeclaratorDecl(FD);
Richard Smith2b013182012-06-10 03:12:00 +00001161 FD->Mutable = Record[Idx++];
1162 if (int BitWidthOrInitializer = Record[Idx++]) {
John McCallc90c1492014-10-10 18:44:34 +00001163 FD->InitStorage.setInt(
1164 static_cast<FieldDecl::InitStorageKind>(BitWidthOrInitializer - 1));
1165 if (FD->InitStorage.getInt() == FieldDecl::ISK_CapturedVLAType) {
Alexey Bataev39c81e22014-08-28 04:28:19 +00001166 // Read captured variable length array.
John McCallc90c1492014-10-10 18:44:34 +00001167 FD->InitStorage.setPointer(
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001168 Record.readType(Idx).getAsOpaquePtr());
Alexey Bataev39c81e22014-08-28 04:28:19 +00001169 } else {
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001170 FD->InitStorage.setPointer(Record.ReadExpr());
Alexey Bataev39c81e22014-08-28 04:28:19 +00001171 }
Richard Smith2b013182012-06-10 03:12:00 +00001172 }
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +00001173 if (!FD->getDeclName()) {
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001174 if (FieldDecl *Tmpl = ReadDeclAs<FieldDecl>())
Douglas Gregor4163aca2011-09-09 21:34:22 +00001175 Reader.getContext().setInstantiatedFromUnnamedFieldDecl(FD, Tmpl);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +00001176 }
Richard Smith0b87e072013-10-07 08:02:11 +00001177 mergeMergeable(FD);
Chris Lattner487412d2009-04-27 05:27:42 +00001178}
1179
John McCall5e77d762013-04-16 07:28:30 +00001180void ASTDeclReader::VisitMSPropertyDecl(MSPropertyDecl *PD) {
1181 VisitDeclaratorDecl(PD);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001182 PD->GetterId = Record.GetIdentifierInfo(Idx);
1183 PD->SetterId = Record.GetIdentifierInfo(Idx);
John McCall5e77d762013-04-16 07:28:30 +00001184}
1185
Francois Pichet783dd6e2010-11-21 06:08:52 +00001186void ASTDeclReader::VisitIndirectFieldDecl(IndirectFieldDecl *FD) {
1187 VisitValueDecl(FD);
1188
1189 FD->ChainingSize = Record[Idx++];
1190 assert(FD->ChainingSize >= 2 && "Anonymous chaining must be >= 2");
Douglas Gregor4163aca2011-09-09 21:34:22 +00001191 FD->Chaining = new (Reader.getContext())NamedDecl*[FD->ChainingSize];
Francois Pichet783dd6e2010-11-21 06:08:52 +00001192
1193 for (unsigned I = 0; I != FD->ChainingSize; ++I)
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001194 FD->Chaining[I] = ReadDeclAs<NamedDecl>();
Richard Smith8cbd8952015-08-04 02:05:09 +00001195
1196 mergeMergeable(FD);
Francois Pichet783dd6e2010-11-21 06:08:52 +00001197}
1198
Larisse Voufo39a1e502013-08-06 01:03:05 +00001199ASTDeclReader::RedeclarableResult ASTDeclReader::VisitVarDeclImpl(VarDecl *VD) {
Douglas Gregorb8c6f1e2012-01-04 17:21:36 +00001200 RedeclarableResult Redecl = VisitRedeclarable(VD);
Douglas Gregor3e300102011-10-26 17:53:41 +00001201 VisitDeclaratorDecl(VD);
Rafael Espindola6ae7e502013-04-03 19:27:57 +00001202
John McCallbeaa11c2011-05-01 02:13:58 +00001203 VD->VarDeclBits.SClass = (StorageClass)Record[Idx++];
Enea Zaffanellaacb8ecd2013-05-04 08:27:07 +00001204 VD->VarDeclBits.TSCSpec = Record[Idx++];
Sebastian Redla9351792012-02-11 23:51:47 +00001205 VD->VarDeclBits.InitStyle = Record[Idx++];
David Majnemerfa7bc782015-05-19 00:57:16 +00001206 if (!isa<ParmVarDecl>(VD)) {
Richard Smithedbc6e92016-10-14 21:41:24 +00001207 VD->NonParmVarDeclBits.IsThisDeclarationADemotedDefinition = Record[Idx++];
David Majnemerfa7bc782015-05-19 00:57:16 +00001208 VD->NonParmVarDeclBits.ExceptionVar = Record[Idx++];
1209 VD->NonParmVarDeclBits.NRVOVariable = Record[Idx++];
1210 VD->NonParmVarDeclBits.CXXForRangeDecl = Record[Idx++];
1211 VD->NonParmVarDeclBits.ARCPseudoStrong = Record[Idx++];
Richard Smith62f19e72016-06-25 00:15:56 +00001212 VD->NonParmVarDeclBits.IsInline = Record[Idx++];
1213 VD->NonParmVarDeclBits.IsInlineSpecified = Record[Idx++];
David Majnemerfa7bc782015-05-19 00:57:16 +00001214 VD->NonParmVarDeclBits.IsConstexpr = Record[Idx++];
1215 VD->NonParmVarDeclBits.IsInitCapture = Record[Idx++];
1216 VD->NonParmVarDeclBits.PreviousDeclInSameBlockScope = Record[Idx++];
1217 }
Richard Smith541b38b2013-09-20 01:15:31 +00001218 Linkage VarLinkage = Linkage(Record[Idx++]);
1219 VD->setCachedLinkage(VarLinkage);
1220
1221 // Reconstruct the one piece of the IdentifierNamespace that we need.
Ted Kremeneka683f632014-02-11 06:29:29 +00001222 if (VD->getStorageClass() == SC_Extern && VarLinkage != NoLinkage &&
Richard Smith541b38b2013-09-20 01:15:31 +00001223 VD->getLexicalDeclContext()->isFunctionOrMethod())
1224 VD->setLocalExternDecl();
Rafael Espindola50df3a02013-05-25 17:16:20 +00001225
Richard Smithd0b4dd62011-12-19 06:19:21 +00001226 if (uint64_t Val = Record[Idx++]) {
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001227 VD->setInit(Record.ReadExpr());
Vassil Vassilevd1a88132016-10-06 13:04:54 +00001228 if (Val > 1) { // IsInitKnownICE = 1, IsInitNotICE = 2, IsInitICE = 3
Richard Smithd0b4dd62011-12-19 06:19:21 +00001229 EvaluatedStmt *Eval = VD->ensureEvaluatedStmt();
1230 Eval->CheckedICE = true;
1231 Eval->IsICE = Val == 3;
1232 }
1233 }
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +00001234
Larisse Voufod8dd97c2013-08-14 03:09:19 +00001235 enum VarKind {
1236 VarNotTemplate = 0, VarTemplate, StaticDataMemberSpecialization
1237 };
1238 switch ((VarKind)Record[Idx++]) {
1239 case VarNotTemplate:
Richard Smith9b88a4c2015-07-27 05:40:23 +00001240 // Only true variables (not parameters or implicit parameters) can be
1241 // merged; the other kinds are not really redeclarable at all.
Richard Smith0144f512015-08-22 02:09:38 +00001242 if (!isa<ParmVarDecl>(VD) && !isa<ImplicitParamDecl>(VD) &&
1243 !isa<VarTemplateSpecializationDecl>(VD))
Richard Smithf17fdbd2014-04-24 02:25:27 +00001244 mergeRedeclarable(VD, Redecl);
Larisse Voufod8dd97c2013-08-14 03:09:19 +00001245 break;
1246 case VarTemplate:
Richard Smithf17fdbd2014-04-24 02:25:27 +00001247 // Merged when we merge the template.
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001248 VD->setDescribedVarTemplate(ReadDeclAs<VarTemplateDecl>());
Larisse Voufod8dd97c2013-08-14 03:09:19 +00001249 break;
1250 case StaticDataMemberSpecialization: { // HasMemberSpecializationInfo.
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001251 VarDecl *Tmpl = ReadDeclAs<VarDecl>();
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +00001252 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001253 SourceLocation POI = ReadSourceLocation();
Douglas Gregor4163aca2011-09-09 21:34:22 +00001254 Reader.getContext().setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI);
Richard Smithf17fdbd2014-04-24 02:25:27 +00001255 mergeRedeclarable(VD, Redecl);
Larisse Voufod8dd97c2013-08-14 03:09:19 +00001256 break;
1257 }
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +00001258 }
Larisse Voufo39a1e502013-08-06 01:03:05 +00001259
1260 return Redecl;
Chris Lattner487412d2009-04-27 05:27:42 +00001261}
1262
Sebastian Redlb3298c32010-08-18 23:56:48 +00001263void ASTDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
Chris Lattner487412d2009-04-27 05:27:42 +00001264 VisitVarDecl(PD);
1265}
1266
Sebastian Redlb3298c32010-08-18 23:56:48 +00001267void ASTDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
Chris Lattner487412d2009-04-27 05:27:42 +00001268 VisitVarDecl(PD);
John McCall82490832011-05-02 00:30:12 +00001269 unsigned isObjCMethodParam = Record[Idx++];
1270 unsigned scopeDepth = Record[Idx++];
1271 unsigned scopeIndex = Record[Idx++];
1272 unsigned declQualifier = Record[Idx++];
1273 if (isObjCMethodParam) {
1274 assert(scopeDepth == 0);
1275 PD->setObjCMethodScopeInfo(scopeIndex);
1276 PD->ParmVarDeclBits.ScopeDepthOrObjCQuals = declQualifier;
1277 } else {
1278 PD->setScopeInfo(scopeDepth, scopeIndex);
1279 }
John McCallbeaa11c2011-05-01 02:13:58 +00001280 PD->ParmVarDeclBits.IsKNRPromoted = Record[Idx++];
1281 PD->ParmVarDeclBits.HasInheritedDefaultArg = Record[Idx++];
Argyrios Kyrtzidisccde6a02010-07-04 21:44:07 +00001282 if (Record[Idx++]) // hasUninstantiatedDefaultArg.
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001283 PD->setUninstantiatedDefaultArg(Record.ReadExpr());
Richard Smithbf78e642013-06-24 22:51:00 +00001284
1285 // FIXME: If this is a redeclaration of a function from another module, handle
1286 // inheritance of default arguments.
Chris Lattner487412d2009-04-27 05:27:42 +00001287}
1288
Richard Smith7b76d812016-08-12 02:21:25 +00001289void ASTDeclReader::VisitDecompositionDecl(DecompositionDecl *DD) {
1290 VisitVarDecl(DD);
1291 BindingDecl **BDs = DD->getTrailingObjects<BindingDecl*>();
1292 for (unsigned I = 0; I != DD->NumBindings; ++I)
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001293 BDs[I] = ReadDeclAs<BindingDecl>();
Richard Smith7b76d812016-08-12 02:21:25 +00001294}
1295
1296void ASTDeclReader::VisitBindingDecl(BindingDecl *BD) {
1297 VisitValueDecl(BD);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001298 BD->Binding = Record.ReadExpr();
Richard Smith7b76d812016-08-12 02:21:25 +00001299}
1300
Sebastian Redlb3298c32010-08-18 23:56:48 +00001301void ASTDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
Chris Lattner487412d2009-04-27 05:27:42 +00001302 VisitDecl(AD);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001303 AD->setAsmString(cast<StringLiteral>(Record.ReadExpr()));
1304 AD->setRParenLoc(ReadSourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001305}
1306
Sebastian Redlb3298c32010-08-18 23:56:48 +00001307void ASTDeclReader::VisitBlockDecl(BlockDecl *BD) {
Chris Lattner487412d2009-04-27 05:27:42 +00001308 VisitDecl(BD);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001309 BD->setBody(cast_or_null<CompoundStmt>(Record.ReadStmt()));
1310 BD->setSignatureAsWritten(GetTypeSourceInfo());
Chris Lattner487412d2009-04-27 05:27:42 +00001311 unsigned NumParams = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +00001312 SmallVector<ParmVarDecl *, 16> Params;
Chris Lattner487412d2009-04-27 05:27:42 +00001313 Params.reserve(NumParams);
1314 for (unsigned I = 0; I != NumParams; ++I)
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001315 Params.push_back(ReadDeclAs<ParmVarDecl>());
David Blaikie9c70e042011-09-21 18:16:56 +00001316 BD->setParams(Params);
John McCallc63de662011-02-02 13:00:07 +00001317
John McCallcf6ce282012-04-13 17:33:29 +00001318 BD->setIsVariadic(Record[Idx++]);
1319 BD->setBlockMissingReturnType(Record[Idx++]);
1320 BD->setIsConversionFromLambda(Record[Idx++]);
1321
John McCallc63de662011-02-02 13:00:07 +00001322 bool capturesCXXThis = Record[Idx++];
John McCall351762c2011-02-07 10:33:21 +00001323 unsigned numCaptures = Record[Idx++];
Chris Lattner0e62c1c2011-07-23 10:55:15 +00001324 SmallVector<BlockDecl::Capture, 16> captures;
John McCall351762c2011-02-07 10:33:21 +00001325 captures.reserve(numCaptures);
1326 for (unsigned i = 0; i != numCaptures; ++i) {
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001327 VarDecl *decl = ReadDeclAs<VarDecl>();
John McCall351762c2011-02-07 10:33:21 +00001328 unsigned flags = Record[Idx++];
1329 bool byRef = (flags & 1);
1330 bool nested = (flags & 2);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001331 Expr *copyExpr = ((flags & 4) ? Record.ReadExpr() : nullptr);
John McCall351762c2011-02-07 10:33:21 +00001332
1333 captures.push_back(BlockDecl::Capture(decl, byRef, nested, copyExpr));
1334 }
Benjamin Kramerb40e4af2015-08-05 09:40:35 +00001335 BD->setCaptures(Reader.getContext(), captures, capturesCXXThis);
Chris Lattner487412d2009-04-27 05:27:42 +00001336}
1337
Ben Langmuirce914fc2013-05-03 19:20:19 +00001338void ASTDeclReader::VisitCapturedDecl(CapturedDecl *CD) {
1339 VisitDecl(CD);
Alexey Bataev9959db52014-05-06 10:08:46 +00001340 unsigned ContextParamPos = Record[Idx++];
1341 CD->setNothrow(Record[Idx++] != 0);
Ben Langmuirce914fc2013-05-03 19:20:19 +00001342 // Body is set by VisitCapturedStmt.
Alexey Bataev9959db52014-05-06 10:08:46 +00001343 for (unsigned I = 0; I < CD->NumParams; ++I) {
1344 if (I != ContextParamPos)
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001345 CD->setParam(I, ReadDeclAs<ImplicitParamDecl>());
Alexey Bataev9959db52014-05-06 10:08:46 +00001346 else
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001347 CD->setContextParam(I, ReadDeclAs<ImplicitParamDecl>());
Alexey Bataev9959db52014-05-06 10:08:46 +00001348 }
Tareq A. Siraj6dfa25a2013-04-16 19:37:38 +00001349}
1350
Sebastian Redlb3298c32010-08-18 23:56:48 +00001351void ASTDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001352 VisitDecl(D);
1353 D->setLanguage((LinkageSpecDecl::LanguageIDs)Record[Idx++]);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001354 D->setExternLoc(ReadSourceLocation());
1355 D->setRBraceLoc(ReadSourceLocation());
Chris Lattnerca025db2010-05-07 21:43:38 +00001356}
1357
Richard Smith8df390f2016-09-08 23:14:54 +00001358void ASTDeclReader::VisitExportDecl(ExportDecl *D) {
1359 VisitDecl(D);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001360 D->RBraceLoc = ReadSourceLocation();
Richard Smith8df390f2016-09-08 23:14:54 +00001361}
1362
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001363void ASTDeclReader::VisitLabelDecl(LabelDecl *D) {
1364 VisitNamedDecl(D);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001365 D->setLocStart(ReadSourceLocation());
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001366}
1367
Sebastian Redlb3298c32010-08-18 23:56:48 +00001368void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
Douglas Gregore57e7522012-01-07 09:11:48 +00001369 RedeclarableResult Redecl = VisitRedeclarable(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001370 VisitNamedDecl(D);
Douglas Gregore57e7522012-01-07 09:11:48 +00001371 D->setInline(Record[Idx++]);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001372 D->LocStart = ReadSourceLocation();
1373 D->RBraceLoc = ReadSourceLocation();
Douglas Gregorcfe7dc62012-01-09 17:30:44 +00001374
Richard Smith15e32fd2015-03-17 02:23:11 +00001375 // Defer loading the anonymous namespace until we've finished merging
1376 // this namespace; loading it might load a later declaration of the
1377 // same namespace, and we have an invariant that older declarations
1378 // get merged before newer ones try to merge.
1379 GlobalDeclID AnonNamespace = 0;
Douglas Gregore57e7522012-01-07 09:11:48 +00001380 if (Redecl.getFirstID() == ThisDeclID) {
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001381 AnonNamespace = ReadDeclID();
Douglas Gregore57e7522012-01-07 09:11:48 +00001382 } else {
1383 // Link this namespace back to the first declaration, which has already
1384 // been deserialized.
Rafael Espindola8db352d2013-10-17 15:37:26 +00001385 D->AnonOrFirstNamespaceAndInline.setPointer(D->getFirstDecl());
Douglas Gregore57e7522012-01-07 09:11:48 +00001386 }
Richard Smith5e9e56a2014-07-15 03:37:06 +00001387
1388 mergeRedeclarable(D, Redecl);
Richard Smith15e32fd2015-03-17 02:23:11 +00001389
1390 if (AnonNamespace) {
1391 // Each module has its own anonymous namespace, which is disjoint from
1392 // any other module's anonymous namespaces, so don't attach the anonymous
1393 // namespace at all.
1394 NamespaceDecl *Anon = cast<NamespaceDecl>(Reader.GetDecl(AnonNamespace));
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001395 if (!Record.isModule())
Richard Smith15e32fd2015-03-17 02:23:11 +00001396 D->setAnonymousNamespace(Anon);
1397 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001398}
1399
Sebastian Redlb3298c32010-08-18 23:56:48 +00001400void ASTDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
Richard Smithf4634362014-09-03 23:11:22 +00001401 RedeclarableResult Redecl = VisitRedeclarable(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001402 VisitNamedDecl(D);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001403 D->NamespaceLoc = ReadSourceLocation();
1404 D->IdentLoc = ReadSourceLocation();
1405 D->QualifierLoc = Record.ReadNestedNameSpecifierLoc(Idx);
1406 D->Namespace = ReadDeclAs<NamedDecl>();
Richard Smithf4634362014-09-03 23:11:22 +00001407 mergeRedeclarable(D, Redecl);
Chris Lattnerca025db2010-05-07 21:43:38 +00001408}
1409
Sebastian Redlb3298c32010-08-18 23:56:48 +00001410void ASTDeclReader::VisitUsingDecl(UsingDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001411 VisitNamedDecl(D);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001412 D->setUsingLoc(ReadSourceLocation());
1413 D->QualifierLoc = Record.ReadNestedNameSpecifierLoc(Idx);
1414 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName());
1415 D->FirstUsingShadow.setPointer(ReadDeclAs<UsingShadowDecl>());
Enea Zaffanellae05a3cf2013-07-22 10:54:09 +00001416 D->setTypename(Record[Idx++]);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001417 if (NamedDecl *Pattern = ReadDeclAs<NamedDecl>())
Douglas Gregor4163aca2011-09-09 21:34:22 +00001418 Reader.getContext().setInstantiatedFromUsingDecl(D, Pattern);
Richard Smith32952e12014-10-14 02:00:47 +00001419 mergeMergeable(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001420}
1421
Sebastian Redlb3298c32010-08-18 23:56:48 +00001422void ASTDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) {
Richard Smithfd8634a2013-10-23 02:17:46 +00001423 RedeclarableResult Redecl = VisitRedeclarable(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001424 VisitNamedDecl(D);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001425 D->setTargetDecl(ReadDeclAs<NamedDecl>());
1426 D->UsingOrNextShadow = ReadDeclAs<NamedDecl>();
1427 UsingShadowDecl *Pattern = ReadDeclAs<UsingShadowDecl>();
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +00001428 if (Pattern)
Douglas Gregor4163aca2011-09-09 21:34:22 +00001429 Reader.getContext().setInstantiatedFromUsingShadowDecl(D, Pattern);
Richard Smithfd8634a2013-10-23 02:17:46 +00001430 mergeRedeclarable(D, Redecl);
Chris Lattnerca025db2010-05-07 21:43:38 +00001431}
1432
Richard Smith5179eb72016-06-28 19:03:57 +00001433void ASTDeclReader::VisitConstructorUsingShadowDecl(
1434 ConstructorUsingShadowDecl *D) {
1435 VisitUsingShadowDecl(D);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001436 D->NominatedBaseClassShadowDecl = ReadDeclAs<ConstructorUsingShadowDecl>();
1437 D->ConstructedBaseClassShadowDecl = ReadDeclAs<ConstructorUsingShadowDecl>();
Richard Smith5179eb72016-06-28 19:03:57 +00001438 D->IsVirtual = Record[Idx++];
1439}
1440
Sebastian Redlb3298c32010-08-18 23:56:48 +00001441void ASTDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001442 VisitNamedDecl(D);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001443 D->UsingLoc = ReadSourceLocation();
1444 D->NamespaceLoc = ReadSourceLocation();
1445 D->QualifierLoc = Record.ReadNestedNameSpecifierLoc(Idx);
1446 D->NominatedNamespace = ReadDeclAs<NamedDecl>();
1447 D->CommonAncestor = ReadDeclAs<DeclContext>();
Chris Lattnerca025db2010-05-07 21:43:38 +00001448}
1449
Sebastian Redlb3298c32010-08-18 23:56:48 +00001450void ASTDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001451 VisitValueDecl(D);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001452 D->setUsingLoc(ReadSourceLocation());
1453 D->QualifierLoc = Record.ReadNestedNameSpecifierLoc(Idx);
1454 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName());
Richard Smith32952e12014-10-14 02:00:47 +00001455 mergeMergeable(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001456}
1457
Sebastian Redlb3298c32010-08-18 23:56:48 +00001458void ASTDeclReader::VisitUnresolvedUsingTypenameDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001459 UnresolvedUsingTypenameDecl *D) {
1460 VisitTypeDecl(D);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001461 D->TypenameLocation = ReadSourceLocation();
1462 D->QualifierLoc = Record.ReadNestedNameSpecifierLoc(Idx);
Richard Smith32952e12014-10-14 02:00:47 +00001463 mergeMergeable(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001464}
1465
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +00001466void ASTDeclReader::ReadCXXDefinitionData(
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +00001467 struct CXXRecordDecl::DefinitionData &Data,
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001468 unsigned &Idx) {
Douglas Gregor99ae8062012-02-14 17:54:36 +00001469 // Note: the caller has deserialized the IsLambda bit already.
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +00001470 Data.UserDeclaredConstructor = Record[Idx++];
Richard Smith328aae52012-11-30 05:11:39 +00001471 Data.UserDeclaredSpecialMembers = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +00001472 Data.Aggregate = Record[Idx++];
1473 Data.PlainOldData = Record[Idx++];
1474 Data.Empty = Record[Idx++];
1475 Data.Polymorphic = Record[Idx++];
1476 Data.Abstract = Record[Idx++];
Chandler Carruth583edf82011-04-30 10:07:30 +00001477 Data.IsStandardLayout = Record[Idx++];
Chandler Carruthb1963742011-04-30 09:17:45 +00001478 Data.HasNoNonEmptyBases = Record[Idx++];
1479 Data.HasPrivateFields = Record[Idx++];
1480 Data.HasProtectedFields = Record[Idx++];
1481 Data.HasPublicFields = Record[Idx++];
Douglas Gregor61226d32011-05-13 01:05:07 +00001482 Data.HasMutableFields = Record[Idx++];
Richard Smithab44d5b2013-12-10 08:25:00 +00001483 Data.HasVariantMembers = Record[Idx++];
Richard Smith561fb152012-02-25 07:33:38 +00001484 Data.HasOnlyCMembers = Record[Idx++];
Richard Smithe2648ba2012-05-07 01:07:30 +00001485 Data.HasInClassInitializer = Record[Idx++];
Richard Smith593f9932012-12-08 02:01:17 +00001486 Data.HasUninitializedReferenceMember = Record[Idx++];
Nico Weber6a6376b2016-02-19 01:52:46 +00001487 Data.HasUninitializedFields = Record[Idx++];
Richard Smith12e79312016-05-13 06:47:56 +00001488 Data.HasInheritedConstructor = Record[Idx++];
1489 Data.HasInheritedAssignment = Record[Idx++];
Richard Smith6b02d462012-12-08 08:32:28 +00001490 Data.NeedOverloadResolutionForMoveConstructor = Record[Idx++];
1491 Data.NeedOverloadResolutionForMoveAssignment = Record[Idx++];
1492 Data.NeedOverloadResolutionForDestructor = Record[Idx++];
1493 Data.DefaultedMoveConstructorIsDeleted = Record[Idx++];
1494 Data.DefaultedMoveAssignmentIsDeleted = Record[Idx++];
1495 Data.DefaultedDestructorIsDeleted = Record[Idx++];
Richard Smith328aae52012-11-30 05:11:39 +00001496 Data.HasTrivialSpecialMembers = Record[Idx++];
Richard Smithb45a6f72014-04-17 20:33:01 +00001497 Data.DeclaredNonTrivialSpecialMembers = Record[Idx++];
Richard Smith328aae52012-11-30 05:11:39 +00001498 Data.HasIrrelevantDestructor = Record[Idx++];
Richard Smith111af8d2011-08-10 18:11:37 +00001499 Data.HasConstexprNonCopyMoveConstructor = Record[Idx++];
Nico Weber72c57f42016-02-24 20:58:14 +00001500 Data.HasDefaultedDefaultConstructor = Record[Idx++];
Richard Smith561fb152012-02-25 07:33:38 +00001501 Data.DefaultedDefaultConstructorIsConstexpr = Record[Idx++];
Richard Smith561fb152012-02-25 07:33:38 +00001502 Data.HasConstexprDefaultConstructor = Record[Idx++];
Chandler Carruthe71d0622011-04-24 02:49:34 +00001503 Data.HasNonLiteralTypeFieldsOrBases = Record[Idx++];
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +00001504 Data.ComputedVisibleConversions = Record[Idx++];
Alexis Huntea6f0322011-05-11 22:34:38 +00001505 Data.UserProvidedDefaultConstructor = Record[Idx++];
Richard Smith328aae52012-11-30 05:11:39 +00001506 Data.DeclaredSpecialMembers = Record[Idx++];
Richard Smith1c33fe82012-11-28 06:23:12 +00001507 Data.ImplicitCopyConstructorHasConstParam = Record[Idx++];
1508 Data.ImplicitCopyAssignmentHasConstParam = Record[Idx++];
1509 Data.HasDeclaredCopyConstructorWithConstParam = Record[Idx++];
1510 Data.HasDeclaredCopyAssignmentWithConstParam = Record[Idx++];
Anders Carlsson703d6e62011-01-22 18:11:02 +00001511
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +00001512 Data.NumBases = Record[Idx++];
Douglas Gregord4c5ed02010-10-29 22:39:52 +00001513 if (Data.NumBases)
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001514 Data.Bases = ReadGlobalOffset();
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +00001515 Data.NumVBases = Record[Idx++];
Douglas Gregord4c5ed02010-10-29 22:39:52 +00001516 if (Data.NumVBases)
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001517 Data.VBases = ReadGlobalOffset();
1518
1519 Record.ReadUnresolvedSet(Data.Conversions, Idx);
1520 Record.ReadUnresolvedSet(Data.VisibleConversions, Idx);
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +00001521 assert(Data.Definition && "Data.Definition should be already set!");
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001522 Data.FirstFriend = ReadDeclID();
Richard Smith9dd9f032013-08-30 00:23:29 +00001523
Douglas Gregor99ae8062012-02-14 17:54:36 +00001524 if (Data.IsLambda) {
Benjamin Kramerf3ca26982014-05-10 16:31:55 +00001525 typedef LambdaCapture Capture;
Douglas Gregor99ae8062012-02-14 17:54:36 +00001526 CXXRecordDecl::LambdaDefinitionData &Lambda
1527 = static_cast<CXXRecordDecl::LambdaDefinitionData &>(Data);
Douglas Gregor680e9e02012-02-21 19:11:17 +00001528 Lambda.Dependent = Record[Idx++];
Faisal Valic1a6dc42013-10-23 16:10:50 +00001529 Lambda.IsGenericLambda = Record[Idx++];
1530 Lambda.CaptureDefault = Record[Idx++];
Douglas Gregor99ae8062012-02-14 17:54:36 +00001531 Lambda.NumCaptures = Record[Idx++];
1532 Lambda.NumExplicitCaptures = Record[Idx++];
Douglas Gregor63798542012-02-20 19:44:39 +00001533 Lambda.ManglingNumber = Record[Idx++];
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001534 Lambda.ContextDecl = ReadDeclID();
Douglas Gregor99ae8062012-02-14 17:54:36 +00001535 Lambda.Captures
1536 = (Capture*)Reader.Context.Allocate(sizeof(Capture)*Lambda.NumCaptures);
1537 Capture *ToCapture = Lambda.Captures;
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001538 Lambda.MethodTyInfo = GetTypeSourceInfo();
Douglas Gregor99ae8062012-02-14 17:54:36 +00001539 for (unsigned I = 0, N = Lambda.NumCaptures; I != N; ++I) {
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001540 SourceLocation Loc = ReadSourceLocation();
Douglas Gregor99ae8062012-02-14 17:54:36 +00001541 bool IsImplicit = Record[Idx++];
1542 LambdaCaptureKind Kind = static_cast<LambdaCaptureKind>(Record[Idx++]);
Richard Smithba71c082013-05-16 06:20:58 +00001543 switch (Kind) {
Faisal Validc6b5962016-03-21 09:25:37 +00001544 case LCK_StarThis:
Richard Smithba71c082013-05-16 06:20:58 +00001545 case LCK_This:
Alexey Bataev39c81e22014-08-28 04:28:19 +00001546 case LCK_VLAType:
Craig Toppera13603a2014-05-22 05:54:18 +00001547 *ToCapture++ = Capture(Loc, IsImplicit, Kind, nullptr,SourceLocation());
Richard Smithba71c082013-05-16 06:20:58 +00001548 break;
1549 case LCK_ByCopy:
Richard Smithbb13c9a2013-09-28 04:02:39 +00001550 case LCK_ByRef:
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001551 VarDecl *Var = ReadDeclAs<VarDecl>();
1552 SourceLocation EllipsisLoc = ReadSourceLocation();
Richard Smithba71c082013-05-16 06:20:58 +00001553 *ToCapture++ = Capture(Loc, IsImplicit, Kind, Var, EllipsisLoc);
1554 break;
1555 }
Douglas Gregor99ae8062012-02-14 17:54:36 +00001556 }
1557 }
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +00001558}
1559
Richard Smithcd45dbc2014-04-19 03:48:30 +00001560void ASTDeclReader::MergeDefinitionData(
Richard Smith8a639892015-01-24 01:07:20 +00001561 CXXRecordDecl *D, struct CXXRecordDecl::DefinitionData &&MergeDD) {
Richard Smithb6483992016-05-17 22:44:15 +00001562 assert(D->DefinitionData &&
Richard Smith053f6c62014-05-16 23:01:30 +00001563 "merging class definition into non-definition");
Richard Smithb6483992016-05-17 22:44:15 +00001564 auto &DD = *D->DefinitionData;
Richard Smithcd45dbc2014-04-19 03:48:30 +00001565
Richard Smith02793752015-03-27 21:16:39 +00001566 if (DD.Definition != MergeDD.Definition) {
Richard Smith97100e32015-06-20 00:22:34 +00001567 // Track that we merged the definitions.
1568 Reader.MergedDeclContexts.insert(std::make_pair(MergeDD.Definition,
1569 DD.Definition));
1570 Reader.PendingDefinitions.erase(MergeDD.Definition);
1571 MergeDD.Definition->IsCompleteDefinition = false;
Richard Smith6561f922016-09-12 21:06:40 +00001572 Reader.mergeDefinitionVisibility(DD.Definition, MergeDD.Definition);
Richard Smithd88a7f12015-09-01 20:35:42 +00001573 assert(Reader.Lookups.find(MergeDD.Definition) == Reader.Lookups.end() &&
1574 "already loaded pending lookups for merged definition");
Richard Smith02793752015-03-27 21:16:39 +00001575 }
1576
Richard Smith2a9e5c52015-02-03 03:32:14 +00001577 auto PFDI = Reader.PendingFakeDefinitionData.find(&DD);
1578 if (PFDI != Reader.PendingFakeDefinitionData.end() &&
1579 PFDI->second == ASTReader::PendingFakeDefinitionKind::Fake) {
Richard Smith8a639892015-01-24 01:07:20 +00001580 // We faked up this definition data because we found a class for which we'd
1581 // not yet loaded the definition. Replace it with the real thing now.
Richard Smith8a639892015-01-24 01:07:20 +00001582 assert(!DD.IsLambda && !MergeDD.IsLambda && "faked up lambda definition?");
Richard Smith2a9e5c52015-02-03 03:32:14 +00001583 PFDI->second = ASTReader::PendingFakeDefinitionKind::FakeLoaded;
Richard Smith8a639892015-01-24 01:07:20 +00001584
1585 // Don't change which declaration is the definition; that is required
1586 // to be invariant once we select it.
1587 auto *Def = DD.Definition;
1588 DD = std::move(MergeDD);
1589 DD.Definition = Def;
1590 return;
1591 }
1592
Richard Smithcd45dbc2014-04-19 03:48:30 +00001593 // FIXME: Move this out into a .def file?
Richard Smithcd45dbc2014-04-19 03:48:30 +00001594 bool DetectedOdrViolation = false;
1595#define OR_FIELD(Field) DD.Field |= MergeDD.Field;
1596#define MATCH_FIELD(Field) \
1597 DetectedOdrViolation |= DD.Field != MergeDD.Field; \
1598 OR_FIELD(Field)
1599 MATCH_FIELD(UserDeclaredConstructor)
1600 MATCH_FIELD(UserDeclaredSpecialMembers)
1601 MATCH_FIELD(Aggregate)
1602 MATCH_FIELD(PlainOldData)
1603 MATCH_FIELD(Empty)
1604 MATCH_FIELD(Polymorphic)
1605 MATCH_FIELD(Abstract)
1606 MATCH_FIELD(IsStandardLayout)
1607 MATCH_FIELD(HasNoNonEmptyBases)
1608 MATCH_FIELD(HasPrivateFields)
1609 MATCH_FIELD(HasProtectedFields)
1610 MATCH_FIELD(HasPublicFields)
1611 MATCH_FIELD(HasMutableFields)
1612 MATCH_FIELD(HasVariantMembers)
1613 MATCH_FIELD(HasOnlyCMembers)
1614 MATCH_FIELD(HasInClassInitializer)
1615 MATCH_FIELD(HasUninitializedReferenceMember)
Nico Weber6a6376b2016-02-19 01:52:46 +00001616 MATCH_FIELD(HasUninitializedFields)
Richard Smith12e79312016-05-13 06:47:56 +00001617 MATCH_FIELD(HasInheritedConstructor)
1618 MATCH_FIELD(HasInheritedAssignment)
Richard Smithcd45dbc2014-04-19 03:48:30 +00001619 MATCH_FIELD(NeedOverloadResolutionForMoveConstructor)
1620 MATCH_FIELD(NeedOverloadResolutionForMoveAssignment)
1621 MATCH_FIELD(NeedOverloadResolutionForDestructor)
1622 MATCH_FIELD(DefaultedMoveConstructorIsDeleted)
1623 MATCH_FIELD(DefaultedMoveAssignmentIsDeleted)
1624 MATCH_FIELD(DefaultedDestructorIsDeleted)
1625 OR_FIELD(HasTrivialSpecialMembers)
1626 OR_FIELD(DeclaredNonTrivialSpecialMembers)
1627 MATCH_FIELD(HasIrrelevantDestructor)
1628 OR_FIELD(HasConstexprNonCopyMoveConstructor)
Nico Weber72c57f42016-02-24 20:58:14 +00001629 OR_FIELD(HasDefaultedDefaultConstructor)
Richard Smithcd45dbc2014-04-19 03:48:30 +00001630 MATCH_FIELD(DefaultedDefaultConstructorIsConstexpr)
1631 OR_FIELD(HasConstexprDefaultConstructor)
1632 MATCH_FIELD(HasNonLiteralTypeFieldsOrBases)
1633 // ComputedVisibleConversions is handled below.
1634 MATCH_FIELD(UserProvidedDefaultConstructor)
1635 OR_FIELD(DeclaredSpecialMembers)
1636 MATCH_FIELD(ImplicitCopyConstructorHasConstParam)
1637 MATCH_FIELD(ImplicitCopyAssignmentHasConstParam)
1638 OR_FIELD(HasDeclaredCopyConstructorWithConstParam)
1639 OR_FIELD(HasDeclaredCopyAssignmentWithConstParam)
1640 MATCH_FIELD(IsLambda)
1641#undef OR_FIELD
1642#undef MATCH_FIELD
1643
1644 if (DD.NumBases != MergeDD.NumBases || DD.NumVBases != MergeDD.NumVBases)
1645 DetectedOdrViolation = true;
1646 // FIXME: Issue a diagnostic if the base classes don't match when we come
1647 // to lazily load them.
1648
1649 // FIXME: Issue a diagnostic if the list of conversion functions doesn't
1650 // match when we come to lazily load them.
1651 if (MergeDD.ComputedVisibleConversions && !DD.ComputedVisibleConversions) {
1652 DD.VisibleConversions = std::move(MergeDD.VisibleConversions);
1653 DD.ComputedVisibleConversions = true;
1654 }
1655
1656 // FIXME: Issue a diagnostic if FirstFriend doesn't match when we come to
1657 // lazily load it.
1658
1659 if (DD.IsLambda) {
1660 // FIXME: ODR-checking for merging lambdas (this happens, for instance,
1661 // when they occur within the body of a function template specialization).
1662 }
1663
1664 if (DetectedOdrViolation)
1665 Reader.PendingOdrMergeFailures[DD.Definition].push_back(MergeDD.Definition);
1666}
1667
Richard Smith2a9e5c52015-02-03 03:32:14 +00001668void ASTDeclReader::ReadCXXRecordDefinition(CXXRecordDecl *D, bool Update) {
Richard Smithcd45dbc2014-04-19 03:48:30 +00001669 struct CXXRecordDecl::DefinitionData *DD;
1670 ASTContext &C = Reader.getContext();
1671
1672 // Determine whether this is a lambda closure type, so that we can
1673 // allocate the appropriate DefinitionData structure.
1674 bool IsLambda = Record[Idx++];
1675 if (IsLambda)
Craig Toppera13603a2014-05-22 05:54:18 +00001676 DD = new (C) CXXRecordDecl::LambdaDefinitionData(D, nullptr, false, false,
Richard Smithcd45dbc2014-04-19 03:48:30 +00001677 LCD_None);
1678 else
1679 DD = new (C) struct CXXRecordDecl::DefinitionData(D);
1680
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001681 ReadCXXDefinitionData(*DD, Idx);
Richard Smithcd45dbc2014-04-19 03:48:30 +00001682
Richard Smith5156c382015-01-22 01:41:56 +00001683 // We might already have a definition for this record. This can happen either
1684 // because we're reading an update record, or because we've already done some
1685 // merging. Either way, just merge into it.
Richard Smith8a639892015-01-24 01:07:20 +00001686 CXXRecordDecl *Canon = D->getCanonicalDecl();
Richard Smithb6483992016-05-17 22:44:15 +00001687 if (Canon->DefinitionData) {
Richard Smith8a639892015-01-24 01:07:20 +00001688 MergeDefinitionData(Canon, std::move(*DD));
1689 D->DefinitionData = Canon->DefinitionData;
Richard Smithcd45dbc2014-04-19 03:48:30 +00001690 return;
1691 }
1692
Richard Smith97100e32015-06-20 00:22:34 +00001693 // Mark this declaration as being a definition.
1694 D->IsCompleteDefinition = true;
1695 D->DefinitionData = DD;
Richard Smith2a9e5c52015-02-03 03:32:14 +00001696
Richard Smith97100e32015-06-20 00:22:34 +00001697 // If this is not the first declaration or is an update record, we can have
1698 // other redeclarations already. Make a note that we need to propagate the
1699 // DefinitionData pointer onto them.
1700 if (Update || Canon != D) {
1701 Canon->DefinitionData = D->DefinitionData;
Richard Smithcd45dbc2014-04-19 03:48:30 +00001702 Reader.PendingDefinitions.insert(D);
Richard Smithcd45dbc2014-04-19 03:48:30 +00001703 }
1704}
1705
Richard Smith1d209d02013-05-23 01:49:11 +00001706ASTDeclReader::RedeclarableResult
1707ASTDeclReader::VisitCXXRecordDeclImpl(CXXRecordDecl *D) {
1708 RedeclarableResult Redecl = VisitRecordDeclImpl(D);
Argyrios Kyrtzidisa41f6602010-10-20 00:11:15 +00001709
Douglas Gregor3a5ae562012-01-15 18:17:48 +00001710 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +00001711
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001712 enum CXXRecKind {
1713 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
1714 };
1715 switch ((CXXRecKind)Record[Idx++]) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001716 case CXXRecNotTemplate:
Richard Smithdc5523d2014-07-11 00:20:06 +00001717 // Merged when we merge the folding set entry in the primary template.
1718 if (!isa<ClassTemplateSpecializationDecl>(D))
1719 mergeRedeclarable(D, Redecl);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001720 break;
Richard Smithf17fdbd2014-04-24 02:25:27 +00001721 case CXXRecTemplate: {
1722 // Merged when we merge the template.
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001723 ClassTemplateDecl *Template = ReadDeclAs<ClassTemplateDecl>();
Richard Smithf17fdbd2014-04-24 02:25:27 +00001724 D->TemplateOrInstantiation = Template;
1725 if (!Template->getTemplatedDecl()) {
1726 // We've not actually loaded the ClassTemplateDecl yet, because we're
1727 // currently being loaded as its pattern. Rely on it to set up our
1728 // TypeForDecl (see VisitClassTemplateDecl).
1729 //
1730 // Beware: we do not yet know our canonical declaration, and may still
1731 // get merged once the surrounding class template has got off the ground.
1732 TypeIDForTypeDecl = 0;
1733 }
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001734 break;
Richard Smithf17fdbd2014-04-24 02:25:27 +00001735 }
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001736 case CXXRecMemberSpecialization: {
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001737 CXXRecordDecl *RD = ReadDeclAs<CXXRecordDecl>();
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001738 TemplateSpecializationKind TSK = (TemplateSpecializationKind)Record[Idx++];
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001739 SourceLocation POI = ReadSourceLocation();
Argyrios Kyrtzidiscaf82482010-09-13 11:45:25 +00001740 MemberSpecializationInfo *MSI = new (C) MemberSpecializationInfo(RD, TSK);
1741 MSI->setPointOfInstantiation(POI);
1742 D->TemplateOrInstantiation = MSI;
Richard Smithcd45dbc2014-04-19 03:48:30 +00001743 mergeRedeclarable(D, Redecl);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001744 break;
1745 }
1746 }
Argyrios Kyrtzidis68431412010-10-14 20:14:38 +00001747
Richard Smithcd45dbc2014-04-19 03:48:30 +00001748 bool WasDefinition = Record[Idx++];
1749 if (WasDefinition)
Richard Smith2a9e5c52015-02-03 03:32:14 +00001750 ReadCXXRecordDefinition(D, /*Update*/false);
Richard Smithcd45dbc2014-04-19 03:48:30 +00001751 else
1752 // Propagate DefinitionData pointer from the canonical declaration.
1753 D->DefinitionData = D->getCanonicalDecl()->DefinitionData;
1754
Richard Smith676c4042013-08-29 23:59:27 +00001755 // Lazily load the key function to avoid deserializing every method so we can
Argyrios Kyrtzidis68431412010-10-14 20:14:38 +00001756 // compute it.
Richard Smithd55889a2013-09-09 16:55:27 +00001757 if (WasDefinition) {
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001758 DeclID KeyFn = ReadDeclID();
Richard Smithd55889a2013-09-09 16:55:27 +00001759 if (KeyFn && D->IsCompleteDefinition)
Richard Smitha9a1c682014-07-07 06:38:20 +00001760 // FIXME: This is wrong for the ARM ABI, where some other module may have
1761 // made this function no longer be a key function. We need an update
1762 // record or similar for that case.
Richard Smith676c4042013-08-29 23:59:27 +00001763 C.KeyFunctions[D] = KeyFn;
Argyrios Kyrtzidis68431412010-10-14 20:14:38 +00001764 }
Richard Smith1d209d02013-05-23 01:49:11 +00001765
1766 return Redecl;
Chris Lattnerca025db2010-05-07 21:43:38 +00001767}
1768
Sebastian Redlb3298c32010-08-18 23:56:48 +00001769void ASTDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001770 VisitFunctionDecl(D);
Richard Smithb1108732014-08-26 23:29:11 +00001771
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +00001772 unsigned NumOverridenMethods = Record[Idx++];
Richard Smithb1108732014-08-26 23:29:11 +00001773 if (D->isCanonicalDecl()) {
1774 while (NumOverridenMethods--) {
1775 // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod,
1776 // MD may be initializing.
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001777 if (CXXMethodDecl *MD = ReadDeclAs<CXXMethodDecl>())
Richard Smithb1108732014-08-26 23:29:11 +00001778 Reader.getContext().addOverriddenMethod(D, MD->getCanonicalDecl());
1779 }
1780 } else {
1781 // We don't care about which declarations this used to override; we get
1782 // the relevant information from the canonical declaration.
1783 Idx += NumOverridenMethods;
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +00001784 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001785}
1786
Sebastian Redlb3298c32010-08-18 23:56:48 +00001787void ASTDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
Richard Smith5179eb72016-06-28 19:03:57 +00001788 // We need the inherited constructor information to merge the declaration,
1789 // so we have to read it before we call VisitCXXMethodDecl.
1790 if (D->isInheritingConstructor()) {
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001791 auto *Shadow = ReadDeclAs<ConstructorUsingShadowDecl>();
1792 auto *Ctor = ReadDeclAs<CXXConstructorDecl>();
Richard Smith5179eb72016-06-28 19:03:57 +00001793 *D->getTrailingObjects<InheritedConstructor>() =
1794 InheritedConstructor(Shadow, Ctor);
1795 }
1796
Chris Lattnerca025db2010-05-07 21:43:38 +00001797 VisitCXXMethodDecl(D);
Stephan Tolksdorfa6a08632014-03-27 19:22:19 +00001798
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001799 D->IsExplicitSpecified = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +00001800}
1801
Sebastian Redlb3298c32010-08-18 23:56:48 +00001802void ASTDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001803 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001804
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001805 if (auto *OperatorDelete = ReadDeclAs<FunctionDecl>()) {
Richard Smithf8134002015-03-10 01:41:22 +00001806 auto *Canon = cast<CXXDestructorDecl>(D->getCanonicalDecl());
1807 // FIXME: Check consistency if we have an old and new operator delete.
1808 if (!Canon->OperatorDelete)
1809 Canon->OperatorDelete = OperatorDelete;
1810 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001811}
1812
Sebastian Redlb3298c32010-08-18 23:56:48 +00001813void ASTDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001814 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001815 D->IsExplicitSpecified = Record[Idx++];
Chris Lattnerca025db2010-05-07 21:43:38 +00001816}
1817
Douglas Gregorba345522011-12-02 23:23:56 +00001818void ASTDeclReader::VisitImportDecl(ImportDecl *D) {
1819 VisitDecl(D);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001820 D->ImportedAndComplete.setPointer(readModule());
Douglas Gregorba345522011-12-02 23:23:56 +00001821 D->ImportedAndComplete.setInt(Record[Idx++]);
James Y Knight967eb202015-12-29 22:13:13 +00001822 SourceLocation *StoredLocs = D->getTrailingObjects<SourceLocation>();
Douglas Gregorba345522011-12-02 23:23:56 +00001823 for (unsigned I = 0, N = Record.back(); I != N; ++I)
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001824 StoredLocs[I] = ReadSourceLocation();
Argyrios Kyrtzidis7b8e5552012-10-03 01:58:45 +00001825 ++Idx; // The number of stored source locations.
Douglas Gregorba345522011-12-02 23:23:56 +00001826}
1827
Sebastian Redlb3298c32010-08-18 23:56:48 +00001828void ASTDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) {
Abramo Bagnarad7340582010-06-05 05:09:32 +00001829 VisitDecl(D);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001830 D->setColonLoc(ReadSourceLocation());
Abramo Bagnarad7340582010-06-05 05:09:32 +00001831}
1832
Sebastian Redlb3298c32010-08-18 23:56:48 +00001833void ASTDeclReader::VisitFriendDecl(FriendDecl *D) {
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +00001834 VisitDecl(D);
Enea Zaffanellaeb22c872013-01-31 09:54:08 +00001835 if (Record[Idx++]) // hasFriendDecl
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001836 D->Friend = ReadDeclAs<NamedDecl>();
Enea Zaffanellaeb22c872013-01-31 09:54:08 +00001837 else
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001838 D->Friend = GetTypeSourceInfo();
Enea Zaffanellaeb22c872013-01-31 09:54:08 +00001839 for (unsigned i = 0; i != D->NumTPLists; ++i)
James Y Knight967eb202015-12-29 22:13:13 +00001840 D->getTrailingObjects<TemplateParameterList *>()[i] =
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001841 Record.ReadTemplateParameterList(Idx);
1842 D->NextFriend = ReadDeclID();
John McCall2c2eb122010-10-16 06:59:13 +00001843 D->UnsupportedFriend = (Record[Idx++] != 0);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001844 D->FriendLoc = ReadSourceLocation();
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00001845}
1846
Sebastian Redlb3298c32010-08-18 23:56:48 +00001847void ASTDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001848 VisitDecl(D);
1849 unsigned NumParams = Record[Idx++];
1850 D->NumParams = NumParams;
1851 D->Params = new TemplateParameterList*[NumParams];
1852 for (unsigned i = 0; i != NumParams; ++i)
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001853 D->Params[i] = Record.ReadTemplateParameterList(Idx);
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001854 if (Record[Idx++]) // HasFriendDecl
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001855 D->Friend = ReadDeclAs<NamedDecl>();
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00001856 else
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001857 D->Friend = GetTypeSourceInfo();
1858 D->FriendLoc = ReadSourceLocation();
Chris Lattnerca025db2010-05-07 21:43:38 +00001859}
1860
Richard Smithf17fdbd2014-04-24 02:25:27 +00001861DeclID ASTDeclReader::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001862 VisitNamedDecl(D);
1863
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001864 DeclID PatternID = ReadDeclID();
Richard Smithf17fdbd2014-04-24 02:25:27 +00001865 NamedDecl *TemplatedDecl = cast_or_null<NamedDecl>(Reader.GetDecl(PatternID));
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001866 TemplateParameterList* TemplateParams
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001867 = Record.ReadTemplateParameterList(Idx);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001868 D->init(TemplatedDecl, TemplateParams);
Richard Smithbf78e642013-06-24 22:51:00 +00001869
Richard Smithf17fdbd2014-04-24 02:25:27 +00001870 return PatternID;
Chris Lattnerca025db2010-05-07 21:43:38 +00001871}
1872
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001873ASTDeclReader::RedeclarableResult
Douglas Gregor54079202012-01-06 22:05:37 +00001874ASTDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) {
Douglas Gregor68444de2012-01-14 15:13:49 +00001875 RedeclarableResult Redecl = VisitRedeclarable(D);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001876
Douglas Gregor68444de2012-01-14 15:13:49 +00001877 // Make sure we've allocated the Common pointer first. We do this before
1878 // VisitTemplateDecl so that getCommonPtr() can be used during initialization.
1879 RedeclarableTemplateDecl *CanonD = D->getCanonicalDecl();
1880 if (!CanonD->Common) {
1881 CanonD->Common = CanonD->newCommon(Reader.getContext());
1882 Reader.PendingDefinitions.insert(CanonD);
1883 }
1884 D->Common = CanonD->Common;
Douglas Gregor022857e2011-12-22 01:48:48 +00001885
Douglas Gregor68444de2012-01-14 15:13:49 +00001886 // If this is the first declaration of the template, fill in the information
1887 // for the 'common' pointer.
1888 if (ThisDeclID == Redecl.getFirstID()) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001889 if (RedeclarableTemplateDecl *RTD
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001890 = ReadDeclAs<RedeclarableTemplateDecl>()) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001891 assert(RTD->getKind() == D->getKind() &&
1892 "InstantiatedFromMemberTemplate kind mismatch");
Douglas Gregor68444de2012-01-14 15:13:49 +00001893 D->setInstantiatedFromMemberTemplate(RTD);
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001894 if (Record[Idx++])
1895 D->setMemberSpecialization();
1896 }
1897 }
Axel Naumann866ba3e2012-10-01 09:18:00 +00001898
Richard Smithf17fdbd2014-04-24 02:25:27 +00001899 DeclID PatternID = VisitTemplateDecl(D);
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +00001900 D->IdentifierNamespace = Record[Idx++];
Axel Naumann866ba3e2012-10-01 09:18:00 +00001901
Richard Smithf17fdbd2014-04-24 02:25:27 +00001902 mergeRedeclarable(D, Redecl, PatternID);
Axel Naumann866ba3e2012-10-01 09:18:00 +00001903
Richard Smithd46d6de2013-10-13 23:50:45 +00001904 // If we merged the template with a prior declaration chain, merge the common
1905 // pointer.
1906 // FIXME: Actually merge here, don't just overwrite.
1907 D->Common = D->getCanonicalDecl()->Common;
1908
Douglas Gregor68444de2012-01-14 15:13:49 +00001909 return Redecl;
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001910}
1911
Richard Smith0b884372015-02-27 00:25:58 +00001912static DeclID *newDeclIDList(ASTContext &Context, DeclID *Old,
1913 SmallVectorImpl<DeclID> &IDs) {
1914 assert(!IDs.empty() && "no IDs to add to list");
Richard Smith36befce2015-02-28 01:45:19 +00001915 if (Old) {
1916 IDs.insert(IDs.end(), Old + 1, Old + 1 + Old[0]);
1917 std::sort(IDs.begin(), IDs.end());
1918 IDs.erase(std::unique(IDs.begin(), IDs.end()), IDs.end());
1919 }
Richard Smith0b884372015-02-27 00:25:58 +00001920
Richard Smith36befce2015-02-28 01:45:19 +00001921 auto *Result = new (Context) DeclID[1 + IDs.size()];
1922 *Result = IDs.size();
1923 std::copy(IDs.begin(), IDs.end(), Result + 1);
Richard Smith0b884372015-02-27 00:25:58 +00001924 return Result;
1925}
1926
Sebastian Redlb3298c32010-08-18 23:56:48 +00001927void ASTDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Douglas Gregor68444de2012-01-14 15:13:49 +00001928 RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D);
Peter Collingbourne91b25b72010-07-29 16:11:51 +00001929
Douglas Gregor68444de2012-01-14 15:13:49 +00001930 if (ThisDeclID == Redecl.getFirstID()) {
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001931 // This ClassTemplateDecl owns a CommonPtr; read it to keep track of all of
1932 // the specializations.
Richard Smith0b884372015-02-27 00:25:58 +00001933 SmallVector<serialization::DeclID, 32> SpecIDs;
Richard Smith0b884372015-02-27 00:25:58 +00001934 ReadDeclIDList(SpecIDs);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001935
Richard Smith0b884372015-02-27 00:25:58 +00001936 if (!SpecIDs.empty()) {
1937 auto *CommonPtr = D->getCommonPtr();
1938 CommonPtr->LazySpecializations = newDeclIDList(
1939 Reader.getContext(), CommonPtr->LazySpecializations, SpecIDs);
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00001940 }
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001941 }
Richard Smithf17fdbd2014-04-24 02:25:27 +00001942
1943 if (D->getTemplatedDecl()->TemplateOrInstantiation) {
1944 // We were loaded before our templated declaration was. We've not set up
1945 // its corresponding type yet (see VisitCXXRecordDeclImpl), so reconstruct
1946 // it now.
1947 Reader.Context.getInjectedClassNameType(
Richard Smitha1406fa2014-05-23 21:31:59 +00001948 D->getTemplatedDecl(), D->getInjectedClassNameSpecialization());
Richard Smithf17fdbd2014-04-24 02:25:27 +00001949 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001950}
1951
David Majnemerd9b1a4f2015-11-04 03:40:30 +00001952void ASTDeclReader::VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D) {
1953 llvm_unreachable("BuiltinTemplates are not serialized");
1954}
1955
Larisse Voufo30616382013-08-23 22:21:36 +00001956/// TODO: Unify with ClassTemplateDecl version?
1957/// May require unifying ClassTemplateDecl and
1958/// VarTemplateDecl beyond TemplateDecl...
Larisse Voufo39a1e502013-08-06 01:03:05 +00001959void ASTDeclReader::VisitVarTemplateDecl(VarTemplateDecl *D) {
1960 RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D);
1961
1962 if (ThisDeclID == Redecl.getFirstID()) {
Larisse Voufod8dd97c2013-08-14 03:09:19 +00001963 // This VarTemplateDecl owns a CommonPtr; read it to keep track of all of
Larisse Voufo39a1e502013-08-06 01:03:05 +00001964 // the specializations.
Richard Smith0b884372015-02-27 00:25:58 +00001965 SmallVector<serialization::DeclID, 32> SpecIDs;
Richard Smith0b884372015-02-27 00:25:58 +00001966 ReadDeclIDList(SpecIDs);
Larisse Voufo39a1e502013-08-06 01:03:05 +00001967
Richard Smith0b884372015-02-27 00:25:58 +00001968 if (!SpecIDs.empty()) {
1969 auto *CommonPtr = D->getCommonPtr();
1970 CommonPtr->LazySpecializations = newDeclIDList(
1971 Reader.getContext(), CommonPtr->LazySpecializations, SpecIDs);
Larisse Voufo39a1e502013-08-06 01:03:05 +00001972 }
1973 }
1974}
1975
Richard Smith1d209d02013-05-23 01:49:11 +00001976ASTDeclReader::RedeclarableResult
1977ASTDeclReader::VisitClassTemplateSpecializationDeclImpl(
1978 ClassTemplateSpecializationDecl *D) {
1979 RedeclarableResult Redecl = VisitCXXRecordDeclImpl(D);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001980
Douglas Gregor4163aca2011-09-09 21:34:22 +00001981 ASTContext &C = Reader.getContext();
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001982 if (Decl *InstD = ReadDecl()) {
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001983 if (ClassTemplateDecl *CTD = dyn_cast<ClassTemplateDecl>(InstD)) {
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001984 D->SpecializedTemplate = CTD;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001985 } else {
Chris Lattner0e62c1c2011-07-23 10:55:15 +00001986 SmallVector<TemplateArgument, 8> TemplArgs;
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001987 Record.ReadTemplateArgumentList(TemplArgs, Idx);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001988 TemplateArgumentList *ArgList
David Majnemer8b622692016-07-03 21:17:51 +00001989 = TemplateArgumentList::CreateCopy(C, TemplArgs);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00001990 ClassTemplateSpecializationDecl::SpecializedPartialSpecialization *PS
1991 = new (C) ClassTemplateSpecializationDecl::
1992 SpecializedPartialSpecialization();
1993 PS->PartialSpecialization
1994 = cast<ClassTemplatePartialSpecializationDecl>(InstD);
1995 PS->TemplateArgs = ArgList;
1996 D->SpecializedTemplate = PS;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00001997 }
1998 }
1999
Chris Lattner0e62c1c2011-07-23 10:55:15 +00002000 SmallVector<TemplateArgument, 8> TemplArgs;
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002001 Record.ReadTemplateArgumentList(TemplArgs, Idx,
Richard Smith2bb3c342015-08-09 01:05:31 +00002002 /*Canonicalize*/ true);
David Majnemer8b622692016-07-03 21:17:51 +00002003 D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002004 D->PointOfInstantiation = ReadSourceLocation();
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00002005 D->SpecializationKind = (TemplateSpecializationKind)Record[Idx++];
Axel Naumanna31dee22012-10-01 07:34:47 +00002006
2007 bool writtenAsCanonicalDecl = Record[Idx++];
2008 if (writtenAsCanonicalDecl) {
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002009 ClassTemplateDecl *CanonPattern = ReadDeclAs<ClassTemplateDecl>();
Axel Naumanna31dee22012-10-01 07:34:47 +00002010 if (D->isCanonicalDecl()) { // It's kept in the folding set.
Richard Smithd55889a2013-09-09 16:55:27 +00002011 // Set this as, or find, the canonical declaration for this specialization
2012 ClassTemplateSpecializationDecl *CanonSpec;
Richard Smith5de91b52013-06-25 01:25:15 +00002013 if (ClassTemplatePartialSpecializationDecl *Partial =
2014 dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) {
Richard Smithd55889a2013-09-09 16:55:27 +00002015 CanonSpec = CanonPattern->getCommonPtr()->PartialSpecializations
Richard Smith5de91b52013-06-25 01:25:15 +00002016 .GetOrInsertNode(Partial);
Axel Naumanna31dee22012-10-01 07:34:47 +00002017 } else {
Richard Smithd55889a2013-09-09 16:55:27 +00002018 CanonSpec =
2019 CanonPattern->getCommonPtr()->Specializations.GetOrInsertNode(D);
2020 }
2021 // If there was already a canonical specialization, merge into it.
2022 if (CanonSpec != D) {
2023 mergeRedeclarable<TagDecl>(D, CanonSpec, Redecl);
2024
2025 // This declaration might be a definition. Merge with any existing
2026 // definition.
Richard Smithb6483992016-05-17 22:44:15 +00002027 if (auto *DDD = D->DefinitionData) {
2028 if (CanonSpec->DefinitionData)
Richard Smith8a639892015-01-24 01:07:20 +00002029 MergeDefinitionData(CanonSpec, std::move(*DDD));
Richard Smith97100e32015-06-20 00:22:34 +00002030 else
Richard Smith053f6c62014-05-16 23:01:30 +00002031 CanonSpec->DefinitionData = D->DefinitionData;
Richard Smithd55889a2013-09-09 16:55:27 +00002032 }
Richard Smith547864d2014-07-11 18:22:58 +00002033 D->DefinitionData = CanonSpec->DefinitionData;
Axel Naumanna31dee22012-10-01 07:34:47 +00002034 }
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00002035 }
2036 }
Richard Smith1d209d02013-05-23 01:49:11 +00002037
Richard Smithd55889a2013-09-09 16:55:27 +00002038 // Explicit info.
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002039 if (TypeSourceInfo *TyInfo = GetTypeSourceInfo()) {
Richard Smithd55889a2013-09-09 16:55:27 +00002040 ClassTemplateSpecializationDecl::ExplicitSpecializationInfo *ExplicitInfo
2041 = new (C) ClassTemplateSpecializationDecl::ExplicitSpecializationInfo;
2042 ExplicitInfo->TypeAsWritten = TyInfo;
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002043 ExplicitInfo->ExternLoc = ReadSourceLocation();
2044 ExplicitInfo->TemplateKeywordLoc = ReadSourceLocation();
Richard Smithd55889a2013-09-09 16:55:27 +00002045 D->ExplicitInfo = ExplicitInfo;
2046 }
2047
Richard Smith1d209d02013-05-23 01:49:11 +00002048 return Redecl;
Chris Lattnerca025db2010-05-07 21:43:38 +00002049}
2050
Sebastian Redlb3298c32010-08-18 23:56:48 +00002051void ASTDeclReader::VisitClassTemplatePartialSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00002052 ClassTemplatePartialSpecializationDecl *D) {
Richard Smith1d209d02013-05-23 01:49:11 +00002053 RedeclarableResult Redecl = VisitClassTemplateSpecializationDeclImpl(D);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00002054
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002055 D->TemplateParams = Record.ReadTemplateParameterList(Idx);
2056 D->ArgsAsWritten = Record.ReadASTTemplateArgumentListInfo(Idx);
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00002057
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00002058 // These are read/set from/to the first declaration.
Richard Smith1d209d02013-05-23 01:49:11 +00002059 if (ThisDeclID == Redecl.getFirstID()) {
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00002060 D->InstantiatedFromMember.setPointer(
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002061 ReadDeclAs<ClassTemplatePartialSpecializationDecl>());
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00002062 D->InstantiatedFromMember.setInt(Record[Idx++]);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00002063 }
Chris Lattnerca025db2010-05-07 21:43:38 +00002064}
2065
Sebastian Redlb7448632011-08-31 13:59:56 +00002066void ASTDeclReader::VisitClassScopeFunctionSpecializationDecl(
2067 ClassScopeFunctionSpecializationDecl *D) {
Francois Pichet09af8c32011-08-17 01:06:54 +00002068 VisitDecl(D);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002069 D->Specialization = ReadDeclAs<CXXMethodDecl>();
Francois Pichet09af8c32011-08-17 01:06:54 +00002070}
2071
Sebastian Redlb3298c32010-08-18 23:56:48 +00002072void ASTDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
Douglas Gregor68444de2012-01-14 15:13:49 +00002073 RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00002074
Douglas Gregor68444de2012-01-14 15:13:49 +00002075 if (ThisDeclID == Redecl.getFirstID()) {
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00002076 // This FunctionTemplateDecl owns a CommonPtr; read it.
Richard Smith0b884372015-02-27 00:25:58 +00002077 SmallVector<serialization::DeclID, 32> SpecIDs;
2078 ReadDeclIDList(SpecIDs);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00002079
Richard Smith0b884372015-02-27 00:25:58 +00002080 if (!SpecIDs.empty()) {
2081 auto *CommonPtr = D->getCommonPtr();
2082 CommonPtr->LazySpecializations = newDeclIDList(
2083 Reader.getContext(), CommonPtr->LazySpecializations, SpecIDs);
Richard Smithfeb3e1a2013-06-28 04:37:53 +00002084 }
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00002085 }
Chris Lattnerca025db2010-05-07 21:43:38 +00002086}
2087
Larisse Voufo30616382013-08-23 22:21:36 +00002088/// TODO: Unify with ClassTemplateSpecializationDecl version?
2089/// May require unifying ClassTemplate(Partial)SpecializationDecl and
2090/// VarTemplate(Partial)SpecializationDecl with a new data
2091/// structure Template(Partial)SpecializationDecl, and
2092/// using Template(Partial)SpecializationDecl as input type.
Larisse Voufo39a1e502013-08-06 01:03:05 +00002093ASTDeclReader::RedeclarableResult
2094ASTDeclReader::VisitVarTemplateSpecializationDeclImpl(
2095 VarTemplateSpecializationDecl *D) {
2096 RedeclarableResult Redecl = VisitVarDeclImpl(D);
2097
2098 ASTContext &C = Reader.getContext();
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002099 if (Decl *InstD = ReadDecl()) {
Larisse Voufo39a1e502013-08-06 01:03:05 +00002100 if (VarTemplateDecl *VTD = dyn_cast<VarTemplateDecl>(InstD)) {
2101 D->SpecializedTemplate = VTD;
2102 } else {
2103 SmallVector<TemplateArgument, 8> TemplArgs;
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002104 Record.ReadTemplateArgumentList(TemplArgs, Idx);
Larisse Voufo39a1e502013-08-06 01:03:05 +00002105 TemplateArgumentList *ArgList = TemplateArgumentList::CreateCopy(
David Majnemer8b622692016-07-03 21:17:51 +00002106 C, TemplArgs);
Larisse Voufo39a1e502013-08-06 01:03:05 +00002107 VarTemplateSpecializationDecl::SpecializedPartialSpecialization *PS =
2108 new (C)
2109 VarTemplateSpecializationDecl::SpecializedPartialSpecialization();
2110 PS->PartialSpecialization =
2111 cast<VarTemplatePartialSpecializationDecl>(InstD);
2112 PS->TemplateArgs = ArgList;
2113 D->SpecializedTemplate = PS;
2114 }
2115 }
2116
2117 // Explicit info.
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002118 if (TypeSourceInfo *TyInfo = GetTypeSourceInfo()) {
Larisse Voufo39a1e502013-08-06 01:03:05 +00002119 VarTemplateSpecializationDecl::ExplicitSpecializationInfo *ExplicitInfo =
2120 new (C) VarTemplateSpecializationDecl::ExplicitSpecializationInfo;
2121 ExplicitInfo->TypeAsWritten = TyInfo;
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002122 ExplicitInfo->ExternLoc = ReadSourceLocation();
2123 ExplicitInfo->TemplateKeywordLoc = ReadSourceLocation();
Larisse Voufo39a1e502013-08-06 01:03:05 +00002124 D->ExplicitInfo = ExplicitInfo;
2125 }
2126
2127 SmallVector<TemplateArgument, 8> TemplArgs;
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002128 Record.ReadTemplateArgumentList(TemplArgs, Idx,
Richard Smith2bb3c342015-08-09 01:05:31 +00002129 /*Canonicalize*/ true);
David Majnemer8b622692016-07-03 21:17:51 +00002130 D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002131 D->PointOfInstantiation = ReadSourceLocation();
Larisse Voufo39a1e502013-08-06 01:03:05 +00002132 D->SpecializationKind = (TemplateSpecializationKind)Record[Idx++];
2133
2134 bool writtenAsCanonicalDecl = Record[Idx++];
2135 if (writtenAsCanonicalDecl) {
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002136 VarTemplateDecl *CanonPattern = ReadDeclAs<VarTemplateDecl>();
Larisse Voufo39a1e502013-08-06 01:03:05 +00002137 if (D->isCanonicalDecl()) { // It's kept in the folding set.
Richard Smith9b88a4c2015-07-27 05:40:23 +00002138 // FIXME: If it's already present, merge it.
Larisse Voufo39a1e502013-08-06 01:03:05 +00002139 if (VarTemplatePartialSpecializationDecl *Partial =
2140 dyn_cast<VarTemplatePartialSpecializationDecl>(D)) {
Larisse Voufo39a1e502013-08-06 01:03:05 +00002141 CanonPattern->getCommonPtr()->PartialSpecializations
2142 .GetOrInsertNode(Partial);
2143 } else {
2144 CanonPattern->getCommonPtr()->Specializations.GetOrInsertNode(D);
2145 }
2146 }
2147 }
2148
2149 return Redecl;
2150}
2151
Larisse Voufo30616382013-08-23 22:21:36 +00002152/// TODO: Unify with ClassTemplatePartialSpecializationDecl version?
2153/// May require unifying ClassTemplate(Partial)SpecializationDecl and
2154/// VarTemplate(Partial)SpecializationDecl with a new data
2155/// structure Template(Partial)SpecializationDecl, and
2156/// using Template(Partial)SpecializationDecl as input type.
Larisse Voufo39a1e502013-08-06 01:03:05 +00002157void ASTDeclReader::VisitVarTemplatePartialSpecializationDecl(
2158 VarTemplatePartialSpecializationDecl *D) {
2159 RedeclarableResult Redecl = VisitVarTemplateSpecializationDeclImpl(D);
2160
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002161 D->TemplateParams = Record.ReadTemplateParameterList(Idx);
2162 D->ArgsAsWritten = Record.ReadASTTemplateArgumentListInfo(Idx);
Larisse Voufo39a1e502013-08-06 01:03:05 +00002163
2164 // These are read/set from/to the first declaration.
2165 if (ThisDeclID == Redecl.getFirstID()) {
2166 D->InstantiatedFromMember.setPointer(
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002167 ReadDeclAs<VarTemplatePartialSpecializationDecl>());
Larisse Voufo39a1e502013-08-06 01:03:05 +00002168 D->InstantiatedFromMember.setInt(Record[Idx++]);
2169 }
2170}
2171
Sebastian Redlb3298c32010-08-18 23:56:48 +00002172void ASTDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00002173 VisitTypeDecl(D);
2174
2175 D->setDeclaredWithTypename(Record[Idx++]);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00002176
Richard Smith1469b912015-06-10 00:29:03 +00002177 if (Record[Idx++])
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002178 D->setDefaultArgument(GetTypeSourceInfo());
Chris Lattnerca025db2010-05-07 21:43:38 +00002179}
2180
Sebastian Redlb3298c32010-08-18 23:56:48 +00002181void ASTDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
John McCallf4cd4f92011-02-09 01:13:10 +00002182 VisitDeclaratorDecl(D);
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00002183 // TemplateParmPosition.
2184 D->setDepth(Record[Idx++]);
2185 D->setPosition(Record[Idx++]);
Douglas Gregor0231d8d2011-01-19 20:10:05 +00002186 if (D->isExpandedParameterPack()) {
James Y Knight967eb202015-12-29 22:13:13 +00002187 auto TypesAndInfos =
2188 D->getTrailingObjects<std::pair<QualType, TypeSourceInfo *>>();
Douglas Gregor0231d8d2011-01-19 20:10:05 +00002189 for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) {
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002190 new (&TypesAndInfos[I].first) QualType(Record.readType(Idx));
2191 TypesAndInfos[I].second = GetTypeSourceInfo();
Douglas Gregor0231d8d2011-01-19 20:10:05 +00002192 }
2193 } else {
2194 // Rest of NonTypeTemplateParmDecl.
2195 D->ParameterPack = Record[Idx++];
Richard Smith1469b912015-06-10 00:29:03 +00002196 if (Record[Idx++])
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002197 D->setDefaultArgument(Record.ReadExpr());
Douglas Gregor0231d8d2011-01-19 20:10:05 +00002198 }
Chris Lattnerca025db2010-05-07 21:43:38 +00002199}
2200
Sebastian Redlb3298c32010-08-18 23:56:48 +00002201void ASTDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00002202 VisitTemplateDecl(D);
2203 // TemplateParmPosition.
2204 D->setDepth(Record[Idx++]);
2205 D->setPosition(Record[Idx++]);
Richard Smith1fde8ec2012-09-07 02:06:42 +00002206 if (D->isExpandedParameterPack()) {
James Y Knight967eb202015-12-29 22:13:13 +00002207 TemplateParameterList **Data =
2208 D->getTrailingObjects<TemplateParameterList *>();
Richard Smith1fde8ec2012-09-07 02:06:42 +00002209 for (unsigned I = 0, N = D->getNumExpansionTemplateParameters();
2210 I != N; ++I)
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002211 Data[I] = Record.ReadTemplateParameterList(Idx);
Richard Smith1fde8ec2012-09-07 02:06:42 +00002212 } else {
2213 // Rest of TemplateTemplateParmDecl.
Richard Smith1fde8ec2012-09-07 02:06:42 +00002214 D->ParameterPack = Record[Idx++];
Richard Smith1469b912015-06-10 00:29:03 +00002215 if (Record[Idx++])
Richard Smith1469b912015-06-10 00:29:03 +00002216 D->setDefaultArgument(Reader.getContext(),
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002217 Record.ReadTemplateArgumentLoc(Idx));
Richard Smith1fde8ec2012-09-07 02:06:42 +00002218 }
Chris Lattnerca025db2010-05-07 21:43:38 +00002219}
2220
Richard Smith3f1b5d02011-05-05 21:57:07 +00002221void ASTDeclReader::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) {
2222 VisitRedeclarableTemplateDecl(D);
2223}
2224
Sebastian Redlb3298c32010-08-18 23:56:48 +00002225void ASTDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
Argyrios Kyrtzidis2d8891c2010-07-22 17:28:12 +00002226 VisitDecl(D);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002227 D->AssertExprAndFailed.setPointer(Record.ReadExpr());
Richard Smithded9c2e2012-07-11 22:37:56 +00002228 D->AssertExprAndFailed.setInt(Record[Idx++]);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002229 D->Message = cast_or_null<StringLiteral>(Record.ReadExpr());
2230 D->RParenLoc = ReadSourceLocation();
Chris Lattnerca025db2010-05-07 21:43:38 +00002231}
2232
Michael Han84324352013-02-22 17:15:32 +00002233void ASTDeclReader::VisitEmptyDecl(EmptyDecl *D) {
2234 VisitDecl(D);
2235}
2236
Mike Stump11289f42009-09-09 15:08:12 +00002237std::pair<uint64_t, uint64_t>
Sebastian Redlb3298c32010-08-18 23:56:48 +00002238ASTDeclReader::VisitDeclContext(DeclContext *DC) {
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002239 uint64_t LexicalOffset = ReadLocalOffset();
2240 uint64_t VisibleOffset = ReadLocalOffset();
Chris Lattner487412d2009-04-27 05:27:42 +00002241 return std::make_pair(LexicalOffset, VisibleOffset);
2242}
2243
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00002244template <typename T>
Richard Smith5a4737c2015-02-06 02:42:59 +00002245ASTDeclReader::RedeclarableResult
Douglas Gregor022857e2011-12-22 01:48:48 +00002246ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) {
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002247 DeclID FirstDeclID = ReadDeclID();
Richard Smith5a4737c2015-02-06 02:42:59 +00002248 Decl *MergeWith = nullptr;
Richard Smithd8a83712015-08-22 01:47:18 +00002249
Richard Smith5fc18a92015-07-12 23:43:21 +00002250 bool IsKeyDecl = ThisDeclID == FirstDeclID;
Richard Smithd8a83712015-08-22 01:47:18 +00002251 bool IsFirstLocalDecl = false;
Richard Smith5a4737c2015-02-06 02:42:59 +00002252
Richard Smithd61d4ac2015-08-22 20:13:39 +00002253 uint64_t RedeclOffset = 0;
2254
Douglas Gregor358cd442012-01-15 16:58:34 +00002255 // 0 indicates that this declaration was the only declaration of its entity,
2256 // and is used for space optimization.
Richard Smith5fc18a92015-07-12 23:43:21 +00002257 if (FirstDeclID == 0) {
Douglas Gregor074a4092011-12-19 18:19:24 +00002258 FirstDeclID = ThisDeclID;
Richard Smith5fc18a92015-07-12 23:43:21 +00002259 IsKeyDecl = true;
Richard Smithd8a83712015-08-22 01:47:18 +00002260 IsFirstLocalDecl = true;
Richard Smith5fc18a92015-07-12 23:43:21 +00002261 } else if (unsigned N = Record[Idx++]) {
Richard Smithd8a83712015-08-22 01:47:18 +00002262 // This declaration was the first local declaration, but may have imported
2263 // other declarations.
2264 IsKeyDecl = N == 1;
2265 IsFirstLocalDecl = true;
Richard Smith5fc18a92015-07-12 23:43:21 +00002266
Richard Smithfe620d22015-03-05 23:24:12 +00002267 // We have some declarations that must be before us in our redeclaration
2268 // chain. Read them now, and remember that we ought to merge with one of
2269 // them.
2270 // FIXME: Provide a known merge target to the second and subsequent such
2271 // declaration.
Richard Smithd8a83712015-08-22 01:47:18 +00002272 for (unsigned I = 0; I != N - 1; ++I)
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002273 MergeWith = ReadDecl();
Richard Smithd61d4ac2015-08-22 20:13:39 +00002274
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002275 RedeclOffset = ReadLocalOffset();
Richard Smithd8a83712015-08-22 01:47:18 +00002276 } else {
2277 // This declaration was not the first local declaration. Read the first
2278 // local declaration now, to trigger the import of other redeclarations.
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002279 (void)ReadDecl();
Richard Smith5a4737c2015-02-06 02:42:59 +00002280 }
2281
Douglas Gregor358cd442012-01-15 16:58:34 +00002282 T *FirstDecl = cast_or_null<T>(Reader.GetDecl(FirstDeclID));
2283 if (FirstDecl != D) {
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00002284 // We delay loading of the redeclaration chain to avoid deeply nested calls.
2285 // We temporarily set the first (canonical) declaration as the previous one
2286 // which is the one that matters and mark the real previous DeclID to be
2287 // loaded & attached later on.
David Blaikie7e64fd92012-05-28 19:38:42 +00002288 D->RedeclLink = Redeclarable<T>::PreviousDeclLink(FirstDecl);
Manuel Klimek093b2d42015-03-25 23:18:30 +00002289 D->First = FirstDecl->getCanonicalDecl();
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002290 }
Richard Smithd8a83712015-08-22 01:47:18 +00002291
Richard Smithd8a83712015-08-22 01:47:18 +00002292 T *DAsT = static_cast<T*>(D);
Richard Smithd8a83712015-08-22 01:47:18 +00002293
2294 // Note that we need to load local redeclarations of this decl and build a
2295 // decl chain for them. This must happen *after* we perform the preloading
2296 // above; this ensures that the redeclaration chain is built in the correct
2297 // order.
2298 if (IsFirstLocalDecl)
Richard Smithd61d4ac2015-08-22 20:13:39 +00002299 Reader.PendingDeclChains.push_back(std::make_pair(DAsT, RedeclOffset));
Richard Smithd8a83712015-08-22 01:47:18 +00002300
Alexander Shaposhnikovfbc4d682016-09-24 04:21:53 +00002301 return RedeclarableResult(MergeWith, FirstDeclID, IsKeyDecl);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00002302}
2303
Douglas Gregor2c46b5b2012-01-03 17:27:13 +00002304/// \brief Attempts to merge the given declaration (D) with another declaration
2305/// of the same entity.
2306template<typename T>
Richard Smith5e9e56a2014-07-15 03:37:06 +00002307void ASTDeclReader::mergeRedeclarable(Redeclarable<T> *DBase,
Richard Smithf17fdbd2014-04-24 02:25:27 +00002308 RedeclarableResult &Redecl,
2309 DeclID TemplatePatternID) {
Douglas Gregore097d4b2012-01-03 17:31:38 +00002310 // If modules are not available, there is no reason to perform this merge.
David Blaikiebbafb8a2012-03-11 07:00:24 +00002311 if (!Reader.getContext().getLangOpts().Modules)
Douglas Gregore097d4b2012-01-03 17:31:38 +00002312 return;
Richard Smithd55889a2013-09-09 16:55:27 +00002313
Richard Smith202850a2015-03-10 02:57:50 +00002314 // If we're not the canonical declaration, we don't need to merge.
2315 if (!DBase->isFirstDecl())
2316 return;
2317
Vassil Vassilev916d8be2016-10-06 13:18:06 +00002318 T *D = static_cast<T*>(DBase);
2319
Richard Smith5a4737c2015-02-06 02:42:59 +00002320 if (auto *Existing = Redecl.getKnownMergeTarget())
2321 // We already know of an existing declaration we should merge with.
2322 mergeRedeclarable(D, cast<T>(Existing), Redecl, TemplatePatternID);
2323 else if (FindExistingResult ExistingRes = findExisting(D))
Richard Smithd55889a2013-09-09 16:55:27 +00002324 if (T *Existing = ExistingRes)
Richard Smithf17fdbd2014-04-24 02:25:27 +00002325 mergeRedeclarable(D, Existing, Redecl, TemplatePatternID);
2326}
2327
2328/// \brief "Cast" to type T, asserting if we don't have an implicit conversion.
2329/// We use this to put code in a template that will only be valid for certain
2330/// instantiations.
2331template<typename T> static T assert_cast(T t) { return t; }
2332template<typename T> static T assert_cast(...) {
2333 llvm_unreachable("bad assert_cast");
2334}
2335
2336/// \brief Merge together the pattern declarations from two template
2337/// declarations.
2338void ASTDeclReader::mergeTemplatePattern(RedeclarableTemplateDecl *D,
2339 RedeclarableTemplateDecl *Existing,
Richard Smith5fc18a92015-07-12 23:43:21 +00002340 DeclID DsID, bool IsKeyDecl) {
Richard Smithf17fdbd2014-04-24 02:25:27 +00002341 auto *DPattern = D->getTemplatedDecl();
2342 auto *ExistingPattern = Existing->getTemplatedDecl();
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002343 RedeclarableResult Result(/*MergeWith*/ ExistingPattern,
2344 DPattern->getCanonicalDecl()->getGlobalID(),
Alexander Shaposhnikovfbc4d682016-09-24 04:21:53 +00002345 IsKeyDecl);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002346
Richard Smith547864d2014-07-11 18:22:58 +00002347 if (auto *DClass = dyn_cast<CXXRecordDecl>(DPattern)) {
2348 // Merge with any existing definition.
2349 // FIXME: This is duplicated in several places. Refactor.
2350 auto *ExistingClass =
2351 cast<CXXRecordDecl>(ExistingPattern)->getCanonicalDecl();
Richard Smithb6483992016-05-17 22:44:15 +00002352 if (auto *DDD = DClass->DefinitionData) {
2353 if (ExistingClass->DefinitionData) {
Richard Smith8a639892015-01-24 01:07:20 +00002354 MergeDefinitionData(ExistingClass, std::move(*DDD));
Richard Smith547864d2014-07-11 18:22:58 +00002355 } else {
2356 ExistingClass->DefinitionData = DClass->DefinitionData;
Richard Smith97100e32015-06-20 00:22:34 +00002357 // We may have skipped this before because we thought that DClass
2358 // was the canonical declaration.
Richard Smith7474dd922015-03-11 18:21:02 +00002359 Reader.PendingDefinitions.insert(DClass);
Richard Smith547864d2014-07-11 18:22:58 +00002360 }
2361 }
2362 DClass->DefinitionData = ExistingClass->DefinitionData;
2363
Richard Smithf17fdbd2014-04-24 02:25:27 +00002364 return mergeRedeclarable(DClass, cast<TagDecl>(ExistingPattern),
2365 Result);
Richard Smith547864d2014-07-11 18:22:58 +00002366 }
Richard Smithf17fdbd2014-04-24 02:25:27 +00002367 if (auto *DFunction = dyn_cast<FunctionDecl>(DPattern))
2368 return mergeRedeclarable(DFunction, cast<FunctionDecl>(ExistingPattern),
2369 Result);
2370 if (auto *DVar = dyn_cast<VarDecl>(DPattern))
2371 return mergeRedeclarable(DVar, cast<VarDecl>(ExistingPattern), Result);
Richard Smithf59b7352014-07-28 21:16:37 +00002372 if (auto *DAlias = dyn_cast<TypeAliasDecl>(DPattern))
2373 return mergeRedeclarable(DAlias, cast<TypedefNameDecl>(ExistingPattern),
2374 Result);
Richard Smithf17fdbd2014-04-24 02:25:27 +00002375 llvm_unreachable("merged an unknown kind of redeclarable template");
Richard Smithd55889a2013-09-09 16:55:27 +00002376}
2377
2378/// \brief Attempts to merge the given declaration (D) with another declaration
2379/// of the same entity.
2380template<typename T>
Richard Smithf17fdbd2014-04-24 02:25:27 +00002381void ASTDeclReader::mergeRedeclarable(Redeclarable<T> *DBase, T *Existing,
2382 RedeclarableResult &Redecl,
2383 DeclID TemplatePatternID) {
2384 T *D = static_cast<T*>(DBase);
Richard Smithd55889a2013-09-09 16:55:27 +00002385 T *ExistingCanon = Existing->getCanonicalDecl();
Richard Smithf17fdbd2014-04-24 02:25:27 +00002386 T *DCanon = D->getCanonicalDecl();
Richard Smithd55889a2013-09-09 16:55:27 +00002387 if (ExistingCanon != DCanon) {
Richard Smith202850a2015-03-10 02:57:50 +00002388 assert(DCanon->getGlobalID() == Redecl.getFirstID() &&
2389 "already merged this declaration");
Richard Smith5e9e56a2014-07-15 03:37:06 +00002390
Richard Smithd55889a2013-09-09 16:55:27 +00002391 // Have our redeclaration link point back at the canonical declaration
Richard Smith5e9e56a2014-07-15 03:37:06 +00002392 // of the existing declaration, so that this declaration has the
Richard Smithd55889a2013-09-09 16:55:27 +00002393 // appropriate canonical declaration.
2394 D->RedeclLink = Redeclarable<T>::PreviousDeclLink(ExistingCanon);
Manuel Klimek093b2d42015-03-25 23:18:30 +00002395 D->First = ExistingCanon;
Vassil Vassilev928c8252016-04-28 14:13:28 +00002396 ExistingCanon->Used |= D->Used;
2397 D->Used = false;
Richard Smithd55889a2013-09-09 16:55:27 +00002398
2399 // When we merge a namespace, update its pointer to the first namespace.
Richard Smith15e32fd2015-03-17 02:23:11 +00002400 // We cannot have loaded any redeclarations of this declaration yet, so
2401 // there's nothing else that needs to be updated.
Richard Smithf17fdbd2014-04-24 02:25:27 +00002402 if (auto *Namespace = dyn_cast<NamespaceDecl>(D))
Richard Smithd55889a2013-09-09 16:55:27 +00002403 Namespace->AnonOrFirstNamespaceAndInline.setPointer(
Richard Smithf17fdbd2014-04-24 02:25:27 +00002404 assert_cast<NamespaceDecl*>(ExistingCanon));
2405
2406 // When we merge a template, merge its pattern.
2407 if (auto *DTemplate = dyn_cast<RedeclarableTemplateDecl>(D))
2408 mergeTemplatePattern(
2409 DTemplate, assert_cast<RedeclarableTemplateDecl*>(ExistingCanon),
Richard Smith5fc18a92015-07-12 23:43:21 +00002410 TemplatePatternID, Redecl.isKeyDecl());
Richard Smithd55889a2013-09-09 16:55:27 +00002411
Richard Smith5fc18a92015-07-12 23:43:21 +00002412 // If this declaration is a key declaration, make a note of that.
Richard Smithd8a83712015-08-22 01:47:18 +00002413 if (Redecl.isKeyDecl())
Richard Smith5fc18a92015-07-12 23:43:21 +00002414 Reader.KeyDecls[ExistingCanon].push_back(Redecl.getFirstID());
Douglas Gregor2c46b5b2012-01-03 17:27:13 +00002415 }
2416}
2417
Richard Smith0b87e072013-10-07 08:02:11 +00002418/// \brief Attempts to merge the given declaration (D) with another declaration
2419/// of the same entity, for the case where the entity is not actually
2420/// redeclarable. This happens, for instance, when merging the fields of
2421/// identical class definitions from two different modules.
2422template<typename T>
2423void ASTDeclReader::mergeMergeable(Mergeable<T> *D) {
2424 // If modules are not available, there is no reason to perform this merge.
2425 if (!Reader.getContext().getLangOpts().Modules)
2426 return;
2427
Richard Smith01a73372013-10-15 22:02:41 +00002428 // ODR-based merging is only performed in C++. In C, identically-named things
2429 // in different translation units are not redeclarations (but may still have
2430 // compatible types).
2431 if (!Reader.getContext().getLangOpts().CPlusPlus)
2432 return;
2433
Richard Smith0b87e072013-10-07 08:02:11 +00002434 if (FindExistingResult ExistingRes = findExisting(static_cast<T*>(D)))
2435 if (T *Existing = ExistingRes)
2436 Reader.Context.setPrimaryMergedDecl(static_cast<T*>(D),
2437 Existing->getCanonicalDecl());
2438}
2439
Alexey Bataeva769e072013-03-22 06:34:35 +00002440void ASTDeclReader::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) {
2441 VisitDecl(D);
2442 unsigned NumVars = D->varlist_size();
Alexey Bataev6f6f3b42013-05-13 04:18:18 +00002443 SmallVector<Expr *, 16> Vars;
Alexey Bataeva769e072013-03-22 06:34:35 +00002444 Vars.reserve(NumVars);
2445 for (unsigned i = 0; i != NumVars; ++i) {
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002446 Vars.push_back(Record.ReadExpr());
Alexey Bataeva769e072013-03-22 06:34:35 +00002447 }
2448 D->setVars(Vars);
2449}
2450
Alexey Bataev94a4f0c2016-03-03 05:21:39 +00002451void ASTDeclReader::VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D) {
Alexey Bataevc5b1d322016-03-04 09:22:22 +00002452 VisitValueDecl(D);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002453 D->setLocation(ReadSourceLocation());
2454 D->setCombiner(Record.ReadExpr());
2455 D->setInitializer(Record.ReadExpr());
2456 D->PrevDeclInScope = ReadDeclID();
Alexey Bataev94a4f0c2016-03-03 05:21:39 +00002457}
2458
Alexey Bataev4244be22016-02-11 05:35:55 +00002459void ASTDeclReader::VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D) {
Alexey Bataev90c228f2016-02-08 09:29:13 +00002460 VisitVarDecl(D);
2461}
2462
Chris Lattner487412d2009-04-27 05:27:42 +00002463//===----------------------------------------------------------------------===//
Chris Lattner8f63ab52009-04-27 06:01:06 +00002464// Attribute Reading
Chris Lattner487412d2009-04-27 05:27:42 +00002465//===----------------------------------------------------------------------===//
2466
Chris Lattner8f63ab52009-04-27 06:01:06 +00002467/// \brief Reads attributes from the current stream position.
Douglas Gregorde3ef502011-11-30 23:21:26 +00002468void ASTReader::ReadAttributes(ModuleFile &F, AttrVec &Attrs,
Argyrios Kyrtzidis9beef8e2010-10-18 19:20:11 +00002469 const RecordData &Record, unsigned &Idx) {
2470 for (unsigned i = 0, e = Record[Idx++]; i != e; ++i) {
Craig Toppera13603a2014-05-22 05:54:18 +00002471 Attr *New = nullptr;
Alexis Hunt344393e2010-06-16 23:43:53 +00002472 attr::Kind Kind = (attr::Kind)Record[Idx++];
Argyrios Kyrtzidis309b4c42011-09-13 16:05:58 +00002473 SourceRange Range = ReadSourceRange(F, Record, Idx);
Chris Lattner8f63ab52009-04-27 06:01:06 +00002474
Alexis Huntdcfba7b2010-08-18 23:23:40 +00002475#include "clang/Serialization/AttrPCHRead.inc"
Chris Lattner8f63ab52009-04-27 06:01:06 +00002476
2477 assert(New && "Unable to decode attribute?");
Alexis Huntdcfba7b2010-08-18 23:23:40 +00002478 Attrs.push_back(New);
Chris Lattner8f63ab52009-04-27 06:01:06 +00002479 }
Chris Lattner8f63ab52009-04-27 06:01:06 +00002480}
2481
2482//===----------------------------------------------------------------------===//
Sebastian Redl2c499f62010-08-18 23:56:43 +00002483// ASTReader Implementation
Chris Lattner8f63ab52009-04-27 06:01:06 +00002484//===----------------------------------------------------------------------===//
Chris Lattner487412d2009-04-27 05:27:42 +00002485
2486/// \brief Note that we have loaded the declaration with the given
2487/// Index.
Mike Stump11289f42009-09-09 15:08:12 +00002488///
Chris Lattner487412d2009-04-27 05:27:42 +00002489/// This routine notes that this declaration has already been loaded,
2490/// so that future GetDecl calls will return this declaration rather
2491/// than trying to load a new declaration.
Sebastian Redl2c499f62010-08-18 23:56:43 +00002492inline void ASTReader::LoadedDecl(unsigned Index, Decl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +00002493 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
2494 DeclsLoaded[Index] = D;
2495}
2496
2497
2498/// \brief Determine whether the consumer will be interested in seeing
2499/// this declaration (via HandleTopLevelDecl).
2500///
2501/// This routine should return true for anything that might affect
2502/// code generation, e.g., inline function definitions, Objective-C
2503/// declarations with metadata, etc.
Richard Smithdc1f0422016-07-20 19:10:16 +00002504static bool isConsumerInterestedIn(ASTContext &Ctx, Decl *D, bool HasBody) {
Argyrios Kyrtzidisa98e8612011-09-13 21:35:00 +00002505 // An ObjCMethodDecl is never considered as "interesting" because its
2506 // implementation container always is.
2507
Richard Smithdc1f0422016-07-20 19:10:16 +00002508 // An ImportDecl or VarDecl imported from a module will get emitted when
2509 // we import the relevant module.
2510 if ((isa<ImportDecl>(D) || isa<VarDecl>(D)) && Ctx.DeclMustBeEmitted(D) &&
2511 D->getImportedOwningModule())
2512 return false;
2513
Douglas Gregor87d81242011-09-10 00:22:34 +00002514 if (isa<FileScopeAsmDecl>(D) ||
2515 isa<ObjCProtocolDecl>(D) ||
Ben Langmuir332aafe2014-01-31 01:06:56 +00002516 isa<ObjCImplDecl>(D) ||
Alexey Bataev97720002014-11-11 04:05:39 +00002517 isa<ImportDecl>(D) ||
Nico Weber66220292016-03-02 17:28:48 +00002518 isa<PragmaCommentDecl>(D) ||
Alexey Bataevc5b1d322016-03-04 09:22:22 +00002519 isa<PragmaDetectMismatchDecl>(D))
Daniel Dunbar865c2a72009-09-17 03:06:44 +00002520 return true;
Alexey Bataevc5b1d322016-03-04 09:22:22 +00002521 if (isa<OMPThreadPrivateDecl>(D) || isa<OMPDeclareReductionDecl>(D))
2522 return !D->getDeclContext()->isFunctionOrMethod();
Chris Lattner487412d2009-04-27 05:27:42 +00002523 if (VarDecl *Var = dyn_cast<VarDecl>(D))
Argyrios Kyrtzidis4ba81b22010-08-05 09:47:59 +00002524 return Var->isFileVarDecl() &&
2525 Var->isThisDeclarationADefinition() == VarDecl::Definition;
Chris Lattner487412d2009-04-27 05:27:42 +00002526 if (FunctionDecl *Func = dyn_cast<FunctionDecl>(D))
Douglas Gregora6017bb2012-10-09 17:21:28 +00002527 return Func->doesThisDeclarationHaveABody() || HasBody;
Douglas Gregor87d81242011-09-10 00:22:34 +00002528
2529 return false;
Chris Lattner487412d2009-04-27 05:27:42 +00002530}
2531
Douglas Gregor047d2ef2011-07-20 00:27:43 +00002532/// \brief Get the correct cursor and offset for loading a declaration.
Sebastian Redl2c499f62010-08-18 23:56:43 +00002533ASTReader::RecordLocation
Richard Smithcb34bd32016-03-27 07:28:06 +00002534ASTReader::DeclCursorForID(DeclID ID, SourceLocation &Loc) {
Douglas Gregor047d2ef2011-07-20 00:27:43 +00002535 GlobalDeclMapType::iterator I = GlobalDeclMap.find(ID);
2536 assert(I != GlobalDeclMap.end() && "Corrupted global declaration map");
Douglas Gregorde3ef502011-11-30 23:21:26 +00002537 ModuleFile *M = I->second;
Richard Smith34da7512016-03-27 05:52:25 +00002538 const DeclOffset &DOffs =
2539 M->DeclOffsets[ID - M->BaseDeclID - NUM_PREDEF_DECL_IDS];
Richard Smithcb34bd32016-03-27 07:28:06 +00002540 Loc = TranslateSourceLocation(*M, DOffs.getLocation());
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +00002541 return RecordLocation(M, DOffs.BitOffset);
Sebastian Redl34627792010-07-20 22:46:15 +00002542}
2543
Douglas Gregord32f0352011-07-22 06:10:01 +00002544ASTReader::RecordLocation ASTReader::getLocalBitOffset(uint64_t GlobalOffset) {
Douglas Gregorde3ef502011-11-30 23:21:26 +00002545 ContinuousRangeMap<uint64_t, ModuleFile*, 4>::iterator I
Douglas Gregord32f0352011-07-22 06:10:01 +00002546 = GlobalBitOffsetsMap.find(GlobalOffset);
2547
2548 assert(I != GlobalBitOffsetsMap.end() && "Corrupted global bit offsets map");
2549 return RecordLocation(I->second, GlobalOffset - I->second->GlobalBitOffset);
2550}
2551
Douglas Gregorde3ef502011-11-30 23:21:26 +00002552uint64_t ASTReader::getGlobalBitOffset(ModuleFile &M, uint32_t LocalOffset) {
Douglas Gregorc27b2872011-08-04 00:01:48 +00002553 return LocalOffset + M.GlobalBitOffset;
2554}
2555
Richard Smithbf78e642013-06-24 22:51:00 +00002556static bool isSameTemplateParameterList(const TemplateParameterList *X,
2557 const TemplateParameterList *Y);
2558
2559/// \brief Determine whether two template parameters are similar enough
2560/// that they may be used in declarations of the same template.
2561static bool isSameTemplateParameter(const NamedDecl *X,
2562 const NamedDecl *Y) {
2563 if (X->getKind() != Y->getKind())
2564 return false;
2565
2566 if (const TemplateTypeParmDecl *TX = dyn_cast<TemplateTypeParmDecl>(X)) {
2567 const TemplateTypeParmDecl *TY = cast<TemplateTypeParmDecl>(Y);
2568 return TX->isParameterPack() == TY->isParameterPack();
2569 }
2570
2571 if (const NonTypeTemplateParmDecl *TX = dyn_cast<NonTypeTemplateParmDecl>(X)) {
2572 const NonTypeTemplateParmDecl *TY = cast<NonTypeTemplateParmDecl>(Y);
2573 return TX->isParameterPack() == TY->isParameterPack() &&
2574 TX->getASTContext().hasSameType(TX->getType(), TY->getType());
2575 }
2576
2577 const TemplateTemplateParmDecl *TX = cast<TemplateTemplateParmDecl>(X);
2578 const TemplateTemplateParmDecl *TY = cast<TemplateTemplateParmDecl>(Y);
2579 return TX->isParameterPack() == TY->isParameterPack() &&
2580 isSameTemplateParameterList(TX->getTemplateParameters(),
2581 TY->getTemplateParameters());
2582}
2583
Richard Smith32952e12014-10-14 02:00:47 +00002584static NamespaceDecl *getNamespace(const NestedNameSpecifier *X) {
2585 if (auto *NS = X->getAsNamespace())
2586 return NS;
2587 if (auto *NAS = X->getAsNamespaceAlias())
2588 return NAS->getNamespace();
2589 return nullptr;
2590}
2591
2592static bool isSameQualifier(const NestedNameSpecifier *X,
2593 const NestedNameSpecifier *Y) {
2594 if (auto *NSX = getNamespace(X)) {
2595 auto *NSY = getNamespace(Y);
2596 if (!NSY || NSX->getCanonicalDecl() != NSY->getCanonicalDecl())
2597 return false;
2598 } else if (X->getKind() != Y->getKind())
2599 return false;
2600
2601 // FIXME: For namespaces and types, we're permitted to check that the entity
2602 // is named via the same tokens. We should probably do so.
2603 switch (X->getKind()) {
2604 case NestedNameSpecifier::Identifier:
2605 if (X->getAsIdentifier() != Y->getAsIdentifier())
2606 return false;
2607 break;
2608 case NestedNameSpecifier::Namespace:
2609 case NestedNameSpecifier::NamespaceAlias:
2610 // We've already checked that we named the same namespace.
2611 break;
2612 case NestedNameSpecifier::TypeSpec:
2613 case NestedNameSpecifier::TypeSpecWithTemplate:
2614 if (X->getAsType()->getCanonicalTypeInternal() !=
2615 Y->getAsType()->getCanonicalTypeInternal())
2616 return false;
2617 break;
2618 case NestedNameSpecifier::Global:
2619 case NestedNameSpecifier::Super:
2620 return true;
2621 }
2622
2623 // Recurse into earlier portion of NNS, if any.
2624 auto *PX = X->getPrefix();
2625 auto *PY = Y->getPrefix();
2626 if (PX && PY)
2627 return isSameQualifier(PX, PY);
2628 return !PX && !PY;
2629}
2630
Richard Smithbf78e642013-06-24 22:51:00 +00002631/// \brief Determine whether two template parameter lists are similar enough
2632/// that they may be used in declarations of the same template.
2633static bool isSameTemplateParameterList(const TemplateParameterList *X,
2634 const TemplateParameterList *Y) {
2635 if (X->size() != Y->size())
2636 return false;
2637
2638 for (unsigned I = 0, N = X->size(); I != N; ++I)
2639 if (!isSameTemplateParameter(X->getParam(I), Y->getParam(I)))
2640 return false;
2641
2642 return true;
2643}
2644
Douglas Gregor022857e2011-12-22 01:48:48 +00002645/// \brief Determine whether the two declarations refer to the same entity.
2646static bool isSameEntity(NamedDecl *X, NamedDecl *Y) {
2647 assert(X->getDeclName() == Y->getDeclName() && "Declaration name mismatch!");
Richard Smithf4634362014-09-03 23:11:22 +00002648
Douglas Gregor022857e2011-12-22 01:48:48 +00002649 if (X == Y)
2650 return true;
Richard Smithf4634362014-09-03 23:11:22 +00002651
Douglas Gregor022857e2011-12-22 01:48:48 +00002652 // Must be in the same context.
2653 if (!X->getDeclContext()->getRedeclContext()->Equals(
2654 Y->getDeclContext()->getRedeclContext()))
2655 return false;
Douglas Gregor9b7b3912012-01-04 16:44:10 +00002656
2657 // Two typedefs refer to the same entity if they have the same underlying
2658 // type.
2659 if (TypedefNameDecl *TypedefX = dyn_cast<TypedefNameDecl>(X))
2660 if (TypedefNameDecl *TypedefY = dyn_cast<TypedefNameDecl>(Y))
2661 return X->getASTContext().hasSameType(TypedefX->getUnderlyingType(),
2662 TypedefY->getUnderlyingType());
Richard Smithf4634362014-09-03 23:11:22 +00002663
Douglas Gregor9b7b3912012-01-04 16:44:10 +00002664 // Must have the same kind.
2665 if (X->getKind() != Y->getKind())
2666 return false;
Richard Smithf4634362014-09-03 23:11:22 +00002667
Douglas Gregorda389302012-01-01 21:47:52 +00002668 // Objective-C classes and protocols with the same name always match.
2669 if (isa<ObjCInterfaceDecl>(X) || isa<ObjCProtocolDecl>(X))
Douglas Gregor022857e2011-12-22 01:48:48 +00002670 return true;
Richard Smith1d209d02013-05-23 01:49:11 +00002671
2672 if (isa<ClassTemplateSpecializationDecl>(X)) {
Richard Smithd55889a2013-09-09 16:55:27 +00002673 // No need to handle these here: we merge them when adding them to the
2674 // template.
Richard Smith1d209d02013-05-23 01:49:11 +00002675 return false;
2676 }
Richard Smithd55889a2013-09-09 16:55:27 +00002677
Douglas Gregor2009cee2012-01-03 22:46:00 +00002678 // Compatible tags match.
Joao Matose9a3ed42012-08-31 22:18:20 +00002679 if (TagDecl *TagX = dyn_cast<TagDecl>(X)) {
2680 TagDecl *TagY = cast<TagDecl>(Y);
2681 return (TagX->getTagKind() == TagY->getTagKind()) ||
2682 ((TagX->getTagKind() == TTK_Struct || TagX->getTagKind() == TTK_Class ||
2683 TagX->getTagKind() == TTK_Interface) &&
2684 (TagY->getTagKind() == TTK_Struct || TagY->getTagKind() == TTK_Class ||
2685 TagY->getTagKind() == TTK_Interface));
2686 }
Richard Smith8f8f05c2013-06-24 04:45:28 +00002687
Joao Matose9a3ed42012-08-31 22:18:20 +00002688 // Functions with the same type and linkage match.
Richard Smithf4634362014-09-03 23:11:22 +00002689 // FIXME: This needs to cope with merging of prototyped/non-prototyped
2690 // functions, etc.
Douglas Gregorb2585692012-01-04 17:13:46 +00002691 if (FunctionDecl *FuncX = dyn_cast<FunctionDecl>(X)) {
2692 FunctionDecl *FuncY = cast<FunctionDecl>(Y);
Richard Smith5179eb72016-06-28 19:03:57 +00002693 if (CXXConstructorDecl *CtorX = dyn_cast<CXXConstructorDecl>(X)) {
2694 CXXConstructorDecl *CtorY = cast<CXXConstructorDecl>(Y);
2695 if (CtorX->getInheritedConstructor() &&
2696 !isSameEntity(CtorX->getInheritedConstructor().getConstructor(),
2697 CtorY->getInheritedConstructor().getConstructor()))
2698 return false;
2699 }
Rafael Espindola3ae00052013-05-13 00:12:11 +00002700 return (FuncX->getLinkageInternal() == FuncY->getLinkageInternal()) &&
Douglas Gregorb2585692012-01-04 17:13:46 +00002701 FuncX->getASTContext().hasSameType(FuncX->getType(), FuncY->getType());
2702 }
Axel Naumann866ba3e2012-10-01 09:18:00 +00002703
Douglas Gregorb8c6f1e2012-01-04 17:21:36 +00002704 // Variables with the same type and linkage match.
2705 if (VarDecl *VarX = dyn_cast<VarDecl>(X)) {
2706 VarDecl *VarY = cast<VarDecl>(Y);
Yaron Kerene94da642016-01-22 19:03:27 +00002707 if (VarX->getLinkageInternal() == VarY->getLinkageInternal()) {
2708 ASTContext &C = VarX->getASTContext();
2709 if (C.hasSameType(VarX->getType(), VarY->getType()))
2710 return true;
2711
2712 // We can get decls with different types on the redecl chain. Eg.
2713 // template <typename T> struct S { static T Var[]; }; // #1
2714 // template <typename T> T S<T>::Var[sizeof(T)]; // #2
2715 // Only? happens when completing an incomplete array type. In this case
Vassil Vassilev4d75e8d2016-02-28 19:08:24 +00002716 // when comparing #1 and #2 we should go through their element type.
Yaron Kerene94da642016-01-22 19:03:27 +00002717 const ArrayType *VarXTy = C.getAsArrayType(VarX->getType());
2718 const ArrayType *VarYTy = C.getAsArrayType(VarY->getType());
2719 if (!VarXTy || !VarYTy)
2720 return false;
2721 if (VarXTy->isIncompleteArrayType() || VarYTy->isIncompleteArrayType())
2722 return C.hasSameType(VarXTy->getElementType(), VarYTy->getElementType());
2723 }
2724 return false;
Douglas Gregorb8c6f1e2012-01-04 17:21:36 +00002725 }
Richard Smith8f8f05c2013-06-24 04:45:28 +00002726
Douglas Gregorcfe7dc62012-01-09 17:30:44 +00002727 // Namespaces with the same name and inlinedness match.
2728 if (NamespaceDecl *NamespaceX = dyn_cast<NamespaceDecl>(X)) {
2729 NamespaceDecl *NamespaceY = cast<NamespaceDecl>(Y);
2730 return NamespaceX->isInline() == NamespaceY->isInline();
2731 }
Axel Naumann866ba3e2012-10-01 09:18:00 +00002732
Richard Smith8f8f05c2013-06-24 04:45:28 +00002733 // Identical template names and kinds match if their template parameter lists
2734 // and patterns match.
2735 if (TemplateDecl *TemplateX = dyn_cast<TemplateDecl>(X)) {
Richard Smithbf78e642013-06-24 22:51:00 +00002736 TemplateDecl *TemplateY = cast<TemplateDecl>(Y);
Richard Smith8f8f05c2013-06-24 04:45:28 +00002737 return isSameEntity(TemplateX->getTemplatedDecl(),
Richard Smithbf78e642013-06-24 22:51:00 +00002738 TemplateY->getTemplatedDecl()) &&
2739 isSameTemplateParameterList(TemplateX->getTemplateParameters(),
2740 TemplateY->getTemplateParameters());
Richard Smith8f8f05c2013-06-24 04:45:28 +00002741 }
Axel Naumann866ba3e2012-10-01 09:18:00 +00002742
Richard Smith0b87e072013-10-07 08:02:11 +00002743 // Fields with the same name and the same type match.
2744 if (FieldDecl *FDX = dyn_cast<FieldDecl>(X)) {
2745 FieldDecl *FDY = cast<FieldDecl>(Y);
Richard Smith01a73372013-10-15 22:02:41 +00002746 // FIXME: Also check the bitwidth is odr-equivalent, if any.
Richard Smith0b87e072013-10-07 08:02:11 +00002747 return X->getASTContext().hasSameType(FDX->getType(), FDY->getType());
2748 }
2749
Richard Smith8cbd8952015-08-04 02:05:09 +00002750 // Indirect fields with the same target field match.
2751 if (auto *IFDX = dyn_cast<IndirectFieldDecl>(X)) {
2752 auto *IFDY = cast<IndirectFieldDecl>(Y);
2753 return IFDX->getAnonField()->getCanonicalDecl() ==
2754 IFDY->getAnonField()->getCanonicalDecl();
2755 }
2756
Richard Smith01a73372013-10-15 22:02:41 +00002757 // Enumerators with the same name match.
2758 if (isa<EnumConstantDecl>(X))
2759 // FIXME: Also check the value is odr-equivalent.
2760 return true;
2761
Richard Smithfd8634a2013-10-23 02:17:46 +00002762 // Using shadow declarations with the same target match.
2763 if (UsingShadowDecl *USX = dyn_cast<UsingShadowDecl>(X)) {
2764 UsingShadowDecl *USY = cast<UsingShadowDecl>(Y);
2765 return USX->getTargetDecl() == USY->getTargetDecl();
2766 }
2767
Richard Smith32952e12014-10-14 02:00:47 +00002768 // Using declarations with the same qualifier match. (We already know that
2769 // the name matches.)
2770 if (auto *UX = dyn_cast<UsingDecl>(X)) {
2771 auto *UY = cast<UsingDecl>(Y);
2772 return isSameQualifier(UX->getQualifier(), UY->getQualifier()) &&
2773 UX->hasTypename() == UY->hasTypename() &&
2774 UX->isAccessDeclaration() == UY->isAccessDeclaration();
2775 }
2776 if (auto *UX = dyn_cast<UnresolvedUsingValueDecl>(X)) {
2777 auto *UY = cast<UnresolvedUsingValueDecl>(Y);
2778 return isSameQualifier(UX->getQualifier(), UY->getQualifier()) &&
2779 UX->isAccessDeclaration() == UY->isAccessDeclaration();
2780 }
2781 if (auto *UX = dyn_cast<UnresolvedUsingTypenameDecl>(X))
2782 return isSameQualifier(
2783 UX->getQualifier(),
2784 cast<UnresolvedUsingTypenameDecl>(Y)->getQualifier());
2785
Richard Smithf4634362014-09-03 23:11:22 +00002786 // Namespace alias definitions with the same target match.
2787 if (auto *NAX = dyn_cast<NamespaceAliasDecl>(X)) {
2788 auto *NAY = cast<NamespaceAliasDecl>(Y);
2789 return NAX->getNamespace()->Equals(NAY->getNamespace());
2790 }
2791
Douglas Gregor022857e2011-12-22 01:48:48 +00002792 return false;
2793}
2794
Richard Smithd55889a2013-09-09 16:55:27 +00002795/// Find the context in which we should search for previous declarations when
2796/// looking for declarations to merge.
Richard Smith8a639892015-01-24 01:07:20 +00002797DeclContext *ASTDeclReader::getPrimaryContextForMerging(ASTReader &Reader,
2798 DeclContext *DC) {
Richard Smithd55889a2013-09-09 16:55:27 +00002799 if (NamespaceDecl *ND = dyn_cast<NamespaceDecl>(DC))
2800 return ND->getOriginalNamespace();
2801
Richard Smith8a639892015-01-24 01:07:20 +00002802 if (CXXRecordDecl *RD = dyn_cast<CXXRecordDecl>(DC)) {
2803 // Try to dig out the definition.
Richard Smithb6483992016-05-17 22:44:15 +00002804 auto *DD = RD->DefinitionData;
Richard Smith8a639892015-01-24 01:07:20 +00002805 if (!DD)
Richard Smithb6483992016-05-17 22:44:15 +00002806 DD = RD->getCanonicalDecl()->DefinitionData;
Richard Smith8a639892015-01-24 01:07:20 +00002807
2808 // If there's no definition yet, then DC's definition is added by an update
2809 // record, but we've not yet loaded that update record. In this case, we
2810 // commit to DC being the canonical definition now, and will fix this when
2811 // we load the update record.
2812 if (!DD) {
2813 DD = new (Reader.Context) struct CXXRecordDecl::DefinitionData(RD);
2814 RD->IsCompleteDefinition = true;
2815 RD->DefinitionData = DD;
2816 RD->getCanonicalDecl()->DefinitionData = DD;
2817
2818 // Track that we did this horrible thing so that we can fix it later.
Richard Smith2a9e5c52015-02-03 03:32:14 +00002819 Reader.PendingFakeDefinitionData.insert(
2820 std::make_pair(DD, ASTReader::PendingFakeDefinitionKind::Fake));
Richard Smith8a639892015-01-24 01:07:20 +00002821 }
2822
2823 return DD->Definition;
2824 }
Richard Smithd55889a2013-09-09 16:55:27 +00002825
Richard Smith01a73372013-10-15 22:02:41 +00002826 if (EnumDecl *ED = dyn_cast<EnumDecl>(DC))
Craig Toppera13603a2014-05-22 05:54:18 +00002827 return ED->getASTContext().getLangOpts().CPlusPlus? ED->getDefinition()
2828 : nullptr;
Richard Smith01a73372013-10-15 22:02:41 +00002829
Richard Smith4eca9b92015-02-04 23:37:59 +00002830 // We can see the TU here only if we have no Sema object. In that case,
2831 // there's no TU scope to look in, so using the DC alone is sufficient.
2832 if (auto *TU = dyn_cast<TranslationUnitDecl>(DC))
2833 return TU;
2834
Craig Toppera13603a2014-05-22 05:54:18 +00002835 return nullptr;
Richard Smithd55889a2013-09-09 16:55:27 +00002836}
2837
Douglas Gregor022857e2011-12-22 01:48:48 +00002838ASTDeclReader::FindExistingResult::~FindExistingResult() {
Richard Smithf1f4bc22015-01-22 02:21:23 +00002839 // Record that we had a typedef name for linkage whether or not we merge
2840 // with that declaration.
2841 if (TypedefNameForLinkage) {
2842 DeclContext *DC = New->getDeclContext()->getRedeclContext();
2843 Reader.ImportedTypedefNamesForLinkage.insert(
2844 std::make_pair(std::make_pair(DC, TypedefNameForLinkage), New));
2845 return;
2846 }
2847
Douglas Gregor9b47f942012-01-09 17:38:47 +00002848 if (!AddResult || Existing)
Douglas Gregor022857e2011-12-22 01:48:48 +00002849 return;
Richard Smith95d99302013-07-13 02:00:19 +00002850
Richard Smith70d58502014-08-30 00:04:23 +00002851 DeclarationName Name = New->getDeclName();
Richard Smith95d99302013-07-13 02:00:19 +00002852 DeclContext *DC = New->getDeclContext()->getRedeclContext();
Richard Smith2b560572015-02-07 03:11:11 +00002853 if (needsAnonymousDeclarationNumber(New)) {
Richard Smithd08aeb62014-08-28 01:33:39 +00002854 setAnonymousDeclForMerging(Reader, New->getLexicalDeclContext(),
2855 AnonymousDeclNumber, New);
Richard Smith10379092016-05-06 23:14:07 +00002856 } else if (DC->isTranslationUnit() &&
Richard Smith9e2341d2015-03-23 03:25:59 +00002857 !Reader.getContext().getLangOpts().CPlusPlus) {
Richard Smith10379092016-05-06 23:14:07 +00002858 if (Reader.getIdResolver().tryAddTopLevelDecl(New, Name))
Richard Smith9e2341d2015-03-23 03:25:59 +00002859 Reader.PendingFakeLookupResults[Name.getAsIdentifierInfo()]
2860 .push_back(New);
Richard Smith8a639892015-01-24 01:07:20 +00002861 } else if (DeclContext *MergeDC = getPrimaryContextForMerging(Reader, DC)) {
Richard Smith95d99302013-07-13 02:00:19 +00002862 // Add the declaration to its redeclaration context so later merging
2863 // lookups will find it.
Richard Smithd55889a2013-09-09 16:55:27 +00002864 MergeDC->makeDeclVisibleInContextImpl(New, /*Internal*/true);
Douglas Gregor022857e2011-12-22 01:48:48 +00002865 }
2866}
2867
Richard Smith88ebade2014-08-23 01:45:27 +00002868/// Find the declaration that should be merged into, given the declaration found
2869/// by name lookup. If we're merging an anonymous declaration within a typedef,
2870/// we need a matching typedef, and we merge with the type inside it.
2871static NamedDecl *getDeclForMerging(NamedDecl *Found,
2872 bool IsTypedefNameForLinkage) {
2873 if (!IsTypedefNameForLinkage)
2874 return Found;
2875
2876 // If we found a typedef declaration that gives a name to some other
2877 // declaration, then we want that inner declaration. Declarations from
2878 // AST files are handled via ImportedTypedefNamesForLinkage.
Richard Smitha5230222015-03-27 01:37:43 +00002879 if (Found->isFromASTFile())
Hans Wennborgdcfba332015-10-06 23:40:43 +00002880 return nullptr;
Richard Smitha5230222015-03-27 01:37:43 +00002881
2882 if (auto *TND = dyn_cast<TypedefNameDecl>(Found))
Richard Smith3fb1a852016-08-30 19:13:18 +00002883 return TND->getAnonDeclWithTypedefName(/*AnyRedecl*/true);
Richard Smith88ebade2014-08-23 01:45:27 +00002884
Hans Wennborgdcfba332015-10-06 23:40:43 +00002885 return nullptr;
Richard Smith88ebade2014-08-23 01:45:27 +00002886}
2887
Richard Smithd08aeb62014-08-28 01:33:39 +00002888NamedDecl *ASTDeclReader::getAnonymousDeclForMerging(ASTReader &Reader,
2889 DeclContext *DC,
2890 unsigned Index) {
2891 // If the lexical context has been merged, look into the now-canonical
2892 // definition.
2893 if (auto *Merged = Reader.MergedDeclContexts.lookup(DC))
2894 DC = Merged;
2895
2896 // If we've seen this before, return the canonical declaration.
2897 auto &Previous = Reader.AnonymousDeclarationsForMerging[DC];
2898 if (Index < Previous.size() && Previous[Index])
2899 return Previous[Index];
2900
2901 // If this is the first time, but we have parsed a declaration of the context,
2902 // build the anonymous declaration list from the parsed declaration.
2903 if (!cast<Decl>(DC)->isFromASTFile()) {
Richard Smith2b560572015-02-07 03:11:11 +00002904 numberAnonymousDeclsWithin(DC, [&](NamedDecl *ND, unsigned Number) {
2905 if (Previous.size() == Number)
Richard Smithd08aeb62014-08-28 01:33:39 +00002906 Previous.push_back(cast<NamedDecl>(ND->getCanonicalDecl()));
2907 else
Richard Smith2b560572015-02-07 03:11:11 +00002908 Previous[Number] = cast<NamedDecl>(ND->getCanonicalDecl());
2909 });
Richard Smithd08aeb62014-08-28 01:33:39 +00002910 }
2911
2912 return Index < Previous.size() ? Previous[Index] : nullptr;
2913}
2914
2915void ASTDeclReader::setAnonymousDeclForMerging(ASTReader &Reader,
2916 DeclContext *DC, unsigned Index,
2917 NamedDecl *D) {
2918 if (auto *Merged = Reader.MergedDeclContexts.lookup(DC))
2919 DC = Merged;
2920
2921 auto &Previous = Reader.AnonymousDeclarationsForMerging[DC];
2922 if (Index >= Previous.size())
2923 Previous.resize(Index + 1);
2924 if (!Previous[Index])
2925 Previous[Index] = D;
2926}
2927
Douglas Gregor022857e2011-12-22 01:48:48 +00002928ASTDeclReader::FindExistingResult ASTDeclReader::findExisting(NamedDecl *D) {
Richard Smith70d58502014-08-30 00:04:23 +00002929 DeclarationName Name = TypedefNameForLinkage ? TypedefNameForLinkage
2930 : D->getDeclName();
Richard Smith88ebade2014-08-23 01:45:27 +00002931
Richard Smithd08aeb62014-08-28 01:33:39 +00002932 if (!Name && !needsAnonymousDeclarationNumber(D)) {
2933 // Don't bother trying to find unnamed declarations that are in
2934 // unmergeable contexts.
Richard Smith70d58502014-08-30 00:04:23 +00002935 FindExistingResult Result(Reader, D, /*Existing=*/nullptr,
2936 AnonymousDeclNumber, TypedefNameForLinkage);
Douglas Gregor2009cee2012-01-03 22:46:00 +00002937 Result.suppress();
2938 return Result;
2939 }
Richard Smith95d99302013-07-13 02:00:19 +00002940
Douglas Gregor022857e2011-12-22 01:48:48 +00002941 DeclContext *DC = D->getDeclContext()->getRedeclContext();
Richard Smith70d58502014-08-30 00:04:23 +00002942 if (TypedefNameForLinkage) {
Richard Smith88ebade2014-08-23 01:45:27 +00002943 auto It = Reader.ImportedTypedefNamesForLinkage.find(
Richard Smith70d58502014-08-30 00:04:23 +00002944 std::make_pair(DC, TypedefNameForLinkage));
Richard Smith88ebade2014-08-23 01:45:27 +00002945 if (It != Reader.ImportedTypedefNamesForLinkage.end())
2946 if (isSameEntity(It->second, D))
Richard Smith70d58502014-08-30 00:04:23 +00002947 return FindExistingResult(Reader, D, It->second, AnonymousDeclNumber,
2948 TypedefNameForLinkage);
Richard Smith88ebade2014-08-23 01:45:27 +00002949 // Go on to check in other places in case an existing typedef name
2950 // was not imported.
2951 }
Richard Smithd08aeb62014-08-28 01:33:39 +00002952
Richard Smith2b560572015-02-07 03:11:11 +00002953 if (needsAnonymousDeclarationNumber(D)) {
Richard Smithd08aeb62014-08-28 01:33:39 +00002954 // This is an anonymous declaration that we may need to merge. Look it up
2955 // in its context by number.
Richard Smithd08aeb62014-08-28 01:33:39 +00002956 if (auto *Existing = getAnonymousDeclForMerging(
2957 Reader, D->getLexicalDeclContext(), AnonymousDeclNumber))
2958 if (isSameEntity(Existing, D))
Richard Smith70d58502014-08-30 00:04:23 +00002959 return FindExistingResult(Reader, D, Existing, AnonymousDeclNumber,
2960 TypedefNameForLinkage);
Richard Smith10379092016-05-06 23:14:07 +00002961 } else if (DC->isTranslationUnit() &&
Richard Smith9e2341d2015-03-23 03:25:59 +00002962 !Reader.getContext().getLangOpts().CPlusPlus) {
Richard Smith10379092016-05-06 23:14:07 +00002963 IdentifierResolver &IdResolver = Reader.getIdResolver();
Douglas Gregor6168bd22013-02-18 15:53:43 +00002964
2965 // Temporarily consider the identifier to be up-to-date. We don't want to
2966 // cause additional lookups here.
2967 class UpToDateIdentifierRAII {
2968 IdentifierInfo *II;
2969 bool WasOutToDate;
2970
2971 public:
2972 explicit UpToDateIdentifierRAII(IdentifierInfo *II)
2973 : II(II), WasOutToDate(false)
2974 {
2975 if (II) {
2976 WasOutToDate = II->isOutOfDate();
2977 if (WasOutToDate)
2978 II->setOutOfDate(false);
2979 }
2980 }
2981
2982 ~UpToDateIdentifierRAII() {
2983 if (WasOutToDate)
2984 II->setOutOfDate(true);
2985 }
2986 } UpToDate(Name.getAsIdentifierInfo());
2987
Douglas Gregor2009cee2012-01-03 22:46:00 +00002988 for (IdentifierResolver::iterator I = IdResolver.begin(Name),
Douglas Gregor022857e2011-12-22 01:48:48 +00002989 IEnd = IdResolver.end();
2990 I != IEnd; ++I) {
Richard Smith70d58502014-08-30 00:04:23 +00002991 if (NamedDecl *Existing = getDeclForMerging(*I, TypedefNameForLinkage))
Richard Smith87dacc72014-08-25 23:33:46 +00002992 if (isSameEntity(Existing, D))
Richard Smith70d58502014-08-30 00:04:23 +00002993 return FindExistingResult(Reader, D, Existing, AnonymousDeclNumber,
2994 TypedefNameForLinkage);
Douglas Gregor022857e2011-12-22 01:48:48 +00002995 }
Richard Smith8a639892015-01-24 01:07:20 +00002996 } else if (DeclContext *MergeDC = getPrimaryContextForMerging(Reader, DC)) {
Richard Smithd55889a2013-09-09 16:55:27 +00002997 DeclContext::lookup_result R = MergeDC->noload_lookup(Name);
Richard Smith95d99302013-07-13 02:00:19 +00002998 for (DeclContext::lookup_iterator I = R.begin(), E = R.end(); I != E; ++I) {
Richard Smith70d58502014-08-30 00:04:23 +00002999 if (NamedDecl *Existing = getDeclForMerging(*I, TypedefNameForLinkage))
Richard Smith88ebade2014-08-23 01:45:27 +00003000 if (isSameEntity(Existing, D))
Richard Smith70d58502014-08-30 00:04:23 +00003001 return FindExistingResult(Reader, D, Existing, AnonymousDeclNumber,
3002 TypedefNameForLinkage);
Douglas Gregor9b47f942012-01-09 17:38:47 +00003003 }
Richard Smith2b9e3e32013-10-18 06:05:18 +00003004 } else {
3005 // Not in a mergeable context.
3006 return FindExistingResult(Reader);
Douglas Gregor9b47f942012-01-09 17:38:47 +00003007 }
Richard Smithd55889a2013-09-09 16:55:27 +00003008
Richard Smith2b9e3e32013-10-18 06:05:18 +00003009 // If this declaration is from a merged context, make a note that we need to
3010 // check that the canonical definition of that context contains the decl.
Richard Smithcd45dbc2014-04-19 03:48:30 +00003011 //
3012 // FIXME: We should do something similar if we merge two definitions of the
3013 // same template specialization into the same CXXRecordDecl.
Richard Smith88126a22014-08-25 02:10:01 +00003014 auto MergedDCIt = Reader.MergedDeclContexts.find(D->getLexicalDeclContext());
3015 if (MergedDCIt != Reader.MergedDeclContexts.end() &&
3016 MergedDCIt->second == D->getDeclContext())
Richard Smith2b9e3e32013-10-18 06:05:18 +00003017 Reader.PendingOdrMergeChecks.push_back(D);
3018
Richard Smithd08aeb62014-08-28 01:33:39 +00003019 return FindExistingResult(Reader, D, /*Existing=*/nullptr,
Richard Smith70d58502014-08-30 00:04:23 +00003020 AnonymousDeclNumber, TypedefNameForLinkage);
Douglas Gregor022857e2011-12-22 01:48:48 +00003021}
3022
Richard Smithb321ecb2014-05-13 01:15:00 +00003023template<typename DeclT>
Richard Smithc3a53252015-02-28 05:57:02 +00003024Decl *ASTDeclReader::getMostRecentDeclImpl(Redeclarable<DeclT> *D) {
3025 return D->RedeclLink.getLatestNotUpdated();
3026}
3027Decl *ASTDeclReader::getMostRecentDeclImpl(...) {
3028 llvm_unreachable("getMostRecentDecl on non-redeclarable declaration");
3029}
3030
3031Decl *ASTDeclReader::getMostRecentDecl(Decl *D) {
3032 assert(D);
3033
3034 switch (D->getKind()) {
3035#define ABSTRACT_DECL(TYPE)
3036#define DECL(TYPE, BASE) \
3037 case Decl::TYPE: \
3038 return getMostRecentDeclImpl(cast<TYPE##Decl>(D));
3039#include "clang/AST/DeclNodes.inc"
3040 }
3041 llvm_unreachable("unknown decl kind");
3042}
3043
Richard Smith8ce51082015-03-11 01:44:51 +00003044Decl *ASTReader::getMostRecentExistingDecl(Decl *D) {
3045 return ASTDeclReader::getMostRecentDecl(D->getCanonicalDecl());
3046}
3047
Richard Smithc3a53252015-02-28 05:57:02 +00003048template<typename DeclT>
Richard Smith6de7a242014-07-31 23:46:44 +00003049void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader,
3050 Redeclarable<DeclT> *D,
Richard Smith9e2341d2015-03-23 03:25:59 +00003051 Decl *Previous, Decl *Canon) {
Richard Smith053f6c62014-05-16 23:01:30 +00003052 D->RedeclLink.setPrevious(cast<DeclT>(Previous));
Manuel Klimek093b2d42015-03-25 23:18:30 +00003053 D->First = cast<DeclT>(Previous)->First;
Richard Smithb321ecb2014-05-13 01:15:00 +00003054}
Hans Wennborgdcfba332015-10-06 23:40:43 +00003055
Richard Smith24d166c2014-07-31 23:52:38 +00003056namespace clang {
Richard Smith6de7a242014-07-31 23:46:44 +00003057template<>
3058void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader,
Richard Smithedbc6e92016-10-14 21:41:24 +00003059 Redeclarable<VarDecl> *D,
3060 Decl *Previous, Decl *Canon) {
3061 VarDecl *VD = static_cast<VarDecl*>(D);
3062 VarDecl *PrevVD = cast<VarDecl>(Previous);
3063 D->RedeclLink.setPrevious(PrevVD);
3064 D->First = PrevVD->First;
3065
3066 // We should keep at most one definition on the chain.
3067 // FIXME: Cache the definition once we've found it. Building a chain with
3068 // N definitions currently takes O(N^2) time here.
3069 if (VD->isThisDeclarationADefinition() == VarDecl::Definition) {
3070 for (VarDecl *CurD = PrevVD; CurD; CurD = CurD->getPreviousDecl()) {
3071 if (CurD->isThisDeclarationADefinition() == VarDecl::Definition) {
3072 Reader.mergeDefinitionVisibility(CurD, VD);
3073 VD->demoteThisDefinitionToDeclaration();
3074 break;
3075 }
3076 }
3077 }
3078}
3079
3080template<>
3081void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader,
Richard Smith6de7a242014-07-31 23:46:44 +00003082 Redeclarable<FunctionDecl> *D,
Richard Smith9e2341d2015-03-23 03:25:59 +00003083 Decl *Previous, Decl *Canon) {
Richard Smith6de7a242014-07-31 23:46:44 +00003084 FunctionDecl *FD = static_cast<FunctionDecl*>(D);
3085 FunctionDecl *PrevFD = cast<FunctionDecl>(Previous);
3086
3087 FD->RedeclLink.setPrevious(PrevFD);
Manuel Klimek093b2d42015-03-25 23:18:30 +00003088 FD->First = PrevFD->First;
Richard Smith6de7a242014-07-31 23:46:44 +00003089
3090 // If the previous declaration is an inline function declaration, then this
3091 // declaration is too.
3092 if (PrevFD->IsInline != FD->IsInline) {
3093 // FIXME: [dcl.fct.spec]p4:
3094 // If a function with external linkage is declared inline in one
3095 // translation unit, it shall be declared inline in all translation
3096 // units in which it appears.
3097 //
3098 // Be careful of this case:
3099 //
3100 // module A:
3101 // template<typename T> struct X { void f(); };
3102 // template<typename T> inline void X<T>::f() {}
3103 //
3104 // module B instantiates the declaration of X<int>::f
3105 // module C instantiates the definition of X<int>::f
3106 //
3107 // If module B and C are merged, we do not have a violation of this rule.
3108 FD->IsInline = true;
3109 }
3110
Richard Smith9e2341d2015-03-23 03:25:59 +00003111 // If we need to propagate an exception specification along the redecl
3112 // chain, make a note of that so that we can do so later.
Richard Smith6de7a242014-07-31 23:46:44 +00003113 auto *FPT = FD->getType()->getAs<FunctionProtoType>();
3114 auto *PrevFPT = PrevFD->getType()->getAs<FunctionProtoType>();
Richard Smith80969752015-03-10 02:00:53 +00003115 if (FPT && PrevFPT) {
Richard Smith9e2341d2015-03-23 03:25:59 +00003116 bool IsUnresolved = isUnresolvedExceptionSpec(FPT->getExceptionSpecType());
3117 bool WasUnresolved =
3118 isUnresolvedExceptionSpec(PrevFPT->getExceptionSpecType());
3119 if (IsUnresolved != WasUnresolved)
3120 Reader.PendingExceptionSpecUpdates.insert(
3121 std::make_pair(Canon, IsUnresolved ? PrevFD : FD));
Richard Smith6de7a242014-07-31 23:46:44 +00003122 }
3123}
Hans Wennborgdcfba332015-10-06 23:40:43 +00003124} // end namespace clang
3125
Richard Smith6de7a242014-07-31 23:46:44 +00003126void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader, ...) {
Richard Smithb321ecb2014-05-13 01:15:00 +00003127 llvm_unreachable("attachPreviousDecl on non-redeclarable declaration");
3128}
3129
Richard Smith8346e522015-06-10 01:47:58 +00003130/// Inherit the default template argument from \p From to \p To. Returns
3131/// \c false if there is no default template for \p From.
3132template <typename ParmDecl>
3133static bool inheritDefaultTemplateArgument(ASTContext &Context, ParmDecl *From,
3134 Decl *ToD) {
3135 auto *To = cast<ParmDecl>(ToD);
3136 if (!From->hasDefaultArgument())
3137 return false;
Richard Smithe7bd6de2015-06-10 20:30:23 +00003138 To->setInheritedDefaultArgument(Context, From);
Richard Smith8346e522015-06-10 01:47:58 +00003139 return true;
3140}
3141
3142static void inheritDefaultTemplateArguments(ASTContext &Context,
3143 TemplateDecl *From,
3144 TemplateDecl *To) {
3145 auto *FromTP = From->getTemplateParameters();
3146 auto *ToTP = To->getTemplateParameters();
3147 assert(FromTP->size() == ToTP->size() && "merged mismatched templates?");
3148
3149 for (unsigned I = 0, N = FromTP->size(); I != N; ++I) {
3150 NamedDecl *FromParam = FromTP->getParam(N - I - 1);
Richard Smith3d987032016-02-04 22:54:41 +00003151 if (FromParam->isParameterPack())
3152 continue;
Richard Smith8346e522015-06-10 01:47:58 +00003153 NamedDecl *ToParam = ToTP->getParam(N - I - 1);
3154
3155 if (auto *FTTP = dyn_cast<TemplateTypeParmDecl>(FromParam)) {
Richard Smithafe800c2015-06-17 22:13:23 +00003156 if (!inheritDefaultTemplateArgument(Context, FTTP, ToParam))
Richard Smith8346e522015-06-10 01:47:58 +00003157 break;
3158 } else if (auto *FNTTP = dyn_cast<NonTypeTemplateParmDecl>(FromParam)) {
Richard Smithafe800c2015-06-17 22:13:23 +00003159 if (!inheritDefaultTemplateArgument(Context, FNTTP, ToParam))
Richard Smith8346e522015-06-10 01:47:58 +00003160 break;
3161 } else {
Richard Smithafe800c2015-06-17 22:13:23 +00003162 if (!inheritDefaultTemplateArgument(
Richard Smith8346e522015-06-10 01:47:58 +00003163 Context, cast<TemplateTemplateParmDecl>(FromParam), ToParam))
3164 break;
3165 }
3166 }
3167}
3168
Richard Smith6de7a242014-07-31 23:46:44 +00003169void ASTDeclReader::attachPreviousDecl(ASTReader &Reader, Decl *D,
Richard Smith9e2341d2015-03-23 03:25:59 +00003170 Decl *Previous, Decl *Canon) {
Richard Smithb321ecb2014-05-13 01:15:00 +00003171 assert(D && Previous);
3172
3173 switch (D->getKind()) {
3174#define ABSTRACT_DECL(TYPE)
Richard Smith9e2341d2015-03-23 03:25:59 +00003175#define DECL(TYPE, BASE) \
3176 case Decl::TYPE: \
3177 attachPreviousDeclImpl(Reader, cast<TYPE##Decl>(D), Previous, Canon); \
Richard Smithb321ecb2014-05-13 01:15:00 +00003178 break;
3179#include "clang/AST/DeclNodes.inc"
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00003180 }
Richard Smith7ecc31b2013-08-02 01:09:12 +00003181
3182 // If the declaration was visible in one module, a redeclaration of it in
3183 // another module remains visible even if it wouldn't be visible by itself.
3184 //
3185 // FIXME: In this case, the declaration should only be visible if a module
3186 // that makes it visible has been imported.
Richard Smith7ecc31b2013-08-02 01:09:12 +00003187 D->IdentifierNamespace |=
Richard Smithb321ecb2014-05-13 01:15:00 +00003188 Previous->IdentifierNamespace &
Richard Smith7ecc31b2013-08-02 01:09:12 +00003189 (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type);
Richard Smith195d8ef2014-05-29 03:15:31 +00003190
Richard Smith8346e522015-06-10 01:47:58 +00003191 // If the declaration declares a template, it may inherit default arguments
3192 // from the previous declaration.
3193 if (TemplateDecl *TD = dyn_cast<TemplateDecl>(D))
3194 inheritDefaultTemplateArguments(Reader.getContext(),
3195 cast<TemplateDecl>(Previous), TD);
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00003196}
3197
Richard Smithb321ecb2014-05-13 01:15:00 +00003198template<typename DeclT>
3199void ASTDeclReader::attachLatestDeclImpl(Redeclarable<DeclT> *D, Decl *Latest) {
Richard Smith053f6c62014-05-16 23:01:30 +00003200 D->RedeclLink.setLatest(cast<DeclT>(Latest));
Richard Smithb321ecb2014-05-13 01:15:00 +00003201}
3202void ASTDeclReader::attachLatestDeclImpl(...) {
3203 llvm_unreachable("attachLatestDecl on non-redeclarable declaration");
3204}
3205
Douglas Gregor05f10352011-12-17 23:38:30 +00003206void ASTDeclReader::attachLatestDecl(Decl *D, Decl *Latest) {
3207 assert(D && Latest);
Richard Smithb321ecb2014-05-13 01:15:00 +00003208
3209 switch (D->getKind()) {
3210#define ABSTRACT_DECL(TYPE)
Richard Smith053f6c62014-05-16 23:01:30 +00003211#define DECL(TYPE, BASE) \
3212 case Decl::TYPE: \
Richard Smithb321ecb2014-05-13 01:15:00 +00003213 attachLatestDeclImpl(cast<TYPE##Decl>(D), Latest); \
3214 break;
3215#include "clang/AST/DeclNodes.inc"
Douglas Gregor05f10352011-12-17 23:38:30 +00003216 }
3217}
3218
Richard Smith851072e2014-05-19 20:59:20 +00003219template<typename DeclT>
3220void ASTDeclReader::markIncompleteDeclChainImpl(Redeclarable<DeclT> *D) {
3221 D->RedeclLink.markIncomplete();
3222}
3223void ASTDeclReader::markIncompleteDeclChainImpl(...) {
3224 llvm_unreachable("markIncompleteDeclChain on non-redeclarable declaration");
3225}
3226
3227void ASTReader::markIncompleteDeclChain(Decl *D) {
3228 switch (D->getKind()) {
3229#define ABSTRACT_DECL(TYPE)
3230#define DECL(TYPE, BASE) \
3231 case Decl::TYPE: \
3232 ASTDeclReader::markIncompleteDeclChainImpl(cast<TYPE##Decl>(D)); \
3233 break;
3234#include "clang/AST/DeclNodes.inc"
3235 }
3236}
3237
Sebastian Redlb3298c32010-08-18 23:56:48 +00003238/// \brief Read the declaration at the given offset from the AST file.
Douglas Gregorf7180622011-08-03 15:48:04 +00003239Decl *ASTReader::ReadDeclRecord(DeclID ID) {
Douglas Gregordab42432011-08-12 00:15:20 +00003240 unsigned Index = ID - NUM_PREDEF_DECL_IDS;
Richard Smithcb34bd32016-03-27 07:28:06 +00003241 SourceLocation DeclLoc;
3242 RecordLocation Loc = DeclCursorForID(ID, DeclLoc);
Sebastian Redl2c373b92010-10-05 15:59:54 +00003243 llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor;
Chris Lattner487412d2009-04-27 05:27:42 +00003244 // Keep track of where we are in the stream, then jump back there
3245 // after reading this declaration.
Chris Lattner1de76db2009-04-27 05:58:23 +00003246 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner487412d2009-04-27 05:27:42 +00003247
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +00003248 ReadingKindTracker ReadingKind(Read_Decl, *this);
3249
Douglas Gregor1342e842009-07-06 18:54:52 +00003250 // Note that we are loading a declaration record.
Argyrios Kyrtzidisb24355a2010-07-30 10:03:16 +00003251 Deserializing ADecl(this);
Mike Stump11289f42009-09-09 15:08:12 +00003252
Sebastian Redl2c373b92010-10-05 15:59:54 +00003253 DeclsCursor.JumpToBit(Loc.Offset);
Chris Lattner487412d2009-04-27 05:27:42 +00003254 RecordData Record;
Chris Lattner1de76db2009-04-27 05:58:23 +00003255 unsigned Code = DeclsCursor.ReadCode();
Chris Lattner487412d2009-04-27 05:27:42 +00003256 unsigned Idx = 0;
Richard Smithcb34bd32016-03-27 07:28:06 +00003257 ASTDeclReader Reader(*this, Loc, ID, DeclLoc, Record,Idx);
Chris Lattner487412d2009-04-27 05:27:42 +00003258
Craig Toppera13603a2014-05-22 05:54:18 +00003259 Decl *D = nullptr;
Chris Lattner0e6c9402013-01-20 02:38:54 +00003260 switch ((DeclCode)DeclsCursor.readRecord(Code, Record)) {
Sebastian Redl539c5062010-08-18 23:57:32 +00003261 case DECL_CONTEXT_LEXICAL:
3262 case DECL_CONTEXT_VISIBLE:
David Blaikie83d382b2011-09-23 05:06:16 +00003263 llvm_unreachable("Record cannot be de-serialized with ReadDeclRecord");
Sebastian Redl539c5062010-08-18 23:57:32 +00003264 case DECL_TYPEDEF:
Douglas Gregor72172e92012-01-05 21:55:30 +00003265 D = TypedefDecl::CreateDeserialized(Context, ID);
Chris Lattner487412d2009-04-27 05:27:42 +00003266 break;
Richard Smithdda56e42011-04-15 14:24:37 +00003267 case DECL_TYPEALIAS:
Douglas Gregor72172e92012-01-05 21:55:30 +00003268 D = TypeAliasDecl::CreateDeserialized(Context, ID);
Richard Smithdda56e42011-04-15 14:24:37 +00003269 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003270 case DECL_ENUM:
Douglas Gregor72172e92012-01-05 21:55:30 +00003271 D = EnumDecl::CreateDeserialized(Context, ID);
Chris Lattner487412d2009-04-27 05:27:42 +00003272 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003273 case DECL_RECORD:
Douglas Gregor72172e92012-01-05 21:55:30 +00003274 D = RecordDecl::CreateDeserialized(Context, ID);
Chris Lattner487412d2009-04-27 05:27:42 +00003275 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003276 case DECL_ENUM_CONSTANT:
Douglas Gregor72172e92012-01-05 21:55:30 +00003277 D = EnumConstantDecl::CreateDeserialized(Context, ID);
Chris Lattner487412d2009-04-27 05:27:42 +00003278 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003279 case DECL_FUNCTION:
Douglas Gregor72172e92012-01-05 21:55:30 +00003280 D = FunctionDecl::CreateDeserialized(Context, ID);
Chris Lattner487412d2009-04-27 05:27:42 +00003281 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003282 case DECL_LINKAGE_SPEC:
Douglas Gregor72172e92012-01-05 21:55:30 +00003283 D = LinkageSpecDecl::CreateDeserialized(Context, ID);
Chris Lattnerca025db2010-05-07 21:43:38 +00003284 break;
Richard Smith8df390f2016-09-08 23:14:54 +00003285 case DECL_EXPORT:
3286 D = ExportDecl::CreateDeserialized(Context, ID);
3287 break;
Chris Lattnerc8e630e2011-02-17 07:39:24 +00003288 case DECL_LABEL:
Douglas Gregor72172e92012-01-05 21:55:30 +00003289 D = LabelDecl::CreateDeserialized(Context, ID);
Chris Lattnerc8e630e2011-02-17 07:39:24 +00003290 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003291 case DECL_NAMESPACE:
Douglas Gregor72172e92012-01-05 21:55:30 +00003292 D = NamespaceDecl::CreateDeserialized(Context, ID);
Chris Lattnerca025db2010-05-07 21:43:38 +00003293 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003294 case DECL_NAMESPACE_ALIAS:
Douglas Gregor72172e92012-01-05 21:55:30 +00003295 D = NamespaceAliasDecl::CreateDeserialized(Context, ID);
Chris Lattnerca025db2010-05-07 21:43:38 +00003296 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003297 case DECL_USING:
Douglas Gregor72172e92012-01-05 21:55:30 +00003298 D = UsingDecl::CreateDeserialized(Context, ID);
Chris Lattnerca025db2010-05-07 21:43:38 +00003299 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003300 case DECL_USING_SHADOW:
Douglas Gregor72172e92012-01-05 21:55:30 +00003301 D = UsingShadowDecl::CreateDeserialized(Context, ID);
Chris Lattnerca025db2010-05-07 21:43:38 +00003302 break;
Richard Smith5179eb72016-06-28 19:03:57 +00003303 case DECL_CONSTRUCTOR_USING_SHADOW:
3304 D = ConstructorUsingShadowDecl::CreateDeserialized(Context, ID);
3305 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003306 case DECL_USING_DIRECTIVE:
Douglas Gregor72172e92012-01-05 21:55:30 +00003307 D = UsingDirectiveDecl::CreateDeserialized(Context, ID);
Chris Lattnerca025db2010-05-07 21:43:38 +00003308 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003309 case DECL_UNRESOLVED_USING_VALUE:
Douglas Gregor72172e92012-01-05 21:55:30 +00003310 D = UnresolvedUsingValueDecl::CreateDeserialized(Context, ID);
Chris Lattnerca025db2010-05-07 21:43:38 +00003311 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003312 case DECL_UNRESOLVED_USING_TYPENAME:
Douglas Gregor72172e92012-01-05 21:55:30 +00003313 D = UnresolvedUsingTypenameDecl::CreateDeserialized(Context, ID);
Chris Lattnerca025db2010-05-07 21:43:38 +00003314 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003315 case DECL_CXX_RECORD:
Douglas Gregor72172e92012-01-05 21:55:30 +00003316 D = CXXRecordDecl::CreateDeserialized(Context, ID);
Chris Lattnerca025db2010-05-07 21:43:38 +00003317 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003318 case DECL_CXX_METHOD:
Douglas Gregor72172e92012-01-05 21:55:30 +00003319 D = CXXMethodDecl::CreateDeserialized(Context, ID);
Chris Lattnerca025db2010-05-07 21:43:38 +00003320 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003321 case DECL_CXX_CONSTRUCTOR:
Richard Smith5179eb72016-06-28 19:03:57 +00003322 D = CXXConstructorDecl::CreateDeserialized(Context, ID, false);
3323 break;
3324 case DECL_CXX_INHERITED_CONSTRUCTOR:
3325 D = CXXConstructorDecl::CreateDeserialized(Context, ID, true);
Chris Lattnerca025db2010-05-07 21:43:38 +00003326 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003327 case DECL_CXX_DESTRUCTOR:
Douglas Gregor72172e92012-01-05 21:55:30 +00003328 D = CXXDestructorDecl::CreateDeserialized(Context, ID);
Chris Lattnerca025db2010-05-07 21:43:38 +00003329 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003330 case DECL_CXX_CONVERSION:
Douglas Gregor72172e92012-01-05 21:55:30 +00003331 D = CXXConversionDecl::CreateDeserialized(Context, ID);
Chris Lattnerca025db2010-05-07 21:43:38 +00003332 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003333 case DECL_ACCESS_SPEC:
Douglas Gregor72172e92012-01-05 21:55:30 +00003334 D = AccessSpecDecl::CreateDeserialized(Context, ID);
Abramo Bagnarad7340582010-06-05 05:09:32 +00003335 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003336 case DECL_FRIEND:
Enea Zaffanellaeb22c872013-01-31 09:54:08 +00003337 D = FriendDecl::CreateDeserialized(Context, ID, Record[Idx++]);
Chris Lattnerca025db2010-05-07 21:43:38 +00003338 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003339 case DECL_FRIEND_TEMPLATE:
Douglas Gregor72172e92012-01-05 21:55:30 +00003340 D = FriendTemplateDecl::CreateDeserialized(Context, ID);
Chris Lattnerca025db2010-05-07 21:43:38 +00003341 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003342 case DECL_CLASS_TEMPLATE:
Douglas Gregor72172e92012-01-05 21:55:30 +00003343 D = ClassTemplateDecl::CreateDeserialized(Context, ID);
Chris Lattnerca025db2010-05-07 21:43:38 +00003344 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003345 case DECL_CLASS_TEMPLATE_SPECIALIZATION:
Douglas Gregor72172e92012-01-05 21:55:30 +00003346 D = ClassTemplateSpecializationDecl::CreateDeserialized(Context, ID);
Chris Lattnerca025db2010-05-07 21:43:38 +00003347 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003348 case DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION:
Douglas Gregor72172e92012-01-05 21:55:30 +00003349 D = ClassTemplatePartialSpecializationDecl::CreateDeserialized(Context, ID);
Chris Lattnerca025db2010-05-07 21:43:38 +00003350 break;
Larisse Voufo39a1e502013-08-06 01:03:05 +00003351 case DECL_VAR_TEMPLATE:
3352 D = VarTemplateDecl::CreateDeserialized(Context, ID);
3353 break;
3354 case DECL_VAR_TEMPLATE_SPECIALIZATION:
3355 D = VarTemplateSpecializationDecl::CreateDeserialized(Context, ID);
3356 break;
3357 case DECL_VAR_TEMPLATE_PARTIAL_SPECIALIZATION:
3358 D = VarTemplatePartialSpecializationDecl::CreateDeserialized(Context, ID);
3359 break;
Francois Pichet00c7e6c2011-08-14 03:52:19 +00003360 case DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION:
Douglas Gregor72172e92012-01-05 21:55:30 +00003361 D = ClassScopeFunctionSpecializationDecl::CreateDeserialized(Context, ID);
Francois Pichet00c7e6c2011-08-14 03:52:19 +00003362 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003363 case DECL_FUNCTION_TEMPLATE:
Douglas Gregor72172e92012-01-05 21:55:30 +00003364 D = FunctionTemplateDecl::CreateDeserialized(Context, ID);
Chris Lattnerca025db2010-05-07 21:43:38 +00003365 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003366 case DECL_TEMPLATE_TYPE_PARM:
Douglas Gregor72172e92012-01-05 21:55:30 +00003367 D = TemplateTypeParmDecl::CreateDeserialized(Context, ID);
Chris Lattnerca025db2010-05-07 21:43:38 +00003368 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003369 case DECL_NON_TYPE_TEMPLATE_PARM:
Douglas Gregor72172e92012-01-05 21:55:30 +00003370 D = NonTypeTemplateParmDecl::CreateDeserialized(Context, ID);
Chris Lattnerca025db2010-05-07 21:43:38 +00003371 break;
Douglas Gregor0231d8d2011-01-19 20:10:05 +00003372 case DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK:
Douglas Gregor72172e92012-01-05 21:55:30 +00003373 D = NonTypeTemplateParmDecl::CreateDeserialized(Context, ID, Record[Idx++]);
Douglas Gregor0231d8d2011-01-19 20:10:05 +00003374 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003375 case DECL_TEMPLATE_TEMPLATE_PARM:
Douglas Gregor72172e92012-01-05 21:55:30 +00003376 D = TemplateTemplateParmDecl::CreateDeserialized(Context, ID);
Chris Lattnerca025db2010-05-07 21:43:38 +00003377 break;
Richard Smith1fde8ec2012-09-07 02:06:42 +00003378 case DECL_EXPANDED_TEMPLATE_TEMPLATE_PARM_PACK:
3379 D = TemplateTemplateParmDecl::CreateDeserialized(Context, ID,
3380 Record[Idx++]);
3381 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +00003382 case DECL_TYPE_ALIAS_TEMPLATE:
Douglas Gregor72172e92012-01-05 21:55:30 +00003383 D = TypeAliasTemplateDecl::CreateDeserialized(Context, ID);
Richard Smith3f1b5d02011-05-05 21:57:07 +00003384 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003385 case DECL_STATIC_ASSERT:
Douglas Gregor72172e92012-01-05 21:55:30 +00003386 D = StaticAssertDecl::CreateDeserialized(Context, ID);
Chris Lattnerca025db2010-05-07 21:43:38 +00003387 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003388 case DECL_OBJC_METHOD:
Douglas Gregor72172e92012-01-05 21:55:30 +00003389 D = ObjCMethodDecl::CreateDeserialized(Context, ID);
Chris Lattner487412d2009-04-27 05:27:42 +00003390 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003391 case DECL_OBJC_INTERFACE:
Douglas Gregor72172e92012-01-05 21:55:30 +00003392 D = ObjCInterfaceDecl::CreateDeserialized(Context, ID);
Chris Lattner487412d2009-04-27 05:27:42 +00003393 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003394 case DECL_OBJC_IVAR:
Douglas Gregor72172e92012-01-05 21:55:30 +00003395 D = ObjCIvarDecl::CreateDeserialized(Context, ID);
Chris Lattner487412d2009-04-27 05:27:42 +00003396 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003397 case DECL_OBJC_PROTOCOL:
Douglas Gregor72172e92012-01-05 21:55:30 +00003398 D = ObjCProtocolDecl::CreateDeserialized(Context, ID);
Chris Lattner487412d2009-04-27 05:27:42 +00003399 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003400 case DECL_OBJC_AT_DEFS_FIELD:
Douglas Gregor72172e92012-01-05 21:55:30 +00003401 D = ObjCAtDefsFieldDecl::CreateDeserialized(Context, ID);
Chris Lattner487412d2009-04-27 05:27:42 +00003402 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003403 case DECL_OBJC_CATEGORY:
Douglas Gregor72172e92012-01-05 21:55:30 +00003404 D = ObjCCategoryDecl::CreateDeserialized(Context, ID);
Chris Lattner487412d2009-04-27 05:27:42 +00003405 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003406 case DECL_OBJC_CATEGORY_IMPL:
Douglas Gregor72172e92012-01-05 21:55:30 +00003407 D = ObjCCategoryImplDecl::CreateDeserialized(Context, ID);
Chris Lattner487412d2009-04-27 05:27:42 +00003408 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003409 case DECL_OBJC_IMPLEMENTATION:
Douglas Gregor72172e92012-01-05 21:55:30 +00003410 D = ObjCImplementationDecl::CreateDeserialized(Context, ID);
Chris Lattner487412d2009-04-27 05:27:42 +00003411 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003412 case DECL_OBJC_COMPATIBLE_ALIAS:
Douglas Gregor72172e92012-01-05 21:55:30 +00003413 D = ObjCCompatibleAliasDecl::CreateDeserialized(Context, ID);
Chris Lattner487412d2009-04-27 05:27:42 +00003414 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003415 case DECL_OBJC_PROPERTY:
Douglas Gregor72172e92012-01-05 21:55:30 +00003416 D = ObjCPropertyDecl::CreateDeserialized(Context, ID);
Chris Lattner487412d2009-04-27 05:27:42 +00003417 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003418 case DECL_OBJC_PROPERTY_IMPL:
Douglas Gregor72172e92012-01-05 21:55:30 +00003419 D = ObjCPropertyImplDecl::CreateDeserialized(Context, ID);
Chris Lattner487412d2009-04-27 05:27:42 +00003420 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003421 case DECL_FIELD:
Douglas Gregor72172e92012-01-05 21:55:30 +00003422 D = FieldDecl::CreateDeserialized(Context, ID);
Chris Lattner487412d2009-04-27 05:27:42 +00003423 break;
Francois Pichet783dd6e2010-11-21 06:08:52 +00003424 case DECL_INDIRECTFIELD:
Douglas Gregor72172e92012-01-05 21:55:30 +00003425 D = IndirectFieldDecl::CreateDeserialized(Context, ID);
Francois Pichet783dd6e2010-11-21 06:08:52 +00003426 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003427 case DECL_VAR:
Douglas Gregor72172e92012-01-05 21:55:30 +00003428 D = VarDecl::CreateDeserialized(Context, ID);
Chris Lattner487412d2009-04-27 05:27:42 +00003429 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003430 case DECL_IMPLICIT_PARAM:
Douglas Gregor72172e92012-01-05 21:55:30 +00003431 D = ImplicitParamDecl::CreateDeserialized(Context, ID);
Chris Lattner487412d2009-04-27 05:27:42 +00003432 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003433 case DECL_PARM_VAR:
Douglas Gregor72172e92012-01-05 21:55:30 +00003434 D = ParmVarDecl::CreateDeserialized(Context, ID);
Chris Lattner487412d2009-04-27 05:27:42 +00003435 break;
Richard Smith7b76d812016-08-12 02:21:25 +00003436 case DECL_DECOMPOSITION:
3437 D = DecompositionDecl::CreateDeserialized(Context, ID, Record[Idx++]);
3438 break;
3439 case DECL_BINDING:
3440 D = BindingDecl::CreateDeserialized(Context, ID);
3441 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003442 case DECL_FILE_SCOPE_ASM:
Douglas Gregor72172e92012-01-05 21:55:30 +00003443 D = FileScopeAsmDecl::CreateDeserialized(Context, ID);
Chris Lattner487412d2009-04-27 05:27:42 +00003444 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003445 case DECL_BLOCK:
Douglas Gregor72172e92012-01-05 21:55:30 +00003446 D = BlockDecl::CreateDeserialized(Context, ID);
Chris Lattner487412d2009-04-27 05:27:42 +00003447 break;
John McCall5e77d762013-04-16 07:28:30 +00003448 case DECL_MS_PROPERTY:
3449 D = MSPropertyDecl::CreateDeserialized(Context, ID);
3450 break;
Tareq A. Siraj6dfa25a2013-04-16 19:37:38 +00003451 case DECL_CAPTURED:
Ben Langmuirce914fc2013-05-03 19:20:19 +00003452 D = CapturedDecl::CreateDeserialized(Context, ID, Record[Idx++]);
Tareq A. Siraj6dfa25a2013-04-16 19:37:38 +00003453 break;
Douglas Gregord4c5ed02010-10-29 22:39:52 +00003454 case DECL_CXX_BASE_SPECIFIERS:
3455 Error("attempt to read a C++ base-specifier record as a declaration");
Craig Toppera13603a2014-05-22 05:54:18 +00003456 return nullptr;
Richard Smithc2bb8182015-03-24 06:36:48 +00003457 case DECL_CXX_CTOR_INITIALIZERS:
3458 Error("attempt to read a C++ ctor initializer record as a declaration");
3459 return nullptr;
Douglas Gregorba345522011-12-02 23:23:56 +00003460 case DECL_IMPORT:
3461 // Note: last entry of the ImportDecl record is the number of stored source
3462 // locations.
Douglas Gregor72172e92012-01-05 21:55:30 +00003463 D = ImportDecl::CreateDeserialized(Context, ID, Record.back());
Douglas Gregorba345522011-12-02 23:23:56 +00003464 break;
Alexey Bataeva769e072013-03-22 06:34:35 +00003465 case DECL_OMP_THREADPRIVATE:
3466 D = OMPThreadPrivateDecl::CreateDeserialized(Context, ID, Record[Idx++]);
3467 break;
Alexey Bataev94a4f0c2016-03-03 05:21:39 +00003468 case DECL_OMP_DECLARE_REDUCTION:
3469 D = OMPDeclareReductionDecl::CreateDeserialized(Context, ID);
3470 break;
Alexey Bataev4244be22016-02-11 05:35:55 +00003471 case DECL_OMP_CAPTUREDEXPR:
3472 D = OMPCapturedExprDecl::CreateDeserialized(Context, ID);
Alexey Bataev90c228f2016-02-08 09:29:13 +00003473 break;
Nico Weber66220292016-03-02 17:28:48 +00003474 case DECL_PRAGMA_COMMENT:
3475 D = PragmaCommentDecl::CreateDeserialized(Context, ID, Record[Idx++]);
3476 break;
Nico Webercbbaeb12016-03-02 19:28:54 +00003477 case DECL_PRAGMA_DETECT_MISMATCH:
3478 D = PragmaDetectMismatchDecl::CreateDeserialized(Context, ID,
3479 Record[Idx++]);
3480 break;
Michael Han84324352013-02-22 17:15:32 +00003481 case DECL_EMPTY:
3482 D = EmptyDecl::CreateDeserialized(Context, ID);
3483 break;
Douglas Gregor85f3f952015-07-07 03:57:15 +00003484 case DECL_OBJC_TYPE_PARAM:
3485 D = ObjCTypeParamDecl::CreateDeserialized(Context, ID);
3486 break;
Chris Lattner487412d2009-04-27 05:27:42 +00003487 }
Chris Lattner487412d2009-04-27 05:27:42 +00003488
Sebastian Redlb3298c32010-08-18 23:56:48 +00003489 assert(D && "Unknown declaration reading AST file");
Chris Lattner8f63ab52009-04-27 06:01:06 +00003490 LoadedDecl(Index, D);
Argyrios Kyrtzidis6c075472012-02-09 06:02:44 +00003491 // Set the DeclContext before doing any deserialization, to make sure internal
3492 // calls to Decl::getASTContext() by Decl's methods will find the
3493 // TranslationUnitDecl without crashing.
3494 D->setDeclContext(Context.getTranslationUnitDecl());
Chris Lattner8f63ab52009-04-27 06:01:06 +00003495 Reader.Visit(D);
Chris Lattner487412d2009-04-27 05:27:42 +00003496
3497 // If this declaration is also a declaration context, get the
3498 // offsets for its tables of lexical and visible declarations.
3499 if (DeclContext *DC = dyn_cast<DeclContext>(D)) {
3500 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
Richard Smith0f4e2c42015-08-06 04:23:48 +00003501 if (Offsets.first &&
3502 ReadLexicalDeclContextStorage(*Loc.F, DeclsCursor, Offsets.first, DC))
3503 return nullptr;
3504 if (Offsets.second &&
3505 ReadVisibleDeclContextStorage(*Loc.F, DeclsCursor, Offsets.second, ID))
3506 return nullptr;
Chris Lattner487412d2009-04-27 05:27:42 +00003507 }
3508 assert(Idx == Record.size());
3509
Douglas Gregordab42432011-08-12 00:15:20 +00003510 // Load any relevant update records.
Richard Smithd1c46742014-04-30 02:24:17 +00003511 PendingUpdateRecords.push_back(std::make_pair(ID, D));
Argyrios Kyrtzidis7d268c32011-11-14 07:07:59 +00003512
Douglas Gregor404cdde2012-01-27 01:47:08 +00003513 // Load the categories after recursive loading is finished.
3514 if (ObjCInterfaceDecl *Class = dyn_cast<ObjCInterfaceDecl>(D))
Manman Renec315f12016-09-09 23:48:27 +00003515 // If we already have a definition when deserializing the ObjCInterfaceDecl,
3516 // we put the Decl in PendingDefinitions so we can pull the categories here.
3517 if (Class->isThisDeclarationADefinition() ||
3518 PendingDefinitions.count(Class))
Douglas Gregor404cdde2012-01-27 01:47:08 +00003519 loadObjCCategories(ID, Class);
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00003520
Richard Smith13fb8602016-07-15 21:33:46 +00003521 // If we have deserialized a declaration that has a definition the
3522 // AST consumer might need to know about, queue it.
3523 // We don't pass it to the consumer immediately because we may be in recursive
3524 // loading, and some declarations may still be initializing.
Richard Smithdc1f0422016-07-20 19:10:16 +00003525 if (isConsumerInterestedIn(Context, D, Reader.hasPendingBody()))
Richard Smith13fb8602016-07-15 21:33:46 +00003526 InterestingDecls.push_back(D);
3527
Douglas Gregordab42432011-08-12 00:15:20 +00003528 return D;
3529}
3530
3531void ASTReader::loadDeclUpdateRecords(serialization::DeclID ID, Decl *D) {
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00003532 // The declaration may have been modified by files later in the chain.
3533 // If this is the case, read the record containing the updates from each file
3534 // and pass it to ASTDeclReader to make the modifications.
Vassil Vassilev19765fb2016-07-22 21:08:24 +00003535 ProcessingUpdatesRAIIObj ProcessingUpdates(*this);
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00003536 DeclUpdateOffsetsMap::iterator UpdI = DeclUpdateOffsets.find(ID);
3537 if (UpdI != DeclUpdateOffsets.end()) {
Richard Smith0f4e2c42015-08-06 04:23:48 +00003538 auto UpdateOffsets = std::move(UpdI->second);
3539 DeclUpdateOffsets.erase(UpdI);
3540
Richard Smithdc1f0422016-07-20 19:10:16 +00003541 bool WasInteresting = isConsumerInterestedIn(Context, D, false);
Richard Smith0f4e2c42015-08-06 04:23:48 +00003542 for (auto &FileAndOffset : UpdateOffsets) {
3543 ModuleFile *F = FileAndOffset.first;
3544 uint64_t Offset = FileAndOffset.second;
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00003545 llvm::BitstreamCursor &Cursor = F->DeclsCursor;
3546 SavedStreamPosition SavedPosition(Cursor);
3547 Cursor.JumpToBit(Offset);
3548 RecordData Record;
3549 unsigned Code = Cursor.ReadCode();
Chris Lattner0e6c9402013-01-20 02:38:54 +00003550 unsigned RecCode = Cursor.readRecord(Code, Record);
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00003551 (void)RecCode;
3552 assert(RecCode == DECL_UPDATES && "Expected DECL_UPDATES record!");
Richard Smith04d05b52014-03-23 00:27:18 +00003553
Douglas Gregordab42432011-08-12 00:15:20 +00003554 unsigned Idx = 0;
Richard Smithcb34bd32016-03-27 07:28:06 +00003555 ASTDeclReader Reader(*this, RecordLocation(F, Offset), ID,
3556 SourceLocation(), Record, Idx);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00003557 Reader.UpdateDecl(D);
Richard Smith04d05b52014-03-23 00:27:18 +00003558
3559 // We might have made this declaration interesting. If so, remember that
3560 // we need to hand it off to the consumer.
3561 if (!WasInteresting &&
Richard Smithdc1f0422016-07-20 19:10:16 +00003562 isConsumerInterestedIn(Context, D, Reader.hasPendingBody())) {
Richard Smith13fb8602016-07-15 21:33:46 +00003563 InterestingDecls.push_back(D);
Richard Smith04d05b52014-03-23 00:27:18 +00003564 WasInteresting = true;
3565 }
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00003566 }
3567 }
Richard Smith1e8e91b2016-04-08 20:53:26 +00003568
3569 // Load the pending visible updates for this decl context, if it has any.
3570 auto I = PendingVisibleUpdates.find(ID);
3571 if (I != PendingVisibleUpdates.end()) {
3572 auto VisibleUpdates = std::move(I->second);
3573 PendingVisibleUpdates.erase(I);
3574
3575 auto *DC = cast<DeclContext>(D)->getPrimaryContext();
3576 for (const PendingVisibleUpdate &Update : VisibleUpdates)
3577 Lookups[DC].Table.add(
3578 Update.Mod, Update.Data,
3579 reader::ASTDeclContextNameLookupTrait(*this, *Update.Mod));
3580 DC->setHasExternalVisibleStorage(true);
3581 }
Chris Lattner487412d2009-04-27 05:27:42 +00003582}
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00003583
Richard Smithd61d4ac2015-08-22 20:13:39 +00003584void ASTReader::loadPendingDeclChain(Decl *FirstLocal, uint64_t LocalOffset) {
3585 // Attach FirstLocal to the end of the decl chain.
Richard Smithd8a83712015-08-22 01:47:18 +00003586 Decl *CanonDecl = FirstLocal->getCanonicalDecl();
Richard Smithd61d4ac2015-08-22 20:13:39 +00003587 if (FirstLocal != CanonDecl) {
3588 Decl *PrevMostRecent = ASTDeclReader::getMostRecentDecl(CanonDecl);
3589 ASTDeclReader::attachPreviousDecl(
3590 *this, FirstLocal, PrevMostRecent ? PrevMostRecent : CanonDecl,
3591 CanonDecl);
3592 }
3593
3594 if (!LocalOffset) {
3595 ASTDeclReader::attachLatestDecl(CanonDecl, FirstLocal);
3596 return;
3597 }
3598
3599 // Load the list of other redeclarations from this module file.
3600 ModuleFile *M = getOwningModuleFile(FirstLocal);
3601 assert(M && "imported decl from no module file");
3602
3603 llvm::BitstreamCursor &Cursor = M->DeclsCursor;
3604 SavedStreamPosition SavedPosition(Cursor);
3605 Cursor.JumpToBit(LocalOffset);
3606
3607 RecordData Record;
3608 unsigned Code = Cursor.ReadCode();
3609 unsigned RecCode = Cursor.readRecord(Code, Record);
3610 (void)RecCode;
3611 assert(RecCode == LOCAL_REDECLARATIONS && "expected LOCAL_REDECLARATIONS record!");
3612
3613 // FIXME: We have several different dispatches on decl kind here; maybe
3614 // we should instead generate one loop per kind and dispatch up-front?
3615 Decl *MostRecent = FirstLocal;
3616 for (unsigned I = 0, N = Record.size(); I != N; ++I) {
3617 auto *D = GetLocalDecl(*M, Record[N - I - 1]);
Richard Smithe2f8ce92015-07-15 00:02:40 +00003618 ASTDeclReader::attachPreviousDecl(*this, D, MostRecent, CanonDecl);
3619 MostRecent = D;
Douglas Gregor05f10352011-12-17 23:38:30 +00003620 }
Richard Smithc3a53252015-02-28 05:57:02 +00003621 ASTDeclReader::attachLatestDecl(CanonDecl, MostRecent);
Douglas Gregor05f10352011-12-17 23:38:30 +00003622}
3623
3624namespace {
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00003625 /// \brief Given an ObjC interface, goes through the modules and links to the
3626 /// interface all the categories for it.
Douglas Gregor404cdde2012-01-27 01:47:08 +00003627 class ObjCCategoriesVisitor {
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00003628 ASTReader &Reader;
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00003629 ObjCInterfaceDecl *Interface;
Craig Topper4dd9b432014-08-17 23:49:53 +00003630 llvm::SmallPtrSetImpl<ObjCCategoryDecl *> &Deserialized;
Douglas Gregor404cdde2012-01-27 01:47:08 +00003631 ObjCCategoryDecl *Tail;
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00003632 llvm::DenseMap<DeclarationName, ObjCCategoryDecl *> NameCategoryMap;
Alexander Shaposhnikov96cbe7b2016-09-24 02:07:19 +00003633 serialization::GlobalDeclID InterfaceID;
3634 unsigned PreviousGeneration;
Douglas Gregor404cdde2012-01-27 01:47:08 +00003635
3636 void add(ObjCCategoryDecl *Cat) {
3637 // Only process each category once.
Benjamin Kramerfc6eb7d2012-08-22 15:37:55 +00003638 if (!Deserialized.erase(Cat))
Douglas Gregor404cdde2012-01-27 01:47:08 +00003639 return;
Douglas Gregor404cdde2012-01-27 01:47:08 +00003640
3641 // Check for duplicate categories.
3642 if (Cat->getDeclName()) {
3643 ObjCCategoryDecl *&Existing = NameCategoryMap[Cat->getDeclName()];
3644 if (Existing &&
3645 Reader.getOwningModuleFile(Existing)
3646 != Reader.getOwningModuleFile(Cat)) {
3647 // FIXME: We should not warn for duplicates in diamond:
3648 //
3649 // MT //
3650 // / \ //
3651 // ML MR //
3652 // \ / //
3653 // MB //
3654 //
3655 // If there are duplicates in ML/MR, there will be warning when
3656 // creating MB *and* when importing MB. We should not warn when
3657 // importing.
3658 Reader.Diag(Cat->getLocation(), diag::warn_dup_category_def)
3659 << Interface->getDeclName() << Cat->getDeclName();
3660 Reader.Diag(Existing->getLocation(), diag::note_previous_definition);
3661 } else if (!Existing) {
3662 // Record this category.
3663 Existing = Cat;
3664 }
3665 }
3666
3667 // Add this category to the end of the chain.
3668 if (Tail)
3669 ASTDeclReader::setNextObjCCategory(Tail, Cat);
3670 else
Douglas Gregor048fbfa2013-01-16 23:00:23 +00003671 Interface->setCategoryListRaw(Cat);
Douglas Gregor404cdde2012-01-27 01:47:08 +00003672 Tail = Cat;
3673 }
3674
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00003675 public:
Douglas Gregor404cdde2012-01-27 01:47:08 +00003676 ObjCCategoriesVisitor(ASTReader &Reader,
Douglas Gregor404cdde2012-01-27 01:47:08 +00003677 ObjCInterfaceDecl *Interface,
Alexander Shaposhnikov96cbe7b2016-09-24 02:07:19 +00003678 llvm::SmallPtrSetImpl<ObjCCategoryDecl *> &Deserialized,
3679 serialization::GlobalDeclID InterfaceID,
Douglas Gregor404cdde2012-01-27 01:47:08 +00003680 unsigned PreviousGeneration)
Alexander Shaposhnikov96cbe7b2016-09-24 02:07:19 +00003681 : Reader(Reader), Interface(Interface), Deserialized(Deserialized),
3682 Tail(nullptr), InterfaceID(InterfaceID),
3683 PreviousGeneration(PreviousGeneration)
Douglas Gregor404cdde2012-01-27 01:47:08 +00003684 {
3685 // Populate the name -> category map with the set of known categories.
Aaron Ballman15063e12014-03-13 21:35:02 +00003686 for (auto *Cat : Interface->known_categories()) {
Douglas Gregor404cdde2012-01-27 01:47:08 +00003687 if (Cat->getDeclName())
Aaron Ballman15063e12014-03-13 21:35:02 +00003688 NameCategoryMap[Cat->getDeclName()] = Cat;
Douglas Gregor404cdde2012-01-27 01:47:08 +00003689
3690 // Keep track of the tail of the category list.
Aaron Ballman15063e12014-03-13 21:35:02 +00003691 Tail = Cat;
Douglas Gregor404cdde2012-01-27 01:47:08 +00003692 }
3693 }
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00003694
Benjamin Kramer9a9efba2015-07-25 12:14:04 +00003695 bool operator()(ModuleFile &M) {
Douglas Gregor404cdde2012-01-27 01:47:08 +00003696 // If we've loaded all of the category information we care about from
3697 // this module file, we're done.
3698 if (M.Generation <= PreviousGeneration)
3699 return true;
3700
3701 // Map global ID of the definition down to the local ID used in this
3702 // module file. If there is no such mapping, we'll find nothing here
3703 // (or in any module it imports).
3704 DeclID LocalID = Reader.mapGlobalIDToModuleFileGlobalID(M, InterfaceID);
3705 if (!LocalID)
3706 return true;
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00003707
Douglas Gregor404cdde2012-01-27 01:47:08 +00003708 // Perform a binary search to find the local redeclarations for this
3709 // declaration (if any).
Benjamin Kramera6f39502014-03-15 14:21:58 +00003710 const ObjCCategoriesInfo Compare = { LocalID, 0 };
Douglas Gregor404cdde2012-01-27 01:47:08 +00003711 const ObjCCategoriesInfo *Result
3712 = std::lower_bound(M.ObjCCategoriesMap,
3713 M.ObjCCategoriesMap + M.LocalNumObjCCategoriesInMap,
Benjamin Kramera6f39502014-03-15 14:21:58 +00003714 Compare);
Douglas Gregor404cdde2012-01-27 01:47:08 +00003715 if (Result == M.ObjCCategoriesMap + M.LocalNumObjCCategoriesInMap ||
3716 Result->DefinitionID != LocalID) {
3717 // We didn't find anything. If the class definition is in this module
3718 // file, then the module files it depends on cannot have any categories,
3719 // so suppress further lookup.
3720 return Reader.isDeclIDFromModule(InterfaceID, M);
3721 }
3722
3723 // We found something. Dig out all of the categories.
3724 unsigned Offset = Result->Offset;
3725 unsigned N = M.ObjCCategories[Offset];
3726 M.ObjCCategories[Offset++] = 0; // Don't try to deserialize again
3727 for (unsigned I = 0; I != N; ++I)
3728 add(cast_or_null<ObjCCategoryDecl>(
3729 Reader.GetLocalDecl(M, M.ObjCCategories[Offset++])));
3730 return true;
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00003731 }
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00003732 };
Hans Wennborgdcfba332015-10-06 23:40:43 +00003733} // end anonymous namespace
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00003734
Douglas Gregor404cdde2012-01-27 01:47:08 +00003735void ASTReader::loadObjCCategories(serialization::GlobalDeclID ID,
3736 ObjCInterfaceDecl *D,
3737 unsigned PreviousGeneration) {
Alexander Shaposhnikov96cbe7b2016-09-24 02:07:19 +00003738 ObjCCategoriesVisitor Visitor(*this, D, CategoriesDeserialized, ID,
Douglas Gregor404cdde2012-01-27 01:47:08 +00003739 PreviousGeneration);
Benjamin Kramer9a9efba2015-07-25 12:14:04 +00003740 ModuleMgr.visit(Visitor);
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00003741}
Douglas Gregordab42432011-08-12 00:15:20 +00003742
Richard Smithd6db68c2014-08-07 20:58:41 +00003743template<typename DeclT, typename Fn>
3744static void forAllLaterRedecls(DeclT *D, Fn F) {
3745 F(D);
3746
3747 // Check whether we've already merged D into its redeclaration chain.
3748 // MostRecent may or may not be nullptr if D has not been merged. If
3749 // not, walk the merged redecl chain and see if it's there.
3750 auto *MostRecent = D->getMostRecentDecl();
3751 bool Found = false;
3752 for (auto *Redecl = MostRecent; Redecl && !Found;
3753 Redecl = Redecl->getPreviousDecl())
3754 Found = (Redecl == D);
3755
3756 // If this declaration is merged, apply the functor to all later decls.
3757 if (Found) {
3758 for (auto *Redecl = MostRecent; Redecl != D;
3759 Redecl = Redecl->getPreviousDecl())
3760 F(Redecl);
3761 }
3762}
3763
David L. Jonesc4808b9e2016-12-15 20:53:26 +00003764void ASTDeclReader::UpdateDecl(Decl *D) {
Argyrios Kyrtzidisd170d842010-10-24 17:26:50 +00003765 while (Idx < Record.size()) {
3766 switch ((DeclUpdateKind)Record[Idx++]) {
Richard Smithcd45dbc2014-04-19 03:48:30 +00003767 case UPD_CXX_ADDED_IMPLICIT_MEMBER: {
Richard Smith1b65dbc2015-01-22 03:50:31 +00003768 auto *RD = cast<CXXRecordDecl>(D);
Richard Smithd6db68c2014-08-07 20:58:41 +00003769 // FIXME: If we also have an update record for instantiating the
3770 // definition of D, we need that to happen before we get here.
David L. Jonesc4808b9e2016-12-15 20:53:26 +00003771 Decl *MD = Record.ReadDecl(Idx);
Richard Smithcd45dbc2014-04-19 03:48:30 +00003772 assert(MD && "couldn't read decl from update record");
Richard Smith46bb5812014-08-01 01:56:39 +00003773 // FIXME: We should call addHiddenDecl instead, to add the member
3774 // to its DeclContext.
Richard Smith1b65dbc2015-01-22 03:50:31 +00003775 RD->addedMember(MD);
Argyrios Kyrtzidise16a5302010-10-24 17:26:54 +00003776 break;
Richard Smithcd45dbc2014-04-19 03:48:30 +00003777 }
Argyrios Kyrtzidis402dbbb2010-10-28 07:38:42 +00003778
3779 case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION:
3780 // It will be added to the template's specializations set when loaded.
David L. Jonesc4808b9e2016-12-15 20:53:26 +00003781 (void)Record.ReadDecl(Idx);
Sebastian Redlfa1f3702011-04-24 16:28:13 +00003782 break;
3783
3784 case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: {
David L. Jonesc4808b9e2016-12-15 20:53:26 +00003785 NamespaceDecl *Anon = ReadDeclAs<NamespaceDecl>();
3786
Douglas Gregor540fd812012-01-09 18:07:24 +00003787 // Each module has its own anonymous namespace, which is disjoint from
3788 // any other module's anonymous namespaces, so don't attach the anonymous
3789 // namespace at all.
David L. Jonesc4808b9e2016-12-15 20:53:26 +00003790 if (!Record.isModule()) {
Douglas Gregor540fd812012-01-09 18:07:24 +00003791 if (TranslationUnitDecl *TU = dyn_cast<TranslationUnitDecl>(D))
3792 TU->setAnonymousNamespace(Anon);
3793 else
3794 cast<NamespaceDecl>(D)->setAnonymousNamespace(Anon);
3795 }
Sebastian Redlfa1f3702011-04-24 16:28:13 +00003796 break;
3797 }
Sebastian Redl2ac2c722011-04-29 08:19:30 +00003798
3799 case UPD_CXX_INSTANTIATED_STATIC_DATA_MEMBER:
3800 cast<VarDecl>(D)->getMemberSpecializationInfo()->setPointOfInstantiation(
David L. Jonesc4808b9e2016-12-15 20:53:26 +00003801 ReadSourceLocation());
Sebastian Redl2ac2c722011-04-29 08:19:30 +00003802 break;
Richard Smith1fa5d642013-05-11 05:45:24 +00003803
John McCall32791cc2016-01-06 22:34:54 +00003804 case UPD_CXX_INSTANTIATED_DEFAULT_ARGUMENT: {
3805 auto Param = cast<ParmVarDecl>(D);
3806
3807 // We have to read the default argument regardless of whether we use it
3808 // so that hypothetical further update records aren't messed up.
3809 // TODO: Add a function to skip over the next expr record.
David L. Jonesc4808b9e2016-12-15 20:53:26 +00003810 auto DefaultArg = Record.ReadExpr();
John McCall32791cc2016-01-06 22:34:54 +00003811
3812 // Only apply the update if the parameter still has an uninstantiated
3813 // default argument.
3814 if (Param->hasUninstantiatedDefaultArg())
3815 Param->setDefaultArg(DefaultArg);
3816 break;
3817 }
3818
Richard Smith4b054b22016-08-24 21:25:37 +00003819 case UPD_CXX_INSTANTIATED_DEFAULT_MEMBER_INITIALIZER: {
3820 auto FD = cast<FieldDecl>(D);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00003821 auto DefaultInit = Record.ReadExpr();
Richard Smith4b054b22016-08-24 21:25:37 +00003822
3823 // Only apply the update if the field still has an uninstantiated
3824 // default member initializer.
3825 if (FD->hasInClassInitializer() && !FD->getInClassInitializer()) {
3826 if (DefaultInit)
3827 FD->setInClassInitializer(DefaultInit);
3828 else
3829 // Instantiation failed. We can get here if we serialized an AST for
3830 // an invalid program.
3831 FD->removeInClassInitializer();
3832 }
3833 break;
3834 }
3835
Richard Smith4d235792014-08-07 18:53:08 +00003836 case UPD_CXX_ADDED_FUNCTION_DEFINITION: {
Richard Smithd28ac5b2014-03-22 23:33:22 +00003837 FunctionDecl *FD = cast<FunctionDecl>(D);
Richard Smithcd45dbc2014-04-19 03:48:30 +00003838 if (Reader.PendingBodies[FD]) {
Richard Smithd28ac5b2014-03-22 23:33:22 +00003839 // FIXME: Maybe check for ODR violations.
Richard Smithcd45dbc2014-04-19 03:48:30 +00003840 // It's safe to stop now because this update record is always last.
3841 return;
3842 }
Richard Smithd28ac5b2014-03-22 23:33:22 +00003843
Richard Smith195d8ef2014-05-29 03:15:31 +00003844 if (Record[Idx++]) {
3845 // Maintain AST consistency: any later redeclarations of this function
3846 // are inline if this one is. (We might have merged another declaration
3847 // into this one.)
Richard Smithd6db68c2014-08-07 20:58:41 +00003848 forAllLaterRedecls(FD, [](FunctionDecl *FD) {
3849 FD->setImplicitlyInline();
3850 });
Richard Smith195d8ef2014-05-29 03:15:31 +00003851 }
David L. Jonesc4808b9e2016-12-15 20:53:26 +00003852 FD->setInnerLocStart(ReadSourceLocation());
Richard Smithc2bb8182015-03-24 06:36:48 +00003853 if (auto *CD = dyn_cast<CXXConstructorDecl>(FD)) {
3854 CD->NumCtorInitializers = Record[Idx++];
3855 if (CD->NumCtorInitializers)
David L. Jonesc4808b9e2016-12-15 20:53:26 +00003856 CD->CtorInitializers = ReadGlobalOffset();
Richard Smithc2bb8182015-03-24 06:36:48 +00003857 }
Richard Smithd28ac5b2014-03-22 23:33:22 +00003858 // Store the offset of the body so we can lazily load it later.
3859 Reader.PendingBodies[FD] = GetCurrentCursorOffset();
Richard Smith04d05b52014-03-23 00:27:18 +00003860 HasPendingBody = true;
Richard Smithd28ac5b2014-03-22 23:33:22 +00003861 assert(Idx == Record.size() && "lazy body must be last");
3862 break;
3863 }
3864
Richard Smithcd45dbc2014-04-19 03:48:30 +00003865 case UPD_CXX_INSTANTIATED_CLASS_DEFINITION: {
3866 auto *RD = cast<CXXRecordDecl>(D);
Richard Smithb6483992016-05-17 22:44:15 +00003867 auto *OldDD = RD->getCanonicalDecl()->DefinitionData;
Richard Smith2a9e5c52015-02-03 03:32:14 +00003868 bool HadRealDefinition =
Richard Smith7483d202015-02-04 01:23:46 +00003869 OldDD && (OldDD->Definition != RD ||
3870 !Reader.PendingFakeDefinitionData.count(OldDD));
Richard Smith2a9e5c52015-02-03 03:32:14 +00003871 ReadCXXRecordDefinition(RD, /*Update*/true);
3872
Richard Smithcd45dbc2014-04-19 03:48:30 +00003873 // Visible update is handled separately.
David L. Jonesc4808b9e2016-12-15 20:53:26 +00003874 uint64_t LexicalOffset = ReadLocalOffset();
Richard Smith8a639892015-01-24 01:07:20 +00003875 if (!HadRealDefinition && LexicalOffset) {
David L. Jonesc4808b9e2016-12-15 20:53:26 +00003876 Record.ReadLexicalDeclContextStorage(LexicalOffset, RD);
Richard Smith2a9e5c52015-02-03 03:32:14 +00003877 Reader.PendingFakeDefinitionData.erase(OldDD);
Richard Smithcd45dbc2014-04-19 03:48:30 +00003878 }
3879
3880 auto TSK = (TemplateSpecializationKind)Record[Idx++];
David L. Jonesc4808b9e2016-12-15 20:53:26 +00003881 SourceLocation POI = ReadSourceLocation();
Richard Smithcd45dbc2014-04-19 03:48:30 +00003882 if (MemberSpecializationInfo *MSInfo =
3883 RD->getMemberSpecializationInfo()) {
3884 MSInfo->setTemplateSpecializationKind(TSK);
3885 MSInfo->setPointOfInstantiation(POI);
3886 } else {
3887 ClassTemplateSpecializationDecl *Spec =
3888 cast<ClassTemplateSpecializationDecl>(RD);
3889 Spec->setTemplateSpecializationKind(TSK);
3890 Spec->setPointOfInstantiation(POI);
Richard Smithdf352052014-05-22 20:59:29 +00003891
3892 if (Record[Idx++]) {
3893 auto PartialSpec =
David L. Jonesc4808b9e2016-12-15 20:53:26 +00003894 ReadDeclAs<ClassTemplatePartialSpecializationDecl>();
Richard Smithdf352052014-05-22 20:59:29 +00003895 SmallVector<TemplateArgument, 8> TemplArgs;
David L. Jonesc4808b9e2016-12-15 20:53:26 +00003896 Record.ReadTemplateArgumentList(TemplArgs, Idx);
Richard Smithdf352052014-05-22 20:59:29 +00003897 auto *TemplArgList = TemplateArgumentList::CreateCopy(
David Majnemer8b622692016-07-03 21:17:51 +00003898 Reader.getContext(), TemplArgs);
Richard Smith72544f82014-08-14 03:30:27 +00003899
3900 // FIXME: If we already have a partial specialization set,
3901 // check that it matches.
3902 if (!Spec->getSpecializedTemplateOrPartial()
3903 .is<ClassTemplatePartialSpecializationDecl *>())
3904 Spec->setInstantiationOf(PartialSpec, TemplArgList);
Richard Smithdf352052014-05-22 20:59:29 +00003905 }
Richard Smithcd45dbc2014-04-19 03:48:30 +00003906 }
3907
3908 RD->setTagKind((TagTypeKind)Record[Idx++]);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00003909 RD->setLocation(ReadSourceLocation());
3910 RD->setLocStart(ReadSourceLocation());
3911 RD->setBraceRange(ReadSourceRange());
Richard Smithcd45dbc2014-04-19 03:48:30 +00003912
3913 if (Record[Idx++]) {
3914 AttrVec Attrs;
David L. Jonesc4808b9e2016-12-15 20:53:26 +00003915 Record.ReadAttributes(Attrs, Idx);
Richard Smith842e46e2016-10-26 02:31:56 +00003916 // If the declaration already has attributes, we assume that some other
3917 // AST file already loaded them.
3918 if (!D->hasAttrs())
3919 D->setAttrsImpl(Attrs, Reader.getContext());
Richard Smithcd45dbc2014-04-19 03:48:30 +00003920 }
3921 break;
3922 }
3923
Richard Smithf8134002015-03-10 01:41:22 +00003924 case UPD_CXX_RESOLVED_DTOR_DELETE: {
3925 // Set the 'operator delete' directly to avoid emitting another update
3926 // record.
David L. Jonesc4808b9e2016-12-15 20:53:26 +00003927 auto *Del = ReadDeclAs<FunctionDecl>();
Richard Smithf8134002015-03-10 01:41:22 +00003928 auto *First = cast<CXXDestructorDecl>(D->getCanonicalDecl());
3929 // FIXME: Check consistency if we have an old and new operator delete.
3930 if (!First->OperatorDelete)
3931 First->OperatorDelete = Del;
3932 break;
3933 }
3934
Richard Smith564417a2014-03-20 21:47:22 +00003935 case UPD_CXX_RESOLVED_EXCEPTION_SPEC: {
Richard Smith8acb4282014-07-31 21:57:55 +00003936 FunctionProtoType::ExceptionSpecInfo ESI;
Richard Smith6de7a242014-07-31 23:46:44 +00003937 SmallVector<QualType, 8> ExceptionStorage;
David L. Jonesc4808b9e2016-12-15 20:53:26 +00003938 Record.readExceptionSpec(ExceptionStorage, ESI, Idx);
Richard Smith9e2341d2015-03-23 03:25:59 +00003939
3940 // Update this declaration's exception specification, if needed.
3941 auto *FD = cast<FunctionDecl>(D);
3942 auto *FPT = FD->getType()->castAs<FunctionProtoType>();
3943 // FIXME: If the exception specification is already present, check that it
3944 // matches.
3945 if (isUnresolvedExceptionSpec(FPT->getExceptionSpecType())) {
Richard Smith6de7a242014-07-31 23:46:44 +00003946 FD->setType(Reader.Context.getFunctionType(
3947 FPT->getReturnType(), FPT->getParamTypes(),
3948 FPT->getExtProtoInfo().withExceptionSpec(ESI)));
Richard Smith9e2341d2015-03-23 03:25:59 +00003949
3950 // When we get to the end of deserializing, see if there are other decls
3951 // that we need to propagate this exception specification onto.
3952 Reader.PendingExceptionSpecUpdates.insert(
3953 std::make_pair(FD->getCanonicalDecl(), FD));
Richard Smith6de7a242014-07-31 23:46:44 +00003954 }
Richard Smith564417a2014-03-20 21:47:22 +00003955 break;
3956 }
3957
Richard Smith1fa5d642013-05-11 05:45:24 +00003958 case UPD_CXX_DEDUCED_RETURN_TYPE: {
Richard Smithd6db68c2014-08-07 20:58:41 +00003959 // FIXME: Also do this when merging redecls.
David L. Jonesc4808b9e2016-12-15 20:53:26 +00003960 QualType DeducedResultType = Record.readType(Idx);
Richard Smithd6db68c2014-08-07 20:58:41 +00003961 for (auto *Redecl : merged_redecls(D)) {
3962 // FIXME: If the return type is already deduced, check that it matches.
3963 FunctionDecl *FD = cast<FunctionDecl>(Redecl);
3964 Reader.Context.adjustDeducedFunctionResultType(FD, DeducedResultType);
3965 }
Richard Smith1fa5d642013-05-11 05:45:24 +00003966 break;
3967 }
Eli Friedman276dd182013-09-05 00:02:25 +00003968
3969 case UPD_DECL_MARKED_USED: {
Richard Smith675d2792014-06-16 20:26:19 +00003970 // Maintain AST consistency: any later redeclarations are used too.
Vassil Vassilev19765fb2016-07-22 21:08:24 +00003971 D->markUsed(Reader.Context);
Eli Friedman276dd182013-09-05 00:02:25 +00003972 break;
3973 }
Richard Smith5652c0f2014-03-21 01:48:23 +00003974
3975 case UPD_MANGLING_NUMBER:
3976 Reader.Context.setManglingNumber(cast<NamedDecl>(D), Record[Idx++]);
3977 break;
3978
3979 case UPD_STATIC_LOCAL_NUMBER:
3980 Reader.Context.setStaticLocalNumber(cast<VarDecl>(D), Record[Idx++]);
3981 break;
Richard Smith65ebb4a2015-03-26 04:09:53 +00003982
Alexey Bataev97720002014-11-11 04:05:39 +00003983 case UPD_DECL_MARKED_OPENMP_THREADPRIVATE:
3984 D->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit(
David L. Jonesc4808b9e2016-12-15 20:53:26 +00003985 Reader.Context, ReadSourceRange()));
Alexey Bataev97720002014-11-11 04:05:39 +00003986 break;
Richard Smith65ebb4a2015-03-26 04:09:53 +00003987
Alex Denisovfde64952015-06-26 05:28:36 +00003988 case UPD_DECL_EXPORTED: {
David L. Jonesc4808b9e2016-12-15 20:53:26 +00003989 unsigned SubmoduleID = readSubmoduleID();
Richard Smithbeb44782015-06-20 01:05:19 +00003990 auto *Exported = cast<NamedDecl>(D);
3991 if (auto *TD = dyn_cast<TagDecl>(Exported))
3992 Exported = TD->getDefinition();
Richard Smith65ebb4a2015-03-26 04:09:53 +00003993 Module *Owner = SubmoduleID ? Reader.getSubmodule(SubmoduleID) : nullptr;
Richard Smith42413142015-05-15 20:05:43 +00003994 if (Reader.getContext().getLangOpts().ModulesLocalVisibility) {
Vassil Vassilev19765fb2016-07-22 21:08:24 +00003995 Reader.getContext().mergeDefinitionIntoModule(cast<NamedDecl>(Exported),
3996 Owner);
Richard Smith1e02a5a2015-06-25 21:42:33 +00003997 Reader.PendingMergedDefinitionsToDeduplicate.insert(
3998 cast<NamedDecl>(Exported));
Richard Smith42413142015-05-15 20:05:43 +00003999 } else if (Owner && Owner->NameVisibility != Module::AllVisible) {
Richard Smith65ebb4a2015-03-26 04:09:53 +00004000 // If Owner is made visible at some later point, make this declaration
4001 // visible too.
Richard Smith1e02a5a2015-06-25 21:42:33 +00004002 Reader.HiddenNamesMap[Owner].push_back(Exported);
Richard Smith65ebb4a2015-03-26 04:09:53 +00004003 } else {
4004 // The declaration is now visible.
Richard Smith1e02a5a2015-06-25 21:42:33 +00004005 Exported->Hidden = false;
Richard Smith65ebb4a2015-03-26 04:09:53 +00004006 }
4007 break;
Argyrios Kyrtzidisd170d842010-10-24 17:26:50 +00004008 }
Alex Denisovfde64952015-06-26 05:28:36 +00004009
Dmitry Polukhind69b5052016-05-09 14:59:13 +00004010 case UPD_DECL_MARKED_OPENMP_DECLARETARGET:
Alex Denisovfde64952015-06-26 05:28:36 +00004011 case UPD_ADDED_ATTR_TO_RECORD:
4012 AttrVec Attrs;
David L. Jonesc4808b9e2016-12-15 20:53:26 +00004013 Record.ReadAttributes(Attrs, Idx);
Alex Denisovfde64952015-06-26 05:28:36 +00004014 assert(Attrs.size() == 1);
4015 D->addAttr(Attrs[0]);
4016 break;
4017 }
Argyrios Kyrtzidisd170d842010-10-24 17:26:50 +00004018 }
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00004019}