blob: 8b9cb9677193f160e944b450b870efb8ba92edcc [file] [log] [blame]
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00001//===- ASTReaderDecl.cpp - Decl Deserialization ---------------------------===//
Chris Lattner487412d2009-04-27 05:27:42 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Chris Lattner487412d2009-04-27 05:27:42 +00006//
7//===----------------------------------------------------------------------===//
8//
Sebastian Redl2c499f62010-08-18 23:56:43 +00009// This file implements the ASTReader::ReadDeclRecord method, which is the
Chris Lattner487412d2009-04-27 05:27:42 +000010// entrypoint for loading a decl.
11//
12//===----------------------------------------------------------------------===//
13
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +000014#include "ASTCommon.h"
Benjamin Kramer89f0b2d2012-04-15 12:36:49 +000015#include "ASTReaderInternals.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000016#include "clang/AST/ASTContext.h"
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +000017#include "clang/AST/Attr.h"
18#include "clang/AST/AttrIterator.h"
19#include "clang/AST/Decl.h"
20#include "clang/AST/DeclBase.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000021#include "clang/AST/DeclCXX.h"
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +000022#include "clang/AST/DeclFriend.h"
23#include "clang/AST/DeclObjC.h"
24#include "clang/AST/DeclOpenMP.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000025#include "clang/AST/DeclTemplate.h"
26#include "clang/AST/DeclVisitor.h"
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +000027#include "clang/AST/DeclarationName.h"
Chandler Carruth3a022472012-12-04 09:13:33 +000028#include "clang/AST/Expr.h"
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +000029#include "clang/AST/ExternalASTSource.h"
30#include "clang/AST/LambdaCapture.h"
31#include "clang/AST/NestedNameSpecifier.h"
Kelvin Li1408f912018-09-26 04:28:39 +000032#include "clang/AST/OpenMPClause.h"
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +000033#include "clang/AST/Redeclarable.h"
34#include "clang/AST/Stmt.h"
35#include "clang/AST/TemplateBase.h"
36#include "clang/AST/Type.h"
37#include "clang/AST/UnresolvedSet.h"
38#include "clang/Basic/AttrKinds.h"
39#include "clang/Basic/ExceptionSpecificationType.h"
40#include "clang/Basic/IdentifierTable.h"
41#include "clang/Basic/LLVM.h"
42#include "clang/Basic/Lambda.h"
43#include "clang/Basic/LangOptions.h"
44#include "clang/Basic/Linkage.h"
45#include "clang/Basic/Module.h"
46#include "clang/Basic/PragmaKinds.h"
47#include "clang/Basic/SourceLocation.h"
48#include "clang/Basic/Specifiers.h"
Douglas Gregor022857e2011-12-22 01:48:48 +000049#include "clang/Sema/IdentifierResolver.h"
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +000050#include "clang/Serialization/ASTBitCodes.h"
Mehdi Amini9670f842016-07-18 19:02:11 +000051#include "clang/Serialization/ASTReader.h"
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +000052#include "clang/Serialization/ContinuousRangeMap.h"
Duncan P. N. Exon Smithf7170d12019-11-21 18:49:05 -080053#include "clang/Serialization/ModuleFile.h"
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +000054#include "llvm/ADT/DenseMap.h"
55#include "llvm/ADT/FoldingSet.h"
56#include "llvm/ADT/STLExtras.h"
57#include "llvm/ADT/SmallPtrSet.h"
58#include "llvm/ADT/SmallVector.h"
59#include "llvm/ADT/iterator_range.h"
Francis Visoiu Mistrihe0308272019-07-03 22:40:07 +000060#include "llvm/Bitstream/BitstreamReader.h"
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +000061#include "llvm/Support/Casting.h"
62#include "llvm/Support/ErrorHandling.h"
Argyrios Kyrtzidis0f7d7ab2012-05-04 01:49:36 +000063#include "llvm/Support/SaveAndRestore.h"
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +000064#include <algorithm>
65#include <cassert>
66#include <cstdint>
67#include <cstring>
68#include <string>
69#include <utility>
Hans Wennborgdcfba332015-10-06 23:40:43 +000070
Chris Lattner487412d2009-04-27 05:27:42 +000071using namespace clang;
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +000072using namespace serialization;
Chris Lattner487412d2009-04-27 05:27:42 +000073
74//===----------------------------------------------------------------------===//
75// Declaration deserialization
76//===----------------------------------------------------------------------===//
77
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +000078namespace clang {
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +000079
Sebastian Redlb3298c32010-08-18 23:56:48 +000080 class ASTDeclReader : public DeclVisitor<ASTDeclReader, void> {
Sebastian Redl2c499f62010-08-18 23:56:43 +000081 ASTReader &Reader;
David L. Jonesbe1557a2016-12-21 00:17:49 +000082 ASTRecordReader &Record;
David L. Jonesc4808b9e2016-12-15 20:53:26 +000083 ASTReader::RecordLocation Loc;
Sebastian Redl539c5062010-08-18 23:57:32 +000084 const DeclID ThisDeclID;
Richard Smithcb34bd32016-03-27 07:28:06 +000085 const SourceLocation ThisDeclLoc;
Vassil Vassilev6565dfc2016-02-26 10:43:34 +000086
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +000087 using RecordData = ASTReader::RecordData;
88
Richard Smith600adef2018-07-04 02:25:38 +000089 TypeID DeferredTypeID = 0;
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +000090 unsigned AnonymousDeclNumber;
91 GlobalDeclID NamedDeclForTagDecl = 0;
92 IdentifierInfo *TypedefNameForLinkage = nullptr;
93
94 bool HasPendingBody = false;
Daniel Jasper4a6d5b72017-10-11 07:47:54 +000095
Adrian Prantl9fc8faf2018-05-09 01:00:01 +000096 ///A flag to carry the information for a decl from the entity is
Vassil Vassilev928c8252016-04-28 14:13:28 +000097 /// used. We use it to delay the marking of the canonical decl as used until
98 /// the entire declaration is deserialized and merged.
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +000099 bool IsDeclMarkedUsed = false;
Vassil Vassilev928c8252016-04-28 14:13:28 +0000100
Sebastian Redlc67764e2010-07-22 22:43:28 +0000101 uint64_t GetCurrentCursorOffset();
Vassil Vassilev6565dfc2016-02-26 10:43:34 +0000102
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000103 uint64_t ReadLocalOffset() {
David L. Jonesbe1557a2016-12-21 00:17:49 +0000104 uint64_t LocalOffset = Record.readInt();
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000105 assert(LocalOffset < Loc.Offset && "offset point after current record");
106 return LocalOffset ? Loc.Offset - LocalOffset : 0;
Richard Smithe37e9f42016-03-25 01:17:43 +0000107 }
108
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000109 uint64_t ReadGlobalOffset() {
110 uint64_t Local = ReadLocalOffset();
111 return Local ? Record.getGlobalBitOffset(Local) : 0;
Richard Smithaa165cf2016-04-13 21:57:08 +0000112 }
113
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000114 SourceLocation ReadSourceLocation() {
David L. Jonesb6a8f022016-12-21 04:34:52 +0000115 return Record.readSourceLocation();
Sebastian Redl2c373b92010-10-05 15:59:54 +0000116 }
Vassil Vassilev6565dfc2016-02-26 10:43:34 +0000117
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000118 SourceRange ReadSourceRange() {
David L. Jonesb6a8f022016-12-21 04:34:52 +0000119 return Record.readSourceRange();
Sebastian Redl2c373b92010-10-05 15:59:54 +0000120 }
Vassil Vassilev6565dfc2016-02-26 10:43:34 +0000121
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000122 TypeSourceInfo *GetTypeSourceInfo() {
David L. Jonesb6a8f022016-12-21 04:34:52 +0000123 return Record.getTypeSourceInfo();
Sebastian Redl2c373b92010-10-05 15:59:54 +0000124 }
Vassil Vassilev6565dfc2016-02-26 10:43:34 +0000125
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000126 serialization::DeclID ReadDeclID() {
David L. Jonesb6a8f022016-12-21 04:34:52 +0000127 return Record.readDeclID();
Douglas Gregor7fb09192011-07-21 22:35:25 +0000128 }
Richard Smith0b884372015-02-27 00:25:58 +0000129
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000130 std::string ReadString() {
David L. Jonesb6a8f022016-12-21 04:34:52 +0000131 return Record.readString();
Nico Weber66220292016-03-02 17:28:48 +0000132 }
133
Richard Smith0b884372015-02-27 00:25:58 +0000134 void ReadDeclIDList(SmallVectorImpl<DeclID> &IDs) {
David L. Jonesbe1557a2016-12-21 00:17:49 +0000135 for (unsigned I = 0, Size = Record.readInt(); I != Size; ++I)
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000136 IDs.push_back(ReadDeclID());
Richard Smith0b884372015-02-27 00:25:58 +0000137 }
138
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000139 Decl *ReadDecl() {
David L. Jonesb6a8f022016-12-21 04:34:52 +0000140 return Record.readDecl();
Douglas Gregor7fb09192011-07-21 22:35:25 +0000141 }
142
143 template<typename T>
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000144 T *ReadDeclAs() {
David L. Jonesb6a8f022016-12-21 04:34:52 +0000145 return Record.readDeclAs<T>();
Douglas Gregor7fb09192011-07-21 22:35:25 +0000146 }
147
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000148 void ReadQualifierInfo(QualifierInfo &Info) {
David L. Jonesb6a8f022016-12-21 04:34:52 +0000149 Record.readQualifierInfo(Info);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000150 }
Sebastian Redlc67764e2010-07-22 22:43:28 +0000151
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000152 void ReadDeclarationNameLoc(DeclarationNameLoc &DNLoc, DeclarationName Name) {
David L. Jonesb6a8f022016-12-21 04:34:52 +0000153 Record.readDeclarationNameLoc(DNLoc, Name);
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000154 }
155
156 serialization::SubmoduleID readSubmoduleID() {
David L. Jonesbe1557a2016-12-21 00:17:49 +0000157 if (Record.getIdx() == Record.size())
Douglas Gregorcf68c582011-12-01 22:20:10 +0000158 return 0;
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000159
David L. Jonesbe1557a2016-12-21 00:17:49 +0000160 return Record.getGlobalSubmoduleID(Record.readInt());
Douglas Gregorcf68c582011-12-01 22:20:10 +0000161 }
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000162
163 Module *readModule() {
164 return Record.getSubmodule(readSubmoduleID());
Douglas Gregorba345522011-12-02 23:23:56 +0000165 }
Richard Smithcd45dbc2014-04-19 03:48:30 +0000166
Richard Smith2a9e5c52015-02-03 03:32:14 +0000167 void ReadCXXRecordDefinition(CXXRecordDecl *D, bool Update);
David Blaikie1ac9c982017-04-11 21:13:37 +0000168 void ReadCXXDefinitionData(struct CXXRecordDecl::DefinitionData &Data,
169 const CXXRecordDecl *D);
Richard Smithcd45dbc2014-04-19 03:48:30 +0000170 void MergeDefinitionData(CXXRecordDecl *D,
Richard Smith8a639892015-01-24 01:07:20 +0000171 struct CXXRecordDecl::DefinitionData &&NewDD);
David L. Jonesbe1557a2016-12-21 00:17:49 +0000172 void ReadObjCDefinitionData(struct ObjCInterfaceDecl::DefinitionData &Data);
Manman Renec315f12016-09-09 23:48:27 +0000173 void MergeDefinitionData(ObjCInterfaceDecl *D,
174 struct ObjCInterfaceDecl::DefinitionData &&NewDD);
Graydon Hoaree0a68352017-06-28 18:36:27 +0000175 void ReadObjCDefinitionData(struct ObjCProtocolDecl::DefinitionData &Data);
176 void MergeDefinitionData(ObjCProtocolDecl *D,
177 struct ObjCProtocolDecl::DefinitionData &&NewDD);
Argyrios Kyrtzidiseb39d9a2010-10-24 17:26:40 +0000178
Richard Smith600adef2018-07-04 02:25:38 +0000179 static DeclContext *getPrimaryDCForAnonymousDecl(DeclContext *LexicalDC);
180
Richard Smithd08aeb62014-08-28 01:33:39 +0000181 static NamedDecl *getAnonymousDeclForMerging(ASTReader &Reader,
182 DeclContext *DC,
183 unsigned Index);
184 static void setAnonymousDeclForMerging(ASTReader &Reader, DeclContext *DC,
185 unsigned Index, NamedDecl *D);
186
Richard Smith0144f512015-08-22 02:09:38 +0000187 /// Results from loading a RedeclarableDecl.
Douglas Gregor022857e2011-12-22 01:48:48 +0000188 class RedeclarableResult {
Richard Smith5a4737c2015-02-06 02:42:59 +0000189 Decl *MergeWith;
Alexander Shaposhnikovfbc4d682016-09-24 04:21:53 +0000190 GlobalDeclID FirstID;
Richard Smith5fc18a92015-07-12 23:43:21 +0000191 bool IsKeyDecl;
Richard Smithc89bb9d2015-02-25 01:11:29 +0000192
Douglas Gregor022857e2011-12-22 01:48:48 +0000193 public:
Alexander Shaposhnikovfbc4d682016-09-24 04:21:53 +0000194 RedeclarableResult(Decl *MergeWith, GlobalDeclID FirstID, bool IsKeyDecl)
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +0000195 : MergeWith(MergeWith), FirstID(FirstID), IsKeyDecl(IsKeyDecl) {}
Richard Smith9b88a4c2015-07-27 05:40:23 +0000196
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000197 /// Retrieve the first ID.
Douglas Gregor022857e2011-12-22 01:48:48 +0000198 GlobalDeclID getFirstID() const { return FirstID; }
Richard Smith5a4737c2015-02-06 02:42:59 +0000199
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000200 /// Is this declaration a key declaration?
Richard Smith5fc18a92015-07-12 23:43:21 +0000201 bool isKeyDecl() const { return IsKeyDecl; }
202
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000203 /// Get a known declaration that this should be merged with, if
Richard Smith5a4737c2015-02-06 02:42:59 +0000204 /// any.
205 Decl *getKnownMergeTarget() const { return MergeWith; }
Douglas Gregor022857e2011-12-22 01:48:48 +0000206 };
Douglas Gregorfe732d52013-01-21 16:16:40 +0000207
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000208 /// Class used to capture the result of searching for an existing
Douglas Gregor022857e2011-12-22 01:48:48 +0000209 /// declaration of a specific kind and name, along with the ability
210 /// to update the place where this result was found (the declaration
211 /// chain hanging off an identifier or the DeclContext we searched in)
212 /// if requested.
213 class FindExistingResult {
214 ASTReader &Reader;
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +0000215 NamedDecl *New = nullptr;
216 NamedDecl *Existing = nullptr;
217 bool AddResult = false;
218 unsigned AnonymousDeclNumber = 0;
219 IdentifierInfo *TypedefNameForLinkage = nullptr;
Richard Smithd08aeb62014-08-28 01:33:39 +0000220
Douglas Gregor022857e2011-12-22 01:48:48 +0000221 public:
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +0000222 FindExistingResult(ASTReader &Reader) : Reader(Reader) {}
Craig Toppera13603a2014-05-22 05:54:18 +0000223
Richard Smithd08aeb62014-08-28 01:33:39 +0000224 FindExistingResult(ASTReader &Reader, NamedDecl *New, NamedDecl *Existing,
Richard Smith70d58502014-08-30 00:04:23 +0000225 unsigned AnonymousDeclNumber,
226 IdentifierInfo *TypedefNameForLinkage)
Richard Smithd08aeb62014-08-28 01:33:39 +0000227 : Reader(Reader), New(New), Existing(Existing), AddResult(true),
Richard Smith70d58502014-08-30 00:04:23 +0000228 AnonymousDeclNumber(AnonymousDeclNumber),
229 TypedefNameForLinkage(TypedefNameForLinkage) {}
Richard Smithd08aeb62014-08-28 01:33:39 +0000230
Benjamin Kramerb6aadc12016-08-06 12:45:16 +0000231 FindExistingResult(FindExistingResult &&Other)
Richard Smithd08aeb62014-08-28 01:33:39 +0000232 : Reader(Other.Reader), New(Other.New), Existing(Other.Existing),
233 AddResult(Other.AddResult),
Richard Smith70d58502014-08-30 00:04:23 +0000234 AnonymousDeclNumber(Other.AnonymousDeclNumber),
235 TypedefNameForLinkage(Other.TypedefNameForLinkage) {
Douglas Gregor022857e2011-12-22 01:48:48 +0000236 Other.AddResult = false;
237 }
Richard Smithd08aeb62014-08-28 01:33:39 +0000238
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +0000239 FindExistingResult &operator=(FindExistingResult &&) = delete;
Douglas Gregor022857e2011-12-22 01:48:48 +0000240 ~FindExistingResult();
Richard Smithd08aeb62014-08-28 01:33:39 +0000241
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000242 /// Suppress the addition of this result into the known set of
Douglas Gregor2009cee2012-01-03 22:46:00 +0000243 /// names.
244 void suppress() { AddResult = false; }
Richard Smithd08aeb62014-08-28 01:33:39 +0000245
Douglas Gregor022857e2011-12-22 01:48:48 +0000246 operator NamedDecl*() const { return Existing; }
Richard Smithd08aeb62014-08-28 01:33:39 +0000247
Douglas Gregor022857e2011-12-22 01:48:48 +0000248 template<typename T>
249 operator T*() const { return dyn_cast_or_null<T>(Existing); }
250 };
Richard Smithd08aeb62014-08-28 01:33:39 +0000251
Richard Smith8a639892015-01-24 01:07:20 +0000252 static DeclContext *getPrimaryContextForMerging(ASTReader &Reader,
253 DeclContext *DC);
Douglas Gregor022857e2011-12-22 01:48:48 +0000254 FindExistingResult findExisting(NamedDecl *D);
Richard Smithd08aeb62014-08-28 01:33:39 +0000255
Chris Lattner487412d2009-04-27 05:27:42 +0000256 public:
David L. Jonesbe1557a2016-12-21 00:17:49 +0000257 ASTDeclReader(ASTReader &Reader, ASTRecordReader &Record,
258 ASTReader::RecordLocation Loc,
259 DeclID thisDeclID, SourceLocation ThisDeclLoc)
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +0000260 : Reader(Reader), Record(Record), Loc(Loc), ThisDeclID(thisDeclID),
261 ThisDeclLoc(ThisDeclLoc) {}
Chris Lattner487412d2009-04-27 05:27:42 +0000262
Vassil Vassilev7d264622017-06-30 22:40:17 +0000263 template <typename T> static
264 void AddLazySpecializations(T *D,
265 SmallVectorImpl<serialization::DeclID>& IDs) {
266 if (IDs.empty())
267 return;
268
269 // FIXME: We should avoid this pattern of getting the ASTContext.
270 ASTContext &C = D->getASTContext();
271
272 auto *&LazySpecializations = D->getCommonPtr()->LazySpecializations;
273
274 if (auto &Old = LazySpecializations) {
275 IDs.insert(IDs.end(), Old + 1, Old + 1 + Old[0]);
Fangrui Song55fab262018-09-26 22:16:28 +0000276 llvm::sort(IDs);
Vassil Vassilev7d264622017-06-30 22:40:17 +0000277 IDs.erase(std::unique(IDs.begin(), IDs.end()), IDs.end());
278 }
279
280 auto *Result = new (C) serialization::DeclID[1 + IDs.size()];
281 *Result = IDs.size();
282 std::copy(IDs.begin(), IDs.end(), Result + 1);
283
284 LazySpecializations = Result;
285 }
286
Richard Smithb321ecb2014-05-13 01:15:00 +0000287 template <typename DeclT>
Richard Smithc3a53252015-02-28 05:57:02 +0000288 static Decl *getMostRecentDeclImpl(Redeclarable<DeclT> *D);
289 static Decl *getMostRecentDeclImpl(...);
290 static Decl *getMostRecentDecl(Decl *D);
291
292 template <typename DeclT>
Richard Smith6de7a242014-07-31 23:46:44 +0000293 static void attachPreviousDeclImpl(ASTReader &Reader,
Richard Smith9e2341d2015-03-23 03:25:59 +0000294 Redeclarable<DeclT> *D, Decl *Previous,
295 Decl *Canon);
Richard Smith6de7a242014-07-31 23:46:44 +0000296 static void attachPreviousDeclImpl(ASTReader &Reader, ...);
Richard Smith9e2341d2015-03-23 03:25:59 +0000297 static void attachPreviousDecl(ASTReader &Reader, Decl *D, Decl *Previous,
298 Decl *Canon);
Richard Smithb321ecb2014-05-13 01:15:00 +0000299
300 template <typename DeclT>
301 static void attachLatestDeclImpl(Redeclarable<DeclT> *D, Decl *Latest);
302 static void attachLatestDeclImpl(...);
Douglas Gregor05f10352011-12-17 23:38:30 +0000303 static void attachLatestDecl(Decl *D, Decl *latest);
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +0000304
Richard Smith851072e2014-05-19 20:59:20 +0000305 template <typename DeclT>
306 static void markIncompleteDeclChainImpl(Redeclarable<DeclT> *D);
307 static void markIncompleteDeclChainImpl(...);
308
Adrian Prantl9fc8faf2018-05-09 01:00:01 +0000309 /// Determine whether this declaration has a pending body.
Daniel Jasper4a6d5b72017-10-11 07:47:54 +0000310 bool hasPendingBody() const { return HasPendingBody; }
311
David Blaikieac4345c2017-02-12 18:45:31 +0000312 void ReadFunctionDefinition(FunctionDecl *FD);
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000313 void Visit(Decl *D);
314
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +0000315 void UpdateDecl(Decl *D, SmallVectorImpl<serialization::DeclID> &);
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +0000316
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +0000317 static void setNextObjCCategory(ObjCCategoryDecl *Cat,
318 ObjCCategoryDecl *Next) {
319 Cat->NextClassCategory = Next;
320 }
321
Chris Lattner487412d2009-04-27 05:27:42 +0000322 void VisitDecl(Decl *D);
Nico Weber66220292016-03-02 17:28:48 +0000323 void VisitPragmaCommentDecl(PragmaCommentDecl *D);
Nico Webercbbaeb12016-03-02 19:28:54 +0000324 void VisitPragmaDetectMismatchDecl(PragmaDetectMismatchDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000325 void VisitTranslationUnitDecl(TranslationUnitDecl *TU);
326 void VisitNamedDecl(NamedDecl *ND);
Chris Lattnerc8e630e2011-02-17 07:39:24 +0000327 void VisitLabelDecl(LabelDecl *LD);
Douglas Gregore31bbd92010-02-21 18:22:14 +0000328 void VisitNamespaceDecl(NamespaceDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000329 void VisitUsingDirectiveDecl(UsingDirectiveDecl *D);
330 void VisitNamespaceAliasDecl(NamespaceAliasDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000331 void VisitTypeDecl(TypeDecl *TD);
Richard Smith43ccec8e2014-08-26 03:52:16 +0000332 RedeclarableResult VisitTypedefNameDecl(TypedefNameDecl *TD);
Chris Lattner487412d2009-04-27 05:27:42 +0000333 void VisitTypedefDecl(TypedefDecl *TD);
Richard Smithdda56e42011-04-15 14:24:37 +0000334 void VisitTypeAliasDecl(TypeAliasDecl *TD);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +0000335 void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D);
Richard Smith1d209d02013-05-23 01:49:11 +0000336 RedeclarableResult VisitTagDecl(TagDecl *TD);
Chris Lattner487412d2009-04-27 05:27:42 +0000337 void VisitEnumDecl(EnumDecl *ED);
Richard Smith1d209d02013-05-23 01:49:11 +0000338 RedeclarableResult VisitRecordDeclImpl(RecordDecl *RD);
339 void VisitRecordDecl(RecordDecl *RD) { VisitRecordDeclImpl(RD); }
340 RedeclarableResult VisitCXXRecordDeclImpl(CXXRecordDecl *D);
341 void VisitCXXRecordDecl(CXXRecordDecl *D) { VisitCXXRecordDeclImpl(D); }
342 RedeclarableResult VisitClassTemplateSpecializationDeclImpl(
Chris Lattnerca025db2010-05-07 21:43:38 +0000343 ClassTemplateSpecializationDecl *D);
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +0000344
Richard Smith1d209d02013-05-23 01:49:11 +0000345 void VisitClassTemplateSpecializationDecl(
346 ClassTemplateSpecializationDecl *D) {
347 VisitClassTemplateSpecializationDeclImpl(D);
348 }
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +0000349
Chris Lattnerca025db2010-05-07 21:43:38 +0000350 void VisitClassTemplatePartialSpecializationDecl(
351 ClassTemplatePartialSpecializationDecl *D);
Sebastian Redlb7448632011-08-31 13:59:56 +0000352 void VisitClassScopeFunctionSpecializationDecl(
353 ClassScopeFunctionSpecializationDecl *D);
Larisse Voufo39a1e502013-08-06 01:03:05 +0000354 RedeclarableResult
355 VisitVarTemplateSpecializationDeclImpl(VarTemplateSpecializationDecl *D);
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +0000356
Larisse Voufo39a1e502013-08-06 01:03:05 +0000357 void VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D) {
358 VisitVarTemplateSpecializationDeclImpl(D);
359 }
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +0000360
Larisse Voufo39a1e502013-08-06 01:03:05 +0000361 void VisitVarTemplatePartialSpecializationDecl(
362 VarTemplatePartialSpecializationDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000363 void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000364 void VisitValueDecl(ValueDecl *VD);
365 void VisitEnumConstantDecl(EnumConstantDecl *ECD);
Argyrios Kyrtzidisbd8ac8c2010-06-30 08:49:30 +0000366 void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D);
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000367 void VisitDeclaratorDecl(DeclaratorDecl *DD);
Chris Lattner487412d2009-04-27 05:27:42 +0000368 void VisitFunctionDecl(FunctionDecl *FD);
Richard Smithbc491202017-02-17 20:05:37 +0000369 void VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *GD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000370 void VisitCXXMethodDecl(CXXMethodDecl *D);
371 void VisitCXXConstructorDecl(CXXConstructorDecl *D);
372 void VisitCXXDestructorDecl(CXXDestructorDecl *D);
373 void VisitCXXConversionDecl(CXXConversionDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000374 void VisitFieldDecl(FieldDecl *FD);
John McCall5e77d762013-04-16 07:28:30 +0000375 void VisitMSPropertyDecl(MSPropertyDecl *FD);
Francois Pichet783dd6e2010-11-21 06:08:52 +0000376 void VisitIndirectFieldDecl(IndirectFieldDecl *FD);
Larisse Voufo39a1e502013-08-06 01:03:05 +0000377 RedeclarableResult VisitVarDeclImpl(VarDecl *D);
378 void VisitVarDecl(VarDecl *VD) { VisitVarDeclImpl(VD); }
Chris Lattner487412d2009-04-27 05:27:42 +0000379 void VisitImplicitParamDecl(ImplicitParamDecl *PD);
380 void VisitParmVarDecl(ParmVarDecl *PD);
Richard Smith7b76d812016-08-12 02:21:25 +0000381 void VisitDecompositionDecl(DecompositionDecl *DD);
382 void VisitBindingDecl(BindingDecl *BD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000383 void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D);
Richard Smithf17fdbd2014-04-24 02:25:27 +0000384 DeclID VisitTemplateDecl(TemplateDecl *D);
Saar Razd7aae332019-07-10 21:25:49 +0000385 void VisitConceptDecl(ConceptDecl *D);
Douglas Gregor54079202012-01-06 22:05:37 +0000386 RedeclarableResult VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000387 void VisitClassTemplateDecl(ClassTemplateDecl *D);
David Majnemerd9b1a4f2015-11-04 03:40:30 +0000388 void VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D);
Larisse Voufo39a1e502013-08-06 01:03:05 +0000389 void VisitVarTemplateDecl(VarTemplateDecl *D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000390 void VisitFunctionTemplateDecl(FunctionTemplateDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000391 void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D);
Richard Smith3f1b5d02011-05-05 21:57:07 +0000392 void VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D);
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +0000393 void VisitUsingDecl(UsingDecl *D);
Richard Smith151c4562016-12-20 21:35:28 +0000394 void VisitUsingPackDecl(UsingPackDecl *D);
Argyrios Kyrtzidis41d45622010-06-20 14:40:59 +0000395 void VisitUsingShadowDecl(UsingShadowDecl *D);
Richard Smith5179eb72016-06-28 19:03:57 +0000396 void VisitConstructorUsingShadowDecl(ConstructorUsingShadowDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000397 void VisitLinkageSpecDecl(LinkageSpecDecl *D);
Richard Smith8df390f2016-09-08 23:14:54 +0000398 void VisitExportDecl(ExportDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000399 void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD);
Douglas Gregorba345522011-12-02 23:23:56 +0000400 void VisitImportDecl(ImportDecl *D);
Abramo Bagnarad7340582010-06-05 05:09:32 +0000401 void VisitAccessSpecDecl(AccessSpecDecl *D);
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +0000402 void VisitFriendDecl(FriendDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000403 void VisitFriendTemplateDecl(FriendTemplateDecl *D);
404 void VisitStaticAssertDecl(StaticAssertDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000405 void VisitBlockDecl(BlockDecl *BD);
Tareq A. Siraj6dfa25a2013-04-16 19:37:38 +0000406 void VisitCapturedDecl(CapturedDecl *CD);
Michael Han84324352013-02-22 17:15:32 +0000407 void VisitEmptyDecl(EmptyDecl *D);
Tykerb0561b32019-11-17 11:41:55 +0100408 void VisitLifetimeExtendedTemporaryDecl(LifetimeExtendedTemporaryDecl *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000409
Chris Lattner487412d2009-04-27 05:27:42 +0000410 std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC);
Richard Smithf17fdbd2014-04-24 02:25:27 +0000411
412 template<typename T>
Douglas Gregor022857e2011-12-22 01:48:48 +0000413 RedeclarableResult VisitRedeclarable(Redeclarable<T> *D);
Chris Lattnerca025db2010-05-07 21:43:38 +0000414
Douglas Gregor2c46b5b2012-01-03 17:27:13 +0000415 template<typename T>
Richard Smithf17fdbd2014-04-24 02:25:27 +0000416 void mergeRedeclarable(Redeclarable<T> *D, RedeclarableResult &Redecl,
417 DeclID TemplatePatternID = 0);
Richard Smithd55889a2013-09-09 16:55:27 +0000418
419 template<typename T>
420 void mergeRedeclarable(Redeclarable<T> *D, T *Existing,
Richard Smithf17fdbd2014-04-24 02:25:27 +0000421 RedeclarableResult &Redecl,
422 DeclID TemplatePatternID = 0);
Richard Smithd55889a2013-09-09 16:55:27 +0000423
Richard Smith0b87e072013-10-07 08:02:11 +0000424 template<typename T>
425 void mergeMergeable(Mergeable<T> *D);
426
Tyker9ec6d712019-11-30 16:42:33 +0100427 void mergeMergeable(LifetimeExtendedTemporaryDecl *D);
428
Richard Smithf17fdbd2014-04-24 02:25:27 +0000429 void mergeTemplatePattern(RedeclarableTemplateDecl *D,
430 RedeclarableTemplateDecl *Existing,
Richard Smith5fc18a92015-07-12 23:43:21 +0000431 DeclID DsID, bool IsKeyDecl);
Richard Smithf17fdbd2014-04-24 02:25:27 +0000432
Douglas Gregor85f3f952015-07-07 03:57:15 +0000433 ObjCTypeParamList *ReadObjCTypeParamList();
434
Alexis Hunted053252010-05-30 07:21:58 +0000435 // FIXME: Reorder according to DeclNodes.td?
Chris Lattner487412d2009-04-27 05:27:42 +0000436 void VisitObjCMethodDecl(ObjCMethodDecl *D);
Douglas Gregor85f3f952015-07-07 03:57:15 +0000437 void VisitObjCTypeParamDecl(ObjCTypeParamDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000438 void VisitObjCContainerDecl(ObjCContainerDecl *D);
439 void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D);
440 void VisitObjCIvarDecl(ObjCIvarDecl *D);
441 void VisitObjCProtocolDecl(ObjCProtocolDecl *D);
442 void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000443 void VisitObjCCategoryDecl(ObjCCategoryDecl *D);
444 void VisitObjCImplDecl(ObjCImplDecl *D);
445 void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D);
446 void VisitObjCImplementationDecl(ObjCImplementationDecl *D);
447 void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D);
448 void VisitObjCPropertyDecl(ObjCPropertyDecl *D);
449 void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D);
Alexey Bataeva769e072013-03-22 06:34:35 +0000450 void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D);
Alexey Bataev25ed0c02019-03-07 17:54:44 +0000451 void VisitOMPAllocateDecl(OMPAllocateDecl *D);
Alexey Bataev94a4f0c2016-03-03 05:21:39 +0000452 void VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D);
Michael Kruse251e1482019-02-01 20:25:04 +0000453 void VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D);
Kelvin Li1408f912018-09-26 04:28:39 +0000454 void VisitOMPRequiresDecl(OMPRequiresDecl *D);
Alexey Bataev4244be22016-02-11 05:35:55 +0000455 void VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D);
Chris Lattner487412d2009-04-27 05:27:42 +0000456 };
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +0000457
458} // namespace clang
Chris Lattner487412d2009-04-27 05:27:42 +0000459
Richard Smith86dfc1e2015-06-18 22:07:00 +0000460namespace {
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +0000461
Richard Smith86dfc1e2015-06-18 22:07:00 +0000462/// Iterator over the redeclarations of a declaration that have already
463/// been merged into the same redeclaration chain.
464template<typename DeclT>
465class MergedRedeclIterator {
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +0000466 DeclT *Start;
467 DeclT *Canonical = nullptr;
468 DeclT *Current = nullptr;
469
Richard Smith86dfc1e2015-06-18 22:07:00 +0000470public:
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +0000471 MergedRedeclIterator() = default;
472 MergedRedeclIterator(DeclT *Start) : Start(Start), Current(Start) {}
Richard Smith86dfc1e2015-06-18 22:07:00 +0000473
474 DeclT *operator*() { return Current; }
475
476 MergedRedeclIterator &operator++() {
477 if (Current->isFirstDecl()) {
478 Canonical = Current;
Daniel Jasper4a6d5b72017-10-11 07:47:54 +0000479 Current = Current->getMostRecentDecl();
Richard Smith86dfc1e2015-06-18 22:07:00 +0000480 } else
481 Current = Current->getPreviousDecl();
482
483 // If we started in the merged portion, we'll reach our start position
484 // eventually. Otherwise, we'll never reach it, but the second declaration
485 // we reached was the canonical declaration, so stop when we see that one
486 // again.
487 if (Current == Start || Current == Canonical)
488 Current = nullptr;
489 return *this;
490 }
491
492 friend bool operator!=(const MergedRedeclIterator &A,
493 const MergedRedeclIterator &B) {
494 return A.Current != B.Current;
495 }
496};
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +0000497
498} // namespace
Hans Wennborgdcfba332015-10-06 23:40:43 +0000499
Benjamin Kramera0a13c32016-08-06 11:21:04 +0000500template <typename DeclT>
501static llvm::iterator_range<MergedRedeclIterator<DeclT>>
502merged_redecls(DeclT *D) {
Craig Topper59c2ada2015-12-06 05:07:12 +0000503 return llvm::make_range(MergedRedeclIterator<DeclT>(D),
504 MergedRedeclIterator<DeclT>());
Richard Smith86dfc1e2015-06-18 22:07:00 +0000505}
506
Sebastian Redlb3298c32010-08-18 23:56:48 +0000507uint64_t ASTDeclReader::GetCurrentCursorOffset() {
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000508 return Loc.F->DeclsCursor.GetCurrentBitNo() + Loc.F->GlobalBitOffset;
Sebastian Redlc67764e2010-07-22 22:43:28 +0000509}
510
David Blaikieac4345c2017-02-12 18:45:31 +0000511void ASTDeclReader::ReadFunctionDefinition(FunctionDecl *FD) {
Daniel Jasper4a6d5b72017-10-11 07:47:54 +0000512 if (Record.readInt())
Richard Smitha4653622017-09-06 20:01:14 +0000513 Reader.DefinitionSource[FD] = Loc.F->Kind == ModuleKind::MK_MainFile;
David Blaikieac4345c2017-02-12 18:45:31 +0000514 if (auto *CD = dyn_cast<CXXConstructorDecl>(FD)) {
Erich Keane9c665062018-08-01 21:02:40 +0000515 CD->setNumCtorInitializers(Record.readInt());
516 if (CD->getNumCtorInitializers())
David Blaikieac4345c2017-02-12 18:45:31 +0000517 CD->CtorInitializers = ReadGlobalOffset();
518 }
519 // Store the offset of the body so we can lazily load it later.
Daniel Jasper4a6d5b72017-10-11 07:47:54 +0000520 Reader.PendingBodies[FD] = GetCurrentCursorOffset();
521 HasPendingBody = true;
David Blaikieac4345c2017-02-12 18:45:31 +0000522}
523
Sebastian Redlb3298c32010-08-18 23:56:48 +0000524void ASTDeclReader::Visit(Decl *D) {
525 DeclVisitor<ASTDeclReader, void>::Visit(D);
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000526
Vassil Vassilev928c8252016-04-28 14:13:28 +0000527 // At this point we have deserialized and merged the decl and it is safe to
528 // update its canonical decl to signal that the entire entity is used.
529 D->getCanonicalDecl()->Used |= IsDeclMarkedUsed;
530 IsDeclMarkedUsed = false;
531
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +0000532 if (auto *DD = dyn_cast<DeclaratorDecl>(D)) {
Richard Smithc23d7342018-06-29 20:46:25 +0000533 if (auto *TInfo = DD->getTypeSourceInfo())
534 Record.readTypeLoc(TInfo->getTypeLoc());
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000535 }
536
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +0000537 if (auto *TD = dyn_cast<TypeDecl>(D)) {
Richard Smithf17fdbd2014-04-24 02:25:27 +0000538 // We have a fully initialized TypeDecl. Read its type now.
Richard Smith600adef2018-07-04 02:25:38 +0000539 TD->setTypeForDecl(Reader.GetType(DeferredTypeID).getTypePtrOrNull());
Richard Smith70d58502014-08-30 00:04:23 +0000540
541 // If this is a tag declaration with a typedef name for linkage, it's safe
542 // to load that typedef now.
543 if (NamedDeclForTagDecl)
David Majnemer00350522015-08-31 18:48:39 +0000544 cast<TagDecl>(D)->TypedefNameDeclOrQualifier =
545 cast<TypedefNameDecl>(Reader.GetDecl(NamedDeclForTagDecl));
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +0000546 } else if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) {
Douglas Gregorab1ec82e2011-12-16 03:12:41 +0000547 // if we have a fully initialized TypeDecl, we can safely read its type now.
Richard Smith600adef2018-07-04 02:25:38 +0000548 ID->TypeForDecl = Reader.GetType(DeferredTypeID).getTypePtrOrNull();
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +0000549 } else if (auto *FD = dyn_cast<FunctionDecl>(D)) {
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000550 // FunctionDecl's body was written last after all other Stmts/Exprs.
Douglas Gregor559458c2012-10-03 18:34:48 +0000551 // We only read it if FD doesn't already have a body (e.g., from another
552 // module).
Douglas Gregore4a838a2012-10-03 18:36:10 +0000553 // FIXME: Can we diagnose ODR violations somehow?
David Blaikieac4345c2017-02-12 18:45:31 +0000554 if (Record.readInt())
555 ReadFunctionDefinition(FD);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +0000556 }
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000557}
558
Sebastian Redlb3298c32010-08-18 23:56:48 +0000559void ASTDeclReader::VisitDecl(Decl *D) {
Dmitri Gribenkob353ee12013-12-19 02:05:20 +0000560 if (D->isTemplateParameter() || D->isTemplateParameterPack() ||
561 isa<ParmVarDecl>(D)) {
Douglas Gregor250ffb12011-03-05 01:35:54 +0000562 // We don't want to deserialize the DeclContext of a template
Dmitri Gribenkob353ee12013-12-19 02:05:20 +0000563 // parameter or of a parameter of a function template immediately. These
564 // entities might be used in the formulation of its DeclContext (for
565 // example, a function parameter can be used in decltype() in trailing
566 // return type of the function). Use the translation unit DeclContext as a
567 // placeholder.
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000568 GlobalDeclID SemaDCIDForTemplateParmDecl = ReadDeclID();
569 GlobalDeclID LexicalDCIDForTemplateParmDecl = ReadDeclID();
Richard Smith8aed4222015-12-11 22:41:00 +0000570 if (!LexicalDCIDForTemplateParmDecl)
571 LexicalDCIDForTemplateParmDecl = SemaDCIDForTemplateParmDecl;
Argyrios Kyrtzidis83a6e3b2013-02-16 00:48:59 +0000572 Reader.addPendingDeclContextInfo(D,
573 SemaDCIDForTemplateParmDecl,
574 LexicalDCIDForTemplateParmDecl);
Fangrui Song6907ce22018-07-30 19:24:48 +0000575 D->setDeclContext(Reader.getContext().getTranslationUnitDecl());
Douglas Gregor250ffb12011-03-05 01:35:54 +0000576 } else {
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +0000577 auto *SemaDC = ReadDeclAs<DeclContext>();
578 auto *LexicalDC = ReadDeclAs<DeclContext>();
Richard Smith8aed4222015-12-11 22:41:00 +0000579 if (!LexicalDC)
580 LexicalDC = SemaDC;
Richard Smithd55889a2013-09-09 16:55:27 +0000581 DeclContext *MergedSemaDC = Reader.MergedDeclContexts.lookup(SemaDC);
Argyrios Kyrtzidis7456ac42012-02-09 07:46:54 +0000582 // Avoid calling setLexicalDeclContext() directly because it uses
583 // Decl::getASTContext() internally which is unsafe during derialization.
Richard Smithd55889a2013-09-09 16:55:27 +0000584 D->setDeclContextsImpl(MergedSemaDC ? MergedSemaDC : SemaDC, LexicalDC,
585 Reader.getContext());
Douglas Gregor250ffb12011-03-05 01:35:54 +0000586 }
Richard Smithcb34bd32016-03-27 07:28:06 +0000587 D->setLocation(ThisDeclLoc);
David L. Jonesbe1557a2016-12-21 00:17:49 +0000588 D->setInvalidDecl(Record.readInt());
589 if (Record.readInt()) { // hasAttrs
Alexis Huntdcfba7b2010-08-18 23:23:40 +0000590 AttrVec Attrs;
David L. Jonesb6a8f022016-12-21 04:34:52 +0000591 Record.readAttributes(Attrs);
Argyrios Kyrtzidis7456ac42012-02-09 07:46:54 +0000592 // Avoid calling setAttrs() directly because it uses Decl::getASTContext()
593 // internally which is unsafe during derialization.
Argyrios Kyrtzidis6f40eb72012-02-09 02:44:08 +0000594 D->setAttrsImpl(Attrs, Reader.getContext());
Alexis Huntdcfba7b2010-08-18 23:23:40 +0000595 }
David L. Jonesbe1557a2016-12-21 00:17:49 +0000596 D->setImplicit(Record.readInt());
597 D->Used = Record.readInt();
Vassil Vassilev928c8252016-04-28 14:13:28 +0000598 IsDeclMarkedUsed |= D->Used;
David L. Jonesbe1557a2016-12-21 00:17:49 +0000599 D->setReferenced(Record.readInt());
600 D->setTopLevelDeclInObjCContainer(Record.readInt());
601 D->setAccess((AccessSpecifier)Record.readInt());
Douglas Gregor98c05b22011-09-10 00:09:20 +0000602 D->FromASTFile = true;
Richard Smith90dc5252017-06-23 01:04:34 +0000603 bool ModulePrivate = Record.readInt();
Richard Smith42413142015-05-15 20:05:43 +0000604
Douglas Gregorcf68c582011-12-01 22:20:10 +0000605 // Determine whether this declaration is part of a (sub)module. If so, it
606 // may not yet be visible.
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000607 if (unsigned SubmoduleID = readSubmoduleID()) {
Douglas Gregorcfe7dc62012-01-09 17:30:44 +0000608 // Store the owning submodule ID in the declaration.
Richard Smith90dc5252017-06-23 01:04:34 +0000609 D->setModuleOwnershipKind(
610 ModulePrivate ? Decl::ModuleOwnershipKind::ModulePrivate
611 : Decl::ModuleOwnershipKind::VisibleWhenImported);
Douglas Gregorcfe7dc62012-01-09 17:30:44 +0000612 D->setOwningModuleID(SubmoduleID);
Richard Smith42413142015-05-15 20:05:43 +0000613
Richard Smith90dc5252017-06-23 01:04:34 +0000614 if (ModulePrivate) {
615 // Module-private declarations are never visible, so there is no work to
616 // do.
Richard Smith42413142015-05-15 20:05:43 +0000617 } else if (Reader.getContext().getLangOpts().ModulesLocalVisibility) {
618 // If local visibility is being tracked, this declaration will become
Richard Smith90dc5252017-06-23 01:04:34 +0000619 // hidden and visible as the owning module does.
Richard Smith42413142015-05-15 20:05:43 +0000620 } else if (Module *Owner = Reader.getSubmodule(SubmoduleID)) {
Richard Smith90dc5252017-06-23 01:04:34 +0000621 // Mark the declaration as visible when its owning module becomes visible.
622 if (Owner->NameVisibility == Module::AllVisible)
623 D->setVisibleDespiteOwningModule();
624 else
Richard Smith42413142015-05-15 20:05:43 +0000625 Reader.HiddenNamesMap[Owner].push_back(D);
Douglas Gregorcf68c582011-12-01 22:20:10 +0000626 }
Richard Smithd19389a2017-07-05 07:47:11 +0000627 } else if (ModulePrivate) {
628 D->setModuleOwnershipKind(Decl::ModuleOwnershipKind::ModulePrivate);
Douglas Gregorcf68c582011-12-01 22:20:10 +0000629 }
Chris Lattner487412d2009-04-27 05:27:42 +0000630}
631
Nico Weber66220292016-03-02 17:28:48 +0000632void ASTDeclReader::VisitPragmaCommentDecl(PragmaCommentDecl *D) {
633 VisitDecl(D);
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000634 D->setLocation(ReadSourceLocation());
David L. Jonesbe1557a2016-12-21 00:17:49 +0000635 D->CommentKind = (PragmaMSCommentKind)Record.readInt();
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000636 std::string Arg = ReadString();
Nico Weber66220292016-03-02 17:28:48 +0000637 memcpy(D->getTrailingObjects<char>(), Arg.data(), Arg.size());
638 D->getTrailingObjects<char>()[Arg.size()] = '\0';
639}
640
Nico Webercbbaeb12016-03-02 19:28:54 +0000641void ASTDeclReader::VisitPragmaDetectMismatchDecl(PragmaDetectMismatchDecl *D) {
642 VisitDecl(D);
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000643 D->setLocation(ReadSourceLocation());
644 std::string Name = ReadString();
Nico Webercbbaeb12016-03-02 19:28:54 +0000645 memcpy(D->getTrailingObjects<char>(), Name.data(), Name.size());
646 D->getTrailingObjects<char>()[Name.size()] = '\0';
647
648 D->ValueStart = Name.size() + 1;
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000649 std::string Value = ReadString();
Nico Webercbbaeb12016-03-02 19:28:54 +0000650 memcpy(D->getTrailingObjects<char>() + D->ValueStart, Value.data(),
651 Value.size());
652 D->getTrailingObjects<char>()[D->ValueStart + Value.size()] = '\0';
653}
654
Sebastian Redlb3298c32010-08-18 23:56:48 +0000655void ASTDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) {
Douglas Gregordab42432011-08-12 00:15:20 +0000656 llvm_unreachable("Translation units are not serialized");
Chris Lattner487412d2009-04-27 05:27:42 +0000657}
658
Sebastian Redlb3298c32010-08-18 23:56:48 +0000659void ASTDeclReader::VisitNamedDecl(NamedDecl *ND) {
Chris Lattner487412d2009-04-27 05:27:42 +0000660 VisitDecl(ND);
David L. Jonesb6a8f022016-12-21 04:34:52 +0000661 ND->setDeclName(Record.readDeclarationName());
David L. Jonesbe1557a2016-12-21 00:17:49 +0000662 AnonymousDeclNumber = Record.readInt();
Chris Lattner487412d2009-04-27 05:27:42 +0000663}
664
Sebastian Redlb3298c32010-08-18 23:56:48 +0000665void ASTDeclReader::VisitTypeDecl(TypeDecl *TD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000666 VisitNamedDecl(TD);
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000667 TD->setLocStart(ReadSourceLocation());
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000668 // Delay type reading until after we have fully initialized the decl.
Richard Smith600adef2018-07-04 02:25:38 +0000669 DeferredTypeID = Record.getGlobalTypeID(Record.readInt());
Chris Lattner487412d2009-04-27 05:27:42 +0000670}
671
Richard Smith43ccec8e2014-08-26 03:52:16 +0000672ASTDeclReader::RedeclarableResult
673ASTDeclReader::VisitTypedefNameDecl(TypedefNameDecl *TD) {
Douglas Gregor9b7b3912012-01-04 16:44:10 +0000674 RedeclarableResult Redecl = VisitRedeclarable(TD);
Argyrios Kyrtzidis318b0e72010-07-02 11:55:01 +0000675 VisitTypeDecl(TD);
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000676 TypeSourceInfo *TInfo = GetTypeSourceInfo();
David L. Jonesbe1557a2016-12-21 00:17:49 +0000677 if (Record.readInt()) { // isModed
678 QualType modedT = Record.readType();
Enea Zaffanellaa86d88c2013-06-20 12:46:19 +0000679 TD->setModedTypeSourceInfo(TInfo, modedT);
680 } else
681 TD->setTypeSourceInfo(TInfo);
Richard Smithc0ca4c22017-01-26 22:39:55 +0000682 // Read and discard the declaration for which this is a typedef name for
683 // linkage, if it exists. We cannot rely on our type to pull in this decl,
684 // because it might have been merged with a type from another module and
685 // thus might not refer to our version of the declaration.
686 ReadDecl();
Richard Smith43ccec8e2014-08-26 03:52:16 +0000687 return Redecl;
Douglas Gregor1f179062011-12-19 14:40:25 +0000688}
689
690void ASTDeclReader::VisitTypedefDecl(TypedefDecl *TD) {
Richard Smith43ccec8e2014-08-26 03:52:16 +0000691 RedeclarableResult Redecl = VisitTypedefNameDecl(TD);
692 mergeRedeclarable(TD, Redecl);
Chris Lattner487412d2009-04-27 05:27:42 +0000693}
694
Richard Smithdda56e42011-04-15 14:24:37 +0000695void ASTDeclReader::VisitTypeAliasDecl(TypeAliasDecl *TD) {
Richard Smith43ccec8e2014-08-26 03:52:16 +0000696 RedeclarableResult Redecl = VisitTypedefNameDecl(TD);
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000697 if (auto *Template = ReadDeclAs<TypeAliasTemplateDecl>())
Richard Smith43ccec8e2014-08-26 03:52:16 +0000698 // Merged when we merge the template.
699 TD->setDescribedAliasTemplate(Template);
700 else
701 mergeRedeclarable(TD, Redecl);
Richard Smithdda56e42011-04-15 14:24:37 +0000702}
703
Richard Smith1d209d02013-05-23 01:49:11 +0000704ASTDeclReader::RedeclarableResult ASTDeclReader::VisitTagDecl(TagDecl *TD) {
Douglas Gregor2009cee2012-01-03 22:46:00 +0000705 RedeclarableResult Redecl = VisitRedeclarable(TD);
Douglas Gregor3e300102011-10-26 17:53:41 +0000706 VisitTypeDecl(TD);
Fangrui Song6907ce22018-07-30 19:24:48 +0000707
David L. Jonesbe1557a2016-12-21 00:17:49 +0000708 TD->IdentifierNamespace = Record.readInt();
709 TD->setTagKind((TagDecl::TagKind)Record.readInt());
Richard Smith2c381642014-08-27 23:11:59 +0000710 if (!isa<CXXRecordDecl>(TD))
David L. Jonesbe1557a2016-12-21 00:17:49 +0000711 TD->setCompleteDefinition(Record.readInt());
712 TD->setEmbeddedInDeclarator(Record.readInt());
713 TD->setFreeStanding(Record.readInt());
714 TD->setCompleteDefinitionRequired(Record.readInt());
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000715 TD->setBraceRange(ReadSourceRange());
Fangrui Song6907ce22018-07-30 19:24:48 +0000716
David L. Jonesbe1557a2016-12-21 00:17:49 +0000717 switch (Record.readInt()) {
Richard Smith70d58502014-08-30 00:04:23 +0000718 case 0:
719 break;
720 case 1: { // ExtInfo
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +0000721 auto *Info = new (Reader.getContext()) TagDecl::ExtInfo();
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000722 ReadQualifierInfo(*Info);
David Majnemer00350522015-08-31 18:48:39 +0000723 TD->TypedefNameDeclOrQualifier = Info;
Richard Smith70d58502014-08-30 00:04:23 +0000724 break;
725 }
726 case 2: // TypedefNameForAnonDecl
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000727 NamedDeclForTagDecl = ReadDeclID();
David L. Jonesb6a8f022016-12-21 04:34:52 +0000728 TypedefNameForLinkage = Record.getIdentifierInfo();
Richard Smith70d58502014-08-30 00:04:23 +0000729 break;
Richard Smith70d58502014-08-30 00:04:23 +0000730 default:
731 llvm_unreachable("unexpected tag info kind");
732 }
Douglas Gregor2009cee2012-01-03 22:46:00 +0000733
Richard Smithcd45dbc2014-04-19 03:48:30 +0000734 if (!isa<CXXRecordDecl>(TD))
735 mergeRedeclarable(TD, Redecl);
Richard Smith1d209d02013-05-23 01:49:11 +0000736 return Redecl;
Chris Lattner487412d2009-04-27 05:27:42 +0000737}
738
Sebastian Redlb3298c32010-08-18 23:56:48 +0000739void ASTDeclReader::VisitEnumDecl(EnumDecl *ED) {
Chris Lattner487412d2009-04-27 05:27:42 +0000740 VisitTagDecl(ED);
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000741 if (TypeSourceInfo *TI = GetTypeSourceInfo())
Douglas Gregor0bf31402010-10-08 23:50:27 +0000742 ED->setIntegerTypeSourceInfo(TI);
743 else
David L. Jonesbe1557a2016-12-21 00:17:49 +0000744 ED->setIntegerType(Record.readType());
745 ED->setPromotionType(Record.readType());
746 ED->setNumPositiveBits(Record.readInt());
747 ED->setNumNegativeBits(Record.readInt());
Erich Keanef92f31c2018-08-01 20:48:16 +0000748 ED->setScoped(Record.readInt());
749 ED->setScopedUsingClassTag(Record.readInt());
750 ED->setFixed(Record.readInt());
Richard Smith4b38ded2012-03-14 23:13:10 +0000751
Erich Keanef92f31c2018-08-01 20:48:16 +0000752 ED->setHasODRHash(true);
Richard Trieuab4d7302018-07-25 22:52:05 +0000753 ED->ODRHash = Record.readInt();
754
Richard Smith01a73372013-10-15 22:02:41 +0000755 // If this is a definition subject to the ODR, and we already have a
756 // definition, merge this one into it.
Erich Keanef92f31c2018-08-01 20:48:16 +0000757 if (ED->isCompleteDefinition() &&
Richard Smith01a73372013-10-15 22:02:41 +0000758 Reader.getContext().getLangOpts().Modules &&
759 Reader.getContext().getLangOpts().CPlusPlus) {
Richard Smith86dfc1e2015-06-18 22:07:00 +0000760 EnumDecl *&OldDef = Reader.EnumDefinitions[ED->getCanonicalDecl()];
761 if (!OldDef) {
762 // This is the first time we've seen an imported definition. Look for a
763 // local definition before deciding that we are the first definition.
764 for (auto *D : merged_redecls(ED->getCanonicalDecl())) {
765 if (!D->isFromASTFile() && D->isCompleteDefinition()) {
766 OldDef = D;
767 break;
768 }
769 }
770 }
771 if (OldDef) {
Richard Smith01a73372013-10-15 22:02:41 +0000772 Reader.MergedDeclContexts.insert(std::make_pair(ED, OldDef));
Erich Keanef92f31c2018-08-01 20:48:16 +0000773 ED->setCompleteDefinition(false);
Richard Smith6561f922016-09-12 21:06:40 +0000774 Reader.mergeDefinitionVisibility(OldDef, ED);
Richard Trieuab4d7302018-07-25 22:52:05 +0000775 if (OldDef->getODRHash() != ED->getODRHash())
776 Reader.PendingEnumOdrMergeFailures[OldDef].push_back(ED);
Richard Smith01a73372013-10-15 22:02:41 +0000777 } else {
778 OldDef = ED;
779 }
780 }
781
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +0000782 if (auto *InstED = ReadDeclAs<EnumDecl>()) {
783 auto TSK = (TemplateSpecializationKind)Record.readInt();
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000784 SourceLocation POI = ReadSourceLocation();
Richard Smith4b38ded2012-03-14 23:13:10 +0000785 ED->setInstantiationOfMemberEnum(Reader.getContext(), InstED, TSK);
786 ED->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
787 }
Chris Lattner487412d2009-04-27 05:27:42 +0000788}
789
Richard Smith1d209d02013-05-23 01:49:11 +0000790ASTDeclReader::RedeclarableResult
791ASTDeclReader::VisitRecordDeclImpl(RecordDecl *RD) {
792 RedeclarableResult Redecl = VisitTagDecl(RD);
David L. Jonesbe1557a2016-12-21 00:17:49 +0000793 RD->setHasFlexibleArrayMember(Record.readInt());
794 RD->setAnonymousStructOrUnion(Record.readInt());
795 RD->setHasObjectMember(Record.readInt());
796 RD->setHasVolatileMember(Record.readInt());
Akira Hatanaka34fb2642018-03-13 18:58:25 +0000797 RD->setNonTrivialToPrimitiveDefaultInitialize(Record.readInt());
798 RD->setNonTrivialToPrimitiveCopy(Record.readInt());
799 RD->setNonTrivialToPrimitiveDestroy(Record.readInt());
Akira Hatanaka09051062019-09-07 00:34:43 +0000800 RD->setHasNonTrivialToPrimitiveDefaultInitializeCUnion(Record.readInt());
801 RD->setHasNonTrivialToPrimitiveDestructCUnion(Record.readInt());
802 RD->setHasNonTrivialToPrimitiveCopyCUnion(Record.readInt());
Akira Hatanakafcbe17c2018-03-28 21:13:14 +0000803 RD->setParamDestroyedInCallee(Record.readInt());
Akira Hatanakae6313ac2018-04-09 22:48:22 +0000804 RD->setArgPassingRestrictions((RecordDecl::ArgPassingKind)Record.readInt());
Richard Smith1d209d02013-05-23 01:49:11 +0000805 return Redecl;
Chris Lattner487412d2009-04-27 05:27:42 +0000806}
807
Sebastian Redlb3298c32010-08-18 23:56:48 +0000808void ASTDeclReader::VisitValueDecl(ValueDecl *VD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000809 VisitNamedDecl(VD);
Richard Smith600adef2018-07-04 02:25:38 +0000810 // For function declarations, defer reading the type in case the function has
811 // a deduced return type that references an entity declared within the
812 // function.
813 if (isa<FunctionDecl>(VD))
814 DeferredTypeID = Record.getGlobalTypeID(Record.readInt());
815 else
816 VD->setType(Record.readType());
Chris Lattner487412d2009-04-27 05:27:42 +0000817}
818
Sebastian Redlb3298c32010-08-18 23:56:48 +0000819void ASTDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) {
Chris Lattner487412d2009-04-27 05:27:42 +0000820 VisitValueDecl(ECD);
David L. Jonesbe1557a2016-12-21 00:17:49 +0000821 if (Record.readInt())
David L. Jonesb6a8f022016-12-21 04:34:52 +0000822 ECD->setInitExpr(Record.readExpr());
823 ECD->setInitVal(Record.readAPSInt());
Richard Smith01a73372013-10-15 22:02:41 +0000824 mergeMergeable(ECD);
Chris Lattner487412d2009-04-27 05:27:42 +0000825}
826
Sebastian Redlb3298c32010-08-18 23:56:48 +0000827void ASTDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000828 VisitValueDecl(DD);
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000829 DD->setInnerLocStart(ReadSourceLocation());
David L. Jonesbe1557a2016-12-21 00:17:49 +0000830 if (Record.readInt()) { // hasExtInfo
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +0000831 auto *Info = new (Reader.getContext()) DeclaratorDecl::ExtInfo();
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000832 ReadQualifierInfo(*Info);
Argyrios Kyrtzidis434383d2010-10-15 18:21:24 +0000833 DD->DeclInfo = Info;
Jonathan D. Turner205c7d52011-06-03 23:11:16 +0000834 }
Richard Smithc23d7342018-06-29 20:46:25 +0000835 QualType TSIType = Record.readType();
836 DD->setTypeSourceInfo(
837 TSIType.isNull() ? nullptr
838 : Reader.getContext().CreateTypeSourceInfo(TSIType));
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +0000839}
840
Sebastian Redlb3298c32010-08-18 23:56:48 +0000841void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) {
Douglas Gregorb2585692012-01-04 17:13:46 +0000842 RedeclarableResult Redecl = VisitRedeclarable(FD);
Douglas Gregor3e300102011-10-26 17:53:41 +0000843 VisitDeclaratorDecl(FD);
Chris Lattnerca025db2010-05-07 21:43:38 +0000844
Richard Smith600adef2018-07-04 02:25:38 +0000845 // Attach a type to this function. Use the real type if possible, but fall
846 // back to the type as written if it involves a deduced return type.
847 if (FD->getTypeSourceInfo() &&
848 FD->getTypeSourceInfo()->getType()->castAs<FunctionType>()
849 ->getReturnType()->getContainedAutoType()) {
850 // We'll set up the real type in Visit, once we've finished loading the
851 // function.
852 FD->setType(FD->getTypeSourceInfo()->getType());
Richard Smitha62d1982018-08-03 01:00:01 +0000853 Reader.PendingFunctionTypes.push_back({FD, DeferredTypeID});
Richard Smith600adef2018-07-04 02:25:38 +0000854 } else {
855 FD->setType(Reader.GetType(DeferredTypeID));
Richard Smith600adef2018-07-04 02:25:38 +0000856 }
Richard Smitha62d1982018-08-03 01:00:01 +0000857 DeferredTypeID = 0;
Richard Smith600adef2018-07-04 02:25:38 +0000858
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000859 ReadDeclarationNameLoc(FD->DNLoc, FD->getDeclName());
David L. Jonesbe1557a2016-12-21 00:17:49 +0000860 FD->IdentifierNamespace = Record.readInt();
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000861
Douglas Gregorb2585692012-01-04 17:13:46 +0000862 // FunctionDecl's body is handled last at ASTDeclReader::Visit,
863 // after everything else is read.
Rafael Espindola6ae7e502013-04-03 19:27:57 +0000864
Erich Keane9c665062018-08-01 21:02:40 +0000865 FD->setStorageClass(static_cast<StorageClass>(Record.readInt()));
866 FD->setInlineSpecified(Record.readInt());
867 FD->setImplicitlyInline(Record.readInt());
Erich Keane9c665062018-08-01 21:02:40 +0000868 FD->setVirtualAsWritten(Record.readInt());
869 FD->setPure(Record.readInt());
870 FD->setHasInheritedPrototype(Record.readInt());
871 FD->setHasWrittenPrototype(Record.readInt());
872 FD->setDeletedAsWritten(Record.readInt());
873 FD->setTrivial(Record.readInt());
874 FD->setTrivialForCall(Record.readInt());
875 FD->setDefaulted(Record.readInt());
876 FD->setExplicitlyDefaulted(Record.readInt());
877 FD->setHasImplicitReturnZero(Record.readInt());
Gauthier Harnisch796ed032019-06-14 08:56:20 +0000878 FD->setConstexprKind(static_cast<ConstexprSpecKind>(Record.readInt()));
Erich Keane9c665062018-08-01 21:02:40 +0000879 FD->setUsesSEHTry(Record.readInt());
880 FD->setHasSkippedBody(Record.readInt());
881 FD->setIsMultiVersion(Record.readInt());
882 FD->setLateTemplateParsed(Record.readInt());
883
884 FD->setCachedLinkage(static_cast<Linkage>(Record.readInt()));
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000885 FD->EndRangeLoc = ReadSourceLocation();
Douglas Gregorb2585692012-01-04 17:13:46 +0000886
Richard Trieue6caa262017-12-23 00:41:01 +0000887 FD->ODRHash = Record.readInt();
Erich Keane9c665062018-08-01 21:02:40 +0000888 FD->setHasODRHash(true);
Melanie Blower7f9b5132019-12-04 12:23:46 -0800889 FD->setUsesFPIntrin(Record.readInt());
Richard Trieue6caa262017-12-23 00:41:01 +0000890
Richard Smith848934c2019-12-05 13:37:35 -0800891 if (FD->isDefaulted()) {
892 if (unsigned NumLookups = Record.readInt()) {
893 SmallVector<DeclAccessPair, 8> Lookups;
894 for (unsigned I = 0; I != NumLookups; ++I) {
895 NamedDecl *ND = Record.readDeclAs<NamedDecl>();
896 AccessSpecifier AS = (AccessSpecifier)Record.readInt();
897 Lookups.push_back(DeclAccessPair::make(ND, AS));
898 }
899 FD->setDefaultedFunctionInfo(FunctionDecl::DefaultedFunctionInfo::Create(
900 Reader.getContext(), Lookups));
901 }
902 }
903
David L. Jonesbe1557a2016-12-21 00:17:49 +0000904 switch ((FunctionDecl::TemplatedKind)Record.readInt()) {
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000905 case FunctionDecl::TK_NonTemplate:
Richard Smithcd45dbc2014-04-19 03:48:30 +0000906 mergeRedeclarable(FD, Redecl);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000907 break;
908 case FunctionDecl::TK_FunctionTemplate:
Richard Smithcd45dbc2014-04-19 03:48:30 +0000909 // Merged when we merge the template.
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000910 FD->setDescribedFunctionTemplate(ReadDeclAs<FunctionTemplateDecl>());
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000911 break;
912 case FunctionDecl::TK_MemberSpecialization: {
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +0000913 auto *InstFD = ReadDeclAs<FunctionDecl>();
914 auto TSK = (TemplateSpecializationKind)Record.readInt();
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000915 SourceLocation POI = ReadSourceLocation();
Douglas Gregor4163aca2011-09-09 21:34:22 +0000916 FD->setInstantiationOfMemberFunction(Reader.getContext(), InstFD, TSK);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000917 FD->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
Richard Smithcd45dbc2014-04-19 03:48:30 +0000918 mergeRedeclarable(FD, Redecl);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000919 break;
920 }
921 case FunctionDecl::TK_FunctionTemplateSpecialization: {
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +0000922 auto *Template = ReadDeclAs<FunctionTemplateDecl>();
923 auto TSK = (TemplateSpecializationKind)Record.readInt();
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000924
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000925 // Template arguments.
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000926 SmallVector<TemplateArgument, 8> TemplArgs;
David L. Jonesb6a8f022016-12-21 04:34:52 +0000927 Record.readTemplateArgumentList(TemplArgs, /*Canonicalize*/ true);
Richard Smith2bb3c342015-08-09 01:05:31 +0000928
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000929 // Template args as written.
Chris Lattner0e62c1c2011-07-23 10:55:15 +0000930 SmallVector<TemplateArgumentLoc, 8> TemplArgLocs;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000931 SourceLocation LAngleLoc, RAngleLoc;
David L. Jonesbe1557a2016-12-21 00:17:49 +0000932 bool HasTemplateArgumentsAsWritten = Record.readInt();
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000933 if (HasTemplateArgumentsAsWritten) {
David L. Jonesbe1557a2016-12-21 00:17:49 +0000934 unsigned NumTemplateArgLocs = Record.readInt();
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +0000935 TemplArgLocs.reserve(NumTemplateArgLocs);
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +0000936 for (unsigned i = 0; i != NumTemplateArgLocs; ++i)
David L. Jonesb6a8f022016-12-21 04:34:52 +0000937 TemplArgLocs.push_back(Record.readTemplateArgumentLoc());
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000938
939 LAngleLoc = ReadSourceLocation();
940 RAngleLoc = ReadSourceLocation();
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000941 }
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000942
943 SourceLocation POI = ReadSourceLocation();
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000944
Douglas Gregor4163aca2011-09-09 21:34:22 +0000945 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000946 TemplateArgumentList *TemplArgList
David Majnemer8b622692016-07-03 21:17:51 +0000947 = TemplateArgumentList::CreateCopy(C, TemplArgs);
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000948 TemplateArgumentListInfo TemplArgsInfo(LAngleLoc, RAngleLoc);
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +0000949 for (unsigned i = 0, e = TemplArgLocs.size(); i != e; ++i)
Argyrios Kyrtzidise9a24432011-09-22 20:07:09 +0000950 TemplArgsInfo.addArgument(TemplArgLocs[i]);
Richard Smithf19a8b02019-05-02 00:49:14 +0000951
952 MemberSpecializationInfo *MSInfo = nullptr;
953 if (Record.readInt()) {
954 auto *FD = ReadDeclAs<FunctionDecl>();
955 auto TSK = (TemplateSpecializationKind)Record.readInt();
956 SourceLocation POI = ReadSourceLocation();
957
958 MSInfo = new (C) MemberSpecializationInfo(FD, TSK);
959 MSInfo->setPointOfInstantiation(POI);
960 }
961
962 FunctionTemplateSpecializationInfo *FTInfo =
963 FunctionTemplateSpecializationInfo::Create(
964 C, FD, Template, TSK, TemplArgList,
965 HasTemplateArgumentsAsWritten ? &TemplArgsInfo : nullptr, POI,
966 MSInfo);
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000967 FD->TemplateOrSpecialization = FTInfo;
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000968
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000969 if (FD->isCanonicalDecl()) { // if canonical add to template's set.
Argyrios Kyrtzidisf24d5692010-09-13 11:45:48 +0000970 // The template that contains the specializations set. It's not safe to
971 // use getCanonicalDecl on Template since it may still be initializing.
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +0000972 auto *CanonTemplate = ReadDeclAs<FunctionTemplateDecl>();
Argyrios Kyrtzidise262a952010-09-09 11:28:23 +0000973 // Get the InsertPos by FindNodeOrInsertPos() instead of calling
974 // InsertNode(FTInfo) directly to avoid the getASTContext() call in
975 // FunctionTemplateSpecializationInfo's Profile().
976 // We avoid getASTContext because a decl in the parent hierarchy may
977 // be initializing.
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000978 llvm::FoldingSetNodeID ID;
Craig Topper7e0daca2014-06-26 04:58:53 +0000979 FunctionTemplateSpecializationInfo::Profile(ID, TemplArgs, C);
Craig Toppera13603a2014-05-22 05:54:18 +0000980 void *InsertPos = nullptr;
Richard Smithfeb3e1a2013-06-28 04:37:53 +0000981 FunctionTemplateDecl::Common *CommonPtr = CanonTemplate->getCommonPtr();
Richard Smithda6c2342015-07-01 23:19:58 +0000982 FunctionTemplateSpecializationInfo *ExistingInfo =
983 CommonPtr->Specializations.FindNodeOrInsertPos(ID, InsertPos);
Argyrios Kyrtzidise60e4082012-09-10 23:28:22 +0000984 if (InsertPos)
Richard Smithfeb3e1a2013-06-28 04:37:53 +0000985 CommonPtr->Specializations.InsertNode(FTInfo, InsertPos);
986 else {
987 assert(Reader.getContext().getLangOpts().Modules &&
988 "already deserialized this template specialization");
Richard Smithf19a8b02019-05-02 00:49:14 +0000989 mergeRedeclarable(FD, ExistingInfo->getFunction(), Redecl);
Richard Smithfeb3e1a2013-06-28 04:37:53 +0000990 }
Argyrios Kyrtzidisf4bc0d82010-09-08 19:31:22 +0000991 }
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +0000992 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000993 }
994 case FunctionDecl::TK_DependentFunctionTemplateSpecialization: {
995 // Templates.
996 UnresolvedSet<8> TemplDecls;
David L. Jonesbe1557a2016-12-21 00:17:49 +0000997 unsigned NumTemplates = Record.readInt();
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +0000998 while (NumTemplates--)
David L. Jonesc4808b9e2016-12-15 20:53:26 +0000999 TemplDecls.addDecl(ReadDeclAs<NamedDecl>());
1000
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001001 // Templates args.
1002 TemplateArgumentListInfo TemplArgs;
David L. Jonesbe1557a2016-12-21 00:17:49 +00001003 unsigned NumArgs = Record.readInt();
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001004 while (NumArgs--)
David L. Jonesb6a8f022016-12-21 04:34:52 +00001005 TemplArgs.addArgument(Record.readTemplateArgumentLoc());
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001006 TemplArgs.setLAngleLoc(ReadSourceLocation());
1007 TemplArgs.setRAngleLoc(ReadSourceLocation());
1008
Douglas Gregor4163aca2011-09-09 21:34:22 +00001009 FD->setDependentTemplateSpecialization(Reader.getContext(),
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001010 TemplDecls, TemplArgs);
Richard Smithda6c2342015-07-01 23:19:58 +00001011 // These are not merged; we don't need to merge redeclarations of dependent
1012 // template friends.
Argyrios Kyrtzidis0b0369a2010-06-28 09:31:34 +00001013 break;
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00001014 }
1015 }
Argyrios Kyrtzidis373a83a2010-07-02 11:55:40 +00001016
Chris Lattnerca025db2010-05-07 21:43:38 +00001017 // Read in the parameters.
David L. Jonesbe1557a2016-12-21 00:17:49 +00001018 unsigned NumParams = Record.readInt();
Chris Lattner0e62c1c2011-07-23 10:55:15 +00001019 SmallVector<ParmVarDecl *, 16> Params;
Chris Lattner487412d2009-04-27 05:27:42 +00001020 Params.reserve(NumParams);
1021 for (unsigned I = 0; I != NumParams; ++I)
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001022 Params.push_back(ReadDeclAs<ParmVarDecl>());
David Blaikie9c70e042011-09-21 18:16:56 +00001023 FD->setParams(Reader.getContext(), Params);
Chris Lattner487412d2009-04-27 05:27:42 +00001024}
1025
Sebastian Redlb3298c32010-08-18 23:56:48 +00001026void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) {
Chris Lattner487412d2009-04-27 05:27:42 +00001027 VisitNamedDecl(MD);
David L. Jonesbe1557a2016-12-21 00:17:49 +00001028 if (Record.readInt()) {
Daniel Jasper4a6d5b72017-10-11 07:47:54 +00001029 // Load the body on-demand. Most clients won't care, because method
1030 // definitions rarely show up in headers.
1031 Reader.PendingBodies[MD] = GetCurrentCursorOffset();
1032 HasPendingBody = true;
Chris Lattner487412d2009-04-27 05:27:42 +00001033 }
Alex Lorenzf3efd692019-12-06 14:24:37 -08001034 MD->setSelfDecl(ReadDeclAs<ImplicitParamDecl>());
1035 MD->setCmdDecl(ReadDeclAs<ImplicitParamDecl>());
David L. Jonesbe1557a2016-12-21 00:17:49 +00001036 MD->setInstanceMethod(Record.readInt());
1037 MD->setVariadic(Record.readInt());
1038 MD->setPropertyAccessor(Record.readInt());
Adrian Prantl2073dd22019-11-04 14:28:14 -08001039 MD->setSynthesizedAccessorStub(Record.readInt());
David L. Jonesbe1557a2016-12-21 00:17:49 +00001040 MD->setDefined(Record.readInt());
Erich Keane9b18eca2018-08-01 21:31:08 +00001041 MD->setOverriding(Record.readInt());
1042 MD->setHasSkippedBody(Record.readInt());
Argyrios Kyrtzidisdb215962011-10-14 17:41:52 +00001043
Erich Keane9b18eca2018-08-01 21:31:08 +00001044 MD->setIsRedeclaration(Record.readInt());
1045 MD->setHasRedeclaration(Record.readInt());
1046 if (MD->hasRedeclaration())
Argyrios Kyrtzidisdb215962011-10-14 17:41:52 +00001047 Reader.getContext().setObjCMethodRedeclaration(MD,
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001048 ReadDeclAs<ObjCMethodDecl>());
Argyrios Kyrtzidisdb215962011-10-14 17:41:52 +00001049
David L. Jonesbe1557a2016-12-21 00:17:49 +00001050 MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record.readInt());
1051 MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record.readInt());
Erich Keane9b18eca2018-08-01 21:31:08 +00001052 MD->setRelatedResultType(Record.readInt());
David L. Jonesbe1557a2016-12-21 00:17:49 +00001053 MD->setReturnType(Record.readType());
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001054 MD->setReturnTypeSourceInfo(GetTypeSourceInfo());
1055 MD->DeclEndLoc = ReadSourceLocation();
David L. Jonesbe1557a2016-12-21 00:17:49 +00001056 unsigned NumParams = Record.readInt();
Chris Lattner0e62c1c2011-07-23 10:55:15 +00001057 SmallVector<ParmVarDecl *, 16> Params;
Chris Lattner487412d2009-04-27 05:27:42 +00001058 Params.reserve(NumParams);
1059 for (unsigned I = 0; I != NumParams; ++I)
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001060 Params.push_back(ReadDeclAs<ParmVarDecl>());
Argyrios Kyrtzidisb8c3aaf2011-10-03 06:37:04 +00001061
Erich Keane9b18eca2018-08-01 21:31:08 +00001062 MD->setSelLocsKind((SelectorLocationsKind)Record.readInt());
David L. Jonesbe1557a2016-12-21 00:17:49 +00001063 unsigned NumStoredSelLocs = Record.readInt();
Argyrios Kyrtzidisb8c3aaf2011-10-03 06:37:04 +00001064 SmallVector<SourceLocation, 16> SelLocs;
1065 SelLocs.reserve(NumStoredSelLocs);
1066 for (unsigned i = 0; i != NumStoredSelLocs; ++i)
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001067 SelLocs.push_back(ReadSourceLocation());
Argyrios Kyrtzidisb8c3aaf2011-10-03 06:37:04 +00001068
1069 MD->setParamsAndSelLocs(Reader.getContext(), Params, SelLocs);
Chris Lattner487412d2009-04-27 05:27:42 +00001070}
1071
Douglas Gregor85f3f952015-07-07 03:57:15 +00001072void ASTDeclReader::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) {
David Blaikie27a1bc02015-09-28 23:48:49 +00001073 VisitTypedefNameDecl(D);
Richard Smith9b88a4c2015-07-27 05:40:23 +00001074
David L. Jonesbe1557a2016-12-21 00:17:49 +00001075 D->Variance = Record.readInt();
1076 D->Index = Record.readInt();
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001077 D->VarianceLoc = ReadSourceLocation();
1078 D->ColonLoc = ReadSourceLocation();
Douglas Gregor85f3f952015-07-07 03:57:15 +00001079}
1080
Sebastian Redlb3298c32010-08-18 23:56:48 +00001081void ASTDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) {
Chris Lattner487412d2009-04-27 05:27:42 +00001082 VisitNamedDecl(CD);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001083 CD->setAtStartLoc(ReadSourceLocation());
1084 CD->setAtEndRange(ReadSourceRange());
Chris Lattner487412d2009-04-27 05:27:42 +00001085}
1086
Douglas Gregor85f3f952015-07-07 03:57:15 +00001087ObjCTypeParamList *ASTDeclReader::ReadObjCTypeParamList() {
David L. Jonesbe1557a2016-12-21 00:17:49 +00001088 unsigned numParams = Record.readInt();
Douglas Gregor85f3f952015-07-07 03:57:15 +00001089 if (numParams == 0)
1090 return nullptr;
1091
1092 SmallVector<ObjCTypeParamDecl *, 4> typeParams;
1093 typeParams.reserve(numParams);
1094 for (unsigned i = 0; i != numParams; ++i) {
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00001095 auto *typeParam = ReadDeclAs<ObjCTypeParamDecl>();
Douglas Gregor85f3f952015-07-07 03:57:15 +00001096 if (!typeParam)
1097 return nullptr;
1098
1099 typeParams.push_back(typeParam);
1100 }
1101
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001102 SourceLocation lAngleLoc = ReadSourceLocation();
1103 SourceLocation rAngleLoc = ReadSourceLocation();
Douglas Gregor85f3f952015-07-07 03:57:15 +00001104
1105 return ObjCTypeParamList::create(Reader.getContext(), lAngleLoc,
1106 typeParams, rAngleLoc);
1107}
1108
Manman Renec315f12016-09-09 23:48:27 +00001109void ASTDeclReader::ReadObjCDefinitionData(
David L. Jonesbe1557a2016-12-21 00:17:49 +00001110 struct ObjCInterfaceDecl::DefinitionData &Data) {
Manman Renec315f12016-09-09 23:48:27 +00001111 // Read the superclass.
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001112 Data.SuperClassTInfo = GetTypeSourceInfo();
Manman Renec315f12016-09-09 23:48:27 +00001113
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001114 Data.EndLoc = ReadSourceLocation();
David L. Jonesbe1557a2016-12-21 00:17:49 +00001115 Data.HasDesignatedInitializers = Record.readInt();
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001116
Manman Renec315f12016-09-09 23:48:27 +00001117 // Read the directly referenced protocols and their SourceLocations.
David L. Jonesbe1557a2016-12-21 00:17:49 +00001118 unsigned NumProtocols = Record.readInt();
Manman Renec315f12016-09-09 23:48:27 +00001119 SmallVector<ObjCProtocolDecl *, 16> Protocols;
1120 Protocols.reserve(NumProtocols);
1121 for (unsigned I = 0; I != NumProtocols; ++I)
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001122 Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>());
Manman Renec315f12016-09-09 23:48:27 +00001123 SmallVector<SourceLocation, 16> ProtoLocs;
1124 ProtoLocs.reserve(NumProtocols);
1125 for (unsigned I = 0; I != NumProtocols; ++I)
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001126 ProtoLocs.push_back(ReadSourceLocation());
Manman Renec315f12016-09-09 23:48:27 +00001127 Data.ReferencedProtocols.set(Protocols.data(), NumProtocols, ProtoLocs.data(),
1128 Reader.getContext());
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001129
Manman Renec315f12016-09-09 23:48:27 +00001130 // Read the transitive closure of protocols referenced by this class.
David L. Jonesbe1557a2016-12-21 00:17:49 +00001131 NumProtocols = Record.readInt();
Manman Renec315f12016-09-09 23:48:27 +00001132 Protocols.clear();
1133 Protocols.reserve(NumProtocols);
1134 for (unsigned I = 0; I != NumProtocols; ++I)
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001135 Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>());
Manman Renec315f12016-09-09 23:48:27 +00001136 Data.AllReferencedProtocols.set(Protocols.data(), NumProtocols,
1137 Reader.getContext());
1138}
1139
1140void ASTDeclReader::MergeDefinitionData(ObjCInterfaceDecl *D,
1141 struct ObjCInterfaceDecl::DefinitionData &&NewDD) {
1142 // FIXME: odr checking?
1143}
1144
Sebastian Redlb3298c32010-08-18 23:56:48 +00001145void ASTDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) {
Douglas Gregor022857e2011-12-22 01:48:48 +00001146 RedeclarableResult Redecl = VisitRedeclarable(ID);
Chris Lattner487412d2009-04-27 05:27:42 +00001147 VisitObjCContainerDecl(ID);
Richard Smith600adef2018-07-04 02:25:38 +00001148 DeferredTypeID = Record.getGlobalTypeID(Record.readInt());
Douglas Gregor2c46b5b2012-01-03 17:27:13 +00001149 mergeRedeclarable(ID, Redecl);
Douglas Gregor85f3f952015-07-07 03:57:15 +00001150
1151 ID->TypeParamList = ReadObjCTypeParamList();
David L. Jonesbe1557a2016-12-21 00:17:49 +00001152 if (Record.readInt()) {
Douglas Gregorc0ac7d62011-12-15 05:27:12 +00001153 // Read the definition.
1154 ID->allocateDefinitionData();
Douglas Gregorc0ac7d62011-12-15 05:27:12 +00001155
David L. Jonesbe1557a2016-12-21 00:17:49 +00001156 ReadObjCDefinitionData(ID->data());
Manman Renec315f12016-09-09 23:48:27 +00001157 ObjCInterfaceDecl *Canon = ID->getCanonicalDecl();
1158 if (Canon->Data.getPointer()) {
1159 // If we already have a definition, keep the definition invariant and
1160 // merge the data.
1161 MergeDefinitionData(Canon, std::move(ID->data()));
1162 ID->Data = Canon->Data;
1163 } else {
1164 // Set the definition data of the canonical declaration, so other
1165 // redeclarations will see it.
1166 ID->getCanonicalDecl()->Data = ID->Data;
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001167
Manman Renec315f12016-09-09 23:48:27 +00001168 // We will rebuild this list lazily.
1169 ID->setIvarList(nullptr);
1170 }
Craig Toppera13603a2014-05-22 05:54:18 +00001171
Douglas Gregorc1a61fe2011-12-19 20:51:16 +00001172 // Note that we have deserialized a definition.
1173 Reader.PendingDefinitions.insert(ID);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001174
Douglas Gregor404cdde2012-01-27 01:47:08 +00001175 // Note that we've loaded this Objective-C class.
1176 Reader.ObjCClassesLoaded.push_back(ID);
Douglas Gregorc03c52e2012-01-15 18:08:05 +00001177 } else {
1178 ID->Data = ID->getCanonicalDecl()->Data;
Douglas Gregorc0ac7d62011-12-15 05:27:12 +00001179 }
Chris Lattner487412d2009-04-27 05:27:42 +00001180}
1181
Sebastian Redlb3298c32010-08-18 23:56:48 +00001182void ASTDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) {
Chris Lattner487412d2009-04-27 05:27:42 +00001183 VisitFieldDecl(IVD);
David L. Jonesbe1557a2016-12-21 00:17:49 +00001184 IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record.readInt());
Fariborz Jahaniana50b3a22010-08-20 21:21:08 +00001185 // This field will be built lazily.
Craig Toppera13603a2014-05-22 05:54:18 +00001186 IVD->setNextIvar(nullptr);
David L. Jonesbe1557a2016-12-21 00:17:49 +00001187 bool synth = Record.readInt();
Fariborz Jahanianaea8e1e2010-07-17 18:35:47 +00001188 IVD->setSynthesize(synth);
Chris Lattner487412d2009-04-27 05:27:42 +00001189}
1190
Graydon Hoaree0a68352017-06-28 18:36:27 +00001191void ASTDeclReader::ReadObjCDefinitionData(
1192 struct ObjCProtocolDecl::DefinitionData &Data) {
David L. Jonesbe1557a2016-12-21 00:17:49 +00001193 unsigned NumProtoRefs = Record.readInt();
Douglas Gregore6e48b12012-01-01 19:29:29 +00001194 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
1195 ProtoRefs.reserve(NumProtoRefs);
1196 for (unsigned I = 0; I != NumProtoRefs; ++I)
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001197 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>());
Douglas Gregore6e48b12012-01-01 19:29:29 +00001198 SmallVector<SourceLocation, 16> ProtoLocs;
1199 ProtoLocs.reserve(NumProtoRefs);
1200 for (unsigned I = 0; I != NumProtoRefs; ++I)
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001201 ProtoLocs.push_back(ReadSourceLocation());
Graydon Hoaree0a68352017-06-28 18:36:27 +00001202 Data.ReferencedProtocols.set(ProtoRefs.data(), NumProtoRefs,
1203 ProtoLocs.data(), Reader.getContext());
1204}
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001205
Graydon Hoaree0a68352017-06-28 18:36:27 +00001206void ASTDeclReader::MergeDefinitionData(ObjCProtocolDecl *D,
1207 struct ObjCProtocolDecl::DefinitionData &&NewDD) {
1208 // FIXME: odr checking?
1209}
1210
1211void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) {
1212 RedeclarableResult Redecl = VisitRedeclarable(PD);
1213 VisitObjCContainerDecl(PD);
1214 mergeRedeclarable(PD, Redecl);
1215
1216 if (Record.readInt()) {
1217 // Read the definition.
1218 PD->allocateDefinitionData();
1219
1220 ReadObjCDefinitionData(PD->data());
1221
1222 ObjCProtocolDecl *Canon = PD->getCanonicalDecl();
1223 if (Canon->Data.getPointer()) {
1224 // If we already have a definition, keep the definition invariant and
1225 // merge the data.
1226 MergeDefinitionData(Canon, std::move(PD->data()));
1227 PD->Data = Canon->Data;
1228 } else {
1229 // Set the definition data of the canonical declaration, so other
1230 // redeclarations will see it.
1231 PD->getCanonicalDecl()->Data = PD->Data;
1232 }
Douglas Gregora715bff2012-01-01 19:51:50 +00001233 // Note that we have deserialized a definition.
1234 Reader.PendingDefinitions.insert(PD);
Douglas Gregorc03c52e2012-01-15 18:08:05 +00001235 } else {
1236 PD->Data = PD->getCanonicalDecl()->Data;
Douglas Gregore6e48b12012-01-01 19:29:29 +00001237 }
Chris Lattner487412d2009-04-27 05:27:42 +00001238}
1239
Sebastian Redlb3298c32010-08-18 23:56:48 +00001240void ASTDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) {
Chris Lattner487412d2009-04-27 05:27:42 +00001241 VisitFieldDecl(FD);
1242}
1243
Sebastian Redlb3298c32010-08-18 23:56:48 +00001244void ASTDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) {
Chris Lattner487412d2009-04-27 05:27:42 +00001245 VisitObjCContainerDecl(CD);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001246 CD->setCategoryNameLoc(ReadSourceLocation());
1247 CD->setIvarLBraceLoc(ReadSourceLocation());
1248 CD->setIvarRBraceLoc(ReadSourceLocation());
1249
Douglas Gregor404cdde2012-01-27 01:47:08 +00001250 // Note that this category has been deserialized. We do this before
1251 // deserializing the interface declaration, so that it will consider this
1252 /// category.
1253 Reader.CategoriesDeserialized.insert(CD);
1254
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001255 CD->ClassInterface = ReadDeclAs<ObjCInterfaceDecl>();
Douglas Gregor85f3f952015-07-07 03:57:15 +00001256 CD->TypeParamList = ReadObjCTypeParamList();
David L. Jonesbe1557a2016-12-21 00:17:49 +00001257 unsigned NumProtoRefs = Record.readInt();
Chris Lattner0e62c1c2011-07-23 10:55:15 +00001258 SmallVector<ObjCProtocolDecl *, 16> ProtoRefs;
Chris Lattner487412d2009-04-27 05:27:42 +00001259 ProtoRefs.reserve(NumProtoRefs);
1260 for (unsigned I = 0; I != NumProtoRefs; ++I)
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001261 ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>());
Chris Lattner0e62c1c2011-07-23 10:55:15 +00001262 SmallVector<SourceLocation, 16> ProtoLocs;
Douglas Gregor002b6712010-01-16 15:02:53 +00001263 ProtoLocs.reserve(NumProtoRefs);
1264 for (unsigned I = 0; I != NumProtoRefs; ++I)
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001265 ProtoLocs.push_back(ReadSourceLocation());
Douglas Gregor002b6712010-01-16 15:02:53 +00001266 CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(),
Douglas Gregor4163aca2011-09-09 21:34:22 +00001267 Reader.getContext());
Bruno Cardoso Lopesfbff2fa2018-04-27 18:01:23 +00001268
1269 // Protocols in the class extension belong to the class.
1270 if (NumProtoRefs > 0 && CD->ClassInterface && CD->IsClassExtension())
1271 CD->ClassInterface->mergeClassExtensionProtocolList(
1272 (ObjCProtocolDecl *const *)ProtoRefs.data(), NumProtoRefs,
1273 Reader.getContext());
Chris Lattner487412d2009-04-27 05:27:42 +00001274}
1275
Sebastian Redlb3298c32010-08-18 23:56:48 +00001276void ASTDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) {
Chris Lattner487412d2009-04-27 05:27:42 +00001277 VisitNamedDecl(CAD);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001278 CAD->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>());
Chris Lattner487412d2009-04-27 05:27:42 +00001279}
1280
Sebastian Redlb3298c32010-08-18 23:56:48 +00001281void ASTDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +00001282 VisitNamedDecl(D);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001283 D->setAtLoc(ReadSourceLocation());
1284 D->setLParenLoc(ReadSourceLocation());
David L. Jonesbe1557a2016-12-21 00:17:49 +00001285 QualType T = Record.readType();
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001286 TypeSourceInfo *TSI = GetTypeSourceInfo();
Douglas Gregor813a0662015-06-19 18:14:38 +00001287 D->setType(T, TSI);
Chris Lattner487412d2009-04-27 05:27:42 +00001288 D->setPropertyAttributes(
David L. Jonesbe1557a2016-12-21 00:17:49 +00001289 (ObjCPropertyDecl::PropertyAttributeKind)Record.readInt());
Fariborz Jahanian3bf0ded2010-06-22 23:20:40 +00001290 D->setPropertyAttributesAsWritten(
David L. Jonesbe1557a2016-12-21 00:17:49 +00001291 (ObjCPropertyDecl::PropertyAttributeKind)Record.readInt());
Chris Lattner487412d2009-04-27 05:27:42 +00001292 D->setPropertyImplementation(
David L. Jonesbe1557a2016-12-21 00:17:49 +00001293 (ObjCPropertyDecl::PropertyControl)Record.readInt());
Argyrios Kyrtzidisc6c4ec82017-03-17 00:49:42 +00001294 DeclarationName GetterName = Record.readDeclarationName();
1295 SourceLocation GetterLoc = ReadSourceLocation();
1296 D->setGetterName(GetterName.getObjCSelector(), GetterLoc);
1297 DeclarationName SetterName = Record.readDeclarationName();
1298 SourceLocation SetterLoc = ReadSourceLocation();
1299 D->setSetterName(SetterName.getObjCSelector(), SetterLoc);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001300 D->setGetterMethodDecl(ReadDeclAs<ObjCMethodDecl>());
1301 D->setSetterMethodDecl(ReadDeclAs<ObjCMethodDecl>());
1302 D->setPropertyIvarDecl(ReadDeclAs<ObjCIvarDecl>());
Chris Lattner487412d2009-04-27 05:27:42 +00001303}
1304
Sebastian Redlb3298c32010-08-18 23:56:48 +00001305void ASTDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) {
Argyrios Kyrtzidis067c4072009-07-27 19:04:32 +00001306 VisitObjCContainerDecl(D);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001307 D->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>());
Chris Lattner487412d2009-04-27 05:27:42 +00001308}
1309
Sebastian Redlb3298c32010-08-18 23:56:48 +00001310void ASTDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +00001311 VisitObjCImplDecl(D);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001312 D->CategoryNameLoc = ReadSourceLocation();
Chris Lattner487412d2009-04-27 05:27:42 +00001313}
1314
Sebastian Redlb3298c32010-08-18 23:56:48 +00001315void ASTDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +00001316 VisitObjCImplDecl(D);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001317 D->setSuperClass(ReadDeclAs<ObjCInterfaceDecl>());
1318 D->SuperLoc = ReadSourceLocation();
1319 D->setIvarLBraceLoc(ReadSourceLocation());
1320 D->setIvarRBraceLoc(ReadSourceLocation());
David L. Jonesbe1557a2016-12-21 00:17:49 +00001321 D->setHasNonZeroConstructors(Record.readInt());
1322 D->setHasDestructors(Record.readInt());
1323 D->NumIvarInitializers = Record.readInt();
Richard Smithc2bb8182015-03-24 06:36:48 +00001324 if (D->NumIvarInitializers)
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001325 D->IvarInitializers = ReadGlobalOffset();
Chris Lattner487412d2009-04-27 05:27:42 +00001326}
1327
Sebastian Redlb3298c32010-08-18 23:56:48 +00001328void ASTDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +00001329 VisitDecl(D);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001330 D->setAtLoc(ReadSourceLocation());
1331 D->setPropertyDecl(ReadDeclAs<ObjCPropertyDecl>());
1332 D->PropertyIvarDecl = ReadDeclAs<ObjCIvarDecl>();
1333 D->IvarLoc = ReadSourceLocation();
Adrian Prantl2073dd22019-11-04 14:28:14 -08001334 D->setGetterMethodDecl(ReadDeclAs<ObjCMethodDecl>());
1335 D->setSetterMethodDecl(ReadDeclAs<ObjCMethodDecl>());
David L. Jonesb6a8f022016-12-21 04:34:52 +00001336 D->setGetterCXXConstructor(Record.readExpr());
1337 D->setSetterCXXAssignment(Record.readExpr());
Chris Lattner487412d2009-04-27 05:27:42 +00001338}
1339
Sebastian Redlb3298c32010-08-18 23:56:48 +00001340void ASTDeclReader::VisitFieldDecl(FieldDecl *FD) {
Argyrios Kyrtzidis560ac972009-08-19 01:28:35 +00001341 VisitDeclaratorDecl(FD);
David L. Jonesbe1557a2016-12-21 00:17:49 +00001342 FD->Mutable = Record.readInt();
Richard Smith6b8e3c02017-08-28 00:28:14 +00001343
1344 if (auto ISK = static_cast<FieldDecl::InitStorageKind>(Record.readInt())) {
1345 FD->InitStorage.setInt(ISK);
1346 FD->InitStorage.setPointer(ISK == FieldDecl::ISK_CapturedVLAType
1347 ? Record.readType().getAsOpaquePtr()
1348 : Record.readExpr());
Richard Smith2b013182012-06-10 03:12:00 +00001349 }
Richard Smith6b8e3c02017-08-28 00:28:14 +00001350
1351 if (auto *BW = Record.readExpr())
1352 FD->setBitWidth(BW);
1353
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +00001354 if (!FD->getDeclName()) {
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00001355 if (auto *Tmpl = ReadDeclAs<FieldDecl>())
Douglas Gregor4163aca2011-09-09 21:34:22 +00001356 Reader.getContext().setInstantiatedFromUnnamedFieldDecl(FD, Tmpl);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +00001357 }
Richard Smith0b87e072013-10-07 08:02:11 +00001358 mergeMergeable(FD);
Chris Lattner487412d2009-04-27 05:27:42 +00001359}
1360
John McCall5e77d762013-04-16 07:28:30 +00001361void ASTDeclReader::VisitMSPropertyDecl(MSPropertyDecl *PD) {
1362 VisitDeclaratorDecl(PD);
David L. Jonesb6a8f022016-12-21 04:34:52 +00001363 PD->GetterId = Record.getIdentifierInfo();
1364 PD->SetterId = Record.getIdentifierInfo();
John McCall5e77d762013-04-16 07:28:30 +00001365}
1366
Francois Pichet783dd6e2010-11-21 06:08:52 +00001367void ASTDeclReader::VisitIndirectFieldDecl(IndirectFieldDecl *FD) {
1368 VisitValueDecl(FD);
1369
David L. Jonesbe1557a2016-12-21 00:17:49 +00001370 FD->ChainingSize = Record.readInt();
Francois Pichet783dd6e2010-11-21 06:08:52 +00001371 assert(FD->ChainingSize >= 2 && "Anonymous chaining must be >= 2");
Douglas Gregor4163aca2011-09-09 21:34:22 +00001372 FD->Chaining = new (Reader.getContext())NamedDecl*[FD->ChainingSize];
Francois Pichet783dd6e2010-11-21 06:08:52 +00001373
1374 for (unsigned I = 0; I != FD->ChainingSize; ++I)
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001375 FD->Chaining[I] = ReadDeclAs<NamedDecl>();
Richard Smith8cbd8952015-08-04 02:05:09 +00001376
1377 mergeMergeable(FD);
Francois Pichet783dd6e2010-11-21 06:08:52 +00001378}
1379
Larisse Voufo39a1e502013-08-06 01:03:05 +00001380ASTDeclReader::RedeclarableResult ASTDeclReader::VisitVarDeclImpl(VarDecl *VD) {
Douglas Gregorb8c6f1e2012-01-04 17:21:36 +00001381 RedeclarableResult Redecl = VisitRedeclarable(VD);
Douglas Gregor3e300102011-10-26 17:53:41 +00001382 VisitDeclaratorDecl(VD);
Rafael Espindola6ae7e502013-04-03 19:27:57 +00001383
David L. Jonesbe1557a2016-12-21 00:17:49 +00001384 VD->VarDeclBits.SClass = (StorageClass)Record.readInt();
1385 VD->VarDeclBits.TSCSpec = Record.readInt();
1386 VD->VarDeclBits.InitStyle = Record.readInt();
Erik Pilkington1e368822019-01-04 18:33:06 +00001387 VD->VarDeclBits.ARCPseudoStrong = Record.readInt();
David Majnemerfa7bc782015-05-19 00:57:16 +00001388 if (!isa<ParmVarDecl>(VD)) {
David L. Jonesbe1557a2016-12-21 00:17:49 +00001389 VD->NonParmVarDeclBits.IsThisDeclarationADemotedDefinition =
1390 Record.readInt();
1391 VD->NonParmVarDeclBits.ExceptionVar = Record.readInt();
Taiju Tsuiki3be68e12018-06-19 05:35:30 +00001392 VD->NonParmVarDeclBits.NRVOVariable = Record.readInt();
David L. Jonesbe1557a2016-12-21 00:17:49 +00001393 VD->NonParmVarDeclBits.CXXForRangeDecl = Record.readInt();
George Karpenkovec38cf72018-03-29 00:56:24 +00001394 VD->NonParmVarDeclBits.ObjCForDecl = Record.readInt();
David L. Jonesbe1557a2016-12-21 00:17:49 +00001395 VD->NonParmVarDeclBits.IsInline = Record.readInt();
1396 VD->NonParmVarDeclBits.IsInlineSpecified = Record.readInt();
1397 VD->NonParmVarDeclBits.IsConstexpr = Record.readInt();
1398 VD->NonParmVarDeclBits.IsInitCapture = Record.readInt();
1399 VD->NonParmVarDeclBits.PreviousDeclInSameBlockScope = Record.readInt();
Alexey Bataev56223232017-06-09 13:40:18 +00001400 VD->NonParmVarDeclBits.ImplicitParamKind = Record.readInt();
Akira Hatanaka8e57b072018-10-01 21:51:28 +00001401 VD->NonParmVarDeclBits.EscapingByref = Record.readInt();
David Majnemerfa7bc782015-05-19 00:57:16 +00001402 }
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00001403 auto VarLinkage = Linkage(Record.readInt());
Richard Smith541b38b2013-09-20 01:15:31 +00001404 VD->setCachedLinkage(VarLinkage);
1405
1406 // Reconstruct the one piece of the IdentifierNamespace that we need.
Ted Kremeneka683f632014-02-11 06:29:29 +00001407 if (VD->getStorageClass() == SC_Extern && VarLinkage != NoLinkage &&
Richard Smith541b38b2013-09-20 01:15:31 +00001408 VD->getLexicalDeclContext()->isFunctionOrMethod())
1409 VD->setLocalExternDecl();
Rafael Espindola50df3a02013-05-25 17:16:20 +00001410
David L. Jonesbe1557a2016-12-21 00:17:49 +00001411 if (uint64_t Val = Record.readInt()) {
David L. Jonesb6a8f022016-12-21 04:34:52 +00001412 VD->setInit(Record.readExpr());
Richard Smith2b4fa532019-09-29 05:08:46 +00001413 if (Val > 1) {
Richard Smithd0b4dd62011-12-19 06:19:21 +00001414 EvaluatedStmt *Eval = VD->ensureEvaluatedStmt();
1415 Eval->CheckedICE = true;
Richard Smith2b4fa532019-09-29 05:08:46 +00001416 Eval->IsICE = (Val & 1) != 0;
1417 Eval->HasConstantDestruction = (Val & 4) != 0;
Richard Smithd0b4dd62011-12-19 06:19:21 +00001418 }
1419 }
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +00001420
Akira Hatanaka9978da32018-08-10 15:09:24 +00001421 if (VD->hasAttr<BlocksAttr>() && VD->getType()->getAsCXXRecordDecl()) {
1422 Expr *CopyExpr = Record.readExpr();
1423 if (CopyExpr)
1424 Reader.getContext().setBlockVarCopyInit(VD, CopyExpr, Record.readInt());
1425 }
1426
Richard Smitha4653622017-09-06 20:01:14 +00001427 if (VD->getStorageDuration() == SD_Static && Record.readInt())
1428 Reader.DefinitionSource[VD] = Loc.F->Kind == ModuleKind::MK_MainFile;
1429
Larisse Voufod8dd97c2013-08-14 03:09:19 +00001430 enum VarKind {
1431 VarNotTemplate = 0, VarTemplate, StaticDataMemberSpecialization
1432 };
David L. Jonesbe1557a2016-12-21 00:17:49 +00001433 switch ((VarKind)Record.readInt()) {
Larisse Voufod8dd97c2013-08-14 03:09:19 +00001434 case VarNotTemplate:
Richard Smith9b88a4c2015-07-27 05:40:23 +00001435 // Only true variables (not parameters or implicit parameters) can be
1436 // merged; the other kinds are not really redeclarable at all.
Richard Smith0144f512015-08-22 02:09:38 +00001437 if (!isa<ParmVarDecl>(VD) && !isa<ImplicitParamDecl>(VD) &&
1438 !isa<VarTemplateSpecializationDecl>(VD))
Richard Smithf17fdbd2014-04-24 02:25:27 +00001439 mergeRedeclarable(VD, Redecl);
Larisse Voufod8dd97c2013-08-14 03:09:19 +00001440 break;
1441 case VarTemplate:
Richard Smithf17fdbd2014-04-24 02:25:27 +00001442 // Merged when we merge the template.
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001443 VD->setDescribedVarTemplate(ReadDeclAs<VarTemplateDecl>());
Larisse Voufod8dd97c2013-08-14 03:09:19 +00001444 break;
1445 case StaticDataMemberSpecialization: { // HasMemberSpecializationInfo.
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00001446 auto *Tmpl = ReadDeclAs<VarDecl>();
1447 auto TSK = (TemplateSpecializationKind)Record.readInt();
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001448 SourceLocation POI = ReadSourceLocation();
Douglas Gregor4163aca2011-09-09 21:34:22 +00001449 Reader.getContext().setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI);
Richard Smithf17fdbd2014-04-24 02:25:27 +00001450 mergeRedeclarable(VD, Redecl);
Larisse Voufod8dd97c2013-08-14 03:09:19 +00001451 break;
1452 }
Argyrios Kyrtzidiscdb8b3f2010-07-04 21:44:00 +00001453 }
Larisse Voufo39a1e502013-08-06 01:03:05 +00001454
1455 return Redecl;
Chris Lattner487412d2009-04-27 05:27:42 +00001456}
1457
Sebastian Redlb3298c32010-08-18 23:56:48 +00001458void ASTDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) {
Chris Lattner487412d2009-04-27 05:27:42 +00001459 VisitVarDecl(PD);
1460}
1461
Sebastian Redlb3298c32010-08-18 23:56:48 +00001462void ASTDeclReader::VisitParmVarDecl(ParmVarDecl *PD) {
Chris Lattner487412d2009-04-27 05:27:42 +00001463 VisitVarDecl(PD);
David L. Jonesbe1557a2016-12-21 00:17:49 +00001464 unsigned isObjCMethodParam = Record.readInt();
1465 unsigned scopeDepth = Record.readInt();
1466 unsigned scopeIndex = Record.readInt();
1467 unsigned declQualifier = Record.readInt();
John McCall82490832011-05-02 00:30:12 +00001468 if (isObjCMethodParam) {
1469 assert(scopeDepth == 0);
1470 PD->setObjCMethodScopeInfo(scopeIndex);
1471 PD->ParmVarDeclBits.ScopeDepthOrObjCQuals = declQualifier;
1472 } else {
1473 PD->setScopeInfo(scopeDepth, scopeIndex);
1474 }
David L. Jonesbe1557a2016-12-21 00:17:49 +00001475 PD->ParmVarDeclBits.IsKNRPromoted = Record.readInt();
1476 PD->ParmVarDeclBits.HasInheritedDefaultArg = Record.readInt();
1477 if (Record.readInt()) // hasUninstantiatedDefaultArg.
David L. Jonesb6a8f022016-12-21 04:34:52 +00001478 PD->setUninstantiatedDefaultArg(Record.readExpr());
Richard Smithbf78e642013-06-24 22:51:00 +00001479
1480 // FIXME: If this is a redeclaration of a function from another module, handle
1481 // inheritance of default arguments.
Chris Lattner487412d2009-04-27 05:27:42 +00001482}
1483
Richard Smith7b76d812016-08-12 02:21:25 +00001484void ASTDeclReader::VisitDecompositionDecl(DecompositionDecl *DD) {
1485 VisitVarDecl(DD);
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00001486 auto **BDs = DD->getTrailingObjects<BindingDecl *>();
Richard Smith0353e5a2019-05-25 01:04:17 +00001487 for (unsigned I = 0; I != DD->NumBindings; ++I) {
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001488 BDs[I] = ReadDeclAs<BindingDecl>();
Richard Smith0353e5a2019-05-25 01:04:17 +00001489 BDs[I]->setDecomposedDecl(DD);
1490 }
Richard Smith7b76d812016-08-12 02:21:25 +00001491}
1492
1493void ASTDeclReader::VisitBindingDecl(BindingDecl *BD) {
1494 VisitValueDecl(BD);
David L. Jonesb6a8f022016-12-21 04:34:52 +00001495 BD->Binding = Record.readExpr();
Richard Smith7b76d812016-08-12 02:21:25 +00001496}
1497
Sebastian Redlb3298c32010-08-18 23:56:48 +00001498void ASTDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) {
Chris Lattner487412d2009-04-27 05:27:42 +00001499 VisitDecl(AD);
David L. Jonesb6a8f022016-12-21 04:34:52 +00001500 AD->setAsmString(cast<StringLiteral>(Record.readExpr()));
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001501 AD->setRParenLoc(ReadSourceLocation());
Chris Lattner487412d2009-04-27 05:27:42 +00001502}
1503
Sebastian Redlb3298c32010-08-18 23:56:48 +00001504void ASTDeclReader::VisitBlockDecl(BlockDecl *BD) {
Chris Lattner487412d2009-04-27 05:27:42 +00001505 VisitDecl(BD);
David L. Jonesb6a8f022016-12-21 04:34:52 +00001506 BD->setBody(cast_or_null<CompoundStmt>(Record.readStmt()));
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001507 BD->setSignatureAsWritten(GetTypeSourceInfo());
David L. Jonesbe1557a2016-12-21 00:17:49 +00001508 unsigned NumParams = Record.readInt();
Chris Lattner0e62c1c2011-07-23 10:55:15 +00001509 SmallVector<ParmVarDecl *, 16> Params;
Chris Lattner487412d2009-04-27 05:27:42 +00001510 Params.reserve(NumParams);
1511 for (unsigned I = 0; I != NumParams; ++I)
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001512 Params.push_back(ReadDeclAs<ParmVarDecl>());
David Blaikie9c70e042011-09-21 18:16:56 +00001513 BD->setParams(Params);
John McCallc63de662011-02-02 13:00:07 +00001514
David L. Jonesbe1557a2016-12-21 00:17:49 +00001515 BD->setIsVariadic(Record.readInt());
1516 BD->setBlockMissingReturnType(Record.readInt());
1517 BD->setIsConversionFromLambda(Record.readInt());
Akira Hatanakadb49a1f2018-08-01 23:51:53 +00001518 BD->setDoesNotEscape(Record.readInt());
Akira Hatanakac5792aa2019-02-27 18:17:16 +00001519 BD->setCanAvoidCopyToHeap(Record.readInt());
John McCallcf6ce282012-04-13 17:33:29 +00001520
David L. Jonesbe1557a2016-12-21 00:17:49 +00001521 bool capturesCXXThis = Record.readInt();
1522 unsigned numCaptures = Record.readInt();
Chris Lattner0e62c1c2011-07-23 10:55:15 +00001523 SmallVector<BlockDecl::Capture, 16> captures;
John McCall351762c2011-02-07 10:33:21 +00001524 captures.reserve(numCaptures);
1525 for (unsigned i = 0; i != numCaptures; ++i) {
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00001526 auto *decl = ReadDeclAs<VarDecl>();
David L. Jonesbe1557a2016-12-21 00:17:49 +00001527 unsigned flags = Record.readInt();
John McCall351762c2011-02-07 10:33:21 +00001528 bool byRef = (flags & 1);
1529 bool nested = (flags & 2);
David L. Jonesb6a8f022016-12-21 04:34:52 +00001530 Expr *copyExpr = ((flags & 4) ? Record.readExpr() : nullptr);
John McCall351762c2011-02-07 10:33:21 +00001531
1532 captures.push_back(BlockDecl::Capture(decl, byRef, nested, copyExpr));
1533 }
Benjamin Kramerb40e4af2015-08-05 09:40:35 +00001534 BD->setCaptures(Reader.getContext(), captures, capturesCXXThis);
Chris Lattner487412d2009-04-27 05:27:42 +00001535}
1536
Ben Langmuirce914fc2013-05-03 19:20:19 +00001537void ASTDeclReader::VisitCapturedDecl(CapturedDecl *CD) {
1538 VisitDecl(CD);
David L. Jonesbe1557a2016-12-21 00:17:49 +00001539 unsigned ContextParamPos = Record.readInt();
1540 CD->setNothrow(Record.readInt() != 0);
Ben Langmuirce914fc2013-05-03 19:20:19 +00001541 // Body is set by VisitCapturedStmt.
Alexey Bataev9959db52014-05-06 10:08:46 +00001542 for (unsigned I = 0; I < CD->NumParams; ++I) {
1543 if (I != ContextParamPos)
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001544 CD->setParam(I, ReadDeclAs<ImplicitParamDecl>());
Alexey Bataev9959db52014-05-06 10:08:46 +00001545 else
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001546 CD->setContextParam(I, ReadDeclAs<ImplicitParamDecl>());
Alexey Bataev9959db52014-05-06 10:08:46 +00001547 }
Tareq A. Siraj6dfa25a2013-04-16 19:37:38 +00001548}
1549
Sebastian Redlb3298c32010-08-18 23:56:48 +00001550void ASTDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001551 VisitDecl(D);
David L. Jonesbe1557a2016-12-21 00:17:49 +00001552 D->setLanguage((LinkageSpecDecl::LanguageIDs)Record.readInt());
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001553 D->setExternLoc(ReadSourceLocation());
1554 D->setRBraceLoc(ReadSourceLocation());
Chris Lattnerca025db2010-05-07 21:43:38 +00001555}
1556
Richard Smith8df390f2016-09-08 23:14:54 +00001557void ASTDeclReader::VisitExportDecl(ExportDecl *D) {
1558 VisitDecl(D);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001559 D->RBraceLoc = ReadSourceLocation();
Richard Smith8df390f2016-09-08 23:14:54 +00001560}
1561
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001562void ASTDeclReader::VisitLabelDecl(LabelDecl *D) {
1563 VisitNamedDecl(D);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001564 D->setLocStart(ReadSourceLocation());
Chris Lattnerc8e630e2011-02-17 07:39:24 +00001565}
1566
Sebastian Redlb3298c32010-08-18 23:56:48 +00001567void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl *D) {
Douglas Gregore57e7522012-01-07 09:11:48 +00001568 RedeclarableResult Redecl = VisitRedeclarable(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001569 VisitNamedDecl(D);
David L. Jonesbe1557a2016-12-21 00:17:49 +00001570 D->setInline(Record.readInt());
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001571 D->LocStart = ReadSourceLocation();
1572 D->RBraceLoc = ReadSourceLocation();
Douglas Gregorcfe7dc62012-01-09 17:30:44 +00001573
Richard Smith15e32fd2015-03-17 02:23:11 +00001574 // Defer loading the anonymous namespace until we've finished merging
1575 // this namespace; loading it might load a later declaration of the
1576 // same namespace, and we have an invariant that older declarations
1577 // get merged before newer ones try to merge.
1578 GlobalDeclID AnonNamespace = 0;
Douglas Gregore57e7522012-01-07 09:11:48 +00001579 if (Redecl.getFirstID() == ThisDeclID) {
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001580 AnonNamespace = ReadDeclID();
Douglas Gregore57e7522012-01-07 09:11:48 +00001581 } else {
1582 // Link this namespace back to the first declaration, which has already
1583 // been deserialized.
Rafael Espindola8db352d2013-10-17 15:37:26 +00001584 D->AnonOrFirstNamespaceAndInline.setPointer(D->getFirstDecl());
Douglas Gregore57e7522012-01-07 09:11:48 +00001585 }
Richard Smith5e9e56a2014-07-15 03:37:06 +00001586
1587 mergeRedeclarable(D, Redecl);
Richard Smith15e32fd2015-03-17 02:23:11 +00001588
1589 if (AnonNamespace) {
1590 // Each module has its own anonymous namespace, which is disjoint from
1591 // any other module's anonymous namespaces, so don't attach the anonymous
1592 // namespace at all.
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00001593 auto *Anon = cast<NamespaceDecl>(Reader.GetDecl(AnonNamespace));
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001594 if (!Record.isModule())
Richard Smith15e32fd2015-03-17 02:23:11 +00001595 D->setAnonymousNamespace(Anon);
1596 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001597}
1598
Sebastian Redlb3298c32010-08-18 23:56:48 +00001599void ASTDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) {
Richard Smithf4634362014-09-03 23:11:22 +00001600 RedeclarableResult Redecl = VisitRedeclarable(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001601 VisitNamedDecl(D);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001602 D->NamespaceLoc = ReadSourceLocation();
1603 D->IdentLoc = ReadSourceLocation();
David L. Jonesb6a8f022016-12-21 04:34:52 +00001604 D->QualifierLoc = Record.readNestedNameSpecifierLoc();
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001605 D->Namespace = ReadDeclAs<NamedDecl>();
Richard Smithf4634362014-09-03 23:11:22 +00001606 mergeRedeclarable(D, Redecl);
Chris Lattnerca025db2010-05-07 21:43:38 +00001607}
1608
Sebastian Redlb3298c32010-08-18 23:56:48 +00001609void ASTDeclReader::VisitUsingDecl(UsingDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001610 VisitNamedDecl(D);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001611 D->setUsingLoc(ReadSourceLocation());
David L. Jonesb6a8f022016-12-21 04:34:52 +00001612 D->QualifierLoc = Record.readNestedNameSpecifierLoc();
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001613 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName());
1614 D->FirstUsingShadow.setPointer(ReadDeclAs<UsingShadowDecl>());
David L. Jonesbe1557a2016-12-21 00:17:49 +00001615 D->setTypename(Record.readInt());
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00001616 if (auto *Pattern = ReadDeclAs<NamedDecl>())
Douglas Gregor4163aca2011-09-09 21:34:22 +00001617 Reader.getContext().setInstantiatedFromUsingDecl(D, Pattern);
Richard Smith32952e12014-10-14 02:00:47 +00001618 mergeMergeable(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001619}
1620
Richard Smith151c4562016-12-20 21:35:28 +00001621void ASTDeclReader::VisitUsingPackDecl(UsingPackDecl *D) {
1622 VisitNamedDecl(D);
1623 D->InstantiatedFrom = ReadDeclAs<NamedDecl>();
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00001624 auto **Expansions = D->getTrailingObjects<NamedDecl *>();
Richard Smith151c4562016-12-20 21:35:28 +00001625 for (unsigned I = 0; I != D->NumExpansions; ++I)
1626 Expansions[I] = ReadDeclAs<NamedDecl>();
1627 mergeMergeable(D);
1628}
1629
Sebastian Redlb3298c32010-08-18 23:56:48 +00001630void ASTDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) {
Richard Smithfd8634a2013-10-23 02:17:46 +00001631 RedeclarableResult Redecl = VisitRedeclarable(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001632 VisitNamedDecl(D);
Richard Smitha263c342018-01-06 01:07:05 +00001633 D->Underlying = ReadDeclAs<NamedDecl>();
1634 D->IdentifierNamespace = Record.readInt();
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001635 D->UsingOrNextShadow = ReadDeclAs<NamedDecl>();
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00001636 auto *Pattern = ReadDeclAs<UsingShadowDecl>();
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +00001637 if (Pattern)
Douglas Gregor4163aca2011-09-09 21:34:22 +00001638 Reader.getContext().setInstantiatedFromUsingShadowDecl(D, Pattern);
Richard Smithfd8634a2013-10-23 02:17:46 +00001639 mergeRedeclarable(D, Redecl);
Chris Lattnerca025db2010-05-07 21:43:38 +00001640}
1641
Richard Smith5179eb72016-06-28 19:03:57 +00001642void ASTDeclReader::VisitConstructorUsingShadowDecl(
1643 ConstructorUsingShadowDecl *D) {
1644 VisitUsingShadowDecl(D);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001645 D->NominatedBaseClassShadowDecl = ReadDeclAs<ConstructorUsingShadowDecl>();
1646 D->ConstructedBaseClassShadowDecl = ReadDeclAs<ConstructorUsingShadowDecl>();
David L. Jonesbe1557a2016-12-21 00:17:49 +00001647 D->IsVirtual = Record.readInt();
Richard Smith5179eb72016-06-28 19:03:57 +00001648}
1649
Sebastian Redlb3298c32010-08-18 23:56:48 +00001650void ASTDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001651 VisitNamedDecl(D);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001652 D->UsingLoc = ReadSourceLocation();
1653 D->NamespaceLoc = ReadSourceLocation();
David L. Jonesb6a8f022016-12-21 04:34:52 +00001654 D->QualifierLoc = Record.readNestedNameSpecifierLoc();
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001655 D->NominatedNamespace = ReadDeclAs<NamedDecl>();
1656 D->CommonAncestor = ReadDeclAs<DeclContext>();
Chris Lattnerca025db2010-05-07 21:43:38 +00001657}
1658
Sebastian Redlb3298c32010-08-18 23:56:48 +00001659void ASTDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001660 VisitValueDecl(D);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001661 D->setUsingLoc(ReadSourceLocation());
David L. Jonesb6a8f022016-12-21 04:34:52 +00001662 D->QualifierLoc = Record.readNestedNameSpecifierLoc();
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001663 ReadDeclarationNameLoc(D->DNLoc, D->getDeclName());
Richard Smith151c4562016-12-20 21:35:28 +00001664 D->EllipsisLoc = ReadSourceLocation();
Richard Smith32952e12014-10-14 02:00:47 +00001665 mergeMergeable(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001666}
1667
Sebastian Redlb3298c32010-08-18 23:56:48 +00001668void ASTDeclReader::VisitUnresolvedUsingTypenameDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00001669 UnresolvedUsingTypenameDecl *D) {
1670 VisitTypeDecl(D);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001671 D->TypenameLocation = ReadSourceLocation();
David L. Jonesb6a8f022016-12-21 04:34:52 +00001672 D->QualifierLoc = Record.readNestedNameSpecifierLoc();
Richard Smith151c4562016-12-20 21:35:28 +00001673 D->EllipsisLoc = ReadSourceLocation();
Richard Smith32952e12014-10-14 02:00:47 +00001674 mergeMergeable(D);
Chris Lattnerca025db2010-05-07 21:43:38 +00001675}
1676
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +00001677void ASTDeclReader::ReadCXXDefinitionData(
David Blaikie1ac9c982017-04-11 21:13:37 +00001678 struct CXXRecordDecl::DefinitionData &Data, const CXXRecordDecl *D) {
Richard Smith91aeacc2019-10-11 00:29:04 +00001679 #define FIELD(Name, Width, Merge) \
1680 Data.Name = Record.readInt();
1681 #include "clang/AST/CXXRecordDeclDefinitionBits.def"
1682
Douglas Gregor99ae8062012-02-14 17:54:36 +00001683 // Note: the caller has deserialized the IsLambda bit already.
Richard Trieub6adf542017-02-18 02:09:28 +00001684 Data.ODRHash = Record.readInt();
Richard Trieufd1acbb2017-04-11 21:31:00 +00001685 Data.HasODRHash = true;
Anders Carlsson703d6e62011-01-22 18:11:02 +00001686
Richard Smithcd4a7a42017-09-07 00:55:55 +00001687 if (Record.readInt())
1688 Reader.DefinitionSource[D] = Loc.F->Kind == ModuleKind::MK_MainFile;
David Blaikie1ac9c982017-04-11 21:13:37 +00001689
David L. Jonesbe1557a2016-12-21 00:17:49 +00001690 Data.NumBases = Record.readInt();
Douglas Gregord4c5ed02010-10-29 22:39:52 +00001691 if (Data.NumBases)
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001692 Data.Bases = ReadGlobalOffset();
David L. Jonesbe1557a2016-12-21 00:17:49 +00001693 Data.NumVBases = Record.readInt();
Douglas Gregord4c5ed02010-10-29 22:39:52 +00001694 if (Data.NumVBases)
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001695 Data.VBases = ReadGlobalOffset();
1696
David L. Jonesb6a8f022016-12-21 04:34:52 +00001697 Record.readUnresolvedSet(Data.Conversions);
Richard Smith91aeacc2019-10-11 00:29:04 +00001698 Data.ComputedVisibleConversions = Record.readInt();
1699 if (Data.ComputedVisibleConversions)
1700 Record.readUnresolvedSet(Data.VisibleConversions);
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +00001701 assert(Data.Definition && "Data.Definition should be already set!");
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001702 Data.FirstFriend = ReadDeclID();
Richard Smith9dd9f032013-08-30 00:23:29 +00001703
Douglas Gregor99ae8062012-02-14 17:54:36 +00001704 if (Data.IsLambda) {
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00001705 using Capture = LambdaCapture;
1706
1707 auto &Lambda = static_cast<CXXRecordDecl::LambdaDefinitionData &>(Data);
David L. Jonesbe1557a2016-12-21 00:17:49 +00001708 Lambda.Dependent = Record.readInt();
1709 Lambda.IsGenericLambda = Record.readInt();
1710 Lambda.CaptureDefault = Record.readInt();
1711 Lambda.NumCaptures = Record.readInt();
1712 Lambda.NumExplicitCaptures = Record.readInt();
Michael Liao243ebfb2019-10-19 00:15:19 +00001713 Lambda.HasKnownInternalLinkage = Record.readInt();
David L. Jonesbe1557a2016-12-21 00:17:49 +00001714 Lambda.ManglingNumber = Record.readInt();
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001715 Lambda.ContextDecl = ReadDeclID();
Richard Smithdbafb6c2017-06-29 23:23:46 +00001716 Lambda.Captures = (Capture *)Reader.getContext().Allocate(
1717 sizeof(Capture) * Lambda.NumCaptures);
Douglas Gregor99ae8062012-02-14 17:54:36 +00001718 Capture *ToCapture = Lambda.Captures;
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001719 Lambda.MethodTyInfo = GetTypeSourceInfo();
Douglas Gregor99ae8062012-02-14 17:54:36 +00001720 for (unsigned I = 0, N = Lambda.NumCaptures; I != N; ++I) {
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001721 SourceLocation Loc = ReadSourceLocation();
David L. Jonesbe1557a2016-12-21 00:17:49 +00001722 bool IsImplicit = Record.readInt();
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00001723 auto Kind = static_cast<LambdaCaptureKind>(Record.readInt());
Richard Smithba71c082013-05-16 06:20:58 +00001724 switch (Kind) {
Fangrui Song6907ce22018-07-30 19:24:48 +00001725 case LCK_StarThis:
Richard Smithba71c082013-05-16 06:20:58 +00001726 case LCK_This:
Alexey Bataev39c81e22014-08-28 04:28:19 +00001727 case LCK_VLAType:
Craig Toppera13603a2014-05-22 05:54:18 +00001728 *ToCapture++ = Capture(Loc, IsImplicit, Kind, nullptr,SourceLocation());
Richard Smithba71c082013-05-16 06:20:58 +00001729 break;
1730 case LCK_ByCopy:
Richard Smithbb13c9a2013-09-28 04:02:39 +00001731 case LCK_ByRef:
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00001732 auto *Var = ReadDeclAs<VarDecl>();
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001733 SourceLocation EllipsisLoc = ReadSourceLocation();
Richard Smithba71c082013-05-16 06:20:58 +00001734 *ToCapture++ = Capture(Loc, IsImplicit, Kind, Var, EllipsisLoc);
1735 break;
1736 }
Douglas Gregor99ae8062012-02-14 17:54:36 +00001737 }
1738 }
Argyrios Kyrtzidis8b200a52010-10-24 17:26:27 +00001739}
1740
Richard Smithcd45dbc2014-04-19 03:48:30 +00001741void ASTDeclReader::MergeDefinitionData(
Richard Smith8a639892015-01-24 01:07:20 +00001742 CXXRecordDecl *D, struct CXXRecordDecl::DefinitionData &&MergeDD) {
Richard Smithb6483992016-05-17 22:44:15 +00001743 assert(D->DefinitionData &&
Richard Smith053f6c62014-05-16 23:01:30 +00001744 "merging class definition into non-definition");
Richard Smithb6483992016-05-17 22:44:15 +00001745 auto &DD = *D->DefinitionData;
Richard Smithcd45dbc2014-04-19 03:48:30 +00001746
Richard Smith02793752015-03-27 21:16:39 +00001747 if (DD.Definition != MergeDD.Definition) {
Richard Smith97100e32015-06-20 00:22:34 +00001748 // Track that we merged the definitions.
1749 Reader.MergedDeclContexts.insert(std::make_pair(MergeDD.Definition,
1750 DD.Definition));
1751 Reader.PendingDefinitions.erase(MergeDD.Definition);
Erich Keanef92f31c2018-08-01 20:48:16 +00001752 MergeDD.Definition->setCompleteDefinition(false);
Richard Smith6561f922016-09-12 21:06:40 +00001753 Reader.mergeDefinitionVisibility(DD.Definition, MergeDD.Definition);
Richard Smithd88a7f12015-09-01 20:35:42 +00001754 assert(Reader.Lookups.find(MergeDD.Definition) == Reader.Lookups.end() &&
1755 "already loaded pending lookups for merged definition");
Richard Smith02793752015-03-27 21:16:39 +00001756 }
1757
Richard Smith2a9e5c52015-02-03 03:32:14 +00001758 auto PFDI = Reader.PendingFakeDefinitionData.find(&DD);
1759 if (PFDI != Reader.PendingFakeDefinitionData.end() &&
1760 PFDI->second == ASTReader::PendingFakeDefinitionKind::Fake) {
Richard Smith8a639892015-01-24 01:07:20 +00001761 // We faked up this definition data because we found a class for which we'd
1762 // not yet loaded the definition. Replace it with the real thing now.
Richard Smith8a639892015-01-24 01:07:20 +00001763 assert(!DD.IsLambda && !MergeDD.IsLambda && "faked up lambda definition?");
Richard Smith2a9e5c52015-02-03 03:32:14 +00001764 PFDI->second = ASTReader::PendingFakeDefinitionKind::FakeLoaded;
Richard Smith8a639892015-01-24 01:07:20 +00001765
1766 // Don't change which declaration is the definition; that is required
1767 // to be invariant once we select it.
1768 auto *Def = DD.Definition;
1769 DD = std::move(MergeDD);
1770 DD.Definition = Def;
1771 return;
1772 }
1773
Richard Smithcd45dbc2014-04-19 03:48:30 +00001774 bool DetectedOdrViolation = false;
Richard Smith91aeacc2019-10-11 00:29:04 +00001775
1776 #define FIELD(Name, Width, Merge) Merge(Name)
1777 #define MERGE_OR(Field) DD.Field |= MergeDD.Field;
1778 #define NO_MERGE(Field) \
Richard Smithcd45dbc2014-04-19 03:48:30 +00001779 DetectedOdrViolation |= DD.Field != MergeDD.Field; \
Richard Smith91aeacc2019-10-11 00:29:04 +00001780 MERGE_OR(Field)
1781 #include "clang/AST/CXXRecordDeclDefinitionBits.def"
1782 NO_MERGE(IsLambda)
1783 #undef NO_MERGE
1784 #undef MERGE_OR
Richard Smithcd45dbc2014-04-19 03:48:30 +00001785
1786 if (DD.NumBases != MergeDD.NumBases || DD.NumVBases != MergeDD.NumVBases)
1787 DetectedOdrViolation = true;
1788 // FIXME: Issue a diagnostic if the base classes don't match when we come
1789 // to lazily load them.
1790
1791 // FIXME: Issue a diagnostic if the list of conversion functions doesn't
1792 // match when we come to lazily load them.
1793 if (MergeDD.ComputedVisibleConversions && !DD.ComputedVisibleConversions) {
1794 DD.VisibleConversions = std::move(MergeDD.VisibleConversions);
1795 DD.ComputedVisibleConversions = true;
1796 }
1797
1798 // FIXME: Issue a diagnostic if FirstFriend doesn't match when we come to
1799 // lazily load it.
1800
1801 if (DD.IsLambda) {
1802 // FIXME: ODR-checking for merging lambdas (this happens, for instance,
1803 // when they occur within the body of a function template specialization).
1804 }
1805
Richard Trieufd1acbb2017-04-11 21:31:00 +00001806 if (D->getODRHash() != MergeDD.ODRHash) {
1807 DetectedOdrViolation = true;
1808 }
1809
Richard Smithcd45dbc2014-04-19 03:48:30 +00001810 if (DetectedOdrViolation)
Richard Trieue13eabe2017-09-30 02:19:17 +00001811 Reader.PendingOdrMergeFailures[DD.Definition].push_back(
1812 {MergeDD.Definition, &MergeDD});
Richard Smithcd45dbc2014-04-19 03:48:30 +00001813}
1814
Richard Smith2a9e5c52015-02-03 03:32:14 +00001815void ASTDeclReader::ReadCXXRecordDefinition(CXXRecordDecl *D, bool Update) {
Richard Smithcd45dbc2014-04-19 03:48:30 +00001816 struct CXXRecordDecl::DefinitionData *DD;
1817 ASTContext &C = Reader.getContext();
1818
1819 // Determine whether this is a lambda closure type, so that we can
1820 // allocate the appropriate DefinitionData structure.
David L. Jonesbe1557a2016-12-21 00:17:49 +00001821 bool IsLambda = Record.readInt();
Richard Smithcd45dbc2014-04-19 03:48:30 +00001822 if (IsLambda)
Craig Toppera13603a2014-05-22 05:54:18 +00001823 DD = new (C) CXXRecordDecl::LambdaDefinitionData(D, nullptr, false, false,
Richard Smithcd45dbc2014-04-19 03:48:30 +00001824 LCD_None);
1825 else
1826 DD = new (C) struct CXXRecordDecl::DefinitionData(D);
1827
Volodymyr Sapsai8a5943f2018-03-21 21:28:54 +00001828 CXXRecordDecl *Canon = D->getCanonicalDecl();
1829 // Set decl definition data before reading it, so that during deserialization
1830 // when we read CXXRecordDecl, it already has definition data and we don't
1831 // set fake one.
1832 if (!Canon->DefinitionData)
1833 Canon->DefinitionData = DD;
1834 D->DefinitionData = Canon->DefinitionData;
David Blaikie1ac9c982017-04-11 21:13:37 +00001835 ReadCXXDefinitionData(*DD, D);
Richard Smithcd45dbc2014-04-19 03:48:30 +00001836
Volodymyr Sapsai8a5943f2018-03-21 21:28:54 +00001837 // We might already have a different definition for this record. This can
1838 // happen either because we're reading an update record, or because we've
1839 // already done some merging. Either way, just merge into it.
1840 if (Canon->DefinitionData != DD) {
Richard Smith8a639892015-01-24 01:07:20 +00001841 MergeDefinitionData(Canon, std::move(*DD));
Richard Smithcd45dbc2014-04-19 03:48:30 +00001842 return;
1843 }
1844
Richard Smith97100e32015-06-20 00:22:34 +00001845 // Mark this declaration as being a definition.
Erich Keanef92f31c2018-08-01 20:48:16 +00001846 D->setCompleteDefinition(true);
Richard Smith2a9e5c52015-02-03 03:32:14 +00001847
Richard Smith97100e32015-06-20 00:22:34 +00001848 // If this is not the first declaration or is an update record, we can have
1849 // other redeclarations already. Make a note that we need to propagate the
1850 // DefinitionData pointer onto them.
Volodymyr Sapsai8a5943f2018-03-21 21:28:54 +00001851 if (Update || Canon != D)
Richard Smithcd45dbc2014-04-19 03:48:30 +00001852 Reader.PendingDefinitions.insert(D);
Richard Smithcd45dbc2014-04-19 03:48:30 +00001853}
1854
Richard Smith1d209d02013-05-23 01:49:11 +00001855ASTDeclReader::RedeclarableResult
1856ASTDeclReader::VisitCXXRecordDeclImpl(CXXRecordDecl *D) {
1857 RedeclarableResult Redecl = VisitRecordDeclImpl(D);
Argyrios Kyrtzidisa41f6602010-10-20 00:11:15 +00001858
Douglas Gregor3a5ae562012-01-15 18:17:48 +00001859 ASTContext &C = Reader.getContext();
Argyrios Kyrtzidis2c2167a2010-07-02 11:55:32 +00001860
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001861 enum CXXRecKind {
1862 CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization
1863 };
David L. Jonesbe1557a2016-12-21 00:17:49 +00001864 switch ((CXXRecKind)Record.readInt()) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001865 case CXXRecNotTemplate:
Richard Smithdc5523d2014-07-11 00:20:06 +00001866 // Merged when we merge the folding set entry in the primary template.
1867 if (!isa<ClassTemplateSpecializationDecl>(D))
1868 mergeRedeclarable(D, Redecl);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001869 break;
Richard Smithf17fdbd2014-04-24 02:25:27 +00001870 case CXXRecTemplate: {
1871 // Merged when we merge the template.
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00001872 auto *Template = ReadDeclAs<ClassTemplateDecl>();
Richard Smithf17fdbd2014-04-24 02:25:27 +00001873 D->TemplateOrInstantiation = Template;
1874 if (!Template->getTemplatedDecl()) {
1875 // We've not actually loaded the ClassTemplateDecl yet, because we're
1876 // currently being loaded as its pattern. Rely on it to set up our
1877 // TypeForDecl (see VisitClassTemplateDecl).
1878 //
1879 // Beware: we do not yet know our canonical declaration, and may still
1880 // get merged once the surrounding class template has got off the ground.
Richard Smith600adef2018-07-04 02:25:38 +00001881 DeferredTypeID = 0;
Richard Smithf17fdbd2014-04-24 02:25:27 +00001882 }
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001883 break;
Richard Smithf17fdbd2014-04-24 02:25:27 +00001884 }
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001885 case CXXRecMemberSpecialization: {
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00001886 auto *RD = ReadDeclAs<CXXRecordDecl>();
1887 auto TSK = (TemplateSpecializationKind)Record.readInt();
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001888 SourceLocation POI = ReadSourceLocation();
Argyrios Kyrtzidiscaf82482010-09-13 11:45:25 +00001889 MemberSpecializationInfo *MSI = new (C) MemberSpecializationInfo(RD, TSK);
1890 MSI->setPointOfInstantiation(POI);
1891 D->TemplateOrInstantiation = MSI;
Richard Smithcd45dbc2014-04-19 03:48:30 +00001892 mergeRedeclarable(D, Redecl);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00001893 break;
1894 }
1895 }
Argyrios Kyrtzidis68431412010-10-14 20:14:38 +00001896
David L. Jonesbe1557a2016-12-21 00:17:49 +00001897 bool WasDefinition = Record.readInt();
Richard Smithcd45dbc2014-04-19 03:48:30 +00001898 if (WasDefinition)
Richard Smith2a9e5c52015-02-03 03:32:14 +00001899 ReadCXXRecordDefinition(D, /*Update*/false);
Richard Smithcd45dbc2014-04-19 03:48:30 +00001900 else
1901 // Propagate DefinitionData pointer from the canonical declaration.
1902 D->DefinitionData = D->getCanonicalDecl()->DefinitionData;
1903
Richard Smith676c4042013-08-29 23:59:27 +00001904 // Lazily load the key function to avoid deserializing every method so we can
Argyrios Kyrtzidis68431412010-10-14 20:14:38 +00001905 // compute it.
Richard Smithd55889a2013-09-09 16:55:27 +00001906 if (WasDefinition) {
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001907 DeclID KeyFn = ReadDeclID();
Erich Keanef92f31c2018-08-01 20:48:16 +00001908 if (KeyFn && D->isCompleteDefinition())
Richard Smitha9a1c682014-07-07 06:38:20 +00001909 // FIXME: This is wrong for the ARM ABI, where some other module may have
1910 // made this function no longer be a key function. We need an update
1911 // record or similar for that case.
Richard Smith676c4042013-08-29 23:59:27 +00001912 C.KeyFunctions[D] = KeyFn;
Argyrios Kyrtzidis68431412010-10-14 20:14:38 +00001913 }
Richard Smith1d209d02013-05-23 01:49:11 +00001914
1915 return Redecl;
Chris Lattnerca025db2010-05-07 21:43:38 +00001916}
1917
Richard Smithbc491202017-02-17 20:05:37 +00001918void ASTDeclReader::VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D) {
Richard Smith76b90272019-05-09 03:59:21 +00001919 D->setExplicitSpecifier(Record.readExplicitSpec());
Richard Smithbc491202017-02-17 20:05:37 +00001920 VisitFunctionDecl(D);
Erich Keane9c665062018-08-01 21:02:40 +00001921 D->setIsCopyDeductionCandidate(Record.readInt());
Richard Smithbc491202017-02-17 20:05:37 +00001922}
1923
Sebastian Redlb3298c32010-08-18 23:56:48 +00001924void ASTDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001925 VisitFunctionDecl(D);
Richard Smithb1108732014-08-26 23:29:11 +00001926
David L. Jonesbe1557a2016-12-21 00:17:49 +00001927 unsigned NumOverridenMethods = Record.readInt();
Richard Smithb1108732014-08-26 23:29:11 +00001928 if (D->isCanonicalDecl()) {
1929 while (NumOverridenMethods--) {
1930 // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod,
1931 // MD may be initializing.
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00001932 if (auto *MD = ReadDeclAs<CXXMethodDecl>())
Richard Smithb1108732014-08-26 23:29:11 +00001933 Reader.getContext().addOverriddenMethod(D, MD->getCanonicalDecl());
1934 }
1935 } else {
1936 // We don't care about which declarations this used to override; we get
1937 // the relevant information from the canonical declaration.
David L. Jonesbe1557a2016-12-21 00:17:49 +00001938 Record.skipInts(NumOverridenMethods);
Argyrios Kyrtzidis6685e8a2010-07-04 21:44:35 +00001939 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001940}
1941
Sebastian Redlb3298c32010-08-18 23:56:48 +00001942void ASTDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) {
Richard Smith5179eb72016-06-28 19:03:57 +00001943 // We need the inherited constructor information to merge the declaration,
1944 // so we have to read it before we call VisitCXXMethodDecl.
Richard Smith76b90272019-05-09 03:59:21 +00001945 D->setExplicitSpecifier(Record.readExplicitSpec());
Richard Smith5179eb72016-06-28 19:03:57 +00001946 if (D->isInheritingConstructor()) {
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001947 auto *Shadow = ReadDeclAs<ConstructorUsingShadowDecl>();
1948 auto *Ctor = ReadDeclAs<CXXConstructorDecl>();
Richard Smith5179eb72016-06-28 19:03:57 +00001949 *D->getTrailingObjects<InheritedConstructor>() =
1950 InheritedConstructor(Shadow, Ctor);
1951 }
1952
Chris Lattnerca025db2010-05-07 21:43:38 +00001953 VisitCXXMethodDecl(D);
1954}
1955
Sebastian Redlb3298c32010-08-18 23:56:48 +00001956void ASTDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) {
Chris Lattnerca025db2010-05-07 21:43:38 +00001957 VisitCXXMethodDecl(D);
Argyrios Kyrtzidis33575162010-07-02 15:58:43 +00001958
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001959 if (auto *OperatorDelete = ReadDeclAs<FunctionDecl>()) {
George Burgess IV00f70bd2018-03-01 05:43:23 +00001960 CXXDestructorDecl *Canon = D->getCanonicalDecl();
Richard Smith5b349582017-10-13 01:55:36 +00001961 auto *ThisArg = Record.readExpr();
Richard Smithf8134002015-03-10 01:41:22 +00001962 // FIXME: Check consistency if we have an old and new operator delete.
Richard Smith5b349582017-10-13 01:55:36 +00001963 if (!Canon->OperatorDelete) {
Richard Smithf8134002015-03-10 01:41:22 +00001964 Canon->OperatorDelete = OperatorDelete;
Richard Smith5b349582017-10-13 01:55:36 +00001965 Canon->OperatorDeleteThisArg = ThisArg;
1966 }
Richard Smithf8134002015-03-10 01:41:22 +00001967 }
Chris Lattnerca025db2010-05-07 21:43:38 +00001968}
1969
Sebastian Redlb3298c32010-08-18 23:56:48 +00001970void ASTDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) {
Richard Smith76b90272019-05-09 03:59:21 +00001971 D->setExplicitSpecifier(Record.readExplicitSpec());
Chris Lattnerca025db2010-05-07 21:43:38 +00001972 VisitCXXMethodDecl(D);
1973}
1974
Douglas Gregorba345522011-12-02 23:23:56 +00001975void ASTDeclReader::VisitImportDecl(ImportDecl *D) {
1976 VisitDecl(D);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001977 D->ImportedAndComplete.setPointer(readModule());
David L. Jonesbe1557a2016-12-21 00:17:49 +00001978 D->ImportedAndComplete.setInt(Record.readInt());
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00001979 auto *StoredLocs = D->getTrailingObjects<SourceLocation>();
Douglas Gregorba345522011-12-02 23:23:56 +00001980 for (unsigned I = 0, N = Record.back(); I != N; ++I)
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001981 StoredLocs[I] = ReadSourceLocation();
David L. Jones267b8842017-01-24 01:04:30 +00001982 Record.skipInts(1); // The number of stored source locations.
Douglas Gregorba345522011-12-02 23:23:56 +00001983}
1984
Sebastian Redlb3298c32010-08-18 23:56:48 +00001985void ASTDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) {
Abramo Bagnarad7340582010-06-05 05:09:32 +00001986 VisitDecl(D);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001987 D->setColonLoc(ReadSourceLocation());
Abramo Bagnarad7340582010-06-05 05:09:32 +00001988}
1989
Sebastian Redlb3298c32010-08-18 23:56:48 +00001990void ASTDeclReader::VisitFriendDecl(FriendDecl *D) {
Argyrios Kyrtzidisa95d0192010-07-05 10:38:01 +00001991 VisitDecl(D);
David L. Jonesbe1557a2016-12-21 00:17:49 +00001992 if (Record.readInt()) // hasFriendDecl
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001993 D->Friend = ReadDeclAs<NamedDecl>();
Enea Zaffanellaeb22c872013-01-31 09:54:08 +00001994 else
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001995 D->Friend = GetTypeSourceInfo();
Enea Zaffanellaeb22c872013-01-31 09:54:08 +00001996 for (unsigned i = 0; i != D->NumTPLists; ++i)
James Y Knight967eb202015-12-29 22:13:13 +00001997 D->getTrailingObjects<TemplateParameterList *>()[i] =
David L. Jonesb6a8f022016-12-21 04:34:52 +00001998 Record.readTemplateParameterList();
David L. Jonesc4808b9e2016-12-15 20:53:26 +00001999 D->NextFriend = ReadDeclID();
David L. Jonesbe1557a2016-12-21 00:17:49 +00002000 D->UnsupportedFriend = (Record.readInt() != 0);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002001 D->FriendLoc = ReadSourceLocation();
Argyrios Kyrtzidis74d28bd2010-06-29 22:47:00 +00002002}
2003
Sebastian Redlb3298c32010-08-18 23:56:48 +00002004void ASTDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) {
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00002005 VisitDecl(D);
David L. Jonesbe1557a2016-12-21 00:17:49 +00002006 unsigned NumParams = Record.readInt();
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00002007 D->NumParams = NumParams;
2008 D->Params = new TemplateParameterList*[NumParams];
2009 for (unsigned i = 0; i != NumParams; ++i)
David L. Jonesb6a8f022016-12-21 04:34:52 +00002010 D->Params[i] = Record.readTemplateParameterList();
David L. Jonesbe1557a2016-12-21 00:17:49 +00002011 if (Record.readInt()) // HasFriendDecl
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002012 D->Friend = ReadDeclAs<NamedDecl>();
Argyrios Kyrtzidis165b5812010-07-22 16:04:10 +00002013 else
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002014 D->Friend = GetTypeSourceInfo();
2015 D->FriendLoc = ReadSourceLocation();
Chris Lattnerca025db2010-05-07 21:43:38 +00002016}
2017
Richard Smithf17fdbd2014-04-24 02:25:27 +00002018DeclID ASTDeclReader::VisitTemplateDecl(TemplateDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00002019 VisitNamedDecl(D);
2020
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002021 DeclID PatternID = ReadDeclID();
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00002022 auto *TemplatedDecl = cast_or_null<NamedDecl>(Reader.GetDecl(PatternID));
David L. Jonesb6a8f022016-12-21 04:34:52 +00002023 TemplateParameterList *TemplateParams = Record.readTemplateParameterList();
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00002024 D->init(TemplatedDecl, TemplateParams);
Richard Smithbf78e642013-06-24 22:51:00 +00002025
Richard Smithf17fdbd2014-04-24 02:25:27 +00002026 return PatternID;
Chris Lattnerca025db2010-05-07 21:43:38 +00002027}
2028
Saar Razd7aae332019-07-10 21:25:49 +00002029void ASTDeclReader::VisitConceptDecl(ConceptDecl *D) {
2030 VisitTemplateDecl(D);
2031 D->ConstraintExpr = Record.readExpr();
2032 mergeMergeable(D);
2033}
2034
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002035ASTDeclReader::RedeclarableResult
Douglas Gregor54079202012-01-06 22:05:37 +00002036ASTDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) {
Douglas Gregor68444de2012-01-14 15:13:49 +00002037 RedeclarableResult Redecl = VisitRedeclarable(D);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00002038
Douglas Gregor68444de2012-01-14 15:13:49 +00002039 // Make sure we've allocated the Common pointer first. We do this before
2040 // VisitTemplateDecl so that getCommonPtr() can be used during initialization.
2041 RedeclarableTemplateDecl *CanonD = D->getCanonicalDecl();
2042 if (!CanonD->Common) {
2043 CanonD->Common = CanonD->newCommon(Reader.getContext());
2044 Reader.PendingDefinitions.insert(CanonD);
2045 }
2046 D->Common = CanonD->Common;
Douglas Gregor022857e2011-12-22 01:48:48 +00002047
Douglas Gregor68444de2012-01-14 15:13:49 +00002048 // If this is the first declaration of the template, fill in the information
2049 // for the 'common' pointer.
2050 if (ThisDeclID == Redecl.getFirstID()) {
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00002051 if (auto *RTD = ReadDeclAs<RedeclarableTemplateDecl>()) {
Peter Collingbourne91b25b72010-07-29 16:11:51 +00002052 assert(RTD->getKind() == D->getKind() &&
2053 "InstantiatedFromMemberTemplate kind mismatch");
Douglas Gregor68444de2012-01-14 15:13:49 +00002054 D->setInstantiatedFromMemberTemplate(RTD);
David L. Jonesbe1557a2016-12-21 00:17:49 +00002055 if (Record.readInt())
Peter Collingbourne91b25b72010-07-29 16:11:51 +00002056 D->setMemberSpecialization();
2057 }
2058 }
Axel Naumann866ba3e2012-10-01 09:18:00 +00002059
Richard Smithf17fdbd2014-04-24 02:25:27 +00002060 DeclID PatternID = VisitTemplateDecl(D);
David L. Jonesbe1557a2016-12-21 00:17:49 +00002061 D->IdentifierNamespace = Record.readInt();
Axel Naumann866ba3e2012-10-01 09:18:00 +00002062
Richard Smithf17fdbd2014-04-24 02:25:27 +00002063 mergeRedeclarable(D, Redecl, PatternID);
Axel Naumann866ba3e2012-10-01 09:18:00 +00002064
Richard Smithd46d6de2013-10-13 23:50:45 +00002065 // If we merged the template with a prior declaration chain, merge the common
2066 // pointer.
2067 // FIXME: Actually merge here, don't just overwrite.
2068 D->Common = D->getCanonicalDecl()->Common;
2069
Douglas Gregor68444de2012-01-14 15:13:49 +00002070 return Redecl;
Peter Collingbourne91b25b72010-07-29 16:11:51 +00002071}
2072
Sebastian Redlb3298c32010-08-18 23:56:48 +00002073void ASTDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) {
Douglas Gregor68444de2012-01-14 15:13:49 +00002074 RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D);
Peter Collingbourne91b25b72010-07-29 16:11:51 +00002075
Douglas Gregor68444de2012-01-14 15:13:49 +00002076 if (ThisDeclID == Redecl.getFirstID()) {
Douglas Gregor7e8c4e02010-10-27 22:21:36 +00002077 // This ClassTemplateDecl owns a CommonPtr; read it to keep track of all of
2078 // the specializations.
Richard Smith0b884372015-02-27 00:25:58 +00002079 SmallVector<serialization::DeclID, 32> SpecIDs;
Richard Smith0b884372015-02-27 00:25:58 +00002080 ReadDeclIDList(SpecIDs);
Vassil Vassilev7d264622017-06-30 22:40:17 +00002081 ASTDeclReader::AddLazySpecializations(D, SpecIDs);
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00002082 }
Richard Smithf17fdbd2014-04-24 02:25:27 +00002083
2084 if (D->getTemplatedDecl()->TemplateOrInstantiation) {
2085 // We were loaded before our templated declaration was. We've not set up
2086 // its corresponding type yet (see VisitCXXRecordDeclImpl), so reconstruct
2087 // it now.
Richard Smithdbafb6c2017-06-29 23:23:46 +00002088 Reader.getContext().getInjectedClassNameType(
Richard Smitha1406fa2014-05-23 21:31:59 +00002089 D->getTemplatedDecl(), D->getInjectedClassNameSpecialization());
Richard Smithf17fdbd2014-04-24 02:25:27 +00002090 }
Chris Lattnerca025db2010-05-07 21:43:38 +00002091}
2092
David Majnemerd9b1a4f2015-11-04 03:40:30 +00002093void ASTDeclReader::VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D) {
2094 llvm_unreachable("BuiltinTemplates are not serialized");
2095}
2096
Larisse Voufo30616382013-08-23 22:21:36 +00002097/// TODO: Unify with ClassTemplateDecl version?
2098/// May require unifying ClassTemplateDecl and
2099/// VarTemplateDecl beyond TemplateDecl...
Larisse Voufo39a1e502013-08-06 01:03:05 +00002100void ASTDeclReader::VisitVarTemplateDecl(VarTemplateDecl *D) {
2101 RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D);
2102
2103 if (ThisDeclID == Redecl.getFirstID()) {
Larisse Voufod8dd97c2013-08-14 03:09:19 +00002104 // This VarTemplateDecl owns a CommonPtr; read it to keep track of all of
Larisse Voufo39a1e502013-08-06 01:03:05 +00002105 // the specializations.
Richard Smith0b884372015-02-27 00:25:58 +00002106 SmallVector<serialization::DeclID, 32> SpecIDs;
Richard Smith0b884372015-02-27 00:25:58 +00002107 ReadDeclIDList(SpecIDs);
Vassil Vassilev7d264622017-06-30 22:40:17 +00002108 ASTDeclReader::AddLazySpecializations(D, SpecIDs);
Larisse Voufo39a1e502013-08-06 01:03:05 +00002109 }
2110}
2111
Richard Smith1d209d02013-05-23 01:49:11 +00002112ASTDeclReader::RedeclarableResult
2113ASTDeclReader::VisitClassTemplateSpecializationDeclImpl(
2114 ClassTemplateSpecializationDecl *D) {
2115 RedeclarableResult Redecl = VisitCXXRecordDeclImpl(D);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002116
Douglas Gregor4163aca2011-09-09 21:34:22 +00002117 ASTContext &C = Reader.getContext();
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002118 if (Decl *InstD = ReadDecl()) {
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00002119 if (auto *CTD = dyn_cast<ClassTemplateDecl>(InstD)) {
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00002120 D->SpecializedTemplate = CTD;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00002121 } else {
Chris Lattner0e62c1c2011-07-23 10:55:15 +00002122 SmallVector<TemplateArgument, 8> TemplArgs;
David L. Jonesb6a8f022016-12-21 04:34:52 +00002123 Record.readTemplateArgumentList(TemplArgs);
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00002124 TemplateArgumentList *ArgList
David Majnemer8b622692016-07-03 21:17:51 +00002125 = TemplateArgumentList::CreateCopy(C, TemplArgs);
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00002126 auto *PS =
2127 new (C) ClassTemplateSpecializationDecl::
Argyrios Kyrtzidisb4c659b2010-09-13 11:45:32 +00002128 SpecializedPartialSpecialization();
2129 PS->PartialSpecialization
2130 = cast<ClassTemplatePartialSpecializationDecl>(InstD);
2131 PS->TemplateArgs = ArgList;
2132 D->SpecializedTemplate = PS;
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00002133 }
2134 }
2135
Chris Lattner0e62c1c2011-07-23 10:55:15 +00002136 SmallVector<TemplateArgument, 8> TemplArgs;
David L. Jonesb6a8f022016-12-21 04:34:52 +00002137 Record.readTemplateArgumentList(TemplArgs, /*Canonicalize*/ true);
David Majnemer8b622692016-07-03 21:17:51 +00002138 D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002139 D->PointOfInstantiation = ReadSourceLocation();
David L. Jonesbe1557a2016-12-21 00:17:49 +00002140 D->SpecializationKind = (TemplateSpecializationKind)Record.readInt();
Axel Naumanna31dee22012-10-01 07:34:47 +00002141
David L. Jonesbe1557a2016-12-21 00:17:49 +00002142 bool writtenAsCanonicalDecl = Record.readInt();
Axel Naumanna31dee22012-10-01 07:34:47 +00002143 if (writtenAsCanonicalDecl) {
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00002144 auto *CanonPattern = ReadDeclAs<ClassTemplateDecl>();
Axel Naumanna31dee22012-10-01 07:34:47 +00002145 if (D->isCanonicalDecl()) { // It's kept in the folding set.
Richard Smithd55889a2013-09-09 16:55:27 +00002146 // Set this as, or find, the canonical declaration for this specialization
2147 ClassTemplateSpecializationDecl *CanonSpec;
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00002148 if (auto *Partial = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) {
Richard Smithd55889a2013-09-09 16:55:27 +00002149 CanonSpec = CanonPattern->getCommonPtr()->PartialSpecializations
Richard Smith5de91b52013-06-25 01:25:15 +00002150 .GetOrInsertNode(Partial);
Axel Naumanna31dee22012-10-01 07:34:47 +00002151 } else {
Richard Smithd55889a2013-09-09 16:55:27 +00002152 CanonSpec =
2153 CanonPattern->getCommonPtr()->Specializations.GetOrInsertNode(D);
2154 }
2155 // If there was already a canonical specialization, merge into it.
2156 if (CanonSpec != D) {
2157 mergeRedeclarable<TagDecl>(D, CanonSpec, Redecl);
2158
2159 // This declaration might be a definition. Merge with any existing
2160 // definition.
Richard Smithb6483992016-05-17 22:44:15 +00002161 if (auto *DDD = D->DefinitionData) {
2162 if (CanonSpec->DefinitionData)
Richard Smith8a639892015-01-24 01:07:20 +00002163 MergeDefinitionData(CanonSpec, std::move(*DDD));
Richard Smith97100e32015-06-20 00:22:34 +00002164 else
Richard Smith053f6c62014-05-16 23:01:30 +00002165 CanonSpec->DefinitionData = D->DefinitionData;
Richard Smithd55889a2013-09-09 16:55:27 +00002166 }
Richard Smith547864d2014-07-11 18:22:58 +00002167 D->DefinitionData = CanonSpec->DefinitionData;
Axel Naumanna31dee22012-10-01 07:34:47 +00002168 }
Argyrios Kyrtzidis87040572010-07-09 21:11:43 +00002169 }
2170 }
Richard Smith1d209d02013-05-23 01:49:11 +00002171
Richard Smithd55889a2013-09-09 16:55:27 +00002172 // Explicit info.
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002173 if (TypeSourceInfo *TyInfo = GetTypeSourceInfo()) {
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00002174 auto *ExplicitInfo =
2175 new (C) ClassTemplateSpecializationDecl::ExplicitSpecializationInfo;
Richard Smithd55889a2013-09-09 16:55:27 +00002176 ExplicitInfo->TypeAsWritten = TyInfo;
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002177 ExplicitInfo->ExternLoc = ReadSourceLocation();
2178 ExplicitInfo->TemplateKeywordLoc = ReadSourceLocation();
Richard Smithd55889a2013-09-09 16:55:27 +00002179 D->ExplicitInfo = ExplicitInfo;
2180 }
2181
Richard Smith1d209d02013-05-23 01:49:11 +00002182 return Redecl;
Chris Lattnerca025db2010-05-07 21:43:38 +00002183}
2184
Sebastian Redlb3298c32010-08-18 23:56:48 +00002185void ASTDeclReader::VisitClassTemplatePartialSpecializationDecl(
Chris Lattnerca025db2010-05-07 21:43:38 +00002186 ClassTemplatePartialSpecializationDecl *D) {
Richard Smith1d209d02013-05-23 01:49:11 +00002187 RedeclarableResult Redecl = VisitClassTemplateSpecializationDeclImpl(D);
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00002188
Saar Raz0330fba2019-10-15 18:44:06 +00002189 TemplateParameterList *Params = Record.readTemplateParameterList();
2190 D->TemplateParams = Params;
David L. Jonesb6a8f022016-12-21 04:34:52 +00002191 D->ArgsAsWritten = Record.readASTTemplateArgumentListInfo();
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00002192
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00002193 // These are read/set from/to the first declaration.
Richard Smith1d209d02013-05-23 01:49:11 +00002194 if (ThisDeclID == Redecl.getFirstID()) {
Argyrios Kyrtzidis0e8b3ce2010-09-13 11:45:41 +00002195 D->InstantiatedFromMember.setPointer(
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002196 ReadDeclAs<ClassTemplatePartialSpecializationDecl>());
David L. Jonesbe1557a2016-12-21 00:17:49 +00002197 D->InstantiatedFromMember.setInt(Record.readInt());
Argyrios Kyrtzidis818c5db2010-06-23 13:48:30 +00002198 }
Chris Lattnerca025db2010-05-07 21:43:38 +00002199}
2200
Sebastian Redlb7448632011-08-31 13:59:56 +00002201void ASTDeclReader::VisitClassScopeFunctionSpecializationDecl(
2202 ClassScopeFunctionSpecializationDecl *D) {
Francois Pichet09af8c32011-08-17 01:06:54 +00002203 VisitDecl(D);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002204 D->Specialization = ReadDeclAs<CXXMethodDecl>();
Richard Smithf19a8b02019-05-02 00:49:14 +00002205 if (Record.readInt())
2206 D->TemplateArgs = Record.readASTTemplateArgumentListInfo();
Francois Pichet09af8c32011-08-17 01:06:54 +00002207}
2208
Sebastian Redlb3298c32010-08-18 23:56:48 +00002209void ASTDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) {
Douglas Gregor68444de2012-01-14 15:13:49 +00002210 RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00002211
Douglas Gregor68444de2012-01-14 15:13:49 +00002212 if (ThisDeclID == Redecl.getFirstID()) {
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00002213 // This FunctionTemplateDecl owns a CommonPtr; read it.
Richard Smith0b884372015-02-27 00:25:58 +00002214 SmallVector<serialization::DeclID, 32> SpecIDs;
2215 ReadDeclIDList(SpecIDs);
Vassil Vassilev7d264622017-06-30 22:40:17 +00002216 ASTDeclReader::AddLazySpecializations(D, SpecIDs);
Argyrios Kyrtzidis69da4a82010-06-22 09:55:07 +00002217 }
Chris Lattnerca025db2010-05-07 21:43:38 +00002218}
2219
Larisse Voufo30616382013-08-23 22:21:36 +00002220/// TODO: Unify with ClassTemplateSpecializationDecl version?
2221/// May require unifying ClassTemplate(Partial)SpecializationDecl and
2222/// VarTemplate(Partial)SpecializationDecl with a new data
2223/// structure Template(Partial)SpecializationDecl, and
2224/// using Template(Partial)SpecializationDecl as input type.
Larisse Voufo39a1e502013-08-06 01:03:05 +00002225ASTDeclReader::RedeclarableResult
2226ASTDeclReader::VisitVarTemplateSpecializationDeclImpl(
2227 VarTemplateSpecializationDecl *D) {
2228 RedeclarableResult Redecl = VisitVarDeclImpl(D);
2229
2230 ASTContext &C = Reader.getContext();
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002231 if (Decl *InstD = ReadDecl()) {
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00002232 if (auto *VTD = dyn_cast<VarTemplateDecl>(InstD)) {
Larisse Voufo39a1e502013-08-06 01:03:05 +00002233 D->SpecializedTemplate = VTD;
2234 } else {
2235 SmallVector<TemplateArgument, 8> TemplArgs;
David L. Jonesb6a8f022016-12-21 04:34:52 +00002236 Record.readTemplateArgumentList(TemplArgs);
Larisse Voufo39a1e502013-08-06 01:03:05 +00002237 TemplateArgumentList *ArgList = TemplateArgumentList::CreateCopy(
David Majnemer8b622692016-07-03 21:17:51 +00002238 C, TemplArgs);
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00002239 auto *PS =
Larisse Voufo39a1e502013-08-06 01:03:05 +00002240 new (C)
2241 VarTemplateSpecializationDecl::SpecializedPartialSpecialization();
2242 PS->PartialSpecialization =
2243 cast<VarTemplatePartialSpecializationDecl>(InstD);
2244 PS->TemplateArgs = ArgList;
2245 D->SpecializedTemplate = PS;
2246 }
2247 }
2248
2249 // Explicit info.
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002250 if (TypeSourceInfo *TyInfo = GetTypeSourceInfo()) {
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00002251 auto *ExplicitInfo =
Larisse Voufo39a1e502013-08-06 01:03:05 +00002252 new (C) VarTemplateSpecializationDecl::ExplicitSpecializationInfo;
2253 ExplicitInfo->TypeAsWritten = TyInfo;
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002254 ExplicitInfo->ExternLoc = ReadSourceLocation();
2255 ExplicitInfo->TemplateKeywordLoc = ReadSourceLocation();
Larisse Voufo39a1e502013-08-06 01:03:05 +00002256 D->ExplicitInfo = ExplicitInfo;
2257 }
2258
2259 SmallVector<TemplateArgument, 8> TemplArgs;
David L. Jonesb6a8f022016-12-21 04:34:52 +00002260 Record.readTemplateArgumentList(TemplArgs, /*Canonicalize*/ true);
David Majnemer8b622692016-07-03 21:17:51 +00002261 D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002262 D->PointOfInstantiation = ReadSourceLocation();
David L. Jonesbe1557a2016-12-21 00:17:49 +00002263 D->SpecializationKind = (TemplateSpecializationKind)Record.readInt();
Richard Smith435e6472017-12-02 02:48:42 +00002264 D->IsCompleteDefinition = Record.readInt();
Larisse Voufo39a1e502013-08-06 01:03:05 +00002265
David L. Jonesbe1557a2016-12-21 00:17:49 +00002266 bool writtenAsCanonicalDecl = Record.readInt();
Larisse Voufo39a1e502013-08-06 01:03:05 +00002267 if (writtenAsCanonicalDecl) {
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00002268 auto *CanonPattern = ReadDeclAs<VarTemplateDecl>();
Larisse Voufo39a1e502013-08-06 01:03:05 +00002269 if (D->isCanonicalDecl()) { // It's kept in the folding set.
Richard Smith9b88a4c2015-07-27 05:40:23 +00002270 // FIXME: If it's already present, merge it.
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00002271 if (auto *Partial = dyn_cast<VarTemplatePartialSpecializationDecl>(D)) {
Larisse Voufo39a1e502013-08-06 01:03:05 +00002272 CanonPattern->getCommonPtr()->PartialSpecializations
2273 .GetOrInsertNode(Partial);
2274 } else {
2275 CanonPattern->getCommonPtr()->Specializations.GetOrInsertNode(D);
2276 }
2277 }
2278 }
2279
2280 return Redecl;
2281}
2282
Larisse Voufo30616382013-08-23 22:21:36 +00002283/// TODO: Unify with ClassTemplatePartialSpecializationDecl version?
2284/// May require unifying ClassTemplate(Partial)SpecializationDecl and
2285/// VarTemplate(Partial)SpecializationDecl with a new data
2286/// structure Template(Partial)SpecializationDecl, and
2287/// using Template(Partial)SpecializationDecl as input type.
Larisse Voufo39a1e502013-08-06 01:03:05 +00002288void ASTDeclReader::VisitVarTemplatePartialSpecializationDecl(
2289 VarTemplatePartialSpecializationDecl *D) {
2290 RedeclarableResult Redecl = VisitVarTemplateSpecializationDeclImpl(D);
2291
Saar Raz0330fba2019-10-15 18:44:06 +00002292 TemplateParameterList *Params = Record.readTemplateParameterList();
2293 D->TemplateParams = Params;
David L. Jonesb6a8f022016-12-21 04:34:52 +00002294 D->ArgsAsWritten = Record.readASTTemplateArgumentListInfo();
Larisse Voufo39a1e502013-08-06 01:03:05 +00002295
2296 // These are read/set from/to the first declaration.
2297 if (ThisDeclID == Redecl.getFirstID()) {
2298 D->InstantiatedFromMember.setPointer(
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002299 ReadDeclAs<VarTemplatePartialSpecializationDecl>());
David L. Jonesbe1557a2016-12-21 00:17:49 +00002300 D->InstantiatedFromMember.setInt(Record.readInt());
Larisse Voufo39a1e502013-08-06 01:03:05 +00002301 }
2302}
2303
Sebastian Redlb3298c32010-08-18 23:56:48 +00002304void ASTDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) {
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00002305 VisitTypeDecl(D);
2306
David L. Jonesbe1557a2016-12-21 00:17:49 +00002307 D->setDeclaredWithTypename(Record.readInt());
Argyrios Kyrtzidis95c04ca2010-06-19 19:29:09 +00002308
Saar Raz0330fba2019-10-15 18:44:06 +00002309 // TODO: Concepts: Immediately introduced constraint
David L. Jonesbe1557a2016-12-21 00:17:49 +00002310 if (Record.readInt())
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002311 D->setDefaultArgument(GetTypeSourceInfo());
Chris Lattnerca025db2010-05-07 21:43:38 +00002312}
2313
Sebastian Redlb3298c32010-08-18 23:56:48 +00002314void ASTDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) {
John McCallf4cd4f92011-02-09 01:13:10 +00002315 VisitDeclaratorDecl(D);
Argyrios Kyrtzidisb1d38e32010-06-25 16:25:09 +00002316 // TemplateParmPosition.
David L. Jonesbe1557a2016-12-21 00:17:49 +00002317 D->setDepth(Record.readInt());
2318 D->setPosition(Record.readInt());
Douglas Gregor0231d8d2011-01-19 20:10:05 +00002319 if (D->isExpandedParameterPack()) {
James Y Knight967eb202015-12-29 22:13:13 +00002320 auto TypesAndInfos =
2321 D->getTrailingObjects<std::pair<QualType, TypeSourceInfo *>>();
Douglas Gregor0231d8d2011-01-19 20:10:05 +00002322 for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) {
David L. Jonesbe1557a2016-12-21 00:17:49 +00002323 new (&TypesAndInfos[I].first) QualType(Record.readType());
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002324 TypesAndInfos[I].second = GetTypeSourceInfo();
Douglas Gregor0231d8d2011-01-19 20:10:05 +00002325 }
2326 } else {
2327 // Rest of NonTypeTemplateParmDecl.
David L. Jonesbe1557a2016-12-21 00:17:49 +00002328 D->ParameterPack = Record.readInt();
2329 if (Record.readInt())
David L. Jonesb6a8f022016-12-21 04:34:52 +00002330 D->setDefaultArgument(Record.readExpr());
Douglas Gregor0231d8d2011-01-19 20:10:05 +00002331 }
Chris Lattnerca025db2010-05-07 21:43:38 +00002332}
2333
Sebastian Redlb3298c32010-08-18 23:56:48 +00002334void ASTDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) {
Argyrios Kyrtzidis9f2d24a2010-07-08 17:12:57 +00002335 VisitTemplateDecl(D);
2336 // TemplateParmPosition.
David L. Jonesbe1557a2016-12-21 00:17:49 +00002337 D->setDepth(Record.readInt());
2338 D->setPosition(Record.readInt());
Richard Smith1fde8ec2012-09-07 02:06:42 +00002339 if (D->isExpandedParameterPack()) {
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00002340 auto **Data = D->getTrailingObjects<TemplateParameterList *>();
Richard Smith1fde8ec2012-09-07 02:06:42 +00002341 for (unsigned I = 0, N = D->getNumExpansionTemplateParameters();
2342 I != N; ++I)
David L. Jonesb6a8f022016-12-21 04:34:52 +00002343 Data[I] = Record.readTemplateParameterList();
Richard Smith1fde8ec2012-09-07 02:06:42 +00002344 } else {
2345 // Rest of TemplateTemplateParmDecl.
David L. Jonesbe1557a2016-12-21 00:17:49 +00002346 D->ParameterPack = Record.readInt();
2347 if (Record.readInt())
Richard Smith1469b912015-06-10 00:29:03 +00002348 D->setDefaultArgument(Reader.getContext(),
David L. Jonesb6a8f022016-12-21 04:34:52 +00002349 Record.readTemplateArgumentLoc());
Richard Smith1fde8ec2012-09-07 02:06:42 +00002350 }
Chris Lattnerca025db2010-05-07 21:43:38 +00002351}
2352
Richard Smith3f1b5d02011-05-05 21:57:07 +00002353void ASTDeclReader::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) {
2354 VisitRedeclarableTemplateDecl(D);
2355}
2356
Sebastian Redlb3298c32010-08-18 23:56:48 +00002357void ASTDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) {
Argyrios Kyrtzidis2d8891c2010-07-22 17:28:12 +00002358 VisitDecl(D);
David L. Jonesb6a8f022016-12-21 04:34:52 +00002359 D->AssertExprAndFailed.setPointer(Record.readExpr());
David L. Jonesbe1557a2016-12-21 00:17:49 +00002360 D->AssertExprAndFailed.setInt(Record.readInt());
David L. Jonesb6a8f022016-12-21 04:34:52 +00002361 D->Message = cast_or_null<StringLiteral>(Record.readExpr());
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002362 D->RParenLoc = ReadSourceLocation();
Chris Lattnerca025db2010-05-07 21:43:38 +00002363}
2364
Michael Han84324352013-02-22 17:15:32 +00002365void ASTDeclReader::VisitEmptyDecl(EmptyDecl *D) {
2366 VisitDecl(D);
2367}
2368
Tykerb0561b32019-11-17 11:41:55 +01002369void ASTDeclReader::VisitLifetimeExtendedTemporaryDecl(
2370 LifetimeExtendedTemporaryDecl *D) {
2371 VisitDecl(D);
2372 D->ExtendingDecl = ReadDeclAs<ValueDecl>();
2373 D->ExprWithTemporary = Record.readStmt();
2374 if (Record.readInt())
2375 D->Value = new (D->getASTContext()) APValue(Record.readAPValue());
2376 D->ManglingNumber = Record.readInt();
Tyker9ec6d712019-11-30 16:42:33 +01002377 mergeMergeable(D);
Tykerb0561b32019-11-17 11:41:55 +01002378}
2379
Mike Stump11289f42009-09-09 15:08:12 +00002380std::pair<uint64_t, uint64_t>
Sebastian Redlb3298c32010-08-18 23:56:48 +00002381ASTDeclReader::VisitDeclContext(DeclContext *DC) {
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002382 uint64_t LexicalOffset = ReadLocalOffset();
2383 uint64_t VisibleOffset = ReadLocalOffset();
Chris Lattner487412d2009-04-27 05:27:42 +00002384 return std::make_pair(LexicalOffset, VisibleOffset);
2385}
2386
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00002387template <typename T>
Richard Smith5a4737c2015-02-06 02:42:59 +00002388ASTDeclReader::RedeclarableResult
Douglas Gregor022857e2011-12-22 01:48:48 +00002389ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) {
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002390 DeclID FirstDeclID = ReadDeclID();
Richard Smith5a4737c2015-02-06 02:42:59 +00002391 Decl *MergeWith = nullptr;
Richard Smithd8a83712015-08-22 01:47:18 +00002392
Richard Smith5fc18a92015-07-12 23:43:21 +00002393 bool IsKeyDecl = ThisDeclID == FirstDeclID;
Richard Smithd8a83712015-08-22 01:47:18 +00002394 bool IsFirstLocalDecl = false;
Richard Smith5a4737c2015-02-06 02:42:59 +00002395
Richard Smithd61d4ac2015-08-22 20:13:39 +00002396 uint64_t RedeclOffset = 0;
2397
Douglas Gregor358cd442012-01-15 16:58:34 +00002398 // 0 indicates that this declaration was the only declaration of its entity,
2399 // and is used for space optimization.
Richard Smith5fc18a92015-07-12 23:43:21 +00002400 if (FirstDeclID == 0) {
Douglas Gregor074a4092011-12-19 18:19:24 +00002401 FirstDeclID = ThisDeclID;
Richard Smith5fc18a92015-07-12 23:43:21 +00002402 IsKeyDecl = true;
Richard Smithd8a83712015-08-22 01:47:18 +00002403 IsFirstLocalDecl = true;
David L. Jonesbe1557a2016-12-21 00:17:49 +00002404 } else if (unsigned N = Record.readInt()) {
Richard Smithd8a83712015-08-22 01:47:18 +00002405 // This declaration was the first local declaration, but may have imported
2406 // other declarations.
2407 IsKeyDecl = N == 1;
2408 IsFirstLocalDecl = true;
Richard Smith5fc18a92015-07-12 23:43:21 +00002409
Richard Smithfe620d22015-03-05 23:24:12 +00002410 // We have some declarations that must be before us in our redeclaration
2411 // chain. Read them now, and remember that we ought to merge with one of
2412 // them.
2413 // FIXME: Provide a known merge target to the second and subsequent such
2414 // declaration.
Richard Smithd8a83712015-08-22 01:47:18 +00002415 for (unsigned I = 0; I != N - 1; ++I)
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002416 MergeWith = ReadDecl();
Richard Smithd61d4ac2015-08-22 20:13:39 +00002417
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002418 RedeclOffset = ReadLocalOffset();
Richard Smithd8a83712015-08-22 01:47:18 +00002419 } else {
2420 // This declaration was not the first local declaration. Read the first
2421 // local declaration now, to trigger the import of other redeclarations.
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002422 (void)ReadDecl();
Richard Smith5a4737c2015-02-06 02:42:59 +00002423 }
2424
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00002425 auto *FirstDecl = cast_or_null<T>(Reader.GetDecl(FirstDeclID));
Douglas Gregor358cd442012-01-15 16:58:34 +00002426 if (FirstDecl != D) {
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00002427 // We delay loading of the redeclaration chain to avoid deeply nested calls.
2428 // We temporarily set the first (canonical) declaration as the previous one
2429 // which is the one that matters and mark the real previous DeclID to be
2430 // loaded & attached later on.
David Blaikie7e64fd92012-05-28 19:38:42 +00002431 D->RedeclLink = Redeclarable<T>::PreviousDeclLink(FirstDecl);
Manuel Klimek093b2d42015-03-25 23:18:30 +00002432 D->First = FirstDecl->getCanonicalDecl();
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002433 }
Richard Smithd8a83712015-08-22 01:47:18 +00002434
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00002435 auto *DAsT = static_cast<T *>(D);
Richard Smithd8a83712015-08-22 01:47:18 +00002436
2437 // Note that we need to load local redeclarations of this decl and build a
2438 // decl chain for them. This must happen *after* we perform the preloading
2439 // above; this ensures that the redeclaration chain is built in the correct
2440 // order.
2441 if (IsFirstLocalDecl)
Richard Smithd61d4ac2015-08-22 20:13:39 +00002442 Reader.PendingDeclChains.push_back(std::make_pair(DAsT, RedeclOffset));
Richard Smithd8a83712015-08-22 01:47:18 +00002443
Alexander Shaposhnikovfbc4d682016-09-24 04:21:53 +00002444 return RedeclarableResult(MergeWith, FirstDeclID, IsKeyDecl);
Argyrios Kyrtzidis839bbac2010-08-03 17:30:10 +00002445}
2446
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002447/// Attempts to merge the given declaration (D) with another declaration
Douglas Gregor2c46b5b2012-01-03 17:27:13 +00002448/// of the same entity.
2449template<typename T>
Richard Smith5e9e56a2014-07-15 03:37:06 +00002450void ASTDeclReader::mergeRedeclarable(Redeclarable<T> *DBase,
Richard Smithf17fdbd2014-04-24 02:25:27 +00002451 RedeclarableResult &Redecl,
2452 DeclID TemplatePatternID) {
Douglas Gregore097d4b2012-01-03 17:31:38 +00002453 // If modules are not available, there is no reason to perform this merge.
David Blaikiebbafb8a2012-03-11 07:00:24 +00002454 if (!Reader.getContext().getLangOpts().Modules)
Douglas Gregore097d4b2012-01-03 17:31:38 +00002455 return;
Richard Smithd55889a2013-09-09 16:55:27 +00002456
Richard Smith202850a2015-03-10 02:57:50 +00002457 // If we're not the canonical declaration, we don't need to merge.
2458 if (!DBase->isFirstDecl())
2459 return;
2460
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00002461 auto *D = static_cast<T *>(DBase);
Vassil Vassilev916d8be2016-10-06 13:18:06 +00002462
Richard Smith5a4737c2015-02-06 02:42:59 +00002463 if (auto *Existing = Redecl.getKnownMergeTarget())
2464 // We already know of an existing declaration we should merge with.
2465 mergeRedeclarable(D, cast<T>(Existing), Redecl, TemplatePatternID);
2466 else if (FindExistingResult ExistingRes = findExisting(D))
Richard Smithd55889a2013-09-09 16:55:27 +00002467 if (T *Existing = ExistingRes)
Richard Smithf17fdbd2014-04-24 02:25:27 +00002468 mergeRedeclarable(D, Existing, Redecl, TemplatePatternID);
2469}
2470
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002471/// "Cast" to type T, asserting if we don't have an implicit conversion.
Richard Smithf17fdbd2014-04-24 02:25:27 +00002472/// We use this to put code in a template that will only be valid for certain
2473/// instantiations.
2474template<typename T> static T assert_cast(T t) { return t; }
2475template<typename T> static T assert_cast(...) {
2476 llvm_unreachable("bad assert_cast");
2477}
2478
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002479/// Merge together the pattern declarations from two template
Richard Smithf17fdbd2014-04-24 02:25:27 +00002480/// declarations.
2481void ASTDeclReader::mergeTemplatePattern(RedeclarableTemplateDecl *D,
2482 RedeclarableTemplateDecl *Existing,
Richard Smith5fc18a92015-07-12 23:43:21 +00002483 DeclID DsID, bool IsKeyDecl) {
Richard Smithf17fdbd2014-04-24 02:25:27 +00002484 auto *DPattern = D->getTemplatedDecl();
2485 auto *ExistingPattern = Existing->getTemplatedDecl();
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002486 RedeclarableResult Result(/*MergeWith*/ ExistingPattern,
2487 DPattern->getCanonicalDecl()->getGlobalID(),
Alexander Shaposhnikovfbc4d682016-09-24 04:21:53 +00002488 IsKeyDecl);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002489
Richard Smith547864d2014-07-11 18:22:58 +00002490 if (auto *DClass = dyn_cast<CXXRecordDecl>(DPattern)) {
2491 // Merge with any existing definition.
2492 // FIXME: This is duplicated in several places. Refactor.
2493 auto *ExistingClass =
2494 cast<CXXRecordDecl>(ExistingPattern)->getCanonicalDecl();
Richard Smithb6483992016-05-17 22:44:15 +00002495 if (auto *DDD = DClass->DefinitionData) {
2496 if (ExistingClass->DefinitionData) {
Richard Smith8a639892015-01-24 01:07:20 +00002497 MergeDefinitionData(ExistingClass, std::move(*DDD));
Richard Smith547864d2014-07-11 18:22:58 +00002498 } else {
2499 ExistingClass->DefinitionData = DClass->DefinitionData;
Richard Smith97100e32015-06-20 00:22:34 +00002500 // We may have skipped this before because we thought that DClass
2501 // was the canonical declaration.
Richard Smith7474dd922015-03-11 18:21:02 +00002502 Reader.PendingDefinitions.insert(DClass);
Richard Smith547864d2014-07-11 18:22:58 +00002503 }
2504 }
2505 DClass->DefinitionData = ExistingClass->DefinitionData;
2506
Richard Smithf17fdbd2014-04-24 02:25:27 +00002507 return mergeRedeclarable(DClass, cast<TagDecl>(ExistingPattern),
2508 Result);
Richard Smith547864d2014-07-11 18:22:58 +00002509 }
Richard Smithf17fdbd2014-04-24 02:25:27 +00002510 if (auto *DFunction = dyn_cast<FunctionDecl>(DPattern))
2511 return mergeRedeclarable(DFunction, cast<FunctionDecl>(ExistingPattern),
2512 Result);
2513 if (auto *DVar = dyn_cast<VarDecl>(DPattern))
2514 return mergeRedeclarable(DVar, cast<VarDecl>(ExistingPattern), Result);
Richard Smithf59b7352014-07-28 21:16:37 +00002515 if (auto *DAlias = dyn_cast<TypeAliasDecl>(DPattern))
2516 return mergeRedeclarable(DAlias, cast<TypedefNameDecl>(ExistingPattern),
2517 Result);
Richard Smithf17fdbd2014-04-24 02:25:27 +00002518 llvm_unreachable("merged an unknown kind of redeclarable template");
Richard Smithd55889a2013-09-09 16:55:27 +00002519}
2520
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002521/// Attempts to merge the given declaration (D) with another declaration
Richard Smithd55889a2013-09-09 16:55:27 +00002522/// of the same entity.
2523template<typename T>
Richard Smithf17fdbd2014-04-24 02:25:27 +00002524void ASTDeclReader::mergeRedeclarable(Redeclarable<T> *DBase, T *Existing,
2525 RedeclarableResult &Redecl,
2526 DeclID TemplatePatternID) {
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00002527 auto *D = static_cast<T *>(DBase);
Richard Smithd55889a2013-09-09 16:55:27 +00002528 T *ExistingCanon = Existing->getCanonicalDecl();
Richard Smithf17fdbd2014-04-24 02:25:27 +00002529 T *DCanon = D->getCanonicalDecl();
Richard Smithd55889a2013-09-09 16:55:27 +00002530 if (ExistingCanon != DCanon) {
Richard Smith202850a2015-03-10 02:57:50 +00002531 assert(DCanon->getGlobalID() == Redecl.getFirstID() &&
2532 "already merged this declaration");
Richard Smith5e9e56a2014-07-15 03:37:06 +00002533
Richard Smithd55889a2013-09-09 16:55:27 +00002534 // Have our redeclaration link point back at the canonical declaration
Richard Smith5e9e56a2014-07-15 03:37:06 +00002535 // of the existing declaration, so that this declaration has the
Richard Smithd55889a2013-09-09 16:55:27 +00002536 // appropriate canonical declaration.
2537 D->RedeclLink = Redeclarable<T>::PreviousDeclLink(ExistingCanon);
Manuel Klimek093b2d42015-03-25 23:18:30 +00002538 D->First = ExistingCanon;
Vassil Vassilev928c8252016-04-28 14:13:28 +00002539 ExistingCanon->Used |= D->Used;
2540 D->Used = false;
Richard Smithd55889a2013-09-09 16:55:27 +00002541
2542 // When we merge a namespace, update its pointer to the first namespace.
Richard Smith15e32fd2015-03-17 02:23:11 +00002543 // We cannot have loaded any redeclarations of this declaration yet, so
2544 // there's nothing else that needs to be updated.
Richard Smithf17fdbd2014-04-24 02:25:27 +00002545 if (auto *Namespace = dyn_cast<NamespaceDecl>(D))
Richard Smithd55889a2013-09-09 16:55:27 +00002546 Namespace->AnonOrFirstNamespaceAndInline.setPointer(
Richard Smithf17fdbd2014-04-24 02:25:27 +00002547 assert_cast<NamespaceDecl*>(ExistingCanon));
2548
2549 // When we merge a template, merge its pattern.
2550 if (auto *DTemplate = dyn_cast<RedeclarableTemplateDecl>(D))
2551 mergeTemplatePattern(
2552 DTemplate, assert_cast<RedeclarableTemplateDecl*>(ExistingCanon),
Richard Smith5fc18a92015-07-12 23:43:21 +00002553 TemplatePatternID, Redecl.isKeyDecl());
Richard Smithd55889a2013-09-09 16:55:27 +00002554
Richard Smith5fc18a92015-07-12 23:43:21 +00002555 // If this declaration is a key declaration, make a note of that.
Richard Smithd8a83712015-08-22 01:47:18 +00002556 if (Redecl.isKeyDecl())
Richard Smith5fc18a92015-07-12 23:43:21 +00002557 Reader.KeyDecls[ExistingCanon].push_back(Redecl.getFirstID());
Douglas Gregor2c46b5b2012-01-03 17:27:13 +00002558 }
2559}
2560
Bruno Cardoso Lopes85f87dd2018-04-30 22:14:29 +00002561/// ODR-like semantics for C/ObjC allow us to merge tag types and a structural
2562/// check in Sema guarantees the types can be merged (see C11 6.2.7/1 or C89
2563/// 6.1.2.6/1). Although most merging is done in Sema, we need to guarantee
2564/// that some types are mergeable during deserialization, otherwise name
2565/// lookup fails. This is the case for EnumConstantDecl.
Benjamin Kramer651d0bf2018-05-15 21:26:47 +00002566static bool allowODRLikeMergeInC(NamedDecl *ND) {
Bruno Cardoso Lopes85f87dd2018-04-30 22:14:29 +00002567 if (!ND)
2568 return false;
2569 // TODO: implement merge for other necessary decls.
Benjamin Kramer651d0bf2018-05-15 21:26:47 +00002570 if (isa<EnumConstantDecl>(ND))
Bruno Cardoso Lopes85f87dd2018-04-30 22:14:29 +00002571 return true;
2572 return false;
2573}
2574
Tyker9ec6d712019-11-30 16:42:33 +01002575/// Attempts to merge LifetimeExtendedTemporaryDecl with
2576/// identical class definitions from two different modules.
2577void ASTDeclReader::mergeMergeable(LifetimeExtendedTemporaryDecl *D) {
2578 // If modules are not available, there is no reason to perform this merge.
2579 if (!Reader.getContext().getLangOpts().Modules)
2580 return;
2581
2582 LifetimeExtendedTemporaryDecl *LETDecl = D;
2583
2584 LifetimeExtendedTemporaryDecl *&LookupResult =
2585 Reader.LETemporaryForMerging[std::make_pair(
2586 LETDecl->getExtendingDecl(), LETDecl->getManglingNumber())];
2587 if (LookupResult)
2588 Reader.getContext().setPrimaryMergedDecl(LETDecl,
2589 LookupResult->getCanonicalDecl());
2590 else
2591 LookupResult = LETDecl;
2592}
2593
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002594/// Attempts to merge the given declaration (D) with another declaration
Richard Smith0b87e072013-10-07 08:02:11 +00002595/// of the same entity, for the case where the entity is not actually
2596/// redeclarable. This happens, for instance, when merging the fields of
2597/// identical class definitions from two different modules.
2598template<typename T>
2599void ASTDeclReader::mergeMergeable(Mergeable<T> *D) {
2600 // If modules are not available, there is no reason to perform this merge.
2601 if (!Reader.getContext().getLangOpts().Modules)
2602 return;
2603
Bruno Cardoso Lopes85f87dd2018-04-30 22:14:29 +00002604 // ODR-based merging is performed in C++ and in some cases (tag types) in C.
2605 // Note that C identically-named things in different translation units are
2606 // not redeclarations, but may still have compatible types, where ODR-like
2607 // semantics may apply.
2608 if (!Reader.getContext().getLangOpts().CPlusPlus &&
2609 !allowODRLikeMergeInC(dyn_cast<NamedDecl>(static_cast<T*>(D))))
Richard Smith01a73372013-10-15 22:02:41 +00002610 return;
2611
Richard Smith0b87e072013-10-07 08:02:11 +00002612 if (FindExistingResult ExistingRes = findExisting(static_cast<T*>(D)))
2613 if (T *Existing = ExistingRes)
Richard Smithdbafb6c2017-06-29 23:23:46 +00002614 Reader.getContext().setPrimaryMergedDecl(static_cast<T *>(D),
2615 Existing->getCanonicalDecl());
Richard Smith0b87e072013-10-07 08:02:11 +00002616}
2617
Alexey Bataeva769e072013-03-22 06:34:35 +00002618void ASTDeclReader::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) {
2619 VisitDecl(D);
2620 unsigned NumVars = D->varlist_size();
Alexey Bataev6f6f3b42013-05-13 04:18:18 +00002621 SmallVector<Expr *, 16> Vars;
Alexey Bataeva769e072013-03-22 06:34:35 +00002622 Vars.reserve(NumVars);
2623 for (unsigned i = 0; i != NumVars; ++i) {
David L. Jonesb6a8f022016-12-21 04:34:52 +00002624 Vars.push_back(Record.readExpr());
Alexey Bataeva769e072013-03-22 06:34:35 +00002625 }
2626 D->setVars(Vars);
2627}
2628
Alexey Bataev25ed0c02019-03-07 17:54:44 +00002629void ASTDeclReader::VisitOMPAllocateDecl(OMPAllocateDecl *D) {
2630 VisitDecl(D);
2631 unsigned NumVars = D->varlist_size();
Alexey Bataev9cc10fc2019-03-12 18:52:33 +00002632 unsigned NumClauses = D->clauselist_size();
Alexey Bataev25ed0c02019-03-07 17:54:44 +00002633 SmallVector<Expr *, 16> Vars;
2634 Vars.reserve(NumVars);
2635 for (unsigned i = 0; i != NumVars; ++i) {
2636 Vars.push_back(Record.readExpr());
2637 }
2638 D->setVars(Vars);
Alexey Bataev9cc10fc2019-03-12 18:52:33 +00002639 SmallVector<OMPClause *, 8> Clauses;
2640 Clauses.reserve(NumClauses);
2641 OMPClauseReader ClauseReader(Record);
2642 for (unsigned I = 0; I != NumClauses; ++I)
2643 Clauses.push_back(ClauseReader.readClause());
2644 D->setClauses(Clauses);
Alexey Bataev25ed0c02019-03-07 17:54:44 +00002645}
2646
Kelvin Li1408f912018-09-26 04:28:39 +00002647void ASTDeclReader::VisitOMPRequiresDecl(OMPRequiresDecl * D) {
2648 VisitDecl(D);
2649 unsigned NumClauses = D->clauselist_size();
2650 SmallVector<OMPClause *, 8> Clauses;
2651 Clauses.reserve(NumClauses);
2652 OMPClauseReader ClauseReader(Record);
2653 for (unsigned I = 0; I != NumClauses; ++I)
2654 Clauses.push_back(ClauseReader.readClause());
2655 D->setClauses(Clauses);
2656}
2657
Alexey Bataev94a4f0c2016-03-03 05:21:39 +00002658void ASTDeclReader::VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D) {
Alexey Bataevc5b1d322016-03-04 09:22:22 +00002659 VisitValueDecl(D);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002660 D->setLocation(ReadSourceLocation());
Alexey Bataeve6aa4692018-09-13 16:54:05 +00002661 Expr *In = Record.readExpr();
2662 Expr *Out = Record.readExpr();
2663 D->setCombinerData(In, Out);
2664 Expr *Combiner = Record.readExpr();
2665 D->setCombiner(Combiner);
2666 Expr *Orig = Record.readExpr();
2667 Expr *Priv = Record.readExpr();
2668 D->setInitializerData(Orig, Priv);
2669 Expr *Init = Record.readExpr();
2670 auto IK = static_cast<OMPDeclareReductionDecl::InitKind>(Record.readInt());
2671 D->setInitializer(Init, IK);
David L. Jonesc4808b9e2016-12-15 20:53:26 +00002672 D->PrevDeclInScope = ReadDeclID();
Alexey Bataev94a4f0c2016-03-03 05:21:39 +00002673}
2674
Michael Kruse251e1482019-02-01 20:25:04 +00002675void ASTDeclReader::VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D) {
2676 VisitValueDecl(D);
2677 D->setLocation(ReadSourceLocation());
2678 Expr *MapperVarRefE = Record.readExpr();
2679 D->setMapperVarRef(MapperVarRefE);
2680 D->VarName = Record.readDeclarationName();
2681 D->PrevDeclInScope = ReadDeclID();
2682 unsigned NumClauses = D->clauselist_size();
2683 SmallVector<OMPClause *, 8> Clauses;
2684 Clauses.reserve(NumClauses);
2685 OMPClauseReader ClauseReader(Record);
2686 for (unsigned I = 0; I != NumClauses; ++I)
2687 Clauses.push_back(ClauseReader.readClause());
2688 D->setClauses(Clauses);
2689}
2690
Alexey Bataev4244be22016-02-11 05:35:55 +00002691void ASTDeclReader::VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D) {
Alexey Bataev90c228f2016-02-08 09:29:13 +00002692 VisitVarDecl(D);
2693}
2694
Chris Lattner487412d2009-04-27 05:27:42 +00002695//===----------------------------------------------------------------------===//
Chris Lattner8f63ab52009-04-27 06:01:06 +00002696// Attribute Reading
Chris Lattner487412d2009-04-27 05:27:42 +00002697//===----------------------------------------------------------------------===//
2698
Richard Smithe43e2b32018-08-20 21:47:29 +00002699namespace {
2700class AttrReader {
2701 ModuleFile *F;
2702 ASTReader *Reader;
2703 const ASTReader::RecordData &Record;
2704 unsigned &Idx;
2705
2706public:
2707 AttrReader(ModuleFile &F, ASTReader &Reader,
2708 const ASTReader::RecordData &Record, unsigned &Idx)
2709 : F(&F), Reader(&Reader), Record(Record), Idx(Idx) {}
2710
2711 const uint64_t &readInt() { return Record[Idx++]; }
2712
2713 SourceRange readSourceRange() {
2714 return Reader->ReadSourceRange(*F, Record, Idx);
2715 }
2716
Erich Keane6a24e802019-09-13 17:39:31 +00002717 SourceLocation readSourceLocation() {
2718 return Reader->ReadSourceLocation(*F, Record, Idx);
2719 }
2720
Richard Smithe43e2b32018-08-20 21:47:29 +00002721 Expr *readExpr() { return Reader->ReadExpr(*F); }
2722
2723 std::string readString() {
2724 return Reader->ReadString(Record, Idx);
2725 }
2726
2727 TypeSourceInfo *getTypeSourceInfo() {
2728 return Reader->GetTypeSourceInfo(*F, Record, Idx);
2729 }
2730
2731 IdentifierInfo *getIdentifierInfo() {
2732 return Reader->GetIdentifierInfo(*F, Record, Idx);
2733 }
2734
2735 VersionTuple readVersionTuple() {
2736 return ASTReader::ReadVersionTuple(Record, Idx);
2737 }
2738
2739 template <typename T> T *GetLocalDeclAs(uint32_t LocalID) {
2740 return cast_or_null<T>(Reader->GetLocalDecl(*F, LocalID));
2741 }
2742};
2743}
2744
2745Attr *ASTReader::ReadAttr(ModuleFile &M, const RecordData &Rec,
2746 unsigned &Idx) {
2747 AttrReader Record(M, *this, Rec, Idx);
2748 auto V = Record.readInt();
2749 if (!V)
2750 return nullptr;
2751
2752 Attr *New = nullptr;
2753 // Kind is stored as a 1-based integer because 0 is used to indicate a null
2754 // Attr pointer.
2755 auto Kind = static_cast<attr::Kind>(V - 1);
Richard Smithe43e2b32018-08-20 21:47:29 +00002756 ASTContext &Context = getContext();
Chris Lattner8f63ab52009-04-27 06:01:06 +00002757
Erich Keane6a24e802019-09-13 17:39:31 +00002758 IdentifierInfo *AttrName = Record.getIdentifierInfo();
2759 IdentifierInfo *ScopeName = Record.getIdentifierInfo();
2760 SourceRange AttrRange = Record.readSourceRange();
2761 SourceLocation ScopeLoc = Record.readSourceLocation();
2762 unsigned ParsedKind = Record.readInt();
2763 unsigned Syntax = Record.readInt();
2764 unsigned SpellingIndex = Record.readInt();
2765
2766 AttributeCommonInfo Info(AttrName, ScopeName, AttrRange, ScopeLoc,
2767 AttributeCommonInfo::Kind(ParsedKind),
2768 AttributeCommonInfo::Syntax(Syntax), SpellingIndex);
2769
Alexis Huntdcfba7b2010-08-18 23:23:40 +00002770#include "clang/Serialization/AttrPCHRead.inc"
Chris Lattner8f63ab52009-04-27 06:01:06 +00002771
Richard Smithe43e2b32018-08-20 21:47:29 +00002772 assert(New && "Unable to decode attribute?");
2773 return New;
2774}
2775
2776/// Reads attributes from the current stream position.
2777void ASTReader::ReadAttributes(ASTRecordReader &Record, AttrVec &Attrs) {
2778 for (unsigned I = 0, E = Record.readInt(); I != E; ++I)
2779 Attrs.push_back(Record.readAttr());
Chris Lattner8f63ab52009-04-27 06:01:06 +00002780}
2781
2782//===----------------------------------------------------------------------===//
Sebastian Redl2c499f62010-08-18 23:56:43 +00002783// ASTReader Implementation
Chris Lattner8f63ab52009-04-27 06:01:06 +00002784//===----------------------------------------------------------------------===//
Chris Lattner487412d2009-04-27 05:27:42 +00002785
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002786/// Note that we have loaded the declaration with the given
Chris Lattner487412d2009-04-27 05:27:42 +00002787/// Index.
Mike Stump11289f42009-09-09 15:08:12 +00002788///
Chris Lattner487412d2009-04-27 05:27:42 +00002789/// This routine notes that this declaration has already been loaded,
2790/// so that future GetDecl calls will return this declaration rather
2791/// than trying to load a new declaration.
Sebastian Redl2c499f62010-08-18 23:56:43 +00002792inline void ASTReader::LoadedDecl(unsigned Index, Decl *D) {
Chris Lattner487412d2009-04-27 05:27:42 +00002793 assert(!DeclsLoaded[Index] && "Decl loaded twice?");
2794 DeclsLoaded[Index] = D;
2795}
2796
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002797/// Determine whether the consumer will be interested in seeing
Chris Lattner487412d2009-04-27 05:27:42 +00002798/// this declaration (via HandleTopLevelDecl).
2799///
2800/// This routine should return true for anything that might affect
2801/// code generation, e.g., inline function definitions, Objective-C
2802/// declarations with metadata, etc.
Daniel Jasper4a6d5b72017-10-11 07:47:54 +00002803static bool isConsumerInterestedIn(ASTContext &Ctx, Decl *D, bool HasBody) {
Argyrios Kyrtzidisa98e8612011-09-13 21:35:00 +00002804 // An ObjCMethodDecl is never considered as "interesting" because its
2805 // implementation container always is.
2806
Richard Smithcd4a7a42017-09-07 00:55:55 +00002807 // An ImportDecl or VarDecl imported from a module map module will get
2808 // emitted when we import the relevant module.
Richard Smith520a37f2019-02-05 23:37:13 +00002809 if (isPartOfPerModuleInitializer(D)) {
Richard Smithcd4a7a42017-09-07 00:55:55 +00002810 auto *M = D->getImportedOwningModule();
2811 if (M && M->Kind == Module::ModuleMapModule &&
2812 Ctx.DeclMustBeEmitted(D))
2813 return false;
2814 }
Richard Smithdc1f0422016-07-20 19:10:16 +00002815
Fangrui Song6907ce22018-07-30 19:24:48 +00002816 if (isa<FileScopeAsmDecl>(D) ||
2817 isa<ObjCProtocolDecl>(D) ||
Ben Langmuir332aafe2014-01-31 01:06:56 +00002818 isa<ObjCImplDecl>(D) ||
Alexey Bataev97720002014-11-11 04:05:39 +00002819 isa<ImportDecl>(D) ||
Nico Weber66220292016-03-02 17:28:48 +00002820 isa<PragmaCommentDecl>(D) ||
Alexey Bataevc5b1d322016-03-04 09:22:22 +00002821 isa<PragmaDetectMismatchDecl>(D))
Daniel Dunbar865c2a72009-09-17 03:06:44 +00002822 return true;
Michael Kruse251e1482019-02-01 20:25:04 +00002823 if (isa<OMPThreadPrivateDecl>(D) || isa<OMPDeclareReductionDecl>(D) ||
Alexey Bataev25ed0c02019-03-07 17:54:44 +00002824 isa<OMPDeclareMapperDecl>(D) || isa<OMPAllocateDecl>(D))
Alexey Bataevc5b1d322016-03-04 09:22:22 +00002825 return !D->getDeclContext()->isFunctionOrMethod();
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00002826 if (const auto *Var = dyn_cast<VarDecl>(D))
Argyrios Kyrtzidis4ba81b22010-08-05 09:47:59 +00002827 return Var->isFileVarDecl() &&
Alexey Bataevd01b7492018-08-15 19:45:12 +00002828 (Var->isThisDeclarationADefinition() == VarDecl::Definition ||
2829 OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(Var));
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00002830 if (const auto *Func = dyn_cast<FunctionDecl>(D))
Daniel Jasper4a6d5b72017-10-11 07:47:54 +00002831 return Func->doesThisDeclarationHaveABody() || HasBody;
David Blaikie1ac9c982017-04-11 21:13:37 +00002832
2833 if (auto *ES = D->getASTContext().getExternalSource())
2834 if (ES->hasExternalDefinitions(D) == ExternalASTSource::EK_Never)
2835 return true;
2836
Douglas Gregor87d81242011-09-10 00:22:34 +00002837 return false;
Chris Lattner487412d2009-04-27 05:27:42 +00002838}
2839
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002840/// Get the correct cursor and offset for loading a declaration.
Sebastian Redl2c499f62010-08-18 23:56:43 +00002841ASTReader::RecordLocation
Richard Smithcb34bd32016-03-27 07:28:06 +00002842ASTReader::DeclCursorForID(DeclID ID, SourceLocation &Loc) {
Douglas Gregor047d2ef2011-07-20 00:27:43 +00002843 GlobalDeclMapType::iterator I = GlobalDeclMap.find(ID);
2844 assert(I != GlobalDeclMap.end() && "Corrupted global declaration map");
Douglas Gregorde3ef502011-11-30 23:21:26 +00002845 ModuleFile *M = I->second;
Richard Smith34da7512016-03-27 05:52:25 +00002846 const DeclOffset &DOffs =
2847 M->DeclOffsets[ID - M->BaseDeclID - NUM_PREDEF_DECL_IDS];
Richard Smithcb34bd32016-03-27 07:28:06 +00002848 Loc = TranslateSourceLocation(*M, DOffs.getLocation());
Argyrios Kyrtzidis81ddd182011-10-27 18:47:35 +00002849 return RecordLocation(M, DOffs.BitOffset);
Sebastian Redl34627792010-07-20 22:46:15 +00002850}
2851
Douglas Gregord32f0352011-07-22 06:10:01 +00002852ASTReader::RecordLocation ASTReader::getLocalBitOffset(uint64_t GlobalOffset) {
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00002853 auto I = GlobalBitOffsetsMap.find(GlobalOffset);
Douglas Gregord32f0352011-07-22 06:10:01 +00002854
2855 assert(I != GlobalBitOffsetsMap.end() && "Corrupted global bit offsets map");
2856 return RecordLocation(I->second, GlobalOffset - I->second->GlobalBitOffset);
2857}
2858
Douglas Gregorde3ef502011-11-30 23:21:26 +00002859uint64_t ASTReader::getGlobalBitOffset(ModuleFile &M, uint32_t LocalOffset) {
Douglas Gregorc27b2872011-08-04 00:01:48 +00002860 return LocalOffset + M.GlobalBitOffset;
2861}
2862
Richard Smithbf78e642013-06-24 22:51:00 +00002863static bool isSameTemplateParameterList(const TemplateParameterList *X,
2864 const TemplateParameterList *Y);
2865
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002866/// Determine whether two template parameters are similar enough
Richard Smithbf78e642013-06-24 22:51:00 +00002867/// that they may be used in declarations of the same template.
2868static bool isSameTemplateParameter(const NamedDecl *X,
2869 const NamedDecl *Y) {
2870 if (X->getKind() != Y->getKind())
2871 return false;
2872
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00002873 if (const auto *TX = dyn_cast<TemplateTypeParmDecl>(X)) {
2874 const auto *TY = cast<TemplateTypeParmDecl>(Y);
Richard Smithbf78e642013-06-24 22:51:00 +00002875 return TX->isParameterPack() == TY->isParameterPack();
2876 }
2877
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00002878 if (const auto *TX = dyn_cast<NonTypeTemplateParmDecl>(X)) {
2879 const auto *TY = cast<NonTypeTemplateParmDecl>(Y);
Richard Smithbf78e642013-06-24 22:51:00 +00002880 return TX->isParameterPack() == TY->isParameterPack() &&
2881 TX->getASTContext().hasSameType(TX->getType(), TY->getType());
2882 }
2883
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00002884 const auto *TX = cast<TemplateTemplateParmDecl>(X);
2885 const auto *TY = cast<TemplateTemplateParmDecl>(Y);
Richard Smithbf78e642013-06-24 22:51:00 +00002886 return TX->isParameterPack() == TY->isParameterPack() &&
2887 isSameTemplateParameterList(TX->getTemplateParameters(),
2888 TY->getTemplateParameters());
2889}
2890
Richard Smith32952e12014-10-14 02:00:47 +00002891static NamespaceDecl *getNamespace(const NestedNameSpecifier *X) {
2892 if (auto *NS = X->getAsNamespace())
2893 return NS;
2894 if (auto *NAS = X->getAsNamespaceAlias())
2895 return NAS->getNamespace();
2896 return nullptr;
2897}
2898
2899static bool isSameQualifier(const NestedNameSpecifier *X,
2900 const NestedNameSpecifier *Y) {
2901 if (auto *NSX = getNamespace(X)) {
2902 auto *NSY = getNamespace(Y);
2903 if (!NSY || NSX->getCanonicalDecl() != NSY->getCanonicalDecl())
2904 return false;
2905 } else if (X->getKind() != Y->getKind())
2906 return false;
2907
2908 // FIXME: For namespaces and types, we're permitted to check that the entity
2909 // is named via the same tokens. We should probably do so.
2910 switch (X->getKind()) {
2911 case NestedNameSpecifier::Identifier:
2912 if (X->getAsIdentifier() != Y->getAsIdentifier())
2913 return false;
2914 break;
2915 case NestedNameSpecifier::Namespace:
2916 case NestedNameSpecifier::NamespaceAlias:
2917 // We've already checked that we named the same namespace.
2918 break;
2919 case NestedNameSpecifier::TypeSpec:
2920 case NestedNameSpecifier::TypeSpecWithTemplate:
2921 if (X->getAsType()->getCanonicalTypeInternal() !=
2922 Y->getAsType()->getCanonicalTypeInternal())
2923 return false;
2924 break;
2925 case NestedNameSpecifier::Global:
2926 case NestedNameSpecifier::Super:
2927 return true;
2928 }
2929
2930 // Recurse into earlier portion of NNS, if any.
2931 auto *PX = X->getPrefix();
2932 auto *PY = Y->getPrefix();
2933 if (PX && PY)
2934 return isSameQualifier(PX, PY);
2935 return !PX && !PY;
2936}
2937
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002938/// Determine whether two template parameter lists are similar enough
Richard Smithbf78e642013-06-24 22:51:00 +00002939/// that they may be used in declarations of the same template.
2940static bool isSameTemplateParameterList(const TemplateParameterList *X,
2941 const TemplateParameterList *Y) {
2942 if (X->size() != Y->size())
2943 return false;
2944
2945 for (unsigned I = 0, N = X->size(); I != N; ++I)
2946 if (!isSameTemplateParameter(X->getParam(I), Y->getParam(I)))
2947 return false;
2948
2949 return true;
2950}
2951
George Burgess IV95845082017-02-15 22:43:27 +00002952/// Determine whether the attributes we can overload on are identical for A and
George Burgess IVb7760212017-02-24 02:49:47 +00002953/// B. Will ignore any overloadable attrs represented in the type of A and B.
George Burgess IV95845082017-02-15 22:43:27 +00002954static bool hasSameOverloadableAttrs(const FunctionDecl *A,
2955 const FunctionDecl *B) {
George Burgess IVb7760212017-02-24 02:49:47 +00002956 // Note that pass_object_size attributes are represented in the function's
2957 // ExtParameterInfo, so we don't need to check them here.
2958
George Burgess IV95845082017-02-15 22:43:27 +00002959 llvm::FoldingSetNodeID Cand1ID, Cand2ID;
Michael Krusedc5ce722018-08-03 01:21:16 +00002960 auto AEnableIfAttrs = A->specific_attrs<EnableIfAttr>();
2961 auto BEnableIfAttrs = B->specific_attrs<EnableIfAttr>();
Michael Kruse157a3552018-12-10 15:16:37 +00002962
2963 for (auto Pair : zip_longest(AEnableIfAttrs, BEnableIfAttrs)) {
2964 Optional<EnableIfAttr *> Cand1A = std::get<0>(Pair);
2965 Optional<EnableIfAttr *> Cand2A = std::get<1>(Pair);
2966
2967 // Return false if the number of enable_if attributes is different.
2968 if (!Cand1A || !Cand2A)
2969 return false;
2970
George Burgess IV95845082017-02-15 22:43:27 +00002971 Cand1ID.clear();
2972 Cand2ID.clear();
2973
Michael Kruse157a3552018-12-10 15:16:37 +00002974 (*Cand1A)->getCond()->Profile(Cand1ID, A->getASTContext(), true);
2975 (*Cand2A)->getCond()->Profile(Cand2ID, B->getASTContext(), true);
2976
2977 // Return false if any of the enable_if expressions of A and B are
2978 // different.
George Burgess IV95845082017-02-15 22:43:27 +00002979 if (Cand1ID != Cand2ID)
2980 return false;
2981 }
Michael Kruse157a3552018-12-10 15:16:37 +00002982 return true;
George Burgess IV95845082017-02-15 22:43:27 +00002983}
2984
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00002985/// Determine whether the two declarations refer to the same entity.
Douglas Gregor022857e2011-12-22 01:48:48 +00002986static bool isSameEntity(NamedDecl *X, NamedDecl *Y) {
2987 assert(X->getDeclName() == Y->getDeclName() && "Declaration name mismatch!");
Richard Smithf4634362014-09-03 23:11:22 +00002988
Douglas Gregor022857e2011-12-22 01:48:48 +00002989 if (X == Y)
2990 return true;
Richard Smithf4634362014-09-03 23:11:22 +00002991
Douglas Gregor022857e2011-12-22 01:48:48 +00002992 // Must be in the same context.
Richard Smith600adef2018-07-04 02:25:38 +00002993 //
2994 // Note that we can't use DeclContext::Equals here, because the DeclContexts
2995 // could be two different declarations of the same function. (We will fix the
2996 // semantic DC to refer to the primary definition after merging.)
2997 if (!declaresSameEntity(cast<Decl>(X->getDeclContext()->getRedeclContext()),
2998 cast<Decl>(Y->getDeclContext()->getRedeclContext())))
Douglas Gregor022857e2011-12-22 01:48:48 +00002999 return false;
Douglas Gregor9b7b3912012-01-04 16:44:10 +00003000
3001 // Two typedefs refer to the same entity if they have the same underlying
3002 // type.
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00003003 if (const auto *TypedefX = dyn_cast<TypedefNameDecl>(X))
3004 if (const auto *TypedefY = dyn_cast<TypedefNameDecl>(Y))
Douglas Gregor9b7b3912012-01-04 16:44:10 +00003005 return X->getASTContext().hasSameType(TypedefX->getUnderlyingType(),
3006 TypedefY->getUnderlyingType());
Richard Smithf4634362014-09-03 23:11:22 +00003007
Douglas Gregor9b7b3912012-01-04 16:44:10 +00003008 // Must have the same kind.
3009 if (X->getKind() != Y->getKind())
3010 return false;
Richard Smithf4634362014-09-03 23:11:22 +00003011
Douglas Gregorda389302012-01-01 21:47:52 +00003012 // Objective-C classes and protocols with the same name always match.
3013 if (isa<ObjCInterfaceDecl>(X) || isa<ObjCProtocolDecl>(X))
Douglas Gregor022857e2011-12-22 01:48:48 +00003014 return true;
Richard Smith1d209d02013-05-23 01:49:11 +00003015
3016 if (isa<ClassTemplateSpecializationDecl>(X)) {
Richard Smithd55889a2013-09-09 16:55:27 +00003017 // No need to handle these here: we merge them when adding them to the
3018 // template.
Richard Smith1d209d02013-05-23 01:49:11 +00003019 return false;
3020 }
Richard Smithd55889a2013-09-09 16:55:27 +00003021
Douglas Gregor2009cee2012-01-03 22:46:00 +00003022 // Compatible tags match.
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00003023 if (const auto *TagX = dyn_cast<TagDecl>(X)) {
3024 const auto *TagY = cast<TagDecl>(Y);
Joao Matose9a3ed42012-08-31 22:18:20 +00003025 return (TagX->getTagKind() == TagY->getTagKind()) ||
3026 ((TagX->getTagKind() == TTK_Struct || TagX->getTagKind() == TTK_Class ||
3027 TagX->getTagKind() == TTK_Interface) &&
3028 (TagY->getTagKind() == TTK_Struct || TagY->getTagKind() == TTK_Class ||
3029 TagY->getTagKind() == TTK_Interface));
3030 }
Richard Smith8f8f05c2013-06-24 04:45:28 +00003031
Joao Matose9a3ed42012-08-31 22:18:20 +00003032 // Functions with the same type and linkage match.
Richard Smithf4634362014-09-03 23:11:22 +00003033 // FIXME: This needs to cope with merging of prototyped/non-prototyped
3034 // functions, etc.
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00003035 if (const auto *FuncX = dyn_cast<FunctionDecl>(X)) {
3036 const auto *FuncY = cast<FunctionDecl>(Y);
3037 if (const auto *CtorX = dyn_cast<CXXConstructorDecl>(X)) {
3038 const auto *CtorY = cast<CXXConstructorDecl>(Y);
Richard Smith5179eb72016-06-28 19:03:57 +00003039 if (CtorX->getInheritedConstructor() &&
3040 !isSameEntity(CtorX->getInheritedConstructor().getConstructor(),
3041 CtorY->getInheritedConstructor().getConstructor()))
3042 return false;
3043 }
Erich Keane281d20b2018-01-08 21:34:17 +00003044
3045 if (FuncX->isMultiVersion() != FuncY->isMultiVersion())
3046 return false;
3047
3048 // Multiversioned functions with different feature strings are represented
3049 // as separate declarations.
3050 if (FuncX->isMultiVersion()) {
3051 const auto *TAX = FuncX->getAttr<TargetAttr>();
3052 const auto *TAY = FuncY->getAttr<TargetAttr>();
3053 assert(TAX && TAY && "Multiversion Function without target attribute");
3054
3055 if (TAX->getFeaturesStr() != TAY->getFeaturesStr())
3056 return false;
3057 }
3058
Richard Smitha54d3242017-03-08 23:00:26 +00003059 ASTContext &C = FuncX->getASTContext();
Richard Smith600adef2018-07-04 02:25:38 +00003060 auto GetTypeAsWritten = [](const FunctionDecl *FD) {
3061 // Map to the first declaration that we've already merged into this one.
3062 // The TSI of redeclarations might not match (due to calling conventions
3063 // being inherited onto the type but not the TSI), but the TSI type of
3064 // the first declaration of the function should match across modules.
3065 FD = FD->getCanonicalDecl();
3066 return FD->getTypeSourceInfo() ? FD->getTypeSourceInfo()->getType()
3067 : FD->getType();
3068 };
3069 QualType XT = GetTypeAsWritten(FuncX), YT = GetTypeAsWritten(FuncY);
3070 if (!C.hasSameType(XT, YT)) {
Richard Smitha54d3242017-03-08 23:00:26 +00003071 // We can get functions with different types on the redecl chain in C++17
3072 // if they have differing exception specifications and at least one of
3073 // the excpetion specs is unresolved.
Richard Smith600adef2018-07-04 02:25:38 +00003074 auto *XFPT = XT->getAs<FunctionProtoType>();
3075 auto *YFPT = YT->getAs<FunctionProtoType>();
Aaron Ballmanc351fba2017-12-04 20:27:34 +00003076 if (C.getLangOpts().CPlusPlus17 && XFPT && YFPT &&
Richard Smitha54d3242017-03-08 23:00:26 +00003077 (isUnresolvedExceptionSpec(XFPT->getExceptionSpecType()) ||
3078 isUnresolvedExceptionSpec(YFPT->getExceptionSpecType())) &&
Richard Smith600adef2018-07-04 02:25:38 +00003079 C.hasSameFunctionTypeIgnoringExceptionSpec(XT, YT))
Richard Smitha54d3242017-03-08 23:00:26 +00003080 return true;
3081 return false;
3082 }
George Burgess IV95845082017-02-15 22:43:27 +00003083 return FuncX->getLinkageInternal() == FuncY->getLinkageInternal() &&
George Burgess IV95845082017-02-15 22:43:27 +00003084 hasSameOverloadableAttrs(FuncX, FuncY);
Douglas Gregorb2585692012-01-04 17:13:46 +00003085 }
Axel Naumann866ba3e2012-10-01 09:18:00 +00003086
Douglas Gregorb8c6f1e2012-01-04 17:21:36 +00003087 // Variables with the same type and linkage match.
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00003088 if (const auto *VarX = dyn_cast<VarDecl>(X)) {
3089 const auto *VarY = cast<VarDecl>(Y);
Yaron Kerene94da642016-01-22 19:03:27 +00003090 if (VarX->getLinkageInternal() == VarY->getLinkageInternal()) {
3091 ASTContext &C = VarX->getASTContext();
3092 if (C.hasSameType(VarX->getType(), VarY->getType()))
3093 return true;
3094
3095 // We can get decls with different types on the redecl chain. Eg.
3096 // template <typename T> struct S { static T Var[]; }; // #1
3097 // template <typename T> T S<T>::Var[sizeof(T)]; // #2
3098 // Only? happens when completing an incomplete array type. In this case
Vassil Vassilev4d75e8d2016-02-28 19:08:24 +00003099 // when comparing #1 and #2 we should go through their element type.
Yaron Kerene94da642016-01-22 19:03:27 +00003100 const ArrayType *VarXTy = C.getAsArrayType(VarX->getType());
3101 const ArrayType *VarYTy = C.getAsArrayType(VarY->getType());
3102 if (!VarXTy || !VarYTy)
3103 return false;
3104 if (VarXTy->isIncompleteArrayType() || VarYTy->isIncompleteArrayType())
3105 return C.hasSameType(VarXTy->getElementType(), VarYTy->getElementType());
3106 }
3107 return false;
Douglas Gregorb8c6f1e2012-01-04 17:21:36 +00003108 }
Richard Smith8f8f05c2013-06-24 04:45:28 +00003109
Douglas Gregorcfe7dc62012-01-09 17:30:44 +00003110 // Namespaces with the same name and inlinedness match.
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00003111 if (const auto *NamespaceX = dyn_cast<NamespaceDecl>(X)) {
3112 const auto *NamespaceY = cast<NamespaceDecl>(Y);
Douglas Gregorcfe7dc62012-01-09 17:30:44 +00003113 return NamespaceX->isInline() == NamespaceY->isInline();
3114 }
Axel Naumann866ba3e2012-10-01 09:18:00 +00003115
Richard Smith8f8f05c2013-06-24 04:45:28 +00003116 // Identical template names and kinds match if their template parameter lists
3117 // and patterns match.
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00003118 if (const auto *TemplateX = dyn_cast<TemplateDecl>(X)) {
3119 const auto *TemplateY = cast<TemplateDecl>(Y);
Richard Smith8f8f05c2013-06-24 04:45:28 +00003120 return isSameEntity(TemplateX->getTemplatedDecl(),
Richard Smithbf78e642013-06-24 22:51:00 +00003121 TemplateY->getTemplatedDecl()) &&
3122 isSameTemplateParameterList(TemplateX->getTemplateParameters(),
3123 TemplateY->getTemplateParameters());
Richard Smith8f8f05c2013-06-24 04:45:28 +00003124 }
Axel Naumann866ba3e2012-10-01 09:18:00 +00003125
Richard Smith0b87e072013-10-07 08:02:11 +00003126 // Fields with the same name and the same type match.
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00003127 if (const auto *FDX = dyn_cast<FieldDecl>(X)) {
3128 const auto *FDY = cast<FieldDecl>(Y);
Richard Smith01a73372013-10-15 22:02:41 +00003129 // FIXME: Also check the bitwidth is odr-equivalent, if any.
Richard Smith0b87e072013-10-07 08:02:11 +00003130 return X->getASTContext().hasSameType(FDX->getType(), FDY->getType());
3131 }
3132
Richard Smith8cbd8952015-08-04 02:05:09 +00003133 // Indirect fields with the same target field match.
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00003134 if (const auto *IFDX = dyn_cast<IndirectFieldDecl>(X)) {
3135 const auto *IFDY = cast<IndirectFieldDecl>(Y);
Richard Smith8cbd8952015-08-04 02:05:09 +00003136 return IFDX->getAnonField()->getCanonicalDecl() ==
3137 IFDY->getAnonField()->getCanonicalDecl();
3138 }
3139
Richard Smith01a73372013-10-15 22:02:41 +00003140 // Enumerators with the same name match.
3141 if (isa<EnumConstantDecl>(X))
3142 // FIXME: Also check the value is odr-equivalent.
3143 return true;
3144
Richard Smithfd8634a2013-10-23 02:17:46 +00003145 // Using shadow declarations with the same target match.
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00003146 if (const auto *USX = dyn_cast<UsingShadowDecl>(X)) {
3147 const auto *USY = cast<UsingShadowDecl>(Y);
Richard Smithfd8634a2013-10-23 02:17:46 +00003148 return USX->getTargetDecl() == USY->getTargetDecl();
3149 }
3150
Richard Smith32952e12014-10-14 02:00:47 +00003151 // Using declarations with the same qualifier match. (We already know that
3152 // the name matches.)
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00003153 if (const auto *UX = dyn_cast<UsingDecl>(X)) {
3154 const auto *UY = cast<UsingDecl>(Y);
Richard Smith32952e12014-10-14 02:00:47 +00003155 return isSameQualifier(UX->getQualifier(), UY->getQualifier()) &&
3156 UX->hasTypename() == UY->hasTypename() &&
3157 UX->isAccessDeclaration() == UY->isAccessDeclaration();
3158 }
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00003159 if (const auto *UX = dyn_cast<UnresolvedUsingValueDecl>(X)) {
3160 const auto *UY = cast<UnresolvedUsingValueDecl>(Y);
Richard Smith32952e12014-10-14 02:00:47 +00003161 return isSameQualifier(UX->getQualifier(), UY->getQualifier()) &&
3162 UX->isAccessDeclaration() == UY->isAccessDeclaration();
3163 }
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00003164 if (const auto *UX = dyn_cast<UnresolvedUsingTypenameDecl>(X))
Richard Smith32952e12014-10-14 02:00:47 +00003165 return isSameQualifier(
3166 UX->getQualifier(),
3167 cast<UnresolvedUsingTypenameDecl>(Y)->getQualifier());
3168
Richard Smithf4634362014-09-03 23:11:22 +00003169 // Namespace alias definitions with the same target match.
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00003170 if (const auto *NAX = dyn_cast<NamespaceAliasDecl>(X)) {
3171 const auto *NAY = cast<NamespaceAliasDecl>(Y);
Richard Smithf4634362014-09-03 23:11:22 +00003172 return NAX->getNamespace()->Equals(NAY->getNamespace());
3173 }
3174
Douglas Gregor022857e2011-12-22 01:48:48 +00003175 return false;
3176}
3177
Richard Smithd55889a2013-09-09 16:55:27 +00003178/// Find the context in which we should search for previous declarations when
3179/// looking for declarations to merge.
Richard Smith8a639892015-01-24 01:07:20 +00003180DeclContext *ASTDeclReader::getPrimaryContextForMerging(ASTReader &Reader,
3181 DeclContext *DC) {
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00003182 if (auto *ND = dyn_cast<NamespaceDecl>(DC))
Richard Smithd55889a2013-09-09 16:55:27 +00003183 return ND->getOriginalNamespace();
3184
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00003185 if (auto *RD = dyn_cast<CXXRecordDecl>(DC)) {
Richard Smith8a639892015-01-24 01:07:20 +00003186 // Try to dig out the definition.
Richard Smithb6483992016-05-17 22:44:15 +00003187 auto *DD = RD->DefinitionData;
Richard Smith8a639892015-01-24 01:07:20 +00003188 if (!DD)
Richard Smithb6483992016-05-17 22:44:15 +00003189 DD = RD->getCanonicalDecl()->DefinitionData;
Richard Smith8a639892015-01-24 01:07:20 +00003190
3191 // If there's no definition yet, then DC's definition is added by an update
3192 // record, but we've not yet loaded that update record. In this case, we
3193 // commit to DC being the canonical definition now, and will fix this when
3194 // we load the update record.
3195 if (!DD) {
Richard Smithdbafb6c2017-06-29 23:23:46 +00003196 DD = new (Reader.getContext()) struct CXXRecordDecl::DefinitionData(RD);
Erich Keanef92f31c2018-08-01 20:48:16 +00003197 RD->setCompleteDefinition(true);
Richard Smith8a639892015-01-24 01:07:20 +00003198 RD->DefinitionData = DD;
3199 RD->getCanonicalDecl()->DefinitionData = DD;
3200
3201 // Track that we did this horrible thing so that we can fix it later.
Richard Smith2a9e5c52015-02-03 03:32:14 +00003202 Reader.PendingFakeDefinitionData.insert(
3203 std::make_pair(DD, ASTReader::PendingFakeDefinitionKind::Fake));
Richard Smith8a639892015-01-24 01:07:20 +00003204 }
3205
3206 return DD->Definition;
3207 }
Richard Smithd55889a2013-09-09 16:55:27 +00003208
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00003209 if (auto *ED = dyn_cast<EnumDecl>(DC))
Craig Toppera13603a2014-05-22 05:54:18 +00003210 return ED->getASTContext().getLangOpts().CPlusPlus? ED->getDefinition()
3211 : nullptr;
Richard Smith01a73372013-10-15 22:02:41 +00003212
Richard Smith4eca9b92015-02-04 23:37:59 +00003213 // We can see the TU here only if we have no Sema object. In that case,
3214 // there's no TU scope to look in, so using the DC alone is sufficient.
3215 if (auto *TU = dyn_cast<TranslationUnitDecl>(DC))
3216 return TU;
3217
Craig Toppera13603a2014-05-22 05:54:18 +00003218 return nullptr;
Richard Smithd55889a2013-09-09 16:55:27 +00003219}
3220
Douglas Gregor022857e2011-12-22 01:48:48 +00003221ASTDeclReader::FindExistingResult::~FindExistingResult() {
Richard Smithf1f4bc22015-01-22 02:21:23 +00003222 // Record that we had a typedef name for linkage whether or not we merge
3223 // with that declaration.
3224 if (TypedefNameForLinkage) {
3225 DeclContext *DC = New->getDeclContext()->getRedeclContext();
3226 Reader.ImportedTypedefNamesForLinkage.insert(
3227 std::make_pair(std::make_pair(DC, TypedefNameForLinkage), New));
3228 return;
3229 }
3230
Douglas Gregor9b47f942012-01-09 17:38:47 +00003231 if (!AddResult || Existing)
Douglas Gregor022857e2011-12-22 01:48:48 +00003232 return;
Richard Smith95d99302013-07-13 02:00:19 +00003233
Richard Smith70d58502014-08-30 00:04:23 +00003234 DeclarationName Name = New->getDeclName();
Richard Smith95d99302013-07-13 02:00:19 +00003235 DeclContext *DC = New->getDeclContext()->getRedeclContext();
Richard Smith2b560572015-02-07 03:11:11 +00003236 if (needsAnonymousDeclarationNumber(New)) {
Richard Smithd08aeb62014-08-28 01:33:39 +00003237 setAnonymousDeclForMerging(Reader, New->getLexicalDeclContext(),
3238 AnonymousDeclNumber, New);
Richard Smith10379092016-05-06 23:14:07 +00003239 } else if (DC->isTranslationUnit() &&
Richard Smith9e2341d2015-03-23 03:25:59 +00003240 !Reader.getContext().getLangOpts().CPlusPlus) {
Richard Smith10379092016-05-06 23:14:07 +00003241 if (Reader.getIdResolver().tryAddTopLevelDecl(New, Name))
Richard Smith9e2341d2015-03-23 03:25:59 +00003242 Reader.PendingFakeLookupResults[Name.getAsIdentifierInfo()]
3243 .push_back(New);
Richard Smith8a639892015-01-24 01:07:20 +00003244 } else if (DeclContext *MergeDC = getPrimaryContextForMerging(Reader, DC)) {
Richard Smith95d99302013-07-13 02:00:19 +00003245 // Add the declaration to its redeclaration context so later merging
3246 // lookups will find it.
Richard Smithd55889a2013-09-09 16:55:27 +00003247 MergeDC->makeDeclVisibleInContextImpl(New, /*Internal*/true);
Douglas Gregor022857e2011-12-22 01:48:48 +00003248 }
3249}
3250
Richard Smith88ebade2014-08-23 01:45:27 +00003251/// Find the declaration that should be merged into, given the declaration found
3252/// by name lookup. If we're merging an anonymous declaration within a typedef,
3253/// we need a matching typedef, and we merge with the type inside it.
3254static NamedDecl *getDeclForMerging(NamedDecl *Found,
3255 bool IsTypedefNameForLinkage) {
3256 if (!IsTypedefNameForLinkage)
3257 return Found;
3258
3259 // If we found a typedef declaration that gives a name to some other
3260 // declaration, then we want that inner declaration. Declarations from
3261 // AST files are handled via ImportedTypedefNamesForLinkage.
Richard Smitha5230222015-03-27 01:37:43 +00003262 if (Found->isFromASTFile())
Hans Wennborgdcfba332015-10-06 23:40:43 +00003263 return nullptr;
Richard Smitha5230222015-03-27 01:37:43 +00003264
3265 if (auto *TND = dyn_cast<TypedefNameDecl>(Found))
Richard Smith3fb1a852016-08-30 19:13:18 +00003266 return TND->getAnonDeclWithTypedefName(/*AnyRedecl*/true);
Richard Smith88ebade2014-08-23 01:45:27 +00003267
Hans Wennborgdcfba332015-10-06 23:40:43 +00003268 return nullptr;
Richard Smith88ebade2014-08-23 01:45:27 +00003269}
3270
Richard Smith600adef2018-07-04 02:25:38 +00003271/// Find the declaration to use to populate the anonymous declaration table
3272/// for the given lexical DeclContext. We only care about finding local
3273/// definitions of the context; we'll merge imported ones as we go.
3274DeclContext *
3275ASTDeclReader::getPrimaryDCForAnonymousDecl(DeclContext *LexicalDC) {
3276 // For classes, we track the definition as we merge.
3277 if (auto *RD = dyn_cast<CXXRecordDecl>(LexicalDC)) {
3278 auto *DD = RD->getCanonicalDecl()->DefinitionData;
3279 return DD ? DD->Definition : nullptr;
3280 }
3281
3282 // For anything else, walk its merged redeclarations looking for a definition.
3283 // Note that we can't just call getDefinition here because the redeclaration
3284 // chain isn't wired up.
3285 for (auto *D : merged_redecls(cast<Decl>(LexicalDC))) {
3286 if (auto *FD = dyn_cast<FunctionDecl>(D))
3287 if (FD->isThisDeclarationADefinition())
3288 return FD;
3289 if (auto *MD = dyn_cast<ObjCMethodDecl>(D))
3290 if (MD->isThisDeclarationADefinition())
3291 return MD;
3292 }
3293
3294 // No merged definition yet.
3295 return nullptr;
3296}
3297
Richard Smithd08aeb62014-08-28 01:33:39 +00003298NamedDecl *ASTDeclReader::getAnonymousDeclForMerging(ASTReader &Reader,
3299 DeclContext *DC,
3300 unsigned Index) {
3301 // If the lexical context has been merged, look into the now-canonical
3302 // definition.
Richard Smith600adef2018-07-04 02:25:38 +00003303 auto *CanonDC = cast<Decl>(DC)->getCanonicalDecl();
Richard Smithd08aeb62014-08-28 01:33:39 +00003304
3305 // If we've seen this before, return the canonical declaration.
Richard Smith600adef2018-07-04 02:25:38 +00003306 auto &Previous = Reader.AnonymousDeclarationsForMerging[CanonDC];
Richard Smithd08aeb62014-08-28 01:33:39 +00003307 if (Index < Previous.size() && Previous[Index])
3308 return Previous[Index];
3309
3310 // If this is the first time, but we have parsed a declaration of the context,
3311 // build the anonymous declaration list from the parsed declaration.
Richard Smith600adef2018-07-04 02:25:38 +00003312 auto *PrimaryDC = getPrimaryDCForAnonymousDecl(DC);
3313 if (PrimaryDC && !cast<Decl>(PrimaryDC)->isFromASTFile()) {
3314 numberAnonymousDeclsWithin(PrimaryDC, [&](NamedDecl *ND, unsigned Number) {
Richard Smith2b560572015-02-07 03:11:11 +00003315 if (Previous.size() == Number)
Richard Smithd08aeb62014-08-28 01:33:39 +00003316 Previous.push_back(cast<NamedDecl>(ND->getCanonicalDecl()));
3317 else
Richard Smith2b560572015-02-07 03:11:11 +00003318 Previous[Number] = cast<NamedDecl>(ND->getCanonicalDecl());
3319 });
Richard Smithd08aeb62014-08-28 01:33:39 +00003320 }
3321
3322 return Index < Previous.size() ? Previous[Index] : nullptr;
3323}
3324
3325void ASTDeclReader::setAnonymousDeclForMerging(ASTReader &Reader,
3326 DeclContext *DC, unsigned Index,
3327 NamedDecl *D) {
Richard Smith600adef2018-07-04 02:25:38 +00003328 auto *CanonDC = cast<Decl>(DC)->getCanonicalDecl();
Richard Smithd08aeb62014-08-28 01:33:39 +00003329
Richard Smith600adef2018-07-04 02:25:38 +00003330 auto &Previous = Reader.AnonymousDeclarationsForMerging[CanonDC];
Richard Smithd08aeb62014-08-28 01:33:39 +00003331 if (Index >= Previous.size())
3332 Previous.resize(Index + 1);
3333 if (!Previous[Index])
3334 Previous[Index] = D;
3335}
3336
Douglas Gregor022857e2011-12-22 01:48:48 +00003337ASTDeclReader::FindExistingResult ASTDeclReader::findExisting(NamedDecl *D) {
Richard Smith70d58502014-08-30 00:04:23 +00003338 DeclarationName Name = TypedefNameForLinkage ? TypedefNameForLinkage
3339 : D->getDeclName();
Richard Smith88ebade2014-08-23 01:45:27 +00003340
Richard Smithd08aeb62014-08-28 01:33:39 +00003341 if (!Name && !needsAnonymousDeclarationNumber(D)) {
3342 // Don't bother trying to find unnamed declarations that are in
3343 // unmergeable contexts.
Richard Smith70d58502014-08-30 00:04:23 +00003344 FindExistingResult Result(Reader, D, /*Existing=*/nullptr,
3345 AnonymousDeclNumber, TypedefNameForLinkage);
Douglas Gregor2009cee2012-01-03 22:46:00 +00003346 Result.suppress();
3347 return Result;
3348 }
Richard Smith95d99302013-07-13 02:00:19 +00003349
Douglas Gregor022857e2011-12-22 01:48:48 +00003350 DeclContext *DC = D->getDeclContext()->getRedeclContext();
Richard Smith70d58502014-08-30 00:04:23 +00003351 if (TypedefNameForLinkage) {
Richard Smith88ebade2014-08-23 01:45:27 +00003352 auto It = Reader.ImportedTypedefNamesForLinkage.find(
Richard Smith70d58502014-08-30 00:04:23 +00003353 std::make_pair(DC, TypedefNameForLinkage));
Richard Smith88ebade2014-08-23 01:45:27 +00003354 if (It != Reader.ImportedTypedefNamesForLinkage.end())
3355 if (isSameEntity(It->second, D))
Richard Smith70d58502014-08-30 00:04:23 +00003356 return FindExistingResult(Reader, D, It->second, AnonymousDeclNumber,
3357 TypedefNameForLinkage);
Richard Smith88ebade2014-08-23 01:45:27 +00003358 // Go on to check in other places in case an existing typedef name
3359 // was not imported.
3360 }
Richard Smithd08aeb62014-08-28 01:33:39 +00003361
Richard Smith2b560572015-02-07 03:11:11 +00003362 if (needsAnonymousDeclarationNumber(D)) {
Richard Smithd08aeb62014-08-28 01:33:39 +00003363 // This is an anonymous declaration that we may need to merge. Look it up
3364 // in its context by number.
Richard Smithd08aeb62014-08-28 01:33:39 +00003365 if (auto *Existing = getAnonymousDeclForMerging(
3366 Reader, D->getLexicalDeclContext(), AnonymousDeclNumber))
3367 if (isSameEntity(Existing, D))
Richard Smith70d58502014-08-30 00:04:23 +00003368 return FindExistingResult(Reader, D, Existing, AnonymousDeclNumber,
3369 TypedefNameForLinkage);
Richard Smith10379092016-05-06 23:14:07 +00003370 } else if (DC->isTranslationUnit() &&
Richard Smith9e2341d2015-03-23 03:25:59 +00003371 !Reader.getContext().getLangOpts().CPlusPlus) {
Richard Smith10379092016-05-06 23:14:07 +00003372 IdentifierResolver &IdResolver = Reader.getIdResolver();
Douglas Gregor6168bd22013-02-18 15:53:43 +00003373
3374 // Temporarily consider the identifier to be up-to-date. We don't want to
3375 // cause additional lookups here.
3376 class UpToDateIdentifierRAII {
3377 IdentifierInfo *II;
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00003378 bool WasOutToDate = false;
Douglas Gregor6168bd22013-02-18 15:53:43 +00003379
3380 public:
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00003381 explicit UpToDateIdentifierRAII(IdentifierInfo *II) : II(II) {
Douglas Gregor6168bd22013-02-18 15:53:43 +00003382 if (II) {
3383 WasOutToDate = II->isOutOfDate();
3384 if (WasOutToDate)
3385 II->setOutOfDate(false);
3386 }
3387 }
3388
3389 ~UpToDateIdentifierRAII() {
3390 if (WasOutToDate)
3391 II->setOutOfDate(true);
3392 }
3393 } UpToDate(Name.getAsIdentifierInfo());
3394
Fangrui Song6907ce22018-07-30 19:24:48 +00003395 for (IdentifierResolver::iterator I = IdResolver.begin(Name),
Douglas Gregor022857e2011-12-22 01:48:48 +00003396 IEnd = IdResolver.end();
3397 I != IEnd; ++I) {
Richard Smith70d58502014-08-30 00:04:23 +00003398 if (NamedDecl *Existing = getDeclForMerging(*I, TypedefNameForLinkage))
Richard Smith87dacc72014-08-25 23:33:46 +00003399 if (isSameEntity(Existing, D))
Richard Smith70d58502014-08-30 00:04:23 +00003400 return FindExistingResult(Reader, D, Existing, AnonymousDeclNumber,
3401 TypedefNameForLinkage);
Douglas Gregor022857e2011-12-22 01:48:48 +00003402 }
Richard Smith8a639892015-01-24 01:07:20 +00003403 } else if (DeclContext *MergeDC = getPrimaryContextForMerging(Reader, DC)) {
Richard Smithd55889a2013-09-09 16:55:27 +00003404 DeclContext::lookup_result R = MergeDC->noload_lookup(Name);
Richard Smith95d99302013-07-13 02:00:19 +00003405 for (DeclContext::lookup_iterator I = R.begin(), E = R.end(); I != E; ++I) {
Richard Smith70d58502014-08-30 00:04:23 +00003406 if (NamedDecl *Existing = getDeclForMerging(*I, TypedefNameForLinkage))
Richard Smith88ebade2014-08-23 01:45:27 +00003407 if (isSameEntity(Existing, D))
Richard Smith70d58502014-08-30 00:04:23 +00003408 return FindExistingResult(Reader, D, Existing, AnonymousDeclNumber,
3409 TypedefNameForLinkage);
Douglas Gregor9b47f942012-01-09 17:38:47 +00003410 }
Richard Smith2b9e3e32013-10-18 06:05:18 +00003411 } else {
3412 // Not in a mergeable context.
3413 return FindExistingResult(Reader);
Douglas Gregor9b47f942012-01-09 17:38:47 +00003414 }
Richard Smithd55889a2013-09-09 16:55:27 +00003415
Richard Smith2b9e3e32013-10-18 06:05:18 +00003416 // If this declaration is from a merged context, make a note that we need to
3417 // check that the canonical definition of that context contains the decl.
Richard Smithcd45dbc2014-04-19 03:48:30 +00003418 //
3419 // FIXME: We should do something similar if we merge two definitions of the
3420 // same template specialization into the same CXXRecordDecl.
Richard Smith88126a22014-08-25 02:10:01 +00003421 auto MergedDCIt = Reader.MergedDeclContexts.find(D->getLexicalDeclContext());
3422 if (MergedDCIt != Reader.MergedDeclContexts.end() &&
3423 MergedDCIt->second == D->getDeclContext())
Richard Smith2b9e3e32013-10-18 06:05:18 +00003424 Reader.PendingOdrMergeChecks.push_back(D);
3425
Richard Smithd08aeb62014-08-28 01:33:39 +00003426 return FindExistingResult(Reader, D, /*Existing=*/nullptr,
Richard Smith70d58502014-08-30 00:04:23 +00003427 AnonymousDeclNumber, TypedefNameForLinkage);
Douglas Gregor022857e2011-12-22 01:48:48 +00003428}
3429
Richard Smithb321ecb2014-05-13 01:15:00 +00003430template<typename DeclT>
Richard Smithc3a53252015-02-28 05:57:02 +00003431Decl *ASTDeclReader::getMostRecentDeclImpl(Redeclarable<DeclT> *D) {
3432 return D->RedeclLink.getLatestNotUpdated();
3433}
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00003434
Richard Smithc3a53252015-02-28 05:57:02 +00003435Decl *ASTDeclReader::getMostRecentDeclImpl(...) {
3436 llvm_unreachable("getMostRecentDecl on non-redeclarable declaration");
3437}
3438
3439Decl *ASTDeclReader::getMostRecentDecl(Decl *D) {
3440 assert(D);
3441
3442 switch (D->getKind()) {
3443#define ABSTRACT_DECL(TYPE)
3444#define DECL(TYPE, BASE) \
3445 case Decl::TYPE: \
3446 return getMostRecentDeclImpl(cast<TYPE##Decl>(D));
3447#include "clang/AST/DeclNodes.inc"
3448 }
3449 llvm_unreachable("unknown decl kind");
3450}
3451
Richard Smith8ce51082015-03-11 01:44:51 +00003452Decl *ASTReader::getMostRecentExistingDecl(Decl *D) {
3453 return ASTDeclReader::getMostRecentDecl(D->getCanonicalDecl());
3454}
3455
Richard Smithc3a53252015-02-28 05:57:02 +00003456template<typename DeclT>
Richard Smith6de7a242014-07-31 23:46:44 +00003457void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader,
3458 Redeclarable<DeclT> *D,
Richard Smith9e2341d2015-03-23 03:25:59 +00003459 Decl *Previous, Decl *Canon) {
Richard Smith053f6c62014-05-16 23:01:30 +00003460 D->RedeclLink.setPrevious(cast<DeclT>(Previous));
Manuel Klimek093b2d42015-03-25 23:18:30 +00003461 D->First = cast<DeclT>(Previous)->First;
Richard Smithb321ecb2014-05-13 01:15:00 +00003462}
Hans Wennborgdcfba332015-10-06 23:40:43 +00003463
Richard Smith24d166c2014-07-31 23:52:38 +00003464namespace clang {
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00003465
Richard Smith6de7a242014-07-31 23:46:44 +00003466template<>
3467void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader,
Richard Smithedbc6e92016-10-14 21:41:24 +00003468 Redeclarable<VarDecl> *D,
3469 Decl *Previous, Decl *Canon) {
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00003470 auto *VD = static_cast<VarDecl *>(D);
3471 auto *PrevVD = cast<VarDecl>(Previous);
Richard Smithedbc6e92016-10-14 21:41:24 +00003472 D->RedeclLink.setPrevious(PrevVD);
3473 D->First = PrevVD->First;
3474
3475 // We should keep at most one definition on the chain.
3476 // FIXME: Cache the definition once we've found it. Building a chain with
3477 // N definitions currently takes O(N^2) time here.
3478 if (VD->isThisDeclarationADefinition() == VarDecl::Definition) {
3479 for (VarDecl *CurD = PrevVD; CurD; CurD = CurD->getPreviousDecl()) {
3480 if (CurD->isThisDeclarationADefinition() == VarDecl::Definition) {
3481 Reader.mergeDefinitionVisibility(CurD, VD);
3482 VD->demoteThisDefinitionToDeclaration();
3483 break;
3484 }
3485 }
3486 }
3487}
3488
Richard Smitha62d1982018-08-03 01:00:01 +00003489static bool isUndeducedReturnType(QualType T) {
3490 auto *DT = T->getContainedDeducedType();
3491 return DT && !DT->isDeduced();
3492}
3493
Richard Smithedbc6e92016-10-14 21:41:24 +00003494template<>
3495void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader,
Richard Smith6de7a242014-07-31 23:46:44 +00003496 Redeclarable<FunctionDecl> *D,
Richard Smith9e2341d2015-03-23 03:25:59 +00003497 Decl *Previous, Decl *Canon) {
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00003498 auto *FD = static_cast<FunctionDecl *>(D);
3499 auto *PrevFD = cast<FunctionDecl>(Previous);
Richard Smith6de7a242014-07-31 23:46:44 +00003500
3501 FD->RedeclLink.setPrevious(PrevFD);
Manuel Klimek093b2d42015-03-25 23:18:30 +00003502 FD->First = PrevFD->First;
Richard Smith6de7a242014-07-31 23:46:44 +00003503
3504 // If the previous declaration is an inline function declaration, then this
3505 // declaration is too.
Erich Keane9c665062018-08-01 21:02:40 +00003506 if (PrevFD->isInlined() != FD->isInlined()) {
Richard Smith6de7a242014-07-31 23:46:44 +00003507 // FIXME: [dcl.fct.spec]p4:
3508 // If a function with external linkage is declared inline in one
3509 // translation unit, it shall be declared inline in all translation
3510 // units in which it appears.
3511 //
3512 // Be careful of this case:
3513 //
3514 // module A:
3515 // template<typename T> struct X { void f(); };
3516 // template<typename T> inline void X<T>::f() {}
3517 //
3518 // module B instantiates the declaration of X<int>::f
3519 // module C instantiates the definition of X<int>::f
3520 //
3521 // If module B and C are merged, we do not have a violation of this rule.
Erich Keane9c665062018-08-01 21:02:40 +00003522 FD->setImplicitlyInline(true);
Richard Smith6de7a242014-07-31 23:46:44 +00003523 }
3524
Richard Smith6de7a242014-07-31 23:46:44 +00003525 auto *FPT = FD->getType()->getAs<FunctionProtoType>();
3526 auto *PrevFPT = PrevFD->getType()->getAs<FunctionProtoType>();
Richard Smith80969752015-03-10 02:00:53 +00003527 if (FPT && PrevFPT) {
Richard Smitha62d1982018-08-03 01:00:01 +00003528 // If we need to propagate an exception specification along the redecl
3529 // chain, make a note of that so that we can do so later.
Richard Smith9e2341d2015-03-23 03:25:59 +00003530 bool IsUnresolved = isUnresolvedExceptionSpec(FPT->getExceptionSpecType());
3531 bool WasUnresolved =
3532 isUnresolvedExceptionSpec(PrevFPT->getExceptionSpecType());
3533 if (IsUnresolved != WasUnresolved)
3534 Reader.PendingExceptionSpecUpdates.insert(
Richard Smitha62d1982018-08-03 01:00:01 +00003535 {Canon, IsUnresolved ? PrevFD : FD});
3536
3537 // If we need to propagate a deduced return type along the redecl chain,
3538 // make a note of that so that we can do it later.
3539 bool IsUndeduced = isUndeducedReturnType(FPT->getReturnType());
3540 bool WasUndeduced = isUndeducedReturnType(PrevFPT->getReturnType());
3541 if (IsUndeduced != WasUndeduced)
3542 Reader.PendingDeducedTypeUpdates.insert(
3543 {cast<FunctionDecl>(Canon),
3544 (IsUndeduced ? PrevFPT : FPT)->getReturnType()});
Richard Smith6de7a242014-07-31 23:46:44 +00003545 }
3546}
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00003547
3548} // namespace clang
Hans Wennborgdcfba332015-10-06 23:40:43 +00003549
Richard Smith6de7a242014-07-31 23:46:44 +00003550void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader, ...) {
Richard Smithb321ecb2014-05-13 01:15:00 +00003551 llvm_unreachable("attachPreviousDecl on non-redeclarable declaration");
3552}
3553
Richard Smith8346e522015-06-10 01:47:58 +00003554/// Inherit the default template argument from \p From to \p To. Returns
3555/// \c false if there is no default template for \p From.
3556template <typename ParmDecl>
3557static bool inheritDefaultTemplateArgument(ASTContext &Context, ParmDecl *From,
3558 Decl *ToD) {
3559 auto *To = cast<ParmDecl>(ToD);
3560 if (!From->hasDefaultArgument())
3561 return false;
Richard Smithe7bd6de2015-06-10 20:30:23 +00003562 To->setInheritedDefaultArgument(Context, From);
Richard Smith8346e522015-06-10 01:47:58 +00003563 return true;
3564}
3565
3566static void inheritDefaultTemplateArguments(ASTContext &Context,
3567 TemplateDecl *From,
3568 TemplateDecl *To) {
3569 auto *FromTP = From->getTemplateParameters();
3570 auto *ToTP = To->getTemplateParameters();
3571 assert(FromTP->size() == ToTP->size() && "merged mismatched templates?");
3572
3573 for (unsigned I = 0, N = FromTP->size(); I != N; ++I) {
Richard Smith559cc692018-07-31 21:01:53 +00003574 NamedDecl *FromParam = FromTP->getParam(I);
3575 NamedDecl *ToParam = ToTP->getParam(I);
Richard Smith8346e522015-06-10 01:47:58 +00003576
Richard Smith559cc692018-07-31 21:01:53 +00003577 if (auto *FTTP = dyn_cast<TemplateTypeParmDecl>(FromParam))
3578 inheritDefaultTemplateArgument(Context, FTTP, ToParam);
3579 else if (auto *FNTTP = dyn_cast<NonTypeTemplateParmDecl>(FromParam))
3580 inheritDefaultTemplateArgument(Context, FNTTP, ToParam);
3581 else
3582 inheritDefaultTemplateArgument(
3583 Context, cast<TemplateTemplateParmDecl>(FromParam), ToParam);
Richard Smith8346e522015-06-10 01:47:58 +00003584 }
3585}
3586
Richard Smith6de7a242014-07-31 23:46:44 +00003587void ASTDeclReader::attachPreviousDecl(ASTReader &Reader, Decl *D,
Richard Smith9e2341d2015-03-23 03:25:59 +00003588 Decl *Previous, Decl *Canon) {
Richard Smithb321ecb2014-05-13 01:15:00 +00003589 assert(D && Previous);
3590
3591 switch (D->getKind()) {
3592#define ABSTRACT_DECL(TYPE)
Richard Smith9e2341d2015-03-23 03:25:59 +00003593#define DECL(TYPE, BASE) \
3594 case Decl::TYPE: \
3595 attachPreviousDeclImpl(Reader, cast<TYPE##Decl>(D), Previous, Canon); \
Richard Smithb321ecb2014-05-13 01:15:00 +00003596 break;
3597#include "clang/AST/DeclNodes.inc"
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00003598 }
Richard Smith7ecc31b2013-08-02 01:09:12 +00003599
3600 // If the declaration was visible in one module, a redeclaration of it in
3601 // another module remains visible even if it wouldn't be visible by itself.
3602 //
3603 // FIXME: In this case, the declaration should only be visible if a module
3604 // that makes it visible has been imported.
Richard Smith7ecc31b2013-08-02 01:09:12 +00003605 D->IdentifierNamespace |=
Richard Smithb321ecb2014-05-13 01:15:00 +00003606 Previous->IdentifierNamespace &
Richard Smith7ecc31b2013-08-02 01:09:12 +00003607 (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type);
Richard Smith195d8ef2014-05-29 03:15:31 +00003608
Richard Smith8346e522015-06-10 01:47:58 +00003609 // If the declaration declares a template, it may inherit default arguments
3610 // from the previous declaration.
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00003611 if (auto *TD = dyn_cast<TemplateDecl>(D))
Richard Smith8346e522015-06-10 01:47:58 +00003612 inheritDefaultTemplateArguments(Reader.getContext(),
3613 cast<TemplateDecl>(Previous), TD);
Argyrios Kyrtzidis9fdd2542011-02-12 07:50:47 +00003614}
3615
Richard Smithb321ecb2014-05-13 01:15:00 +00003616template<typename DeclT>
3617void ASTDeclReader::attachLatestDeclImpl(Redeclarable<DeclT> *D, Decl *Latest) {
Richard Smith053f6c62014-05-16 23:01:30 +00003618 D->RedeclLink.setLatest(cast<DeclT>(Latest));
Richard Smithb321ecb2014-05-13 01:15:00 +00003619}
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00003620
Richard Smithb321ecb2014-05-13 01:15:00 +00003621void ASTDeclReader::attachLatestDeclImpl(...) {
3622 llvm_unreachable("attachLatestDecl on non-redeclarable declaration");
3623}
3624
Douglas Gregor05f10352011-12-17 23:38:30 +00003625void ASTDeclReader::attachLatestDecl(Decl *D, Decl *Latest) {
3626 assert(D && Latest);
Richard Smithb321ecb2014-05-13 01:15:00 +00003627
3628 switch (D->getKind()) {
3629#define ABSTRACT_DECL(TYPE)
Richard Smith053f6c62014-05-16 23:01:30 +00003630#define DECL(TYPE, BASE) \
3631 case Decl::TYPE: \
Richard Smithb321ecb2014-05-13 01:15:00 +00003632 attachLatestDeclImpl(cast<TYPE##Decl>(D), Latest); \
3633 break;
3634#include "clang/AST/DeclNodes.inc"
Douglas Gregor05f10352011-12-17 23:38:30 +00003635 }
3636}
3637
Richard Smith851072e2014-05-19 20:59:20 +00003638template<typename DeclT>
3639void ASTDeclReader::markIncompleteDeclChainImpl(Redeclarable<DeclT> *D) {
3640 D->RedeclLink.markIncomplete();
3641}
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00003642
Richard Smith851072e2014-05-19 20:59:20 +00003643void ASTDeclReader::markIncompleteDeclChainImpl(...) {
3644 llvm_unreachable("markIncompleteDeclChain on non-redeclarable declaration");
3645}
3646
3647void ASTReader::markIncompleteDeclChain(Decl *D) {
3648 switch (D->getKind()) {
3649#define ABSTRACT_DECL(TYPE)
3650#define DECL(TYPE, BASE) \
3651 case Decl::TYPE: \
3652 ASTDeclReader::markIncompleteDeclChainImpl(cast<TYPE##Decl>(D)); \
3653 break;
3654#include "clang/AST/DeclNodes.inc"
3655 }
3656}
3657
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00003658/// Read the declaration at the given offset from the AST file.
Douglas Gregorf7180622011-08-03 15:48:04 +00003659Decl *ASTReader::ReadDeclRecord(DeclID ID) {
Douglas Gregordab42432011-08-12 00:15:20 +00003660 unsigned Index = ID - NUM_PREDEF_DECL_IDS;
Richard Smithcb34bd32016-03-27 07:28:06 +00003661 SourceLocation DeclLoc;
3662 RecordLocation Loc = DeclCursorForID(ID, DeclLoc);
Sebastian Redl2c373b92010-10-05 15:59:54 +00003663 llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor;
Chris Lattner487412d2009-04-27 05:27:42 +00003664 // Keep track of where we are in the stream, then jump back there
3665 // after reading this declaration.
Chris Lattner1de76db2009-04-27 05:58:23 +00003666 SavedStreamPosition SavedPosition(DeclsCursor);
Chris Lattner487412d2009-04-27 05:27:42 +00003667
Argyrios Kyrtzidisd0795b22010-06-28 22:28:35 +00003668 ReadingKindTracker ReadingKind(Read_Decl, *this);
3669
Douglas Gregor1342e842009-07-06 18:54:52 +00003670 // Note that we are loading a declaration record.
Argyrios Kyrtzidisb24355a2010-07-30 10:03:16 +00003671 Deserializing ADecl(this);
Mike Stump11289f42009-09-09 15:08:12 +00003672
JF Bastien0e828952019-06-26 19:50:12 +00003673 auto Fail = [](const char *what, llvm::Error &&Err) {
3674 llvm::report_fatal_error(Twine("ASTReader::ReadDeclRecord failed ") + what +
3675 ": " + toString(std::move(Err)));
3676 };
3677
3678 if (llvm::Error JumpFailed = DeclsCursor.JumpToBit(Loc.Offset))
3679 Fail("jumping", std::move(JumpFailed));
David L. Jonesbe1557a2016-12-21 00:17:49 +00003680 ASTRecordReader Record(*this, *Loc.F);
3681 ASTDeclReader Reader(*this, Record, Loc, ID, DeclLoc);
JF Bastien0e828952019-06-26 19:50:12 +00003682 Expected<unsigned> MaybeCode = DeclsCursor.ReadCode();
3683 if (!MaybeCode)
3684 Fail("reading code", MaybeCode.takeError());
3685 unsigned Code = MaybeCode.get();
Chris Lattner487412d2009-04-27 05:27:42 +00003686
Richard Smithdbafb6c2017-06-29 23:23:46 +00003687 ASTContext &Context = getContext();
Craig Toppera13603a2014-05-22 05:54:18 +00003688 Decl *D = nullptr;
JF Bastien0e828952019-06-26 19:50:12 +00003689 Expected<unsigned> MaybeDeclCode = Record.readRecord(DeclsCursor, Code);
3690 if (!MaybeDeclCode)
3691 llvm::report_fatal_error(
3692 "ASTReader::ReadDeclRecord failed reading decl code: " +
3693 toString(MaybeDeclCode.takeError()));
3694 switch ((DeclCode)MaybeDeclCode.get()) {
Sebastian Redl539c5062010-08-18 23:57:32 +00003695 case DECL_CONTEXT_LEXICAL:
3696 case DECL_CONTEXT_VISIBLE:
David Blaikie83d382b2011-09-23 05:06:16 +00003697 llvm_unreachable("Record cannot be de-serialized with ReadDeclRecord");
Sebastian Redl539c5062010-08-18 23:57:32 +00003698 case DECL_TYPEDEF:
Douglas Gregor72172e92012-01-05 21:55:30 +00003699 D = TypedefDecl::CreateDeserialized(Context, ID);
Chris Lattner487412d2009-04-27 05:27:42 +00003700 break;
Richard Smithdda56e42011-04-15 14:24:37 +00003701 case DECL_TYPEALIAS:
Douglas Gregor72172e92012-01-05 21:55:30 +00003702 D = TypeAliasDecl::CreateDeserialized(Context, ID);
Richard Smithdda56e42011-04-15 14:24:37 +00003703 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003704 case DECL_ENUM:
Douglas Gregor72172e92012-01-05 21:55:30 +00003705 D = EnumDecl::CreateDeserialized(Context, ID);
Chris Lattner487412d2009-04-27 05:27:42 +00003706 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003707 case DECL_RECORD:
Douglas Gregor72172e92012-01-05 21:55:30 +00003708 D = RecordDecl::CreateDeserialized(Context, ID);
Chris Lattner487412d2009-04-27 05:27:42 +00003709 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003710 case DECL_ENUM_CONSTANT:
Douglas Gregor72172e92012-01-05 21:55:30 +00003711 D = EnumConstantDecl::CreateDeserialized(Context, ID);
Chris Lattner487412d2009-04-27 05:27:42 +00003712 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003713 case DECL_FUNCTION:
Douglas Gregor72172e92012-01-05 21:55:30 +00003714 D = FunctionDecl::CreateDeserialized(Context, ID);
Chris Lattner487412d2009-04-27 05:27:42 +00003715 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003716 case DECL_LINKAGE_SPEC:
Douglas Gregor72172e92012-01-05 21:55:30 +00003717 D = LinkageSpecDecl::CreateDeserialized(Context, ID);
Chris Lattnerca025db2010-05-07 21:43:38 +00003718 break;
Richard Smith8df390f2016-09-08 23:14:54 +00003719 case DECL_EXPORT:
3720 D = ExportDecl::CreateDeserialized(Context, ID);
3721 break;
Chris Lattnerc8e630e2011-02-17 07:39:24 +00003722 case DECL_LABEL:
Douglas Gregor72172e92012-01-05 21:55:30 +00003723 D = LabelDecl::CreateDeserialized(Context, ID);
Chris Lattnerc8e630e2011-02-17 07:39:24 +00003724 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003725 case DECL_NAMESPACE:
Douglas Gregor72172e92012-01-05 21:55:30 +00003726 D = NamespaceDecl::CreateDeserialized(Context, ID);
Chris Lattnerca025db2010-05-07 21:43:38 +00003727 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003728 case DECL_NAMESPACE_ALIAS:
Douglas Gregor72172e92012-01-05 21:55:30 +00003729 D = NamespaceAliasDecl::CreateDeserialized(Context, ID);
Chris Lattnerca025db2010-05-07 21:43:38 +00003730 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003731 case DECL_USING:
Douglas Gregor72172e92012-01-05 21:55:30 +00003732 D = UsingDecl::CreateDeserialized(Context, ID);
Chris Lattnerca025db2010-05-07 21:43:38 +00003733 break;
Richard Smith151c4562016-12-20 21:35:28 +00003734 case DECL_USING_PACK:
David L. Jonesbe1557a2016-12-21 00:17:49 +00003735 D = UsingPackDecl::CreateDeserialized(Context, ID, Record.readInt());
Richard Smith151c4562016-12-20 21:35:28 +00003736 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003737 case DECL_USING_SHADOW:
Douglas Gregor72172e92012-01-05 21:55:30 +00003738 D = UsingShadowDecl::CreateDeserialized(Context, ID);
Chris Lattnerca025db2010-05-07 21:43:38 +00003739 break;
Richard Smith5179eb72016-06-28 19:03:57 +00003740 case DECL_CONSTRUCTOR_USING_SHADOW:
3741 D = ConstructorUsingShadowDecl::CreateDeserialized(Context, ID);
3742 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003743 case DECL_USING_DIRECTIVE:
Douglas Gregor72172e92012-01-05 21:55:30 +00003744 D = UsingDirectiveDecl::CreateDeserialized(Context, ID);
Chris Lattnerca025db2010-05-07 21:43:38 +00003745 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003746 case DECL_UNRESOLVED_USING_VALUE:
Douglas Gregor72172e92012-01-05 21:55:30 +00003747 D = UnresolvedUsingValueDecl::CreateDeserialized(Context, ID);
Chris Lattnerca025db2010-05-07 21:43:38 +00003748 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003749 case DECL_UNRESOLVED_USING_TYPENAME:
Douglas Gregor72172e92012-01-05 21:55:30 +00003750 D = UnresolvedUsingTypenameDecl::CreateDeserialized(Context, ID);
Chris Lattnerca025db2010-05-07 21:43:38 +00003751 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003752 case DECL_CXX_RECORD:
Douglas Gregor72172e92012-01-05 21:55:30 +00003753 D = CXXRecordDecl::CreateDeserialized(Context, ID);
Chris Lattnerca025db2010-05-07 21:43:38 +00003754 break;
Richard Smithbc491202017-02-17 20:05:37 +00003755 case DECL_CXX_DEDUCTION_GUIDE:
3756 D = CXXDeductionGuideDecl::CreateDeserialized(Context, ID);
3757 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003758 case DECL_CXX_METHOD:
Douglas Gregor72172e92012-01-05 21:55:30 +00003759 D = CXXMethodDecl::CreateDeserialized(Context, ID);
Chris Lattnerca025db2010-05-07 21:43:38 +00003760 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003761 case DECL_CXX_CONSTRUCTOR:
Richard Smith76b90272019-05-09 03:59:21 +00003762 D = CXXConstructorDecl::CreateDeserialized(Context, ID, Record.readInt());
Chris Lattnerca025db2010-05-07 21:43:38 +00003763 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003764 case DECL_CXX_DESTRUCTOR:
Douglas Gregor72172e92012-01-05 21:55:30 +00003765 D = CXXDestructorDecl::CreateDeserialized(Context, ID);
Chris Lattnerca025db2010-05-07 21:43:38 +00003766 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003767 case DECL_CXX_CONVERSION:
Douglas Gregor72172e92012-01-05 21:55:30 +00003768 D = CXXConversionDecl::CreateDeserialized(Context, ID);
Chris Lattnerca025db2010-05-07 21:43:38 +00003769 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003770 case DECL_ACCESS_SPEC:
Douglas Gregor72172e92012-01-05 21:55:30 +00003771 D = AccessSpecDecl::CreateDeserialized(Context, ID);
Abramo Bagnarad7340582010-06-05 05:09:32 +00003772 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003773 case DECL_FRIEND:
David L. Jonesbe1557a2016-12-21 00:17:49 +00003774 D = FriendDecl::CreateDeserialized(Context, ID, Record.readInt());
Chris Lattnerca025db2010-05-07 21:43:38 +00003775 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003776 case DECL_FRIEND_TEMPLATE:
Douglas Gregor72172e92012-01-05 21:55:30 +00003777 D = FriendTemplateDecl::CreateDeserialized(Context, ID);
Chris Lattnerca025db2010-05-07 21:43:38 +00003778 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003779 case DECL_CLASS_TEMPLATE:
Douglas Gregor72172e92012-01-05 21:55:30 +00003780 D = ClassTemplateDecl::CreateDeserialized(Context, ID);
Chris Lattnerca025db2010-05-07 21:43:38 +00003781 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003782 case DECL_CLASS_TEMPLATE_SPECIALIZATION:
Douglas Gregor72172e92012-01-05 21:55:30 +00003783 D = ClassTemplateSpecializationDecl::CreateDeserialized(Context, ID);
Chris Lattnerca025db2010-05-07 21:43:38 +00003784 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003785 case DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION:
Douglas Gregor72172e92012-01-05 21:55:30 +00003786 D = ClassTemplatePartialSpecializationDecl::CreateDeserialized(Context, ID);
Chris Lattnerca025db2010-05-07 21:43:38 +00003787 break;
Larisse Voufo39a1e502013-08-06 01:03:05 +00003788 case DECL_VAR_TEMPLATE:
3789 D = VarTemplateDecl::CreateDeserialized(Context, ID);
3790 break;
3791 case DECL_VAR_TEMPLATE_SPECIALIZATION:
3792 D = VarTemplateSpecializationDecl::CreateDeserialized(Context, ID);
3793 break;
3794 case DECL_VAR_TEMPLATE_PARTIAL_SPECIALIZATION:
3795 D = VarTemplatePartialSpecializationDecl::CreateDeserialized(Context, ID);
3796 break;
Francois Pichet00c7e6c2011-08-14 03:52:19 +00003797 case DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION:
Douglas Gregor72172e92012-01-05 21:55:30 +00003798 D = ClassScopeFunctionSpecializationDecl::CreateDeserialized(Context, ID);
Francois Pichet00c7e6c2011-08-14 03:52:19 +00003799 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003800 case DECL_FUNCTION_TEMPLATE:
Douglas Gregor72172e92012-01-05 21:55:30 +00003801 D = FunctionTemplateDecl::CreateDeserialized(Context, ID);
Chris Lattnerca025db2010-05-07 21:43:38 +00003802 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003803 case DECL_TEMPLATE_TYPE_PARM:
Douglas Gregor72172e92012-01-05 21:55:30 +00003804 D = TemplateTypeParmDecl::CreateDeserialized(Context, ID);
Chris Lattnerca025db2010-05-07 21:43:38 +00003805 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003806 case DECL_NON_TYPE_TEMPLATE_PARM:
Douglas Gregor72172e92012-01-05 21:55:30 +00003807 D = NonTypeTemplateParmDecl::CreateDeserialized(Context, ID);
Chris Lattnerca025db2010-05-07 21:43:38 +00003808 break;
Douglas Gregor0231d8d2011-01-19 20:10:05 +00003809 case DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK:
David L. Jonesbe1557a2016-12-21 00:17:49 +00003810 D = NonTypeTemplateParmDecl::CreateDeserialized(Context, ID,
3811 Record.readInt());
Douglas Gregor0231d8d2011-01-19 20:10:05 +00003812 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003813 case DECL_TEMPLATE_TEMPLATE_PARM:
Douglas Gregor72172e92012-01-05 21:55:30 +00003814 D = TemplateTemplateParmDecl::CreateDeserialized(Context, ID);
Chris Lattnerca025db2010-05-07 21:43:38 +00003815 break;
Richard Smith1fde8ec2012-09-07 02:06:42 +00003816 case DECL_EXPANDED_TEMPLATE_TEMPLATE_PARM_PACK:
3817 D = TemplateTemplateParmDecl::CreateDeserialized(Context, ID,
David L. Jonesbe1557a2016-12-21 00:17:49 +00003818 Record.readInt());
Richard Smith1fde8ec2012-09-07 02:06:42 +00003819 break;
Richard Smith3f1b5d02011-05-05 21:57:07 +00003820 case DECL_TYPE_ALIAS_TEMPLATE:
Douglas Gregor72172e92012-01-05 21:55:30 +00003821 D = TypeAliasTemplateDecl::CreateDeserialized(Context, ID);
Richard Smith3f1b5d02011-05-05 21:57:07 +00003822 break;
Saar Razd7aae332019-07-10 21:25:49 +00003823 case DECL_CONCEPT:
3824 D = ConceptDecl::CreateDeserialized(Context, ID);
3825 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003826 case DECL_STATIC_ASSERT:
Douglas Gregor72172e92012-01-05 21:55:30 +00003827 D = StaticAssertDecl::CreateDeserialized(Context, ID);
Chris Lattnerca025db2010-05-07 21:43:38 +00003828 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003829 case DECL_OBJC_METHOD:
Douglas Gregor72172e92012-01-05 21:55:30 +00003830 D = ObjCMethodDecl::CreateDeserialized(Context, ID);
Chris Lattner487412d2009-04-27 05:27:42 +00003831 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003832 case DECL_OBJC_INTERFACE:
Douglas Gregor72172e92012-01-05 21:55:30 +00003833 D = ObjCInterfaceDecl::CreateDeserialized(Context, ID);
Chris Lattner487412d2009-04-27 05:27:42 +00003834 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003835 case DECL_OBJC_IVAR:
Douglas Gregor72172e92012-01-05 21:55:30 +00003836 D = ObjCIvarDecl::CreateDeserialized(Context, ID);
Chris Lattner487412d2009-04-27 05:27:42 +00003837 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003838 case DECL_OBJC_PROTOCOL:
Douglas Gregor72172e92012-01-05 21:55:30 +00003839 D = ObjCProtocolDecl::CreateDeserialized(Context, ID);
Chris Lattner487412d2009-04-27 05:27:42 +00003840 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003841 case DECL_OBJC_AT_DEFS_FIELD:
Douglas Gregor72172e92012-01-05 21:55:30 +00003842 D = ObjCAtDefsFieldDecl::CreateDeserialized(Context, ID);
Chris Lattner487412d2009-04-27 05:27:42 +00003843 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003844 case DECL_OBJC_CATEGORY:
Douglas Gregor72172e92012-01-05 21:55:30 +00003845 D = ObjCCategoryDecl::CreateDeserialized(Context, ID);
Chris Lattner487412d2009-04-27 05:27:42 +00003846 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003847 case DECL_OBJC_CATEGORY_IMPL:
Douglas Gregor72172e92012-01-05 21:55:30 +00003848 D = ObjCCategoryImplDecl::CreateDeserialized(Context, ID);
Chris Lattner487412d2009-04-27 05:27:42 +00003849 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003850 case DECL_OBJC_IMPLEMENTATION:
Douglas Gregor72172e92012-01-05 21:55:30 +00003851 D = ObjCImplementationDecl::CreateDeserialized(Context, ID);
Chris Lattner487412d2009-04-27 05:27:42 +00003852 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003853 case DECL_OBJC_COMPATIBLE_ALIAS:
Douglas Gregor72172e92012-01-05 21:55:30 +00003854 D = ObjCCompatibleAliasDecl::CreateDeserialized(Context, ID);
Chris Lattner487412d2009-04-27 05:27:42 +00003855 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003856 case DECL_OBJC_PROPERTY:
Douglas Gregor72172e92012-01-05 21:55:30 +00003857 D = ObjCPropertyDecl::CreateDeserialized(Context, ID);
Chris Lattner487412d2009-04-27 05:27:42 +00003858 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003859 case DECL_OBJC_PROPERTY_IMPL:
Douglas Gregor72172e92012-01-05 21:55:30 +00003860 D = ObjCPropertyImplDecl::CreateDeserialized(Context, ID);
Chris Lattner487412d2009-04-27 05:27:42 +00003861 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003862 case DECL_FIELD:
Douglas Gregor72172e92012-01-05 21:55:30 +00003863 D = FieldDecl::CreateDeserialized(Context, ID);
Chris Lattner487412d2009-04-27 05:27:42 +00003864 break;
Francois Pichet783dd6e2010-11-21 06:08:52 +00003865 case DECL_INDIRECTFIELD:
Douglas Gregor72172e92012-01-05 21:55:30 +00003866 D = IndirectFieldDecl::CreateDeserialized(Context, ID);
Francois Pichet783dd6e2010-11-21 06:08:52 +00003867 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003868 case DECL_VAR:
Douglas Gregor72172e92012-01-05 21:55:30 +00003869 D = VarDecl::CreateDeserialized(Context, ID);
Chris Lattner487412d2009-04-27 05:27:42 +00003870 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003871 case DECL_IMPLICIT_PARAM:
Douglas Gregor72172e92012-01-05 21:55:30 +00003872 D = ImplicitParamDecl::CreateDeserialized(Context, ID);
Chris Lattner487412d2009-04-27 05:27:42 +00003873 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003874 case DECL_PARM_VAR:
Douglas Gregor72172e92012-01-05 21:55:30 +00003875 D = ParmVarDecl::CreateDeserialized(Context, ID);
Chris Lattner487412d2009-04-27 05:27:42 +00003876 break;
Richard Smith7b76d812016-08-12 02:21:25 +00003877 case DECL_DECOMPOSITION:
David L. Jonesbe1557a2016-12-21 00:17:49 +00003878 D = DecompositionDecl::CreateDeserialized(Context, ID, Record.readInt());
Richard Smith7b76d812016-08-12 02:21:25 +00003879 break;
3880 case DECL_BINDING:
3881 D = BindingDecl::CreateDeserialized(Context, ID);
3882 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003883 case DECL_FILE_SCOPE_ASM:
Douglas Gregor72172e92012-01-05 21:55:30 +00003884 D = FileScopeAsmDecl::CreateDeserialized(Context, ID);
Chris Lattner487412d2009-04-27 05:27:42 +00003885 break;
Sebastian Redl539c5062010-08-18 23:57:32 +00003886 case DECL_BLOCK:
Douglas Gregor72172e92012-01-05 21:55:30 +00003887 D = BlockDecl::CreateDeserialized(Context, ID);
Chris Lattner487412d2009-04-27 05:27:42 +00003888 break;
John McCall5e77d762013-04-16 07:28:30 +00003889 case DECL_MS_PROPERTY:
3890 D = MSPropertyDecl::CreateDeserialized(Context, ID);
3891 break;
Tareq A. Siraj6dfa25a2013-04-16 19:37:38 +00003892 case DECL_CAPTURED:
David L. Jonesbe1557a2016-12-21 00:17:49 +00003893 D = CapturedDecl::CreateDeserialized(Context, ID, Record.readInt());
Tareq A. Siraj6dfa25a2013-04-16 19:37:38 +00003894 break;
Douglas Gregord4c5ed02010-10-29 22:39:52 +00003895 case DECL_CXX_BASE_SPECIFIERS:
3896 Error("attempt to read a C++ base-specifier record as a declaration");
Craig Toppera13603a2014-05-22 05:54:18 +00003897 return nullptr;
Richard Smithc2bb8182015-03-24 06:36:48 +00003898 case DECL_CXX_CTOR_INITIALIZERS:
3899 Error("attempt to read a C++ ctor initializer record as a declaration");
3900 return nullptr;
Douglas Gregorba345522011-12-02 23:23:56 +00003901 case DECL_IMPORT:
Fangrui Song6907ce22018-07-30 19:24:48 +00003902 // Note: last entry of the ImportDecl record is the number of stored source
Douglas Gregorba345522011-12-02 23:23:56 +00003903 // locations.
Douglas Gregor72172e92012-01-05 21:55:30 +00003904 D = ImportDecl::CreateDeserialized(Context, ID, Record.back());
Douglas Gregorba345522011-12-02 23:23:56 +00003905 break;
Alexey Bataeva769e072013-03-22 06:34:35 +00003906 case DECL_OMP_THREADPRIVATE:
David L. Jonesbe1557a2016-12-21 00:17:49 +00003907 D = OMPThreadPrivateDecl::CreateDeserialized(Context, ID, Record.readInt());
Alexey Bataeva769e072013-03-22 06:34:35 +00003908 break;
Alexey Bataev9cc10fc2019-03-12 18:52:33 +00003909 case DECL_OMP_ALLOCATE: {
3910 unsigned NumVars = Record.readInt();
3911 unsigned NumClauses = Record.readInt();
3912 D = OMPAllocateDecl::CreateDeserialized(Context, ID, NumVars, NumClauses);
Alexey Bataev25ed0c02019-03-07 17:54:44 +00003913 break;
Alexey Bataev9cc10fc2019-03-12 18:52:33 +00003914 }
Kelvin Li1408f912018-09-26 04:28:39 +00003915 case DECL_OMP_REQUIRES:
3916 D = OMPRequiresDecl::CreateDeserialized(Context, ID, Record.readInt());
3917 break;
Alexey Bataev94a4f0c2016-03-03 05:21:39 +00003918 case DECL_OMP_DECLARE_REDUCTION:
3919 D = OMPDeclareReductionDecl::CreateDeserialized(Context, ID);
3920 break;
Michael Kruse251e1482019-02-01 20:25:04 +00003921 case DECL_OMP_DECLARE_MAPPER:
3922 D = OMPDeclareMapperDecl::CreateDeserialized(Context, ID, Record.readInt());
3923 break;
Alexey Bataev4244be22016-02-11 05:35:55 +00003924 case DECL_OMP_CAPTUREDEXPR:
3925 D = OMPCapturedExprDecl::CreateDeserialized(Context, ID);
Alexey Bataev90c228f2016-02-08 09:29:13 +00003926 break;
Nico Weber66220292016-03-02 17:28:48 +00003927 case DECL_PRAGMA_COMMENT:
David L. Jonesbe1557a2016-12-21 00:17:49 +00003928 D = PragmaCommentDecl::CreateDeserialized(Context, ID, Record.readInt());
Nico Weber66220292016-03-02 17:28:48 +00003929 break;
Nico Webercbbaeb12016-03-02 19:28:54 +00003930 case DECL_PRAGMA_DETECT_MISMATCH:
3931 D = PragmaDetectMismatchDecl::CreateDeserialized(Context, ID,
David L. Jonesbe1557a2016-12-21 00:17:49 +00003932 Record.readInt());
Nico Webercbbaeb12016-03-02 19:28:54 +00003933 break;
Michael Han84324352013-02-22 17:15:32 +00003934 case DECL_EMPTY:
3935 D = EmptyDecl::CreateDeserialized(Context, ID);
3936 break;
Tykerb0561b32019-11-17 11:41:55 +01003937 case DECL_LIFETIME_EXTENDED_TEMPORARY:
3938 D = LifetimeExtendedTemporaryDecl::CreateDeserialized(Context, ID);
3939 break;
Douglas Gregor85f3f952015-07-07 03:57:15 +00003940 case DECL_OBJC_TYPE_PARAM:
3941 D = ObjCTypeParamDecl::CreateDeserialized(Context, ID);
3942 break;
Chris Lattner487412d2009-04-27 05:27:42 +00003943 }
Chris Lattner487412d2009-04-27 05:27:42 +00003944
Sebastian Redlb3298c32010-08-18 23:56:48 +00003945 assert(D && "Unknown declaration reading AST file");
Chris Lattner8f63ab52009-04-27 06:01:06 +00003946 LoadedDecl(Index, D);
Argyrios Kyrtzidis6c075472012-02-09 06:02:44 +00003947 // Set the DeclContext before doing any deserialization, to make sure internal
3948 // calls to Decl::getASTContext() by Decl's methods will find the
3949 // TranslationUnitDecl without crashing.
3950 D->setDeclContext(Context.getTranslationUnitDecl());
Chris Lattner8f63ab52009-04-27 06:01:06 +00003951 Reader.Visit(D);
Chris Lattner487412d2009-04-27 05:27:42 +00003952
3953 // If this declaration is also a declaration context, get the
3954 // offsets for its tables of lexical and visible declarations.
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00003955 if (auto *DC = dyn_cast<DeclContext>(D)) {
Chris Lattner487412d2009-04-27 05:27:42 +00003956 std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC);
Richard Smith0f4e2c42015-08-06 04:23:48 +00003957 if (Offsets.first &&
3958 ReadLexicalDeclContextStorage(*Loc.F, DeclsCursor, Offsets.first, DC))
3959 return nullptr;
3960 if (Offsets.second &&
3961 ReadVisibleDeclContextStorage(*Loc.F, DeclsCursor, Offsets.second, ID))
3962 return nullptr;
Chris Lattner487412d2009-04-27 05:27:42 +00003963 }
David L. Jonesbe1557a2016-12-21 00:17:49 +00003964 assert(Record.getIdx() == Record.size());
Chris Lattner487412d2009-04-27 05:27:42 +00003965
Douglas Gregordab42432011-08-12 00:15:20 +00003966 // Load any relevant update records.
Vassil Vassilev74c3e8c2017-05-19 16:46:06 +00003967 PendingUpdateRecords.push_back(
3968 PendingUpdateRecord(ID, D, /*JustLoaded=*/true));
Argyrios Kyrtzidis7d268c32011-11-14 07:07:59 +00003969
Douglas Gregor404cdde2012-01-27 01:47:08 +00003970 // Load the categories after recursive loading is finished.
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00003971 if (auto *Class = dyn_cast<ObjCInterfaceDecl>(D))
Manman Renec315f12016-09-09 23:48:27 +00003972 // If we already have a definition when deserializing the ObjCInterfaceDecl,
3973 // we put the Decl in PendingDefinitions so we can pull the categories here.
3974 if (Class->isThisDeclarationADefinition() ||
3975 PendingDefinitions.count(Class))
Douglas Gregor404cdde2012-01-27 01:47:08 +00003976 loadObjCCategories(ID, Class);
Fangrui Song6907ce22018-07-30 19:24:48 +00003977
Richard Smith13fb8602016-07-15 21:33:46 +00003978 // If we have deserialized a declaration that has a definition the
3979 // AST consumer might need to know about, queue it.
3980 // We don't pass it to the consumer immediately because we may be in recursive
3981 // loading, and some declarations may still be initializing.
Daniel Jasper4a6d5b72017-10-11 07:47:54 +00003982 PotentiallyInterestingDecls.push_back(
3983 InterestingDecl(D, Reader.hasPendingBody()));
Richard Smith13fb8602016-07-15 21:33:46 +00003984
Douglas Gregordab42432011-08-12 00:15:20 +00003985 return D;
3986}
3987
Vassil Vassilev46afbbb2017-04-12 21:56:05 +00003988void ASTReader::PassInterestingDeclsToConsumer() {
3989 assert(Consumer);
3990
3991 if (PassingDeclsToConsumer)
3992 return;
3993
3994 // Guard variable to avoid recursively redoing the process of passing
3995 // decls to consumer.
3996 SaveAndRestore<bool> GuardPassingDeclsToConsumer(PassingDeclsToConsumer,
3997 true);
3998
3999 // Ensure that we've loaded all potentially-interesting declarations
4000 // that need to be eagerly loaded.
4001 for (auto ID : EagerlyDeserializedDecls)
4002 GetDecl(ID);
4003 EagerlyDeserializedDecls.clear();
4004
4005 while (!PotentiallyInterestingDecls.empty()) {
Daniel Jasper4a6d5b72017-10-11 07:47:54 +00004006 InterestingDecl D = PotentiallyInterestingDecls.front();
Vassil Vassilev46afbbb2017-04-12 21:56:05 +00004007 PotentiallyInterestingDecls.pop_front();
Daniel Jasper4a6d5b72017-10-11 07:47:54 +00004008 if (isConsumerInterestedIn(getContext(), D.getDecl(), D.hasPendingBody()))
4009 PassInterestingDeclToConsumer(D.getDecl());
Vassil Vassilev46afbbb2017-04-12 21:56:05 +00004010 }
4011}
4012
Vassil Vassilev74c3e8c2017-05-19 16:46:06 +00004013void ASTReader::loadDeclUpdateRecords(PendingUpdateRecord &Record) {
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00004014 // The declaration may have been modified by files later in the chain.
4015 // If this is the case, read the record containing the updates from each file
4016 // and pass it to ASTDeclReader to make the modifications.
Vassil Vassilev74c3e8c2017-05-19 16:46:06 +00004017 serialization::GlobalDeclID ID = Record.ID;
4018 Decl *D = Record.D;
Vassil Vassilev19765fb2016-07-22 21:08:24 +00004019 ProcessingUpdatesRAIIObj ProcessingUpdates(*this);
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00004020 DeclUpdateOffsetsMap::iterator UpdI = DeclUpdateOffsets.find(ID);
Vassil Vassilev7d264622017-06-30 22:40:17 +00004021
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00004022 SmallVector<serialization::DeclID, 8> PendingLazySpecializationIDs;
Vassil Vassilev7d264622017-06-30 22:40:17 +00004023
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00004024 if (UpdI != DeclUpdateOffsets.end()) {
Richard Smith0f4e2c42015-08-06 04:23:48 +00004025 auto UpdateOffsets = std::move(UpdI->second);
4026 DeclUpdateOffsets.erase(UpdI);
4027
Vassil Vassilev74c3e8c2017-05-19 16:46:06 +00004028 // Check if this decl was interesting to the consumer. If we just loaded
4029 // the declaration, then we know it was interesting and we skip the call
4030 // to isConsumerInterestedIn because it is unsafe to call in the
4031 // current ASTReader state.
4032 bool WasInteresting =
Daniel Jasper4a6d5b72017-10-11 07:47:54 +00004033 Record.JustLoaded || isConsumerInterestedIn(getContext(), D, false);
Richard Smith0f4e2c42015-08-06 04:23:48 +00004034 for (auto &FileAndOffset : UpdateOffsets) {
4035 ModuleFile *F = FileAndOffset.first;
4036 uint64_t Offset = FileAndOffset.second;
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00004037 llvm::BitstreamCursor &Cursor = F->DeclsCursor;
4038 SavedStreamPosition SavedPosition(Cursor);
JF Bastien0e828952019-06-26 19:50:12 +00004039 if (llvm::Error JumpFailed = Cursor.JumpToBit(Offset))
4040 // FIXME don't do a fatal error.
4041 llvm::report_fatal_error(
4042 "ASTReader::loadDeclUpdateRecords failed jumping: " +
4043 toString(std::move(JumpFailed)));
4044 Expected<unsigned> MaybeCode = Cursor.ReadCode();
4045 if (!MaybeCode)
4046 llvm::report_fatal_error(
4047 "ASTReader::loadDeclUpdateRecords failed reading code: " +
4048 toString(MaybeCode.takeError()));
4049 unsigned Code = MaybeCode.get();
David L. Jonesbe1557a2016-12-21 00:17:49 +00004050 ASTRecordReader Record(*this, *F);
JF Bastien0e828952019-06-26 19:50:12 +00004051 if (Expected<unsigned> MaybeRecCode = Record.readRecord(Cursor, Code))
4052 assert(MaybeRecCode.get() == DECL_UPDATES &&
4053 "Expected DECL_UPDATES record!");
4054 else
4055 llvm::report_fatal_error(
4056 "ASTReader::loadDeclUpdateRecords failed reading rec code: " +
4057 toString(MaybeCode.takeError()));
Richard Smith04d05b52014-03-23 00:27:18 +00004058
David L. Jonesbe1557a2016-12-21 00:17:49 +00004059 ASTDeclReader Reader(*this, Record, RecordLocation(F, Offset), ID,
4060 SourceLocation());
Vassil Vassilev7d264622017-06-30 22:40:17 +00004061 Reader.UpdateDecl(D, PendingLazySpecializationIDs);
Richard Smith04d05b52014-03-23 00:27:18 +00004062
4063 // We might have made this declaration interesting. If so, remember that
4064 // we need to hand it off to the consumer.
Daniel Jasper4a6d5b72017-10-11 07:47:54 +00004065 if (!WasInteresting &&
4066 isConsumerInterestedIn(getContext(), D, Reader.hasPendingBody())) {
4067 PotentiallyInterestingDecls.push_back(
4068 InterestingDecl(D, Reader.hasPendingBody()));
Richard Smith04d05b52014-03-23 00:27:18 +00004069 WasInteresting = true;
4070 }
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00004071 }
4072 }
Vassil Vassilev7d264622017-06-30 22:40:17 +00004073 // Add the lazy specializations to the template.
4074 assert((PendingLazySpecializationIDs.empty() || isa<ClassTemplateDecl>(D) ||
4075 isa<FunctionTemplateDecl>(D) || isa<VarTemplateDecl>(D)) &&
4076 "Must not have pending specializations");
4077 if (auto *CTD = dyn_cast<ClassTemplateDecl>(D))
4078 ASTDeclReader::AddLazySpecializations(CTD, PendingLazySpecializationIDs);
4079 else if (auto *FTD = dyn_cast<FunctionTemplateDecl>(D))
4080 ASTDeclReader::AddLazySpecializations(FTD, PendingLazySpecializationIDs);
4081 else if (auto *VTD = dyn_cast<VarTemplateDecl>(D))
4082 ASTDeclReader::AddLazySpecializations(VTD, PendingLazySpecializationIDs);
4083 PendingLazySpecializationIDs.clear();
Richard Smith1e8e91b2016-04-08 20:53:26 +00004084
4085 // Load the pending visible updates for this decl context, if it has any.
4086 auto I = PendingVisibleUpdates.find(ID);
4087 if (I != PendingVisibleUpdates.end()) {
4088 auto VisibleUpdates = std::move(I->second);
4089 PendingVisibleUpdates.erase(I);
4090
4091 auto *DC = cast<DeclContext>(D)->getPrimaryContext();
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00004092 for (const auto &Update : VisibleUpdates)
Richard Smith1e8e91b2016-04-08 20:53:26 +00004093 Lookups[DC].Table.add(
4094 Update.Mod, Update.Data,
4095 reader::ASTDeclContextNameLookupTrait(*this, *Update.Mod));
4096 DC->setHasExternalVisibleStorage(true);
4097 }
Chris Lattner487412d2009-04-27 05:27:42 +00004098}
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00004099
Richard Smithd61d4ac2015-08-22 20:13:39 +00004100void ASTReader::loadPendingDeclChain(Decl *FirstLocal, uint64_t LocalOffset) {
4101 // Attach FirstLocal to the end of the decl chain.
Richard Smithd8a83712015-08-22 01:47:18 +00004102 Decl *CanonDecl = FirstLocal->getCanonicalDecl();
Richard Smithd61d4ac2015-08-22 20:13:39 +00004103 if (FirstLocal != CanonDecl) {
4104 Decl *PrevMostRecent = ASTDeclReader::getMostRecentDecl(CanonDecl);
4105 ASTDeclReader::attachPreviousDecl(
4106 *this, FirstLocal, PrevMostRecent ? PrevMostRecent : CanonDecl,
4107 CanonDecl);
4108 }
4109
4110 if (!LocalOffset) {
4111 ASTDeclReader::attachLatestDecl(CanonDecl, FirstLocal);
4112 return;
4113 }
4114
4115 // Load the list of other redeclarations from this module file.
4116 ModuleFile *M = getOwningModuleFile(FirstLocal);
4117 assert(M && "imported decl from no module file");
4118
4119 llvm::BitstreamCursor &Cursor = M->DeclsCursor;
4120 SavedStreamPosition SavedPosition(Cursor);
JF Bastien0e828952019-06-26 19:50:12 +00004121 if (llvm::Error JumpFailed = Cursor.JumpToBit(LocalOffset))
4122 llvm::report_fatal_error(
4123 "ASTReader::loadPendingDeclChain failed jumping: " +
4124 toString(std::move(JumpFailed)));
Richard Smithd61d4ac2015-08-22 20:13:39 +00004125
4126 RecordData Record;
JF Bastien0e828952019-06-26 19:50:12 +00004127 Expected<unsigned> MaybeCode = Cursor.ReadCode();
4128 if (!MaybeCode)
4129 llvm::report_fatal_error(
4130 "ASTReader::loadPendingDeclChain failed reading code: " +
4131 toString(MaybeCode.takeError()));
4132 unsigned Code = MaybeCode.get();
4133 if (Expected<unsigned> MaybeRecCode = Cursor.readRecord(Code, Record))
4134 assert(MaybeRecCode.get() == LOCAL_REDECLARATIONS &&
4135 "expected LOCAL_REDECLARATIONS record!");
4136 else
4137 llvm::report_fatal_error(
4138 "ASTReader::loadPendingDeclChain failed reading rec code: " +
4139 toString(MaybeCode.takeError()));
Richard Smithd61d4ac2015-08-22 20:13:39 +00004140
4141 // FIXME: We have several different dispatches on decl kind here; maybe
4142 // we should instead generate one loop per kind and dispatch up-front?
4143 Decl *MostRecent = FirstLocal;
4144 for (unsigned I = 0, N = Record.size(); I != N; ++I) {
4145 auto *D = GetLocalDecl(*M, Record[N - I - 1]);
Richard Smithe2f8ce92015-07-15 00:02:40 +00004146 ASTDeclReader::attachPreviousDecl(*this, D, MostRecent, CanonDecl);
4147 MostRecent = D;
Douglas Gregor05f10352011-12-17 23:38:30 +00004148 }
Richard Smithc3a53252015-02-28 05:57:02 +00004149 ASTDeclReader::attachLatestDecl(CanonDecl, MostRecent);
Douglas Gregor05f10352011-12-17 23:38:30 +00004150}
4151
4152namespace {
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00004153
Adrian Prantl9fc8faf2018-05-09 01:00:01 +00004154 /// Given an ObjC interface, goes through the modules and links to the
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00004155 /// interface all the categories for it.
Douglas Gregor404cdde2012-01-27 01:47:08 +00004156 class ObjCCategoriesVisitor {
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00004157 ASTReader &Reader;
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00004158 ObjCInterfaceDecl *Interface;
Craig Topper4dd9b432014-08-17 23:49:53 +00004159 llvm::SmallPtrSetImpl<ObjCCategoryDecl *> &Deserialized;
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00004160 ObjCCategoryDecl *Tail = nullptr;
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00004161 llvm::DenseMap<DeclarationName, ObjCCategoryDecl *> NameCategoryMap;
Alexander Shaposhnikov96cbe7b2016-09-24 02:07:19 +00004162 serialization::GlobalDeclID InterfaceID;
4163 unsigned PreviousGeneration;
Fangrui Song6907ce22018-07-30 19:24:48 +00004164
Douglas Gregor404cdde2012-01-27 01:47:08 +00004165 void add(ObjCCategoryDecl *Cat) {
4166 // Only process each category once.
Benjamin Kramerfc6eb7d2012-08-22 15:37:55 +00004167 if (!Deserialized.erase(Cat))
Douglas Gregor404cdde2012-01-27 01:47:08 +00004168 return;
Fangrui Song6907ce22018-07-30 19:24:48 +00004169
Douglas Gregor404cdde2012-01-27 01:47:08 +00004170 // Check for duplicate categories.
4171 if (Cat->getDeclName()) {
4172 ObjCCategoryDecl *&Existing = NameCategoryMap[Cat->getDeclName()];
Fangrui Song6907ce22018-07-30 19:24:48 +00004173 if (Existing &&
4174 Reader.getOwningModuleFile(Existing)
Douglas Gregor404cdde2012-01-27 01:47:08 +00004175 != Reader.getOwningModuleFile(Cat)) {
4176 // FIXME: We should not warn for duplicates in diamond:
4177 //
4178 // MT //
4179 // / \ //
4180 // ML MR //
4181 // \ / //
4182 // MB //
4183 //
Fangrui Song6907ce22018-07-30 19:24:48 +00004184 // If there are duplicates in ML/MR, there will be warning when
4185 // creating MB *and* when importing MB. We should not warn when
Douglas Gregor404cdde2012-01-27 01:47:08 +00004186 // importing.
4187 Reader.Diag(Cat->getLocation(), diag::warn_dup_category_def)
4188 << Interface->getDeclName() << Cat->getDeclName();
4189 Reader.Diag(Existing->getLocation(), diag::note_previous_definition);
4190 } else if (!Existing) {
4191 // Record this category.
4192 Existing = Cat;
4193 }
4194 }
Fangrui Song6907ce22018-07-30 19:24:48 +00004195
Douglas Gregor404cdde2012-01-27 01:47:08 +00004196 // Add this category to the end of the chain.
4197 if (Tail)
4198 ASTDeclReader::setNextObjCCategory(Tail, Cat);
4199 else
Douglas Gregor048fbfa2013-01-16 23:00:23 +00004200 Interface->setCategoryListRaw(Cat);
Douglas Gregor404cdde2012-01-27 01:47:08 +00004201 Tail = Cat;
4202 }
Fangrui Song6907ce22018-07-30 19:24:48 +00004203
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00004204 public:
Douglas Gregor404cdde2012-01-27 01:47:08 +00004205 ObjCCategoriesVisitor(ASTReader &Reader,
Douglas Gregor404cdde2012-01-27 01:47:08 +00004206 ObjCInterfaceDecl *Interface,
Alexander Shaposhnikov96cbe7b2016-09-24 02:07:19 +00004207 llvm::SmallPtrSetImpl<ObjCCategoryDecl *> &Deserialized,
4208 serialization::GlobalDeclID InterfaceID,
Douglas Gregor404cdde2012-01-27 01:47:08 +00004209 unsigned PreviousGeneration)
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00004210 : Reader(Reader), Interface(Interface), Deserialized(Deserialized),
4211 InterfaceID(InterfaceID), PreviousGeneration(PreviousGeneration) {
Douglas Gregor404cdde2012-01-27 01:47:08 +00004212 // Populate the name -> category map with the set of known categories.
Aaron Ballman15063e12014-03-13 21:35:02 +00004213 for (auto *Cat : Interface->known_categories()) {
Douglas Gregor404cdde2012-01-27 01:47:08 +00004214 if (Cat->getDeclName())
Aaron Ballman15063e12014-03-13 21:35:02 +00004215 NameCategoryMap[Cat->getDeclName()] = Cat;
Fangrui Song6907ce22018-07-30 19:24:48 +00004216
Douglas Gregor404cdde2012-01-27 01:47:08 +00004217 // Keep track of the tail of the category list.
Aaron Ballman15063e12014-03-13 21:35:02 +00004218 Tail = Cat;
Douglas Gregor404cdde2012-01-27 01:47:08 +00004219 }
4220 }
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00004221
Benjamin Kramer9a9efba2015-07-25 12:14:04 +00004222 bool operator()(ModuleFile &M) {
Douglas Gregor404cdde2012-01-27 01:47:08 +00004223 // If we've loaded all of the category information we care about from
4224 // this module file, we're done.
4225 if (M.Generation <= PreviousGeneration)
4226 return true;
Fangrui Song6907ce22018-07-30 19:24:48 +00004227
4228 // Map global ID of the definition down to the local ID used in this
Douglas Gregor404cdde2012-01-27 01:47:08 +00004229 // module file. If there is no such mapping, we'll find nothing here
4230 // (or in any module it imports).
4231 DeclID LocalID = Reader.mapGlobalIDToModuleFileGlobalID(M, InterfaceID);
4232 if (!LocalID)
4233 return true;
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00004234
Douglas Gregor404cdde2012-01-27 01:47:08 +00004235 // Perform a binary search to find the local redeclarations for this
4236 // declaration (if any).
Benjamin Kramera6f39502014-03-15 14:21:58 +00004237 const ObjCCategoriesInfo Compare = { LocalID, 0 };
Douglas Gregor404cdde2012-01-27 01:47:08 +00004238 const ObjCCategoriesInfo *Result
4239 = std::lower_bound(M.ObjCCategoriesMap,
Fangrui Song6907ce22018-07-30 19:24:48 +00004240 M.ObjCCategoriesMap + M.LocalNumObjCCategoriesInMap,
Benjamin Kramera6f39502014-03-15 14:21:58 +00004241 Compare);
Douglas Gregor404cdde2012-01-27 01:47:08 +00004242 if (Result == M.ObjCCategoriesMap + M.LocalNumObjCCategoriesInMap ||
4243 Result->DefinitionID != LocalID) {
4244 // We didn't find anything. If the class definition is in this module
4245 // file, then the module files it depends on cannot have any categories,
4246 // so suppress further lookup.
4247 return Reader.isDeclIDFromModule(InterfaceID, M);
4248 }
Fangrui Song6907ce22018-07-30 19:24:48 +00004249
Douglas Gregor404cdde2012-01-27 01:47:08 +00004250 // We found something. Dig out all of the categories.
4251 unsigned Offset = Result->Offset;
4252 unsigned N = M.ObjCCategories[Offset];
4253 M.ObjCCategories[Offset++] = 0; // Don't try to deserialize again
4254 for (unsigned I = 0; I != N; ++I)
4255 add(cast_or_null<ObjCCategoryDecl>(
4256 Reader.GetLocalDecl(M, M.ObjCCategories[Offset++])));
4257 return true;
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00004258 }
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00004259 };
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00004260
4261} // namespace
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00004262
Douglas Gregor404cdde2012-01-27 01:47:08 +00004263void ASTReader::loadObjCCategories(serialization::GlobalDeclID ID,
4264 ObjCInterfaceDecl *D,
4265 unsigned PreviousGeneration) {
Alexander Shaposhnikov96cbe7b2016-09-24 02:07:19 +00004266 ObjCCategoriesVisitor Visitor(*this, D, CategoriesDeserialized, ID,
Douglas Gregor404cdde2012-01-27 01:47:08 +00004267 PreviousGeneration);
Benjamin Kramer9a9efba2015-07-25 12:14:04 +00004268 ModuleMgr.visit(Visitor);
Argyrios Kyrtzidis7d847c92011-09-01 00:58:55 +00004269}
Douglas Gregordab42432011-08-12 00:15:20 +00004270
Richard Smithd6db68c2014-08-07 20:58:41 +00004271template<typename DeclT, typename Fn>
4272static void forAllLaterRedecls(DeclT *D, Fn F) {
4273 F(D);
4274
4275 // Check whether we've already merged D into its redeclaration chain.
4276 // MostRecent may or may not be nullptr if D has not been merged. If
4277 // not, walk the merged redecl chain and see if it's there.
4278 auto *MostRecent = D->getMostRecentDecl();
4279 bool Found = false;
4280 for (auto *Redecl = MostRecent; Redecl && !Found;
4281 Redecl = Redecl->getPreviousDecl())
4282 Found = (Redecl == D);
4283
4284 // If this declaration is merged, apply the functor to all later decls.
4285 if (Found) {
4286 for (auto *Redecl = MostRecent; Redecl != D;
4287 Redecl = Redecl->getPreviousDecl())
4288 F(Redecl);
4289 }
4290}
4291
Vassil Vassilev7d264622017-06-30 22:40:17 +00004292void ASTDeclReader::UpdateDecl(Decl *D,
4293 llvm::SmallVectorImpl<serialization::DeclID> &PendingLazySpecializationIDs) {
David L. Jonesbe1557a2016-12-21 00:17:49 +00004294 while (Record.getIdx() < Record.size()) {
4295 switch ((DeclUpdateKind)Record.readInt()) {
Richard Smithcd45dbc2014-04-19 03:48:30 +00004296 case UPD_CXX_ADDED_IMPLICIT_MEMBER: {
Richard Smith1b65dbc2015-01-22 03:50:31 +00004297 auto *RD = cast<CXXRecordDecl>(D);
Richard Smithd6db68c2014-08-07 20:58:41 +00004298 // FIXME: If we also have an update record for instantiating the
4299 // definition of D, we need that to happen before we get here.
David L. Jonesb6a8f022016-12-21 04:34:52 +00004300 Decl *MD = Record.readDecl();
Richard Smithcd45dbc2014-04-19 03:48:30 +00004301 assert(MD && "couldn't read decl from update record");
Richard Smith46bb5812014-08-01 01:56:39 +00004302 // FIXME: We should call addHiddenDecl instead, to add the member
4303 // to its DeclContext.
Richard Smith1b65dbc2015-01-22 03:50:31 +00004304 RD->addedMember(MD);
Argyrios Kyrtzidise16a5302010-10-24 17:26:54 +00004305 break;
Richard Smithcd45dbc2014-04-19 03:48:30 +00004306 }
Argyrios Kyrtzidis402dbbb2010-10-28 07:38:42 +00004307
4308 case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION:
Vassil Vassilev7d264622017-06-30 22:40:17 +00004309 // It will be added to the template's lazy specialization set.
4310 PendingLazySpecializationIDs.push_back(ReadDeclID());
Sebastian Redlfa1f3702011-04-24 16:28:13 +00004311 break;
4312
4313 case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: {
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00004314 auto *Anon = ReadDeclAs<NamespaceDecl>();
David L. Jonesc4808b9e2016-12-15 20:53:26 +00004315
Douglas Gregor540fd812012-01-09 18:07:24 +00004316 // Each module has its own anonymous namespace, which is disjoint from
4317 // any other module's anonymous namespaces, so don't attach the anonymous
4318 // namespace at all.
David L. Jonesc4808b9e2016-12-15 20:53:26 +00004319 if (!Record.isModule()) {
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00004320 if (auto *TU = dyn_cast<TranslationUnitDecl>(D))
Douglas Gregor540fd812012-01-09 18:07:24 +00004321 TU->setAnonymousNamespace(Anon);
4322 else
4323 cast<NamespaceDecl>(D)->setAnonymousNamespace(Anon);
4324 }
Sebastian Redlfa1f3702011-04-24 16:28:13 +00004325 break;
4326 }
Sebastian Redl2ac2c722011-04-29 08:19:30 +00004327
Richard Smith891fc7f2017-12-05 01:31:47 +00004328 case UPD_CXX_ADDED_VAR_DEFINITION: {
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00004329 auto *VD = cast<VarDecl>(D);
Richard Smithf5017592017-11-02 01:06:00 +00004330 VD->NonParmVarDeclBits.IsInline = Record.readInt();
4331 VD->NonParmVarDeclBits.IsInlineSpecified = Record.readInt();
Richard Smith05a21352017-06-22 22:18:46 +00004332 uint64_t Val = Record.readInt();
4333 if (Val && !VD->getInit()) {
4334 VD->setInit(Record.readExpr());
4335 if (Val > 1) { // IsInitKnownICE = 1, IsInitNotICE = 2, IsInitICE = 3
4336 EvaluatedStmt *Eval = VD->ensureEvaluatedStmt();
4337 Eval->CheckedICE = true;
4338 Eval->IsICE = Val == 3;
4339 }
4340 }
Sebastian Redl2ac2c722011-04-29 08:19:30 +00004341 break;
Richard Smith05a21352017-06-22 22:18:46 +00004342 }
Richard Smith1fa5d642013-05-11 05:45:24 +00004343
Richard Smith891fc7f2017-12-05 01:31:47 +00004344 case UPD_CXX_POINT_OF_INSTANTIATION: {
4345 SourceLocation POI = Record.readSourceLocation();
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00004346 if (auto *VTSD = dyn_cast<VarTemplateSpecializationDecl>(D)) {
Richard Smith891fc7f2017-12-05 01:31:47 +00004347 VTSD->setPointOfInstantiation(POI);
4348 } else if (auto *VD = dyn_cast<VarDecl>(D)) {
4349 VD->getMemberSpecializationInfo()->setPointOfInstantiation(POI);
4350 } else {
4351 auto *FD = cast<FunctionDecl>(D);
4352 if (auto *FTSInfo = FD->TemplateOrSpecialization
4353 .dyn_cast<FunctionTemplateSpecializationInfo *>())
4354 FTSInfo->setPointOfInstantiation(POI);
4355 else
4356 FD->TemplateOrSpecialization.get<MemberSpecializationInfo *>()
4357 ->setPointOfInstantiation(POI);
4358 }
4359 break;
4360 }
4361
John McCall32791cc2016-01-06 22:34:54 +00004362 case UPD_CXX_INSTANTIATED_DEFAULT_ARGUMENT: {
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00004363 auto *Param = cast<ParmVarDecl>(D);
John McCall32791cc2016-01-06 22:34:54 +00004364
4365 // We have to read the default argument regardless of whether we use it
4366 // so that hypothetical further update records aren't messed up.
4367 // TODO: Add a function to skip over the next expr record.
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00004368 auto *DefaultArg = Record.readExpr();
John McCall32791cc2016-01-06 22:34:54 +00004369
4370 // Only apply the update if the parameter still has an uninstantiated
4371 // default argument.
4372 if (Param->hasUninstantiatedDefaultArg())
4373 Param->setDefaultArg(DefaultArg);
4374 break;
4375 }
4376
Richard Smith4b054b22016-08-24 21:25:37 +00004377 case UPD_CXX_INSTANTIATED_DEFAULT_MEMBER_INITIALIZER: {
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00004378 auto *FD = cast<FieldDecl>(D);
4379 auto *DefaultInit = Record.readExpr();
Richard Smith4b054b22016-08-24 21:25:37 +00004380
4381 // Only apply the update if the field still has an uninstantiated
4382 // default member initializer.
4383 if (FD->hasInClassInitializer() && !FD->getInClassInitializer()) {
4384 if (DefaultInit)
4385 FD->setInClassInitializer(DefaultInit);
4386 else
4387 // Instantiation failed. We can get here if we serialized an AST for
4388 // an invalid program.
4389 FD->removeInClassInitializer();
4390 }
4391 break;
4392 }
4393
Richard Smith4d235792014-08-07 18:53:08 +00004394 case UPD_CXX_ADDED_FUNCTION_DEFINITION: {
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00004395 auto *FD = cast<FunctionDecl>(D);
Daniel Jasper4a6d5b72017-10-11 07:47:54 +00004396 if (Reader.PendingBodies[FD]) {
4397 // FIXME: Maybe check for ODR violations.
4398 // It's safe to stop now because this update record is always last.
4399 return;
4400 }
4401
David L. Jonesbe1557a2016-12-21 00:17:49 +00004402 if (Record.readInt()) {
Richard Smith195d8ef2014-05-29 03:15:31 +00004403 // Maintain AST consistency: any later redeclarations of this function
4404 // are inline if this one is. (We might have merged another declaration
4405 // into this one.)
Richard Smithd6db68c2014-08-07 20:58:41 +00004406 forAllLaterRedecls(FD, [](FunctionDecl *FD) {
4407 FD->setImplicitlyInline();
4408 });
Richard Smith195d8ef2014-05-29 03:15:31 +00004409 }
David L. Jonesc4808b9e2016-12-15 20:53:26 +00004410 FD->setInnerLocStart(ReadSourceLocation());
David Blaikieac4345c2017-02-12 18:45:31 +00004411 ReadFunctionDefinition(FD);
David L. Jonesbe1557a2016-12-21 00:17:49 +00004412 assert(Record.getIdx() == Record.size() && "lazy body must be last");
Richard Smithd28ac5b2014-03-22 23:33:22 +00004413 break;
4414 }
4415
Richard Smithcd45dbc2014-04-19 03:48:30 +00004416 case UPD_CXX_INSTANTIATED_CLASS_DEFINITION: {
4417 auto *RD = cast<CXXRecordDecl>(D);
Richard Smithb6483992016-05-17 22:44:15 +00004418 auto *OldDD = RD->getCanonicalDecl()->DefinitionData;
Richard Smith2a9e5c52015-02-03 03:32:14 +00004419 bool HadRealDefinition =
Richard Smith7483d202015-02-04 01:23:46 +00004420 OldDD && (OldDD->Definition != RD ||
4421 !Reader.PendingFakeDefinitionData.count(OldDD));
Akira Hatanakafcbe17c2018-03-28 21:13:14 +00004422 RD->setParamDestroyedInCallee(Record.readInt());
Akira Hatanakae6313ac2018-04-09 22:48:22 +00004423 RD->setArgPassingRestrictions(
4424 (RecordDecl::ArgPassingKind)Record.readInt());
Richard Smith2a9e5c52015-02-03 03:32:14 +00004425 ReadCXXRecordDefinition(RD, /*Update*/true);
4426
Richard Smithcd45dbc2014-04-19 03:48:30 +00004427 // Visible update is handled separately.
David L. Jonesc4808b9e2016-12-15 20:53:26 +00004428 uint64_t LexicalOffset = ReadLocalOffset();
Richard Smith8a639892015-01-24 01:07:20 +00004429 if (!HadRealDefinition && LexicalOffset) {
David L. Jonesb6a8f022016-12-21 04:34:52 +00004430 Record.readLexicalDeclContextStorage(LexicalOffset, RD);
Richard Smith2a9e5c52015-02-03 03:32:14 +00004431 Reader.PendingFakeDefinitionData.erase(OldDD);
Richard Smithcd45dbc2014-04-19 03:48:30 +00004432 }
4433
David L. Jonesbe1557a2016-12-21 00:17:49 +00004434 auto TSK = (TemplateSpecializationKind)Record.readInt();
David L. Jonesc4808b9e2016-12-15 20:53:26 +00004435 SourceLocation POI = ReadSourceLocation();
Richard Smithcd45dbc2014-04-19 03:48:30 +00004436 if (MemberSpecializationInfo *MSInfo =
4437 RD->getMemberSpecializationInfo()) {
4438 MSInfo->setTemplateSpecializationKind(TSK);
4439 MSInfo->setPointOfInstantiation(POI);
4440 } else {
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00004441 auto *Spec = cast<ClassTemplateSpecializationDecl>(RD);
Richard Smithcd45dbc2014-04-19 03:48:30 +00004442 Spec->setTemplateSpecializationKind(TSK);
4443 Spec->setPointOfInstantiation(POI);
Richard Smithdf352052014-05-22 20:59:29 +00004444
David L. Jonesbe1557a2016-12-21 00:17:49 +00004445 if (Record.readInt()) {
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00004446 auto *PartialSpec =
David L. Jonesc4808b9e2016-12-15 20:53:26 +00004447 ReadDeclAs<ClassTemplatePartialSpecializationDecl>();
Richard Smithdf352052014-05-22 20:59:29 +00004448 SmallVector<TemplateArgument, 8> TemplArgs;
David L. Jonesb6a8f022016-12-21 04:34:52 +00004449 Record.readTemplateArgumentList(TemplArgs);
Richard Smithdf352052014-05-22 20:59:29 +00004450 auto *TemplArgList = TemplateArgumentList::CreateCopy(
David Majnemer8b622692016-07-03 21:17:51 +00004451 Reader.getContext(), TemplArgs);
Richard Smith72544f82014-08-14 03:30:27 +00004452
4453 // FIXME: If we already have a partial specialization set,
4454 // check that it matches.
4455 if (!Spec->getSpecializedTemplateOrPartial()
4456 .is<ClassTemplatePartialSpecializationDecl *>())
4457 Spec->setInstantiationOf(PartialSpec, TemplArgList);
Richard Smithdf352052014-05-22 20:59:29 +00004458 }
Richard Smithcd45dbc2014-04-19 03:48:30 +00004459 }
4460
David L. Jonesbe1557a2016-12-21 00:17:49 +00004461 RD->setTagKind((TagTypeKind)Record.readInt());
David L. Jonesc4808b9e2016-12-15 20:53:26 +00004462 RD->setLocation(ReadSourceLocation());
4463 RD->setLocStart(ReadSourceLocation());
4464 RD->setBraceRange(ReadSourceRange());
Richard Smithcd45dbc2014-04-19 03:48:30 +00004465
David L. Jonesbe1557a2016-12-21 00:17:49 +00004466 if (Record.readInt()) {
Richard Smithcd45dbc2014-04-19 03:48:30 +00004467 AttrVec Attrs;
David L. Jonesb6a8f022016-12-21 04:34:52 +00004468 Record.readAttributes(Attrs);
Richard Smith842e46e2016-10-26 02:31:56 +00004469 // If the declaration already has attributes, we assume that some other
4470 // AST file already loaded them.
4471 if (!D->hasAttrs())
4472 D->setAttrsImpl(Attrs, Reader.getContext());
Richard Smithcd45dbc2014-04-19 03:48:30 +00004473 }
4474 break;
4475 }
4476
Richard Smithf8134002015-03-10 01:41:22 +00004477 case UPD_CXX_RESOLVED_DTOR_DELETE: {
4478 // Set the 'operator delete' directly to avoid emitting another update
4479 // record.
David L. Jonesc4808b9e2016-12-15 20:53:26 +00004480 auto *Del = ReadDeclAs<FunctionDecl>();
Richard Smithf8134002015-03-10 01:41:22 +00004481 auto *First = cast<CXXDestructorDecl>(D->getCanonicalDecl());
Richard Smith5b349582017-10-13 01:55:36 +00004482 auto *ThisArg = Record.readExpr();
Richard Smithf8134002015-03-10 01:41:22 +00004483 // FIXME: Check consistency if we have an old and new operator delete.
Richard Smith5b349582017-10-13 01:55:36 +00004484 if (!First->OperatorDelete) {
Richard Smithf8134002015-03-10 01:41:22 +00004485 First->OperatorDelete = Del;
Richard Smith5b349582017-10-13 01:55:36 +00004486 First->OperatorDeleteThisArg = ThisArg;
4487 }
Richard Smithf8134002015-03-10 01:41:22 +00004488 break;
4489 }
4490
Richard Smith564417a2014-03-20 21:47:22 +00004491 case UPD_CXX_RESOLVED_EXCEPTION_SPEC: {
Richard Smith8acb4282014-07-31 21:57:55 +00004492 FunctionProtoType::ExceptionSpecInfo ESI;
Richard Smith6de7a242014-07-31 23:46:44 +00004493 SmallVector<QualType, 8> ExceptionStorage;
David L. Jonesbe1557a2016-12-21 00:17:49 +00004494 Record.readExceptionSpec(ExceptionStorage, ESI);
Richard Smith9e2341d2015-03-23 03:25:59 +00004495
4496 // Update this declaration's exception specification, if needed.
4497 auto *FD = cast<FunctionDecl>(D);
4498 auto *FPT = FD->getType()->castAs<FunctionProtoType>();
4499 // FIXME: If the exception specification is already present, check that it
4500 // matches.
4501 if (isUnresolvedExceptionSpec(FPT->getExceptionSpecType())) {
Richard Smithdbafb6c2017-06-29 23:23:46 +00004502 FD->setType(Reader.getContext().getFunctionType(
Richard Smith6de7a242014-07-31 23:46:44 +00004503 FPT->getReturnType(), FPT->getParamTypes(),
4504 FPT->getExtProtoInfo().withExceptionSpec(ESI)));
Richard Smith9e2341d2015-03-23 03:25:59 +00004505
4506 // When we get to the end of deserializing, see if there are other decls
4507 // that we need to propagate this exception specification onto.
4508 Reader.PendingExceptionSpecUpdates.insert(
4509 std::make_pair(FD->getCanonicalDecl(), FD));
Richard Smith6de7a242014-07-31 23:46:44 +00004510 }
Richard Smith564417a2014-03-20 21:47:22 +00004511 break;
4512 }
4513
Richard Smith1fa5d642013-05-11 05:45:24 +00004514 case UPD_CXX_DEDUCED_RETURN_TYPE: {
Richard Smitha62d1982018-08-03 01:00:01 +00004515 auto *FD = cast<FunctionDecl>(D);
David L. Jonesbe1557a2016-12-21 00:17:49 +00004516 QualType DeducedResultType = Record.readType();
Richard Smitha62d1982018-08-03 01:00:01 +00004517 Reader.PendingDeducedTypeUpdates.insert(
4518 {FD->getCanonicalDecl(), DeducedResultType});
Richard Smith1fa5d642013-05-11 05:45:24 +00004519 break;
4520 }
Eli Friedman276dd182013-09-05 00:02:25 +00004521
Eugene Zelenkoe69b33f2018-04-11 20:57:28 +00004522 case UPD_DECL_MARKED_USED:
Richard Smith675d2792014-06-16 20:26:19 +00004523 // Maintain AST consistency: any later redeclarations are used too.
Richard Smithdbafb6c2017-06-29 23:23:46 +00004524 D->markUsed(Reader.getContext());
Eli Friedman276dd182013-09-05 00:02:25 +00004525 break;
Richard Smith5652c0f2014-03-21 01:48:23 +00004526
4527 case UPD_MANGLING_NUMBER:
Richard Smithdbafb6c2017-06-29 23:23:46 +00004528 Reader.getContext().setManglingNumber(cast<NamedDecl>(D),
4529 Record.readInt());
Richard Smith5652c0f2014-03-21 01:48:23 +00004530 break;
4531
4532 case UPD_STATIC_LOCAL_NUMBER:
Richard Smithdbafb6c2017-06-29 23:23:46 +00004533 Reader.getContext().setStaticLocalNumber(cast<VarDecl>(D),
4534 Record.readInt());
Richard Smith5652c0f2014-03-21 01:48:23 +00004535 break;
Richard Smith65ebb4a2015-03-26 04:09:53 +00004536
Alexey Bataev97720002014-11-11 04:05:39 +00004537 case UPD_DECL_MARKED_OPENMP_THREADPRIVATE:
Erich Keane6a24e802019-09-13 17:39:31 +00004538 D->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit(
4539 Reader.getContext(), ReadSourceRange(),
4540 AttributeCommonInfo::AS_Pragma));
Alexey Bataev97720002014-11-11 04:05:39 +00004541 break;
Richard Smith65ebb4a2015-03-26 04:09:53 +00004542
Alexey Bataev27ef9512019-03-20 20:14:22 +00004543 case UPD_DECL_MARKED_OPENMP_ALLOCATE: {
4544 auto AllocatorKind =
4545 static_cast<OMPAllocateDeclAttr::AllocatorTypeTy>(Record.readInt());
4546 Expr *Allocator = Record.readExpr();
4547 SourceRange SR = ReadSourceRange();
Alexey Bataev9cc10fc2019-03-12 18:52:33 +00004548 D->addAttr(OMPAllocateDeclAttr::CreateImplicit(
Erich Keane6a24e802019-09-13 17:39:31 +00004549 Reader.getContext(), AllocatorKind, Allocator, SR,
4550 AttributeCommonInfo::AS_Pragma));
Alexey Bataev25ed0c02019-03-07 17:54:44 +00004551 break;
Alexey Bataev27ef9512019-03-20 20:14:22 +00004552 }
Alexey Bataev25ed0c02019-03-07 17:54:44 +00004553
Alex Denisovfde64952015-06-26 05:28:36 +00004554 case UPD_DECL_EXPORTED: {
David L. Jonesc4808b9e2016-12-15 20:53:26 +00004555 unsigned SubmoduleID = readSubmoduleID();
Richard Smithbeb44782015-06-20 01:05:19 +00004556 auto *Exported = cast<NamedDecl>(D);
Richard Smith65ebb4a2015-03-26 04:09:53 +00004557 Module *Owner = SubmoduleID ? Reader.getSubmodule(SubmoduleID) : nullptr;
Richard Smith13897eb2018-09-12 23:37:00 +00004558 Reader.getContext().mergeDefinitionIntoModule(Exported, Owner);
4559 Reader.PendingMergedDefinitionsToDeduplicate.insert(Exported);
Richard Smith65ebb4a2015-03-26 04:09:53 +00004560 break;
Argyrios Kyrtzidisd170d842010-10-24 17:26:50 +00004561 }
Alex Denisovfde64952015-06-26 05:28:36 +00004562
Alexey Bataev729e2422019-08-23 16:11:14 +00004563 case UPD_DECL_MARKED_OPENMP_DECLARETARGET: {
4564 OMPDeclareTargetDeclAttr::MapTypeTy MapType =
4565 static_cast<OMPDeclareTargetDeclAttr::MapTypeTy>(Record.readInt());
4566 OMPDeclareTargetDeclAttr::DevTypeTy DevType =
4567 static_cast<OMPDeclareTargetDeclAttr::DevTypeTy>(Record.readInt());
Alexey Bataevd01b7492018-08-15 19:45:12 +00004568 D->addAttr(OMPDeclareTargetDeclAttr::CreateImplicit(
Erich Keane6a24e802019-09-13 17:39:31 +00004569 Reader.getContext(), MapType, DevType, ReadSourceRange(),
4570 AttributeCommonInfo::AS_Pragma));
Alexey Bataevd01b7492018-08-15 19:45:12 +00004571 break;
Alexey Bataev729e2422019-08-23 16:11:14 +00004572 }
Alexey Bataevd01b7492018-08-15 19:45:12 +00004573
Alex Denisovfde64952015-06-26 05:28:36 +00004574 case UPD_ADDED_ATTR_TO_RECORD:
4575 AttrVec Attrs;
David L. Jonesb6a8f022016-12-21 04:34:52 +00004576 Record.readAttributes(Attrs);
Alex Denisovfde64952015-06-26 05:28:36 +00004577 assert(Attrs.size() == 1);
4578 D->addAttr(Attrs[0]);
4579 break;
4580 }
Argyrios Kyrtzidisd170d842010-10-24 17:26:50 +00004581 }
Argyrios Kyrtzidis65ad5692010-10-24 17:26:36 +00004582}