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