Bug Summary

File:tools/clang/lib/Serialization/ASTReaderDecl.cpp
Warning:line 5396, column 5
Called C++ object pointer is null

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -disable-llvm-verifier -discard-value-names -main-file-name ASTReaderDecl.cpp -analyzer-store=region -analyzer-opt-analyze-nested-blocks -analyzer-eagerly-assume -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -mrelocation-model pic -pic-level 2 -mthread-model posix -relaxed-aliasing -fmath-errno -masm-verbose -mconstructor-aliases -munwind-tables -fuse-init-array -target-cpu x86-64 -dwarf-column-info -debugger-tuning=gdb -momit-leaf-frame-pointer -ffunction-sections -fdata-sections -resource-dir /usr/lib/llvm-7/lib/clang/7.0.0 -D _DEBUG -D _GNU_SOURCE -D __STDC_CONSTANT_MACROS -D __STDC_FORMAT_MACROS -D __STDC_LIMIT_MACROS -I /build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/lib/Serialization -I /build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Serialization -I /build/llvm-toolchain-snapshot-7~svn329677/tools/clang/include -I /build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include -I /build/llvm-toolchain-snapshot-7~svn329677/build-llvm/include -I /build/llvm-toolchain-snapshot-7~svn329677/include -U NDEBUG -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/x86_64-linux-gnu/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/x86_64-linux-gnu/c++/7.3.0 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/7.3.0/../../../../include/c++/7.3.0/backward -internal-isystem /usr/include/clang/7.0.0/include/ -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-7/lib/clang/7.0.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -Wno-unused-parameter -Wwrite-strings -Wno-missing-field-initializers -Wno-long-long -Wno-maybe-uninitialized -Wno-comment -std=c++11 -fdeprecated-macro -fdebug-compilation-dir /build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/lib/Serialization -ferror-limit 19 -fmessage-length 0 -fvisibility-inlines-hidden -fobjc-runtime=gcc -fno-common -fdiagnostics-show-option -vectorize-loops -vectorize-slp -analyzer-checker optin.performance.Padding -analyzer-output=html -analyzer-config stable-report-filename=true -o /tmp/scan-build-2018-04-11-031539-24776-1 -x c++ /build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Serialization/ASTReaderDecl.cpp

/build/llvm-toolchain-snapshot-7~svn329677/tools/clang/lib/Serialization/ASTReaderDecl.cpp

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

/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc

1/*===- TableGen'erated file -------------------------------------*- C++ -*-===*\
2|* *|
3|* Attribute classes' definitions *|
4|* *|
5|* Automatically generated file, do not edit! *|
6|* *|
7\*===----------------------------------------------------------------------===*/
8
9#ifndef LLVM_CLANG_ATTR_CLASSES_INC
10#define LLVM_CLANG_ATTR_CLASSES_INC
11
12class AMDGPUFlatWorkGroupSizeAttr : public InheritableAttr {
13unsigned min;
14
15unsigned max;
16
17public:
18 static AMDGPUFlatWorkGroupSizeAttr *CreateImplicit(ASTContext &Ctx, unsigned Min, unsigned Max, SourceRange Loc = SourceRange()) {
19 auto *A = new (Ctx) AMDGPUFlatWorkGroupSizeAttr(Loc, Ctx, Min, Max, 0);
20 A->setImplicit(true);
21 return A;
22 }
23
24 AMDGPUFlatWorkGroupSizeAttr(SourceRange R, ASTContext &Ctx
25 , unsigned Min
26 , unsigned Max
27 , unsigned SI
28 )
29 : InheritableAttr(attr::AMDGPUFlatWorkGroupSize, R, SI, false, false)
30 , min(Min)
31 , max(Max)
32 {
33 }
34
35 AMDGPUFlatWorkGroupSizeAttr *clone(ASTContext &C) const;
36 void printPretty(raw_ostream &OS,
37 const PrintingPolicy &Policy) const;
38 const char *getSpelling() const;
39 unsigned getMin() const {
40 return min;
41 }
42
43 unsigned getMax() const {
44 return max;
45 }
46
47
48
49 static bool classof(const Attr *A) { return A->getKind() == attr::AMDGPUFlatWorkGroupSize; }
50};
51
52class AMDGPUNumSGPRAttr : public InheritableAttr {
53unsigned numSGPR;
54
55public:
56 static AMDGPUNumSGPRAttr *CreateImplicit(ASTContext &Ctx, unsigned NumSGPR, SourceRange Loc = SourceRange()) {
57 auto *A = new (Ctx) AMDGPUNumSGPRAttr(Loc, Ctx, NumSGPR, 0);
58 A->setImplicit(true);
59 return A;
60 }
61
62 AMDGPUNumSGPRAttr(SourceRange R, ASTContext &Ctx
63 , unsigned NumSGPR
64 , unsigned SI
65 )
66 : InheritableAttr(attr::AMDGPUNumSGPR, R, SI, false, false)
67 , numSGPR(NumSGPR)
68 {
69 }
70
71 AMDGPUNumSGPRAttr *clone(ASTContext &C) const;
72 void printPretty(raw_ostream &OS,
73 const PrintingPolicy &Policy) const;
74 const char *getSpelling() const;
75 unsigned getNumSGPR() const {
76 return numSGPR;
77 }
78
79
80
81 static bool classof(const Attr *A) { return A->getKind() == attr::AMDGPUNumSGPR; }
82};
83
84class AMDGPUNumVGPRAttr : public InheritableAttr {
85unsigned numVGPR;
86
87public:
88 static AMDGPUNumVGPRAttr *CreateImplicit(ASTContext &Ctx, unsigned NumVGPR, SourceRange Loc = SourceRange()) {
89 auto *A = new (Ctx) AMDGPUNumVGPRAttr(Loc, Ctx, NumVGPR, 0);
90 A->setImplicit(true);
91 return A;
92 }
93
94 AMDGPUNumVGPRAttr(SourceRange R, ASTContext &Ctx
95 , unsigned NumVGPR
96 , unsigned SI
97 )
98 : InheritableAttr(attr::AMDGPUNumVGPR, R, SI, false, false)
99 , numVGPR(NumVGPR)
100 {
101 }
102
103 AMDGPUNumVGPRAttr *clone(ASTContext &C) const;
104 void printPretty(raw_ostream &OS,
105 const PrintingPolicy &Policy) const;
106 const char *getSpelling() const;
107 unsigned getNumVGPR() const {
108 return numVGPR;
109 }
110
111
112
113 static bool classof(const Attr *A) { return A->getKind() == attr::AMDGPUNumVGPR; }
114};
115
116class AMDGPUWavesPerEUAttr : public InheritableAttr {
117unsigned min;
118
119unsigned max;
120
121public:
122 static AMDGPUWavesPerEUAttr *CreateImplicit(ASTContext &Ctx, unsigned Min, unsigned Max, SourceRange Loc = SourceRange()) {
123 auto *A = new (Ctx) AMDGPUWavesPerEUAttr(Loc, Ctx, Min, Max, 0);
124 A->setImplicit(true);
125 return A;
126 }
127
128 AMDGPUWavesPerEUAttr(SourceRange R, ASTContext &Ctx
129 , unsigned Min
130 , unsigned Max
131 , unsigned SI
132 )
133 : InheritableAttr(attr::AMDGPUWavesPerEU, R, SI, false, false)
134 , min(Min)
135 , max(Max)
136 {
137 }
138
139 AMDGPUWavesPerEUAttr(SourceRange R, ASTContext &Ctx
140 , unsigned Min
141 , unsigned SI
142 )
143 : InheritableAttr(attr::AMDGPUWavesPerEU, R, SI, false, false)
144 , min(Min)
145 , max()
146 {
147 }
148
149 AMDGPUWavesPerEUAttr *clone(ASTContext &C) const;
150 void printPretty(raw_ostream &OS,
151 const PrintingPolicy &Policy) const;
152 const char *getSpelling() const;
153 unsigned getMin() const {
154 return min;
155 }
156
157 unsigned getMax() const {
158 return max;
159 }
160
161
162
163 static bool classof(const Attr *A) { return A->getKind() == attr::AMDGPUWavesPerEU; }
164};
165
166class ARMInterruptAttr : public InheritableAttr {
167public:
168 enum InterruptType {
169 IRQ,
170 FIQ,
171 SWI,
172 ABORT,
173 UNDEF,
174 Generic
175 };
176private:
177 InterruptType interrupt;
178
179public:
180 static ARMInterruptAttr *CreateImplicit(ASTContext &Ctx, InterruptType Interrupt, SourceRange Loc = SourceRange()) {
181 auto *A = new (Ctx) ARMInterruptAttr(Loc, Ctx, Interrupt, 0);
182 A->setImplicit(true);
183 return A;
184 }
185
186 ARMInterruptAttr(SourceRange R, ASTContext &Ctx
187 , InterruptType Interrupt
188 , unsigned SI
189 )
190 : InheritableAttr(attr::ARMInterrupt, R, SI, false, false)
191 , interrupt(Interrupt)
192 {
193 }
194
195 ARMInterruptAttr(SourceRange R, ASTContext &Ctx
196 , unsigned SI
197 )
198 : InheritableAttr(attr::ARMInterrupt, R, SI, false, false)
199 , interrupt(InterruptType(0))
200 {
201 }
202
203 ARMInterruptAttr *clone(ASTContext &C) const;
204 void printPretty(raw_ostream &OS,
205 const PrintingPolicy &Policy) const;
206 const char *getSpelling() const;
207 InterruptType getInterrupt() const {
208 return interrupt;
209 }
210
211 static bool ConvertStrToInterruptType(StringRef Val, InterruptType &Out) {
212 Optional<InterruptType> R = llvm::StringSwitch<Optional<InterruptType>>(Val)
213 .Case("IRQ", ARMInterruptAttr::IRQ)
214 .Case("FIQ", ARMInterruptAttr::FIQ)
215 .Case("SWI", ARMInterruptAttr::SWI)
216 .Case("ABORT", ARMInterruptAttr::ABORT)
217 .Case("UNDEF", ARMInterruptAttr::UNDEF)
218 .Case("", ARMInterruptAttr::Generic)
219 .Default(Optional<InterruptType>());
220 if (R) {
221 Out = *R;
222 return true;
223 }
224 return false;
225 }
226
227 static const char *ConvertInterruptTypeToStr(InterruptType Val) {
228 switch(Val) {
229 case ARMInterruptAttr::IRQ: return "IRQ";
230 case ARMInterruptAttr::FIQ: return "FIQ";
231 case ARMInterruptAttr::SWI: return "SWI";
232 case ARMInterruptAttr::ABORT: return "ABORT";
233 case ARMInterruptAttr::UNDEF: return "UNDEF";
234 case ARMInterruptAttr::Generic: return "";
235 }
236 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 236)
;
237 }
238
239
240 static bool classof(const Attr *A) { return A->getKind() == attr::ARMInterrupt; }
241};
242
243class AVRInterruptAttr : public InheritableAttr {
244public:
245 static AVRInterruptAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
246 auto *A = new (Ctx) AVRInterruptAttr(Loc, Ctx, 0);
247 A->setImplicit(true);
248 return A;
249 }
250
251 AVRInterruptAttr(SourceRange R, ASTContext &Ctx
252 , unsigned SI
253 )
254 : InheritableAttr(attr::AVRInterrupt, R, SI, false, false)
255 {
256 }
257
258 AVRInterruptAttr *clone(ASTContext &C) const;
259 void printPretty(raw_ostream &OS,
260 const PrintingPolicy &Policy) const;
261 const char *getSpelling() const;
262
263
264 static bool classof(const Attr *A) { return A->getKind() == attr::AVRInterrupt; }
265};
266
267class AVRSignalAttr : public InheritableAttr {
268public:
269 static AVRSignalAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
270 auto *A = new (Ctx) AVRSignalAttr(Loc, Ctx, 0);
271 A->setImplicit(true);
272 return A;
273 }
274
275 AVRSignalAttr(SourceRange R, ASTContext &Ctx
276 , unsigned SI
277 )
278 : InheritableAttr(attr::AVRSignal, R, SI, false, false)
279 {
280 }
281
282 AVRSignalAttr *clone(ASTContext &C) const;
283 void printPretty(raw_ostream &OS,
284 const PrintingPolicy &Policy) const;
285 const char *getSpelling() const;
286
287
288 static bool classof(const Attr *A) { return A->getKind() == attr::AVRSignal; }
289};
290
291class AbiTagAttr : public Attr {
292 unsigned tags_Size;
293 StringRef *tags_;
294
295public:
296 static AbiTagAttr *CreateImplicit(ASTContext &Ctx, StringRef *Tags, unsigned TagsSize, SourceRange Loc = SourceRange()) {
297 auto *A = new (Ctx) AbiTagAttr(Loc, Ctx, Tags, TagsSize, 0);
298 A->setImplicit(true);
299 return A;
300 }
301
302 AbiTagAttr(SourceRange R, ASTContext &Ctx
303 , StringRef *Tags, unsigned TagsSize
304 , unsigned SI
305 )
306 : Attr(attr::AbiTag, R, SI, false)
307 , tags_Size(TagsSize), tags_(new (Ctx, 16) StringRef[tags_Size])
308 {
309 for (size_t I = 0, E = tags_Size; I != E;
310 ++I) {
311 StringRef Ref = Tags[I];
312 if (!Ref.empty()) {
313 char *Mem = new (Ctx, 1) char[Ref.size()];
314 std::memcpy(Mem, Ref.data(), Ref.size());
315 tags_[I] = StringRef(Mem, Ref.size());
316 }
317 }
318 }
319
320 AbiTagAttr(SourceRange R, ASTContext &Ctx
321 , unsigned SI
322 )
323 : Attr(attr::AbiTag, R, SI, false)
324 , tags_Size(0), tags_(nullptr)
325 {
326 }
327
328 AbiTagAttr *clone(ASTContext &C) const;
329 void printPretty(raw_ostream &OS,
330 const PrintingPolicy &Policy) const;
331 const char *getSpelling() const;
332 typedef StringRef* tags_iterator;
333 tags_iterator tags_begin() const { return tags_; }
334 tags_iterator tags_end() const { return tags_ + tags_Size; }
335 unsigned tags_size() const { return tags_Size; }
336 llvm::iterator_range<tags_iterator> tags() const { return llvm::make_range(tags_begin(), tags_end()); }
337
338
339
340
341 static bool classof(const Attr *A) { return A->getKind() == attr::AbiTag; }
342};
343
344class AcquireCapabilityAttr : public InheritableAttr {
345 unsigned args_Size;
346 Expr * *args_;
347
348public:
349 enum Spelling {
350 GNU_acquire_capability = 0,
351 CXX11_clang_acquire_capability = 1,
352 GNU_acquire_shared_capability = 2,
353 CXX11_clang_acquire_shared_capability = 3,
354 GNU_exclusive_lock_function = 4,
355 GNU_shared_lock_function = 5
356 };
357
358 static AcquireCapabilityAttr *CreateImplicit(ASTContext &Ctx, Spelling S, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) {
359 auto *A = new (Ctx) AcquireCapabilityAttr(Loc, Ctx, Args, ArgsSize, S);
360 A->setImplicit(true);
361 return A;
362 }
363
364 AcquireCapabilityAttr(SourceRange R, ASTContext &Ctx
365 , Expr * *Args, unsigned ArgsSize
366 , unsigned SI
367 )
368 : InheritableAttr(attr::AcquireCapability, R, SI, true, true)
369 , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size])
370 {
371 std::copy(Args, Args + args_Size, args_);
372 }
373
374 AcquireCapabilityAttr(SourceRange R, ASTContext &Ctx
375 , unsigned SI
376 )
377 : InheritableAttr(attr::AcquireCapability, R, SI, true, true)
378 , args_Size(0), args_(nullptr)
379 {
380 }
381
382 AcquireCapabilityAttr *clone(ASTContext &C) const;
383 void printPretty(raw_ostream &OS,
384 const PrintingPolicy &Policy) const;
385 const char *getSpelling() const;
386 Spelling getSemanticSpelling() const {
387 switch (SpellingListIndex) {
388 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 388)
;
389 case 0: return GNU_acquire_capability;
390 case 1: return CXX11_clang_acquire_capability;
391 case 2: return GNU_acquire_shared_capability;
392 case 3: return CXX11_clang_acquire_shared_capability;
393 case 4: return GNU_exclusive_lock_function;
394 case 5: return GNU_shared_lock_function;
395 }
396 }
397 bool isShared() const { return SpellingListIndex == 2 ||
398 SpellingListIndex == 3 ||
399 SpellingListIndex == 5; }
400 typedef Expr ** args_iterator;
401 args_iterator args_begin() const { return args_; }
402 args_iterator args_end() const { return args_ + args_Size; }
403 unsigned args_size() const { return args_Size; }
404 llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); }
405
406
407
408
409 static bool classof(const Attr *A) { return A->getKind() == attr::AcquireCapability; }
410};
411
412class AcquiredAfterAttr : public InheritableAttr {
413 unsigned args_Size;
414 Expr * *args_;
415
416public:
417 static AcquiredAfterAttr *CreateImplicit(ASTContext &Ctx, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) {
418 auto *A = new (Ctx) AcquiredAfterAttr(Loc, Ctx, Args, ArgsSize, 0);
419 A->setImplicit(true);
420 return A;
421 }
422
423 AcquiredAfterAttr(SourceRange R, ASTContext &Ctx
424 , Expr * *Args, unsigned ArgsSize
425 , unsigned SI
426 )
427 : InheritableAttr(attr::AcquiredAfter, R, SI, true, true)
428 , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size])
429 {
430 std::copy(Args, Args + args_Size, args_);
431 }
432
433 AcquiredAfterAttr(SourceRange R, ASTContext &Ctx
434 , unsigned SI
435 )
436 : InheritableAttr(attr::AcquiredAfter, R, SI, true, true)
437 , args_Size(0), args_(nullptr)
438 {
439 }
440
441 AcquiredAfterAttr *clone(ASTContext &C) const;
442 void printPretty(raw_ostream &OS,
443 const PrintingPolicy &Policy) const;
444 const char *getSpelling() const;
445 typedef Expr ** args_iterator;
446 args_iterator args_begin() const { return args_; }
447 args_iterator args_end() const { return args_ + args_Size; }
448 unsigned args_size() const { return args_Size; }
449 llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); }
450
451
452
453
454 static bool classof(const Attr *A) { return A->getKind() == attr::AcquiredAfter; }
455};
456
457class AcquiredBeforeAttr : public InheritableAttr {
458 unsigned args_Size;
459 Expr * *args_;
460
461public:
462 static AcquiredBeforeAttr *CreateImplicit(ASTContext &Ctx, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) {
463 auto *A = new (Ctx) AcquiredBeforeAttr(Loc, Ctx, Args, ArgsSize, 0);
464 A->setImplicit(true);
465 return A;
466 }
467
468 AcquiredBeforeAttr(SourceRange R, ASTContext &Ctx
469 , Expr * *Args, unsigned ArgsSize
470 , unsigned SI
471 )
472 : InheritableAttr(attr::AcquiredBefore, R, SI, true, true)
473 , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size])
474 {
475 std::copy(Args, Args + args_Size, args_);
476 }
477
478 AcquiredBeforeAttr(SourceRange R, ASTContext &Ctx
479 , unsigned SI
480 )
481 : InheritableAttr(attr::AcquiredBefore, R, SI, true, true)
482 , args_Size(0), args_(nullptr)
483 {
484 }
485
486 AcquiredBeforeAttr *clone(ASTContext &C) const;
487 void printPretty(raw_ostream &OS,
488 const PrintingPolicy &Policy) const;
489 const char *getSpelling() const;
490 typedef Expr ** args_iterator;
491 args_iterator args_begin() const { return args_; }
492 args_iterator args_end() const { return args_ + args_Size; }
493 unsigned args_size() const { return args_Size; }
494 llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); }
495
496
497
498
499 static bool classof(const Attr *A) { return A->getKind() == attr::AcquiredBefore; }
500};
501
502class AliasAttr : public Attr {
503unsigned aliaseeLength;
504char *aliasee;
505
506public:
507 static AliasAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Aliasee, SourceRange Loc = SourceRange()) {
508 auto *A = new (Ctx) AliasAttr(Loc, Ctx, Aliasee, 0);
509 A->setImplicit(true);
510 return A;
511 }
512
513 AliasAttr(SourceRange R, ASTContext &Ctx
514 , llvm::StringRef Aliasee
515 , unsigned SI
516 )
517 : Attr(attr::Alias, R, SI, false)
518 , aliaseeLength(Aliasee.size()),aliasee(new (Ctx, 1) char[aliaseeLength])
519 {
520 if (!Aliasee.empty())
521 std::memcpy(aliasee, Aliasee.data(), aliaseeLength);
522 }
523
524 AliasAttr *clone(ASTContext &C) const;
525 void printPretty(raw_ostream &OS,
526 const PrintingPolicy &Policy) const;
527 const char *getSpelling() const;
528 llvm::StringRef getAliasee() const {
529 return llvm::StringRef(aliasee, aliaseeLength);
530 }
531 unsigned getAliaseeLength() const {
532 return aliaseeLength;
533 }
534 void setAliasee(ASTContext &C, llvm::StringRef S) {
535 aliaseeLength = S.size();
536 this->aliasee = new (C, 1) char [aliaseeLength];
537 if (!S.empty())
538 std::memcpy(this->aliasee, S.data(), aliaseeLength);
539 }
540
541
542
543 static bool classof(const Attr *A) { return A->getKind() == attr::Alias; }
544};
545
546class AlignMac68kAttr : public InheritableAttr {
547public:
548 static AlignMac68kAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
549 auto *A = new (Ctx) AlignMac68kAttr(Loc, Ctx, 0);
550 A->setImplicit(true);
551 return A;
552 }
553
554 AlignMac68kAttr(SourceRange R, ASTContext &Ctx
555 , unsigned SI
556 )
557 : InheritableAttr(attr::AlignMac68k, R, SI, false, false)
558 {
559 }
560
561 AlignMac68kAttr *clone(ASTContext &C) const;
562 void printPretty(raw_ostream &OS,
563 const PrintingPolicy &Policy) const;
564 const char *getSpelling() const;
565
566
567 static bool classof(const Attr *A) { return A->getKind() == attr::AlignMac68k; }
568};
569
570class AlignValueAttr : public Attr {
571Expr * alignment;
572
573public:
574 static AlignValueAttr *CreateImplicit(ASTContext &Ctx, Expr * Alignment, SourceRange Loc = SourceRange()) {
575 auto *A = new (Ctx) AlignValueAttr(Loc, Ctx, Alignment, 0);
576 A->setImplicit(true);
577 return A;
578 }
579
580 AlignValueAttr(SourceRange R, ASTContext &Ctx
581 , Expr * Alignment
582 , unsigned SI
583 )
584 : Attr(attr::AlignValue, R, SI, false)
585 , alignment(Alignment)
586 {
587 }
588
589 AlignValueAttr *clone(ASTContext &C) const;
590 void printPretty(raw_ostream &OS,
591 const PrintingPolicy &Policy) const;
592 const char *getSpelling() const;
593 Expr * getAlignment() const {
594 return alignment;
595 }
596
597
598
599 static bool classof(const Attr *A) { return A->getKind() == attr::AlignValue; }
600};
601
602class AlignedAttr : public InheritableAttr {
603bool isalignmentExpr;
604union {
605Expr *alignmentExpr;
606TypeSourceInfo *alignmentType;
607};
608
609public:
610 enum Spelling {
611 GNU_aligned = 0,
612 CXX11_gnu_aligned = 1,
613 Declspec_align = 2,
614 Keyword_alignas = 3,
615 Keyword_Alignas = 4
616 };
617
618 static AlignedAttr *CreateImplicit(ASTContext &Ctx, Spelling S, bool IsAlignmentExpr, void *Alignment, SourceRange Loc = SourceRange()) {
619 auto *A = new (Ctx) AlignedAttr(Loc, Ctx, IsAlignmentExpr, Alignment, S);
620 A->setImplicit(true);
621 return A;
622 }
623
624 AlignedAttr(SourceRange R, ASTContext &Ctx
625 , bool IsAlignmentExpr, void *Alignment
626 , unsigned SI
627 )
628 : InheritableAttr(attr::Aligned, R, SI, false, false)
629 , isalignmentExpr(IsAlignmentExpr)
630 {
631 if (isalignmentExpr)
632 alignmentExpr = reinterpret_cast<Expr *>(Alignment);
633 else
634 alignmentType = reinterpret_cast<TypeSourceInfo *>(Alignment);
635 }
636
637 AlignedAttr(SourceRange R, ASTContext &Ctx
638 , unsigned SI
639 )
640 : InheritableAttr(attr::Aligned, R, SI, false, false)
641 , isalignmentExpr(false)
642 {
643 }
644
645 AlignedAttr *clone(ASTContext &C) const;
646 void printPretty(raw_ostream &OS,
647 const PrintingPolicy &Policy) const;
648 const char *getSpelling() const;
649 Spelling getSemanticSpelling() const {
650 switch (SpellingListIndex) {
651 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 651)
;
652 case 0: return GNU_aligned;
653 case 1: return CXX11_gnu_aligned;
654 case 2: return Declspec_align;
655 case 3: return Keyword_alignas;
656 case 4: return Keyword_Alignas;
657 }
658 }
659 bool isGNU() const { return SpellingListIndex == 0 ||
660 SpellingListIndex == 1; }
661 bool isC11() const { return SpellingListIndex == 4; }
662 bool isAlignas() const { return SpellingListIndex == 3 ||
663 SpellingListIndex == 4; }
664 bool isDeclspec() const { return SpellingListIndex == 2; }
665 bool isAlignmentDependent() const;
666 unsigned getAlignment(ASTContext &Ctx) const;
667 bool isAlignmentExpr() const {
668 return isalignmentExpr;
669 }
670 Expr *getAlignmentExpr() const {
671 assert(isalignmentExpr)(static_cast <bool> (isalignmentExpr) ? void (0) : __assert_fail
("isalignmentExpr", "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 671, __extension__ __PRETTY_FUNCTION__))
;
672 return alignmentExpr;
673 }
674 TypeSourceInfo *getAlignmentType() const {
675 assert(!isalignmentExpr)(static_cast <bool> (!isalignmentExpr) ? void (0) : __assert_fail
("!isalignmentExpr", "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 675, __extension__ __PRETTY_FUNCTION__))
;
676 return alignmentType;
677 }
678
679
680
681 static bool classof(const Attr *A) { return A->getKind() == attr::Aligned; }
682};
683
684class AllocAlignAttr : public InheritableAttr {
685ParamIdx paramIndex;
686
687public:
688 static AllocAlignAttr *CreateImplicit(ASTContext &Ctx, ParamIdx ParamIndex, SourceRange Loc = SourceRange()) {
689 auto *A = new (Ctx) AllocAlignAttr(Loc, Ctx, ParamIndex, 0);
690 A->setImplicit(true);
691 return A;
692 }
693
694 AllocAlignAttr(SourceRange R, ASTContext &Ctx
695 , ParamIdx ParamIndex
696 , unsigned SI
697 )
698 : InheritableAttr(attr::AllocAlign, R, SI, false, false)
699 , paramIndex(ParamIndex)
700 {
701 }
702
703 AllocAlignAttr *clone(ASTContext &C) const;
704 void printPretty(raw_ostream &OS,
705 const PrintingPolicy &Policy) const;
706 const char *getSpelling() const;
707 ParamIdx getParamIndex() const {
708 return paramIndex;
709 }
710
711
712
713 static bool classof(const Attr *A) { return A->getKind() == attr::AllocAlign; }
714};
715
716class AllocSizeAttr : public InheritableAttr {
717ParamIdx elemSizeParam;
718
719ParamIdx numElemsParam;
720
721public:
722 static AllocSizeAttr *CreateImplicit(ASTContext &Ctx, ParamIdx ElemSizeParam, ParamIdx NumElemsParam, SourceRange Loc = SourceRange()) {
723 auto *A = new (Ctx) AllocSizeAttr(Loc, Ctx, ElemSizeParam, NumElemsParam, 0);
724 A->setImplicit(true);
725 return A;
726 }
727
728 AllocSizeAttr(SourceRange R, ASTContext &Ctx
729 , ParamIdx ElemSizeParam
730 , ParamIdx NumElemsParam
731 , unsigned SI
732 )
733 : InheritableAttr(attr::AllocSize, R, SI, false, false)
734 , elemSizeParam(ElemSizeParam)
735 , numElemsParam(NumElemsParam)
736 {
737 }
738
739 AllocSizeAttr(SourceRange R, ASTContext &Ctx
740 , ParamIdx ElemSizeParam
741 , unsigned SI
742 )
743 : InheritableAttr(attr::AllocSize, R, SI, false, false)
744 , elemSizeParam(ElemSizeParam)
745 , numElemsParam()
746 {
747 }
748
749 AllocSizeAttr *clone(ASTContext &C) const;
750 void printPretty(raw_ostream &OS,
751 const PrintingPolicy &Policy) const;
752 const char *getSpelling() const;
753 ParamIdx getElemSizeParam() const {
754 return elemSizeParam;
755 }
756
757 ParamIdx getNumElemsParam() const {
758 return numElemsParam;
759 }
760
761
762
763 static bool classof(const Attr *A) { return A->getKind() == attr::AllocSize; }
764};
765
766class AlwaysInlineAttr : public InheritableAttr {
767public:
768 enum Spelling {
769 GNU_always_inline = 0,
770 CXX11_gnu_always_inline = 1,
771 Keyword_forceinline = 2
772 };
773
774 static AlwaysInlineAttr *CreateImplicit(ASTContext &Ctx, Spelling S, SourceRange Loc = SourceRange()) {
775 auto *A = new (Ctx) AlwaysInlineAttr(Loc, Ctx, S);
776 A->setImplicit(true);
777 return A;
778 }
779
780 AlwaysInlineAttr(SourceRange R, ASTContext &Ctx
781 , unsigned SI
782 )
783 : InheritableAttr(attr::AlwaysInline, R, SI, false, false)
784 {
785 }
786
787 AlwaysInlineAttr *clone(ASTContext &C) const;
788 void printPretty(raw_ostream &OS,
789 const PrintingPolicy &Policy) const;
790 const char *getSpelling() const;
791 Spelling getSemanticSpelling() const {
792 switch (SpellingListIndex) {
793 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 793)
;
794 case 0: return GNU_always_inline;
795 case 1: return CXX11_gnu_always_inline;
796 case 2: return Keyword_forceinline;
797 }
798 }
799
800
801 static bool classof(const Attr *A) { return A->getKind() == attr::AlwaysInline; }
802};
803
804class AnalyzerNoReturnAttr : public InheritableAttr {
805public:
806 static AnalyzerNoReturnAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
807 auto *A = new (Ctx) AnalyzerNoReturnAttr(Loc, Ctx, 0);
808 A->setImplicit(true);
809 return A;
810 }
811
812 AnalyzerNoReturnAttr(SourceRange R, ASTContext &Ctx
813 , unsigned SI
814 )
815 : InheritableAttr(attr::AnalyzerNoReturn, R, SI, false, false)
816 {
817 }
818
819 AnalyzerNoReturnAttr *clone(ASTContext &C) const;
820 void printPretty(raw_ostream &OS,
821 const PrintingPolicy &Policy) const;
822 const char *getSpelling() const;
823
824
825 static bool classof(const Attr *A) { return A->getKind() == attr::AnalyzerNoReturn; }
826};
827
828class AnnotateAttr : public InheritableParamAttr {
829unsigned annotationLength;
830char *annotation;
831
832public:
833 static AnnotateAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Annotation, SourceRange Loc = SourceRange()) {
834 auto *A = new (Ctx) AnnotateAttr(Loc, Ctx, Annotation, 0);
835 A->setImplicit(true);
836 return A;
837 }
838
839 AnnotateAttr(SourceRange R, ASTContext &Ctx
840 , llvm::StringRef Annotation
841 , unsigned SI
842 )
843 : InheritableParamAttr(attr::Annotate, R, SI, false, false)
844 , annotationLength(Annotation.size()),annotation(new (Ctx, 1) char[annotationLength])
845 {
846 if (!Annotation.empty())
847 std::memcpy(annotation, Annotation.data(), annotationLength);
848 }
849
850 AnnotateAttr *clone(ASTContext &C) const;
851 void printPretty(raw_ostream &OS,
852 const PrintingPolicy &Policy) const;
853 const char *getSpelling() const;
854 llvm::StringRef getAnnotation() const {
855 return llvm::StringRef(annotation, annotationLength);
856 }
857 unsigned getAnnotationLength() const {
858 return annotationLength;
859 }
860 void setAnnotation(ASTContext &C, llvm::StringRef S) {
861 annotationLength = S.size();
862 this->annotation = new (C, 1) char [annotationLength];
863 if (!S.empty())
864 std::memcpy(this->annotation, S.data(), annotationLength);
865 }
866
867
868
869 static bool classof(const Attr *A) { return A->getKind() == attr::Annotate; }
870};
871
872class AnyX86InterruptAttr : public InheritableAttr {
873public:
874 static AnyX86InterruptAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
875 auto *A = new (Ctx) AnyX86InterruptAttr(Loc, Ctx, 0);
876 A->setImplicit(true);
877 return A;
878 }
879
880 AnyX86InterruptAttr(SourceRange R, ASTContext &Ctx
881 , unsigned SI
882 )
883 : InheritableAttr(attr::AnyX86Interrupt, R, SI, false, false)
884 {
885 }
886
887 AnyX86InterruptAttr *clone(ASTContext &C) const;
888 void printPretty(raw_ostream &OS,
889 const PrintingPolicy &Policy) const;
890 const char *getSpelling() const;
891
892
893 static bool classof(const Attr *A) { return A->getKind() == attr::AnyX86Interrupt; }
894};
895
896class AnyX86NoCallerSavedRegistersAttr : public InheritableAttr {
897public:
898 static AnyX86NoCallerSavedRegistersAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
899 auto *A = new (Ctx) AnyX86NoCallerSavedRegistersAttr(Loc, Ctx, 0);
900 A->setImplicit(true);
901 return A;
902 }
903
904 AnyX86NoCallerSavedRegistersAttr(SourceRange R, ASTContext &Ctx
905 , unsigned SI
906 )
907 : InheritableAttr(attr::AnyX86NoCallerSavedRegisters, R, SI, false, false)
908 {
909 }
910
911 AnyX86NoCallerSavedRegistersAttr *clone(ASTContext &C) const;
912 void printPretty(raw_ostream &OS,
913 const PrintingPolicy &Policy) const;
914 const char *getSpelling() const;
915
916
917 static bool classof(const Attr *A) { return A->getKind() == attr::AnyX86NoCallerSavedRegisters; }
918};
919
920class AnyX86NoCfCheckAttr : public InheritableAttr {
921public:
922 static AnyX86NoCfCheckAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
923 auto *A = new (Ctx) AnyX86NoCfCheckAttr(Loc, Ctx, 0);
924 A->setImplicit(true);
925 return A;
926 }
927
928 AnyX86NoCfCheckAttr(SourceRange R, ASTContext &Ctx
929 , unsigned SI
930 )
931 : InheritableAttr(attr::AnyX86NoCfCheck, R, SI, false, false)
932 {
933 }
934
935 AnyX86NoCfCheckAttr *clone(ASTContext &C) const;
936 void printPretty(raw_ostream &OS,
937 const PrintingPolicy &Policy) const;
938 const char *getSpelling() const;
939
940
941 static bool classof(const Attr *A) { return A->getKind() == attr::AnyX86NoCfCheck; }
942};
943
944class ArcWeakrefUnavailableAttr : public InheritableAttr {
945public:
946 static ArcWeakrefUnavailableAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
947 auto *A = new (Ctx) ArcWeakrefUnavailableAttr(Loc, Ctx, 0);
948 A->setImplicit(true);
949 return A;
950 }
951
952 ArcWeakrefUnavailableAttr(SourceRange R, ASTContext &Ctx
953 , unsigned SI
954 )
955 : InheritableAttr(attr::ArcWeakrefUnavailable, R, SI, false, false)
956 {
957 }
958
959 ArcWeakrefUnavailableAttr *clone(ASTContext &C) const;
960 void printPretty(raw_ostream &OS,
961 const PrintingPolicy &Policy) const;
962 const char *getSpelling() const;
963
964
965 static bool classof(const Attr *A) { return A->getKind() == attr::ArcWeakrefUnavailable; }
966};
967
968class ArgumentWithTypeTagAttr : public InheritableAttr {
969IdentifierInfo * argumentKind;
970
971ParamIdx argumentIdx;
972
973ParamIdx typeTagIdx;
974
975bool isPointer;
976
977public:
978 enum Spelling {
979 GNU_argument_with_type_tag = 0,
980 CXX11_clang_argument_with_type_tag = 1,
981 C2x_clang_argument_with_type_tag = 2,
982 GNU_pointer_with_type_tag = 3,
983 CXX11_clang_pointer_with_type_tag = 4,
984 C2x_clang_pointer_with_type_tag = 5
985 };
986
987 static ArgumentWithTypeTagAttr *CreateImplicit(ASTContext &Ctx, Spelling S, IdentifierInfo * ArgumentKind, ParamIdx ArgumentIdx, ParamIdx TypeTagIdx, bool IsPointer, SourceRange Loc = SourceRange()) {
988 auto *A = new (Ctx) ArgumentWithTypeTagAttr(Loc, Ctx, ArgumentKind, ArgumentIdx, TypeTagIdx, IsPointer, S);
989 A->setImplicit(true);
990 return A;
991 }
992
993 static ArgumentWithTypeTagAttr *CreateImplicit(ASTContext &Ctx, Spelling S, IdentifierInfo * ArgumentKind, ParamIdx ArgumentIdx, ParamIdx TypeTagIdx, SourceRange Loc = SourceRange()) {
994 auto *A = new (Ctx) ArgumentWithTypeTagAttr(Loc, Ctx, ArgumentKind, ArgumentIdx, TypeTagIdx, S);
995 A->setImplicit(true);
996 return A;
997 }
998
999 ArgumentWithTypeTagAttr(SourceRange R, ASTContext &Ctx
1000 , IdentifierInfo * ArgumentKind
1001 , ParamIdx ArgumentIdx
1002 , ParamIdx TypeTagIdx
1003 , bool IsPointer
1004 , unsigned SI
1005 )
1006 : InheritableAttr(attr::ArgumentWithTypeTag, R, SI, false, false)
1007 , argumentKind(ArgumentKind)
1008 , argumentIdx(ArgumentIdx)
1009 , typeTagIdx(TypeTagIdx)
1010 , isPointer(IsPointer)
1011 {
1012 }
1013
1014 ArgumentWithTypeTagAttr(SourceRange R, ASTContext &Ctx
1015 , IdentifierInfo * ArgumentKind
1016 , ParamIdx ArgumentIdx
1017 , ParamIdx TypeTagIdx
1018 , unsigned SI
1019 )
1020 : InheritableAttr(attr::ArgumentWithTypeTag, R, SI, false, false)
1021 , argumentKind(ArgumentKind)
1022 , argumentIdx(ArgumentIdx)
1023 , typeTagIdx(TypeTagIdx)
1024 , isPointer()
1025 {
1026 }
1027
1028 ArgumentWithTypeTagAttr *clone(ASTContext &C) const;
1029 void printPretty(raw_ostream &OS,
1030 const PrintingPolicy &Policy) const;
1031 const char *getSpelling() const;
1032 Spelling getSemanticSpelling() const {
1033 switch (SpellingListIndex) {
1034 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 1034)
;
1035 case 0: return GNU_argument_with_type_tag;
1036 case 1: return CXX11_clang_argument_with_type_tag;
1037 case 2: return C2x_clang_argument_with_type_tag;
1038 case 3: return GNU_pointer_with_type_tag;
1039 case 4: return CXX11_clang_pointer_with_type_tag;
1040 case 5: return C2x_clang_pointer_with_type_tag;
1041 }
1042 }
1043 IdentifierInfo * getArgumentKind() const {
1044 return argumentKind;
1045 }
1046
1047 ParamIdx getArgumentIdx() const {
1048 return argumentIdx;
1049 }
1050
1051 ParamIdx getTypeTagIdx() const {
1052 return typeTagIdx;
1053 }
1054
1055 bool getIsPointer() const {
1056 return isPointer;
1057 }
1058
1059
1060
1061 static bool classof(const Attr *A) { return A->getKind() == attr::ArgumentWithTypeTag; }
1062};
1063
1064class ArtificialAttr : public InheritableAttr {
1065public:
1066 static ArtificialAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1067 auto *A = new (Ctx) ArtificialAttr(Loc, Ctx, 0);
1068 A->setImplicit(true);
1069 return A;
1070 }
1071
1072 ArtificialAttr(SourceRange R, ASTContext &Ctx
1073 , unsigned SI
1074 )
1075 : InheritableAttr(attr::Artificial, R, SI, false, false)
1076 {
1077 }
1078
1079 ArtificialAttr *clone(ASTContext &C) const;
1080 void printPretty(raw_ostream &OS,
1081 const PrintingPolicy &Policy) const;
1082 const char *getSpelling() const;
1083
1084
1085 static bool classof(const Attr *A) { return A->getKind() == attr::Artificial; }
1086};
1087
1088class AsmLabelAttr : public InheritableAttr {
1089unsigned labelLength;
1090char *label;
1091
1092public:
1093 static AsmLabelAttr *CreateImplicit(ASTContext &Ctx, llvm::StringRef Label, SourceRange Loc = SourceRange()) {
1094 auto *A = new (Ctx) AsmLabelAttr(Loc, Ctx, Label, 0);
1095 A->setImplicit(true);
1096 return A;
1097 }
1098
1099 AsmLabelAttr(SourceRange R, ASTContext &Ctx
1100 , llvm::StringRef Label
1101 , unsigned SI
1102 )
1103 : InheritableAttr(attr::AsmLabel, R, SI, false, false)
1104 , labelLength(Label.size()),label(new (Ctx, 1) char[labelLength])
1105 {
1106 if (!Label.empty())
1107 std::memcpy(label, Label.data(), labelLength);
1108 }
1109
1110 AsmLabelAttr *clone(ASTContext &C) const;
1111 void printPretty(raw_ostream &OS,
1112 const PrintingPolicy &Policy) const;
1113 const char *getSpelling() const;
1114 llvm::StringRef getLabel() const {
1115 return llvm::StringRef(label, labelLength);
1116 }
1117 unsigned getLabelLength() const {
1118 return labelLength;
1119 }
1120 void setLabel(ASTContext &C, llvm::StringRef S) {
1121 labelLength = S.size();
1122 this->label = new (C, 1) char [labelLength];
1123 if (!S.empty())
1124 std::memcpy(this->label, S.data(), labelLength);
1125 }
1126
1127
1128
1129 static bool classof(const Attr *A) { return A->getKind() == attr::AsmLabel; }
1130};
1131
1132class AssertCapabilityAttr : public InheritableAttr {
1133 unsigned args_Size;
1134 Expr * *args_;
1135
1136public:
1137 enum Spelling {
1138 GNU_assert_capability = 0,
1139 CXX11_clang_assert_capability = 1,
1140 GNU_assert_shared_capability = 2,
1141 CXX11_clang_assert_shared_capability = 3
1142 };
1143
1144 static AssertCapabilityAttr *CreateImplicit(ASTContext &Ctx, Spelling S, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) {
1145 auto *A = new (Ctx) AssertCapabilityAttr(Loc, Ctx, Args, ArgsSize, S);
1146 A->setImplicit(true);
1147 return A;
1148 }
1149
1150 AssertCapabilityAttr(SourceRange R, ASTContext &Ctx
1151 , Expr * *Args, unsigned ArgsSize
1152 , unsigned SI
1153 )
1154 : InheritableAttr(attr::AssertCapability, R, SI, true, true)
1155 , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size])
1156 {
1157 std::copy(Args, Args + args_Size, args_);
1158 }
1159
1160 AssertCapabilityAttr(SourceRange R, ASTContext &Ctx
1161 , unsigned SI
1162 )
1163 : InheritableAttr(attr::AssertCapability, R, SI, true, true)
1164 , args_Size(0), args_(nullptr)
1165 {
1166 }
1167
1168 AssertCapabilityAttr *clone(ASTContext &C) const;
1169 void printPretty(raw_ostream &OS,
1170 const PrintingPolicy &Policy) const;
1171 const char *getSpelling() const;
1172 Spelling getSemanticSpelling() const {
1173 switch (SpellingListIndex) {
1174 default: llvm_unreachable("Unknown spelling list index")::llvm::llvm_unreachable_internal("Unknown spelling list index"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 1174)
;
1175 case 0: return GNU_assert_capability;
1176 case 1: return CXX11_clang_assert_capability;
1177 case 2: return GNU_assert_shared_capability;
1178 case 3: return CXX11_clang_assert_shared_capability;
1179 }
1180 }
1181 bool isShared() const { return SpellingListIndex == 2 ||
1182 SpellingListIndex == 3; }
1183 typedef Expr ** args_iterator;
1184 args_iterator args_begin() const { return args_; }
1185 args_iterator args_end() const { return args_ + args_Size; }
1186 unsigned args_size() const { return args_Size; }
1187 llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); }
1188
1189
1190
1191
1192 static bool classof(const Attr *A) { return A->getKind() == attr::AssertCapability; }
1193};
1194
1195class AssertExclusiveLockAttr : public InheritableAttr {
1196 unsigned args_Size;
1197 Expr * *args_;
1198
1199public:
1200 static AssertExclusiveLockAttr *CreateImplicit(ASTContext &Ctx, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) {
1201 auto *A = new (Ctx) AssertExclusiveLockAttr(Loc, Ctx, Args, ArgsSize, 0);
1202 A->setImplicit(true);
1203 return A;
1204 }
1205
1206 AssertExclusiveLockAttr(SourceRange R, ASTContext &Ctx
1207 , Expr * *Args, unsigned ArgsSize
1208 , unsigned SI
1209 )
1210 : InheritableAttr(attr::AssertExclusiveLock, R, SI, true, true)
1211 , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size])
1212 {
1213 std::copy(Args, Args + args_Size, args_);
1214 }
1215
1216 AssertExclusiveLockAttr(SourceRange R, ASTContext &Ctx
1217 , unsigned SI
1218 )
1219 : InheritableAttr(attr::AssertExclusiveLock, R, SI, true, true)
1220 , args_Size(0), args_(nullptr)
1221 {
1222 }
1223
1224 AssertExclusiveLockAttr *clone(ASTContext &C) const;
1225 void printPretty(raw_ostream &OS,
1226 const PrintingPolicy &Policy) const;
1227 const char *getSpelling() const;
1228 typedef Expr ** args_iterator;
1229 args_iterator args_begin() const { return args_; }
1230 args_iterator args_end() const { return args_ + args_Size; }
1231 unsigned args_size() const { return args_Size; }
1232 llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); }
1233
1234
1235
1236
1237 static bool classof(const Attr *A) { return A->getKind() == attr::AssertExclusiveLock; }
1238};
1239
1240class AssertSharedLockAttr : public InheritableAttr {
1241 unsigned args_Size;
1242 Expr * *args_;
1243
1244public:
1245 static AssertSharedLockAttr *CreateImplicit(ASTContext &Ctx, Expr * *Args, unsigned ArgsSize, SourceRange Loc = SourceRange()) {
1246 auto *A = new (Ctx) AssertSharedLockAttr(Loc, Ctx, Args, ArgsSize, 0);
1247 A->setImplicit(true);
1248 return A;
1249 }
1250
1251 AssertSharedLockAttr(SourceRange R, ASTContext &Ctx
1252 , Expr * *Args, unsigned ArgsSize
1253 , unsigned SI
1254 )
1255 : InheritableAttr(attr::AssertSharedLock, R, SI, true, true)
1256 , args_Size(ArgsSize), args_(new (Ctx, 16) Expr *[args_Size])
1257 {
1258 std::copy(Args, Args + args_Size, args_);
1259 }
1260
1261 AssertSharedLockAttr(SourceRange R, ASTContext &Ctx
1262 , unsigned SI
1263 )
1264 : InheritableAttr(attr::AssertSharedLock, R, SI, true, true)
1265 , args_Size(0), args_(nullptr)
1266 {
1267 }
1268
1269 AssertSharedLockAttr *clone(ASTContext &C) const;
1270 void printPretty(raw_ostream &OS,
1271 const PrintingPolicy &Policy) const;
1272 const char *getSpelling() const;
1273 typedef Expr ** args_iterator;
1274 args_iterator args_begin() const { return args_; }
1275 args_iterator args_end() const { return args_ + args_Size; }
1276 unsigned args_size() const { return args_Size; }
1277 llvm::iterator_range<args_iterator> args() const { return llvm::make_range(args_begin(), args_end()); }
1278
1279
1280
1281
1282 static bool classof(const Attr *A) { return A->getKind() == attr::AssertSharedLock; }
1283};
1284
1285class AssumeAlignedAttr : public InheritableAttr {
1286Expr * alignment;
1287
1288Expr * offset;
1289
1290public:
1291 static AssumeAlignedAttr *CreateImplicit(ASTContext &Ctx, Expr * Alignment, Expr * Offset, SourceRange Loc = SourceRange()) {
1292 auto *A = new (Ctx) AssumeAlignedAttr(Loc, Ctx, Alignment, Offset, 0);
1293 A->setImplicit(true);
1294 return A;
1295 }
1296
1297 AssumeAlignedAttr(SourceRange R, ASTContext &Ctx
1298 , Expr * Alignment
1299 , Expr * Offset
1300 , unsigned SI
1301 )
1302 : InheritableAttr(attr::AssumeAligned, R, SI, false, false)
1303 , alignment(Alignment)
1304 , offset(Offset)
1305 {
1306 }
1307
1308 AssumeAlignedAttr(SourceRange R, ASTContext &Ctx
1309 , Expr * Alignment
1310 , unsigned SI
1311 )
1312 : InheritableAttr(attr::AssumeAligned, R, SI, false, false)
1313 , alignment(Alignment)
1314 , offset()
1315 {
1316 }
1317
1318 AssumeAlignedAttr *clone(ASTContext &C) const;
1319 void printPretty(raw_ostream &OS,
1320 const PrintingPolicy &Policy) const;
1321 const char *getSpelling() const;
1322 Expr * getAlignment() const {
1323 return alignment;
1324 }
1325
1326 Expr * getOffset() const {
1327 return offset;
1328 }
1329
1330
1331
1332 static bool classof(const Attr *A) { return A->getKind() == attr::AssumeAligned; }
1333};
1334
1335class AvailabilityAttr : public InheritableAttr {
1336IdentifierInfo * platform;
1337
1338VersionTuple introduced;
1339
1340
1341VersionTuple deprecated;
1342
1343
1344VersionTuple obsoleted;
1345
1346
1347bool unavailable;
1348
1349unsigned messageLength;
1350char *message;
1351
1352bool strict;
1353
1354unsigned replacementLength;
1355char *replacement;
1356
1357public:
1358 static AvailabilityAttr *CreateImplicit(ASTContext &Ctx, IdentifierInfo * Platform, VersionTuple Introduced, VersionTuple Deprecated, VersionTuple Obsoleted, bool Unavailable, llvm::StringRef Message, bool Strict, llvm::StringRef Replacement, SourceRange Loc = SourceRange()) {
1359 auto *A = new (Ctx) AvailabilityAttr(Loc, Ctx, Platform, Introduced, Deprecated, Obsoleted, Unavailable, Message, Strict, Replacement, 0);
1360 A->setImplicit(true);
1361 return A;
1362 }
1363
1364 AvailabilityAttr(SourceRange R, ASTContext &Ctx
1365 , IdentifierInfo * Platform
1366 , VersionTuple Introduced
1367 , VersionTuple Deprecated
1368 , VersionTuple Obsoleted
1369 , bool Unavailable
1370 , llvm::StringRef Message
1371 , bool Strict
1372 , llvm::StringRef Replacement
1373 , unsigned SI
1374 )
1375 : InheritableAttr(attr::Availability, R, SI, false, true)
1376 , platform(Platform)
1377 , introduced(Introduced)
1378 , deprecated(Deprecated)
1379 , obsoleted(Obsoleted)
1380 , unavailable(Unavailable)
1381 , messageLength(Message.size()),message(new (Ctx, 1) char[messageLength])
1382 , strict(Strict)
1383 , replacementLength(Replacement.size()),replacement(new (Ctx, 1) char[replacementLength])
1384 {
1385 if (!Message.empty())
1386 std::memcpy(message, Message.data(), messageLength);
1387 if (!Replacement.empty())
1388 std::memcpy(replacement, Replacement.data(), replacementLength);
1389 }
1390
1391 AvailabilityAttr *clone(ASTContext &C) const;
1392 void printPretty(raw_ostream &OS,
1393 const PrintingPolicy &Policy) const;
1394 const char *getSpelling() const;
1395 IdentifierInfo * getPlatform() const {
1396 return platform;
1397 }
1398
1399 VersionTuple getIntroduced() const {
1400 return introduced;
1401 }
1402 void setIntroduced(ASTContext &C, VersionTuple V) {
1403 introduced = V;
1404 }
1405
1406 VersionTuple getDeprecated() const {
1407 return deprecated;
1408 }
1409 void setDeprecated(ASTContext &C, VersionTuple V) {
1410 deprecated = V;
1411 }
1412
1413 VersionTuple getObsoleted() const {
1414 return obsoleted;
1415 }
1416 void setObsoleted(ASTContext &C, VersionTuple V) {
1417 obsoleted = V;
1418 }
1419
1420 bool getUnavailable() const {
1421 return unavailable;
1422 }
1423
1424 llvm::StringRef getMessage() const {
1425 return llvm::StringRef(message, messageLength);
1426 }
1427 unsigned getMessageLength() const {
1428 return messageLength;
1429 }
1430 void setMessage(ASTContext &C, llvm::StringRef S) {
1431 messageLength = S.size();
1432 this->message = new (C, 1) char [messageLength];
1433 if (!S.empty())
1434 std::memcpy(this->message, S.data(), messageLength);
1435 }
1436
1437 bool getStrict() const {
1438 return strict;
1439 }
1440
1441 llvm::StringRef getReplacement() const {
1442 return llvm::StringRef(replacement, replacementLength);
1443 }
1444 unsigned getReplacementLength() const {
1445 return replacementLength;
1446 }
1447 void setReplacement(ASTContext &C, llvm::StringRef S) {
1448 replacementLength = S.size();
1449 this->replacement = new (C, 1) char [replacementLength];
1450 if (!S.empty())
1451 std::memcpy(this->replacement, S.data(), replacementLength);
1452 }
1453
1454static llvm::StringRef getPrettyPlatformName(llvm::StringRef Platform) {
1455 return llvm::StringSwitch<llvm::StringRef>(Platform)
1456 .Case("android", "Android")
1457 .Case("ios", "iOS")
1458 .Case("macos", "macOS")
1459 .Case("tvos", "tvOS")
1460 .Case("watchos", "watchOS")
1461 .Case("ios_app_extension", "iOS (App Extension)")
1462 .Case("macos_app_extension", "macOS (App Extension)")
1463 .Case("tvos_app_extension", "tvOS (App Extension)")
1464 .Case("watchos_app_extension", "watchOS (App Extension)")
1465 .Default(llvm::StringRef());
1466}
1467static llvm::StringRef getPlatformNameSourceSpelling(llvm::StringRef Platform) {
1468 return llvm::StringSwitch<llvm::StringRef>(Platform)
1469 .Case("ios", "iOS")
1470 .Case("macos", "macOS")
1471 .Case("tvos", "tvOS")
1472 .Case("watchos", "watchOS")
1473 .Case("ios_app_extension", "iOSApplicationExtension")
1474 .Case("macos_app_extension", "macOSApplicationExtension")
1475 .Case("tvos_app_extension", "tvOSApplicationExtension")
1476 .Case("watchos_app_extension", "watchOSApplicationExtension")
1477 .Default(Platform);
1478}
1479static llvm::StringRef canonicalizePlatformName(llvm::StringRef Platform) {
1480 return llvm::StringSwitch<llvm::StringRef>(Platform)
1481 .Case("iOS", "ios")
1482 .Case("macOS", "macos")
1483 .Case("tvOS", "tvos")
1484 .Case("watchOS", "watchos")
1485 .Case("iOSApplicationExtension", "ios_app_extension")
1486 .Case("macOSApplicationExtension", "macos_app_extension")
1487 .Case("tvOSApplicationExtension", "tvos_app_extension")
1488 .Case("watchOSApplicationExtension", "watchos_app_extension")
1489 .Default(Platform);
1490}
1491
1492 static bool classof(const Attr *A) { return A->getKind() == attr::Availability; }
1493};
1494
1495class BlocksAttr : public InheritableAttr {
1496public:
1497 enum BlockType {
1498 ByRef
1499 };
1500private:
1501 BlockType type;
1502
1503public:
1504 static BlocksAttr *CreateImplicit(ASTContext &Ctx, BlockType Type, SourceRange Loc = SourceRange()) {
1505 auto *A = new (Ctx) BlocksAttr(Loc, Ctx, Type, 0);
1506 A->setImplicit(true);
1507 return A;
1508 }
1509
1510 BlocksAttr(SourceRange R, ASTContext &Ctx
1511 , BlockType Type
1512 , unsigned SI
1513 )
1514 : InheritableAttr(attr::Blocks, R, SI, false, false)
1515 , type(Type)
1516 {
1517 }
1518
1519 BlocksAttr *clone(ASTContext &C) const;
1520 void printPretty(raw_ostream &OS,
1521 const PrintingPolicy &Policy) const;
1522 const char *getSpelling() const;
1523 BlockType getType() const {
1524 return type;
1525 }
1526
1527 static bool ConvertStrToBlockType(StringRef Val, BlockType &Out) {
1528 Optional<BlockType> R = llvm::StringSwitch<Optional<BlockType>>(Val)
1529 .Case("byref", BlocksAttr::ByRef)
1530 .Default(Optional<BlockType>());
1531 if (R) {
1532 Out = *R;
1533 return true;
1534 }
1535 return false;
1536 }
1537
1538 static const char *ConvertBlockTypeToStr(BlockType Val) {
1539 switch(Val) {
1540 case BlocksAttr::ByRef: return "byref";
1541 }
1542 llvm_unreachable("No enumerator with that value")::llvm::llvm_unreachable_internal("No enumerator with that value"
, "/build/llvm-toolchain-snapshot-7~svn329677/build-llvm/tools/clang/include/clang/AST/Attrs.inc"
, 1542)
;
1543 }
1544
1545
1546 static bool classof(const Attr *A) { return A->getKind() == attr::Blocks; }
1547};
1548
1549class C11NoReturnAttr : public InheritableAttr {
1550public:
1551 static C11NoReturnAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1552 auto *A = new (Ctx) C11NoReturnAttr(Loc, Ctx, 0);
1553 A->setImplicit(true);
1554 return A;
1555 }
1556
1557 C11NoReturnAttr(SourceRange R, ASTContext &Ctx
1558 , unsigned SI
1559 )
1560 : InheritableAttr(attr::C11NoReturn, R, SI, false, false)
1561 {
1562 }
1563
1564 C11NoReturnAttr *clone(ASTContext &C) const;
1565 void printPretty(raw_ostream &OS,
1566 const PrintingPolicy &Policy) const;
1567 const char *getSpelling() const;
1568
1569
1570 static bool classof(const Attr *A) { return A->getKind() == attr::C11NoReturn; }
1571};
1572
1573class CDeclAttr : public InheritableAttr {
1574public:
1575 static CDeclAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1576 auto *A = new (Ctx) CDeclAttr(Loc, Ctx, 0);
1577 A->setImplicit(true);
1578 return A;
1579 }
1580
1581 CDeclAttr(SourceRange R, ASTContext &Ctx
1582 , unsigned SI
1583 )
1584 : InheritableAttr(attr::CDecl, R, SI, false, false)
1585 {
1586 }
1587
1588 CDeclAttr *clone(ASTContext &C) const;
1589 void printPretty(raw_ostream &OS,
1590 const PrintingPolicy &Policy) const;
1591 const char *getSpelling() const;
1592
1593
1594 static bool classof(const Attr *A) { return A->getKind() == attr::CDecl; }
1595};
1596
1597class CFAuditedTransferAttr : public InheritableAttr {
1598public:
1599 static CFAuditedTransferAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1600 auto *A = new (Ctx) CFAuditedTransferAttr(Loc, Ctx, 0);
1601 A->setImplicit(true);
1602 return A;
1603 }
1604
1605 CFAuditedTransferAttr(SourceRange R, ASTContext &Ctx
1606 , unsigned SI
1607 )
1608 : InheritableAttr(attr::CFAuditedTransfer, R, SI, false, false)
1609 {
1610 }
1611
1612 CFAuditedTransferAttr *clone(ASTContext &C) const;
1613 void printPretty(raw_ostream &OS,
1614 const PrintingPolicy &Policy) const;
1615 const char *getSpelling() const;
1616
1617
1618 static bool classof(const Attr *A) { return A->getKind() == attr::CFAuditedTransfer; }
1619};
1620
1621class CFConsumedAttr : public InheritableParamAttr {
1622public:
1623 static CFConsumedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1624 auto *A = new (Ctx) CFConsumedAttr(Loc, Ctx, 0);
1625 A->setImplicit(true);
1626 return A;
1627 }
1628
1629 CFConsumedAttr(SourceRange R, ASTContext &Ctx
1630 , unsigned SI
1631 )
1632 : InheritableParamAttr(attr::CFConsumed, R, SI, false, false)
1633 {
1634 }
1635
1636 CFConsumedAttr *clone(ASTContext &C) const;
1637 void printPretty(raw_ostream &OS,
1638 const PrintingPolicy &Policy) const;
1639 const char *getSpelling() const;
1640
1641
1642 static bool classof(const Attr *A) { return A->getKind() == attr::CFConsumed; }
1643};
1644
1645class CFReturnsNotRetainedAttr : public InheritableAttr {
1646public:
1647 static CFReturnsNotRetainedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1648 auto *A = new (Ctx) CFReturnsNotRetainedAttr(Loc, Ctx, 0);
1649 A->setImplicit(true);
1650 return A;
1651 }
1652
1653 CFReturnsNotRetainedAttr(SourceRange R, ASTContext &Ctx
1654 , unsigned SI
1655 )
1656 : InheritableAttr(attr::CFReturnsNotRetained, R, SI, false, false)
1657 {
1658 }
1659
1660 CFReturnsNotRetainedAttr *clone(ASTContext &C) const;
1661 void printPretty(raw_ostream &OS,
1662 const PrintingPolicy &Policy) const;
1663 const char *getSpelling() const;
1664
1665
1666 static bool classof(const Attr *A) { return A->getKind() == attr::CFReturnsNotRetained; }
1667};
1668
1669class CFReturnsRetainedAttr : public InheritableAttr {
1670public:
1671 static CFReturnsRetainedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1672 auto *A = new (Ctx) CFReturnsRetainedAttr(Loc, Ctx, 0);
1673 A->setImplicit(true);
1674 return A;
1675 }
1676
1677 CFReturnsRetainedAttr(SourceRange R, ASTContext &Ctx
1678 , unsigned SI
1679 )
1680 : InheritableAttr(attr::CFReturnsRetained, R, SI, false, false)
1681 {
1682 }
1683
1684 CFReturnsRetainedAttr *clone(ASTContext &C) const;
1685 void printPretty(raw_ostream &OS,
1686 const PrintingPolicy &Policy) const;
1687 const char *getSpelling() const;
1688
1689
1690 static bool classof(const Attr *A) { return A->getKind() == attr::CFReturnsRetained; }
1691};
1692
1693class CFUnknownTransferAttr : public InheritableAttr {
1694public:
1695 static CFUnknownTransferAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1696 auto *A = new (Ctx) CFUnknownTransferAttr(Loc, Ctx, 0);
1697 A->setImplicit(true);
1698 return A;
1699 }
1700
1701 CFUnknownTransferAttr(SourceRange R, ASTContext &Ctx
1702 , unsigned SI
1703 )
1704 : InheritableAttr(attr::CFUnknownTransfer, R, SI, false, false)
1705 {
1706 }
1707
1708 CFUnknownTransferAttr *clone(ASTContext &C) const;
1709 void printPretty(raw_ostream &OS,
1710 const PrintingPolicy &Policy) const;
1711 const char *getSpelling() const;
1712
1713
1714 static bool classof(const Attr *A) { return A->getKind() == attr::CFUnknownTransfer; }
1715};
1716
1717class CUDAConstantAttr : public InheritableAttr {
1718public:
1719 static CUDAConstantAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1720 auto *A = new (Ctx) CUDAConstantAttr(Loc, Ctx, 0);
1721 A->setImplicit(true);
1722 return A;
1723 }
1724
1725 CUDAConstantAttr(SourceRange R, ASTContext &Ctx
1726 , unsigned SI
1727 )
1728 : InheritableAttr(attr::CUDAConstant, R, SI, false, false)
1729 {
1730 }
1731
1732 CUDAConstantAttr *clone(ASTContext &C) const;
1733 void printPretty(raw_ostream &OS,
1734 const PrintingPolicy &Policy) const;
1735 const char *getSpelling() const;
1736
1737
1738 static bool classof(const Attr *A) { return A->getKind() == attr::CUDAConstant; }
1739};
1740
1741class CUDADeviceAttr : public InheritableAttr {
1742public:
1743 static CUDADeviceAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1744 auto *A = new (Ctx) CUDADeviceAttr(Loc, Ctx, 0);
1745 A->setImplicit(true);
1746 return A;
1747 }
1748
1749 CUDADeviceAttr(SourceRange R, ASTContext &Ctx
1750 , unsigned SI
1751 )
1752 : InheritableAttr(attr::CUDADevice, R, SI, false, false)
1753 {
1754 }
1755
1756 CUDADeviceAttr *clone(ASTContext &C) const;
1757 void printPretty(raw_ostream &OS,
1758 const PrintingPolicy &Policy) const;
1759 const char *getSpelling() const;
1760
1761
1762 static bool classof(const Attr *A) { return A->getKind() == attr::CUDADevice; }
1763};
1764
1765class CUDAGlobalAttr : public InheritableAttr {
1766public:
1767 static CUDAGlobalAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1768 auto *A = new (Ctx) CUDAGlobalAttr(Loc, Ctx, 0);
1769 A->setImplicit(true);
1770 return A;
1771 }
1772
1773 CUDAGlobalAttr(SourceRange R, ASTContext &Ctx
1774 , unsigned SI
1775 )
1776 : InheritableAttr(attr::CUDAGlobal, R, SI, false, false)
1777 {
1778 }
1779
1780 CUDAGlobalAttr *clone(ASTContext &C) const;
1781 void printPretty(raw_ostream &OS,
1782 const PrintingPolicy &Policy) const;
1783 const char *getSpelling() const;
1784
1785
1786 static bool classof(const Attr *A) { return A->getKind() == attr::CUDAGlobal; }
1787};
1788
1789class CUDAHostAttr : public InheritableAttr {
1790public:
1791 static CUDAHostAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1792 auto *A = new (Ctx) CUDAHostAttr(Loc, Ctx, 0);
1793 A->setImplicit(true);
1794 return A;
1795 }
1796
1797 CUDAHostAttr(SourceRange R, ASTContext &Ctx
1798 , unsigned SI
1799 )
1800 : InheritableAttr(attr::CUDAHost, R, SI, false, false)
1801 {
1802 }
1803
1804 CUDAHostAttr *clone(ASTContext &C) const;
1805 void printPretty(raw_ostream &OS,
1806 const PrintingPolicy &Policy) const;
1807 const char *getSpelling() const;
1808
1809
1810 static bool classof(const Attr *A) { return A->getKind() == attr::CUDAHost; }
1811};
1812
1813class CUDAInvalidTargetAttr : public InheritableAttr {
1814public:
1815 static CUDAInvalidTargetAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1816 auto *A = new (Ctx) CUDAInvalidTargetAttr(Loc, Ctx, 0);
1817 A->setImplicit(true);
1818 return A;
1819 }
1820
1821 CUDAInvalidTargetAttr(SourceRange R, ASTContext &Ctx
1822 , unsigned SI
1823 )
1824 : InheritableAttr(attr::CUDAInvalidTarget, R, SI, false, false)
1825 {
1826 }
1827
1828 CUDAInvalidTargetAttr *clone(ASTContext &C) const;
1829 void printPretty(raw_ostream &OS,
1830 const PrintingPolicy &Policy) const;
1831 const char *getSpelling() const;
1832
1833
1834 static bool classof(const Attr *A) { return A->getKind() == attr::CUDAInvalidTarget; }
1835};
1836
1837class CUDALaunchBoundsAttr : public InheritableAttr {
1838Expr * maxThreads;
1839
1840Expr * minBlocks;
1841
1842public:
1843 static CUDALaunchBoundsAttr *CreateImplicit(ASTContext &Ctx, Expr * MaxThreads, Expr * MinBlocks, SourceRange Loc = SourceRange()) {
1844 auto *A = new (Ctx) CUDALaunchBoundsAttr(Loc, Ctx, MaxThreads, MinBlocks, 0);
1845 A->setImplicit(true);
1846 return A;
1847 }
1848
1849 CUDALaunchBoundsAttr(SourceRange R, ASTContext &Ctx
1850 , Expr * MaxThreads
1851 , Expr * MinBlocks
1852 , unsigned SI
1853 )
1854 : InheritableAttr(attr::CUDALaunchBounds, R, SI, false, false)
1855 , maxThreads(MaxThreads)
1856 , minBlocks(MinBlocks)
1857 {
1858 }
1859
1860 CUDALaunchBoundsAttr(SourceRange R, ASTContext &Ctx
1861 , Expr * MaxThreads
1862 , unsigned SI
1863 )
1864 : InheritableAttr(attr::CUDALaunchBounds, R, SI, false, false)
1865 , maxThreads(MaxThreads)
1866 , minBlocks()
1867 {
1868 }
1869
1870 CUDALaunchBoundsAttr *clone(ASTContext &C) const;
1871 void printPretty(raw_ostream &OS,
1872 const PrintingPolicy &Policy) const;
1873 const char *getSpelling() const;
1874 Expr * getMaxThreads() const {
1875 return maxThreads;
1876 }
1877
1878 Expr * getMinBlocks() const {
1879 return minBlocks;
1880 }
1881
1882
1883
1884 static bool classof(const Attr *A) { return A->getKind() == attr::CUDALaunchBounds; }
1885};
1886
1887class CUDASharedAttr : public InheritableAttr {
1888public:
1889 static CUDASharedAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1890 auto *A = new (Ctx) CUDASharedAttr(Loc, Ctx, 0);
1891 A->setImplicit(true);
1892 return A;
1893 }
1894
1895 CUDASharedAttr(SourceRange R, ASTContext &Ctx
1896 , unsigned SI
1897 )
1898 : InheritableAttr(attr::CUDAShared, R, SI, false, false)
1899 {
1900 }
1901
1902 CUDASharedAttr *clone(ASTContext &C) const;
1903 void printPretty(raw_ostream &OS,
1904 const PrintingPolicy &Policy) const;
1905 const char *getSpelling() const;
1906
1907
1908 static bool classof(const Attr *A) { return A->getKind() == attr::CUDAShared; }
1909};
1910
1911class CXX11NoReturnAttr : public InheritableAttr {
1912public:
1913 static CXX11NoReturnAttr *CreateImplicit(ASTContext &Ctx, SourceRange Loc = SourceRange()) {
1914 auto *A = new (Ctx) CXX11NoReturnAttr(Loc, Ctx, 0);
1915 A->setImplicit(true);
1916 return A;
1917 }
1918
1919 CXX11NoReturnAttr(SourceRange R, ASTContext &Ctx
1920 , unsigned SI
1921 )
1922 : InheritableAttr(attr::CXX11NoReturn, R, SI, false, false)
1923 {
1924 }
1925
1926 CXX11NoReturnAttr *clone(ASTContext &C) const;
1927 void printPretty(raw_ostream &OS,
1928 const PrintingPolicy &Policy) const;
1929 const char *getSpelling() const;
1930
1931
1932 static bool classof(const Attr *A) { return A->getKind() == attr::CXX11NoReturn; }
1933};
1934
1935class CallableWhenAttr : public InheritableAttr {
1936public:
1937 enum ConsumedState {
1938 Unknown,
1939 Consumed,
1940 Unconsumed
1941 };
1942private:
1943 unsigned callableStates_Size;
1944 ConsumedState *callableStates_;
1945
1946public:
1947 static CallableWhenAttr *CreateImplicit(ASTContext &Ctx, ConsumedState *CallableStates, unsigned CallableStatesSize, SourceRange Loc = SourceRange()) {
1948 auto *A = new (Ctx) CallableWhenAttr(Loc, Ctx, CallableStates, CallableStatesSize, 0);
1949 A->setImplicit(true);
1950 return A;
1951 }
1952
1953 CallableWhenAttr(SourceRange R, ASTContext &Ctx
1954 , ConsumedState *CallableStates, unsigned CallableStatesSize
1955 , unsigned SI