File: | build/source/clang/lib/Serialization/ASTReaderDecl.cpp |
Warning: | line 485, column 9 Called C++ object pointer is null |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | //===- ASTReaderDecl.cpp - Decl Deserialization ---------------------------===// | |||
2 | // | |||
3 | // 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 | |||
6 | // | |||
7 | //===----------------------------------------------------------------------===// | |||
8 | // | |||
9 | // This file implements the ASTReader::readDeclRecord method, which is the | |||
10 | // entrypoint for loading a decl. | |||
11 | // | |||
12 | //===----------------------------------------------------------------------===// | |||
13 | ||||
14 | #include "ASTCommon.h" | |||
15 | #include "ASTReaderInternals.h" | |||
16 | #include "clang/AST/ASTContext.h" | |||
17 | #include "clang/AST/ASTStructuralEquivalence.h" | |||
18 | #include "clang/AST/Attr.h" | |||
19 | #include "clang/AST/AttrIterator.h" | |||
20 | #include "clang/AST/Decl.h" | |||
21 | #include "clang/AST/DeclBase.h" | |||
22 | #include "clang/AST/DeclCXX.h" | |||
23 | #include "clang/AST/DeclFriend.h" | |||
24 | #include "clang/AST/DeclObjC.h" | |||
25 | #include "clang/AST/DeclOpenMP.h" | |||
26 | #include "clang/AST/DeclTemplate.h" | |||
27 | #include "clang/AST/DeclVisitor.h" | |||
28 | #include "clang/AST/DeclarationName.h" | |||
29 | #include "clang/AST/Expr.h" | |||
30 | #include "clang/AST/ExternalASTSource.h" | |||
31 | #include "clang/AST/LambdaCapture.h" | |||
32 | #include "clang/AST/NestedNameSpecifier.h" | |||
33 | #include "clang/AST/OpenMPClause.h" | |||
34 | #include "clang/AST/Redeclarable.h" | |||
35 | #include "clang/AST/Stmt.h" | |||
36 | #include "clang/AST/TemplateBase.h" | |||
37 | #include "clang/AST/Type.h" | |||
38 | #include "clang/AST/UnresolvedSet.h" | |||
39 | #include "clang/Basic/AttrKinds.h" | |||
40 | #include "clang/Basic/DiagnosticSema.h" | |||
41 | #include "clang/Basic/ExceptionSpecificationType.h" | |||
42 | #include "clang/Basic/IdentifierTable.h" | |||
43 | #include "clang/Basic/LLVM.h" | |||
44 | #include "clang/Basic/Lambda.h" | |||
45 | #include "clang/Basic/LangOptions.h" | |||
46 | #include "clang/Basic/Linkage.h" | |||
47 | #include "clang/Basic/Module.h" | |||
48 | #include "clang/Basic/PragmaKinds.h" | |||
49 | #include "clang/Basic/SourceLocation.h" | |||
50 | #include "clang/Basic/Specifiers.h" | |||
51 | #include "clang/Sema/IdentifierResolver.h" | |||
52 | #include "clang/Serialization/ASTBitCodes.h" | |||
53 | #include "clang/Serialization/ASTRecordReader.h" | |||
54 | #include "clang/Serialization/ContinuousRangeMap.h" | |||
55 | #include "clang/Serialization/ModuleFile.h" | |||
56 | #include "llvm/ADT/DenseMap.h" | |||
57 | #include "llvm/ADT/FoldingSet.h" | |||
58 | #include "llvm/ADT/STLExtras.h" | |||
59 | #include "llvm/ADT/SmallPtrSet.h" | |||
60 | #include "llvm/ADT/SmallVector.h" | |||
61 | #include "llvm/ADT/iterator_range.h" | |||
62 | #include "llvm/Bitstream/BitstreamReader.h" | |||
63 | #include "llvm/Support/Casting.h" | |||
64 | #include "llvm/Support/ErrorHandling.h" | |||
65 | #include "llvm/Support/SaveAndRestore.h" | |||
66 | #include <algorithm> | |||
67 | #include <cassert> | |||
68 | #include <cstdint> | |||
69 | #include <cstring> | |||
70 | #include <string> | |||
71 | #include <utility> | |||
72 | ||||
73 | using namespace clang; | |||
74 | using namespace serialization; | |||
75 | ||||
76 | //===----------------------------------------------------------------------===// | |||
77 | // Declaration deserialization | |||
78 | //===----------------------------------------------------------------------===// | |||
79 | ||||
80 | namespace clang { | |||
81 | ||||
82 | class ASTDeclReader : public DeclVisitor<ASTDeclReader, void> { | |||
83 | ASTReader &Reader; | |||
84 | ASTRecordReader &Record; | |||
85 | ASTReader::RecordLocation Loc; | |||
86 | const DeclID ThisDeclID; | |||
87 | const SourceLocation ThisDeclLoc; | |||
88 | ||||
89 | using RecordData = ASTReader::RecordData; | |||
90 | ||||
91 | TypeID DeferredTypeID = 0; | |||
92 | unsigned AnonymousDeclNumber; | |||
93 | GlobalDeclID NamedDeclForTagDecl = 0; | |||
94 | IdentifierInfo *TypedefNameForLinkage = nullptr; | |||
95 | ||||
96 | bool HasPendingBody = false; | |||
97 | ||||
98 | ///A flag to carry the information for a decl from the entity is | |||
99 | /// used. We use it to delay the marking of the canonical decl as used until | |||
100 | /// the entire declaration is deserialized and merged. | |||
101 | bool IsDeclMarkedUsed = false; | |||
102 | ||||
103 | uint64_t GetCurrentCursorOffset(); | |||
104 | ||||
105 | uint64_t ReadLocalOffset() { | |||
106 | uint64_t LocalOffset = Record.readInt(); | |||
107 | assert(LocalOffset < Loc.Offset && "offset point after current record")(static_cast <bool> (LocalOffset < Loc.Offset && "offset point after current record") ? void (0) : __assert_fail ("LocalOffset < Loc.Offset && \"offset point after current record\"" , "clang/lib/Serialization/ASTReaderDecl.cpp", 107, __extension__ __PRETTY_FUNCTION__)); | |||
108 | return LocalOffset ? Loc.Offset - LocalOffset : 0; | |||
109 | } | |||
110 | ||||
111 | uint64_t ReadGlobalOffset() { | |||
112 | uint64_t Local = ReadLocalOffset(); | |||
113 | return Local ? Record.getGlobalBitOffset(Local) : 0; | |||
114 | } | |||
115 | ||||
116 | SourceLocation readSourceLocation() { | |||
117 | return Record.readSourceLocation(); | |||
118 | } | |||
119 | ||||
120 | SourceRange readSourceRange() { | |||
121 | return Record.readSourceRange(); | |||
122 | } | |||
123 | ||||
124 | TypeSourceInfo *readTypeSourceInfo() { | |||
125 | return Record.readTypeSourceInfo(); | |||
126 | } | |||
127 | ||||
128 | serialization::DeclID readDeclID() { | |||
129 | return Record.readDeclID(); | |||
130 | } | |||
131 | ||||
132 | std::string readString() { | |||
133 | return Record.readString(); | |||
134 | } | |||
135 | ||||
136 | void readDeclIDList(SmallVectorImpl<DeclID> &IDs) { | |||
137 | for (unsigned I = 0, Size = Record.readInt(); I != Size; ++I) | |||
138 | IDs.push_back(readDeclID()); | |||
139 | } | |||
140 | ||||
141 | Decl *readDecl() { | |||
142 | return Record.readDecl(); | |||
143 | } | |||
144 | ||||
145 | template<typename T> | |||
146 | T *readDeclAs() { | |||
147 | return Record.readDeclAs<T>(); | |||
148 | } | |||
149 | ||||
150 | serialization::SubmoduleID readSubmoduleID() { | |||
151 | if (Record.getIdx() == Record.size()) | |||
152 | return 0; | |||
153 | ||||
154 | return Record.getGlobalSubmoduleID(Record.readInt()); | |||
155 | } | |||
156 | ||||
157 | Module *readModule() { | |||
158 | return Record.getSubmodule(readSubmoduleID()); | |||
159 | } | |||
160 | ||||
161 | void ReadCXXRecordDefinition(CXXRecordDecl *D, bool Update); | |||
162 | void ReadCXXDefinitionData(struct CXXRecordDecl::DefinitionData &Data, | |||
163 | const CXXRecordDecl *D); | |||
164 | void MergeDefinitionData(CXXRecordDecl *D, | |||
165 | struct CXXRecordDecl::DefinitionData &&NewDD); | |||
166 | void ReadObjCDefinitionData(struct ObjCInterfaceDecl::DefinitionData &Data); | |||
167 | void MergeDefinitionData(ObjCInterfaceDecl *D, | |||
168 | struct ObjCInterfaceDecl::DefinitionData &&NewDD); | |||
169 | void ReadObjCDefinitionData(struct ObjCProtocolDecl::DefinitionData &Data); | |||
170 | void MergeDefinitionData(ObjCProtocolDecl *D, | |||
171 | struct ObjCProtocolDecl::DefinitionData &&NewDD); | |||
172 | ||||
173 | static DeclContext *getPrimaryDCForAnonymousDecl(DeclContext *LexicalDC); | |||
174 | ||||
175 | static NamedDecl *getAnonymousDeclForMerging(ASTReader &Reader, | |||
176 | DeclContext *DC, | |||
177 | unsigned Index); | |||
178 | static void setAnonymousDeclForMerging(ASTReader &Reader, DeclContext *DC, | |||
179 | unsigned Index, NamedDecl *D); | |||
180 | ||||
181 | /// Results from loading a RedeclarableDecl. | |||
182 | class RedeclarableResult { | |||
183 | Decl *MergeWith; | |||
184 | GlobalDeclID FirstID; | |||
185 | bool IsKeyDecl; | |||
186 | ||||
187 | public: | |||
188 | RedeclarableResult(Decl *MergeWith, GlobalDeclID FirstID, bool IsKeyDecl) | |||
189 | : MergeWith(MergeWith), FirstID(FirstID), IsKeyDecl(IsKeyDecl) {} | |||
190 | ||||
191 | /// Retrieve the first ID. | |||
192 | GlobalDeclID getFirstID() const { return FirstID; } | |||
193 | ||||
194 | /// Is this declaration a key declaration? | |||
195 | bool isKeyDecl() const { return IsKeyDecl; } | |||
196 | ||||
197 | /// Get a known declaration that this should be merged with, if | |||
198 | /// any. | |||
199 | Decl *getKnownMergeTarget() const { return MergeWith; } | |||
200 | }; | |||
201 | ||||
202 | /// Class used to capture the result of searching for an existing | |||
203 | /// declaration of a specific kind and name, along with the ability | |||
204 | /// to update the place where this result was found (the declaration | |||
205 | /// chain hanging off an identifier or the DeclContext we searched in) | |||
206 | /// if requested. | |||
207 | class FindExistingResult { | |||
208 | ASTReader &Reader; | |||
209 | NamedDecl *New = nullptr; | |||
210 | NamedDecl *Existing = nullptr; | |||
211 | bool AddResult = false; | |||
212 | unsigned AnonymousDeclNumber = 0; | |||
213 | IdentifierInfo *TypedefNameForLinkage = nullptr; | |||
214 | ||||
215 | public: | |||
216 | FindExistingResult(ASTReader &Reader) : Reader(Reader) {} | |||
217 | ||||
218 | FindExistingResult(ASTReader &Reader, NamedDecl *New, NamedDecl *Existing, | |||
219 | unsigned AnonymousDeclNumber, | |||
220 | IdentifierInfo *TypedefNameForLinkage) | |||
221 | : Reader(Reader), New(New), Existing(Existing), AddResult(true), | |||
222 | AnonymousDeclNumber(AnonymousDeclNumber), | |||
223 | TypedefNameForLinkage(TypedefNameForLinkage) {} | |||
224 | ||||
225 | FindExistingResult(FindExistingResult &&Other) | |||
226 | : Reader(Other.Reader), New(Other.New), Existing(Other.Existing), | |||
227 | AddResult(Other.AddResult), | |||
228 | AnonymousDeclNumber(Other.AnonymousDeclNumber), | |||
229 | TypedefNameForLinkage(Other.TypedefNameForLinkage) { | |||
230 | Other.AddResult = false; | |||
231 | } | |||
232 | ||||
233 | FindExistingResult &operator=(FindExistingResult &&) = delete; | |||
234 | ~FindExistingResult(); | |||
235 | ||||
236 | /// Suppress the addition of this result into the known set of | |||
237 | /// names. | |||
238 | void suppress() { AddResult = false; } | |||
239 | ||||
240 | operator NamedDecl*() const { return Existing; } | |||
241 | ||||
242 | template<typename T> | |||
243 | operator T*() const { return dyn_cast_or_null<T>(Existing); } | |||
244 | }; | |||
245 | ||||
246 | static DeclContext *getPrimaryContextForMerging(ASTReader &Reader, | |||
247 | DeclContext *DC); | |||
248 | FindExistingResult findExisting(NamedDecl *D); | |||
249 | ||||
250 | public: | |||
251 | ASTDeclReader(ASTReader &Reader, ASTRecordReader &Record, | |||
252 | ASTReader::RecordLocation Loc, | |||
253 | DeclID thisDeclID, SourceLocation ThisDeclLoc) | |||
254 | : Reader(Reader), Record(Record), Loc(Loc), ThisDeclID(thisDeclID), | |||
255 | ThisDeclLoc(ThisDeclLoc) {} | |||
256 | ||||
257 | template <typename T> static | |||
258 | void AddLazySpecializations(T *D, | |||
259 | SmallVectorImpl<serialization::DeclID>& IDs) { | |||
260 | if (IDs.empty()) | |||
261 | return; | |||
262 | ||||
263 | // FIXME: We should avoid this pattern of getting the ASTContext. | |||
264 | ASTContext &C = D->getASTContext(); | |||
265 | ||||
266 | auto *&LazySpecializations = D->getCommonPtr()->LazySpecializations; | |||
267 | ||||
268 | if (auto &Old = LazySpecializations) { | |||
269 | IDs.insert(IDs.end(), Old + 1, Old + 1 + Old[0]); | |||
270 | llvm::sort(IDs); | |||
271 | IDs.erase(std::unique(IDs.begin(), IDs.end()), IDs.end()); | |||
272 | } | |||
273 | ||||
274 | auto *Result = new (C) serialization::DeclID[1 + IDs.size()]; | |||
275 | *Result = IDs.size(); | |||
276 | std::copy(IDs.begin(), IDs.end(), Result + 1); | |||
277 | ||||
278 | LazySpecializations = Result; | |||
279 | } | |||
280 | ||||
281 | template <typename DeclT> | |||
282 | static Decl *getMostRecentDeclImpl(Redeclarable<DeclT> *D); | |||
283 | static Decl *getMostRecentDeclImpl(...); | |||
284 | static Decl *getMostRecentDecl(Decl *D); | |||
285 | ||||
286 | static void mergeInheritableAttributes(ASTReader &Reader, Decl *D, | |||
287 | Decl *Previous); | |||
288 | ||||
289 | template <typename DeclT> | |||
290 | static void attachPreviousDeclImpl(ASTReader &Reader, | |||
291 | Redeclarable<DeclT> *D, Decl *Previous, | |||
292 | Decl *Canon); | |||
293 | static void attachPreviousDeclImpl(ASTReader &Reader, ...); | |||
294 | static void attachPreviousDecl(ASTReader &Reader, Decl *D, Decl *Previous, | |||
295 | Decl *Canon); | |||
296 | ||||
297 | template <typename DeclT> | |||
298 | static void attachLatestDeclImpl(Redeclarable<DeclT> *D, Decl *Latest); | |||
299 | static void attachLatestDeclImpl(...); | |||
300 | static void attachLatestDecl(Decl *D, Decl *latest); | |||
301 | ||||
302 | template <typename DeclT> | |||
303 | static void markIncompleteDeclChainImpl(Redeclarable<DeclT> *D); | |||
304 | static void markIncompleteDeclChainImpl(...); | |||
305 | ||||
306 | /// Determine whether this declaration has a pending body. | |||
307 | bool hasPendingBody() const { return HasPendingBody; } | |||
308 | ||||
309 | void ReadFunctionDefinition(FunctionDecl *FD); | |||
310 | void Visit(Decl *D); | |||
311 | ||||
312 | void UpdateDecl(Decl *D, SmallVectorImpl<serialization::DeclID> &); | |||
313 | ||||
314 | static void setNextObjCCategory(ObjCCategoryDecl *Cat, | |||
315 | ObjCCategoryDecl *Next) { | |||
316 | Cat->NextClassCategory = Next; | |||
317 | } | |||
318 | ||||
319 | void VisitDecl(Decl *D); | |||
320 | void VisitPragmaCommentDecl(PragmaCommentDecl *D); | |||
321 | void VisitPragmaDetectMismatchDecl(PragmaDetectMismatchDecl *D); | |||
322 | void VisitTranslationUnitDecl(TranslationUnitDecl *TU); | |||
323 | void VisitNamedDecl(NamedDecl *ND); | |||
324 | void VisitLabelDecl(LabelDecl *LD); | |||
325 | void VisitNamespaceDecl(NamespaceDecl *D); | |||
326 | void VisitHLSLBufferDecl(HLSLBufferDecl *D); | |||
327 | void VisitUsingDirectiveDecl(UsingDirectiveDecl *D); | |||
328 | void VisitNamespaceAliasDecl(NamespaceAliasDecl *D); | |||
329 | void VisitTypeDecl(TypeDecl *TD); | |||
330 | RedeclarableResult VisitTypedefNameDecl(TypedefNameDecl *TD); | |||
331 | void VisitTypedefDecl(TypedefDecl *TD); | |||
332 | void VisitTypeAliasDecl(TypeAliasDecl *TD); | |||
333 | void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D); | |||
334 | void VisitUnresolvedUsingIfExistsDecl(UnresolvedUsingIfExistsDecl *D); | |||
335 | RedeclarableResult VisitTagDecl(TagDecl *TD); | |||
336 | void VisitEnumDecl(EnumDecl *ED); | |||
337 | RedeclarableResult VisitRecordDeclImpl(RecordDecl *RD); | |||
338 | void VisitRecordDecl(RecordDecl *RD); | |||
339 | RedeclarableResult VisitCXXRecordDeclImpl(CXXRecordDecl *D); | |||
340 | void VisitCXXRecordDecl(CXXRecordDecl *D) { VisitCXXRecordDeclImpl(D); } | |||
341 | RedeclarableResult VisitClassTemplateSpecializationDeclImpl( | |||
342 | ClassTemplateSpecializationDecl *D); | |||
343 | ||||
344 | void VisitClassTemplateSpecializationDecl( | |||
345 | ClassTemplateSpecializationDecl *D) { | |||
346 | VisitClassTemplateSpecializationDeclImpl(D); | |||
347 | } | |||
348 | ||||
349 | void VisitClassTemplatePartialSpecializationDecl( | |||
350 | ClassTemplatePartialSpecializationDecl *D); | |||
351 | void VisitClassScopeFunctionSpecializationDecl( | |||
352 | ClassScopeFunctionSpecializationDecl *D); | |||
353 | RedeclarableResult | |||
354 | VisitVarTemplateSpecializationDeclImpl(VarTemplateSpecializationDecl *D); | |||
355 | ||||
356 | void VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D) { | |||
357 | VisitVarTemplateSpecializationDeclImpl(D); | |||
358 | } | |||
359 | ||||
360 | void VisitVarTemplatePartialSpecializationDecl( | |||
361 | VarTemplatePartialSpecializationDecl *D); | |||
362 | void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); | |||
363 | void VisitValueDecl(ValueDecl *VD); | |||
364 | void VisitEnumConstantDecl(EnumConstantDecl *ECD); | |||
365 | void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); | |||
366 | void VisitDeclaratorDecl(DeclaratorDecl *DD); | |||
367 | void VisitFunctionDecl(FunctionDecl *FD); | |||
368 | void VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *GD); | |||
369 | void VisitCXXMethodDecl(CXXMethodDecl *D); | |||
370 | void VisitCXXConstructorDecl(CXXConstructorDecl *D); | |||
371 | void VisitCXXDestructorDecl(CXXDestructorDecl *D); | |||
372 | void VisitCXXConversionDecl(CXXConversionDecl *D); | |||
373 | void VisitFieldDecl(FieldDecl *FD); | |||
374 | void VisitMSPropertyDecl(MSPropertyDecl *FD); | |||
375 | void VisitMSGuidDecl(MSGuidDecl *D); | |||
376 | void VisitUnnamedGlobalConstantDecl(UnnamedGlobalConstantDecl *D); | |||
377 | void VisitTemplateParamObjectDecl(TemplateParamObjectDecl *D); | |||
378 | void VisitIndirectFieldDecl(IndirectFieldDecl *FD); | |||
379 | RedeclarableResult VisitVarDeclImpl(VarDecl *D); | |||
380 | void VisitVarDecl(VarDecl *VD) { VisitVarDeclImpl(VD); } | |||
381 | void VisitImplicitParamDecl(ImplicitParamDecl *PD); | |||
382 | void VisitParmVarDecl(ParmVarDecl *PD); | |||
383 | void VisitDecompositionDecl(DecompositionDecl *DD); | |||
384 | void VisitBindingDecl(BindingDecl *BD); | |||
385 | void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); | |||
386 | void VisitTemplateDecl(TemplateDecl *D); | |||
387 | void VisitConceptDecl(ConceptDecl *D); | |||
388 | void VisitImplicitConceptSpecializationDecl( | |||
389 | ImplicitConceptSpecializationDecl *D); | |||
390 | void VisitRequiresExprBodyDecl(RequiresExprBodyDecl *D); | |||
391 | RedeclarableResult VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D); | |||
392 | void VisitClassTemplateDecl(ClassTemplateDecl *D); | |||
393 | void VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D); | |||
394 | void VisitVarTemplateDecl(VarTemplateDecl *D); | |||
395 | void VisitFunctionTemplateDecl(FunctionTemplateDecl *D); | |||
396 | void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); | |||
397 | void VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D); | |||
398 | void VisitUsingDecl(UsingDecl *D); | |||
399 | void VisitUsingEnumDecl(UsingEnumDecl *D); | |||
400 | void VisitUsingPackDecl(UsingPackDecl *D); | |||
401 | void VisitUsingShadowDecl(UsingShadowDecl *D); | |||
402 | void VisitConstructorUsingShadowDecl(ConstructorUsingShadowDecl *D); | |||
403 | void VisitLinkageSpecDecl(LinkageSpecDecl *D); | |||
404 | void VisitExportDecl(ExportDecl *D); | |||
405 | void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD); | |||
406 | void VisitTopLevelStmtDecl(TopLevelStmtDecl *D); | |||
407 | void VisitImportDecl(ImportDecl *D); | |||
408 | void VisitAccessSpecDecl(AccessSpecDecl *D); | |||
409 | void VisitFriendDecl(FriendDecl *D); | |||
410 | void VisitFriendTemplateDecl(FriendTemplateDecl *D); | |||
411 | void VisitStaticAssertDecl(StaticAssertDecl *D); | |||
412 | void VisitBlockDecl(BlockDecl *BD); | |||
413 | void VisitCapturedDecl(CapturedDecl *CD); | |||
414 | void VisitEmptyDecl(EmptyDecl *D); | |||
415 | void VisitLifetimeExtendedTemporaryDecl(LifetimeExtendedTemporaryDecl *D); | |||
416 | ||||
417 | std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC); | |||
418 | ||||
419 | template<typename T> | |||
420 | RedeclarableResult VisitRedeclarable(Redeclarable<T> *D); | |||
421 | ||||
422 | template <typename T> | |||
423 | void mergeRedeclarable(Redeclarable<T> *D, RedeclarableResult &Redecl); | |||
424 | ||||
425 | void mergeRedeclarableTemplate(RedeclarableTemplateDecl *D, | |||
426 | RedeclarableResult &Redecl); | |||
427 | ||||
428 | template <typename T> | |||
429 | void mergeRedeclarable(Redeclarable<T> *D, T *Existing, | |||
430 | RedeclarableResult &Redecl); | |||
431 | ||||
432 | template<typename T> | |||
433 | void mergeMergeable(Mergeable<T> *D); | |||
434 | ||||
435 | void mergeMergeable(LifetimeExtendedTemporaryDecl *D); | |||
436 | ||||
437 | void mergeTemplatePattern(RedeclarableTemplateDecl *D, | |||
438 | RedeclarableTemplateDecl *Existing, | |||
439 | bool IsKeyDecl); | |||
440 | ||||
441 | ObjCTypeParamList *ReadObjCTypeParamList(); | |||
442 | ||||
443 | // FIXME: Reorder according to DeclNodes.td? | |||
444 | void VisitObjCMethodDecl(ObjCMethodDecl *D); | |||
445 | void VisitObjCTypeParamDecl(ObjCTypeParamDecl *D); | |||
446 | void VisitObjCContainerDecl(ObjCContainerDecl *D); | |||
447 | void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); | |||
448 | void VisitObjCIvarDecl(ObjCIvarDecl *D); | |||
449 | void VisitObjCProtocolDecl(ObjCProtocolDecl *D); | |||
450 | void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D); | |||
451 | void VisitObjCCategoryDecl(ObjCCategoryDecl *D); | |||
452 | void VisitObjCImplDecl(ObjCImplDecl *D); | |||
453 | void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); | |||
454 | void VisitObjCImplementationDecl(ObjCImplementationDecl *D); | |||
455 | void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D); | |||
456 | void VisitObjCPropertyDecl(ObjCPropertyDecl *D); | |||
457 | void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); | |||
458 | void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D); | |||
459 | void VisitOMPAllocateDecl(OMPAllocateDecl *D); | |||
460 | void VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D); | |||
461 | void VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D); | |||
462 | void VisitOMPRequiresDecl(OMPRequiresDecl *D); | |||
463 | void VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D); | |||
464 | }; | |||
465 | ||||
466 | } // namespace clang | |||
467 | ||||
468 | namespace { | |||
469 | ||||
470 | /// Iterator over the redeclarations of a declaration that have already | |||
471 | /// been merged into the same redeclaration chain. | |||
472 | template<typename DeclT> | |||
473 | class MergedRedeclIterator { | |||
474 | DeclT *Start; | |||
475 | DeclT *Canonical = nullptr; | |||
476 | DeclT *Current = nullptr; | |||
477 | ||||
478 | public: | |||
479 | MergedRedeclIterator() = default; | |||
480 | MergedRedeclIterator(DeclT *Start) : Start(Start), Current(Start) {} | |||
481 | ||||
482 | DeclT *operator*() { return Current; } | |||
483 | ||||
484 | MergedRedeclIterator &operator++() { | |||
485 | if (Current->isFirstDecl()) { | |||
| ||||
486 | Canonical = Current; | |||
487 | Current = Current->getMostRecentDecl(); | |||
488 | } else | |||
489 | Current = Current->getPreviousDecl(); | |||
490 | ||||
491 | // If we started in the merged portion, we'll reach our start position | |||
492 | // eventually. Otherwise, we'll never reach it, but the second declaration | |||
493 | // we reached was the canonical declaration, so stop when we see that one | |||
494 | // again. | |||
495 | if (Current == Start || Current == Canonical) | |||
496 | Current = nullptr; | |||
497 | return *this; | |||
498 | } | |||
499 | ||||
500 | friend bool operator!=(const MergedRedeclIterator &A, | |||
501 | const MergedRedeclIterator &B) { | |||
502 | return A.Current != B.Current; | |||
503 | } | |||
504 | }; | |||
505 | ||||
506 | } // namespace | |||
507 | ||||
508 | template <typename DeclT> | |||
509 | static llvm::iterator_range<MergedRedeclIterator<DeclT>> | |||
510 | merged_redecls(DeclT *D) { | |||
511 | return llvm::make_range(MergedRedeclIterator<DeclT>(D), | |||
512 | MergedRedeclIterator<DeclT>()); | |||
513 | } | |||
514 | ||||
515 | uint64_t ASTDeclReader::GetCurrentCursorOffset() { | |||
516 | return Loc.F->DeclsCursor.GetCurrentBitNo() + Loc.F->GlobalBitOffset; | |||
517 | } | |||
518 | ||||
519 | void ASTDeclReader::ReadFunctionDefinition(FunctionDecl *FD) { | |||
520 | if (Record.readInt()) { | |||
521 | Reader.DefinitionSource[FD] = | |||
522 | Loc.F->Kind == ModuleKind::MK_MainFile || | |||
523 | Reader.getContext().getLangOpts().BuildingPCHWithObjectFile; | |||
524 | } | |||
525 | if (auto *CD = dyn_cast<CXXConstructorDecl>(FD)) { | |||
526 | CD->setNumCtorInitializers(Record.readInt()); | |||
527 | if (CD->getNumCtorInitializers()) | |||
528 | CD->CtorInitializers = ReadGlobalOffset(); | |||
529 | } | |||
530 | // Store the offset of the body so we can lazily load it later. | |||
531 | Reader.PendingBodies[FD] = GetCurrentCursorOffset(); | |||
532 | HasPendingBody = true; | |||
533 | } | |||
534 | ||||
535 | void ASTDeclReader::Visit(Decl *D) { | |||
536 | DeclVisitor<ASTDeclReader, void>::Visit(D); | |||
537 | ||||
538 | // At this point we have deserialized and merged the decl and it is safe to | |||
539 | // update its canonical decl to signal that the entire entity is used. | |||
540 | D->getCanonicalDecl()->Used |= IsDeclMarkedUsed; | |||
541 | IsDeclMarkedUsed = false; | |||
542 | ||||
543 | if (auto *DD = dyn_cast<DeclaratorDecl>(D)) { | |||
544 | if (auto *TInfo = DD->getTypeSourceInfo()) | |||
545 | Record.readTypeLoc(TInfo->getTypeLoc()); | |||
546 | } | |||
547 | ||||
548 | if (auto *TD = dyn_cast<TypeDecl>(D)) { | |||
549 | // We have a fully initialized TypeDecl. Read its type now. | |||
550 | TD->setTypeForDecl(Reader.GetType(DeferredTypeID).getTypePtrOrNull()); | |||
551 | ||||
552 | // If this is a tag declaration with a typedef name for linkage, it's safe | |||
553 | // to load that typedef now. | |||
554 | if (NamedDeclForTagDecl) | |||
555 | cast<TagDecl>(D)->TypedefNameDeclOrQualifier = | |||
556 | cast<TypedefNameDecl>(Reader.GetDecl(NamedDeclForTagDecl)); | |||
557 | } else if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) { | |||
558 | // if we have a fully initialized TypeDecl, we can safely read its type now. | |||
559 | ID->TypeForDecl = Reader.GetType(DeferredTypeID).getTypePtrOrNull(); | |||
560 | } else if (auto *FD = dyn_cast<FunctionDecl>(D)) { | |||
561 | // FunctionDecl's body was written last after all other Stmts/Exprs. | |||
562 | // We only read it if FD doesn't already have a body (e.g., from another | |||
563 | // module). | |||
564 | // FIXME: Can we diagnose ODR violations somehow? | |||
565 | if (Record.readInt()) | |||
566 | ReadFunctionDefinition(FD); | |||
567 | } | |||
568 | } | |||
569 | ||||
570 | void ASTDeclReader::VisitDecl(Decl *D) { | |||
571 | if (D->isTemplateParameter() || D->isTemplateParameterPack() || | |||
572 | isa<ParmVarDecl, ObjCTypeParamDecl>(D)) { | |||
573 | // We don't want to deserialize the DeclContext of a template | |||
574 | // parameter or of a parameter of a function template immediately. These | |||
575 | // entities might be used in the formulation of its DeclContext (for | |||
576 | // example, a function parameter can be used in decltype() in trailing | |||
577 | // return type of the function). Use the translation unit DeclContext as a | |||
578 | // placeholder. | |||
579 | GlobalDeclID SemaDCIDForTemplateParmDecl = readDeclID(); | |||
580 | GlobalDeclID LexicalDCIDForTemplateParmDecl = readDeclID(); | |||
581 | if (!LexicalDCIDForTemplateParmDecl) | |||
582 | LexicalDCIDForTemplateParmDecl = SemaDCIDForTemplateParmDecl; | |||
583 | Reader.addPendingDeclContextInfo(D, | |||
584 | SemaDCIDForTemplateParmDecl, | |||
585 | LexicalDCIDForTemplateParmDecl); | |||
586 | D->setDeclContext(Reader.getContext().getTranslationUnitDecl()); | |||
587 | } else { | |||
588 | auto *SemaDC = readDeclAs<DeclContext>(); | |||
589 | auto *LexicalDC = readDeclAs<DeclContext>(); | |||
590 | if (!LexicalDC) | |||
591 | LexicalDC = SemaDC; | |||
592 | DeclContext *MergedSemaDC = Reader.MergedDeclContexts.lookup(SemaDC); | |||
593 | // Avoid calling setLexicalDeclContext() directly because it uses | |||
594 | // Decl::getASTContext() internally which is unsafe during derialization. | |||
595 | D->setDeclContextsImpl(MergedSemaDC ? MergedSemaDC : SemaDC, LexicalDC, | |||
596 | Reader.getContext()); | |||
597 | } | |||
598 | D->setLocation(ThisDeclLoc); | |||
599 | D->InvalidDecl = Record.readInt(); | |||
600 | if (Record.readInt()) { // hasAttrs | |||
601 | AttrVec Attrs; | |||
602 | Record.readAttributes(Attrs); | |||
603 | // Avoid calling setAttrs() directly because it uses Decl::getASTContext() | |||
604 | // internally which is unsafe during derialization. | |||
605 | D->setAttrsImpl(Attrs, Reader.getContext()); | |||
606 | } | |||
607 | D->setImplicit(Record.readInt()); | |||
608 | D->Used = Record.readInt(); | |||
609 | IsDeclMarkedUsed |= D->Used; | |||
610 | D->setReferenced(Record.readInt()); | |||
611 | D->setTopLevelDeclInObjCContainer(Record.readInt()); | |||
612 | D->setAccess((AccessSpecifier)Record.readInt()); | |||
613 | D->FromASTFile = true; | |||
614 | auto ModuleOwnership = (Decl::ModuleOwnershipKind)Record.readInt(); | |||
615 | bool ModulePrivate = | |||
616 | (ModuleOwnership == Decl::ModuleOwnershipKind::ModulePrivate); | |||
617 | ||||
618 | // Determine whether this declaration is part of a (sub)module. If so, it | |||
619 | // may not yet be visible. | |||
620 | if (unsigned SubmoduleID = readSubmoduleID()) { | |||
621 | ||||
622 | switch (ModuleOwnership) { | |||
623 | case Decl::ModuleOwnershipKind::Visible: | |||
624 | ModuleOwnership = Decl::ModuleOwnershipKind::VisibleWhenImported; | |||
625 | break; | |||
626 | case Decl::ModuleOwnershipKind::Unowned: | |||
627 | case Decl::ModuleOwnershipKind::VisibleWhenImported: | |||
628 | case Decl::ModuleOwnershipKind::ReachableWhenImported: | |||
629 | case Decl::ModuleOwnershipKind::ModulePrivate: | |||
630 | break; | |||
631 | } | |||
632 | ||||
633 | D->setModuleOwnershipKind(ModuleOwnership); | |||
634 | // Store the owning submodule ID in the declaration. | |||
635 | D->setOwningModuleID(SubmoduleID); | |||
636 | ||||
637 | if (ModulePrivate) { | |||
638 | // Module-private declarations are never visible, so there is no work to | |||
639 | // do. | |||
640 | } else if (Reader.getContext().getLangOpts().ModulesLocalVisibility) { | |||
641 | // If local visibility is being tracked, this declaration will become | |||
642 | // hidden and visible as the owning module does. | |||
643 | } else if (Module *Owner = Reader.getSubmodule(SubmoduleID)) { | |||
644 | // Mark the declaration as visible when its owning module becomes visible. | |||
645 | if (Owner->NameVisibility == Module::AllVisible) | |||
646 | D->setVisibleDespiteOwningModule(); | |||
647 | else | |||
648 | Reader.HiddenNamesMap[Owner].push_back(D); | |||
649 | } | |||
650 | } else if (ModulePrivate) { | |||
651 | D->setModuleOwnershipKind(Decl::ModuleOwnershipKind::ModulePrivate); | |||
652 | } | |||
653 | } | |||
654 | ||||
655 | void ASTDeclReader::VisitPragmaCommentDecl(PragmaCommentDecl *D) { | |||
656 | VisitDecl(D); | |||
657 | D->setLocation(readSourceLocation()); | |||
658 | D->CommentKind = (PragmaMSCommentKind)Record.readInt(); | |||
659 | std::string Arg = readString(); | |||
660 | memcpy(D->getTrailingObjects<char>(), Arg.data(), Arg.size()); | |||
661 | D->getTrailingObjects<char>()[Arg.size()] = '\0'; | |||
662 | } | |||
663 | ||||
664 | void ASTDeclReader::VisitPragmaDetectMismatchDecl(PragmaDetectMismatchDecl *D) { | |||
665 | VisitDecl(D); | |||
666 | D->setLocation(readSourceLocation()); | |||
667 | std::string Name = readString(); | |||
668 | memcpy(D->getTrailingObjects<char>(), Name.data(), Name.size()); | |||
669 | D->getTrailingObjects<char>()[Name.size()] = '\0'; | |||
670 | ||||
671 | D->ValueStart = Name.size() + 1; | |||
672 | std::string Value = readString(); | |||
673 | memcpy(D->getTrailingObjects<char>() + D->ValueStart, Value.data(), | |||
674 | Value.size()); | |||
675 | D->getTrailingObjects<char>()[D->ValueStart + Value.size()] = '\0'; | |||
676 | } | |||
677 | ||||
678 | void ASTDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) { | |||
679 | llvm_unreachable("Translation units are not serialized")::llvm::llvm_unreachable_internal("Translation units are not serialized" , "clang/lib/Serialization/ASTReaderDecl.cpp", 679); | |||
680 | } | |||
681 | ||||
682 | void ASTDeclReader::VisitNamedDecl(NamedDecl *ND) { | |||
683 | VisitDecl(ND); | |||
684 | ND->setDeclName(Record.readDeclarationName()); | |||
685 | AnonymousDeclNumber = Record.readInt(); | |||
686 | } | |||
687 | ||||
688 | void ASTDeclReader::VisitTypeDecl(TypeDecl *TD) { | |||
689 | VisitNamedDecl(TD); | |||
690 | TD->setLocStart(readSourceLocation()); | |||
691 | // Delay type reading until after we have fully initialized the decl. | |||
692 | DeferredTypeID = Record.getGlobalTypeID(Record.readInt()); | |||
693 | } | |||
694 | ||||
695 | ASTDeclReader::RedeclarableResult | |||
696 | ASTDeclReader::VisitTypedefNameDecl(TypedefNameDecl *TD) { | |||
697 | RedeclarableResult Redecl = VisitRedeclarable(TD); | |||
698 | VisitTypeDecl(TD); | |||
699 | TypeSourceInfo *TInfo = readTypeSourceInfo(); | |||
700 | if (Record.readInt()) { // isModed | |||
701 | QualType modedT = Record.readType(); | |||
702 | TD->setModedTypeSourceInfo(TInfo, modedT); | |||
703 | } else | |||
704 | TD->setTypeSourceInfo(TInfo); | |||
705 | // Read and discard the declaration for which this is a typedef name for | |||
706 | // linkage, if it exists. We cannot rely on our type to pull in this decl, | |||
707 | // because it might have been merged with a type from another module and | |||
708 | // thus might not refer to our version of the declaration. | |||
709 | readDecl(); | |||
710 | return Redecl; | |||
711 | } | |||
712 | ||||
713 | void ASTDeclReader::VisitTypedefDecl(TypedefDecl *TD) { | |||
714 | RedeclarableResult Redecl = VisitTypedefNameDecl(TD); | |||
715 | mergeRedeclarable(TD, Redecl); | |||
716 | } | |||
717 | ||||
718 | void ASTDeclReader::VisitTypeAliasDecl(TypeAliasDecl *TD) { | |||
719 | RedeclarableResult Redecl = VisitTypedefNameDecl(TD); | |||
720 | if (auto *Template = readDeclAs<TypeAliasTemplateDecl>()) | |||
721 | // Merged when we merge the template. | |||
722 | TD->setDescribedAliasTemplate(Template); | |||
723 | else | |||
724 | mergeRedeclarable(TD, Redecl); | |||
725 | } | |||
726 | ||||
727 | ASTDeclReader::RedeclarableResult ASTDeclReader::VisitTagDecl(TagDecl *TD) { | |||
728 | RedeclarableResult Redecl = VisitRedeclarable(TD); | |||
729 | VisitTypeDecl(TD); | |||
730 | ||||
731 | TD->IdentifierNamespace = Record.readInt(); | |||
732 | TD->setTagKind((TagDecl::TagKind)Record.readInt()); | |||
733 | if (!isa<CXXRecordDecl>(TD)) | |||
734 | TD->setCompleteDefinition(Record.readInt()); | |||
735 | TD->setEmbeddedInDeclarator(Record.readInt()); | |||
736 | TD->setFreeStanding(Record.readInt()); | |||
737 | TD->setCompleteDefinitionRequired(Record.readInt()); | |||
738 | TD->setBraceRange(readSourceRange()); | |||
739 | ||||
740 | switch (Record.readInt()) { | |||
741 | case 0: | |||
742 | break; | |||
743 | case 1: { // ExtInfo | |||
744 | auto *Info = new (Reader.getContext()) TagDecl::ExtInfo(); | |||
745 | Record.readQualifierInfo(*Info); | |||
746 | TD->TypedefNameDeclOrQualifier = Info; | |||
747 | break; | |||
748 | } | |||
749 | case 2: // TypedefNameForAnonDecl | |||
750 | NamedDeclForTagDecl = readDeclID(); | |||
751 | TypedefNameForLinkage = Record.readIdentifier(); | |||
752 | break; | |||
753 | default: | |||
754 | llvm_unreachable("unexpected tag info kind")::llvm::llvm_unreachable_internal("unexpected tag info kind", "clang/lib/Serialization/ASTReaderDecl.cpp", 754); | |||
755 | } | |||
756 | ||||
757 | if (!isa<CXXRecordDecl>(TD)) | |||
758 | mergeRedeclarable(TD, Redecl); | |||
759 | return Redecl; | |||
760 | } | |||
761 | ||||
762 | void ASTDeclReader::VisitEnumDecl(EnumDecl *ED) { | |||
763 | VisitTagDecl(ED); | |||
764 | if (TypeSourceInfo *TI = readTypeSourceInfo()) | |||
765 | ED->setIntegerTypeSourceInfo(TI); | |||
766 | else | |||
767 | ED->setIntegerType(Record.readType()); | |||
768 | ED->setPromotionType(Record.readType()); | |||
769 | ED->setNumPositiveBits(Record.readInt()); | |||
770 | ED->setNumNegativeBits(Record.readInt()); | |||
771 | ED->setScoped(Record.readInt()); | |||
772 | ED->setScopedUsingClassTag(Record.readInt()); | |||
773 | ED->setFixed(Record.readInt()); | |||
774 | ||||
775 | ED->setHasODRHash(true); | |||
776 | ED->ODRHash = Record.readInt(); | |||
777 | ||||
778 | // If this is a definition subject to the ODR, and we already have a | |||
779 | // definition, merge this one into it. | |||
780 | if (ED->isCompleteDefinition() && | |||
781 | Reader.getContext().getLangOpts().Modules && | |||
782 | Reader.getContext().getLangOpts().CPlusPlus) { | |||
783 | EnumDecl *&OldDef = Reader.EnumDefinitions[ED->getCanonicalDecl()]; | |||
784 | if (!OldDef) { | |||
785 | // This is the first time we've seen an imported definition. Look for a | |||
786 | // local definition before deciding that we are the first definition. | |||
787 | for (auto *D : merged_redecls(ED->getCanonicalDecl())) { | |||
788 | if (!D->isFromASTFile() && D->isCompleteDefinition()) { | |||
789 | OldDef = D; | |||
790 | break; | |||
791 | } | |||
792 | } | |||
793 | } | |||
794 | if (OldDef) { | |||
795 | Reader.MergedDeclContexts.insert(std::make_pair(ED, OldDef)); | |||
796 | ED->demoteThisDefinitionToDeclaration(); | |||
797 | Reader.mergeDefinitionVisibility(OldDef, ED); | |||
798 | if (OldDef->getODRHash() != ED->getODRHash()) | |||
799 | Reader.PendingEnumOdrMergeFailures[OldDef].push_back(ED); | |||
800 | } else { | |||
801 | OldDef = ED; | |||
802 | } | |||
803 | } | |||
804 | ||||
805 | if (auto *InstED = readDeclAs<EnumDecl>()) { | |||
806 | auto TSK = (TemplateSpecializationKind)Record.readInt(); | |||
807 | SourceLocation POI = readSourceLocation(); | |||
808 | ED->setInstantiationOfMemberEnum(Reader.getContext(), InstED, TSK); | |||
809 | ED->getMemberSpecializationInfo()->setPointOfInstantiation(POI); | |||
810 | } | |||
811 | } | |||
812 | ||||
813 | ASTDeclReader::RedeclarableResult | |||
814 | ASTDeclReader::VisitRecordDeclImpl(RecordDecl *RD) { | |||
815 | RedeclarableResult Redecl = VisitTagDecl(RD); | |||
816 | RD->setHasFlexibleArrayMember(Record.readInt()); | |||
817 | RD->setAnonymousStructOrUnion(Record.readInt()); | |||
818 | RD->setHasObjectMember(Record.readInt()); | |||
819 | RD->setHasVolatileMember(Record.readInt()); | |||
820 | RD->setNonTrivialToPrimitiveDefaultInitialize(Record.readInt()); | |||
821 | RD->setNonTrivialToPrimitiveCopy(Record.readInt()); | |||
822 | RD->setNonTrivialToPrimitiveDestroy(Record.readInt()); | |||
823 | RD->setHasNonTrivialToPrimitiveDefaultInitializeCUnion(Record.readInt()); | |||
824 | RD->setHasNonTrivialToPrimitiveDestructCUnion(Record.readInt()); | |||
825 | RD->setHasNonTrivialToPrimitiveCopyCUnion(Record.readInt()); | |||
826 | RD->setParamDestroyedInCallee(Record.readInt()); | |||
827 | RD->setArgPassingRestrictions((RecordDecl::ArgPassingKind)Record.readInt()); | |||
828 | return Redecl; | |||
829 | } | |||
830 | ||||
831 | void ASTDeclReader::VisitRecordDecl(RecordDecl *RD) { | |||
832 | VisitRecordDeclImpl(RD); | |||
833 | RD->setODRHash(Record.readInt()); | |||
834 | ||||
835 | // Maintain the invariant of a redeclaration chain containing only | |||
836 | // a single definition. | |||
837 | if (RD->isCompleteDefinition()) { | |||
838 | RecordDecl *Canon = static_cast<RecordDecl *>(RD->getCanonicalDecl()); | |||
839 | RecordDecl *&OldDef = Reader.RecordDefinitions[Canon]; | |||
840 | if (!OldDef) { | |||
841 | // This is the first time we've seen an imported definition. Look for a | |||
842 | // local definition before deciding that we are the first definition. | |||
843 | for (auto *D : merged_redecls(Canon)) { | |||
844 | if (!D->isFromASTFile() && D->isCompleteDefinition()) { | |||
845 | OldDef = D; | |||
846 | break; | |||
847 | } | |||
848 | } | |||
849 | } | |||
850 | if (OldDef) { | |||
851 | Reader.MergedDeclContexts.insert(std::make_pair(RD, OldDef)); | |||
852 | RD->demoteThisDefinitionToDeclaration(); | |||
853 | Reader.mergeDefinitionVisibility(OldDef, RD); | |||
854 | if (OldDef->getODRHash() != RD->getODRHash()) | |||
855 | Reader.PendingRecordOdrMergeFailures[OldDef].push_back(RD); | |||
856 | } else { | |||
857 | OldDef = RD; | |||
858 | } | |||
859 | } | |||
860 | } | |||
861 | ||||
862 | void ASTDeclReader::VisitValueDecl(ValueDecl *VD) { | |||
863 | VisitNamedDecl(VD); | |||
864 | // For function declarations, defer reading the type in case the function has | |||
865 | // a deduced return type that references an entity declared within the | |||
866 | // function. | |||
867 | if (isa<FunctionDecl>(VD)) | |||
868 | DeferredTypeID = Record.getGlobalTypeID(Record.readInt()); | |||
869 | else | |||
870 | VD->setType(Record.readType()); | |||
871 | } | |||
872 | ||||
873 | void ASTDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) { | |||
874 | VisitValueDecl(ECD); | |||
875 | if (Record.readInt()) | |||
876 | ECD->setInitExpr(Record.readExpr()); | |||
877 | ECD->setInitVal(Record.readAPSInt()); | |||
878 | mergeMergeable(ECD); | |||
879 | } | |||
880 | ||||
881 | void ASTDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) { | |||
882 | VisitValueDecl(DD); | |||
883 | DD->setInnerLocStart(readSourceLocation()); | |||
884 | if (Record.readInt()) { // hasExtInfo | |||
885 | auto *Info = new (Reader.getContext()) DeclaratorDecl::ExtInfo(); | |||
886 | Record.readQualifierInfo(*Info); | |||
887 | Info->TrailingRequiresClause = Record.readExpr(); | |||
888 | DD->DeclInfo = Info; | |||
889 | } | |||
890 | QualType TSIType = Record.readType(); | |||
891 | DD->setTypeSourceInfo( | |||
892 | TSIType.isNull() ? nullptr | |||
893 | : Reader.getContext().CreateTypeSourceInfo(TSIType)); | |||
894 | } | |||
895 | ||||
896 | void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) { | |||
897 | RedeclarableResult Redecl = VisitRedeclarable(FD); | |||
898 | ||||
899 | FunctionDecl *Existing = nullptr; | |||
900 | ||||
901 | switch ((FunctionDecl::TemplatedKind)Record.readInt()) { | |||
902 | case FunctionDecl::TK_NonTemplate: | |||
903 | break; | |||
904 | case FunctionDecl::TK_DependentNonTemplate: | |||
905 | FD->setInstantiatedFromDecl(readDeclAs<FunctionDecl>()); | |||
906 | break; | |||
907 | case FunctionDecl::TK_FunctionTemplate: { | |||
908 | auto *Template = readDeclAs<FunctionTemplateDecl>(); | |||
909 | Template->init(FD); | |||
910 | FD->setDescribedFunctionTemplate(Template); | |||
911 | break; | |||
912 | } | |||
913 | case FunctionDecl::TK_MemberSpecialization: { | |||
914 | auto *InstFD = readDeclAs<FunctionDecl>(); | |||
915 | auto TSK = (TemplateSpecializationKind)Record.readInt(); | |||
916 | SourceLocation POI = readSourceLocation(); | |||
917 | FD->setInstantiationOfMemberFunction(Reader.getContext(), InstFD, TSK); | |||
918 | FD->getMemberSpecializationInfo()->setPointOfInstantiation(POI); | |||
919 | break; | |||
920 | } | |||
921 | case FunctionDecl::TK_FunctionTemplateSpecialization: { | |||
922 | auto *Template = readDeclAs<FunctionTemplateDecl>(); | |||
923 | auto TSK = (TemplateSpecializationKind)Record.readInt(); | |||
924 | ||||
925 | // Template arguments. | |||
926 | SmallVector<TemplateArgument, 8> TemplArgs; | |||
927 | Record.readTemplateArgumentList(TemplArgs, /*Canonicalize*/ true); | |||
928 | ||||
929 | // Template args as written. | |||
930 | SmallVector<TemplateArgumentLoc, 8> TemplArgLocs; | |||
931 | SourceLocation LAngleLoc, RAngleLoc; | |||
932 | bool HasTemplateArgumentsAsWritten = Record.readInt(); | |||
933 | if (HasTemplateArgumentsAsWritten) { | |||
934 | unsigned NumTemplateArgLocs = Record.readInt(); | |||
935 | TemplArgLocs.reserve(NumTemplateArgLocs); | |||
936 | for (unsigned i = 0; i != NumTemplateArgLocs; ++i) | |||
937 | TemplArgLocs.push_back(Record.readTemplateArgumentLoc()); | |||
938 | ||||
939 | LAngleLoc = readSourceLocation(); | |||
940 | RAngleLoc = readSourceLocation(); | |||
941 | } | |||
942 | ||||
943 | SourceLocation POI = readSourceLocation(); | |||
944 | ||||
945 | ASTContext &C = Reader.getContext(); | |||
946 | TemplateArgumentList *TemplArgList | |||
947 | = TemplateArgumentList::CreateCopy(C, TemplArgs); | |||
948 | TemplateArgumentListInfo TemplArgsInfo(LAngleLoc, RAngleLoc); | |||
949 | for (unsigned i = 0, e = TemplArgLocs.size(); i != e; ++i) | |||
950 | TemplArgsInfo.addArgument(TemplArgLocs[i]); | |||
951 | ||||
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); | |||
967 | FD->TemplateOrSpecialization = FTInfo; | |||
968 | ||||
969 | if (FD->isCanonicalDecl()) { // if canonical add to template's set. | |||
970 | // The template that contains the specializations set. It's not safe to | |||
971 | // use getCanonicalDecl on Template since it may still be initializing. | |||
972 | auto *CanonTemplate = readDeclAs<FunctionTemplateDecl>(); | |||
973 | // 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. | |||
978 | llvm::FoldingSetNodeID ID; | |||
979 | FunctionTemplateSpecializationInfo::Profile(ID, TemplArgs, C); | |||
980 | void *InsertPos = nullptr; | |||
981 | FunctionTemplateDecl::Common *CommonPtr = CanonTemplate->getCommonPtr(); | |||
982 | FunctionTemplateSpecializationInfo *ExistingInfo = | |||
983 | CommonPtr->Specializations.FindNodeOrInsertPos(ID, InsertPos); | |||
984 | if (InsertPos) | |||
985 | CommonPtr->Specializations.InsertNode(FTInfo, InsertPos); | |||
986 | else { | |||
987 | assert(Reader.getContext().getLangOpts().Modules &&(static_cast <bool> (Reader.getContext().getLangOpts(). Modules && "already deserialized this template specialization" ) ? void (0) : __assert_fail ("Reader.getContext().getLangOpts().Modules && \"already deserialized this template specialization\"" , "clang/lib/Serialization/ASTReaderDecl.cpp", 988, __extension__ __PRETTY_FUNCTION__)) | |||
988 | "already deserialized this template specialization")(static_cast <bool> (Reader.getContext().getLangOpts(). Modules && "already deserialized this template specialization" ) ? void (0) : __assert_fail ("Reader.getContext().getLangOpts().Modules && \"already deserialized this template specialization\"" , "clang/lib/Serialization/ASTReaderDecl.cpp", 988, __extension__ __PRETTY_FUNCTION__)); | |||
989 | Existing = ExistingInfo->getFunction(); | |||
990 | } | |||
991 | } | |||
992 | break; | |||
993 | } | |||
994 | case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { | |||
995 | // Templates. | |||
996 | UnresolvedSet<8> TemplDecls; | |||
997 | unsigned NumTemplates = Record.readInt(); | |||
998 | while (NumTemplates--) | |||
999 | TemplDecls.addDecl(readDeclAs<NamedDecl>()); | |||
1000 | ||||
1001 | // Templates args. | |||
1002 | TemplateArgumentListInfo TemplArgs; | |||
1003 | unsigned NumArgs = Record.readInt(); | |||
1004 | while (NumArgs--) | |||
1005 | TemplArgs.addArgument(Record.readTemplateArgumentLoc()); | |||
1006 | TemplArgs.setLAngleLoc(readSourceLocation()); | |||
1007 | TemplArgs.setRAngleLoc(readSourceLocation()); | |||
1008 | ||||
1009 | FD->setDependentTemplateSpecialization(Reader.getContext(), | |||
1010 | TemplDecls, TemplArgs); | |||
1011 | // These are not merged; we don't need to merge redeclarations of dependent | |||
1012 | // template friends. | |||
1013 | break; | |||
1014 | } | |||
1015 | } | |||
1016 | ||||
1017 | VisitDeclaratorDecl(FD); | |||
1018 | ||||
1019 | // Attach a type to this function. Use the real type if possible, but fall | |||
1020 | // back to the type as written if it involves a deduced return type. | |||
1021 | if (FD->getTypeSourceInfo() && FD->getTypeSourceInfo() | |||
1022 | ->getType() | |||
1023 | ->castAs<FunctionType>() | |||
1024 | ->getReturnType() | |||
1025 | ->getContainedAutoType()) { | |||
1026 | // We'll set up the real type in Visit, once we've finished loading the | |||
1027 | // function. | |||
1028 | FD->setType(FD->getTypeSourceInfo()->getType()); | |||
1029 | Reader.PendingFunctionTypes.push_back({FD, DeferredTypeID}); | |||
1030 | } else { | |||
1031 | FD->setType(Reader.GetType(DeferredTypeID)); | |||
1032 | } | |||
1033 | DeferredTypeID = 0; | |||
1034 | ||||
1035 | FD->DNLoc = Record.readDeclarationNameLoc(FD->getDeclName()); | |||
1036 | FD->IdentifierNamespace = Record.readInt(); | |||
1037 | ||||
1038 | // FunctionDecl's body is handled last at ASTDeclReader::Visit, | |||
1039 | // after everything else is read. | |||
1040 | ||||
1041 | FD->setStorageClass(static_cast<StorageClass>(Record.readInt())); | |||
1042 | FD->setInlineSpecified(Record.readInt()); | |||
1043 | FD->setImplicitlyInline(Record.readInt()); | |||
1044 | FD->setVirtualAsWritten(Record.readInt()); | |||
1045 | // We defer calling `FunctionDecl::setPure()` here as for methods of | |||
1046 | // `CXXTemplateSpecializationDecl`s, we may not have connected up the | |||
1047 | // definition (which is required for `setPure`). | |||
1048 | const bool Pure = Record.readInt(); | |||
1049 | FD->setHasInheritedPrototype(Record.readInt()); | |||
1050 | FD->setHasWrittenPrototype(Record.readInt()); | |||
1051 | FD->setDeletedAsWritten(Record.readInt()); | |||
1052 | FD->setTrivial(Record.readInt()); | |||
1053 | FD->setTrivialForCall(Record.readInt()); | |||
1054 | FD->setDefaulted(Record.readInt()); | |||
1055 | FD->setExplicitlyDefaulted(Record.readInt()); | |||
1056 | FD->setIneligibleOrNotSelected(Record.readInt()); | |||
1057 | FD->setHasImplicitReturnZero(Record.readInt()); | |||
1058 | FD->setConstexprKind(static_cast<ConstexprSpecKind>(Record.readInt())); | |||
1059 | FD->setUsesSEHTry(Record.readInt()); | |||
1060 | FD->setHasSkippedBody(Record.readInt()); | |||
1061 | FD->setIsMultiVersion(Record.readInt()); | |||
1062 | FD->setLateTemplateParsed(Record.readInt()); | |||
1063 | FD->setFriendConstraintRefersToEnclosingTemplate(Record.readInt()); | |||
1064 | ||||
1065 | FD->setCachedLinkage(static_cast<Linkage>(Record.readInt())); | |||
1066 | FD->EndRangeLoc = readSourceLocation(); | |||
1067 | FD->setDefaultLoc(readSourceLocation()); | |||
1068 | ||||
1069 | FD->ODRHash = Record.readInt(); | |||
1070 | FD->setHasODRHash(true); | |||
1071 | ||||
1072 | if (FD->isDefaulted()) { | |||
1073 | if (unsigned NumLookups = Record.readInt()) { | |||
1074 | SmallVector<DeclAccessPair, 8> Lookups; | |||
1075 | for (unsigned I = 0; I != NumLookups; ++I) { | |||
1076 | NamedDecl *ND = Record.readDeclAs<NamedDecl>(); | |||
1077 | AccessSpecifier AS = (AccessSpecifier)Record.readInt(); | |||
1078 | Lookups.push_back(DeclAccessPair::make(ND, AS)); | |||
1079 | } | |||
1080 | FD->setDefaultedFunctionInfo(FunctionDecl::DefaultedFunctionInfo::Create( | |||
1081 | Reader.getContext(), Lookups)); | |||
1082 | } | |||
1083 | } | |||
1084 | ||||
1085 | if (Existing) | |||
1086 | mergeRedeclarable(FD, Existing, Redecl); | |||
1087 | else if (auto Kind = FD->getTemplatedKind(); | |||
1088 | Kind == FunctionDecl::TK_FunctionTemplate || | |||
1089 | Kind == FunctionDecl::TK_FunctionTemplateSpecialization) { | |||
1090 | // Function Templates have their FunctionTemplateDecls merged instead of | |||
1091 | // their FunctionDecls. | |||
1092 | auto merge = [this, &Redecl, FD](auto &&F) { | |||
1093 | auto *Existing = cast_or_null<FunctionDecl>(Redecl.getKnownMergeTarget()); | |||
1094 | RedeclarableResult NewRedecl(Existing ? F(Existing) : nullptr, | |||
1095 | Redecl.getFirstID(), Redecl.isKeyDecl()); | |||
1096 | mergeRedeclarableTemplate(F(FD), NewRedecl); | |||
1097 | }; | |||
1098 | if (Kind == FunctionDecl::TK_FunctionTemplate) | |||
1099 | merge( | |||
1100 | [](FunctionDecl *FD) { return FD->getDescribedFunctionTemplate(); }); | |||
1101 | else | |||
1102 | merge([](FunctionDecl *FD) { | |||
1103 | return FD->getTemplateSpecializationInfo()->getTemplate(); | |||
1104 | }); | |||
1105 | } else | |||
1106 | mergeRedeclarable(FD, Redecl); | |||
1107 | ||||
1108 | // Defer calling `setPure` until merging above has guaranteed we've set | |||
1109 | // `DefinitionData` (as this will need to access it). | |||
1110 | FD->setPure(Pure); | |||
1111 | ||||
1112 | // Read in the parameters. | |||
1113 | unsigned NumParams = Record.readInt(); | |||
1114 | SmallVector<ParmVarDecl *, 16> Params; | |||
1115 | Params.reserve(NumParams); | |||
1116 | for (unsigned I = 0; I != NumParams; ++I) | |||
1117 | Params.push_back(readDeclAs<ParmVarDecl>()); | |||
1118 | FD->setParams(Reader.getContext(), Params); | |||
1119 | } | |||
1120 | ||||
1121 | void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) { | |||
1122 | VisitNamedDecl(MD); | |||
1123 | if (Record.readInt()) { | |||
1124 | // Load the body on-demand. Most clients won't care, because method | |||
1125 | // definitions rarely show up in headers. | |||
1126 | Reader.PendingBodies[MD] = GetCurrentCursorOffset(); | |||
1127 | HasPendingBody = true; | |||
1128 | } | |||
1129 | MD->setSelfDecl(readDeclAs<ImplicitParamDecl>()); | |||
1130 | MD->setCmdDecl(readDeclAs<ImplicitParamDecl>()); | |||
1131 | MD->setInstanceMethod(Record.readInt()); | |||
1132 | MD->setVariadic(Record.readInt()); | |||
1133 | MD->setPropertyAccessor(Record.readInt()); | |||
1134 | MD->setSynthesizedAccessorStub(Record.readInt()); | |||
1135 | MD->setDefined(Record.readInt()); | |||
1136 | MD->setOverriding(Record.readInt()); | |||
1137 | MD->setHasSkippedBody(Record.readInt()); | |||
1138 | ||||
1139 | MD->setIsRedeclaration(Record.readInt()); | |||
1140 | MD->setHasRedeclaration(Record.readInt()); | |||
1141 | if (MD->hasRedeclaration()) | |||
1142 | Reader.getContext().setObjCMethodRedeclaration(MD, | |||
1143 | readDeclAs<ObjCMethodDecl>()); | |||
1144 | ||||
1145 | MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record.readInt()); | |||
1146 | MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record.readInt()); | |||
1147 | MD->setRelatedResultType(Record.readInt()); | |||
1148 | MD->setReturnType(Record.readType()); | |||
1149 | MD->setReturnTypeSourceInfo(readTypeSourceInfo()); | |||
1150 | MD->DeclEndLoc = readSourceLocation(); | |||
1151 | unsigned NumParams = Record.readInt(); | |||
1152 | SmallVector<ParmVarDecl *, 16> Params; | |||
1153 | Params.reserve(NumParams); | |||
1154 | for (unsigned I = 0; I != NumParams; ++I) | |||
1155 | Params.push_back(readDeclAs<ParmVarDecl>()); | |||
1156 | ||||
1157 | MD->setSelLocsKind((SelectorLocationsKind)Record.readInt()); | |||
1158 | unsigned NumStoredSelLocs = Record.readInt(); | |||
1159 | SmallVector<SourceLocation, 16> SelLocs; | |||
1160 | SelLocs.reserve(NumStoredSelLocs); | |||
1161 | for (unsigned i = 0; i != NumStoredSelLocs; ++i) | |||
1162 | SelLocs.push_back(readSourceLocation()); | |||
1163 | ||||
1164 | MD->setParamsAndSelLocs(Reader.getContext(), Params, SelLocs); | |||
1165 | } | |||
1166 | ||||
1167 | void ASTDeclReader::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { | |||
1168 | VisitTypedefNameDecl(D); | |||
1169 | ||||
1170 | D->Variance = Record.readInt(); | |||
1171 | D->Index = Record.readInt(); | |||
1172 | D->VarianceLoc = readSourceLocation(); | |||
1173 | D->ColonLoc = readSourceLocation(); | |||
1174 | } | |||
1175 | ||||
1176 | void ASTDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) { | |||
1177 | VisitNamedDecl(CD); | |||
1178 | CD->setAtStartLoc(readSourceLocation()); | |||
1179 | CD->setAtEndRange(readSourceRange()); | |||
1180 | } | |||
1181 | ||||
1182 | ObjCTypeParamList *ASTDeclReader::ReadObjCTypeParamList() { | |||
1183 | unsigned numParams = Record.readInt(); | |||
1184 | if (numParams == 0) | |||
1185 | return nullptr; | |||
1186 | ||||
1187 | SmallVector<ObjCTypeParamDecl *, 4> typeParams; | |||
1188 | typeParams.reserve(numParams); | |||
1189 | for (unsigned i = 0; i != numParams; ++i) { | |||
1190 | auto *typeParam = readDeclAs<ObjCTypeParamDecl>(); | |||
1191 | if (!typeParam) | |||
1192 | return nullptr; | |||
1193 | ||||
1194 | typeParams.push_back(typeParam); | |||
1195 | } | |||
1196 | ||||
1197 | SourceLocation lAngleLoc = readSourceLocation(); | |||
1198 | SourceLocation rAngleLoc = readSourceLocation(); | |||
1199 | ||||
1200 | return ObjCTypeParamList::create(Reader.getContext(), lAngleLoc, | |||
1201 | typeParams, rAngleLoc); | |||
1202 | } | |||
1203 | ||||
1204 | void ASTDeclReader::ReadObjCDefinitionData( | |||
1205 | struct ObjCInterfaceDecl::DefinitionData &Data) { | |||
1206 | // Read the superclass. | |||
1207 | Data.SuperClassTInfo = readTypeSourceInfo(); | |||
1208 | ||||
1209 | Data.EndLoc = readSourceLocation(); | |||
1210 | Data.HasDesignatedInitializers = Record.readInt(); | |||
1211 | Data.ODRHash = Record.readInt(); | |||
1212 | Data.HasODRHash = true; | |||
1213 | ||||
1214 | // Read the directly referenced protocols and their SourceLocations. | |||
1215 | unsigned NumProtocols = Record.readInt(); | |||
1216 | SmallVector<ObjCProtocolDecl *, 16> Protocols; | |||
1217 | Protocols.reserve(NumProtocols); | |||
1218 | for (unsigned I = 0; I != NumProtocols; ++I) | |||
1219 | Protocols.push_back(readDeclAs<ObjCProtocolDecl>()); | |||
1220 | SmallVector<SourceLocation, 16> ProtoLocs; | |||
1221 | ProtoLocs.reserve(NumProtocols); | |||
1222 | for (unsigned I = 0; I != NumProtocols; ++I) | |||
1223 | ProtoLocs.push_back(readSourceLocation()); | |||
1224 | Data.ReferencedProtocols.set(Protocols.data(), NumProtocols, ProtoLocs.data(), | |||
1225 | Reader.getContext()); | |||
1226 | ||||
1227 | // Read the transitive closure of protocols referenced by this class. | |||
1228 | NumProtocols = Record.readInt(); | |||
1229 | Protocols.clear(); | |||
1230 | Protocols.reserve(NumProtocols); | |||
1231 | for (unsigned I = 0; I != NumProtocols; ++I) | |||
1232 | Protocols.push_back(readDeclAs<ObjCProtocolDecl>()); | |||
1233 | Data.AllReferencedProtocols.set(Protocols.data(), NumProtocols, | |||
1234 | Reader.getContext()); | |||
1235 | } | |||
1236 | ||||
1237 | void ASTDeclReader::MergeDefinitionData(ObjCInterfaceDecl *D, | |||
1238 | struct ObjCInterfaceDecl::DefinitionData &&NewDD) { | |||
1239 | struct ObjCInterfaceDecl::DefinitionData &DD = D->data(); | |||
1240 | if (DD.Definition == NewDD.Definition) | |||
1241 | return; | |||
1242 | ||||
1243 | Reader.MergedDeclContexts.insert( | |||
1244 | std::make_pair(NewDD.Definition, DD.Definition)); | |||
1245 | Reader.mergeDefinitionVisibility(DD.Definition, NewDD.Definition); | |||
1246 | ||||
1247 | if (D->getODRHash() != NewDD.ODRHash) | |||
1248 | Reader.PendingObjCInterfaceOdrMergeFailures[DD.Definition].push_back( | |||
1249 | {NewDD.Definition, &NewDD}); | |||
1250 | } | |||
1251 | ||||
1252 | void ASTDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) { | |||
1253 | RedeclarableResult Redecl = VisitRedeclarable(ID); | |||
1254 | VisitObjCContainerDecl(ID); | |||
1255 | DeferredTypeID = Record.getGlobalTypeID(Record.readInt()); | |||
1256 | mergeRedeclarable(ID, Redecl); | |||
1257 | ||||
1258 | ID->TypeParamList = ReadObjCTypeParamList(); | |||
1259 | if (Record.readInt()) { | |||
1260 | // Read the definition. | |||
1261 | ID->allocateDefinitionData(); | |||
1262 | ||||
1263 | ReadObjCDefinitionData(ID->data()); | |||
1264 | ObjCInterfaceDecl *Canon = ID->getCanonicalDecl(); | |||
1265 | if (Canon->Data.getPointer()) { | |||
1266 | // If we already have a definition, keep the definition invariant and | |||
1267 | // merge the data. | |||
1268 | MergeDefinitionData(Canon, std::move(ID->data())); | |||
1269 | ID->Data = Canon->Data; | |||
1270 | } else { | |||
1271 | // Set the definition data of the canonical declaration, so other | |||
1272 | // redeclarations will see it. | |||
1273 | ID->getCanonicalDecl()->Data = ID->Data; | |||
1274 | ||||
1275 | // We will rebuild this list lazily. | |||
1276 | ID->setIvarList(nullptr); | |||
1277 | } | |||
1278 | ||||
1279 | // Note that we have deserialized a definition. | |||
1280 | Reader.PendingDefinitions.insert(ID); | |||
1281 | ||||
1282 | // Note that we've loaded this Objective-C class. | |||
1283 | Reader.ObjCClassesLoaded.push_back(ID); | |||
1284 | } else { | |||
1285 | ID->Data = ID->getCanonicalDecl()->Data; | |||
1286 | } | |||
1287 | } | |||
1288 | ||||
1289 | void ASTDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) { | |||
1290 | VisitFieldDecl(IVD); | |||
1291 | IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record.readInt()); | |||
1292 | // This field will be built lazily. | |||
1293 | IVD->setNextIvar(nullptr); | |||
1294 | bool synth = Record.readInt(); | |||
1295 | IVD->setSynthesize(synth); | |||
1296 | ||||
1297 | // Check ivar redeclaration. | |||
1298 | if (IVD->isInvalidDecl()) | |||
1299 | return; | |||
1300 | // Don't check ObjCInterfaceDecl as interfaces are named and mismatches can be | |||
1301 | // detected in VisitObjCInterfaceDecl. Here we are looking for redeclarations | |||
1302 | // in extensions. | |||
1303 | if (isa<ObjCInterfaceDecl>(IVD->getDeclContext())) | |||
1304 | return; | |||
1305 | ObjCInterfaceDecl *CanonIntf = | |||
1306 | IVD->getContainingInterface()->getCanonicalDecl(); | |||
1307 | IdentifierInfo *II = IVD->getIdentifier(); | |||
1308 | ObjCIvarDecl *PrevIvar = CanonIntf->lookupInstanceVariable(II); | |||
1309 | if (PrevIvar && PrevIvar != IVD) { | |||
1310 | auto *ParentExt = dyn_cast<ObjCCategoryDecl>(IVD->getDeclContext()); | |||
1311 | auto *PrevParentExt = | |||
1312 | dyn_cast<ObjCCategoryDecl>(PrevIvar->getDeclContext()); | |||
1313 | if (ParentExt && PrevParentExt) { | |||
1314 | // Postpone diagnostic as we should merge identical extensions from | |||
1315 | // different modules. | |||
1316 | Reader | |||
1317 | .PendingObjCExtensionIvarRedeclarations[std::make_pair(ParentExt, | |||
1318 | PrevParentExt)] | |||
1319 | .push_back(std::make_pair(IVD, PrevIvar)); | |||
1320 | } else if (ParentExt || PrevParentExt) { | |||
1321 | // Duplicate ivars in extension + implementation are never compatible. | |||
1322 | // Compatibility of implementation + implementation should be handled in | |||
1323 | // VisitObjCImplementationDecl. | |||
1324 | Reader.Diag(IVD->getLocation(), diag::err_duplicate_ivar_declaration) | |||
1325 | << II; | |||
1326 | Reader.Diag(PrevIvar->getLocation(), diag::note_previous_definition); | |||
1327 | } | |||
1328 | } | |||
1329 | } | |||
1330 | ||||
1331 | void ASTDeclReader::ReadObjCDefinitionData( | |||
1332 | struct ObjCProtocolDecl::DefinitionData &Data) { | |||
1333 | unsigned NumProtoRefs = Record.readInt(); | |||
1334 | SmallVector<ObjCProtocolDecl *, 16> ProtoRefs; | |||
1335 | ProtoRefs.reserve(NumProtoRefs); | |||
1336 | for (unsigned I = 0; I != NumProtoRefs; ++I) | |||
1337 | ProtoRefs.push_back(readDeclAs<ObjCProtocolDecl>()); | |||
1338 | SmallVector<SourceLocation, 16> ProtoLocs; | |||
1339 | ProtoLocs.reserve(NumProtoRefs); | |||
1340 | for (unsigned I = 0; I != NumProtoRefs; ++I) | |||
1341 | ProtoLocs.push_back(readSourceLocation()); | |||
1342 | Data.ReferencedProtocols.set(ProtoRefs.data(), NumProtoRefs, | |||
1343 | ProtoLocs.data(), Reader.getContext()); | |||
1344 | Data.ODRHash = Record.readInt(); | |||
1345 | Data.HasODRHash = true; | |||
1346 | } | |||
1347 | ||||
1348 | void ASTDeclReader::MergeDefinitionData( | |||
1349 | ObjCProtocolDecl *D, struct ObjCProtocolDecl::DefinitionData &&NewDD) { | |||
1350 | struct ObjCProtocolDecl::DefinitionData &DD = D->data(); | |||
1351 | if (DD.Definition == NewDD.Definition) | |||
1352 | return; | |||
1353 | ||||
1354 | Reader.MergedDeclContexts.insert( | |||
1355 | std::make_pair(NewDD.Definition, DD.Definition)); | |||
1356 | Reader.mergeDefinitionVisibility(DD.Definition, NewDD.Definition); | |||
1357 | ||||
1358 | if (D->getODRHash() != NewDD.ODRHash) | |||
1359 | Reader.PendingObjCProtocolOdrMergeFailures[DD.Definition].push_back( | |||
1360 | {NewDD.Definition, &NewDD}); | |||
1361 | } | |||
1362 | ||||
1363 | void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) { | |||
1364 | RedeclarableResult Redecl = VisitRedeclarable(PD); | |||
1365 | VisitObjCContainerDecl(PD); | |||
1366 | mergeRedeclarable(PD, Redecl); | |||
1367 | ||||
1368 | if (Record.readInt()) { | |||
1369 | // Read the definition. | |||
1370 | PD->allocateDefinitionData(); | |||
1371 | ||||
1372 | ReadObjCDefinitionData(PD->data()); | |||
1373 | ||||
1374 | ObjCProtocolDecl *Canon = PD->getCanonicalDecl(); | |||
1375 | if (Canon->Data.getPointer()) { | |||
1376 | // If we already have a definition, keep the definition invariant and | |||
1377 | // merge the data. | |||
1378 | MergeDefinitionData(Canon, std::move(PD->data())); | |||
1379 | PD->Data = Canon->Data; | |||
1380 | } else { | |||
1381 | // Set the definition data of the canonical declaration, so other | |||
1382 | // redeclarations will see it. | |||
1383 | PD->getCanonicalDecl()->Data = PD->Data; | |||
1384 | } | |||
1385 | // Note that we have deserialized a definition. | |||
1386 | Reader.PendingDefinitions.insert(PD); | |||
1387 | } else { | |||
1388 | PD->Data = PD->getCanonicalDecl()->Data; | |||
1389 | } | |||
1390 | } | |||
1391 | ||||
1392 | void ASTDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) { | |||
1393 | VisitFieldDecl(FD); | |||
1394 | } | |||
1395 | ||||
1396 | void ASTDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) { | |||
1397 | VisitObjCContainerDecl(CD); | |||
1398 | CD->setCategoryNameLoc(readSourceLocation()); | |||
1399 | CD->setIvarLBraceLoc(readSourceLocation()); | |||
1400 | CD->setIvarRBraceLoc(readSourceLocation()); | |||
1401 | ||||
1402 | // Note that this category has been deserialized. We do this before | |||
1403 | // deserializing the interface declaration, so that it will consider this | |||
1404 | /// category. | |||
1405 | Reader.CategoriesDeserialized.insert(CD); | |||
1406 | ||||
1407 | CD->ClassInterface = readDeclAs<ObjCInterfaceDecl>(); | |||
1408 | CD->TypeParamList = ReadObjCTypeParamList(); | |||
1409 | unsigned NumProtoRefs = Record.readInt(); | |||
1410 | SmallVector<ObjCProtocolDecl *, 16> ProtoRefs; | |||
1411 | ProtoRefs.reserve(NumProtoRefs); | |||
1412 | for (unsigned I = 0; I != NumProtoRefs; ++I) | |||
1413 | ProtoRefs.push_back(readDeclAs<ObjCProtocolDecl>()); | |||
1414 | SmallVector<SourceLocation, 16> ProtoLocs; | |||
1415 | ProtoLocs.reserve(NumProtoRefs); | |||
1416 | for (unsigned I = 0; I != NumProtoRefs; ++I) | |||
1417 | ProtoLocs.push_back(readSourceLocation()); | |||
1418 | CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(), | |||
1419 | Reader.getContext()); | |||
1420 | ||||
1421 | // Protocols in the class extension belong to the class. | |||
1422 | if (NumProtoRefs > 0 && CD->ClassInterface && CD->IsClassExtension()) | |||
1423 | CD->ClassInterface->mergeClassExtensionProtocolList( | |||
1424 | (ObjCProtocolDecl *const *)ProtoRefs.data(), NumProtoRefs, | |||
1425 | Reader.getContext()); | |||
1426 | } | |||
1427 | ||||
1428 | void ASTDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) { | |||
1429 | VisitNamedDecl(CAD); | |||
1430 | CAD->setClassInterface(readDeclAs<ObjCInterfaceDecl>()); | |||
1431 | } | |||
1432 | ||||
1433 | void ASTDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { | |||
1434 | VisitNamedDecl(D); | |||
1435 | D->setAtLoc(readSourceLocation()); | |||
1436 | D->setLParenLoc(readSourceLocation()); | |||
1437 | QualType T = Record.readType(); | |||
1438 | TypeSourceInfo *TSI = readTypeSourceInfo(); | |||
1439 | D->setType(T, TSI); | |||
1440 | D->setPropertyAttributes((ObjCPropertyAttribute::Kind)Record.readInt()); | |||
1441 | D->setPropertyAttributesAsWritten( | |||
1442 | (ObjCPropertyAttribute::Kind)Record.readInt()); | |||
1443 | D->setPropertyImplementation( | |||
1444 | (ObjCPropertyDecl::PropertyControl)Record.readInt()); | |||
1445 | DeclarationName GetterName = Record.readDeclarationName(); | |||
1446 | SourceLocation GetterLoc = readSourceLocation(); | |||
1447 | D->setGetterName(GetterName.getObjCSelector(), GetterLoc); | |||
1448 | DeclarationName SetterName = Record.readDeclarationName(); | |||
1449 | SourceLocation SetterLoc = readSourceLocation(); | |||
1450 | D->setSetterName(SetterName.getObjCSelector(), SetterLoc); | |||
1451 | D->setGetterMethodDecl(readDeclAs<ObjCMethodDecl>()); | |||
1452 | D->setSetterMethodDecl(readDeclAs<ObjCMethodDecl>()); | |||
1453 | D->setPropertyIvarDecl(readDeclAs<ObjCIvarDecl>()); | |||
1454 | } | |||
1455 | ||||
1456 | void ASTDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) { | |||
1457 | VisitObjCContainerDecl(D); | |||
1458 | D->setClassInterface(readDeclAs<ObjCInterfaceDecl>()); | |||
1459 | } | |||
1460 | ||||
1461 | void ASTDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { | |||
1462 | VisitObjCImplDecl(D); | |||
1463 | D->CategoryNameLoc = readSourceLocation(); | |||
1464 | } | |||
1465 | ||||
1466 | void ASTDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { | |||
1467 | VisitObjCImplDecl(D); | |||
1468 | D->setSuperClass(readDeclAs<ObjCInterfaceDecl>()); | |||
1469 | D->SuperLoc = readSourceLocation(); | |||
1470 | D->setIvarLBraceLoc(readSourceLocation()); | |||
1471 | D->setIvarRBraceLoc(readSourceLocation()); | |||
1472 | D->setHasNonZeroConstructors(Record.readInt()); | |||
1473 | D->setHasDestructors(Record.readInt()); | |||
1474 | D->NumIvarInitializers = Record.readInt(); | |||
1475 | if (D->NumIvarInitializers) | |||
1476 | D->IvarInitializers = ReadGlobalOffset(); | |||
1477 | } | |||
1478 | ||||
1479 | void ASTDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { | |||
1480 | VisitDecl(D); | |||
1481 | D->setAtLoc(readSourceLocation()); | |||
1482 | D->setPropertyDecl(readDeclAs<ObjCPropertyDecl>()); | |||
1483 | D->PropertyIvarDecl = readDeclAs<ObjCIvarDecl>(); | |||
1484 | D->IvarLoc = readSourceLocation(); | |||
1485 | D->setGetterMethodDecl(readDeclAs<ObjCMethodDecl>()); | |||
1486 | D->setSetterMethodDecl(readDeclAs<ObjCMethodDecl>()); | |||
1487 | D->setGetterCXXConstructor(Record.readExpr()); | |||
1488 | D->setSetterCXXAssignment(Record.readExpr()); | |||
1489 | } | |||
1490 | ||||
1491 | void ASTDeclReader::VisitFieldDecl(FieldDecl *FD) { | |||
1492 | VisitDeclaratorDecl(FD); | |||
1493 | FD->Mutable = Record.readInt(); | |||
1494 | ||||
1495 | if (auto ISK = static_cast<FieldDecl::InitStorageKind>(Record.readInt())) { | |||
1496 | FD->InitStorage.setInt(ISK); | |||
1497 | FD->InitStorage.setPointer(ISK == FieldDecl::ISK_CapturedVLAType | |||
1498 | ? Record.readType().getAsOpaquePtr() | |||
1499 | : Record.readExpr()); | |||
1500 | } | |||
1501 | ||||
1502 | if (auto *BW = Record.readExpr()) | |||
1503 | FD->setBitWidth(BW); | |||
1504 | ||||
1505 | if (!FD->getDeclName()) { | |||
1506 | if (auto *Tmpl = readDeclAs<FieldDecl>()) | |||
1507 | Reader.getContext().setInstantiatedFromUnnamedFieldDecl(FD, Tmpl); | |||
1508 | } | |||
1509 | mergeMergeable(FD); | |||
1510 | } | |||
1511 | ||||
1512 | void ASTDeclReader::VisitMSPropertyDecl(MSPropertyDecl *PD) { | |||
1513 | VisitDeclaratorDecl(PD); | |||
1514 | PD->GetterId = Record.readIdentifier(); | |||
1515 | PD->SetterId = Record.readIdentifier(); | |||
1516 | } | |||
1517 | ||||
1518 | void ASTDeclReader::VisitMSGuidDecl(MSGuidDecl *D) { | |||
1519 | VisitValueDecl(D); | |||
1520 | D->PartVal.Part1 = Record.readInt(); | |||
1521 | D->PartVal.Part2 = Record.readInt(); | |||
1522 | D->PartVal.Part3 = Record.readInt(); | |||
1523 | for (auto &C : D->PartVal.Part4And5) | |||
1524 | C = Record.readInt(); | |||
1525 | ||||
1526 | // Add this GUID to the AST context's lookup structure, and merge if needed. | |||
1527 | if (MSGuidDecl *Existing = Reader.getContext().MSGuidDecls.GetOrInsertNode(D)) | |||
1528 | Reader.getContext().setPrimaryMergedDecl(D, Existing->getCanonicalDecl()); | |||
1529 | } | |||
1530 | ||||
1531 | void ASTDeclReader::VisitUnnamedGlobalConstantDecl( | |||
1532 | UnnamedGlobalConstantDecl *D) { | |||
1533 | VisitValueDecl(D); | |||
1534 | D->Value = Record.readAPValue(); | |||
1535 | ||||
1536 | // Add this to the AST context's lookup structure, and merge if needed. | |||
1537 | if (UnnamedGlobalConstantDecl *Existing = | |||
1538 | Reader.getContext().UnnamedGlobalConstantDecls.GetOrInsertNode(D)) | |||
1539 | Reader.getContext().setPrimaryMergedDecl(D, Existing->getCanonicalDecl()); | |||
1540 | } | |||
1541 | ||||
1542 | void ASTDeclReader::VisitTemplateParamObjectDecl(TemplateParamObjectDecl *D) { | |||
1543 | VisitValueDecl(D); | |||
1544 | D->Value = Record.readAPValue(); | |||
1545 | ||||
1546 | // Add this template parameter object to the AST context's lookup structure, | |||
1547 | // and merge if needed. | |||
1548 | if (TemplateParamObjectDecl *Existing = | |||
1549 | Reader.getContext().TemplateParamObjectDecls.GetOrInsertNode(D)) | |||
1550 | Reader.getContext().setPrimaryMergedDecl(D, Existing->getCanonicalDecl()); | |||
1551 | } | |||
1552 | ||||
1553 | void ASTDeclReader::VisitIndirectFieldDecl(IndirectFieldDecl *FD) { | |||
1554 | VisitValueDecl(FD); | |||
1555 | ||||
1556 | FD->ChainingSize = Record.readInt(); | |||
1557 | assert(FD->ChainingSize >= 2 && "Anonymous chaining must be >= 2")(static_cast <bool> (FD->ChainingSize >= 2 && "Anonymous chaining must be >= 2") ? void (0) : __assert_fail ("FD->ChainingSize >= 2 && \"Anonymous chaining must be >= 2\"" , "clang/lib/Serialization/ASTReaderDecl.cpp", 1557, __extension__ __PRETTY_FUNCTION__)); | |||
1558 | FD->Chaining = new (Reader.getContext())NamedDecl*[FD->ChainingSize]; | |||
1559 | ||||
1560 | for (unsigned I = 0; I != FD->ChainingSize; ++I) | |||
1561 | FD->Chaining[I] = readDeclAs<NamedDecl>(); | |||
1562 | ||||
1563 | mergeMergeable(FD); | |||
1564 | } | |||
1565 | ||||
1566 | ASTDeclReader::RedeclarableResult ASTDeclReader::VisitVarDeclImpl(VarDecl *VD) { | |||
1567 | RedeclarableResult Redecl = VisitRedeclarable(VD); | |||
1568 | VisitDeclaratorDecl(VD); | |||
1569 | ||||
1570 | VD->VarDeclBits.SClass = (StorageClass)Record.readInt(); | |||
1571 | VD->VarDeclBits.TSCSpec = Record.readInt(); | |||
1572 | VD->VarDeclBits.InitStyle = Record.readInt(); | |||
1573 | VD->VarDeclBits.ARCPseudoStrong = Record.readInt(); | |||
1574 | if (!isa<ParmVarDecl>(VD)) { | |||
1575 | VD->NonParmVarDeclBits.IsThisDeclarationADemotedDefinition = | |||
1576 | Record.readInt(); | |||
1577 | VD->NonParmVarDeclBits.ExceptionVar = Record.readInt(); | |||
1578 | VD->NonParmVarDeclBits.NRVOVariable = Record.readInt(); | |||
1579 | VD->NonParmVarDeclBits.CXXForRangeDecl = Record.readInt(); | |||
1580 | VD->NonParmVarDeclBits.ObjCForDecl = Record.readInt(); | |||
1581 | VD->NonParmVarDeclBits.IsInline = Record.readInt(); | |||
1582 | VD->NonParmVarDeclBits.IsInlineSpecified = Record.readInt(); | |||
1583 | VD->NonParmVarDeclBits.IsConstexpr = Record.readInt(); | |||
1584 | VD->NonParmVarDeclBits.IsInitCapture = Record.readInt(); | |||
1585 | VD->NonParmVarDeclBits.PreviousDeclInSameBlockScope = Record.readInt(); | |||
1586 | VD->NonParmVarDeclBits.ImplicitParamKind = Record.readInt(); | |||
1587 | VD->NonParmVarDeclBits.EscapingByref = Record.readInt(); | |||
1588 | } | |||
1589 | auto VarLinkage = Linkage(Record.readInt()); | |||
1590 | VD->setCachedLinkage(VarLinkage); | |||
1591 | ||||
1592 | // Reconstruct the one piece of the IdentifierNamespace that we need. | |||
1593 | if (VD->getStorageClass() == SC_Extern && VarLinkage != NoLinkage && | |||
1594 | VD->getLexicalDeclContext()->isFunctionOrMethod()) | |||
1595 | VD->setLocalExternDecl(); | |||
1596 | ||||
1597 | if (uint64_t Val = Record.readInt()) { | |||
1598 | VD->setInit(Record.readExpr()); | |||
1599 | if (Val != 1) { | |||
1600 | EvaluatedStmt *Eval = VD->ensureEvaluatedStmt(); | |||
1601 | Eval->HasConstantInitialization = (Val & 2) != 0; | |||
1602 | Eval->HasConstantDestruction = (Val & 4) != 0; | |||
1603 | } | |||
1604 | } | |||
1605 | ||||
1606 | if (VD->hasAttr<BlocksAttr>() && VD->getType()->getAsCXXRecordDecl()) { | |||
1607 | Expr *CopyExpr = Record.readExpr(); | |||
1608 | if (CopyExpr) | |||
1609 | Reader.getContext().setBlockVarCopyInit(VD, CopyExpr, Record.readInt()); | |||
1610 | } | |||
1611 | ||||
1612 | if (VD->getStorageDuration() == SD_Static && Record.readInt()) { | |||
1613 | Reader.DefinitionSource[VD] = | |||
1614 | Loc.F->Kind == ModuleKind::MK_MainFile || | |||
1615 | Reader.getContext().getLangOpts().BuildingPCHWithObjectFile; | |||
1616 | } | |||
1617 | ||||
1618 | enum VarKind { | |||
1619 | VarNotTemplate = 0, VarTemplate, StaticDataMemberSpecialization | |||
1620 | }; | |||
1621 | switch ((VarKind)Record.readInt()) { | |||
1622 | case VarNotTemplate: | |||
1623 | // Only true variables (not parameters or implicit parameters) can be | |||
1624 | // merged; the other kinds are not really redeclarable at all. | |||
1625 | if (!isa<ParmVarDecl>(VD) && !isa<ImplicitParamDecl>(VD) && | |||
1626 | !isa<VarTemplateSpecializationDecl>(VD)) | |||
1627 | mergeRedeclarable(VD, Redecl); | |||
1628 | break; | |||
1629 | case VarTemplate: | |||
1630 | // Merged when we merge the template. | |||
1631 | VD->setDescribedVarTemplate(readDeclAs<VarTemplateDecl>()); | |||
1632 | break; | |||
1633 | case StaticDataMemberSpecialization: { // HasMemberSpecializationInfo. | |||
1634 | auto *Tmpl = readDeclAs<VarDecl>(); | |||
1635 | auto TSK = (TemplateSpecializationKind)Record.readInt(); | |||
1636 | SourceLocation POI = readSourceLocation(); | |||
1637 | Reader.getContext().setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI); | |||
1638 | mergeRedeclarable(VD, Redecl); | |||
1639 | break; | |||
1640 | } | |||
1641 | } | |||
1642 | ||||
1643 | return Redecl; | |||
1644 | } | |||
1645 | ||||
1646 | void ASTDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) { | |||
1647 | VisitVarDecl(PD); | |||
1648 | } | |||
1649 | ||||
1650 | void ASTDeclReader::VisitParmVarDecl(ParmVarDecl *PD) { | |||
1651 | VisitVarDecl(PD); | |||
1652 | unsigned isObjCMethodParam = Record.readInt(); | |||
1653 | unsigned scopeDepth = Record.readInt(); | |||
1654 | unsigned scopeIndex = Record.readInt(); | |||
1655 | unsigned declQualifier = Record.readInt(); | |||
1656 | if (isObjCMethodParam) { | |||
1657 | assert(scopeDepth == 0)(static_cast <bool> (scopeDepth == 0) ? void (0) : __assert_fail ("scopeDepth == 0", "clang/lib/Serialization/ASTReaderDecl.cpp" , 1657, __extension__ __PRETTY_FUNCTION__)); | |||
1658 | PD->setObjCMethodScopeInfo(scopeIndex); | |||
1659 | PD->ParmVarDeclBits.ScopeDepthOrObjCQuals = declQualifier; | |||
1660 | } else { | |||
1661 | PD->setScopeInfo(scopeDepth, scopeIndex); | |||
1662 | } | |||
1663 | PD->ParmVarDeclBits.IsKNRPromoted = Record.readInt(); | |||
1664 | PD->ParmVarDeclBits.HasInheritedDefaultArg = Record.readInt(); | |||
1665 | if (Record.readInt()) // hasUninstantiatedDefaultArg. | |||
1666 | PD->setUninstantiatedDefaultArg(Record.readExpr()); | |||
1667 | ||||
1668 | // FIXME: If this is a redeclaration of a function from another module, handle | |||
1669 | // inheritance of default arguments. | |||
1670 | } | |||
1671 | ||||
1672 | void ASTDeclReader::VisitDecompositionDecl(DecompositionDecl *DD) { | |||
1673 | VisitVarDecl(DD); | |||
1674 | auto **BDs = DD->getTrailingObjects<BindingDecl *>(); | |||
1675 | for (unsigned I = 0; I != DD->NumBindings; ++I) { | |||
1676 | BDs[I] = readDeclAs<BindingDecl>(); | |||
1677 | BDs[I]->setDecomposedDecl(DD); | |||
1678 | } | |||
1679 | } | |||
1680 | ||||
1681 | void ASTDeclReader::VisitBindingDecl(BindingDecl *BD) { | |||
1682 | VisitValueDecl(BD); | |||
1683 | BD->Binding = Record.readExpr(); | |||
1684 | } | |||
1685 | ||||
1686 | void ASTDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) { | |||
1687 | VisitDecl(AD); | |||
1688 | AD->setAsmString(cast<StringLiteral>(Record.readExpr())); | |||
1689 | AD->setRParenLoc(readSourceLocation()); | |||
1690 | } | |||
1691 | ||||
1692 | void ASTDeclReader::VisitTopLevelStmtDecl(TopLevelStmtDecl *D) { | |||
1693 | VisitDecl(D); | |||
1694 | D->Statement = Record.readStmt(); | |||
1695 | } | |||
1696 | ||||
1697 | void ASTDeclReader::VisitBlockDecl(BlockDecl *BD) { | |||
1698 | VisitDecl(BD); | |||
1699 | BD->setBody(cast_or_null<CompoundStmt>(Record.readStmt())); | |||
1700 | BD->setSignatureAsWritten(readTypeSourceInfo()); | |||
1701 | unsigned NumParams = Record.readInt(); | |||
1702 | SmallVector<ParmVarDecl *, 16> Params; | |||
1703 | Params.reserve(NumParams); | |||
1704 | for (unsigned I = 0; I != NumParams; ++I) | |||
1705 | Params.push_back(readDeclAs<ParmVarDecl>()); | |||
1706 | BD->setParams(Params); | |||
1707 | ||||
1708 | BD->setIsVariadic(Record.readInt()); | |||
1709 | BD->setBlockMissingReturnType(Record.readInt()); | |||
1710 | BD->setIsConversionFromLambda(Record.readInt()); | |||
1711 | BD->setDoesNotEscape(Record.readInt()); | |||
1712 | BD->setCanAvoidCopyToHeap(Record.readInt()); | |||
1713 | ||||
1714 | bool capturesCXXThis = Record.readInt(); | |||
1715 | unsigned numCaptures = Record.readInt(); | |||
1716 | SmallVector<BlockDecl::Capture, 16> captures; | |||
1717 | captures.reserve(numCaptures); | |||
1718 | for (unsigned i = 0; i != numCaptures; ++i) { | |||
1719 | auto *decl = readDeclAs<VarDecl>(); | |||
1720 | unsigned flags = Record.readInt(); | |||
1721 | bool byRef = (flags & 1); | |||
1722 | bool nested = (flags & 2); | |||
1723 | Expr *copyExpr = ((flags & 4) ? Record.readExpr() : nullptr); | |||
1724 | ||||
1725 | captures.push_back(BlockDecl::Capture(decl, byRef, nested, copyExpr)); | |||
1726 | } | |||
1727 | BD->setCaptures(Reader.getContext(), captures, capturesCXXThis); | |||
1728 | } | |||
1729 | ||||
1730 | void ASTDeclReader::VisitCapturedDecl(CapturedDecl *CD) { | |||
1731 | VisitDecl(CD); | |||
1732 | unsigned ContextParamPos = Record.readInt(); | |||
1733 | CD->setNothrow(Record.readInt() != 0); | |||
1734 | // Body is set by VisitCapturedStmt. | |||
1735 | for (unsigned I = 0; I < CD->NumParams; ++I) { | |||
1736 | if (I != ContextParamPos) | |||
1737 | CD->setParam(I, readDeclAs<ImplicitParamDecl>()); | |||
1738 | else | |||
1739 | CD->setContextParam(I, readDeclAs<ImplicitParamDecl>()); | |||
1740 | } | |||
1741 | } | |||
1742 | ||||
1743 | void ASTDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) { | |||
1744 | VisitDecl(D); | |||
1745 | D->setLanguage((LinkageSpecDecl::LanguageIDs)Record.readInt()); | |||
1746 | D->setExternLoc(readSourceLocation()); | |||
1747 | D->setRBraceLoc(readSourceLocation()); | |||
1748 | } | |||
1749 | ||||
1750 | void ASTDeclReader::VisitExportDecl(ExportDecl *D) { | |||
1751 | VisitDecl(D); | |||
1752 | D->RBraceLoc = readSourceLocation(); | |||
1753 | } | |||
1754 | ||||
1755 | void ASTDeclReader::VisitLabelDecl(LabelDecl *D) { | |||
1756 | VisitNamedDecl(D); | |||
1757 | D->setLocStart(readSourceLocation()); | |||
1758 | } | |||
1759 | ||||
1760 | void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl *D) { | |||
1761 | RedeclarableResult Redecl = VisitRedeclarable(D); | |||
1762 | VisitNamedDecl(D); | |||
1763 | D->setInline(Record.readInt()); | |||
1764 | D->setNested(Record.readInt()); | |||
1765 | D->LocStart = readSourceLocation(); | |||
1766 | D->RBraceLoc = readSourceLocation(); | |||
1767 | ||||
1768 | // Defer loading the anonymous namespace until we've finished merging | |||
1769 | // this namespace; loading it might load a later declaration of the | |||
1770 | // same namespace, and we have an invariant that older declarations | |||
1771 | // get merged before newer ones try to merge. | |||
1772 | GlobalDeclID AnonNamespace = 0; | |||
1773 | if (Redecl.getFirstID() == ThisDeclID) { | |||
1774 | AnonNamespace = readDeclID(); | |||
1775 | } else { | |||
1776 | // Link this namespace back to the first declaration, which has already | |||
1777 | // been deserialized. | |||
1778 | D->AnonOrFirstNamespaceAndFlags.setPointer(D->getFirstDecl()); | |||
1779 | } | |||
1780 | ||||
1781 | mergeRedeclarable(D, Redecl); | |||
1782 | ||||
1783 | if (AnonNamespace) { | |||
1784 | // Each module has its own anonymous namespace, which is disjoint from | |||
1785 | // any other module's anonymous namespaces, so don't attach the anonymous | |||
1786 | // namespace at all. | |||
1787 | auto *Anon = cast<NamespaceDecl>(Reader.GetDecl(AnonNamespace)); | |||
1788 | if (!Record.isModule()) | |||
1789 | D->setAnonymousNamespace(Anon); | |||
1790 | } | |||
1791 | } | |||
1792 | ||||
1793 | void ASTDeclReader::VisitHLSLBufferDecl(HLSLBufferDecl *D) { | |||
1794 | VisitNamedDecl(D); | |||
1795 | VisitDeclContext(D); | |||
1796 | D->IsCBuffer = Record.readBool(); | |||
1797 | D->KwLoc = readSourceLocation(); | |||
1798 | D->LBraceLoc = readSourceLocation(); | |||
1799 | D->RBraceLoc = readSourceLocation(); | |||
1800 | } | |||
1801 | ||||
1802 | void ASTDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { | |||
1803 | RedeclarableResult Redecl = VisitRedeclarable(D); | |||
1804 | VisitNamedDecl(D); | |||
1805 | D->NamespaceLoc = readSourceLocation(); | |||
1806 | D->IdentLoc = readSourceLocation(); | |||
1807 | D->QualifierLoc = Record.readNestedNameSpecifierLoc(); | |||
1808 | D->Namespace = readDeclAs<NamedDecl>(); | |||
1809 | mergeRedeclarable(D, Redecl); | |||
1810 | } | |||
1811 | ||||
1812 | void ASTDeclReader::VisitUsingDecl(UsingDecl *D) { | |||
1813 | VisitNamedDecl(D); | |||
1814 | D->setUsingLoc(readSourceLocation()); | |||
1815 | D->QualifierLoc = Record.readNestedNameSpecifierLoc(); | |||
1816 | D->DNLoc = Record.readDeclarationNameLoc(D->getDeclName()); | |||
1817 | D->FirstUsingShadow.setPointer(readDeclAs<UsingShadowDecl>()); | |||
1818 | D->setTypename(Record.readInt()); | |||
1819 | if (auto *Pattern = readDeclAs<NamedDecl>()) | |||
1820 | Reader.getContext().setInstantiatedFromUsingDecl(D, Pattern); | |||
1821 | mergeMergeable(D); | |||
1822 | } | |||
1823 | ||||
1824 | void ASTDeclReader::VisitUsingEnumDecl(UsingEnumDecl *D) { | |||
1825 | VisitNamedDecl(D); | |||
1826 | D->setUsingLoc(readSourceLocation()); | |||
1827 | D->setEnumLoc(readSourceLocation()); | |||
1828 | D->setEnumType(Record.readTypeSourceInfo()); | |||
1829 | D->FirstUsingShadow.setPointer(readDeclAs<UsingShadowDecl>()); | |||
1830 | if (auto *Pattern = readDeclAs<UsingEnumDecl>()) | |||
1831 | Reader.getContext().setInstantiatedFromUsingEnumDecl(D, Pattern); | |||
1832 | mergeMergeable(D); | |||
1833 | } | |||
1834 | ||||
1835 | void ASTDeclReader::VisitUsingPackDecl(UsingPackDecl *D) { | |||
1836 | VisitNamedDecl(D); | |||
1837 | D->InstantiatedFrom = readDeclAs<NamedDecl>(); | |||
1838 | auto **Expansions = D->getTrailingObjects<NamedDecl *>(); | |||
1839 | for (unsigned I = 0; I != D->NumExpansions; ++I) | |||
1840 | Expansions[I] = readDeclAs<NamedDecl>(); | |||
1841 | mergeMergeable(D); | |||
1842 | } | |||
1843 | ||||
1844 | void ASTDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) { | |||
1845 | RedeclarableResult Redecl = VisitRedeclarable(D); | |||
1846 | VisitNamedDecl(D); | |||
1847 | D->Underlying = readDeclAs<NamedDecl>(); | |||
1848 | D->IdentifierNamespace = Record.readInt(); | |||
1849 | D->UsingOrNextShadow = readDeclAs<NamedDecl>(); | |||
1850 | auto *Pattern = readDeclAs<UsingShadowDecl>(); | |||
1851 | if (Pattern) | |||
1852 | Reader.getContext().setInstantiatedFromUsingShadowDecl(D, Pattern); | |||
1853 | mergeRedeclarable(D, Redecl); | |||
1854 | } | |||
1855 | ||||
1856 | void ASTDeclReader::VisitConstructorUsingShadowDecl( | |||
1857 | ConstructorUsingShadowDecl *D) { | |||
1858 | VisitUsingShadowDecl(D); | |||
1859 | D->NominatedBaseClassShadowDecl = readDeclAs<ConstructorUsingShadowDecl>(); | |||
1860 | D->ConstructedBaseClassShadowDecl = readDeclAs<ConstructorUsingShadowDecl>(); | |||
1861 | D->IsVirtual = Record.readInt(); | |||
1862 | } | |||
1863 | ||||
1864 | void ASTDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { | |||
1865 | VisitNamedDecl(D); | |||
1866 | D->UsingLoc = readSourceLocation(); | |||
1867 | D->NamespaceLoc = readSourceLocation(); | |||
1868 | D->QualifierLoc = Record.readNestedNameSpecifierLoc(); | |||
1869 | D->NominatedNamespace = readDeclAs<NamedDecl>(); | |||
1870 | D->CommonAncestor = readDeclAs<DeclContext>(); | |||
1871 | } | |||
1872 | ||||
1873 | void ASTDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) { | |||
1874 | VisitValueDecl(D); | |||
1875 | D->setUsingLoc(readSourceLocation()); | |||
1876 | D->QualifierLoc = Record.readNestedNameSpecifierLoc(); | |||
1877 | D->DNLoc = Record.readDeclarationNameLoc(D->getDeclName()); | |||
1878 | D->EllipsisLoc = readSourceLocation(); | |||
1879 | mergeMergeable(D); | |||
1880 | } | |||
1881 | ||||
1882 | void ASTDeclReader::VisitUnresolvedUsingTypenameDecl( | |||
1883 | UnresolvedUsingTypenameDecl *D) { | |||
1884 | VisitTypeDecl(D); | |||
1885 | D->TypenameLocation = readSourceLocation(); | |||
1886 | D->QualifierLoc = Record.readNestedNameSpecifierLoc(); | |||
1887 | D->EllipsisLoc = readSourceLocation(); | |||
1888 | mergeMergeable(D); | |||
1889 | } | |||
1890 | ||||
1891 | void ASTDeclReader::VisitUnresolvedUsingIfExistsDecl( | |||
1892 | UnresolvedUsingIfExistsDecl *D) { | |||
1893 | VisitNamedDecl(D); | |||
1894 | } | |||
1895 | ||||
1896 | void ASTDeclReader::ReadCXXDefinitionData( | |||
1897 | struct CXXRecordDecl::DefinitionData &Data, const CXXRecordDecl *D) { | |||
1898 | #define FIELD(Name, Width, Merge) \ | |||
1899 | Data.Name = Record.readInt(); | |||
1900 | #include "clang/AST/CXXRecordDeclDefinitionBits.def" | |||
1901 | ||||
1902 | // Note: the caller has deserialized the IsLambda bit already. | |||
1903 | Data.ODRHash = Record.readInt(); | |||
1904 | Data.HasODRHash = true; | |||
1905 | ||||
1906 | if (Record.readInt()) { | |||
1907 | Reader.DefinitionSource[D] = | |||
1908 | Loc.F->Kind == ModuleKind::MK_MainFile || | |||
1909 | Reader.getContext().getLangOpts().BuildingPCHWithObjectFile; | |||
1910 | } | |||
1911 | ||||
1912 | Data.NumBases = Record.readInt(); | |||
1913 | if (Data.NumBases) | |||
1914 | Data.Bases = ReadGlobalOffset(); | |||
1915 | Data.NumVBases = Record.readInt(); | |||
1916 | if (Data.NumVBases) | |||
1917 | Data.VBases = ReadGlobalOffset(); | |||
1918 | ||||
1919 | Record.readUnresolvedSet(Data.Conversions); | |||
1920 | Data.ComputedVisibleConversions = Record.readInt(); | |||
1921 | if (Data.ComputedVisibleConversions) | |||
1922 | Record.readUnresolvedSet(Data.VisibleConversions); | |||
1923 | assert(Data.Definition && "Data.Definition should be already set!")(static_cast <bool> (Data.Definition && "Data.Definition should be already set!" ) ? void (0) : __assert_fail ("Data.Definition && \"Data.Definition should be already set!\"" , "clang/lib/Serialization/ASTReaderDecl.cpp", 1923, __extension__ __PRETTY_FUNCTION__)); | |||
1924 | Data.FirstFriend = readDeclID(); | |||
1925 | ||||
1926 | if (Data.IsLambda) { | |||
1927 | using Capture = LambdaCapture; | |||
1928 | ||||
1929 | auto &Lambda = static_cast<CXXRecordDecl::LambdaDefinitionData &>(Data); | |||
1930 | Lambda.DependencyKind = Record.readInt(); | |||
1931 | Lambda.IsGenericLambda = Record.readInt(); | |||
1932 | Lambda.CaptureDefault = Record.readInt(); | |||
1933 | Lambda.NumCaptures = Record.readInt(); | |||
1934 | Lambda.NumExplicitCaptures = Record.readInt(); | |||
1935 | Lambda.HasKnownInternalLinkage = Record.readInt(); | |||
1936 | Lambda.ManglingNumber = Record.readInt(); | |||
1937 | D->setDeviceLambdaManglingNumber(Record.readInt()); | |||
1938 | Lambda.ContextDecl = readDeclID(); | |||
1939 | Capture *ToCapture = nullptr; | |||
1940 | if (Lambda.NumCaptures) { | |||
1941 | ToCapture = (Capture *)Reader.getContext().Allocate(sizeof(Capture) * | |||
1942 | Lambda.NumCaptures); | |||
1943 | Lambda.AddCaptureList(Reader.getContext(), ToCapture); | |||
1944 | } | |||
1945 | Lambda.MethodTyInfo = readTypeSourceInfo(); | |||
1946 | for (unsigned I = 0, N = Lambda.NumCaptures; I != N; ++I) { | |||
1947 | SourceLocation Loc = readSourceLocation(); | |||
1948 | bool IsImplicit = Record.readInt(); | |||
1949 | auto Kind = static_cast<LambdaCaptureKind>(Record.readInt()); | |||
1950 | switch (Kind) { | |||
1951 | case LCK_StarThis: | |||
1952 | case LCK_This: | |||
1953 | case LCK_VLAType: | |||
1954 | *ToCapture++ = Capture(Loc, IsImplicit, Kind, nullptr,SourceLocation()); | |||
1955 | break; | |||
1956 | case LCK_ByCopy: | |||
1957 | case LCK_ByRef: | |||
1958 | auto *Var = readDeclAs<VarDecl>(); | |||
1959 | SourceLocation EllipsisLoc = readSourceLocation(); | |||
1960 | *ToCapture++ = Capture(Loc, IsImplicit, Kind, Var, EllipsisLoc); | |||
1961 | break; | |||
1962 | } | |||
1963 | } | |||
1964 | } | |||
1965 | } | |||
1966 | ||||
1967 | void ASTDeclReader::MergeDefinitionData( | |||
1968 | CXXRecordDecl *D, struct CXXRecordDecl::DefinitionData &&MergeDD) { | |||
1969 | assert(D->DefinitionData &&(static_cast <bool> (D->DefinitionData && "merging class definition into non-definition" ) ? void (0) : __assert_fail ("D->DefinitionData && \"merging class definition into non-definition\"" , "clang/lib/Serialization/ASTReaderDecl.cpp", 1970, __extension__ __PRETTY_FUNCTION__)) | |||
1970 | "merging class definition into non-definition")(static_cast <bool> (D->DefinitionData && "merging class definition into non-definition" ) ? void (0) : __assert_fail ("D->DefinitionData && \"merging class definition into non-definition\"" , "clang/lib/Serialization/ASTReaderDecl.cpp", 1970, __extension__ __PRETTY_FUNCTION__)); | |||
1971 | auto &DD = *D->DefinitionData; | |||
1972 | ||||
1973 | if (DD.Definition != MergeDD.Definition) { | |||
1974 | // Track that we merged the definitions. | |||
1975 | Reader.MergedDeclContexts.insert(std::make_pair(MergeDD.Definition, | |||
1976 | DD.Definition)); | |||
1977 | Reader.PendingDefinitions.erase(MergeDD.Definition); | |||
1978 | MergeDD.Definition->setCompleteDefinition(false); | |||
1979 | Reader.mergeDefinitionVisibility(DD.Definition, MergeDD.Definition); | |||
1980 | assert(!Reader.Lookups.contains(MergeDD.Definition) &&(static_cast <bool> (!Reader.Lookups.contains(MergeDD.Definition ) && "already loaded pending lookups for merged definition" ) ? void (0) : __assert_fail ("!Reader.Lookups.contains(MergeDD.Definition) && \"already loaded pending lookups for merged definition\"" , "clang/lib/Serialization/ASTReaderDecl.cpp", 1981, __extension__ __PRETTY_FUNCTION__)) | |||
1981 | "already loaded pending lookups for merged definition")(static_cast <bool> (!Reader.Lookups.contains(MergeDD.Definition ) && "already loaded pending lookups for merged definition" ) ? void (0) : __assert_fail ("!Reader.Lookups.contains(MergeDD.Definition) && \"already loaded pending lookups for merged definition\"" , "clang/lib/Serialization/ASTReaderDecl.cpp", 1981, __extension__ __PRETTY_FUNCTION__)); | |||
1982 | } | |||
1983 | ||||
1984 | auto PFDI = Reader.PendingFakeDefinitionData.find(&DD); | |||
1985 | if (PFDI != Reader.PendingFakeDefinitionData.end() && | |||
1986 | PFDI->second == ASTReader::PendingFakeDefinitionKind::Fake) { | |||
1987 | // We faked up this definition data because we found a class for which we'd | |||
1988 | // not yet loaded the definition. Replace it with the real thing now. | |||
1989 | assert(!DD.IsLambda && !MergeDD.IsLambda && "faked up lambda definition?")(static_cast <bool> (!DD.IsLambda && !MergeDD.IsLambda && "faked up lambda definition?") ? void (0) : __assert_fail ("!DD.IsLambda && !MergeDD.IsLambda && \"faked up lambda definition?\"" , "clang/lib/Serialization/ASTReaderDecl.cpp", 1989, __extension__ __PRETTY_FUNCTION__)); | |||
1990 | PFDI->second = ASTReader::PendingFakeDefinitionKind::FakeLoaded; | |||
1991 | ||||
1992 | // Don't change which declaration is the definition; that is required | |||
1993 | // to be invariant once we select it. | |||
1994 | auto *Def = DD.Definition; | |||
1995 | DD = std::move(MergeDD); | |||
1996 | DD.Definition = Def; | |||
1997 | return; | |||
1998 | } | |||
1999 | ||||
2000 | bool DetectedOdrViolation = false; | |||
2001 | ||||
2002 | #define FIELD(Name, Width, Merge) Merge(Name) | |||
2003 | #define MERGE_OR(Field) DD.Field |= MergeDD.Field; | |||
2004 | #define NO_MERGE(Field) \ | |||
2005 | DetectedOdrViolation |= DD.Field != MergeDD.Field; \ | |||
2006 | MERGE_OR(Field) | |||
2007 | #include "clang/AST/CXXRecordDeclDefinitionBits.def" | |||
2008 | NO_MERGE(IsLambda) | |||
2009 | #undef NO_MERGE | |||
2010 | #undef MERGE_OR | |||
2011 | ||||
2012 | if (DD.NumBases != MergeDD.NumBases || DD.NumVBases != MergeDD.NumVBases) | |||
2013 | DetectedOdrViolation = true; | |||
2014 | // FIXME: Issue a diagnostic if the base classes don't match when we come | |||
2015 | // to lazily load them. | |||
2016 | ||||
2017 | // FIXME: Issue a diagnostic if the list of conversion functions doesn't | |||
2018 | // match when we come to lazily load them. | |||
2019 | if (MergeDD.ComputedVisibleConversions && !DD.ComputedVisibleConversions) { | |||
2020 | DD.VisibleConversions = std::move(MergeDD.VisibleConversions); | |||
2021 | DD.ComputedVisibleConversions = true; | |||
2022 | } | |||
2023 | ||||
2024 | // FIXME: Issue a diagnostic if FirstFriend doesn't match when we come to | |||
2025 | // lazily load it. | |||
2026 | ||||
2027 | if (DD.IsLambda) { | |||
2028 | auto &Lambda1 = static_cast<CXXRecordDecl::LambdaDefinitionData &>(DD); | |||
2029 | auto &Lambda2 = static_cast<CXXRecordDecl::LambdaDefinitionData &>(MergeDD); | |||
2030 | DetectedOdrViolation |= Lambda1.DependencyKind != Lambda2.DependencyKind; | |||
2031 | DetectedOdrViolation |= Lambda1.IsGenericLambda != Lambda2.IsGenericLambda; | |||
2032 | DetectedOdrViolation |= Lambda1.CaptureDefault != Lambda2.CaptureDefault; | |||
2033 | DetectedOdrViolation |= Lambda1.NumCaptures != Lambda2.NumCaptures; | |||
2034 | DetectedOdrViolation |= | |||
2035 | Lambda1.NumExplicitCaptures != Lambda2.NumExplicitCaptures; | |||
2036 | DetectedOdrViolation |= | |||
2037 | Lambda1.HasKnownInternalLinkage != Lambda2.HasKnownInternalLinkage; | |||
2038 | DetectedOdrViolation |= Lambda1.ManglingNumber != Lambda2.ManglingNumber; | |||
2039 | ||||
2040 | if (Lambda1.NumCaptures && Lambda1.NumCaptures == Lambda2.NumCaptures) { | |||
2041 | for (unsigned I = 0, N = Lambda1.NumCaptures; I != N; ++I) { | |||
2042 | LambdaCapture &Cap1 = Lambda1.Captures.front()[I]; | |||
2043 | LambdaCapture &Cap2 = Lambda2.Captures.front()[I]; | |||
2044 | DetectedOdrViolation |= Cap1.getCaptureKind() != Cap2.getCaptureKind(); | |||
2045 | } | |||
2046 | Lambda1.AddCaptureList(Reader.getContext(), Lambda2.Captures.front()); | |||
2047 | } | |||
2048 | } | |||
2049 | ||||
2050 | if (D->getODRHash() != MergeDD.ODRHash) { | |||
2051 | DetectedOdrViolation = true; | |||
2052 | } | |||
2053 | ||||
2054 | if (DetectedOdrViolation) | |||
2055 | Reader.PendingOdrMergeFailures[DD.Definition].push_back( | |||
2056 | {MergeDD.Definition, &MergeDD}); | |||
2057 | } | |||
2058 | ||||
2059 | void ASTDeclReader::ReadCXXRecordDefinition(CXXRecordDecl *D, bool Update) { | |||
2060 | struct CXXRecordDecl::DefinitionData *DD; | |||
2061 | ASTContext &C = Reader.getContext(); | |||
2062 | ||||
2063 | // Determine whether this is a lambda closure type, so that we can | |||
2064 | // allocate the appropriate DefinitionData structure. | |||
2065 | bool IsLambda = Record.readInt(); | |||
2066 | if (IsLambda) | |||
2067 | DD = new (C) CXXRecordDecl::LambdaDefinitionData( | |||
2068 | D, nullptr, CXXRecordDecl::LDK_Unknown, false, LCD_None); | |||
2069 | else | |||
2070 | DD = new (C) struct CXXRecordDecl::DefinitionData(D); | |||
2071 | ||||
2072 | CXXRecordDecl *Canon = D->getCanonicalDecl(); | |||
2073 | // Set decl definition data before reading it, so that during deserialization | |||
2074 | // when we read CXXRecordDecl, it already has definition data and we don't | |||
2075 | // set fake one. | |||
2076 | if (!Canon->DefinitionData) | |||
2077 | Canon->DefinitionData = DD; | |||
2078 | D->DefinitionData = Canon->DefinitionData; | |||
2079 | ReadCXXDefinitionData(*DD, D); | |||
2080 | ||||
2081 | // We might already have a different definition for this record. This can | |||
2082 | // happen either because we're reading an update record, or because we've | |||
2083 | // already done some merging. Either way, just merge into it. | |||
2084 | if (Canon->DefinitionData != DD) { | |||
2085 | MergeDefinitionData(Canon, std::move(*DD)); | |||
2086 | return; | |||
2087 | } | |||
2088 | ||||
2089 | // Mark this declaration as being a definition. | |||
2090 | D->setCompleteDefinition(true); | |||
2091 | ||||
2092 | // If this is not the first declaration or is an update record, we can have | |||
2093 | // other redeclarations already. Make a note that we need to propagate the | |||
2094 | // DefinitionData pointer onto them. | |||
2095 | if (Update || Canon != D) | |||
2096 | Reader.PendingDefinitions.insert(D); | |||
2097 | } | |||
2098 | ||||
2099 | ASTDeclReader::RedeclarableResult | |||
2100 | ASTDeclReader::VisitCXXRecordDeclImpl(CXXRecordDecl *D) { | |||
2101 | RedeclarableResult Redecl = VisitRecordDeclImpl(D); | |||
2102 | ||||
2103 | ASTContext &C = Reader.getContext(); | |||
2104 | ||||
2105 | enum CXXRecKind { | |||
2106 | CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization | |||
2107 | }; | |||
2108 | switch ((CXXRecKind)Record.readInt()) { | |||
2109 | case CXXRecNotTemplate: | |||
2110 | // Merged when we merge the folding set entry in the primary template. | |||
2111 | if (!isa<ClassTemplateSpecializationDecl>(D)) | |||
2112 | mergeRedeclarable(D, Redecl); | |||
2113 | break; | |||
2114 | case CXXRecTemplate: { | |||
2115 | // Merged when we merge the template. | |||
2116 | auto *Template = readDeclAs<ClassTemplateDecl>(); | |||
2117 | D->TemplateOrInstantiation = Template; | |||
2118 | if (!Template->getTemplatedDecl()) { | |||
2119 | // We've not actually loaded the ClassTemplateDecl yet, because we're | |||
2120 | // currently being loaded as its pattern. Rely on it to set up our | |||
2121 | // TypeForDecl (see VisitClassTemplateDecl). | |||
2122 | // | |||
2123 | // Beware: we do not yet know our canonical declaration, and may still | |||
2124 | // get merged once the surrounding class template has got off the ground. | |||
2125 | DeferredTypeID = 0; | |||
2126 | } | |||
2127 | break; | |||
2128 | } | |||
2129 | case CXXRecMemberSpecialization: { | |||
2130 | auto *RD = readDeclAs<CXXRecordDecl>(); | |||
2131 | auto TSK = (TemplateSpecializationKind)Record.readInt(); | |||
2132 | SourceLocation POI = readSourceLocation(); | |||
2133 | MemberSpecializationInfo *MSI = new (C) MemberSpecializationInfo(RD, TSK); | |||
2134 | MSI->setPointOfInstantiation(POI); | |||
2135 | D->TemplateOrInstantiation = MSI; | |||
2136 | mergeRedeclarable(D, Redecl); | |||
2137 | break; | |||
2138 | } | |||
2139 | } | |||
2140 | ||||
2141 | bool WasDefinition = Record.readInt(); | |||
2142 | if (WasDefinition) | |||
2143 | ReadCXXRecordDefinition(D, /*Update*/false); | |||
2144 | else | |||
2145 | // Propagate DefinitionData pointer from the canonical declaration. | |||
2146 | D->DefinitionData = D->getCanonicalDecl()->DefinitionData; | |||
2147 | ||||
2148 | // Lazily load the key function to avoid deserializing every method so we can | |||
2149 | // compute it. | |||
2150 | if (WasDefinition) { | |||
2151 | DeclID KeyFn = readDeclID(); | |||
2152 | if (KeyFn && D->isCompleteDefinition()) | |||
2153 | // FIXME: This is wrong for the ARM ABI, where some other module may have | |||
2154 | // made this function no longer be a key function. We need an update | |||
2155 | // record or similar for that case. | |||
2156 | C.KeyFunctions[D] = KeyFn; | |||
2157 | } | |||
2158 | ||||
2159 | return Redecl; | |||
2160 | } | |||
2161 | ||||
2162 | void ASTDeclReader::VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D) { | |||
2163 | D->setExplicitSpecifier(Record.readExplicitSpec()); | |||
2164 | D->Ctor = readDeclAs<CXXConstructorDecl>(); | |||
2165 | VisitFunctionDecl(D); | |||
2166 | D->setIsCopyDeductionCandidate(Record.readInt()); | |||
2167 | } | |||
2168 | ||||
2169 | void ASTDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) { | |||
2170 | VisitFunctionDecl(D); | |||
2171 | ||||
2172 | unsigned NumOverridenMethods = Record.readInt(); | |||
2173 | if (D->isCanonicalDecl()) { | |||
2174 | while (NumOverridenMethods--) { | |||
2175 | // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod, | |||
2176 | // MD may be initializing. | |||
2177 | if (auto *MD = readDeclAs<CXXMethodDecl>()) | |||
2178 | Reader.getContext().addOverriddenMethod(D, MD->getCanonicalDecl()); | |||
2179 | } | |||
2180 | } else { | |||
2181 | // We don't care about which declarations this used to override; we get | |||
2182 | // the relevant information from the canonical declaration. | |||
2183 | Record.skipInts(NumOverridenMethods); | |||
2184 | } | |||
2185 | } | |||
2186 | ||||
2187 | void ASTDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) { | |||
2188 | // We need the inherited constructor information to merge the declaration, | |||
2189 | // so we have to read it before we call VisitCXXMethodDecl. | |||
2190 | D->setExplicitSpecifier(Record.readExplicitSpec()); | |||
2191 | if (D->isInheritingConstructor()) { | |||
2192 | auto *Shadow = readDeclAs<ConstructorUsingShadowDecl>(); | |||
2193 | auto *Ctor = readDeclAs<CXXConstructorDecl>(); | |||
2194 | *D->getTrailingObjects<InheritedConstructor>() = | |||
2195 | InheritedConstructor(Shadow, Ctor); | |||
2196 | } | |||
2197 | ||||
2198 | VisitCXXMethodDecl(D); | |||
2199 | } | |||
2200 | ||||
2201 | void ASTDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) { | |||
2202 | VisitCXXMethodDecl(D); | |||
2203 | ||||
2204 | if (auto *OperatorDelete = readDeclAs<FunctionDecl>()) { | |||
2205 | CXXDestructorDecl *Canon = D->getCanonicalDecl(); | |||
2206 | auto *ThisArg = Record.readExpr(); | |||
2207 | // FIXME: Check consistency if we have an old and new operator delete. | |||
2208 | if (!Canon->OperatorDelete) { | |||
2209 | Canon->OperatorDelete = OperatorDelete; | |||
2210 | Canon->OperatorDeleteThisArg = ThisArg; | |||
2211 | } | |||
2212 | } | |||
2213 | } | |||
2214 | ||||
2215 | void ASTDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) { | |||
2216 | D->setExplicitSpecifier(Record.readExplicitSpec()); | |||
2217 | VisitCXXMethodDecl(D); | |||
2218 | } | |||
2219 | ||||
2220 | void ASTDeclReader::VisitImportDecl(ImportDecl *D) { | |||
2221 | VisitDecl(D); | |||
2222 | D->ImportedModule = readModule(); | |||
2223 | D->setImportComplete(Record.readInt()); | |||
2224 | auto *StoredLocs = D->getTrailingObjects<SourceLocation>(); | |||
2225 | for (unsigned I = 0, N = Record.back(); I != N; ++I) | |||
2226 | StoredLocs[I] = readSourceLocation(); | |||
2227 | Record.skipInts(1); // The number of stored source locations. | |||
2228 | } | |||
2229 | ||||
2230 | void ASTDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) { | |||
2231 | VisitDecl(D); | |||
2232 | D->setColonLoc(readSourceLocation()); | |||
2233 | } | |||
2234 | ||||
2235 | void ASTDeclReader::VisitFriendDecl(FriendDecl *D) { | |||
2236 | VisitDecl(D); | |||
2237 | if (Record.readInt()) // hasFriendDecl | |||
2238 | D->Friend = readDeclAs<NamedDecl>(); | |||
2239 | else | |||
2240 | D->Friend = readTypeSourceInfo(); | |||
2241 | for (unsigned i = 0; i != D->NumTPLists; ++i) | |||
2242 | D->getTrailingObjects<TemplateParameterList *>()[i] = | |||
2243 | Record.readTemplateParameterList(); | |||
2244 | D->NextFriend = readDeclID(); | |||
2245 | D->UnsupportedFriend = (Record.readInt() != 0); | |||
2246 | D->FriendLoc = readSourceLocation(); | |||
2247 | } | |||
2248 | ||||
2249 | void ASTDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) { | |||
2250 | VisitDecl(D); | |||
2251 | unsigned NumParams = Record.readInt(); | |||
2252 | D->NumParams = NumParams; | |||
2253 | D->Params = new (Reader.getContext()) TemplateParameterList *[NumParams]; | |||
2254 | for (unsigned i = 0; i != NumParams; ++i) | |||
2255 | D->Params[i] = Record.readTemplateParameterList(); | |||
2256 | if (Record.readInt()) // HasFriendDecl | |||
2257 | D->Friend = readDeclAs<NamedDecl>(); | |||
2258 | else | |||
2259 | D->Friend = readTypeSourceInfo(); | |||
2260 | D->FriendLoc = readSourceLocation(); | |||
2261 | } | |||
2262 | ||||
2263 | void ASTDeclReader::VisitTemplateDecl(TemplateDecl *D) { | |||
2264 | VisitNamedDecl(D); | |||
2265 | ||||
2266 | assert(!D->TemplateParams && "TemplateParams already set!")(static_cast <bool> (!D->TemplateParams && "TemplateParams already set!" ) ? void (0) : __assert_fail ("!D->TemplateParams && \"TemplateParams already set!\"" , "clang/lib/Serialization/ASTReaderDecl.cpp", 2266, __extension__ __PRETTY_FUNCTION__)); | |||
2267 | D->TemplateParams = Record.readTemplateParameterList(); | |||
2268 | D->init(readDeclAs<NamedDecl>()); | |||
2269 | } | |||
2270 | ||||
2271 | void ASTDeclReader::VisitConceptDecl(ConceptDecl *D) { | |||
2272 | VisitTemplateDecl(D); | |||
2273 | D->ConstraintExpr = Record.readExpr(); | |||
2274 | mergeMergeable(D); | |||
2275 | } | |||
2276 | ||||
2277 | void ASTDeclReader::VisitImplicitConceptSpecializationDecl( | |||
2278 | ImplicitConceptSpecializationDecl *D) { | |||
2279 | // The size of the template list was read during creation of the Decl, so we | |||
2280 | // don't have to re-read it here. | |||
2281 | VisitDecl(D); | |||
2282 | llvm::SmallVector<TemplateArgument, 4> Args; | |||
2283 | for (unsigned I = 0; I < D->NumTemplateArgs; ++I) | |||
2284 | Args.push_back(Record.readTemplateArgument(/*Canonicalize=*/true)); | |||
2285 | D->setTemplateArguments(Args); | |||
2286 | } | |||
2287 | ||||
2288 | void ASTDeclReader::VisitRequiresExprBodyDecl(RequiresExprBodyDecl *D) { | |||
2289 | } | |||
2290 | ||||
2291 | ASTDeclReader::RedeclarableResult | |||
2292 | ASTDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) { | |||
2293 | RedeclarableResult Redecl = VisitRedeclarable(D); | |||
2294 | ||||
2295 | // Make sure we've allocated the Common pointer first. We do this before | |||
2296 | // VisitTemplateDecl so that getCommonPtr() can be used during initialization. | |||
2297 | RedeclarableTemplateDecl *CanonD = D->getCanonicalDecl(); | |||
2298 | if (!CanonD->Common) { | |||
2299 | CanonD->Common = CanonD->newCommon(Reader.getContext()); | |||
2300 | Reader.PendingDefinitions.insert(CanonD); | |||
2301 | } | |||
2302 | D->Common = CanonD->Common; | |||
2303 | ||||
2304 | // If this is the first declaration of the template, fill in the information | |||
2305 | // for the 'common' pointer. | |||
2306 | if (ThisDeclID == Redecl.getFirstID()) { | |||
2307 | if (auto *RTD = readDeclAs<RedeclarableTemplateDecl>()) { | |||
2308 | assert(RTD->getKind() == D->getKind() &&(static_cast <bool> (RTD->getKind() == D->getKind () && "InstantiatedFromMemberTemplate kind mismatch") ? void (0) : __assert_fail ("RTD->getKind() == D->getKind() && \"InstantiatedFromMemberTemplate kind mismatch\"" , "clang/lib/Serialization/ASTReaderDecl.cpp", 2309, __extension__ __PRETTY_FUNCTION__)) | |||
2309 | "InstantiatedFromMemberTemplate kind mismatch")(static_cast <bool> (RTD->getKind() == D->getKind () && "InstantiatedFromMemberTemplate kind mismatch") ? void (0) : __assert_fail ("RTD->getKind() == D->getKind() && \"InstantiatedFromMemberTemplate kind mismatch\"" , "clang/lib/Serialization/ASTReaderDecl.cpp", 2309, __extension__ __PRETTY_FUNCTION__)); | |||
2310 | D->setInstantiatedFromMemberTemplate(RTD); | |||
2311 | if (Record.readInt()) | |||
2312 | D->setMemberSpecialization(); | |||
2313 | } | |||
2314 | } | |||
2315 | ||||
2316 | VisitTemplateDecl(D); | |||
2317 | D->IdentifierNamespace = Record.readInt(); | |||
2318 | ||||
2319 | return Redecl; | |||
2320 | } | |||
2321 | ||||
2322 | void ASTDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) { | |||
2323 | RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D); | |||
2324 | mergeRedeclarableTemplate(D, Redecl); | |||
2325 | ||||
2326 | if (ThisDeclID == Redecl.getFirstID()) { | |||
2327 | // This ClassTemplateDecl owns a CommonPtr; read it to keep track of all of | |||
2328 | // the specializations. | |||
2329 | SmallVector<serialization::DeclID, 32> SpecIDs; | |||
2330 | readDeclIDList(SpecIDs); | |||
2331 | ASTDeclReader::AddLazySpecializations(D, SpecIDs); | |||
2332 | } | |||
2333 | ||||
2334 | if (D->getTemplatedDecl()->TemplateOrInstantiation) { | |||
2335 | // We were loaded before our templated declaration was. We've not set up | |||
2336 | // its corresponding type yet (see VisitCXXRecordDeclImpl), so reconstruct | |||
2337 | // it now. | |||
2338 | Reader.getContext().getInjectedClassNameType( | |||
2339 | D->getTemplatedDecl(), D->getInjectedClassNameSpecialization()); | |||
2340 | } | |||
2341 | } | |||
2342 | ||||
2343 | void ASTDeclReader::VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D) { | |||
2344 | llvm_unreachable("BuiltinTemplates are not serialized")::llvm::llvm_unreachable_internal("BuiltinTemplates are not serialized" , "clang/lib/Serialization/ASTReaderDecl.cpp", 2344); | |||
2345 | } | |||
2346 | ||||
2347 | /// TODO: Unify with ClassTemplateDecl version? | |||
2348 | /// May require unifying ClassTemplateDecl and | |||
2349 | /// VarTemplateDecl beyond TemplateDecl... | |||
2350 | void ASTDeclReader::VisitVarTemplateDecl(VarTemplateDecl *D) { | |||
2351 | RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D); | |||
2352 | mergeRedeclarableTemplate(D, Redecl); | |||
2353 | ||||
2354 | if (ThisDeclID == Redecl.getFirstID()) { | |||
2355 | // This VarTemplateDecl owns a CommonPtr; read it to keep track of all of | |||
2356 | // the specializations. | |||
2357 | SmallVector<serialization::DeclID, 32> SpecIDs; | |||
2358 | readDeclIDList(SpecIDs); | |||
2359 | ASTDeclReader::AddLazySpecializations(D, SpecIDs); | |||
2360 | } | |||
2361 | } | |||
2362 | ||||
2363 | ASTDeclReader::RedeclarableResult | |||
2364 | ASTDeclReader::VisitClassTemplateSpecializationDeclImpl( | |||
2365 | ClassTemplateSpecializationDecl *D) { | |||
2366 | RedeclarableResult Redecl = VisitCXXRecordDeclImpl(D); | |||
2367 | ||||
2368 | ASTContext &C = Reader.getContext(); | |||
2369 | if (Decl *InstD = readDecl()) { | |||
2370 | if (auto *CTD = dyn_cast<ClassTemplateDecl>(InstD)) { | |||
2371 | D->SpecializedTemplate = CTD; | |||
2372 | } else { | |||
2373 | SmallVector<TemplateArgument, 8> TemplArgs; | |||
2374 | Record.readTemplateArgumentList(TemplArgs); | |||
2375 | TemplateArgumentList *ArgList | |||
2376 | = TemplateArgumentList::CreateCopy(C, TemplArgs); | |||
2377 | auto *PS = | |||
2378 | new (C) ClassTemplateSpecializationDecl:: | |||
2379 | SpecializedPartialSpecialization(); | |||
2380 | PS->PartialSpecialization | |||
2381 | = cast<ClassTemplatePartialSpecializationDecl>(InstD); | |||
2382 | PS->TemplateArgs = ArgList; | |||
2383 | D->SpecializedTemplate = PS; | |||
2384 | } | |||
2385 | } | |||
2386 | ||||
2387 | SmallVector<TemplateArgument, 8> TemplArgs; | |||
2388 | Record.readTemplateArgumentList(TemplArgs, /*Canonicalize*/ true); | |||
2389 | D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs); | |||
2390 | D->PointOfInstantiation = readSourceLocation(); | |||
2391 | D->SpecializationKind = (TemplateSpecializationKind)Record.readInt(); | |||
2392 | ||||
2393 | bool writtenAsCanonicalDecl = Record.readInt(); | |||
2394 | if (writtenAsCanonicalDecl) { | |||
2395 | auto *CanonPattern = readDeclAs<ClassTemplateDecl>(); | |||
2396 | if (D->isCanonicalDecl()) { // It's kept in the folding set. | |||
2397 | // Set this as, or find, the canonical declaration for this specialization | |||
2398 | ClassTemplateSpecializationDecl *CanonSpec; | |||
2399 | if (auto *Partial = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) { | |||
2400 | CanonSpec = CanonPattern->getCommonPtr()->PartialSpecializations | |||
2401 | .GetOrInsertNode(Partial); | |||
2402 | } else { | |||
2403 | CanonSpec = | |||
2404 | CanonPattern->getCommonPtr()->Specializations.GetOrInsertNode(D); | |||
2405 | } | |||
2406 | // If there was already a canonical specialization, merge into it. | |||
2407 | if (CanonSpec != D) { | |||
2408 | mergeRedeclarable<TagDecl>(D, CanonSpec, Redecl); | |||
2409 | ||||
2410 | // This declaration might be a definition. Merge with any existing | |||
2411 | // definition. | |||
2412 | if (auto *DDD = D->DefinitionData) { | |||
2413 | if (CanonSpec->DefinitionData) | |||
2414 | MergeDefinitionData(CanonSpec, std::move(*DDD)); | |||
2415 | else | |||
2416 | CanonSpec->DefinitionData = D->DefinitionData; | |||
2417 | } | |||
2418 | D->DefinitionData = CanonSpec->DefinitionData; | |||
2419 | } | |||
2420 | } | |||
2421 | } | |||
2422 | ||||
2423 | // Explicit info. | |||
2424 | if (TypeSourceInfo *TyInfo = readTypeSourceInfo()) { | |||
2425 | auto *ExplicitInfo = | |||
2426 | new (C) ClassTemplateSpecializationDecl::ExplicitSpecializationInfo; | |||
2427 | ExplicitInfo->TypeAsWritten = TyInfo; | |||
2428 | ExplicitInfo->ExternLoc = readSourceLocation(); | |||
2429 | ExplicitInfo->TemplateKeywordLoc = readSourceLocation(); | |||
2430 | D->ExplicitInfo = ExplicitInfo; | |||
2431 | } | |||
2432 | ||||
2433 | return Redecl; | |||
2434 | } | |||
2435 | ||||
2436 | void ASTDeclReader::VisitClassTemplatePartialSpecializationDecl( | |||
2437 | ClassTemplatePartialSpecializationDecl *D) { | |||
2438 | // We need to read the template params first because redeclarable is going to | |||
2439 | // need them for profiling | |||
2440 | TemplateParameterList *Params = Record.readTemplateParameterList(); | |||
2441 | D->TemplateParams = Params; | |||
2442 | D->ArgsAsWritten = Record.readASTTemplateArgumentListInfo(); | |||
2443 | ||||
2444 | RedeclarableResult Redecl = VisitClassTemplateSpecializationDeclImpl(D); | |||
2445 | ||||
2446 | // These are read/set from/to the first declaration. | |||
2447 | if (ThisDeclID == Redecl.getFirstID()) { | |||
2448 | D->InstantiatedFromMember.setPointer( | |||
2449 | readDeclAs<ClassTemplatePartialSpecializationDecl>()); | |||
2450 | D->InstantiatedFromMember.setInt(Record.readInt()); | |||
2451 | } | |||
2452 | } | |||
2453 | ||||
2454 | void ASTDeclReader::VisitClassScopeFunctionSpecializationDecl( | |||
2455 | ClassScopeFunctionSpecializationDecl *D) { | |||
2456 | VisitDecl(D); | |||
2457 | D->Specialization = readDeclAs<CXXMethodDecl>(); | |||
2458 | if (Record.readInt()) | |||
2459 | D->TemplateArgs = Record.readASTTemplateArgumentListInfo(); | |||
2460 | } | |||
2461 | ||||
2462 | void ASTDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { | |||
2463 | RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D); | |||
2464 | ||||
2465 | if (ThisDeclID == Redecl.getFirstID()) { | |||
2466 | // This FunctionTemplateDecl owns a CommonPtr; read it. | |||
2467 | SmallVector<serialization::DeclID, 32> SpecIDs; | |||
2468 | readDeclIDList(SpecIDs); | |||
2469 | ASTDeclReader::AddLazySpecializations(D, SpecIDs); | |||
2470 | } | |||
2471 | } | |||
2472 | ||||
2473 | /// TODO: Unify with ClassTemplateSpecializationDecl version? | |||
2474 | /// May require unifying ClassTemplate(Partial)SpecializationDecl and | |||
2475 | /// VarTemplate(Partial)SpecializationDecl with a new data | |||
2476 | /// structure Template(Partial)SpecializationDecl, and | |||
2477 | /// using Template(Partial)SpecializationDecl as input type. | |||
2478 | ASTDeclReader::RedeclarableResult | |||
2479 | ASTDeclReader::VisitVarTemplateSpecializationDeclImpl( | |||
2480 | VarTemplateSpecializationDecl *D) { | |||
2481 | ASTContext &C = Reader.getContext(); | |||
2482 | if (Decl *InstD = readDecl()) { | |||
2483 | if (auto *VTD = dyn_cast<VarTemplateDecl>(InstD)) { | |||
2484 | D->SpecializedTemplate = VTD; | |||
2485 | } else { | |||
2486 | SmallVector<TemplateArgument, 8> TemplArgs; | |||
2487 | Record.readTemplateArgumentList(TemplArgs); | |||
2488 | TemplateArgumentList *ArgList = TemplateArgumentList::CreateCopy( | |||
2489 | C, TemplArgs); | |||
2490 | auto *PS = | |||
2491 | new (C) | |||
2492 | VarTemplateSpecializationDecl::SpecializedPartialSpecialization(); | |||
2493 | PS->PartialSpecialization = | |||
2494 | cast<VarTemplatePartialSpecializationDecl>(InstD); | |||
2495 | PS->TemplateArgs = ArgList; | |||
2496 | D->SpecializedTemplate = PS; | |||
2497 | } | |||
2498 | } | |||
2499 | ||||
2500 | // Explicit info. | |||
2501 | if (TypeSourceInfo *TyInfo = readTypeSourceInfo()) { | |||
2502 | auto *ExplicitInfo = | |||
2503 | new (C) VarTemplateSpecializationDecl::ExplicitSpecializationInfo; | |||
2504 | ExplicitInfo->TypeAsWritten = TyInfo; | |||
2505 | ExplicitInfo->ExternLoc = readSourceLocation(); | |||
2506 | ExplicitInfo->TemplateKeywordLoc = readSourceLocation(); | |||
2507 | D->ExplicitInfo = ExplicitInfo; | |||
2508 | } | |||
2509 | ||||
2510 | SmallVector<TemplateArgument, 8> TemplArgs; | |||
2511 | Record.readTemplateArgumentList(TemplArgs, /*Canonicalize*/ true); | |||
2512 | D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs); | |||
2513 | D->PointOfInstantiation = readSourceLocation(); | |||
2514 | D->SpecializationKind = (TemplateSpecializationKind)Record.readInt(); | |||
2515 | D->IsCompleteDefinition = Record.readInt(); | |||
2516 | ||||
2517 | RedeclarableResult Redecl = VisitVarDeclImpl(D); | |||
2518 | ||||
2519 | bool writtenAsCanonicalDecl = Record.readInt(); | |||
2520 | if (writtenAsCanonicalDecl) { | |||
2521 | auto *CanonPattern = readDeclAs<VarTemplateDecl>(); | |||
2522 | if (D->isCanonicalDecl()) { // It's kept in the folding set. | |||
2523 | VarTemplateSpecializationDecl *CanonSpec; | |||
2524 | if (auto *Partial = dyn_cast<VarTemplatePartialSpecializationDecl>(D)) { | |||
2525 | CanonSpec = CanonPattern->getCommonPtr() | |||
2526 | ->PartialSpecializations.GetOrInsertNode(Partial); | |||
2527 | } else { | |||
2528 | CanonSpec = | |||
2529 | CanonPattern->getCommonPtr()->Specializations.GetOrInsertNode(D); | |||
2530 | } | |||
2531 | // If we already have a matching specialization, merge it. | |||
2532 | if (CanonSpec != D) | |||
2533 | mergeRedeclarable<VarDecl>(D, CanonSpec, Redecl); | |||
2534 | } | |||
2535 | } | |||
2536 | ||||
2537 | return Redecl; | |||
2538 | } | |||
2539 | ||||
2540 | /// TODO: Unify with ClassTemplatePartialSpecializationDecl version? | |||
2541 | /// May require unifying ClassTemplate(Partial)SpecializationDecl and | |||
2542 | /// VarTemplate(Partial)SpecializationDecl with a new data | |||
2543 | /// structure Template(Partial)SpecializationDecl, and | |||
2544 | /// using Template(Partial)SpecializationDecl as input type. | |||
2545 | void ASTDeclReader::VisitVarTemplatePartialSpecializationDecl( | |||
2546 | VarTemplatePartialSpecializationDecl *D) { | |||
2547 | TemplateParameterList *Params = Record.readTemplateParameterList(); | |||
2548 | D->TemplateParams = Params; | |||
2549 | D->ArgsAsWritten = Record.readASTTemplateArgumentListInfo(); | |||
2550 | ||||
2551 | RedeclarableResult Redecl = VisitVarTemplateSpecializationDeclImpl(D); | |||
2552 | ||||
2553 | // These are read/set from/to the first declaration. | |||
2554 | if (ThisDeclID == Redecl.getFirstID()) { | |||
2555 | D->InstantiatedFromMember.setPointer( | |||
2556 | readDeclAs<VarTemplatePartialSpecializationDecl>()); | |||
2557 | D->InstantiatedFromMember.setInt(Record.readInt()); | |||
2558 | } | |||
2559 | } | |||
2560 | ||||
2561 | void ASTDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { | |||
2562 | VisitTypeDecl(D); | |||
2563 | ||||
2564 | D->setDeclaredWithTypename(Record.readInt()); | |||
2565 | ||||
2566 | if (Record.readBool()) { | |||
2567 | NestedNameSpecifierLoc NNS = Record.readNestedNameSpecifierLoc(); | |||
2568 | DeclarationNameInfo DN = Record.readDeclarationNameInfo(); | |||
2569 | ConceptDecl *NamedConcept = Record.readDeclAs<ConceptDecl>(); | |||
2570 | const ASTTemplateArgumentListInfo *ArgsAsWritten = nullptr; | |||
2571 | if (Record.readBool()) | |||
2572 | ArgsAsWritten = Record.readASTTemplateArgumentListInfo(); | |||
2573 | Expr *ImmediatelyDeclaredConstraint = Record.readExpr(); | |||
2574 | D->setTypeConstraint(NNS, DN, /*FoundDecl=*/nullptr, NamedConcept, | |||
2575 | ArgsAsWritten, ImmediatelyDeclaredConstraint); | |||
2576 | if ((D->ExpandedParameterPack = Record.readInt())) | |||
2577 | D->NumExpanded = Record.readInt(); | |||
2578 | } | |||
2579 | ||||
2580 | if (Record.readInt()) | |||
2581 | D->setDefaultArgument(readTypeSourceInfo()); | |||
2582 | } | |||
2583 | ||||
2584 | void ASTDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { | |||
2585 | VisitDeclaratorDecl(D); | |||
2586 | // TemplateParmPosition. | |||
2587 | D->setDepth(Record.readInt()); | |||
2588 | D->setPosition(Record.readInt()); | |||
2589 | if (D->hasPlaceholderTypeConstraint()) | |||
2590 | D->setPlaceholderTypeConstraint(Record.readExpr()); | |||
2591 | if (D->isExpandedParameterPack()) { | |||
2592 | auto TypesAndInfos = | |||
2593 | D->getTrailingObjects<std::pair<QualType, TypeSourceInfo *>>(); | |||
2594 | for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) { | |||
2595 | new (&TypesAndInfos[I].first) QualType(Record.readType()); | |||
2596 | TypesAndInfos[I].second = readTypeSourceInfo(); | |||
2597 | } | |||
2598 | } else { | |||
2599 | // Rest of NonTypeTemplateParmDecl. | |||
2600 | D->ParameterPack = Record.readInt(); | |||
2601 | if (Record.readInt()) | |||
2602 | D->setDefaultArgument(Record.readExpr()); | |||
2603 | } | |||
2604 | } | |||
2605 | ||||
2606 | void ASTDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { | |||
2607 | VisitTemplateDecl(D); | |||
2608 | // TemplateParmPosition. | |||
2609 | D->setDepth(Record.readInt()); | |||
2610 | D->setPosition(Record.readInt()); | |||
2611 | if (D->isExpandedParameterPack()) { | |||
2612 | auto **Data = D->getTrailingObjects<TemplateParameterList *>(); | |||
2613 | for (unsigned I = 0, N = D->getNumExpansionTemplateParameters(); | |||
2614 | I != N; ++I) | |||
2615 | Data[I] = Record.readTemplateParameterList(); | |||
2616 | } else { | |||
2617 | // Rest of TemplateTemplateParmDecl. | |||
2618 | D->ParameterPack = Record.readInt(); | |||
2619 | if (Record.readInt()) | |||
2620 | D->setDefaultArgument(Reader.getContext(), | |||
2621 | Record.readTemplateArgumentLoc()); | |||
2622 | } | |||
2623 | } | |||
2624 | ||||
2625 | void ASTDeclReader::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { | |||
2626 | RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D); | |||
2627 | mergeRedeclarableTemplate(D, Redecl); | |||
2628 | } | |||
2629 | ||||
2630 | void ASTDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) { | |||
2631 | VisitDecl(D); | |||
2632 | D->AssertExprAndFailed.setPointer(Record.readExpr()); | |||
2633 | D->AssertExprAndFailed.setInt(Record.readInt()); | |||
2634 | D->Message = cast_or_null<StringLiteral>(Record.readExpr()); | |||
2635 | D->RParenLoc = readSourceLocation(); | |||
2636 | } | |||
2637 | ||||
2638 | void ASTDeclReader::VisitEmptyDecl(EmptyDecl *D) { | |||
2639 | VisitDecl(D); | |||
2640 | } | |||
2641 | ||||
2642 | void ASTDeclReader::VisitLifetimeExtendedTemporaryDecl( | |||
2643 | LifetimeExtendedTemporaryDecl *D) { | |||
2644 | VisitDecl(D); | |||
2645 | D->ExtendingDecl = readDeclAs<ValueDecl>(); | |||
2646 | D->ExprWithTemporary = Record.readStmt(); | |||
2647 | if (Record.readInt()) { | |||
2648 | D->Value = new (D->getASTContext()) APValue(Record.readAPValue()); | |||
2649 | D->getASTContext().addDestruction(D->Value); | |||
2650 | } | |||
2651 | D->ManglingNumber = Record.readInt(); | |||
2652 | mergeMergeable(D); | |||
2653 | } | |||
2654 | ||||
2655 | std::pair<uint64_t, uint64_t> | |||
2656 | ASTDeclReader::VisitDeclContext(DeclContext *DC) { | |||
2657 | uint64_t LexicalOffset = ReadLocalOffset(); | |||
2658 | uint64_t VisibleOffset = ReadLocalOffset(); | |||
2659 | return std::make_pair(LexicalOffset, VisibleOffset); | |||
2660 | } | |||
2661 | ||||
2662 | template <typename T> | |||
2663 | ASTDeclReader::RedeclarableResult | |||
2664 | ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) { | |||
2665 | DeclID FirstDeclID = readDeclID(); | |||
2666 | Decl *MergeWith = nullptr; | |||
2667 | ||||
2668 | bool IsKeyDecl = ThisDeclID == FirstDeclID; | |||
2669 | bool IsFirstLocalDecl = false; | |||
2670 | ||||
2671 | uint64_t RedeclOffset = 0; | |||
2672 | ||||
2673 | // 0 indicates that this declaration was the only declaration of its entity, | |||
2674 | // and is used for space optimization. | |||
2675 | if (FirstDeclID == 0) { | |||
2676 | FirstDeclID = ThisDeclID; | |||
2677 | IsKeyDecl = true; | |||
2678 | IsFirstLocalDecl = true; | |||
2679 | } else if (unsigned N = Record.readInt()) { | |||
2680 | // This declaration was the first local declaration, but may have imported | |||
2681 | // other declarations. | |||
2682 | IsKeyDecl = N == 1; | |||
2683 | IsFirstLocalDecl = true; | |||
2684 | ||||
2685 | // We have some declarations that must be before us in our redeclaration | |||
2686 | // chain. Read them now, and remember that we ought to merge with one of | |||
2687 | // them. | |||
2688 | // FIXME: Provide a known merge target to the second and subsequent such | |||
2689 | // declaration. | |||
2690 | for (unsigned I = 0; I != N - 1; ++I) | |||
2691 | MergeWith = readDecl(); | |||
2692 | ||||
2693 | RedeclOffset = ReadLocalOffset(); | |||
2694 | } else { | |||
2695 | // This declaration was not the first local declaration. Read the first | |||
2696 | // local declaration now, to trigger the import of other redeclarations. | |||
2697 | (void)readDecl(); | |||
2698 | } | |||
2699 | ||||
2700 | auto *FirstDecl = cast_or_null<T>(Reader.GetDecl(FirstDeclID)); | |||
2701 | if (FirstDecl != D) { | |||
2702 | // We delay loading of the redeclaration chain to avoid deeply nested calls. | |||
2703 | // We temporarily set the first (canonical) declaration as the previous one | |||
2704 | // which is the one that matters and mark the real previous DeclID to be | |||
2705 | // loaded & attached later on. | |||
2706 | D->RedeclLink = Redeclarable<T>::PreviousDeclLink(FirstDecl); | |||
2707 | D->First = FirstDecl->getCanonicalDecl(); | |||
2708 | } | |||
2709 | ||||
2710 | auto *DAsT = static_cast<T *>(D); | |||
2711 | ||||
2712 | // Note that we need to load local redeclarations of this decl and build a | |||
2713 | // decl chain for them. This must happen *after* we perform the preloading | |||
2714 | // above; this ensures that the redeclaration chain is built in the correct | |||
2715 | // order. | |||
2716 | if (IsFirstLocalDecl) | |||
2717 | Reader.PendingDeclChains.push_back(std::make_pair(DAsT, RedeclOffset)); | |||
2718 | ||||
2719 | return RedeclarableResult(MergeWith, FirstDeclID, IsKeyDecl); | |||
2720 | } | |||
2721 | ||||
2722 | /// Attempts to merge the given declaration (D) with another declaration | |||
2723 | /// of the same entity. | |||
2724 | template <typename T> | |||
2725 | void ASTDeclReader::mergeRedeclarable(Redeclarable<T> *DBase, | |||
2726 | RedeclarableResult &Redecl) { | |||
2727 | // If modules are not available, there is no reason to perform this merge. | |||
2728 | if (!Reader.getContext().getLangOpts().Modules) | |||
2729 | return; | |||
2730 | ||||
2731 | // If we're not the canonical declaration, we don't need to merge. | |||
2732 | if (!DBase->isFirstDecl()) | |||
2733 | return; | |||
2734 | ||||
2735 | auto *D = static_cast<T *>(DBase); | |||
2736 | ||||
2737 | if (auto *Existing = Redecl.getKnownMergeTarget()) | |||
2738 | // We already know of an existing declaration we should merge with. | |||
2739 | mergeRedeclarable(D, cast<T>(Existing), Redecl); | |||
2740 | else if (FindExistingResult ExistingRes = findExisting(D)) | |||
2741 | if (T *Existing = ExistingRes) | |||
2742 | mergeRedeclarable(D, Existing, Redecl); | |||
2743 | } | |||
2744 | ||||
2745 | void ASTDeclReader::mergeRedeclarableTemplate(RedeclarableTemplateDecl *D, | |||
2746 | RedeclarableResult &Redecl) { | |||
2747 | mergeRedeclarable(D, Redecl); | |||
2748 | // If we merged the template with a prior declaration chain, merge the | |||
2749 | // common pointer. | |||
2750 | // FIXME: Actually merge here, don't just overwrite. | |||
2751 | D->Common = D->getCanonicalDecl()->Common; | |||
2752 | } | |||
2753 | ||||
2754 | /// "Cast" to type T, asserting if we don't have an implicit conversion. | |||
2755 | /// We use this to put code in a template that will only be valid for certain | |||
2756 | /// instantiations. | |||
2757 | template<typename T> static T assert_cast(T t) { return t; } | |||
2758 | template<typename T> static T assert_cast(...) { | |||
2759 | llvm_unreachable("bad assert_cast")::llvm::llvm_unreachable_internal("bad assert_cast", "clang/lib/Serialization/ASTReaderDecl.cpp" , 2759); | |||
2760 | } | |||
2761 | ||||
2762 | /// Merge together the pattern declarations from two template | |||
2763 | /// declarations. | |||
2764 | void ASTDeclReader::mergeTemplatePattern(RedeclarableTemplateDecl *D, | |||
2765 | RedeclarableTemplateDecl *Existing, | |||
2766 | bool IsKeyDecl) { | |||
2767 | auto *DPattern = D->getTemplatedDecl(); | |||
2768 | auto *ExistingPattern = Existing->getTemplatedDecl(); | |||
2769 | RedeclarableResult Result(/*MergeWith*/ ExistingPattern, | |||
2770 | DPattern->getCanonicalDecl()->getGlobalID(), | |||
2771 | IsKeyDecl); | |||
2772 | ||||
2773 | if (auto *DClass = dyn_cast<CXXRecordDecl>(DPattern)) { | |||
2774 | // Merge with any existing definition. | |||
2775 | // FIXME: This is duplicated in several places. Refactor. | |||
2776 | auto *ExistingClass = | |||
2777 | cast<CXXRecordDecl>(ExistingPattern)->getCanonicalDecl(); | |||
2778 | if (auto *DDD = DClass->DefinitionData) { | |||
2779 | if (ExistingClass->DefinitionData) { | |||
2780 | MergeDefinitionData(ExistingClass, std::move(*DDD)); | |||
2781 | } else { | |||
2782 | ExistingClass->DefinitionData = DClass->DefinitionData; | |||
2783 | // We may have skipped this before because we thought that DClass | |||
2784 | // was the canonical declaration. | |||
2785 | Reader.PendingDefinitions.insert(DClass); | |||
2786 | } | |||
2787 | } | |||
2788 | DClass->DefinitionData = ExistingClass->DefinitionData; | |||
2789 | ||||
2790 | return mergeRedeclarable(DClass, cast<TagDecl>(ExistingPattern), | |||
2791 | Result); | |||
2792 | } | |||
2793 | if (auto *DFunction = dyn_cast<FunctionDecl>(DPattern)) | |||
2794 | return mergeRedeclarable(DFunction, cast<FunctionDecl>(ExistingPattern), | |||
2795 | Result); | |||
2796 | if (auto *DVar = dyn_cast<VarDecl>(DPattern)) | |||
2797 | return mergeRedeclarable(DVar, cast<VarDecl>(ExistingPattern), Result); | |||
2798 | if (auto *DAlias = dyn_cast<TypeAliasDecl>(DPattern)) | |||
2799 | return mergeRedeclarable(DAlias, cast<TypedefNameDecl>(ExistingPattern), | |||
2800 | Result); | |||
2801 | llvm_unreachable("merged an unknown kind of redeclarable template")::llvm::llvm_unreachable_internal("merged an unknown kind of redeclarable template" , "clang/lib/Serialization/ASTReaderDecl.cpp", 2801); | |||
2802 | } | |||
2803 | ||||
2804 | /// Attempts to merge the given declaration (D) with another declaration | |||
2805 | /// of the same entity. | |||
2806 | template <typename T> | |||
2807 | void ASTDeclReader::mergeRedeclarable(Redeclarable<T> *DBase, T *Existing, | |||
2808 | RedeclarableResult &Redecl) { | |||
2809 | auto *D = static_cast<T *>(DBase); | |||
2810 | T *ExistingCanon = Existing->getCanonicalDecl(); | |||
2811 | T *DCanon = D->getCanonicalDecl(); | |||
2812 | if (ExistingCanon != DCanon) { | |||
2813 | // Have our redeclaration link point back at the canonical declaration | |||
2814 | // of the existing declaration, so that this declaration has the | |||
2815 | // appropriate canonical declaration. | |||
2816 | D->RedeclLink = Redeclarable<T>::PreviousDeclLink(ExistingCanon); | |||
2817 | D->First = ExistingCanon; | |||
2818 | ExistingCanon->Used |= D->Used; | |||
2819 | D->Used = false; | |||
2820 | ||||
2821 | // When we merge a namespace, update its pointer to the first namespace. | |||
2822 | // We cannot have loaded any redeclarations of this declaration yet, so | |||
2823 | // there's nothing else that needs to be updated. | |||
2824 | if (auto *Namespace = dyn_cast<NamespaceDecl>(D)) | |||
2825 | Namespace->AnonOrFirstNamespaceAndFlags.setPointer( | |||
2826 | assert_cast<NamespaceDecl *>(ExistingCanon)); | |||
2827 | ||||
2828 | // When we merge a template, merge its pattern. | |||
2829 | if (auto *DTemplate = dyn_cast<RedeclarableTemplateDecl>(D)) | |||
2830 | mergeTemplatePattern( | |||
2831 | DTemplate, assert_cast<RedeclarableTemplateDecl *>(ExistingCanon), | |||
2832 | Redecl.isKeyDecl()); | |||
2833 | ||||
2834 | // If this declaration is a key declaration, make a note of that. | |||
2835 | if (Redecl.isKeyDecl()) | |||
2836 | Reader.KeyDecls[ExistingCanon].push_back(Redecl.getFirstID()); | |||
2837 | } | |||
2838 | } | |||
2839 | ||||
2840 | /// ODR-like semantics for C/ObjC allow us to merge tag types and a structural | |||
2841 | /// check in Sema guarantees the types can be merged (see C11 6.2.7/1 or C89 | |||
2842 | /// 6.1.2.6/1). Although most merging is done in Sema, we need to guarantee | |||
2843 | /// that some types are mergeable during deserialization, otherwise name | |||
2844 | /// lookup fails. This is the case for EnumConstantDecl. | |||
2845 | static bool allowODRLikeMergeInC(NamedDecl *ND) { | |||
2846 | if (!ND) | |||
2847 | return false; | |||
2848 | // TODO: implement merge for other necessary decls. | |||
2849 | if (isa<EnumConstantDecl, FieldDecl, IndirectFieldDecl>(ND)) | |||
2850 | return true; | |||
2851 | return false; | |||
2852 | } | |||
2853 | ||||
2854 | /// Attempts to merge LifetimeExtendedTemporaryDecl with | |||
2855 | /// identical class definitions from two different modules. | |||
2856 | void ASTDeclReader::mergeMergeable(LifetimeExtendedTemporaryDecl *D) { | |||
2857 | // If modules are not available, there is no reason to perform this merge. | |||
2858 | if (!Reader.getContext().getLangOpts().Modules) | |||
2859 | return; | |||
2860 | ||||
2861 | LifetimeExtendedTemporaryDecl *LETDecl = D; | |||
2862 | ||||
2863 | LifetimeExtendedTemporaryDecl *&LookupResult = | |||
2864 | Reader.LETemporaryForMerging[std::make_pair( | |||
2865 | LETDecl->getExtendingDecl(), LETDecl->getManglingNumber())]; | |||
2866 | if (LookupResult) | |||
2867 | Reader.getContext().setPrimaryMergedDecl(LETDecl, | |||
2868 | LookupResult->getCanonicalDecl()); | |||
2869 | else | |||
2870 | LookupResult = LETDecl; | |||
2871 | } | |||
2872 | ||||
2873 | /// Attempts to merge the given declaration (D) with another declaration | |||
2874 | /// of the same entity, for the case where the entity is not actually | |||
2875 | /// redeclarable. This happens, for instance, when merging the fields of | |||
2876 | /// identical class definitions from two different modules. | |||
2877 | template<typename T> | |||
2878 | void ASTDeclReader::mergeMergeable(Mergeable<T> *D) { | |||
2879 | // If modules are not available, there is no reason to perform this merge. | |||
2880 | if (!Reader.getContext().getLangOpts().Modules) | |||
| ||||
2881 | return; | |||
2882 | ||||
2883 | // ODR-based merging is performed in C++ and in some cases (tag types) in C. | |||
2884 | // Note that C identically-named things in different translation units are | |||
2885 | // not redeclarations, but may still have compatible types, where ODR-like | |||
2886 | // semantics may apply. | |||
2887 | if (!Reader.getContext().getLangOpts().CPlusPlus && | |||
2888 | !allowODRLikeMergeInC(dyn_cast<NamedDecl>(static_cast<T*>(D)))) | |||
2889 | return; | |||
2890 | ||||
2891 | if (FindExistingResult ExistingRes = findExisting(static_cast<T*>(D))) | |||
2892 | if (T *Existing = ExistingRes) | |||
2893 | Reader.getContext().setPrimaryMergedDecl(static_cast<T *>(D), | |||
2894 | Existing->getCanonicalDecl()); | |||
2895 | } | |||
2896 | ||||
2897 | void ASTDeclReader::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) { | |||
2898 | Record.readOMPChildren(D->Data); | |||
2899 | VisitDecl(D); | |||
2900 | } | |||
2901 | ||||
2902 | void ASTDeclReader::VisitOMPAllocateDecl(OMPAllocateDecl *D) { | |||
2903 | Record.readOMPChildren(D->Data); | |||
2904 | VisitDecl(D); | |||
2905 | } | |||
2906 | ||||
2907 | void ASTDeclReader::VisitOMPRequiresDecl(OMPRequiresDecl * D) { | |||
2908 | Record.readOMPChildren(D->Data); | |||
2909 | VisitDecl(D); | |||
2910 | } | |||
2911 | ||||
2912 | void ASTDeclReader::VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D) { | |||
2913 | VisitValueDecl(D); | |||
2914 | D->setLocation(readSourceLocation()); | |||
2915 | Expr *In = Record.readExpr(); | |||
2916 | Expr *Out = Record.readExpr(); | |||
2917 | D->setCombinerData(In, Out); | |||
2918 | Expr *Combiner = Record.readExpr(); | |||
2919 | D->setCombiner(Combiner); | |||
2920 | Expr *Orig = Record.readExpr(); | |||
2921 | Expr *Priv = Record.readExpr(); | |||
2922 | D->setInitializerData(Orig, Priv); | |||
2923 | Expr *Init = Record.readExpr(); | |||
2924 | auto IK = static_cast<OMPDeclareReductionDecl::InitKind>(Record.readInt()); | |||
2925 | D->setInitializer(Init, IK); | |||
2926 | D->PrevDeclInScope = readDeclID(); | |||
2927 | } | |||
2928 | ||||
2929 | void ASTDeclReader::VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D) { | |||
2930 | Record.readOMPChildren(D->Data); | |||
2931 | VisitValueDecl(D); | |||
2932 | D->VarName = Record.readDeclarationName(); | |||
2933 | D->PrevDeclInScope = readDeclID(); | |||
2934 | } | |||
2935 | ||||
2936 | void ASTDeclReader::VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D) { | |||
2937 | VisitVarDecl(D); | |||
2938 | } | |||
2939 | ||||
2940 | //===----------------------------------------------------------------------===// | |||
2941 | // Attribute Reading | |||
2942 | //===----------------------------------------------------------------------===// | |||
2943 | ||||
2944 | namespace { | |||
2945 | class AttrReader { | |||
2946 | ASTRecordReader &Reader; | |||
2947 | ||||
2948 | public: | |||
2949 | AttrReader(ASTRecordReader &Reader) : Reader(Reader) {} | |||
2950 | ||||
2951 | uint64_t readInt() { | |||
2952 | return Reader.readInt(); | |||
2953 | } | |||
2954 | ||||
2955 | bool readBool() { return Reader.readBool(); } | |||
2956 | ||||
2957 | SourceRange readSourceRange() { | |||
2958 | return Reader.readSourceRange(); | |||
2959 | } | |||
2960 | ||||
2961 | SourceLocation readSourceLocation() { | |||
2962 | return Reader.readSourceLocation(); | |||
2963 | } | |||
2964 | ||||
2965 | Expr *readExpr() { return Reader.readExpr(); } | |||
2966 | ||||
2967 | std::string readString() { | |||
2968 | return Reader.readString(); | |||
2969 | } | |||
2970 | ||||
2971 | TypeSourceInfo *readTypeSourceInfo() { | |||
2972 | return Reader.readTypeSourceInfo(); | |||
2973 | } | |||
2974 | ||||
2975 | IdentifierInfo *readIdentifier() { | |||
2976 | return Reader.readIdentifier(); | |||
2977 | } | |||
2978 | ||||
2979 | VersionTuple readVersionTuple() { | |||
2980 | return Reader.readVersionTuple(); | |||
2981 | } | |||
2982 | ||||
2983 | OMPTraitInfo *readOMPTraitInfo() { return Reader.readOMPTraitInfo(); } | |||
2984 | ||||
2985 | template <typename T> T *GetLocalDeclAs(uint32_t LocalID) { | |||
2986 | return Reader.GetLocalDeclAs<T>(LocalID); | |||
2987 | } | |||
2988 | }; | |||
2989 | } | |||
2990 | ||||
2991 | Attr *ASTRecordReader::readAttr() { | |||
2992 | AttrReader Record(*this); | |||
2993 | auto V = Record.readInt(); | |||
2994 | if (!V) | |||
2995 | return nullptr; | |||
2996 | ||||
2997 | Attr *New = nullptr; | |||
2998 | // Kind is stored as a 1-based integer because 0 is used to indicate a null | |||
2999 | // Attr pointer. | |||
3000 | auto Kind = static_cast<attr::Kind>(V - 1); | |||
3001 | ASTContext &Context = getContext(); | |||
3002 | ||||
3003 | IdentifierInfo *AttrName = Record.readIdentifier(); | |||
3004 | IdentifierInfo *ScopeName = Record.readIdentifier(); | |||
3005 | SourceRange AttrRange = Record.readSourceRange(); | |||
3006 | SourceLocation ScopeLoc = Record.readSourceLocation(); | |||
3007 | unsigned ParsedKind = Record.readInt(); | |||
3008 | unsigned Syntax = Record.readInt(); | |||
3009 | unsigned SpellingIndex = Record.readInt(); | |||
3010 | ||||
3011 | AttributeCommonInfo Info(AttrName, ScopeName, AttrRange, ScopeLoc, | |||
3012 | AttributeCommonInfo::Kind(ParsedKind), | |||
3013 | AttributeCommonInfo::Syntax(Syntax), SpellingIndex); | |||
3014 | ||||
3015 | #include "clang/Serialization/AttrPCHRead.inc" | |||
3016 | ||||
3017 | assert(New && "Unable to decode attribute?")(static_cast <bool> (New && "Unable to decode attribute?" ) ? void (0) : __assert_fail ("New && \"Unable to decode attribute?\"" , "clang/lib/Serialization/ASTReaderDecl.cpp", 3017, __extension__ __PRETTY_FUNCTION__)); | |||
3018 | return New; | |||
3019 | } | |||
3020 | ||||
3021 | /// Reads attributes from the current stream position. | |||
3022 | void ASTRecordReader::readAttributes(AttrVec &Attrs) { | |||
3023 | for (unsigned I = 0, E = readInt(); I != E; ++I) | |||
3024 | if (auto *A = readAttr()) | |||
3025 | Attrs.push_back(A); | |||
3026 | } | |||
3027 | ||||
3028 | //===----------------------------------------------------------------------===// | |||
3029 | // ASTReader Implementation | |||
3030 | //===----------------------------------------------------------------------===// | |||
3031 | ||||
3032 | /// Note that we have loaded the declaration with the given | |||
3033 | /// Index. | |||
3034 | /// | |||
3035 | /// This routine notes that this declaration has already been loaded, | |||
3036 | /// so that future GetDecl calls will return this declaration rather | |||
3037 | /// than trying to load a new declaration. | |||
3038 | inline void ASTReader::LoadedDecl(unsigned Index, Decl *D) { | |||
3039 | assert(!DeclsLoaded[Index] && "Decl loaded twice?")(static_cast <bool> (!DeclsLoaded[Index] && "Decl loaded twice?" ) ? void (0) : __assert_fail ("!DeclsLoaded[Index] && \"Decl loaded twice?\"" , "clang/lib/Serialization/ASTReaderDecl.cpp", 3039, __extension__ __PRETTY_FUNCTION__)); | |||
3040 | DeclsLoaded[Index] = D; | |||
3041 | } | |||
3042 | ||||
3043 | /// Determine whether the consumer will be interested in seeing | |||
3044 | /// this declaration (via HandleTopLevelDecl). | |||
3045 | /// | |||
3046 | /// This routine should return true for anything that might affect | |||
3047 | /// code generation, e.g., inline function definitions, Objective-C | |||
3048 | /// declarations with metadata, etc. | |||
3049 | static bool isConsumerInterestedIn(ASTContext &Ctx, Decl *D, bool HasBody) { | |||
3050 | // An ObjCMethodDecl is never considered as "interesting" because its | |||
3051 | // implementation container always is. | |||
3052 | ||||
3053 | // An ImportDecl or VarDecl imported from a module map module will get | |||
3054 | // emitted when we import the relevant module. | |||
3055 | if (isPartOfPerModuleInitializer(D)) { | |||
3056 | auto *M = D->getImportedOwningModule(); | |||
3057 | if (M && M->Kind == Module::ModuleMapModule && | |||
3058 | Ctx.DeclMustBeEmitted(D)) | |||
3059 | return false; | |||
3060 | } | |||
3061 | ||||
3062 | if (isa<FileScopeAsmDecl, TopLevelStmtDecl, ObjCProtocolDecl, ObjCImplDecl, | |||
3063 | ImportDecl, PragmaCommentDecl, PragmaDetectMismatchDecl>(D)) | |||
3064 | return true; | |||
3065 | if (isa<OMPThreadPrivateDecl, OMPDeclareReductionDecl, OMPDeclareMapperDecl, | |||
3066 | OMPAllocateDecl, OMPRequiresDecl>(D)) | |||
3067 | return !D->getDeclContext()->isFunctionOrMethod(); | |||
3068 | if (const auto *Var = dyn_cast<VarDecl>(D)) | |||
3069 | return Var->isFileVarDecl() && | |||
3070 | (Var->isThisDeclarationADefinition() == VarDecl::Definition || | |||
3071 | OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(Var)); | |||
3072 | if (const auto *Func = dyn_cast<FunctionDecl>(D)) | |||
3073 | return Func->doesThisDeclarationHaveABody() || HasBody; | |||
3074 | ||||
3075 | if (auto *ES = D->getASTContext().getExternalSource()) | |||
3076 | if (ES->hasExternalDefinitions(D) == ExternalASTSource::EK_Never) | |||
3077 | return true; | |||
3078 | ||||
3079 | return false; | |||
3080 | } | |||
3081 | ||||
3082 | /// Get the correct cursor and offset for loading a declaration. | |||
3083 | ASTReader::RecordLocation | |||
3084 | ASTReader::DeclCursorForID(DeclID ID, SourceLocation &Loc) { | |||
3085 | GlobalDeclMapType::iterator I = GlobalDeclMap.find(ID); | |||
3086 | assert(I != GlobalDeclMap.end() && "Corrupted global declaration map")(static_cast <bool> (I != GlobalDeclMap.end() && "Corrupted global declaration map") ? void (0) : __assert_fail ("I != GlobalDeclMap.end() && \"Corrupted global declaration map\"" , "clang/lib/Serialization/ASTReaderDecl.cpp", 3086, __extension__ __PRETTY_FUNCTION__)); | |||
3087 | ModuleFile *M = I->second; | |||
3088 | const DeclOffset &DOffs = | |||
3089 | M->DeclOffsets[ID - M->BaseDeclID - NUM_PREDEF_DECL_IDS]; | |||
3090 | Loc = TranslateSourceLocation(*M, DOffs.getLocation()); | |||
3091 | return RecordLocation(M, DOffs.getBitOffset(M->DeclsBlockStartOffset)); | |||
3092 | } | |||
3093 | ||||
3094 | ASTReader::RecordLocation ASTReader::getLocalBitOffset(uint64_t GlobalOffset) { | |||
3095 | auto I = GlobalBitOffsetsMap.find(GlobalOffset); | |||
3096 | ||||
3097 | assert(I != GlobalBitOffsetsMap.end() && "Corrupted global bit offsets map")(static_cast <bool> (I != GlobalBitOffsetsMap.end() && "Corrupted global bit offsets map") ? void (0) : __assert_fail ("I != GlobalBitOffsetsMap.end() && \"Corrupted global bit offsets map\"" , "clang/lib/Serialization/ASTReaderDecl.cpp", 3097, __extension__ __PRETTY_FUNCTION__)); | |||
3098 | return RecordLocation(I->second, GlobalOffset - I->second->GlobalBitOffset); | |||
3099 | } | |||
3100 | ||||
3101 | uint64_t ASTReader::getGlobalBitOffset(ModuleFile &M, uint64_t LocalOffset) { | |||
3102 | return LocalOffset + M.GlobalBitOffset; | |||
3103 | } | |||
3104 | ||||
3105 | /// Find the context in which we should search for previous declarations when | |||
3106 | /// looking for declarations to merge. | |||
3107 | DeclContext *ASTDeclReader::getPrimaryContextForMerging(ASTReader &Reader, | |||
3108 | DeclContext *DC) { | |||
3109 | if (auto *ND = dyn_cast<NamespaceDecl>(DC)) | |||
3110 | return ND->getOriginalNamespace(); | |||
3111 | ||||
3112 | if (auto *RD = dyn_cast<CXXRecordDecl>(DC)) { | |||
3113 | // Try to dig out the definition. | |||
3114 | auto *DD = RD->DefinitionData; | |||
3115 | if (!DD) | |||
3116 | DD = RD->getCanonicalDecl()->DefinitionData; | |||
3117 | ||||
3118 | // If there's no definition yet, then DC's definition is added by an update | |||
3119 | // record, but we've not yet loaded that update record. In this case, we | |||
3120 | // commit to DC being the canonical definition now, and will fix this when | |||
3121 | // we load the update record. | |||
3122 | if (!DD) { | |||
3123 | DD = new (Reader.getContext()) struct CXXRecordDecl::DefinitionData(RD); | |||
3124 | RD->setCompleteDefinition(true); | |||
3125 | RD->DefinitionData = DD; | |||
3126 | RD->getCanonicalDecl()->DefinitionData = DD; | |||
3127 | ||||
3128 | // Track that we did this horrible thing so that we can fix it later. | |||
3129 | Reader.PendingFakeDefinitionData.insert( | |||
3130 | std::make_pair(DD, ASTReader::PendingFakeDefinitionKind::Fake)); | |||
3131 | } | |||
3132 | ||||
3133 | return DD->Definition; | |||
3134 | } | |||
3135 | ||||
3136 | if (auto *RD = dyn_cast<RecordDecl>(DC)) | |||
3137 | return RD->getDefinition(); | |||
3138 | ||||
3139 | if (auto *ED = dyn_cast<EnumDecl>(DC)) | |||
3140 | return ED->getASTContext().getLangOpts().CPlusPlus? ED->getDefinition() | |||
3141 | : nullptr; | |||
3142 | ||||
3143 | if (auto *OID = dyn_cast<ObjCInterfaceDecl>(DC)) | |||
3144 | return OID->getDefinition(); | |||
3145 | ||||
3146 | // We can see the TU here only if we have no Sema object. In that case, | |||
3147 | // there's no TU scope to look in, so using the DC alone is sufficient. | |||
3148 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) | |||
3149 | return TU; | |||
3150 | ||||
3151 | return nullptr; | |||
3152 | } | |||
3153 | ||||
3154 | ASTDeclReader::FindExistingResult::~FindExistingResult() { | |||
3155 | // Record that we had a typedef name for linkage whether or not we merge | |||
3156 | // with that declaration. | |||
3157 | if (TypedefNameForLinkage) { | |||
3158 | DeclContext *DC = New->getDeclContext()->getRedeclContext(); | |||
3159 | Reader.ImportedTypedefNamesForLinkage.insert( | |||
3160 | std::make_pair(std::make_pair(DC, TypedefNameForLinkage), New)); | |||
3161 | return; | |||
3162 | } | |||
3163 | ||||
3164 | if (!AddResult || Existing) | |||
3165 | return; | |||
3166 | ||||
3167 | DeclarationName Name = New->getDeclName(); | |||
3168 | DeclContext *DC = New->getDeclContext()->getRedeclContext(); | |||
3169 | if (needsAnonymousDeclarationNumber(New)) { | |||
3170 | setAnonymousDeclForMerging(Reader, New->getLexicalDeclContext(), | |||
3171 | AnonymousDeclNumber, New); | |||
3172 | } else if (DC->isTranslationUnit() && | |||
3173 | !Reader.getContext().getLangOpts().CPlusPlus) { | |||
3174 | if (Reader.getIdResolver().tryAddTopLevelDecl(New, Name)) | |||
3175 | Reader.PendingFakeLookupResults[Name.getAsIdentifierInfo()] | |||
3176 | .push_back(New); | |||
3177 | } else if (DeclContext *MergeDC = getPrimaryContextForMerging(Reader, DC)) { | |||
3178 | // Add the declaration to its redeclaration context so later merging | |||
3179 | // lookups will find it. | |||
3180 | MergeDC->makeDeclVisibleInContextImpl(New, /*Internal*/true); | |||
3181 | } | |||
3182 | } | |||
3183 | ||||
3184 | /// Find the declaration that should be merged into, given the declaration found | |||
3185 | /// by name lookup. If we're merging an anonymous declaration within a typedef, | |||
3186 | /// we need a matching typedef, and we merge with the type inside it. | |||
3187 | static NamedDecl *getDeclForMerging(NamedDecl *Found, | |||
3188 | bool IsTypedefNameForLinkage) { | |||
3189 | if (!IsTypedefNameForLinkage) | |||
3190 | return Found; | |||
3191 | ||||
3192 | // If we found a typedef declaration that gives a name to some other | |||
3193 | // declaration, then we want that inner declaration. Declarations from | |||
3194 | // AST files are handled via ImportedTypedefNamesForLinkage. | |||
3195 | if (Found->isFromASTFile()) | |||
3196 | return nullptr; | |||
3197 | ||||
3198 | if (auto *TND = dyn_cast<TypedefNameDecl>(Found)) | |||
3199 | return TND->getAnonDeclWithTypedefName(/*AnyRedecl*/true); | |||
3200 | ||||
3201 | return nullptr; | |||
3202 | } | |||
3203 | ||||
3204 | /// Find the declaration to use to populate the anonymous declaration table | |||
3205 | /// for the given lexical DeclContext. We only care about finding local | |||
3206 | /// definitions of the context; we'll merge imported ones as we go. | |||
3207 | DeclContext * | |||
3208 | ASTDeclReader::getPrimaryDCForAnonymousDecl(DeclContext *LexicalDC) { | |||
3209 | // For classes, we track the definition as we merge. | |||
3210 | if (auto *RD
| |||
3211 | auto *DD = RD->getCanonicalDecl()->DefinitionData; | |||
3212 | return DD ? DD->Definition : nullptr; | |||
3213 | } else if (auto *OID
| |||
3214 | return OID->getCanonicalDecl()->getDefinition(); | |||
3215 | } | |||
3216 | ||||
3217 | // For anything else, walk its merged redeclarations looking for a definition. | |||
3218 | // Note that we can't just call getDefinition here because the redeclaration | |||
3219 | // chain isn't wired up. | |||
3220 | for (auto *D : merged_redecls(cast<Decl>(LexicalDC))) { | |||
3221 | if (auto *FD
| |||
3222 | if (FD->isThisDeclarationADefinition()) | |||
3223 | return FD; | |||
3224 | if (auto *MD
| |||
3225 | if (MD->isThisDeclarationADefinition()) | |||
3226 | return MD; | |||
3227 | if (auto *RD
| |||
3228 | if (RD->isThisDeclarationADefinition()) | |||
3229 | return RD; | |||
3230 | } | |||
3231 | ||||
3232 | // No merged definition yet. | |||
3233 | return nullptr; | |||
3234 | } | |||
3235 | ||||
3236 | NamedDecl *ASTDeclReader::getAnonymousDeclForMerging(ASTReader &Reader, | |||
3237 | DeclContext *DC, | |||
3238 | unsigned Index) { | |||
3239 | // If the lexical context has been merged, look into the now-canonical | |||
3240 | // definition. | |||
3241 | auto *CanonDC = cast<Decl>(DC)->getCanonicalDecl(); | |||
3242 | ||||
3243 | // If we've seen this before, return the canonical declaration. | |||
3244 | auto &Previous = Reader.AnonymousDeclarationsForMerging[CanonDC]; | |||
3245 | if (Index < Previous.size() && Previous[Index]) | |||
3246 | return Previous[Index]; | |||
3247 | ||||
3248 | // If this is the first time, but we have parsed a declaration of the context, | |||
3249 | // build the anonymous declaration list from the parsed declaration. | |||
3250 | auto *PrimaryDC = getPrimaryDCForAnonymousDecl(DC); | |||
3251 | if (PrimaryDC && !cast<Decl>(PrimaryDC)->isFromASTFile()) { | |||
3252 | numberAnonymousDeclsWithin(PrimaryDC, [&](NamedDecl *ND, unsigned Number) { | |||
3253 | if (Previous.size() == Number) | |||
3254 | Previous.push_back(cast<NamedDecl>(ND->getCanonicalDecl())); | |||
3255 | else | |||
3256 | Previous[Number] = cast<NamedDecl>(ND->getCanonicalDecl()); | |||
3257 | }); | |||
3258 | } | |||
3259 | ||||
3260 | return Index < Previous.size() ? Previous[Index] : nullptr; | |||
3261 | } | |||
3262 | ||||
3263 | void ASTDeclReader::setAnonymousDeclForMerging(ASTReader &Reader, | |||
3264 | DeclContext *DC, unsigned Index, | |||
3265 | NamedDecl *D) { | |||
3266 | auto *CanonDC = cast<Decl>(DC)->getCanonicalDecl(); | |||
3267 | ||||
3268 | auto &Previous = Reader.AnonymousDeclarationsForMerging[CanonDC]; | |||
3269 | if (Index >= Previous.size()) | |||
3270 | Previous.resize(Index + 1); | |||
3271 | if (!Previous[Index]) | |||
3272 | Previous[Index] = D; | |||
3273 | } | |||
3274 | ||||
3275 | ASTDeclReader::FindExistingResult ASTDeclReader::findExisting(NamedDecl *D) { | |||
3276 | DeclarationName Name = TypedefNameForLinkage ? TypedefNameForLinkage | |||
3277 | : D->getDeclName(); | |||
3278 | ||||
3279 | if (!Name && !needsAnonymousDeclarationNumber(D)) { | |||
3280 | // Don't bother trying to find unnamed declarations that are in | |||
3281 | // unmergeable contexts. | |||
3282 | FindExistingResult Result(Reader, D, /*Existing=*/nullptr, | |||
3283 | AnonymousDeclNumber, TypedefNameForLinkage); | |||
3284 | Result.suppress(); | |||
3285 | return Result; | |||
3286 | } | |||
3287 | ||||
3288 | ASTContext &C = Reader.getContext(); | |||
3289 | DeclContext *DC = D->getDeclContext()->getRedeclContext(); | |||
3290 | if (TypedefNameForLinkage
| |||
3291 | auto It = Reader.ImportedTypedefNamesForLinkage.find( | |||
3292 | std::make_pair(DC, TypedefNameForLinkage)); | |||
3293 | if (It != Reader.ImportedTypedefNamesForLinkage.end()) | |||
3294 | if (C.isSameEntity(It->second, D)) | |||
3295 | return FindExistingResult(Reader, D, It->second, AnonymousDeclNumber, | |||
3296 | TypedefNameForLinkage); | |||
3297 | // Go on to check in other places in case an existing typedef name | |||
3298 | // was not imported. | |||
3299 | } | |||
3300 | ||||
3301 | if (needsAnonymousDeclarationNumber(D)) { | |||
3302 | // This is an anonymous declaration that we may need to merge. Look it up | |||
3303 | // in its context by number. | |||
3304 | if (auto *Existing = getAnonymousDeclForMerging( | |||
3305 | Reader, D->getLexicalDeclContext(), AnonymousDeclNumber)) | |||
3306 | if (C.isSameEntity(Existing, D)) | |||
3307 | return FindExistingResult(Reader, D, Existing, AnonymousDeclNumber, | |||
3308 | TypedefNameForLinkage); | |||
3309 | } else if (DC->isTranslationUnit() && | |||
3310 | !Reader.getContext().getLangOpts().CPlusPlus) { | |||
3311 | IdentifierResolver &IdResolver = Reader.getIdResolver(); | |||
3312 | ||||
3313 | // Temporarily consider the identifier to be up-to-date. We don't want to | |||
3314 | // cause additional lookups here. | |||
3315 | class UpToDateIdentifierRAII { | |||
3316 | IdentifierInfo *II; | |||
3317 | bool WasOutToDate = false; | |||
3318 | ||||
3319 | public: | |||
3320 | explicit UpToDateIdentifierRAII(IdentifierInfo *II) : II(II) { | |||
3321 | if (II) { | |||
3322 | WasOutToDate = II->isOutOfDate(); | |||
3323 | if (WasOutToDate) | |||
3324 | II->setOutOfDate(false); | |||
3325 | } | |||
3326 | } | |||
3327 | ||||
3328 | ~UpToDateIdentifierRAII() { | |||
3329 | if (WasOutToDate) | |||
3330 | II->setOutOfDate(true); | |||
3331 | } | |||
3332 | } UpToDate(Name.getAsIdentifierInfo()); | |||
3333 | ||||
3334 | for (IdentifierResolver::iterator I = IdResolver.begin(Name), | |||
3335 | IEnd = IdResolver.end(); | |||
3336 | I != IEnd; ++I) { | |||
3337 | if (NamedDecl *Existing = getDeclForMerging(*I, TypedefNameForLinkage)) | |||
3338 | if (C.isSameEntity(Existing, D)) | |||
3339 | return FindExistingResult(Reader, D, Existing, AnonymousDeclNumber, | |||
3340 | TypedefNameForLinkage); | |||
3341 | } | |||
3342 | } else if (DeclContext *MergeDC = getPrimaryContextForMerging(Reader, DC)) { | |||
3343 | DeclContext::lookup_result R = MergeDC->noload_lookup(Name); | |||
3344 | for (DeclContext::lookup_iterator I = R.begin(), E = R.end(); I != E; ++I) { | |||
3345 | if (NamedDecl *Existing = getDeclForMerging(*I, TypedefNameForLinkage)) | |||
3346 | if (C.isSameEntity(Existing, D)) | |||
3347 | return FindExistingResult(Reader, D, Existing, AnonymousDeclNumber, | |||
3348 | TypedefNameForLinkage); | |||
3349 | } | |||
3350 | } else { | |||
3351 | // Not in a mergeable context. | |||
3352 | return FindExistingResult(Reader); | |||
3353 | } | |||
3354 | ||||
3355 | // If this declaration is from a merged context, make a note that we need to | |||
3356 | // check that the canonical definition of that context contains the decl. | |||
3357 | // | |||
3358 | // FIXME: We should do something similar if we merge two definitions of the | |||
3359 | // same template specialization into the same CXXRecordDecl. | |||
3360 | auto MergedDCIt = Reader.MergedDeclContexts.find(D->getLexicalDeclContext()); | |||
3361 | if (MergedDCIt != Reader.MergedDeclContexts.end() && | |||
3362 | MergedDCIt->second == D->getDeclContext()) | |||
3363 | Reader.PendingOdrMergeChecks.push_back(D); | |||
3364 | ||||
3365 | return FindExistingResult(Reader, D, /*Existing=*/nullptr, | |||
3366 | AnonymousDeclNumber, TypedefNameForLinkage); | |||
3367 | } | |||
3368 | ||||
3369 | template<typename DeclT> | |||
3370 | Decl *ASTDeclReader::getMostRecentDeclImpl(Redeclarable<DeclT> *D) { | |||
3371 | return D->RedeclLink.getLatestNotUpdated(); | |||
3372 | } | |||
3373 | ||||
3374 | Decl *ASTDeclReader::getMostRecentDeclImpl(...) { | |||
3375 | llvm_unreachable("getMostRecentDecl on non-redeclarable declaration")::llvm::llvm_unreachable_internal("getMostRecentDecl on non-redeclarable declaration" , "clang/lib/Serialization/ASTReaderDecl.cpp", 3375); | |||
3376 | } | |||
3377 | ||||
3378 | Decl *ASTDeclReader::getMostRecentDecl(Decl *D) { | |||
3379 | assert(D)(static_cast <bool> (D) ? void (0) : __assert_fail ("D" , "clang/lib/Serialization/ASTReaderDecl.cpp", 3379, __extension__ __PRETTY_FUNCTION__)); | |||
3380 | ||||
3381 | switch (D->getKind()) { | |||
3382 | #define ABSTRACT_DECL(TYPE) | |||
3383 | #define DECL(TYPE, BASE) \ | |||
3384 | case Decl::TYPE: \ | |||
3385 | return getMostRecentDeclImpl(cast<TYPE##Decl>(D)); | |||
3386 | #include "clang/AST/DeclNodes.inc" | |||
3387 | } | |||
3388 | llvm_unreachable("unknown decl kind")::llvm::llvm_unreachable_internal("unknown decl kind", "clang/lib/Serialization/ASTReaderDecl.cpp" , 3388); | |||
3389 | } | |||
3390 | ||||
3391 | Decl *ASTReader::getMostRecentExistingDecl(Decl *D) { | |||
3392 | return ASTDeclReader::getMostRecentDecl(D->getCanonicalDecl()); | |||
3393 | } | |||
3394 | ||||
3395 | void ASTDeclReader::mergeInheritableAttributes(ASTReader &Reader, Decl *D, | |||
3396 | Decl *Previous) { | |||
3397 | InheritableAttr *NewAttr = nullptr; | |||
3398 | ASTContext &Context = Reader.getContext(); | |||
3399 | const auto *IA = Previous->getAttr<MSInheritanceAttr>(); | |||
3400 | ||||
3401 | if (IA && !D->hasAttr<MSInheritanceAttr>()) { | |||
3402 | NewAttr = cast<InheritableAttr>(IA->clone(Context)); | |||
3403 | NewAttr->setInherited(true); | |||
3404 | D->addAttr(NewAttr); | |||
3405 | } | |||
3406 | ||||
3407 | const auto *AA = Previous->getAttr<AvailabilityAttr>(); | |||
3408 | if (AA && !D->hasAttr<AvailabilityAttr>()) { | |||
3409 | NewAttr = AA->clone(Context); | |||
3410 | NewAttr->setInherited(true); | |||
3411 | D->addAttr(NewAttr); | |||
3412 | } | |||
3413 | } | |||
3414 | ||||
3415 | template<typename DeclT> | |||
3416 | void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader, | |||
3417 | Redeclarable<DeclT> *D, | |||
3418 | Decl *Previous, Decl *Canon) { | |||
3419 | D->RedeclLink.setPrevious(cast<DeclT>(Previous)); | |||
3420 | D->First = cast<DeclT>(Previous)->First; | |||
3421 | } | |||
3422 | ||||
3423 | namespace clang { | |||
3424 | ||||
3425 | template<> | |||
3426 | void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader, | |||
3427 | Redeclarable<VarDecl> *D, | |||
3428 | Decl *Previous, Decl *Canon) { | |||
3429 | auto *VD = static_cast<VarDecl *>(D); | |||
3430 | auto *PrevVD = cast<VarDecl>(Previous); | |||
3431 | D->RedeclLink.setPrevious(PrevVD); | |||
3432 | D->First = PrevVD->First; | |||
3433 | ||||
3434 | // We should keep at most one definition on the chain. | |||
3435 | // FIXME: Cache the definition once we've found it. Building a chain with | |||
3436 | // N definitions currently takes O(N^2) time here. | |||
3437 | if (VD->isThisDeclarationADefinition() == VarDecl::Definition) { | |||
3438 | for (VarDecl *CurD = PrevVD; CurD; CurD = CurD->getPreviousDecl()) { | |||
3439 | if (CurD->isThisDeclarationADefinition() == VarDecl::Definition) { | |||
3440 | Reader.mergeDefinitionVisibility(CurD, VD); | |||
3441 | VD->demoteThisDefinitionToDeclaration(); | |||
3442 | break; | |||
3443 | } | |||
3444 | } | |||
3445 | } | |||
3446 | } | |||
3447 | ||||
3448 | static bool isUndeducedReturnType(QualType T) { | |||
3449 | auto *DT = T->getContainedDeducedType(); | |||
3450 | return DT && !DT->isDeduced(); | |||
3451 | } | |||
3452 | ||||
3453 | template<> | |||
3454 | void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader, | |||
3455 | Redeclarable<FunctionDecl> *D, | |||
3456 | Decl *Previous, Decl *Canon) { | |||
3457 | auto *FD = static_cast<FunctionDecl *>(D); | |||
3458 | auto *PrevFD = cast<FunctionDecl>(Previous); | |||
3459 | ||||
3460 | FD->RedeclLink.setPrevious(PrevFD); | |||
3461 | FD->First = PrevFD->First; | |||
3462 | ||||
3463 | // If the previous declaration is an inline function declaration, then this | |||
3464 | // declaration is too. | |||
3465 | if (PrevFD->isInlined() != FD->isInlined()) { | |||
3466 | // FIXME: [dcl.fct.spec]p4: | |||
3467 | // If a function with external linkage is declared inline in one | |||
3468 | // translation unit, it shall be declared inline in all translation | |||
3469 | // units in which it appears. | |||
3470 | // | |||
3471 | // Be careful of this case: | |||
3472 | // | |||
3473 | // module A: | |||
3474 | // template<typename T> struct X { void f(); }; | |||
3475 | // template<typename T> inline void X<T>::f() {} | |||
3476 | // | |||
3477 | // module B instantiates the declaration of X<int>::f | |||
3478 | // module C instantiates the definition of X<int>::f | |||
3479 | // | |||
3480 | // If module B and C are merged, we do not have a violation of this rule. | |||
3481 | FD->setImplicitlyInline(true); | |||
3482 | } | |||
3483 | ||||
3484 | auto *FPT = FD->getType()->getAs<FunctionProtoType>(); | |||
3485 | auto *PrevFPT = PrevFD->getType()->getAs<FunctionProtoType>(); | |||
3486 | if (FPT && PrevFPT) { | |||
3487 | // If we need to propagate an exception specification along the redecl | |||
3488 | // chain, make a note of that so that we can do so later. | |||
3489 | bool IsUnresolved = isUnresolvedExceptionSpec(FPT->getExceptionSpecType()); | |||
3490 | bool WasUnresolved = | |||
3491 | isUnresolvedExceptionSpec(PrevFPT->getExceptionSpecType()); | |||
3492 | if (IsUnresolved != WasUnresolved) | |||
3493 | Reader.PendingExceptionSpecUpdates.insert( | |||
3494 | {Canon, IsUnresolved ? PrevFD : FD}); | |||
3495 | ||||
3496 | // If we need to propagate a deduced return type along the redecl chain, | |||
3497 | // make a note of that so that we can do it later. | |||
3498 | bool IsUndeduced = isUndeducedReturnType(FPT->getReturnType()); | |||
3499 | bool WasUndeduced = isUndeducedReturnType(PrevFPT->getReturnType()); | |||
3500 | if (IsUndeduced != WasUndeduced) | |||
3501 | Reader.PendingDeducedTypeUpdates.insert( | |||
3502 | {cast<FunctionDecl>(Canon), | |||
3503 | (IsUndeduced ? PrevFPT : FPT)->getReturnType()}); | |||
3504 | } | |||
3505 | } | |||
3506 | ||||
3507 | } // namespace clang | |||
3508 | ||||
3509 | void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader, ...) { | |||
3510 | llvm_unreachable("attachPreviousDecl on non-redeclarable declaration")::llvm::llvm_unreachable_internal("attachPreviousDecl on non-redeclarable declaration" , "clang/lib/Serialization/ASTReaderDecl.cpp", 3510); | |||
3511 | } | |||
3512 | ||||
3513 | /// Inherit the default template argument from \p From to \p To. Returns | |||
3514 | /// \c false if there is no default template for \p From. | |||
3515 | template <typename ParmDecl> | |||
3516 | static bool inheritDefaultTemplateArgument(ASTContext &Context, ParmDecl *From, | |||
3517 | Decl *ToD) { | |||
3518 | auto *To = cast<ParmDecl>(ToD); | |||
3519 | if (!From->hasDefaultArgument()) | |||
3520 | return false; | |||
3521 | To->setInheritedDefaultArgument(Context, From); | |||
3522 | return true; | |||
3523 | } | |||
3524 | ||||
3525 | static void inheritDefaultTemplateArguments(ASTContext &Context, | |||
3526 | TemplateDecl *From, | |||
3527 | TemplateDecl *To) { | |||
3528 | auto *FromTP = From->getTemplateParameters(); | |||
3529 | auto *ToTP = To->getTemplateParameters(); | |||
3530 | assert(FromTP->size() == ToTP->size() && "merged mismatched templates?")(static_cast <bool> (FromTP->size() == ToTP->size () && "merged mismatched templates?") ? void (0) : __assert_fail ("FromTP->size() == ToTP->size() && \"merged mismatched templates?\"" , "clang/lib/Serialization/ASTReaderDecl.cpp", 3530, __extension__ __PRETTY_FUNCTION__)); | |||
3531 | ||||
3532 | for (unsigned I = 0, N = FromTP->size(); I != N; ++I) { | |||
3533 | NamedDecl *FromParam = FromTP->getParam(I); | |||
3534 | NamedDecl *ToParam = ToTP->getParam(I); | |||
3535 | ||||
3536 | if (auto *FTTP = dyn_cast<TemplateTypeParmDecl>(FromParam)) | |||
3537 | inheritDefaultTemplateArgument(Context, FTTP, ToParam); | |||
3538 | else if (auto *FNTTP = dyn_cast<NonTypeTemplateParmDecl>(FromParam)) | |||
3539 | inheritDefaultTemplateArgument(Context, FNTTP, ToParam); | |||
3540 | else | |||
3541 | inheritDefaultTemplateArgument( | |||
3542 | Context, cast<TemplateTemplateParmDecl>(FromParam), ToParam); | |||
3543 | } | |||
3544 | } | |||
3545 | ||||
3546 | void ASTDeclReader::attachPreviousDecl(ASTReader &Reader, Decl *D, | |||
3547 | Decl *Previous, Decl *Canon) { | |||
3548 | assert(D && Previous)(static_cast <bool> (D && Previous) ? void (0) : __assert_fail ("D && Previous", "clang/lib/Serialization/ASTReaderDecl.cpp" , 3548, __extension__ __PRETTY_FUNCTION__)); | |||
3549 | ||||
3550 | switch (D->getKind()) { | |||
3551 | #define ABSTRACT_DECL(TYPE) | |||
3552 | #define DECL(TYPE, BASE) \ | |||
3553 | case Decl::TYPE: \ | |||
3554 | attachPreviousDeclImpl(Reader, cast<TYPE##Decl>(D), Previous, Canon); \ | |||
3555 | break; | |||
3556 | #include "clang/AST/DeclNodes.inc" | |||
3557 | } | |||
3558 | ||||
3559 | // If the declaration was visible in one module, a redeclaration of it in | |||
3560 | // another module remains visible even if it wouldn't be visible by itself. | |||
3561 | // | |||
3562 | // FIXME: In this case, the declaration should only be visible if a module | |||
3563 | // that makes it visible has been imported. | |||
3564 | D->IdentifierNamespace |= | |||
3565 | Previous->IdentifierNamespace & | |||
3566 | (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type); | |||
3567 | ||||
3568 | // If the declaration declares a template, it may inherit default arguments | |||
3569 | // from the previous declaration. | |||
3570 | if (auto *TD = dyn_cast<TemplateDecl>(D)) | |||
3571 | inheritDefaultTemplateArguments(Reader.getContext(), | |||
3572 | cast<TemplateDecl>(Previous), TD); | |||
3573 | ||||
3574 | // If any of the declaration in the chain contains an Inheritable attribute, | |||
3575 | // it needs to be added to all the declarations in the redeclarable chain. | |||
3576 | // FIXME: Only the logic of merging MSInheritableAttr is present, it should | |||
3577 | // be extended for all inheritable attributes. | |||
3578 | mergeInheritableAttributes(Reader, D, Previous); | |||
3579 | } | |||
3580 | ||||
3581 | template<typename DeclT> | |||
3582 | void ASTDeclReader::attachLatestDeclImpl(Redeclarable<DeclT> *D, Decl *Latest) { | |||
3583 | D->RedeclLink.setLatest(cast<DeclT>(Latest)); | |||
3584 | } | |||
3585 | ||||
3586 | void ASTDeclReader::attachLatestDeclImpl(...) { | |||
3587 | llvm_unreachable("attachLatestDecl on non-redeclarable declaration")::llvm::llvm_unreachable_internal("attachLatestDecl on non-redeclarable declaration" , "clang/lib/Serialization/ASTReaderDecl.cpp", 3587); | |||
3588 | } | |||
3589 | ||||
3590 | void ASTDeclReader::attachLatestDecl(Decl *D, Decl *Latest) { | |||
3591 | assert(D && Latest)(static_cast <bool> (D && Latest) ? void (0) : __assert_fail ("D && Latest", "clang/lib/Serialization/ASTReaderDecl.cpp" , 3591, __extension__ __PRETTY_FUNCTION__)); | |||
3592 | ||||
3593 | switch (D->getKind()) { | |||
3594 | #define ABSTRACT_DECL(TYPE) | |||
3595 | #define DECL(TYPE, BASE) \ | |||
3596 | case Decl::TYPE: \ | |||
3597 | attachLatestDeclImpl(cast<TYPE##Decl>(D), Latest); \ | |||
3598 | break; | |||
3599 | #include "clang/AST/DeclNodes.inc" | |||
3600 | } | |||
3601 | } | |||
3602 | ||||
3603 | template<typename DeclT> | |||
3604 | void ASTDeclReader::markIncompleteDeclChainImpl(Redeclarable<DeclT> *D) { | |||
3605 | D->RedeclLink.markIncomplete(); | |||
3606 | } | |||
3607 | ||||
3608 | void ASTDeclReader::markIncompleteDeclChainImpl(...) { | |||
3609 | llvm_unreachable("markIncompleteDeclChain on non-redeclarable declaration")::llvm::llvm_unreachable_internal("markIncompleteDeclChain on non-redeclarable declaration" , "clang/lib/Serialization/ASTReaderDecl.cpp", 3609); | |||
3610 | } | |||
3611 | ||||
3612 | void ASTReader::markIncompleteDeclChain(Decl *D) { | |||
3613 | switch (D->getKind()) { | |||
3614 | #define ABSTRACT_DECL(TYPE) | |||
3615 | #define DECL(TYPE, BASE) \ | |||
3616 | case Decl::TYPE: \ | |||
3617 | ASTDeclReader::markIncompleteDeclChainImpl(cast<TYPE##Decl>(D)); \ | |||
3618 | break; | |||
3619 | #include "clang/AST/DeclNodes.inc" | |||
3620 | } | |||
3621 | } | |||
3622 | ||||
3623 | /// Read the declaration at the given offset from the AST file. | |||
3624 | Decl *ASTReader::ReadDeclRecord(DeclID ID) { | |||
3625 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; | |||
3626 | SourceLocation DeclLoc; | |||
3627 | RecordLocation Loc = DeclCursorForID(ID, DeclLoc); | |||
3628 | llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor; | |||
3629 | // Keep track of where we are in the stream, then jump back there | |||
3630 | // after reading this declaration. | |||
3631 | SavedStreamPosition SavedPosition(DeclsCursor); | |||
3632 | ||||
3633 | ReadingKindTracker ReadingKind(Read_Decl, *this); | |||
3634 | ||||
3635 | // Note that we are loading a declaration record. | |||
3636 | Deserializing ADecl(this); | |||
3637 | ||||
3638 | auto Fail = [](const char *what, llvm::Error &&Err) { | |||
3639 | llvm::report_fatal_error(Twine("ASTReader::readDeclRecord failed ") + what + | |||
3640 | ": " + toString(std::move(Err))); | |||
3641 | }; | |||
3642 | ||||
3643 | if (llvm::Error JumpFailed = DeclsCursor.JumpToBit(Loc.Offset)) | |||
3644 | Fail("jumping", std::move(JumpFailed)); | |||
3645 | ASTRecordReader Record(*this, *Loc.F); | |||
3646 | ASTDeclReader Reader(*this, Record, Loc, ID, DeclLoc); | |||
3647 | Expected<unsigned> MaybeCode = DeclsCursor.ReadCode(); | |||
3648 | if (!MaybeCode) | |||
3649 | Fail("reading code", MaybeCode.takeError()); | |||
3650 | unsigned Code = MaybeCode.get(); | |||
3651 | ||||
3652 | ASTContext &Context = getContext(); | |||
3653 | Decl *D = nullptr; | |||
3654 | Expected<unsigned> MaybeDeclCode = Record.readRecord(DeclsCursor, Code); | |||
3655 | if (!MaybeDeclCode) | |||
3656 | llvm::report_fatal_error( | |||
3657 | Twine("ASTReader::readDeclRecord failed reading decl code: ") + | |||
3658 | toString(MaybeDeclCode.takeError())); | |||
3659 | switch ((DeclCode)MaybeDeclCode.get()) { | |||
3660 | case DECL_CONTEXT_LEXICAL: | |||
3661 | case DECL_CONTEXT_VISIBLE: | |||
3662 | llvm_unreachable("Record cannot be de-serialized with readDeclRecord")::llvm::llvm_unreachable_internal("Record cannot be de-serialized with readDeclRecord" , "clang/lib/Serialization/ASTReaderDecl.cpp", 3662); | |||
3663 | case DECL_TYPEDEF: | |||
3664 | D = TypedefDecl::CreateDeserialized(Context, ID); | |||
3665 | break; | |||
3666 | case DECL_TYPEALIAS: | |||
3667 | D = TypeAliasDecl::CreateDeserialized(Context, ID); | |||
3668 | break; | |||
3669 | case DECL_ENUM: | |||
3670 | D = EnumDecl::CreateDeserialized(Context, ID); | |||
3671 | break; | |||
3672 | case DECL_RECORD: | |||
3673 | D = RecordDecl::CreateDeserialized(Context, ID); | |||
3674 | break; | |||
3675 | case DECL_ENUM_CONSTANT: | |||
3676 | D = EnumConstantDecl::CreateDeserialized(Context, ID); | |||
3677 | break; | |||
3678 | case DECL_FUNCTION: | |||
3679 | D = FunctionDecl::CreateDeserialized(Context, ID); | |||
3680 | break; | |||
3681 | case DECL_LINKAGE_SPEC: | |||
3682 | D = LinkageSpecDecl::CreateDeserialized(Context, ID); | |||
3683 | break; | |||
3684 | case DECL_EXPORT: | |||
3685 | D = ExportDecl::CreateDeserialized(Context, ID); | |||
3686 | break; | |||
3687 | case DECL_LABEL: | |||
3688 | D = LabelDecl::CreateDeserialized(Context, ID); | |||
3689 | break; | |||
3690 | case DECL_NAMESPACE: | |||
3691 | D = NamespaceDecl::CreateDeserialized(Context, ID); | |||
3692 | break; | |||
3693 | case DECL_NAMESPACE_ALIAS: | |||
3694 | D = NamespaceAliasDecl::CreateDeserialized(Context, ID); | |||
3695 | break; | |||
3696 | case DECL_USING: | |||
3697 | D = UsingDecl::CreateDeserialized(Context, ID); | |||
3698 | break; | |||
3699 | case DECL_USING_PACK: | |||
3700 | D = UsingPackDecl::CreateDeserialized(Context, ID, Record.readInt()); | |||
3701 | break; | |||
3702 | case DECL_USING_SHADOW: | |||
3703 | D = UsingShadowDecl::CreateDeserialized(Context, ID); | |||
3704 | break; | |||
3705 | case DECL_USING_ENUM: | |||
3706 | D = UsingEnumDecl::CreateDeserialized(Context, ID); | |||
3707 | break; | |||
3708 | case DECL_CONSTRUCTOR_USING_SHADOW: | |||
3709 | D = ConstructorUsingShadowDecl::CreateDeserialized(Context, ID); | |||
3710 | break; | |||
3711 | case DECL_USING_DIRECTIVE: | |||
3712 | D = UsingDirectiveDecl::CreateDeserialized(Context, ID); | |||
3713 | break; | |||
3714 | case DECL_UNRESOLVED_USING_VALUE: | |||
3715 | D = UnresolvedUsingValueDecl::CreateDeserialized(Context, ID); | |||
3716 | break; | |||
3717 | case DECL_UNRESOLVED_USING_TYPENAME: | |||
3718 | D = UnresolvedUsingTypenameDecl::CreateDeserialized(Context, ID); | |||
3719 | break; | |||
3720 | case DECL_UNRESOLVED_USING_IF_EXISTS: | |||
3721 | D = UnresolvedUsingIfExistsDecl::CreateDeserialized(Context, ID); | |||
3722 | break; | |||
3723 | case DECL_CXX_RECORD: | |||
3724 | D = CXXRecordDecl::CreateDeserialized(Context, ID); | |||
3725 | break; | |||
3726 | case DECL_CXX_DEDUCTION_GUIDE: | |||
3727 | D = CXXDeductionGuideDecl::CreateDeserialized(Context, ID); | |||
3728 | break; | |||
3729 | case DECL_CXX_METHOD: | |||
3730 | D = CXXMethodDecl::CreateDeserialized(Context, ID); | |||
3731 | break; | |||
3732 | case DECL_CXX_CONSTRUCTOR: | |||
3733 | D = CXXConstructorDecl::CreateDeserialized(Context, ID, Record.readInt()); | |||
3734 | break; | |||
3735 | case DECL_CXX_DESTRUCTOR: | |||
3736 | D = CXXDestructorDecl::CreateDeserialized(Context, ID); | |||
3737 | break; | |||
3738 | case DECL_CXX_CONVERSION: | |||
3739 | D = CXXConversionDecl::CreateDeserialized(Context, ID); | |||
3740 | break; | |||
3741 | case DECL_ACCESS_SPEC: | |||
3742 | D = AccessSpecDecl::CreateDeserialized(Context, ID); | |||
3743 | break; | |||
3744 | case DECL_FRIEND: | |||
3745 | D = FriendDecl::CreateDeserialized(Context, ID, Record.readInt()); | |||
3746 | break; | |||
3747 | case DECL_FRIEND_TEMPLATE: | |||
3748 | D = FriendTemplateDecl::CreateDeserialized(Context, ID); | |||
3749 | break; | |||
3750 | case DECL_CLASS_TEMPLATE: | |||
3751 | D = ClassTemplateDecl::CreateDeserialized(Context, ID); | |||
3752 | break; | |||
3753 | case DECL_CLASS_TEMPLATE_SPECIALIZATION: | |||
3754 | D = ClassTemplateSpecializationDecl::CreateDeserialized(Context, ID); | |||
3755 | break; | |||
3756 | case DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION: | |||
3757 | D = ClassTemplatePartialSpecializationDecl::CreateDeserialized(Context, ID); | |||
3758 | break; | |||
3759 | case DECL_VAR_TEMPLATE: | |||
3760 | D = VarTemplateDecl::CreateDeserialized(Context, ID); | |||
3761 | break; | |||
3762 | case DECL_VAR_TEMPLATE_SPECIALIZATION: | |||
3763 | D = VarTemplateSpecializationDecl::CreateDeserialized(Context, ID); | |||
3764 | break; | |||
3765 | case DECL_VAR_TEMPLATE_PARTIAL_SPECIALIZATION: | |||
3766 | D = VarTemplatePartialSpecializationDecl::CreateDeserialized(Context, ID); | |||
3767 | break; | |||
3768 | case DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION: | |||
3769 | D = ClassScopeFunctionSpecializationDecl::CreateDeserialized(Context, ID); | |||
3770 | break; | |||
3771 | case DECL_FUNCTION_TEMPLATE: | |||
3772 | D = FunctionTemplateDecl::CreateDeserialized(Context, ID); | |||
3773 | break; | |||
3774 | case DECL_TEMPLATE_TYPE_PARM: { | |||
3775 | bool HasTypeConstraint = Record.readInt(); | |||
3776 | D = TemplateTypeParmDecl::CreateDeserialized(Context, ID, | |||
3777 | HasTypeConstraint); | |||
3778 | break; | |||
3779 | } | |||
3780 | case DECL_NON_TYPE_TEMPLATE_PARM: { | |||
3781 | bool HasTypeConstraint = Record.readInt(); | |||
3782 | D = NonTypeTemplateParmDecl::CreateDeserialized(Context, ID, | |||
3783 | HasTypeConstraint); | |||
3784 | break; | |||
3785 | } | |||
3786 | case DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK: { | |||
3787 | bool HasTypeConstraint = Record.readInt(); | |||
3788 | D = NonTypeTemplateParmDecl::CreateDeserialized(Context, ID, | |||
3789 | Record.readInt(), | |||
3790 | HasTypeConstraint); | |||
3791 | break; | |||
3792 | } | |||
3793 | case DECL_TEMPLATE_TEMPLATE_PARM: | |||
3794 | D = TemplateTemplateParmDecl::CreateDeserialized(Context, ID); | |||
3795 | break; | |||
3796 | case DECL_EXPANDED_TEMPLATE_TEMPLATE_PARM_PACK: | |||
3797 | D = TemplateTemplateParmDecl::CreateDeserialized(Context, ID, | |||
3798 | Record.readInt()); | |||
3799 | break; | |||
3800 | case DECL_TYPE_ALIAS_TEMPLATE: | |||
3801 | D = TypeAliasTemplateDecl::CreateDeserialized(Context, ID); | |||
3802 | break; | |||
3803 | case DECL_CONCEPT: | |||
3804 | D = ConceptDecl::CreateDeserialized(Context, ID); | |||
3805 | break; | |||
3806 | case DECL_REQUIRES_EXPR_BODY: | |||
3807 | D = RequiresExprBodyDecl::CreateDeserialized(Context, ID); | |||
3808 | break; | |||
3809 | case DECL_STATIC_ASSERT: | |||
3810 | D = StaticAssertDecl::CreateDeserialized(Context, ID); | |||
3811 | break; | |||
3812 | case DECL_OBJC_METHOD: | |||
3813 | D = ObjCMethodDecl::CreateDeserialized(Context, ID); | |||
3814 | break; | |||
3815 | case DECL_OBJC_INTERFACE: | |||
3816 | D = ObjCInterfaceDecl::CreateDeserialized(Context, ID); | |||
3817 | break; | |||
3818 | case DECL_OBJC_IVAR: | |||
3819 | D = ObjCIvarDecl::CreateDeserialized(Context, ID); | |||
3820 | break; | |||
3821 | case DECL_OBJC_PROTOCOL: | |||
3822 | D = ObjCProtocolDecl::CreateDeserialized(Context, ID); | |||
3823 | break; | |||
3824 | case DECL_OBJC_AT_DEFS_FIELD: | |||
3825 | D = ObjCAtDefsFieldDecl::CreateDeserialized(Context, ID); | |||
3826 | break; | |||
3827 | case DECL_OBJC_CATEGORY: | |||
3828 | D = ObjCCategoryDecl::CreateDeserialized(Context, ID); | |||
3829 | break; | |||
3830 | case DECL_OBJC_CATEGORY_IMPL: | |||
3831 | D = ObjCCategoryImplDecl::CreateDeserialized(Context, ID); | |||
3832 | break; | |||
3833 | case DECL_OBJC_IMPLEMENTATION: | |||
3834 | D = ObjCImplementationDecl::CreateDeserialized(Context, ID); | |||
3835 | break; | |||
3836 | case DECL_OBJC_COMPATIBLE_ALIAS: | |||
3837 | D = ObjCCompatibleAliasDecl::CreateDeserialized(Context, ID); | |||
3838 | break; | |||
3839 | case DECL_OBJC_PROPERTY: | |||
3840 | D = ObjCPropertyDecl::CreateDeserialized(Context, ID); | |||
3841 | break; | |||
3842 | case DECL_OBJC_PROPERTY_IMPL: | |||
3843 | D = ObjCPropertyImplDecl::CreateDeserialized(Context, ID); | |||
3844 | break; | |||
3845 | case DECL_FIELD: | |||
3846 | D = FieldDecl::CreateDeserialized(Context, ID); | |||
3847 | break; | |||
3848 | case DECL_INDIRECTFIELD: | |||
3849 | D = IndirectFieldDecl::CreateDeserialized(Context, ID); | |||
3850 | break; | |||
3851 | case DECL_VAR: | |||
3852 | D = VarDecl::CreateDeserialized(Context, ID); | |||
3853 | break; | |||
3854 | case DECL_IMPLICIT_PARAM: | |||
3855 | D = ImplicitParamDecl::CreateDeserialized(Context, ID); | |||
3856 | break; | |||
3857 | case DECL_PARM_VAR: | |||
3858 | D = ParmVarDecl::CreateDeserialized(Context, ID); | |||
3859 | break; | |||
3860 | case DECL_DECOMPOSITION: | |||
3861 | D = DecompositionDecl::CreateDeserialized(Context, ID, Record.readInt()); | |||
3862 | break; | |||
3863 | case DECL_BINDING: | |||
3864 | D = BindingDecl::CreateDeserialized(Context, ID); | |||
3865 | break; | |||
3866 | case DECL_FILE_SCOPE_ASM: | |||
3867 | D = FileScopeAsmDecl::CreateDeserialized(Context, ID); | |||
3868 | break; | |||
3869 | case DECL_TOP_LEVEL_STMT_DECL: | |||
3870 | D = TopLevelStmtDecl::CreateDeserialized(Context, ID); | |||
3871 | break; | |||
3872 | case DECL_BLOCK: | |||
3873 | D = BlockDecl::CreateDeserialized(Context, ID); | |||
3874 | break; | |||
3875 | case DECL_MS_PROPERTY: | |||
3876 | D = MSPropertyDecl::CreateDeserialized(Context, ID); | |||
3877 | break; | |||
3878 | case DECL_MS_GUID: | |||
3879 | D = MSGuidDecl::CreateDeserialized(Context, ID); | |||
3880 | break; | |||
3881 | case DECL_UNNAMED_GLOBAL_CONSTANT: | |||
3882 | D = UnnamedGlobalConstantDecl::CreateDeserialized(Context, ID); | |||
3883 | break; | |||
3884 | case DECL_TEMPLATE_PARAM_OBJECT: | |||
3885 | D = TemplateParamObjectDecl::CreateDeserialized(Context, ID); | |||
3886 | break; | |||
3887 | case DECL_CAPTURED: | |||
3888 | D = CapturedDecl::CreateDeserialized(Context, ID, Record.readInt()); | |||
3889 | break; | |||
3890 | case DECL_CXX_BASE_SPECIFIERS: | |||
3891 | Error("attempt to read a C++ base-specifier record as a declaration"); | |||
3892 | return nullptr; | |||
3893 | case DECL_CXX_CTOR_INITIALIZERS: | |||
3894 | Error("attempt to read a C++ ctor initializer record as a declaration"); | |||
3895 | return nullptr; | |||
3896 | case DECL_IMPORT: | |||
3897 | // Note: last entry of the ImportDecl record is the number of stored source | |||
3898 | // locations. | |||
3899 | D = ImportDecl::CreateDeserialized(Context, ID, Record.back()); | |||
3900 | break; | |||
3901 | case DECL_OMP_THREADPRIVATE: { | |||
3902 | Record.skipInts(1); | |||
3903 | unsigned NumChildren = Record.readInt(); | |||
3904 | Record.skipInts(1); | |||
3905 | D = OMPThreadPrivateDecl::CreateDeserialized(Context, ID, NumChildren); | |||
3906 | break; | |||
3907 | } | |||
3908 | case DECL_OMP_ALLOCATE: { | |||
3909 | unsigned NumClauses = Record.readInt(); | |||
3910 | unsigned NumVars = Record.readInt(); | |||
3911 | Record.skipInts(1); | |||
3912 | D = OMPAllocateDecl::CreateDeserialized(Context, ID, NumVars, NumClauses); | |||
3913 | break; | |||
3914 | } | |||
3915 | case DECL_OMP_REQUIRES: { | |||
3916 | unsigned NumClauses = Record.readInt(); | |||
3917 | Record.skipInts(2); | |||
3918 | D = OMPRequiresDecl::CreateDeserialized(Context, ID, NumClauses); | |||
3919 | break; | |||
3920 | } | |||
3921 | case DECL_OMP_DECLARE_REDUCTION: | |||
3922 | D = OMPDeclareReductionDecl::CreateDeserialized(Context, ID); | |||
3923 | break; | |||
3924 | case DECL_OMP_DECLARE_MAPPER: { | |||
3925 | unsigned NumClauses = Record.readInt(); | |||
3926 | Record.skipInts(2); | |||
3927 | D = OMPDeclareMapperDecl::CreateDeserialized(Context, ID, NumClauses); | |||
3928 | break; | |||
3929 | } | |||
3930 | case DECL_OMP_CAPTUREDEXPR: | |||
3931 | D = OMPCapturedExprDecl::CreateDeserialized(Context, ID); | |||
3932 | break; | |||
3933 | case DECL_PRAGMA_COMMENT: | |||
3934 | D = PragmaCommentDecl::CreateDeserialized(Context, ID, Record.readInt()); | |||
3935 | break; | |||
3936 | case DECL_PRAGMA_DETECT_MISMATCH: | |||
3937 | D = PragmaDetectMismatchDecl::CreateDeserialized(Context, ID, | |||
3938 | Record.readInt()); | |||
3939 | break; | |||
3940 | case DECL_EMPTY: | |||
3941 | D = EmptyDecl::CreateDeserialized(Context, ID); | |||
3942 | break; | |||
3943 | case DECL_LIFETIME_EXTENDED_TEMPORARY: | |||
3944 | D = LifetimeExtendedTemporaryDecl::CreateDeserialized(Context, ID); | |||
3945 | break; | |||
3946 | case DECL_OBJC_TYPE_PARAM: | |||
3947 | D = ObjCTypeParamDecl::CreateDeserialized(Context, ID); | |||
3948 | break; | |||
3949 | case DECL_HLSL_BUFFER: | |||
3950 | D = HLSLBufferDecl::CreateDeserialized(Context, ID); | |||
3951 | break; | |||
3952 | case DECL_IMPLICIT_CONCEPT_SPECIALIZATION: | |||
3953 | D = ImplicitConceptSpecializationDecl::CreateDeserialized(Context, ID, | |||
3954 | Record.readInt()); | |||
3955 | break; | |||
3956 | } | |||
3957 | ||||
3958 | assert(D && "Unknown declaration reading AST file")(static_cast <bool> (D && "Unknown declaration reading AST file" ) ? void (0) : __assert_fail ("D && \"Unknown declaration reading AST file\"" , "clang/lib/Serialization/ASTReaderDecl.cpp", 3958, __extension__ __PRETTY_FUNCTION__)); | |||
3959 | LoadedDecl(Index, D); | |||
3960 | // Set the DeclContext before doing any deserialization, to make sure internal | |||
3961 | // calls to Decl::getASTContext() by Decl's methods will find the | |||
3962 | // TranslationUnitDecl without crashing. | |||
3963 | D->setDeclContext(Context.getTranslationUnitDecl()); | |||
3964 | Reader.Visit(D); | |||
3965 | ||||
3966 | // If this declaration is also a declaration context, get the | |||
3967 | // offsets for its tables of lexical and visible declarations. | |||
3968 | if (auto *DC = dyn_cast<DeclContext>(D)) { | |||
3969 | std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC); | |||
3970 | if (Offsets.first && | |||
3971 | ReadLexicalDeclContextStorage(*Loc.F, DeclsCursor, Offsets.first, DC)) | |||
3972 | return nullptr; | |||
3973 | if (Offsets.second && | |||
3974 | ReadVisibleDeclContextStorage(*Loc.F, DeclsCursor, Offsets.second, ID)) | |||
3975 | return nullptr; | |||
3976 | } | |||
3977 | assert(Record.getIdx() == Record.size())(static_cast <bool> (Record.getIdx() == Record.size()) ? void (0) : __assert_fail ("Record.getIdx() == Record.size()" , "clang/lib/Serialization/ASTReaderDecl.cpp", 3977, __extension__ __PRETTY_FUNCTION__)); | |||
3978 | ||||
3979 | // Load any relevant update records. | |||
3980 | PendingUpdateRecords.push_back( | |||
3981 | PendingUpdateRecord(ID, D, /*JustLoaded=*/true)); | |||
3982 | ||||
3983 | // Load the categories after recursive loading is finished. | |||
3984 | if (auto *Class = dyn_cast<ObjCInterfaceDecl>(D)) | |||
3985 | // If we already have a definition when deserializing the ObjCInterfaceDecl, | |||
3986 | // we put the Decl in PendingDefinitions so we can pull the categories here. | |||
3987 | if (Class->isThisDeclarationADefinition() || | |||
3988 | PendingDefinitions.count(Class)) | |||
3989 | loadObjCCategories(ID, Class); | |||
3990 | ||||
3991 | // If we have deserialized a declaration that has a definition the | |||
3992 | // AST consumer might need to know about, queue it. | |||
3993 | // We don't pass it to the consumer immediately because we may be in recursive | |||
3994 | // loading, and some declarations may still be initializing. | |||
3995 | PotentiallyInterestingDecls.push_back( | |||
3996 | InterestingDecl(D, Reader.hasPendingBody())); | |||
3997 | ||||
3998 | return D; | |||
3999 | } | |||
4000 | ||||
4001 | void ASTReader::PassInterestingDeclsToConsumer() { | |||
4002 | assert(Consumer)(static_cast <bool> (Consumer) ? void (0) : __assert_fail ("Consumer", "clang/lib/Serialization/ASTReaderDecl.cpp", 4002 , __extension__ __PRETTY_FUNCTION__)); | |||
4003 | ||||
4004 | if (PassingDeclsToConsumer) | |||
4005 | return; | |||
4006 | ||||
4007 | // Guard variable to avoid recursively redoing the process of passing | |||
4008 | // decls to consumer. | |||
4009 | SaveAndRestore GuardPassingDeclsToConsumer(PassingDeclsToConsumer, true); | |||
4010 | ||||
4011 | // Ensure that we've loaded all potentially-interesting declarations | |||
4012 | // that need to be eagerly loaded. | |||
4013 | for (auto ID : EagerlyDeserializedDecls) | |||
4014 | GetDecl(ID); | |||
4015 | EagerlyDeserializedDecls.clear(); | |||
4016 | ||||
4017 | while (!PotentiallyInterestingDecls.empty()) { | |||
4018 | InterestingDecl D = PotentiallyInterestingDecls.front(); | |||
4019 | PotentiallyInterestingDecls.pop_front(); | |||
4020 | if (isConsumerInterestedIn(getContext(), D.getDecl(), D.hasPendingBody())) | |||
4021 | PassInterestingDeclToConsumer(D.getDecl()); | |||
4022 | } | |||
4023 | } | |||
4024 | ||||
4025 | void ASTReader::loadDeclUpdateRecords(PendingUpdateRecord &Record) { | |||
4026 | // The declaration may have been modified by files later in the chain. | |||
4027 | // If this is the case, read the record containing the updates from each file | |||
4028 | // and pass it to ASTDeclReader to make the modifications. | |||
4029 | serialization::GlobalDeclID ID = Record.ID; | |||
4030 | Decl *D = Record.D; | |||
4031 | ProcessingUpdatesRAIIObj ProcessingUpdates(*this); | |||
4032 | DeclUpdateOffsetsMap::iterator UpdI = DeclUpdateOffsets.find(ID); | |||
4033 | ||||
4034 | SmallVector<serialization::DeclID, 8> PendingLazySpecializationIDs; | |||
4035 | ||||
4036 | if (UpdI != DeclUpdateOffsets.end()) { | |||
4037 | auto UpdateOffsets = std::move(UpdI->second); | |||
4038 | DeclUpdateOffsets.erase(UpdI); | |||
4039 | ||||
4040 | // Check if this decl was interesting to the consumer. If we just loaded | |||
4041 | // the declaration, then we know it was interesting and we skip the call | |||
4042 | // to isConsumerInterestedIn because it is unsafe to call in the | |||
4043 | // current ASTReader state. | |||
4044 | bool WasInteresting = | |||
4045 | Record.JustLoaded || isConsumerInterestedIn(getContext(), D, false); | |||
4046 | for (auto &FileAndOffset : UpdateOffsets) { | |||
4047 | ModuleFile *F = FileAndOffset.first; | |||
4048 | uint64_t Offset = FileAndOffset.second; | |||
4049 | llvm::BitstreamCursor &Cursor = F->DeclsCursor; | |||
4050 | SavedStreamPosition SavedPosition(Cursor); | |||
4051 | if (llvm::Error JumpFailed = Cursor.JumpToBit(Offset)) | |||
4052 | // FIXME don't do a fatal error. | |||
4053 | llvm::report_fatal_error( | |||
4054 | Twine("ASTReader::loadDeclUpdateRecords failed jumping: ") + | |||
4055 | toString(std::move(JumpFailed))); | |||
4056 | Expected<unsigned> MaybeCode = Cursor.ReadCode(); | |||
4057 | if (!MaybeCode) | |||
4058 | llvm::report_fatal_error( | |||
4059 | Twine("ASTReader::loadDeclUpdateRecords failed reading code: ") + | |||
4060 | toString(MaybeCode.takeError())); | |||
4061 | unsigned Code = MaybeCode.get(); | |||
4062 | ASTRecordReader Record(*this, *F); | |||
4063 | if (Expected<unsigned> MaybeRecCode = Record.readRecord(Cursor, Code)) | |||
4064 | assert(MaybeRecCode.get() == DECL_UPDATES &&(static_cast <bool> (MaybeRecCode.get() == DECL_UPDATES && "Expected DECL_UPDATES record!") ? void (0) : __assert_fail ("MaybeRecCode.get() == DECL_UPDATES && \"Expected DECL_UPDATES record!\"" , "clang/lib/Serialization/ASTReaderDecl.cpp", 4065, __extension__ __PRETTY_FUNCTION__)) | |||
4065 | "Expected DECL_UPDATES record!")(static_cast <bool> (MaybeRecCode.get() == DECL_UPDATES && "Expected DECL_UPDATES record!") ? void (0) : __assert_fail ("MaybeRecCode.get() == DECL_UPDATES && \"Expected DECL_UPDATES record!\"" , "clang/lib/Serialization/ASTReaderDecl.cpp", 4065, __extension__ __PRETTY_FUNCTION__)); | |||
4066 | else | |||
4067 | llvm::report_fatal_error( | |||
4068 | Twine("ASTReader::loadDeclUpdateRecords failed reading rec code: ") + | |||
4069 | toString(MaybeCode.takeError())); | |||
4070 | ||||
4071 | ASTDeclReader Reader(*this, Record, RecordLocation(F, Offset), ID, | |||
4072 | SourceLocation()); | |||
4073 | Reader.UpdateDecl(D, PendingLazySpecializationIDs); | |||
4074 | ||||
4075 | // We might have made this declaration interesting. If so, remember that | |||
4076 | // we need to hand it off to the consumer. | |||
4077 | if (!WasInteresting && | |||
4078 | isConsumerInterestedIn(getContext(), D, Reader.hasPendingBody())) { | |||
4079 | PotentiallyInterestingDecls.push_back( | |||
4080 | InterestingDecl(D, Reader.hasPendingBody())); | |||
4081 | WasInteresting = true; | |||
4082 | } | |||
4083 | } | |||
4084 | } | |||
4085 | // Add the lazy specializations to the template. | |||
4086 | assert((PendingLazySpecializationIDs.empty() || isa<ClassTemplateDecl>(D) ||(static_cast <bool> ((PendingLazySpecializationIDs.empty () || isa<ClassTemplateDecl>(D) || isa<FunctionTemplateDecl , VarTemplateDecl>(D)) && "Must not have pending specializations" ) ? void (0) : __assert_fail ("(PendingLazySpecializationIDs.empty() || isa<ClassTemplateDecl>(D) || isa<FunctionTemplateDecl, VarTemplateDecl>(D)) && \"Must not have pending specializations\"" , "clang/lib/Serialization/ASTReaderDecl.cpp", 4088, __extension__ __PRETTY_FUNCTION__)) | |||
4087 | isa<FunctionTemplateDecl, VarTemplateDecl>(D)) &&(static_cast <bool> ((PendingLazySpecializationIDs.empty () || isa<ClassTemplateDecl>(D) || isa<FunctionTemplateDecl , VarTemplateDecl>(D)) && "Must not have pending specializations" ) ? void (0) : __assert_fail ("(PendingLazySpecializationIDs.empty() || isa<ClassTemplateDecl>(D) || isa<FunctionTemplateDecl, VarTemplateDecl>(D)) && \"Must not have pending specializations\"" , "clang/lib/Serialization/ASTReaderDecl.cpp", 4088, __extension__ __PRETTY_FUNCTION__)) | |||
4088 | "Must not have pending specializations")(static_cast <bool> ((PendingLazySpecializationIDs.empty () || isa<ClassTemplateDecl>(D) || isa<FunctionTemplateDecl , VarTemplateDecl>(D)) && "Must not have pending specializations" ) ? void (0) : __assert_fail ("(PendingLazySpecializationIDs.empty() || isa<ClassTemplateDecl>(D) || isa<FunctionTemplateDecl, VarTemplateDecl>(D)) && \"Must not have pending specializations\"" , "clang/lib/Serialization/ASTReaderDecl.cpp", 4088, __extension__ __PRETTY_FUNCTION__)); | |||
4089 | if (auto *CTD = dyn_cast<ClassTemplateDecl>(D)) | |||
4090 | ASTDeclReader::AddLazySpecializations(CTD, PendingLazySpecializationIDs); | |||
4091 | else if (auto *FTD = dyn_cast<FunctionTemplateDecl>(D)) | |||
4092 | ASTDeclReader::AddLazySpecializations(FTD, PendingLazySpecializationIDs); | |||
4093 | else if (auto *VTD = dyn_cast<VarTemplateDecl>(D)) | |||
4094 | ASTDeclReader::AddLazySpecializations(VTD, PendingLazySpecializationIDs); | |||
4095 | PendingLazySpecializationIDs.clear(); | |||
4096 | ||||
4097 | // Load the pending visible updates for this decl context, if it has any. | |||
4098 | auto I = PendingVisibleUpdates.find(ID); | |||
4099 | if (I != PendingVisibleUpdates.end()) { | |||
4100 | auto VisibleUpdates = std::move(I->second); | |||
4101 | PendingVisibleUpdates.erase(I); | |||
4102 | ||||
4103 | auto *DC = cast<DeclContext>(D)->getPrimaryContext(); | |||
4104 | for (const auto &Update : VisibleUpdates) | |||
4105 | Lookups[DC].Table.add( | |||
4106 | Update.Mod, Update.Data, | |||
4107 | reader::ASTDeclContextNameLookupTrait(*this, *Update.Mod)); | |||
4108 | DC->setHasExternalVisibleStorage(true); | |||
4109 | } | |||
4110 | } | |||
4111 | ||||
4112 | void ASTReader::loadPendingDeclChain(Decl *FirstLocal, uint64_t LocalOffset) { | |||
4113 | // Attach FirstLocal to the end of the decl chain. | |||
4114 | Decl *CanonDecl = FirstLocal->getCanonicalDecl(); | |||
4115 | if (FirstLocal != CanonDecl) { | |||
4116 | Decl *PrevMostRecent = ASTDeclReader::getMostRecentDecl(CanonDecl); | |||
4117 | ASTDeclReader::attachPreviousDecl( | |||
4118 | *this, FirstLocal, PrevMostRecent ? PrevMostRecent : CanonDecl, | |||
4119 | CanonDecl); | |||
4120 | } | |||
4121 | ||||
4122 | if (!LocalOffset) { | |||
4123 | ASTDeclReader::attachLatestDecl(CanonDecl, FirstLocal); | |||
4124 | return; | |||
4125 | } | |||
4126 | ||||
4127 | // Load the list of other redeclarations from this module file. | |||
4128 | ModuleFile *M = getOwningModuleFile(FirstLocal); | |||
4129 | assert(M && "imported decl from no module file")(static_cast <bool> (M && "imported decl from no module file" ) ? void (0) : __assert_fail ("M && \"imported decl from no module file\"" , "clang/lib/Serialization/ASTReaderDecl.cpp", 4129, __extension__ __PRETTY_FUNCTION__)); | |||
4130 | ||||
4131 | llvm::BitstreamCursor &Cursor = M->DeclsCursor; | |||
4132 | SavedStreamPosition SavedPosition(Cursor); | |||
4133 | if (llvm::Error JumpFailed = Cursor.JumpToBit(LocalOffset)) | |||
4134 | llvm::report_fatal_error( | |||
4135 | Twine("ASTReader::loadPendingDeclChain failed jumping: ") + | |||
4136 | toString(std::move(JumpFailed))); | |||
4137 | ||||
4138 | RecordData Record; | |||
4139 | Expected<unsigned> MaybeCode = Cursor.ReadCode(); | |||
4140 | if (!MaybeCode) | |||
4141 | llvm::report_fatal_error( | |||
4142 | Twine("ASTReader::loadPendingDeclChain failed reading code: ") + | |||
4143 | toString(MaybeCode.takeError())); | |||
4144 | unsigned Code = MaybeCode.get(); | |||
4145 | if (Expected<unsigned> MaybeRecCode = Cursor.readRecord(Code, Record)) | |||
4146 | assert(MaybeRecCode.get() == LOCAL_REDECLARATIONS &&(static_cast <bool> (MaybeRecCode.get() == LOCAL_REDECLARATIONS && "expected LOCAL_REDECLARATIONS record!") ? void ( 0) : __assert_fail ("MaybeRecCode.get() == LOCAL_REDECLARATIONS && \"expected LOCAL_REDECLARATIONS record!\"" , "clang/lib/Serialization/ASTReaderDecl.cpp", 4147, __extension__ __PRETTY_FUNCTION__)) | |||
4147 | "expected LOCAL_REDECLARATIONS record!")(static_cast <bool> (MaybeRecCode.get() == LOCAL_REDECLARATIONS && "expected LOCAL_REDECLARATIONS record!") ? void ( 0) : __assert_fail ("MaybeRecCode.get() == LOCAL_REDECLARATIONS && \"expected LOCAL_REDECLARATIONS record!\"" , "clang/lib/Serialization/ASTReaderDecl.cpp", 4147, __extension__ __PRETTY_FUNCTION__)); | |||
4148 | else | |||
4149 | llvm::report_fatal_error( | |||
4150 | Twine("ASTReader::loadPendingDeclChain failed reading rec code: ") + | |||
4151 | toString(MaybeCode.takeError())); | |||
4152 | ||||
4153 | // FIXME: We have several different dispatches on decl kind here; maybe | |||
4154 | // we should instead generate one loop per kind and dispatch up-front? | |||
4155 | Decl *MostRecent = FirstLocal; | |||
4156 | for (unsigned I = 0, N = Record.size(); I != N; ++I) { | |||
4157 | auto *D = GetLocalDecl(*M, Record[N - I - 1]); | |||
4158 | ASTDeclReader::attachPreviousDecl(*this, D, MostRecent, CanonDecl); | |||
4159 | MostRecent = D; | |||
4160 | } | |||
4161 | ASTDeclReader::attachLatestDecl(CanonDecl, MostRecent); | |||
4162 | } | |||
4163 | ||||
4164 | namespace { | |||
4165 | ||||
4166 | /// Given an ObjC interface, goes through the modules and links to the | |||
4167 | /// interface all the categories for it. | |||
4168 | class ObjCCategoriesVisitor { | |||
4169 | ASTReader &Reader; | |||
4170 | ObjCInterfaceDecl *Interface; | |||
4171 | llvm::SmallPtrSetImpl<ObjCCategoryDecl *> &Deserialized; | |||
4172 | ObjCCategoryDecl *Tail = nullptr; | |||
4173 | llvm::DenseMap<DeclarationName, ObjCCategoryDecl *> NameCategoryMap; | |||
4174 | serialization::GlobalDeclID InterfaceID; | |||
4175 | unsigned PreviousGeneration; | |||
4176 | ||||
4177 | void add(ObjCCategoryDecl *Cat) { | |||
4178 | // Only process each category once. | |||
4179 | if (!Deserialized.erase(Cat)) | |||
4180 | return; | |||
4181 | ||||
4182 | // Check for duplicate categories. | |||
4183 | if (Cat->getDeclName()) { | |||
4184 | ObjCCategoryDecl *&Existing = NameCategoryMap[Cat->getDeclName()]; | |||
4185 | if (Existing && Reader.getOwningModuleFile(Existing) != | |||
4186 | Reader.getOwningModuleFile(Cat)) { | |||
4187 | llvm::DenseSet<std::pair<Decl *, Decl *>> NonEquivalentDecls; | |||
4188 | StructuralEquivalenceContext Ctx( | |||
4189 | Cat->getASTContext(), Existing->getASTContext(), | |||
4190 | NonEquivalentDecls, StructuralEquivalenceKind::Default, | |||
4191 | /*StrictTypeSpelling =*/false, | |||
4192 | /*Complain =*/false, | |||
4193 | /*ErrorOnTagTypeMismatch =*/true); | |||
4194 | if (!Ctx.IsEquivalent(Cat, Existing)) { | |||
4195 | // Warn only if the categories with the same name are different. | |||
4196 | Reader.Diag(Cat->getLocation(), diag::warn_dup_category_def) | |||
4197 | << Interface->getDeclName() << Cat->getDeclName(); | |||
4198 | Reader.Diag(Existing->getLocation(), | |||
4199 | diag::note_previous_definition); | |||
4200 | } | |||
4201 | } else if (!Existing) { | |||
4202 | // Record this category. | |||
4203 | Existing = Cat; | |||
4204 | } | |||
4205 | } | |||
4206 | ||||
4207 | // Add this category to the end of the chain. | |||
4208 | if (Tail) | |||
4209 | ASTDeclReader::setNextObjCCategory(Tail, Cat); | |||
4210 | else | |||
4211 | Interface->setCategoryListRaw(Cat); | |||
4212 | Tail = Cat; | |||
4213 | } | |||
4214 | ||||
4215 | public: | |||
4216 | ObjCCategoriesVisitor(ASTReader &Reader, | |||
4217 | ObjCInterfaceDecl *Interface, | |||
4218 | llvm::SmallPtrSetImpl<ObjCCategoryDecl *> &Deserialized, | |||
4219 | serialization::GlobalDeclID InterfaceID, | |||
4220 | unsigned PreviousGeneration) | |||
4221 | : Reader(Reader), Interface(Interface), Deserialized(Deserialized), | |||
4222 | InterfaceID(InterfaceID), PreviousGeneration(PreviousGeneration) { | |||
4223 | // Populate the name -> category map with the set of known categories. | |||
4224 | for (auto *Cat : Interface->known_categories()) { | |||
4225 | if (Cat->getDeclName()) | |||
4226 | NameCategoryMap[Cat->getDeclName()] = Cat; | |||
4227 | ||||
4228 | // Keep track of the tail of the category list. | |||
4229 | Tail = Cat; | |||
4230 | } | |||
4231 | } | |||
4232 | ||||
4233 | bool operator()(ModuleFile &M) { | |||
4234 | // If we've loaded all of the category information we care about from | |||
4235 | // this module file, we're done. | |||
4236 | if (M.Generation <= PreviousGeneration) | |||
4237 | return true; | |||
4238 | ||||
4239 | // Map global ID of the definition down to the local ID used in this | |||
4240 | // module file. If there is no such mapping, we'll find nothing here | |||
4241 | // (or in any module it imports). | |||
4242 | DeclID LocalID = Reader.mapGlobalIDToModuleFileGlobalID(M, InterfaceID); | |||
4243 | if (!LocalID) | |||
4244 | return true; | |||
4245 | ||||
4246 | // Perform a binary search to find the local redeclarations for this | |||
4247 | // declaration (if any). | |||
4248 | const ObjCCategoriesInfo Compare = { LocalID, 0 }; | |||
4249 | const ObjCCategoriesInfo *Result | |||
4250 | = std::lower_bound(M.ObjCCategoriesMap, | |||
4251 | M.ObjCCategoriesMap + M.LocalNumObjCCategoriesInMap, | |||
4252 | Compare); | |||
4253 | if (Result == M.ObjCCategoriesMap + M.LocalNumObjCCategoriesInMap || | |||
4254 | Result->DefinitionID != LocalID) { | |||
4255 | // We didn't find anything. If the class definition is in this module | |||
4256 | // file, then the module files it depends on cannot have any categories, | |||
4257 | // so suppress further lookup. | |||
4258 | return Reader.isDeclIDFromModule(InterfaceID, M); | |||
4259 | } | |||
4260 | ||||
4261 | // We found something. Dig out all of the categories. | |||
4262 | unsigned Offset = Result->Offset; | |||
4263 | unsigned N = M.ObjCCategories[Offset]; | |||
4264 | M.ObjCCategories[Offset++] = 0; // Don't try to deserialize again | |||
4265 | for (unsigned I = 0; I != N; ++I) | |||
4266 | add(cast_or_null<ObjCCategoryDecl>( | |||
4267 | Reader.GetLocalDecl(M, M.ObjCCategories[Offset++]))); | |||
4268 | return true; | |||
4269 | } | |||
4270 | }; | |||
4271 | ||||
4272 | } // namespace | |||
4273 | ||||
4274 | void ASTReader::loadObjCCategories(serialization::GlobalDeclID ID, | |||
4275 | ObjCInterfaceDecl *D, | |||
4276 | unsigned PreviousGeneration) { | |||
4277 | ObjCCategoriesVisitor Visitor(*this, D, CategoriesDeserialized, ID, | |||
4278 | PreviousGeneration); | |||
4279 | ModuleMgr.visit(Visitor); | |||
4280 | } | |||
4281 | ||||
4282 | template<typename DeclT, typename Fn> | |||
4283 | static void forAllLaterRedecls(DeclT *D, Fn F) { | |||
4284 | F(D); | |||
4285 | ||||
4286 | // Check whether we've already merged D into its redeclaration chain. | |||
4287 | // MostRecent may or may not be nullptr if D has not been merged. If | |||
4288 | // not, walk the merged redecl chain and see if it's there. | |||
4289 | auto *MostRecent = D->getMostRecentDecl(); | |||
4290 | bool Found = false; | |||
4291 | for (auto *Redecl = MostRecent; Redecl && !Found; | |||
4292 | Redecl = Redecl->getPreviousDecl()) | |||
4293 | Found = (Redecl == D); | |||
4294 | ||||
4295 | // If this declaration is merged, apply the functor to all later decls. | |||
4296 | if (Found) { | |||
4297 | for (auto *Redecl = MostRecent; Redecl != D; | |||
4298 | Redecl = Redecl->getPreviousDecl()) | |||
4299 | F(Redecl); | |||
4300 | } | |||
4301 | } | |||
4302 | ||||
4303 | void ASTDeclReader::UpdateDecl(Decl *D, | |||
4304 | llvm::SmallVectorImpl<serialization::DeclID> &PendingLazySpecializationIDs) { | |||
4305 | while (Record.getIdx() < Record.size()) { | |||
4306 | switch ((DeclUpdateKind)Record.readInt()) { | |||
4307 | case UPD_CXX_ADDED_IMPLICIT_MEMBER: { | |||
4308 | auto *RD = cast<CXXRecordDecl>(D); | |||
4309 | // FIXME: If we also have an update record for instantiating the | |||
4310 | // definition of D, we need that to happen before we get here. | |||
4311 | Decl *MD = Record.readDecl(); | |||
4312 | assert(MD && "couldn't read decl from update record")(static_cast <bool> (MD && "couldn't read decl from update record" ) ? void (0) : __assert_fail ("MD && \"couldn't read decl from update record\"" , "clang/lib/Serialization/ASTReaderDecl.cpp", 4312, __extension__ __PRETTY_FUNCTION__)); | |||
4313 | // FIXME: We should call addHiddenDecl instead, to add the member | |||
4314 | // to its DeclContext. | |||
4315 | RD->addedMember(MD); | |||
4316 | break; | |||
4317 | } | |||
4318 | ||||
4319 | case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION: | |||
4320 | // It will be added to the template's lazy specialization set. | |||
4321 | PendingLazySpecializationIDs.push_back(readDeclID()); | |||
4322 | break; | |||
4323 | ||||
4324 | case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: { | |||
4325 | auto *Anon = readDeclAs<NamespaceDecl>(); | |||
4326 | ||||
4327 | // Each module has its own anonymous namespace, which is disjoint from | |||
4328 | // any other module's anonymous namespaces, so don't attach the anonymous | |||
4329 | // namespace at all. | |||
4330 | if (!Record.isModule()) { | |||
4331 | if (auto *TU = dyn_cast<TranslationUnitDecl>(D)) | |||
4332 | TU->setAnonymousNamespace(Anon); | |||
4333 | else | |||
4334 | cast<NamespaceDecl>(D)->setAnonymousNamespace(Anon); | |||
4335 | } | |||
4336 | break; | |||
4337 | } | |||
4338 | ||||
4339 | case UPD_CXX_ADDED_VAR_DEFINITION: { | |||
4340 | auto *VD = cast<VarDecl>(D); | |||
4341 | VD->NonParmVarDeclBits.IsInline = Record.readInt(); | |||
4342 | VD->NonParmVarDeclBits.IsInlineSpecified = Record.readInt(); | |||
4343 | uint64_t Val = Record.readInt(); | |||
4344 | if (Val && !VD->getInit()) { | |||
4345 | VD->setInit(Record.readExpr()); | |||
4346 | if (Val != 1) { | |||
4347 | EvaluatedStmt *Eval = VD->ensureEvaluatedStmt(); | |||
4348 | Eval->HasConstantInitialization = (Val & 2) != 0; | |||
4349 | Eval->HasConstantDestruction = (Val & 4) != 0; | |||
4350 | } | |||
4351 | } | |||
4352 | break; | |||
4353 | } | |||
4354 | ||||
4355 | case UPD_CXX_POINT_OF_INSTANTIATION: { | |||
4356 | SourceLocation POI = Record.readSourceLocation(); | |||
4357 | if (auto *VTSD = dyn_cast<VarTemplateSpecializationDecl>(D)) { | |||
4358 | VTSD->setPointOfInstantiation(POI); | |||
4359 | } else if (auto *VD = dyn_cast<VarDecl>(D)) { | |||
4360 | VD->getMemberSpecializationInfo()->setPointOfInstantiation(POI); | |||
4361 | } else { | |||
4362 | auto *FD = cast<FunctionDecl>(D); | |||
4363 | if (auto *FTSInfo = FD->TemplateOrSpecialization | |||
4364 | .dyn_cast<FunctionTemplateSpecializationInfo *>()) | |||
4365 | FTSInfo->setPointOfInstantiation(POI); | |||
4366 | else | |||
4367 | FD->TemplateOrSpecialization.get<MemberSpecializationInfo *>() | |||
4368 | ->setPointOfInstantiation(POI); | |||
4369 | } | |||
4370 | break; | |||
4371 | } | |||
4372 | ||||
4373 | case UPD_CXX_INSTANTIATED_DEFAULT_ARGUMENT: { | |||
4374 | auto *Param = cast<ParmVarDecl>(D); | |||
4375 | ||||
4376 | // We have to read the default argument regardless of whether we use it | |||
4377 | // so that hypothetical further update records aren't messed up. | |||
4378 | // TODO: Add a function to skip over the next expr record. | |||
4379 | auto *DefaultArg = Record.readExpr(); | |||
4380 | ||||
4381 | // Only apply the update if the parameter still has an uninstantiated | |||
4382 | // default argument. | |||
4383 | if (Param->hasUninstantiatedDefaultArg()) | |||
4384 | Param->setDefaultArg(DefaultArg); | |||
4385 | break; | |||
4386 | } | |||
4387 | ||||
4388 | case UPD_CXX_INSTANTIATED_DEFAULT_MEMBER_INITIALIZER: { | |||
4389 | auto *FD = cast<FieldDecl>(D); | |||
4390 | auto *DefaultInit = Record.readExpr(); | |||
4391 | ||||
4392 | // Only apply the update if the field still has an uninstantiated | |||
4393 | // default member initializer. | |||
4394 | if (FD->hasInClassInitializer() && !FD->getInClassInitializer()) { | |||
4395 | if (DefaultInit) | |||
4396 | FD->setInClassInitializer(DefaultInit); | |||
4397 | else | |||
4398 | // Instantiation failed. We can get here if we serialized an AST for | |||
4399 | // an invalid program. | |||
4400 | FD->removeInClassInitializer(); | |||
4401 | } | |||
4402 | break; | |||
4403 | } | |||
4404 | ||||
4405 | case UPD_CXX_ADDED_FUNCTION_DEFINITION: { | |||
4406 | auto *FD = cast<FunctionDecl>(D); | |||
4407 | if (Reader.PendingBodies[FD]) { | |||
4408 | // FIXME: Maybe check for ODR violations. | |||
4409 | // It's safe to stop now because this update record is always last. | |||
4410 | return; | |||
4411 | } | |||
4412 | ||||
4413 | if (Record.readInt()) { | |||
4414 | // Maintain AST consistency: any later redeclarations of this function | |||
4415 | // are inline if this one is. (We might have merged another declaration | |||
4416 | // into this one.) | |||
4417 | forAllLaterRedecls(FD, [](FunctionDecl *FD) { | |||
4418 | FD->setImplicitlyInline(); | |||
4419 | }); | |||
4420 | } | |||
4421 | FD->setInnerLocStart(readSourceLocation()); | |||
4422 | ReadFunctionDefinition(FD); | |||
4423 | assert(Record.getIdx() == Record.size() && "lazy body must be last")(static_cast <bool> (Record.getIdx() == Record.size() && "lazy body must be last") ? void (0) : __assert_fail ("Record.getIdx() == Record.size() && \"lazy body must be last\"" , "clang/lib/Serialization/ASTReaderDecl.cpp", 4423, __extension__ __PRETTY_FUNCTION__)); | |||
4424 | break; | |||
4425 | } | |||
4426 | ||||
4427 | case UPD_CXX_INSTANTIATED_CLASS_DEFINITION: { | |||
4428 | auto *RD = cast<CXXRecordDecl>(D); | |||
4429 | auto *OldDD = RD->getCanonicalDecl()->DefinitionData; | |||
4430 | bool HadRealDefinition = | |||
4431 | OldDD && (OldDD->Definition != RD || | |||
4432 | !Reader.PendingFakeDefinitionData.count(OldDD)); | |||
4433 | RD->setParamDestroyedInCallee(Record.readInt()); | |||
4434 | RD->setArgPassingRestrictions( | |||
4435 | (RecordDecl::ArgPassingKind)Record.readInt()); | |||
4436 | ReadCXXRecordDefinition(RD, /*Update*/true); | |||
4437 | ||||
4438 | // Visible update is handled separately. | |||
4439 | uint64_t LexicalOffset = ReadLocalOffset(); | |||
4440 | if (!HadRealDefinition && LexicalOffset) { | |||
4441 | Record.readLexicalDeclContextStorage(LexicalOffset, RD); | |||
4442 | Reader.PendingFakeDefinitionData.erase(OldDD); | |||
4443 | } | |||
4444 | ||||
4445 | auto TSK = (TemplateSpecializationKind)Record.readInt(); | |||
4446 | SourceLocation POI = readSourceLocation(); | |||
4447 | if (MemberSpecializationInfo *MSInfo = | |||
4448 | RD->getMemberSpecializationInfo()) { | |||
4449 | MSInfo->setTemplateSpecializationKind(TSK); | |||
4450 | MSInfo->setPointOfInstantiation(POI); | |||
4451 | } else { | |||
4452 | auto *Spec = cast<ClassTemplateSpecializationDecl>(RD); | |||
4453 | Spec->setTemplateSpecializationKind(TSK); | |||
4454 | Spec->setPointOfInstantiation(POI); | |||
4455 | ||||
4456 | if (Record.readInt()) { | |||
4457 | auto *PartialSpec = | |||
4458 | readDeclAs<ClassTemplatePartialSpecializationDecl>(); | |||
4459 | SmallVector<TemplateArgument, 8> TemplArgs; | |||
4460 | Record.readTemplateArgumentList(TemplArgs); | |||
4461 | auto *TemplArgList = TemplateArgumentList::CreateCopy( | |||
4462 | Reader.getContext(), TemplArgs); | |||
4463 | ||||
4464 | // FIXME: If we already have a partial specialization set, | |||
4465 | // check that it matches. | |||
4466 | if (!Spec->getSpecializedTemplateOrPartial() | |||
4467 | .is<ClassTemplatePartialSpecializationDecl *>()) | |||
4468 | Spec->setInstantiationOf(PartialSpec, TemplArgList); | |||
4469 | } | |||
4470 | } | |||
4471 | ||||
4472 | RD->setTagKind((TagTypeKind)Record.readInt()); | |||
4473 | RD->setLocation(readSourceLocation()); | |||
4474 | RD->setLocStart(readSourceLocation()); | |||
4475 | RD->setBraceRange(readSourceRange()); | |||
4476 | ||||
4477 | if (Record.readInt()) { | |||
4478 | AttrVec Attrs; | |||
4479 | Record.readAttributes(Attrs); | |||
4480 | // If the declaration already has attributes, we assume that some other | |||
4481 | // AST file already loaded them. | |||
4482 | if (!D->hasAttrs()) | |||
4483 | D->setAttrsImpl(Attrs, Reader.getContext()); | |||
4484 | } | |||
4485 | break; | |||
4486 | } | |||
4487 | ||||
4488 | case UPD_CXX_RESOLVED_DTOR_DELETE: { | |||
4489 | // Set the 'operator delete' directly to avoid emitting another update | |||
4490 | // record. | |||
4491 | auto *Del = readDeclAs<FunctionDecl>(); | |||
4492 | auto *First = cast<CXXDestructorDecl>(D->getCanonicalDecl()); | |||
4493 | auto *ThisArg = Record.readExpr(); | |||
4494 | // FIXME: Check consistency if we have an old and new operator delete. | |||
4495 | if (!First->OperatorDelete) { | |||
4496 | First->OperatorDelete = Del; | |||
4497 | First->OperatorDeleteThisArg = ThisArg; | |||
4498 | } | |||
4499 | break; | |||
4500 | } | |||
4501 | ||||
4502 | case UPD_CXX_RESOLVED_EXCEPTION_SPEC: { | |||
4503 | SmallVector<QualType, 8> ExceptionStorage; | |||
4504 | auto ESI = Record.readExceptionSpecInfo(ExceptionStorage); | |||
4505 | ||||
4506 | // Update this declaration's exception specification, if needed. | |||
4507 | auto *FD = cast<FunctionDecl>(D); | |||
4508 | auto *FPT = FD->getType()->castAs<FunctionProtoType>(); | |||
4509 | // FIXME: If the exception specification is already present, check that it | |||
4510 | // matches. | |||
4511 | if (isUnresolvedExceptionSpec(FPT->getExceptionSpecType())) { | |||
4512 | FD->setType(Reader.getContext().getFunctionType( | |||
4513 | FPT->getReturnType(), FPT->getParamTypes(), | |||
4514 | FPT->getExtProtoInfo().withExceptionSpec(ESI))); | |||
4515 | ||||
4516 | // When we get to the end of deserializing, see if there are other decls | |||
4517 | // that we need to propagate this exception specification onto. | |||
4518 | Reader.PendingExceptionSpecUpdates.insert( | |||
4519 | std::make_pair(FD->getCanonicalDecl(), FD)); | |||
4520 | } | |||
4521 | break; | |||
4522 | } | |||
4523 | ||||
4524 | case UPD_CXX_DEDUCED_RETURN_TYPE: { | |||
4525 | auto *FD = cast<FunctionDecl>(D); | |||
4526 | QualType DeducedResultType = Record.readType(); | |||
4527 | Reader.PendingDeducedTypeUpdates.insert( | |||
4528 | {FD->getCanonicalDecl(), DeducedResultType}); | |||
4529 | break; | |||
4530 | } | |||
4531 | ||||
4532 | case UPD_DECL_MARKED_USED: | |||
4533 | // Maintain AST consistency: any later redeclarations are used too. | |||
4534 | D->markUsed(Reader.getContext()); | |||
4535 | break; | |||
4536 | ||||
4537 | case UPD_MANGLING_NUMBER: | |||
4538 | Reader.getContext().setManglingNumber(cast<NamedDecl>(D), | |||
4539 | Record.readInt()); | |||
4540 | break; | |||
4541 | ||||
4542 | case UPD_STATIC_LOCAL_NUMBER: | |||
4543 | Reader.getContext().setStaticLocalNumber(cast<VarDecl>(D), | |||
4544 | Record.readInt()); | |||
4545 | break; | |||
4546 | ||||
4547 | case UPD_DECL_MARKED_OPENMP_THREADPRIVATE: | |||
4548 | D->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit( | |||
4549 | Reader.getContext(), readSourceRange(), | |||
4550 | AttributeCommonInfo::AS_Pragma)); | |||
4551 | break; | |||
4552 | ||||
4553 | case UPD_DECL_MARKED_OPENMP_ALLOCATE: { | |||
4554 | auto AllocatorKind = | |||
4555 | static_cast<OMPAllocateDeclAttr::AllocatorTypeTy>(Record.readInt()); | |||
4556 | Expr *Allocator = Record.readExpr(); | |||
4557 | Expr *Alignment = Record.readExpr(); | |||
4558 | SourceRange SR = readSourceRange(); | |||
4559 | D->addAttr(OMPAllocateDeclAttr::CreateImplicit( | |||
4560 | Reader.getContext(), AllocatorKind, Allocator, Alignment, SR, | |||
4561 | AttributeCommonInfo::AS_Pragma)); | |||
4562 | break; | |||
4563 | } | |||
4564 | ||||
4565 | case UPD_DECL_EXPORTED: { | |||
4566 | unsigned SubmoduleID = readSubmoduleID(); | |||
4567 | auto *Exported = cast<NamedDecl>(D); | |||
4568 | Module *Owner = SubmoduleID ? Reader.getSubmodule(SubmoduleID) : nullptr; | |||
4569 | Reader.getContext().mergeDefinitionIntoModule(Exported, Owner); | |||
4570 | Reader.PendingMergedDefinitionsToDeduplicate.insert(Exported); | |||
4571 | break; | |||
4572 | } | |||
4573 | ||||
4574 | case UPD_DECL_MARKED_OPENMP_DECLARETARGET: { | |||
4575 | auto MapType = Record.readEnum<OMPDeclareTargetDeclAttr::MapTypeTy>(); | |||
4576 | auto DevType = Record.readEnum<OMPDeclareTargetDeclAttr::DevTypeTy>(); | |||
4577 | Expr *IndirectE = Record.readExpr(); | |||
4578 | bool Indirect = Record.readBool(); | |||
4579 | unsigned Level = Record.readInt(); | |||
4580 | D->addAttr(OMPDeclareTargetDeclAttr::CreateImplicit( | |||
4581 | Reader.getContext(), MapType, DevType, IndirectE, Indirect, Level, | |||
4582 | readSourceRange(), AttributeCommonInfo::AS_Pragma)); | |||
4583 | break; | |||
4584 | } | |||
4585 | ||||
4586 | case UPD_ADDED_ATTR_TO_RECORD: | |||
4587 | AttrVec Attrs; | |||
4588 | Record.readAttributes(Attrs); | |||
4589 | assert(Attrs.size() == 1)(static_cast <bool> (Attrs.size() == 1) ? void (0) : __assert_fail ("Attrs.size() == 1", "clang/lib/Serialization/ASTReaderDecl.cpp" , 4589, __extension__ __PRETTY_FUNCTION__)); | |||
4590 | D->addAttr(Attrs[0]); | |||
4591 | break; | |||
4592 | } | |||
4593 | } | |||
4594 | } |