Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1 | //===- ASTReaderDecl.cpp - Decl Deserialization ---------------------------===// |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 9 | // This file implements the ASTReader::ReadDeclRecord method, which is the |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 10 | // entrypoint for loading a decl. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 14 | #include "ASTCommon.h" |
Benjamin Kramer | 89f0b2d | 2012-04-15 12:36:49 +0000 | [diff] [blame] | 15 | #include "ASTReaderInternals.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 16 | #include "clang/AST/ASTContext.h" |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 17 | #include "clang/AST/Attr.h" |
| 18 | #include "clang/AST/AttrIterator.h" |
| 19 | #include "clang/AST/Decl.h" |
| 20 | #include "clang/AST/DeclBase.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 21 | #include "clang/AST/DeclCXX.h" |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 22 | #include "clang/AST/DeclFriend.h" |
| 23 | #include "clang/AST/DeclObjC.h" |
| 24 | #include "clang/AST/DeclOpenMP.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 25 | #include "clang/AST/DeclTemplate.h" |
| 26 | #include "clang/AST/DeclVisitor.h" |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 27 | #include "clang/AST/DeclarationName.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 28 | #include "clang/AST/Expr.h" |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 29 | #include "clang/AST/ExternalASTSource.h" |
| 30 | #include "clang/AST/LambdaCapture.h" |
| 31 | #include "clang/AST/NestedNameSpecifier.h" |
Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 32 | #include "clang/AST/OpenMPClause.h" |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 33 | #include "clang/AST/Redeclarable.h" |
| 34 | #include "clang/AST/Stmt.h" |
| 35 | #include "clang/AST/TemplateBase.h" |
| 36 | #include "clang/AST/Type.h" |
| 37 | #include "clang/AST/UnresolvedSet.h" |
| 38 | #include "clang/Basic/AttrKinds.h" |
| 39 | #include "clang/Basic/ExceptionSpecificationType.h" |
| 40 | #include "clang/Basic/IdentifierTable.h" |
| 41 | #include "clang/Basic/LLVM.h" |
| 42 | #include "clang/Basic/Lambda.h" |
| 43 | #include "clang/Basic/LangOptions.h" |
| 44 | #include "clang/Basic/Linkage.h" |
| 45 | #include "clang/Basic/Module.h" |
| 46 | #include "clang/Basic/PragmaKinds.h" |
| 47 | #include "clang/Basic/SourceLocation.h" |
| 48 | #include "clang/Basic/Specifiers.h" |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 49 | #include "clang/Sema/IdentifierResolver.h" |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 50 | #include "clang/Serialization/ASTBitCodes.h" |
Mehdi Amini | 9670f84 | 2016-07-18 19:02:11 +0000 | [diff] [blame] | 51 | #include "clang/Serialization/ASTReader.h" |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 52 | #include "clang/Serialization/ContinuousRangeMap.h" |
| 53 | #include "clang/Serialization/Module.h" |
| 54 | #include "llvm/ADT/DenseMap.h" |
| 55 | #include "llvm/ADT/FoldingSet.h" |
| 56 | #include "llvm/ADT/STLExtras.h" |
| 57 | #include "llvm/ADT/SmallPtrSet.h" |
| 58 | #include "llvm/ADT/SmallVector.h" |
| 59 | #include "llvm/ADT/iterator_range.h" |
Francis Visoiu Mistrih | e030827 | 2019-07-03 22:40:07 +0000 | [diff] [blame] | 60 | #include "llvm/Bitstream/BitstreamReader.h" |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 61 | #include "llvm/Support/Casting.h" |
| 62 | #include "llvm/Support/ErrorHandling.h" |
Argyrios Kyrtzidis | 0f7d7ab | 2012-05-04 01:49:36 +0000 | [diff] [blame] | 63 | #include "llvm/Support/SaveAndRestore.h" |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 64 | #include <algorithm> |
| 65 | #include <cassert> |
| 66 | #include <cstdint> |
| 67 | #include <cstring> |
| 68 | #include <string> |
| 69 | #include <utility> |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 70 | |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 71 | using namespace clang; |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 72 | using namespace serialization; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 73 | |
| 74 | //===----------------------------------------------------------------------===// |
| 75 | // Declaration deserialization |
| 76 | //===----------------------------------------------------------------------===// |
| 77 | |
Argyrios Kyrtzidis | 74d28bd | 2010-06-29 22:47:00 +0000 | [diff] [blame] | 78 | namespace clang { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 79 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 80 | class ASTDeclReader : public DeclVisitor<ASTDeclReader, void> { |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 81 | ASTReader &Reader; |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 82 | ASTRecordReader &Record; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 83 | ASTReader::RecordLocation Loc; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 84 | const DeclID ThisDeclID; |
Richard Smith | cb34bd3 | 2016-03-27 07:28:06 +0000 | [diff] [blame] | 85 | const SourceLocation ThisDeclLoc; |
Vassil Vassilev | 6565dfc | 2016-02-26 10:43:34 +0000 | [diff] [blame] | 86 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 87 | using RecordData = ASTReader::RecordData; |
| 88 | |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 89 | TypeID DeferredTypeID = 0; |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 90 | unsigned AnonymousDeclNumber; |
| 91 | GlobalDeclID NamedDeclForTagDecl = 0; |
| 92 | IdentifierInfo *TypedefNameForLinkage = nullptr; |
| 93 | |
| 94 | bool HasPendingBody = false; |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 95 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 96 | ///A flag to carry the information for a decl from the entity is |
Vassil Vassilev | 928c825 | 2016-04-28 14:13:28 +0000 | [diff] [blame] | 97 | /// used. We use it to delay the marking of the canonical decl as used until |
| 98 | /// the entire declaration is deserialized and merged. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 99 | bool IsDeclMarkedUsed = false; |
Vassil Vassilev | 928c825 | 2016-04-28 14:13:28 +0000 | [diff] [blame] | 100 | |
Sebastian Redl | c67764e | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 101 | uint64_t GetCurrentCursorOffset(); |
Vassil Vassilev | 6565dfc | 2016-02-26 10:43:34 +0000 | [diff] [blame] | 102 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 103 | uint64_t ReadLocalOffset() { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 104 | uint64_t LocalOffset = Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 105 | assert(LocalOffset < Loc.Offset && "offset point after current record"); |
| 106 | return LocalOffset ? Loc.Offset - LocalOffset : 0; |
Richard Smith | e37e9f4 | 2016-03-25 01:17:43 +0000 | [diff] [blame] | 107 | } |
| 108 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 109 | uint64_t ReadGlobalOffset() { |
| 110 | uint64_t Local = ReadLocalOffset(); |
| 111 | return Local ? Record.getGlobalBitOffset(Local) : 0; |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 112 | } |
| 113 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 114 | SourceLocation ReadSourceLocation() { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 115 | return Record.readSourceLocation(); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 116 | } |
Vassil Vassilev | 6565dfc | 2016-02-26 10:43:34 +0000 | [diff] [blame] | 117 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 118 | SourceRange ReadSourceRange() { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 119 | return Record.readSourceRange(); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 120 | } |
Vassil Vassilev | 6565dfc | 2016-02-26 10:43:34 +0000 | [diff] [blame] | 121 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 122 | TypeSourceInfo *GetTypeSourceInfo() { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 123 | return Record.getTypeSourceInfo(); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 124 | } |
Vassil Vassilev | 6565dfc | 2016-02-26 10:43:34 +0000 | [diff] [blame] | 125 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 126 | serialization::DeclID ReadDeclID() { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 127 | return Record.readDeclID(); |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 128 | } |
Richard Smith | 0b88437 | 2015-02-27 00:25:58 +0000 | [diff] [blame] | 129 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 130 | std::string ReadString() { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 131 | return Record.readString(); |
Nico Weber | 6622029 | 2016-03-02 17:28:48 +0000 | [diff] [blame] | 132 | } |
| 133 | |
Richard Smith | 0b88437 | 2015-02-27 00:25:58 +0000 | [diff] [blame] | 134 | void ReadDeclIDList(SmallVectorImpl<DeclID> &IDs) { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 135 | for (unsigned I = 0, Size = Record.readInt(); I != Size; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 136 | IDs.push_back(ReadDeclID()); |
Richard Smith | 0b88437 | 2015-02-27 00:25:58 +0000 | [diff] [blame] | 137 | } |
| 138 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 139 | Decl *ReadDecl() { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 140 | return Record.readDecl(); |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | template<typename T> |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 144 | T *ReadDeclAs() { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 145 | return Record.readDeclAs<T>(); |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 146 | } |
| 147 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 148 | void ReadQualifierInfo(QualifierInfo &Info) { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 149 | Record.readQualifierInfo(Info); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 150 | } |
Sebastian Redl | c67764e | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 151 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 152 | void ReadDeclarationNameLoc(DeclarationNameLoc &DNLoc, DeclarationName Name) { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 153 | Record.readDeclarationNameLoc(DNLoc, Name); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | serialization::SubmoduleID readSubmoduleID() { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 157 | if (Record.getIdx() == Record.size()) |
Douglas Gregor | cf68c58 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 158 | return 0; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 159 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 160 | return Record.getGlobalSubmoduleID(Record.readInt()); |
Douglas Gregor | cf68c58 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 161 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 162 | |
| 163 | Module *readModule() { |
| 164 | return Record.getSubmodule(readSubmoduleID()); |
Douglas Gregor | ba34552 | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 165 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 166 | |
Richard Smith | 2a9e5c5 | 2015-02-03 03:32:14 +0000 | [diff] [blame] | 167 | void ReadCXXRecordDefinition(CXXRecordDecl *D, bool Update); |
David Blaikie | 1ac9c98 | 2017-04-11 21:13:37 +0000 | [diff] [blame] | 168 | void ReadCXXDefinitionData(struct CXXRecordDecl::DefinitionData &Data, |
| 169 | const CXXRecordDecl *D); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 170 | void MergeDefinitionData(CXXRecordDecl *D, |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 171 | struct CXXRecordDecl::DefinitionData &&NewDD); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 172 | void ReadObjCDefinitionData(struct ObjCInterfaceDecl::DefinitionData &Data); |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 173 | void MergeDefinitionData(ObjCInterfaceDecl *D, |
| 174 | struct ObjCInterfaceDecl::DefinitionData &&NewDD); |
Graydon Hoare | e0a6835 | 2017-06-28 18:36:27 +0000 | [diff] [blame] | 175 | void ReadObjCDefinitionData(struct ObjCProtocolDecl::DefinitionData &Data); |
| 176 | void MergeDefinitionData(ObjCProtocolDecl *D, |
| 177 | struct ObjCProtocolDecl::DefinitionData &&NewDD); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 178 | |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 179 | static DeclContext *getPrimaryDCForAnonymousDecl(DeclContext *LexicalDC); |
| 180 | |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 181 | static NamedDecl *getAnonymousDeclForMerging(ASTReader &Reader, |
| 182 | DeclContext *DC, |
| 183 | unsigned Index); |
| 184 | static void setAnonymousDeclForMerging(ASTReader &Reader, DeclContext *DC, |
| 185 | unsigned Index, NamedDecl *D); |
| 186 | |
Richard Smith | 0144f51 | 2015-08-22 02:09:38 +0000 | [diff] [blame] | 187 | /// Results from loading a RedeclarableDecl. |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 188 | class RedeclarableResult { |
Richard Smith | 5a4737c | 2015-02-06 02:42:59 +0000 | [diff] [blame] | 189 | Decl *MergeWith; |
Alexander Shaposhnikov | fbc4d68 | 2016-09-24 04:21:53 +0000 | [diff] [blame] | 190 | GlobalDeclID FirstID; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 191 | bool IsKeyDecl; |
Richard Smith | c89bb9d | 2015-02-25 01:11:29 +0000 | [diff] [blame] | 192 | |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 193 | public: |
Alexander Shaposhnikov | fbc4d68 | 2016-09-24 04:21:53 +0000 | [diff] [blame] | 194 | RedeclarableResult(Decl *MergeWith, GlobalDeclID FirstID, bool IsKeyDecl) |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 195 | : MergeWith(MergeWith), FirstID(FirstID), IsKeyDecl(IsKeyDecl) {} |
Richard Smith | 9b88a4c | 2015-07-27 05:40:23 +0000 | [diff] [blame] | 196 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 197 | /// Retrieve the first ID. |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 198 | GlobalDeclID getFirstID() const { return FirstID; } |
Richard Smith | 5a4737c | 2015-02-06 02:42:59 +0000 | [diff] [blame] | 199 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 200 | /// Is this declaration a key declaration? |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 201 | bool isKeyDecl() const { return IsKeyDecl; } |
| 202 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 203 | /// Get a known declaration that this should be merged with, if |
Richard Smith | 5a4737c | 2015-02-06 02:42:59 +0000 | [diff] [blame] | 204 | /// any. |
| 205 | Decl *getKnownMergeTarget() const { return MergeWith; } |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 206 | }; |
Douglas Gregor | fe732d5 | 2013-01-21 16:16:40 +0000 | [diff] [blame] | 207 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 208 | /// Class used to capture the result of searching for an existing |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 209 | /// declaration of a specific kind and name, along with the ability |
| 210 | /// to update the place where this result was found (the declaration |
| 211 | /// chain hanging off an identifier or the DeclContext we searched in) |
| 212 | /// if requested. |
| 213 | class FindExistingResult { |
| 214 | ASTReader &Reader; |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 215 | NamedDecl *New = nullptr; |
| 216 | NamedDecl *Existing = nullptr; |
| 217 | bool AddResult = false; |
| 218 | unsigned AnonymousDeclNumber = 0; |
| 219 | IdentifierInfo *TypedefNameForLinkage = nullptr; |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 220 | |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 221 | public: |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 222 | FindExistingResult(ASTReader &Reader) : Reader(Reader) {} |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 223 | |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 224 | FindExistingResult(ASTReader &Reader, NamedDecl *New, NamedDecl *Existing, |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 225 | unsigned AnonymousDeclNumber, |
| 226 | IdentifierInfo *TypedefNameForLinkage) |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 227 | : Reader(Reader), New(New), Existing(Existing), AddResult(true), |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 228 | AnonymousDeclNumber(AnonymousDeclNumber), |
| 229 | TypedefNameForLinkage(TypedefNameForLinkage) {} |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 230 | |
Benjamin Kramer | b6aadc1 | 2016-08-06 12:45:16 +0000 | [diff] [blame] | 231 | FindExistingResult(FindExistingResult &&Other) |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 232 | : Reader(Other.Reader), New(Other.New), Existing(Other.Existing), |
| 233 | AddResult(Other.AddResult), |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 234 | AnonymousDeclNumber(Other.AnonymousDeclNumber), |
| 235 | TypedefNameForLinkage(Other.TypedefNameForLinkage) { |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 236 | Other.AddResult = false; |
| 237 | } |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 238 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 239 | FindExistingResult &operator=(FindExistingResult &&) = delete; |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 240 | ~FindExistingResult(); |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 241 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 242 | /// Suppress the addition of this result into the known set of |
Douglas Gregor | 2009cee | 2012-01-03 22:46:00 +0000 | [diff] [blame] | 243 | /// names. |
| 244 | void suppress() { AddResult = false; } |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 245 | |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 246 | operator NamedDecl*() const { return Existing; } |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 247 | |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 248 | template<typename T> |
| 249 | operator T*() const { return dyn_cast_or_null<T>(Existing); } |
| 250 | }; |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 251 | |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 252 | static DeclContext *getPrimaryContextForMerging(ASTReader &Reader, |
| 253 | DeclContext *DC); |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 254 | FindExistingResult findExisting(NamedDecl *D); |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 255 | |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 256 | public: |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 257 | ASTDeclReader(ASTReader &Reader, ASTRecordReader &Record, |
| 258 | ASTReader::RecordLocation Loc, |
| 259 | DeclID thisDeclID, SourceLocation ThisDeclLoc) |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 260 | : Reader(Reader), Record(Record), Loc(Loc), ThisDeclID(thisDeclID), |
| 261 | ThisDeclLoc(ThisDeclLoc) {} |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 262 | |
Vassil Vassilev | 7d26462 | 2017-06-30 22:40:17 +0000 | [diff] [blame] | 263 | template <typename T> static |
| 264 | void AddLazySpecializations(T *D, |
| 265 | SmallVectorImpl<serialization::DeclID>& IDs) { |
| 266 | if (IDs.empty()) |
| 267 | return; |
| 268 | |
| 269 | // FIXME: We should avoid this pattern of getting the ASTContext. |
| 270 | ASTContext &C = D->getASTContext(); |
| 271 | |
| 272 | auto *&LazySpecializations = D->getCommonPtr()->LazySpecializations; |
| 273 | |
| 274 | if (auto &Old = LazySpecializations) { |
| 275 | IDs.insert(IDs.end(), Old + 1, Old + 1 + Old[0]); |
Fangrui Song | 55fab26 | 2018-09-26 22:16:28 +0000 | [diff] [blame] | 276 | llvm::sort(IDs); |
Vassil Vassilev | 7d26462 | 2017-06-30 22:40:17 +0000 | [diff] [blame] | 277 | IDs.erase(std::unique(IDs.begin(), IDs.end()), IDs.end()); |
| 278 | } |
| 279 | |
| 280 | auto *Result = new (C) serialization::DeclID[1 + IDs.size()]; |
| 281 | *Result = IDs.size(); |
| 282 | std::copy(IDs.begin(), IDs.end(), Result + 1); |
| 283 | |
| 284 | LazySpecializations = Result; |
| 285 | } |
| 286 | |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 287 | template <typename DeclT> |
Richard Smith | c3a5325 | 2015-02-28 05:57:02 +0000 | [diff] [blame] | 288 | static Decl *getMostRecentDeclImpl(Redeclarable<DeclT> *D); |
| 289 | static Decl *getMostRecentDeclImpl(...); |
| 290 | static Decl *getMostRecentDecl(Decl *D); |
| 291 | |
| 292 | template <typename DeclT> |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 293 | static void attachPreviousDeclImpl(ASTReader &Reader, |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 294 | Redeclarable<DeclT> *D, Decl *Previous, |
| 295 | Decl *Canon); |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 296 | static void attachPreviousDeclImpl(ASTReader &Reader, ...); |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 297 | static void attachPreviousDecl(ASTReader &Reader, Decl *D, Decl *Previous, |
| 298 | Decl *Canon); |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 299 | |
| 300 | template <typename DeclT> |
| 301 | static void attachLatestDeclImpl(Redeclarable<DeclT> *D, Decl *Latest); |
| 302 | static void attachLatestDeclImpl(...); |
Douglas Gregor | 05f1035 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 303 | static void attachLatestDecl(Decl *D, Decl *latest); |
Argyrios Kyrtzidis | 9fdd254 | 2011-02-12 07:50:47 +0000 | [diff] [blame] | 304 | |
Richard Smith | 851072e | 2014-05-19 20:59:20 +0000 | [diff] [blame] | 305 | template <typename DeclT> |
| 306 | static void markIncompleteDeclChainImpl(Redeclarable<DeclT> *D); |
| 307 | static void markIncompleteDeclChainImpl(...); |
| 308 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 309 | /// Determine whether this declaration has a pending body. |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 310 | bool hasPendingBody() const { return HasPendingBody; } |
| 311 | |
David Blaikie | ac4345c | 2017-02-12 18:45:31 +0000 | [diff] [blame] | 312 | void ReadFunctionDefinition(FunctionDecl *FD); |
Argyrios Kyrtzidis | 318b0e7 | 2010-07-02 11:55:01 +0000 | [diff] [blame] | 313 | void Visit(Decl *D); |
| 314 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 315 | void UpdateDecl(Decl *D, SmallVectorImpl<serialization::DeclID> &); |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 316 | |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 317 | static void setNextObjCCategory(ObjCCategoryDecl *Cat, |
| 318 | ObjCCategoryDecl *Next) { |
| 319 | Cat->NextClassCategory = Next; |
| 320 | } |
| 321 | |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 322 | void VisitDecl(Decl *D); |
Nico Weber | 6622029 | 2016-03-02 17:28:48 +0000 | [diff] [blame] | 323 | void VisitPragmaCommentDecl(PragmaCommentDecl *D); |
Nico Weber | cbbaeb1 | 2016-03-02 19:28:54 +0000 | [diff] [blame] | 324 | void VisitPragmaDetectMismatchDecl(PragmaDetectMismatchDecl *D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 325 | void VisitTranslationUnitDecl(TranslationUnitDecl *TU); |
| 326 | void VisitNamedDecl(NamedDecl *ND); |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 327 | void VisitLabelDecl(LabelDecl *LD); |
Douglas Gregor | e31bbd9 | 2010-02-21 18:22:14 +0000 | [diff] [blame] | 328 | void VisitNamespaceDecl(NamespaceDecl *D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 329 | void VisitUsingDirectiveDecl(UsingDirectiveDecl *D); |
| 330 | void VisitNamespaceAliasDecl(NamespaceAliasDecl *D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 331 | void VisitTypeDecl(TypeDecl *TD); |
Richard Smith | 43ccec8e | 2014-08-26 03:52:16 +0000 | [diff] [blame] | 332 | RedeclarableResult VisitTypedefNameDecl(TypedefNameDecl *TD); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 333 | void VisitTypedefDecl(TypedefDecl *TD); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 334 | void VisitTypeAliasDecl(TypeAliasDecl *TD); |
Argyrios Kyrtzidis | bd8ac8c | 2010-06-30 08:49:30 +0000 | [diff] [blame] | 335 | void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D); |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 336 | RedeclarableResult VisitTagDecl(TagDecl *TD); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 337 | void VisitEnumDecl(EnumDecl *ED); |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 338 | RedeclarableResult VisitRecordDeclImpl(RecordDecl *RD); |
| 339 | void VisitRecordDecl(RecordDecl *RD) { VisitRecordDeclImpl(RD); } |
| 340 | RedeclarableResult VisitCXXRecordDeclImpl(CXXRecordDecl *D); |
| 341 | void VisitCXXRecordDecl(CXXRecordDecl *D) { VisitCXXRecordDeclImpl(D); } |
| 342 | RedeclarableResult VisitClassTemplateSpecializationDeclImpl( |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 343 | ClassTemplateSpecializationDecl *D); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 344 | |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 345 | void VisitClassTemplateSpecializationDecl( |
| 346 | ClassTemplateSpecializationDecl *D) { |
| 347 | VisitClassTemplateSpecializationDeclImpl(D); |
| 348 | } |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 349 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 350 | void VisitClassTemplatePartialSpecializationDecl( |
| 351 | ClassTemplatePartialSpecializationDecl *D); |
Sebastian Redl | b744863 | 2011-08-31 13:59:56 +0000 | [diff] [blame] | 352 | void VisitClassScopeFunctionSpecializationDecl( |
| 353 | ClassScopeFunctionSpecializationDecl *D); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 354 | RedeclarableResult |
| 355 | VisitVarTemplateSpecializationDeclImpl(VarTemplateSpecializationDecl *D); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 356 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 357 | void VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D) { |
| 358 | VisitVarTemplateSpecializationDeclImpl(D); |
| 359 | } |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 360 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 361 | void VisitVarTemplatePartialSpecializationDecl( |
| 362 | VarTemplatePartialSpecializationDecl *D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 363 | void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 364 | void VisitValueDecl(ValueDecl *VD); |
| 365 | void VisitEnumConstantDecl(EnumConstantDecl *ECD); |
Argyrios Kyrtzidis | bd8ac8c | 2010-06-30 08:49:30 +0000 | [diff] [blame] | 366 | void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); |
Argyrios Kyrtzidis | 560ac97 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 367 | void VisitDeclaratorDecl(DeclaratorDecl *DD); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 368 | void VisitFunctionDecl(FunctionDecl *FD); |
Richard Smith | bc49120 | 2017-02-17 20:05:37 +0000 | [diff] [blame] | 369 | void VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *GD); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 370 | void VisitCXXMethodDecl(CXXMethodDecl *D); |
| 371 | void VisitCXXConstructorDecl(CXXConstructorDecl *D); |
| 372 | void VisitCXXDestructorDecl(CXXDestructorDecl *D); |
| 373 | void VisitCXXConversionDecl(CXXConversionDecl *D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 374 | void VisitFieldDecl(FieldDecl *FD); |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 375 | void VisitMSPropertyDecl(MSPropertyDecl *FD); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 376 | void VisitIndirectFieldDecl(IndirectFieldDecl *FD); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 377 | RedeclarableResult VisitVarDeclImpl(VarDecl *D); |
| 378 | void VisitVarDecl(VarDecl *VD) { VisitVarDeclImpl(VD); } |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 379 | void VisitImplicitParamDecl(ImplicitParamDecl *PD); |
| 380 | void VisitParmVarDecl(ParmVarDecl *PD); |
Richard Smith | 7b76d81 | 2016-08-12 02:21:25 +0000 | [diff] [blame] | 381 | void VisitDecompositionDecl(DecompositionDecl *DD); |
| 382 | void VisitBindingDecl(BindingDecl *BD); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 383 | void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 384 | DeclID VisitTemplateDecl(TemplateDecl *D); |
Saar Raz | d7aae33 | 2019-07-10 21:25:49 +0000 | [diff] [blame] | 385 | void VisitConceptDecl(ConceptDecl *D); |
Douglas Gregor | 5407920 | 2012-01-06 22:05:37 +0000 | [diff] [blame] | 386 | RedeclarableResult VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 387 | void VisitClassTemplateDecl(ClassTemplateDecl *D); |
David Majnemer | d9b1a4f | 2015-11-04 03:40:30 +0000 | [diff] [blame] | 388 | void VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 389 | void VisitVarTemplateDecl(VarTemplateDecl *D); |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 390 | void VisitFunctionTemplateDecl(FunctionTemplateDecl *D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 391 | void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 392 | void VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D); |
Argyrios Kyrtzidis | 41d4562 | 2010-06-20 14:40:59 +0000 | [diff] [blame] | 393 | void VisitUsingDecl(UsingDecl *D); |
Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 394 | void VisitUsingPackDecl(UsingPackDecl *D); |
Argyrios Kyrtzidis | 41d4562 | 2010-06-20 14:40:59 +0000 | [diff] [blame] | 395 | void VisitUsingShadowDecl(UsingShadowDecl *D); |
Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 396 | void VisitConstructorUsingShadowDecl(ConstructorUsingShadowDecl *D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 397 | void VisitLinkageSpecDecl(LinkageSpecDecl *D); |
Richard Smith | 8df390f | 2016-09-08 23:14:54 +0000 | [diff] [blame] | 398 | void VisitExportDecl(ExportDecl *D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 399 | void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD); |
Douglas Gregor | ba34552 | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 400 | void VisitImportDecl(ImportDecl *D); |
Abramo Bagnara | d734058 | 2010-06-05 05:09:32 +0000 | [diff] [blame] | 401 | void VisitAccessSpecDecl(AccessSpecDecl *D); |
Argyrios Kyrtzidis | 74d28bd | 2010-06-29 22:47:00 +0000 | [diff] [blame] | 402 | void VisitFriendDecl(FriendDecl *D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 403 | void VisitFriendTemplateDecl(FriendTemplateDecl *D); |
| 404 | void VisitStaticAssertDecl(StaticAssertDecl *D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 405 | void VisitBlockDecl(BlockDecl *BD); |
Tareq A. Siraj | 6dfa25a | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 406 | void VisitCapturedDecl(CapturedDecl *CD); |
Michael Han | 8432435 | 2013-02-22 17:15:32 +0000 | [diff] [blame] | 407 | void VisitEmptyDecl(EmptyDecl *D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 408 | |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 409 | std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC); |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 410 | |
| 411 | template<typename T> |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 412 | RedeclarableResult VisitRedeclarable(Redeclarable<T> *D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 413 | |
Douglas Gregor | 2c46b5b | 2012-01-03 17:27:13 +0000 | [diff] [blame] | 414 | template<typename T> |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 415 | void mergeRedeclarable(Redeclarable<T> *D, RedeclarableResult &Redecl, |
| 416 | DeclID TemplatePatternID = 0); |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 417 | |
| 418 | template<typename T> |
| 419 | void mergeRedeclarable(Redeclarable<T> *D, T *Existing, |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 420 | RedeclarableResult &Redecl, |
| 421 | DeclID TemplatePatternID = 0); |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 422 | |
Richard Smith | 0b87e07 | 2013-10-07 08:02:11 +0000 | [diff] [blame] | 423 | template<typename T> |
| 424 | void mergeMergeable(Mergeable<T> *D); |
| 425 | |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 426 | void mergeTemplatePattern(RedeclarableTemplateDecl *D, |
| 427 | RedeclarableTemplateDecl *Existing, |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 428 | DeclID DsID, bool IsKeyDecl); |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 429 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 430 | ObjCTypeParamList *ReadObjCTypeParamList(); |
| 431 | |
Alexis Hunt | ed05325 | 2010-05-30 07:21:58 +0000 | [diff] [blame] | 432 | // FIXME: Reorder according to DeclNodes.td? |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 433 | void VisitObjCMethodDecl(ObjCMethodDecl *D); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 434 | void VisitObjCTypeParamDecl(ObjCTypeParamDecl *D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 435 | void VisitObjCContainerDecl(ObjCContainerDecl *D); |
| 436 | void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); |
| 437 | void VisitObjCIvarDecl(ObjCIvarDecl *D); |
| 438 | void VisitObjCProtocolDecl(ObjCProtocolDecl *D); |
| 439 | void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 440 | void VisitObjCCategoryDecl(ObjCCategoryDecl *D); |
| 441 | void VisitObjCImplDecl(ObjCImplDecl *D); |
| 442 | void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); |
| 443 | void VisitObjCImplementationDecl(ObjCImplementationDecl *D); |
| 444 | void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D); |
| 445 | void VisitObjCPropertyDecl(ObjCPropertyDecl *D); |
| 446 | void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 447 | void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D); |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 448 | void VisitOMPAllocateDecl(OMPAllocateDecl *D); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 449 | void VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D); |
Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 450 | void VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D); |
Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 451 | void VisitOMPRequiresDecl(OMPRequiresDecl *D); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 452 | void VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 453 | }; |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 454 | |
| 455 | } // namespace clang |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 456 | |
Richard Smith | 86dfc1e | 2015-06-18 22:07:00 +0000 | [diff] [blame] | 457 | namespace { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 458 | |
Richard Smith | 86dfc1e | 2015-06-18 22:07:00 +0000 | [diff] [blame] | 459 | /// Iterator over the redeclarations of a declaration that have already |
| 460 | /// been merged into the same redeclaration chain. |
| 461 | template<typename DeclT> |
| 462 | class MergedRedeclIterator { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 463 | DeclT *Start; |
| 464 | DeclT *Canonical = nullptr; |
| 465 | DeclT *Current = nullptr; |
| 466 | |
Richard Smith | 86dfc1e | 2015-06-18 22:07:00 +0000 | [diff] [blame] | 467 | public: |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 468 | MergedRedeclIterator() = default; |
| 469 | MergedRedeclIterator(DeclT *Start) : Start(Start), Current(Start) {} |
Richard Smith | 86dfc1e | 2015-06-18 22:07:00 +0000 | [diff] [blame] | 470 | |
| 471 | DeclT *operator*() { return Current; } |
| 472 | |
| 473 | MergedRedeclIterator &operator++() { |
| 474 | if (Current->isFirstDecl()) { |
| 475 | Canonical = Current; |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 476 | Current = Current->getMostRecentDecl(); |
Richard Smith | 86dfc1e | 2015-06-18 22:07:00 +0000 | [diff] [blame] | 477 | } else |
| 478 | Current = Current->getPreviousDecl(); |
| 479 | |
| 480 | // If we started in the merged portion, we'll reach our start position |
| 481 | // eventually. Otherwise, we'll never reach it, but the second declaration |
| 482 | // we reached was the canonical declaration, so stop when we see that one |
| 483 | // again. |
| 484 | if (Current == Start || Current == Canonical) |
| 485 | Current = nullptr; |
| 486 | return *this; |
| 487 | } |
| 488 | |
| 489 | friend bool operator!=(const MergedRedeclIterator &A, |
| 490 | const MergedRedeclIterator &B) { |
| 491 | return A.Current != B.Current; |
| 492 | } |
| 493 | }; |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 494 | |
| 495 | } // namespace |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 496 | |
Benjamin Kramer | a0a13c3 | 2016-08-06 11:21:04 +0000 | [diff] [blame] | 497 | template <typename DeclT> |
| 498 | static llvm::iterator_range<MergedRedeclIterator<DeclT>> |
| 499 | merged_redecls(DeclT *D) { |
Craig Topper | 59c2ada | 2015-12-06 05:07:12 +0000 | [diff] [blame] | 500 | return llvm::make_range(MergedRedeclIterator<DeclT>(D), |
| 501 | MergedRedeclIterator<DeclT>()); |
Richard Smith | 86dfc1e | 2015-06-18 22:07:00 +0000 | [diff] [blame] | 502 | } |
| 503 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 504 | uint64_t ASTDeclReader::GetCurrentCursorOffset() { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 505 | return Loc.F->DeclsCursor.GetCurrentBitNo() + Loc.F->GlobalBitOffset; |
Sebastian Redl | c67764e | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 506 | } |
| 507 | |
David Blaikie | ac4345c | 2017-02-12 18:45:31 +0000 | [diff] [blame] | 508 | void ASTDeclReader::ReadFunctionDefinition(FunctionDecl *FD) { |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 509 | if (Record.readInt()) |
Richard Smith | a465362 | 2017-09-06 20:01:14 +0000 | [diff] [blame] | 510 | Reader.DefinitionSource[FD] = Loc.F->Kind == ModuleKind::MK_MainFile; |
David Blaikie | ac4345c | 2017-02-12 18:45:31 +0000 | [diff] [blame] | 511 | if (auto *CD = dyn_cast<CXXConstructorDecl>(FD)) { |
Erich Keane | 9c66506 | 2018-08-01 21:02:40 +0000 | [diff] [blame] | 512 | CD->setNumCtorInitializers(Record.readInt()); |
| 513 | if (CD->getNumCtorInitializers()) |
David Blaikie | ac4345c | 2017-02-12 18:45:31 +0000 | [diff] [blame] | 514 | CD->CtorInitializers = ReadGlobalOffset(); |
| 515 | } |
| 516 | // Store the offset of the body so we can lazily load it later. |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 517 | Reader.PendingBodies[FD] = GetCurrentCursorOffset(); |
| 518 | HasPendingBody = true; |
David Blaikie | ac4345c | 2017-02-12 18:45:31 +0000 | [diff] [blame] | 519 | } |
| 520 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 521 | void ASTDeclReader::Visit(Decl *D) { |
| 522 | DeclVisitor<ASTDeclReader, void>::Visit(D); |
Argyrios Kyrtzidis | 318b0e7 | 2010-07-02 11:55:01 +0000 | [diff] [blame] | 523 | |
Vassil Vassilev | 928c825 | 2016-04-28 14:13:28 +0000 | [diff] [blame] | 524 | // At this point we have deserialized and merged the decl and it is safe to |
| 525 | // update its canonical decl to signal that the entire entity is used. |
| 526 | D->getCanonicalDecl()->Used |= IsDeclMarkedUsed; |
| 527 | IsDeclMarkedUsed = false; |
| 528 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 529 | if (auto *DD = dyn_cast<DeclaratorDecl>(D)) { |
Richard Smith | c23d734 | 2018-06-29 20:46:25 +0000 | [diff] [blame] | 530 | if (auto *TInfo = DD->getTypeSourceInfo()) |
| 531 | Record.readTypeLoc(TInfo->getTypeLoc()); |
Jonathan D. Turner | 205c7d5 | 2011-06-03 23:11:16 +0000 | [diff] [blame] | 532 | } |
| 533 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 534 | if (auto *TD = dyn_cast<TypeDecl>(D)) { |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 535 | // We have a fully initialized TypeDecl. Read its type now. |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 536 | TD->setTypeForDecl(Reader.GetType(DeferredTypeID).getTypePtrOrNull()); |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 537 | |
| 538 | // If this is a tag declaration with a typedef name for linkage, it's safe |
| 539 | // to load that typedef now. |
| 540 | if (NamedDeclForTagDecl) |
David Majnemer | 0035052 | 2015-08-31 18:48:39 +0000 | [diff] [blame] | 541 | cast<TagDecl>(D)->TypedefNameDeclOrQualifier = |
| 542 | cast<TypedefNameDecl>(Reader.GetDecl(NamedDeclForTagDecl)); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 543 | } else if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) { |
Douglas Gregor | ab1ec82e | 2011-12-16 03:12:41 +0000 | [diff] [blame] | 544 | // if we have a fully initialized TypeDecl, we can safely read its type now. |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 545 | ID->TypeForDecl = Reader.GetType(DeferredTypeID).getTypePtrOrNull(); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 546 | } else if (auto *FD = dyn_cast<FunctionDecl>(D)) { |
Argyrios Kyrtzidis | 3357516 | 2010-07-02 15:58:43 +0000 | [diff] [blame] | 547 | // FunctionDecl's body was written last after all other Stmts/Exprs. |
Douglas Gregor | 559458c | 2012-10-03 18:34:48 +0000 | [diff] [blame] | 548 | // We only read it if FD doesn't already have a body (e.g., from another |
| 549 | // module). |
Douglas Gregor | e4a838a | 2012-10-03 18:36:10 +0000 | [diff] [blame] | 550 | // FIXME: Can we diagnose ODR violations somehow? |
David Blaikie | ac4345c | 2017-02-12 18:45:31 +0000 | [diff] [blame] | 551 | if (Record.readInt()) |
| 552 | ReadFunctionDefinition(FD); |
Argyrios Kyrtzidis | 3357516 | 2010-07-02 15:58:43 +0000 | [diff] [blame] | 553 | } |
Argyrios Kyrtzidis | 318b0e7 | 2010-07-02 11:55:01 +0000 | [diff] [blame] | 554 | } |
| 555 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 556 | void ASTDeclReader::VisitDecl(Decl *D) { |
Dmitri Gribenko | b353ee1 | 2013-12-19 02:05:20 +0000 | [diff] [blame] | 557 | if (D->isTemplateParameter() || D->isTemplateParameterPack() || |
| 558 | isa<ParmVarDecl>(D)) { |
Douglas Gregor | 250ffb1 | 2011-03-05 01:35:54 +0000 | [diff] [blame] | 559 | // We don't want to deserialize the DeclContext of a template |
Dmitri Gribenko | b353ee1 | 2013-12-19 02:05:20 +0000 | [diff] [blame] | 560 | // parameter or of a parameter of a function template immediately. These |
| 561 | // entities might be used in the formulation of its DeclContext (for |
| 562 | // example, a function parameter can be used in decltype() in trailing |
| 563 | // return type of the function). Use the translation unit DeclContext as a |
| 564 | // placeholder. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 565 | GlobalDeclID SemaDCIDForTemplateParmDecl = ReadDeclID(); |
| 566 | GlobalDeclID LexicalDCIDForTemplateParmDecl = ReadDeclID(); |
Richard Smith | 8aed422 | 2015-12-11 22:41:00 +0000 | [diff] [blame] | 567 | if (!LexicalDCIDForTemplateParmDecl) |
| 568 | LexicalDCIDForTemplateParmDecl = SemaDCIDForTemplateParmDecl; |
Argyrios Kyrtzidis | 83a6e3b | 2013-02-16 00:48:59 +0000 | [diff] [blame] | 569 | Reader.addPendingDeclContextInfo(D, |
| 570 | SemaDCIDForTemplateParmDecl, |
| 571 | LexicalDCIDForTemplateParmDecl); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 572 | D->setDeclContext(Reader.getContext().getTranslationUnitDecl()); |
Douglas Gregor | 250ffb1 | 2011-03-05 01:35:54 +0000 | [diff] [blame] | 573 | } else { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 574 | auto *SemaDC = ReadDeclAs<DeclContext>(); |
| 575 | auto *LexicalDC = ReadDeclAs<DeclContext>(); |
Richard Smith | 8aed422 | 2015-12-11 22:41:00 +0000 | [diff] [blame] | 576 | if (!LexicalDC) |
| 577 | LexicalDC = SemaDC; |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 578 | DeclContext *MergedSemaDC = Reader.MergedDeclContexts.lookup(SemaDC); |
Argyrios Kyrtzidis | 7456ac4 | 2012-02-09 07:46:54 +0000 | [diff] [blame] | 579 | // Avoid calling setLexicalDeclContext() directly because it uses |
| 580 | // Decl::getASTContext() internally which is unsafe during derialization. |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 581 | D->setDeclContextsImpl(MergedSemaDC ? MergedSemaDC : SemaDC, LexicalDC, |
| 582 | Reader.getContext()); |
Douglas Gregor | 250ffb1 | 2011-03-05 01:35:54 +0000 | [diff] [blame] | 583 | } |
Richard Smith | cb34bd3 | 2016-03-27 07:28:06 +0000 | [diff] [blame] | 584 | D->setLocation(ThisDeclLoc); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 585 | D->setInvalidDecl(Record.readInt()); |
| 586 | if (Record.readInt()) { // hasAttrs |
Alexis Hunt | dcfba7b | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 587 | AttrVec Attrs; |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 588 | Record.readAttributes(Attrs); |
Argyrios Kyrtzidis | 7456ac4 | 2012-02-09 07:46:54 +0000 | [diff] [blame] | 589 | // Avoid calling setAttrs() directly because it uses Decl::getASTContext() |
| 590 | // internally which is unsafe during derialization. |
Argyrios Kyrtzidis | 6f40eb7 | 2012-02-09 02:44:08 +0000 | [diff] [blame] | 591 | D->setAttrsImpl(Attrs, Reader.getContext()); |
Alexis Hunt | dcfba7b | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 592 | } |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 593 | D->setImplicit(Record.readInt()); |
| 594 | D->Used = Record.readInt(); |
Vassil Vassilev | 928c825 | 2016-04-28 14:13:28 +0000 | [diff] [blame] | 595 | IsDeclMarkedUsed |= D->Used; |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 596 | D->setReferenced(Record.readInt()); |
| 597 | D->setTopLevelDeclInObjCContainer(Record.readInt()); |
| 598 | D->setAccess((AccessSpecifier)Record.readInt()); |
Douglas Gregor | 98c05b2 | 2011-09-10 00:09:20 +0000 | [diff] [blame] | 599 | D->FromASTFile = true; |
Richard Smith | 90dc525 | 2017-06-23 01:04:34 +0000 | [diff] [blame] | 600 | bool ModulePrivate = Record.readInt(); |
Richard Smith | 4241314 | 2015-05-15 20:05:43 +0000 | [diff] [blame] | 601 | |
Douglas Gregor | cf68c58 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 602 | // Determine whether this declaration is part of a (sub)module. If so, it |
| 603 | // may not yet be visible. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 604 | if (unsigned SubmoduleID = readSubmoduleID()) { |
Douglas Gregor | cfe7dc6 | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 605 | // Store the owning submodule ID in the declaration. |
Richard Smith | 90dc525 | 2017-06-23 01:04:34 +0000 | [diff] [blame] | 606 | D->setModuleOwnershipKind( |
| 607 | ModulePrivate ? Decl::ModuleOwnershipKind::ModulePrivate |
| 608 | : Decl::ModuleOwnershipKind::VisibleWhenImported); |
Douglas Gregor | cfe7dc6 | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 609 | D->setOwningModuleID(SubmoduleID); |
Richard Smith | 4241314 | 2015-05-15 20:05:43 +0000 | [diff] [blame] | 610 | |
Richard Smith | 90dc525 | 2017-06-23 01:04:34 +0000 | [diff] [blame] | 611 | if (ModulePrivate) { |
| 612 | // Module-private declarations are never visible, so there is no work to |
| 613 | // do. |
Richard Smith | 4241314 | 2015-05-15 20:05:43 +0000 | [diff] [blame] | 614 | } else if (Reader.getContext().getLangOpts().ModulesLocalVisibility) { |
| 615 | // If local visibility is being tracked, this declaration will become |
Richard Smith | 90dc525 | 2017-06-23 01:04:34 +0000 | [diff] [blame] | 616 | // hidden and visible as the owning module does. |
Richard Smith | 4241314 | 2015-05-15 20:05:43 +0000 | [diff] [blame] | 617 | } else if (Module *Owner = Reader.getSubmodule(SubmoduleID)) { |
Richard Smith | 90dc525 | 2017-06-23 01:04:34 +0000 | [diff] [blame] | 618 | // Mark the declaration as visible when its owning module becomes visible. |
| 619 | if (Owner->NameVisibility == Module::AllVisible) |
| 620 | D->setVisibleDespiteOwningModule(); |
| 621 | else |
Richard Smith | 4241314 | 2015-05-15 20:05:43 +0000 | [diff] [blame] | 622 | Reader.HiddenNamesMap[Owner].push_back(D); |
Douglas Gregor | cf68c58 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 623 | } |
Richard Smith | d19389a | 2017-07-05 07:47:11 +0000 | [diff] [blame] | 624 | } else if (ModulePrivate) { |
| 625 | D->setModuleOwnershipKind(Decl::ModuleOwnershipKind::ModulePrivate); |
Douglas Gregor | cf68c58 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 626 | } |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 627 | } |
| 628 | |
Nico Weber | 6622029 | 2016-03-02 17:28:48 +0000 | [diff] [blame] | 629 | void ASTDeclReader::VisitPragmaCommentDecl(PragmaCommentDecl *D) { |
| 630 | VisitDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 631 | D->setLocation(ReadSourceLocation()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 632 | D->CommentKind = (PragmaMSCommentKind)Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 633 | std::string Arg = ReadString(); |
Nico Weber | 6622029 | 2016-03-02 17:28:48 +0000 | [diff] [blame] | 634 | memcpy(D->getTrailingObjects<char>(), Arg.data(), Arg.size()); |
| 635 | D->getTrailingObjects<char>()[Arg.size()] = '\0'; |
| 636 | } |
| 637 | |
Nico Weber | cbbaeb1 | 2016-03-02 19:28:54 +0000 | [diff] [blame] | 638 | void ASTDeclReader::VisitPragmaDetectMismatchDecl(PragmaDetectMismatchDecl *D) { |
| 639 | VisitDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 640 | D->setLocation(ReadSourceLocation()); |
| 641 | std::string Name = ReadString(); |
Nico Weber | cbbaeb1 | 2016-03-02 19:28:54 +0000 | [diff] [blame] | 642 | memcpy(D->getTrailingObjects<char>(), Name.data(), Name.size()); |
| 643 | D->getTrailingObjects<char>()[Name.size()] = '\0'; |
| 644 | |
| 645 | D->ValueStart = Name.size() + 1; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 646 | std::string Value = ReadString(); |
Nico Weber | cbbaeb1 | 2016-03-02 19:28:54 +0000 | [diff] [blame] | 647 | memcpy(D->getTrailingObjects<char>() + D->ValueStart, Value.data(), |
| 648 | Value.size()); |
| 649 | D->getTrailingObjects<char>()[D->ValueStart + Value.size()] = '\0'; |
| 650 | } |
| 651 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 652 | void ASTDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) { |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 653 | llvm_unreachable("Translation units are not serialized"); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 654 | } |
| 655 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 656 | void ASTDeclReader::VisitNamedDecl(NamedDecl *ND) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 657 | VisitDecl(ND); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 658 | ND->setDeclName(Record.readDeclarationName()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 659 | AnonymousDeclNumber = Record.readInt(); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 660 | } |
| 661 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 662 | void ASTDeclReader::VisitTypeDecl(TypeDecl *TD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 663 | VisitNamedDecl(TD); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 664 | TD->setLocStart(ReadSourceLocation()); |
Argyrios Kyrtzidis | 318b0e7 | 2010-07-02 11:55:01 +0000 | [diff] [blame] | 665 | // Delay type reading until after we have fully initialized the decl. |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 666 | DeferredTypeID = Record.getGlobalTypeID(Record.readInt()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 667 | } |
| 668 | |
Richard Smith | 43ccec8e | 2014-08-26 03:52:16 +0000 | [diff] [blame] | 669 | ASTDeclReader::RedeclarableResult |
| 670 | ASTDeclReader::VisitTypedefNameDecl(TypedefNameDecl *TD) { |
Douglas Gregor | 9b7b391 | 2012-01-04 16:44:10 +0000 | [diff] [blame] | 671 | RedeclarableResult Redecl = VisitRedeclarable(TD); |
Argyrios Kyrtzidis | 318b0e7 | 2010-07-02 11:55:01 +0000 | [diff] [blame] | 672 | VisitTypeDecl(TD); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 673 | TypeSourceInfo *TInfo = GetTypeSourceInfo(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 674 | if (Record.readInt()) { // isModed |
| 675 | QualType modedT = Record.readType(); |
Enea Zaffanella | a86d88c | 2013-06-20 12:46:19 +0000 | [diff] [blame] | 676 | TD->setModedTypeSourceInfo(TInfo, modedT); |
| 677 | } else |
| 678 | TD->setTypeSourceInfo(TInfo); |
Richard Smith | c0ca4c2 | 2017-01-26 22:39:55 +0000 | [diff] [blame] | 679 | // Read and discard the declaration for which this is a typedef name for |
| 680 | // linkage, if it exists. We cannot rely on our type to pull in this decl, |
| 681 | // because it might have been merged with a type from another module and |
| 682 | // thus might not refer to our version of the declaration. |
| 683 | ReadDecl(); |
Richard Smith | 43ccec8e | 2014-08-26 03:52:16 +0000 | [diff] [blame] | 684 | return Redecl; |
Douglas Gregor | 1f17906 | 2011-12-19 14:40:25 +0000 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | void ASTDeclReader::VisitTypedefDecl(TypedefDecl *TD) { |
Richard Smith | 43ccec8e | 2014-08-26 03:52:16 +0000 | [diff] [blame] | 688 | RedeclarableResult Redecl = VisitTypedefNameDecl(TD); |
| 689 | mergeRedeclarable(TD, Redecl); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 690 | } |
| 691 | |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 692 | void ASTDeclReader::VisitTypeAliasDecl(TypeAliasDecl *TD) { |
Richard Smith | 43ccec8e | 2014-08-26 03:52:16 +0000 | [diff] [blame] | 693 | RedeclarableResult Redecl = VisitTypedefNameDecl(TD); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 694 | if (auto *Template = ReadDeclAs<TypeAliasTemplateDecl>()) |
Richard Smith | 43ccec8e | 2014-08-26 03:52:16 +0000 | [diff] [blame] | 695 | // Merged when we merge the template. |
| 696 | TD->setDescribedAliasTemplate(Template); |
| 697 | else |
| 698 | mergeRedeclarable(TD, Redecl); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 699 | } |
| 700 | |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 701 | ASTDeclReader::RedeclarableResult ASTDeclReader::VisitTagDecl(TagDecl *TD) { |
Douglas Gregor | 2009cee | 2012-01-03 22:46:00 +0000 | [diff] [blame] | 702 | RedeclarableResult Redecl = VisitRedeclarable(TD); |
Douglas Gregor | 3e30010 | 2011-10-26 17:53:41 +0000 | [diff] [blame] | 703 | VisitTypeDecl(TD); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 704 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 705 | TD->IdentifierNamespace = Record.readInt(); |
| 706 | TD->setTagKind((TagDecl::TagKind)Record.readInt()); |
Richard Smith | 2c38164 | 2014-08-27 23:11:59 +0000 | [diff] [blame] | 707 | if (!isa<CXXRecordDecl>(TD)) |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 708 | TD->setCompleteDefinition(Record.readInt()); |
| 709 | TD->setEmbeddedInDeclarator(Record.readInt()); |
| 710 | TD->setFreeStanding(Record.readInt()); |
| 711 | TD->setCompleteDefinitionRequired(Record.readInt()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 712 | TD->setBraceRange(ReadSourceRange()); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 713 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 714 | switch (Record.readInt()) { |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 715 | case 0: |
| 716 | break; |
| 717 | case 1: { // ExtInfo |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 718 | auto *Info = new (Reader.getContext()) TagDecl::ExtInfo(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 719 | ReadQualifierInfo(*Info); |
David Majnemer | 0035052 | 2015-08-31 18:48:39 +0000 | [diff] [blame] | 720 | TD->TypedefNameDeclOrQualifier = Info; |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 721 | break; |
| 722 | } |
| 723 | case 2: // TypedefNameForAnonDecl |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 724 | NamedDeclForTagDecl = ReadDeclID(); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 725 | TypedefNameForLinkage = Record.getIdentifierInfo(); |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 726 | break; |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 727 | default: |
| 728 | llvm_unreachable("unexpected tag info kind"); |
| 729 | } |
Douglas Gregor | 2009cee | 2012-01-03 22:46:00 +0000 | [diff] [blame] | 730 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 731 | if (!isa<CXXRecordDecl>(TD)) |
| 732 | mergeRedeclarable(TD, Redecl); |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 733 | return Redecl; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 734 | } |
| 735 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 736 | void ASTDeclReader::VisitEnumDecl(EnumDecl *ED) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 737 | VisitTagDecl(ED); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 738 | if (TypeSourceInfo *TI = GetTypeSourceInfo()) |
Douglas Gregor | 0bf3140 | 2010-10-08 23:50:27 +0000 | [diff] [blame] | 739 | ED->setIntegerTypeSourceInfo(TI); |
| 740 | else |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 741 | ED->setIntegerType(Record.readType()); |
| 742 | ED->setPromotionType(Record.readType()); |
| 743 | ED->setNumPositiveBits(Record.readInt()); |
| 744 | ED->setNumNegativeBits(Record.readInt()); |
Erich Keane | f92f31c | 2018-08-01 20:48:16 +0000 | [diff] [blame] | 745 | ED->setScoped(Record.readInt()); |
| 746 | ED->setScopedUsingClassTag(Record.readInt()); |
| 747 | ED->setFixed(Record.readInt()); |
Richard Smith | 4b38ded | 2012-03-14 23:13:10 +0000 | [diff] [blame] | 748 | |
Erich Keane | f92f31c | 2018-08-01 20:48:16 +0000 | [diff] [blame] | 749 | ED->setHasODRHash(true); |
Richard Trieu | ab4d730 | 2018-07-25 22:52:05 +0000 | [diff] [blame] | 750 | ED->ODRHash = Record.readInt(); |
| 751 | |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame] | 752 | // If this is a definition subject to the ODR, and we already have a |
| 753 | // definition, merge this one into it. |
Erich Keane | f92f31c | 2018-08-01 20:48:16 +0000 | [diff] [blame] | 754 | if (ED->isCompleteDefinition() && |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame] | 755 | Reader.getContext().getLangOpts().Modules && |
| 756 | Reader.getContext().getLangOpts().CPlusPlus) { |
Richard Smith | 86dfc1e | 2015-06-18 22:07:00 +0000 | [diff] [blame] | 757 | EnumDecl *&OldDef = Reader.EnumDefinitions[ED->getCanonicalDecl()]; |
| 758 | if (!OldDef) { |
| 759 | // This is the first time we've seen an imported definition. Look for a |
| 760 | // local definition before deciding that we are the first definition. |
| 761 | for (auto *D : merged_redecls(ED->getCanonicalDecl())) { |
| 762 | if (!D->isFromASTFile() && D->isCompleteDefinition()) { |
| 763 | OldDef = D; |
| 764 | break; |
| 765 | } |
| 766 | } |
| 767 | } |
| 768 | if (OldDef) { |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame] | 769 | Reader.MergedDeclContexts.insert(std::make_pair(ED, OldDef)); |
Erich Keane | f92f31c | 2018-08-01 20:48:16 +0000 | [diff] [blame] | 770 | ED->setCompleteDefinition(false); |
Richard Smith | 6561f92 | 2016-09-12 21:06:40 +0000 | [diff] [blame] | 771 | Reader.mergeDefinitionVisibility(OldDef, ED); |
Richard Trieu | ab4d730 | 2018-07-25 22:52:05 +0000 | [diff] [blame] | 772 | if (OldDef->getODRHash() != ED->getODRHash()) |
| 773 | Reader.PendingEnumOdrMergeFailures[OldDef].push_back(ED); |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame] | 774 | } else { |
| 775 | OldDef = ED; |
| 776 | } |
| 777 | } |
| 778 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 779 | if (auto *InstED = ReadDeclAs<EnumDecl>()) { |
| 780 | auto TSK = (TemplateSpecializationKind)Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 781 | SourceLocation POI = ReadSourceLocation(); |
Richard Smith | 4b38ded | 2012-03-14 23:13:10 +0000 | [diff] [blame] | 782 | ED->setInstantiationOfMemberEnum(Reader.getContext(), InstED, TSK); |
| 783 | ED->getMemberSpecializationInfo()->setPointOfInstantiation(POI); |
| 784 | } |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 785 | } |
| 786 | |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 787 | ASTDeclReader::RedeclarableResult |
| 788 | ASTDeclReader::VisitRecordDeclImpl(RecordDecl *RD) { |
| 789 | RedeclarableResult Redecl = VisitTagDecl(RD); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 790 | RD->setHasFlexibleArrayMember(Record.readInt()); |
| 791 | RD->setAnonymousStructOrUnion(Record.readInt()); |
| 792 | RD->setHasObjectMember(Record.readInt()); |
| 793 | RD->setHasVolatileMember(Record.readInt()); |
Akira Hatanaka | 34fb264 | 2018-03-13 18:58:25 +0000 | [diff] [blame] | 794 | RD->setNonTrivialToPrimitiveDefaultInitialize(Record.readInt()); |
| 795 | RD->setNonTrivialToPrimitiveCopy(Record.readInt()); |
| 796 | RD->setNonTrivialToPrimitiveDestroy(Record.readInt()); |
Akira Hatanaka | 0905106 | 2019-09-07 00:34:43 +0000 | [diff] [blame] | 797 | RD->setHasNonTrivialToPrimitiveDefaultInitializeCUnion(Record.readInt()); |
| 798 | RD->setHasNonTrivialToPrimitiveDestructCUnion(Record.readInt()); |
| 799 | RD->setHasNonTrivialToPrimitiveCopyCUnion(Record.readInt()); |
Akira Hatanaka | fcbe17c | 2018-03-28 21:13:14 +0000 | [diff] [blame] | 800 | RD->setParamDestroyedInCallee(Record.readInt()); |
Akira Hatanaka | e6313ac | 2018-04-09 22:48:22 +0000 | [diff] [blame] | 801 | RD->setArgPassingRestrictions((RecordDecl::ArgPassingKind)Record.readInt()); |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 802 | return Redecl; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 803 | } |
| 804 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 805 | void ASTDeclReader::VisitValueDecl(ValueDecl *VD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 806 | VisitNamedDecl(VD); |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 807 | // For function declarations, defer reading the type in case the function has |
| 808 | // a deduced return type that references an entity declared within the |
| 809 | // function. |
| 810 | if (isa<FunctionDecl>(VD)) |
| 811 | DeferredTypeID = Record.getGlobalTypeID(Record.readInt()); |
| 812 | else |
| 813 | VD->setType(Record.readType()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 814 | } |
| 815 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 816 | void ASTDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 817 | VisitValueDecl(ECD); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 818 | if (Record.readInt()) |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 819 | ECD->setInitExpr(Record.readExpr()); |
| 820 | ECD->setInitVal(Record.readAPSInt()); |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame] | 821 | mergeMergeable(ECD); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 822 | } |
| 823 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 824 | void ASTDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) { |
Argyrios Kyrtzidis | 560ac97 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 825 | VisitValueDecl(DD); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 826 | DD->setInnerLocStart(ReadSourceLocation()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 827 | if (Record.readInt()) { // hasExtInfo |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 828 | auto *Info = new (Reader.getContext()) DeclaratorDecl::ExtInfo(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 829 | ReadQualifierInfo(*Info); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 830 | DD->DeclInfo = Info; |
Jonathan D. Turner | 205c7d5 | 2011-06-03 23:11:16 +0000 | [diff] [blame] | 831 | } |
Richard Smith | c23d734 | 2018-06-29 20:46:25 +0000 | [diff] [blame] | 832 | QualType TSIType = Record.readType(); |
| 833 | DD->setTypeSourceInfo( |
| 834 | TSIType.isNull() ? nullptr |
| 835 | : Reader.getContext().CreateTypeSourceInfo(TSIType)); |
Argyrios Kyrtzidis | 560ac97 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 836 | } |
| 837 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 838 | void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) { |
Douglas Gregor | b258569 | 2012-01-04 17:13:46 +0000 | [diff] [blame] | 839 | RedeclarableResult Redecl = VisitRedeclarable(FD); |
Douglas Gregor | 3e30010 | 2011-10-26 17:53:41 +0000 | [diff] [blame] | 840 | VisitDeclaratorDecl(FD); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 841 | |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 842 | // Attach a type to this function. Use the real type if possible, but fall |
| 843 | // back to the type as written if it involves a deduced return type. |
| 844 | if (FD->getTypeSourceInfo() && |
| 845 | FD->getTypeSourceInfo()->getType()->castAs<FunctionType>() |
| 846 | ->getReturnType()->getContainedAutoType()) { |
| 847 | // We'll set up the real type in Visit, once we've finished loading the |
| 848 | // function. |
| 849 | FD->setType(FD->getTypeSourceInfo()->getType()); |
Richard Smith | a62d198 | 2018-08-03 01:00:01 +0000 | [diff] [blame] | 850 | Reader.PendingFunctionTypes.push_back({FD, DeferredTypeID}); |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 851 | } else { |
| 852 | FD->setType(Reader.GetType(DeferredTypeID)); |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 853 | } |
Richard Smith | a62d198 | 2018-08-03 01:00:01 +0000 | [diff] [blame] | 854 | DeferredTypeID = 0; |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 855 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 856 | ReadDeclarationNameLoc(FD->DNLoc, FD->getDeclName()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 857 | FD->IdentifierNamespace = Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 858 | |
Douglas Gregor | b258569 | 2012-01-04 17:13:46 +0000 | [diff] [blame] | 859 | // FunctionDecl's body is handled last at ASTDeclReader::Visit, |
| 860 | // after everything else is read. |
Rafael Espindola | 6ae7e50 | 2013-04-03 19:27:57 +0000 | [diff] [blame] | 861 | |
Erich Keane | 9c66506 | 2018-08-01 21:02:40 +0000 | [diff] [blame] | 862 | FD->setStorageClass(static_cast<StorageClass>(Record.readInt())); |
| 863 | FD->setInlineSpecified(Record.readInt()); |
| 864 | FD->setImplicitlyInline(Record.readInt()); |
Erich Keane | 9c66506 | 2018-08-01 21:02:40 +0000 | [diff] [blame] | 865 | FD->setVirtualAsWritten(Record.readInt()); |
| 866 | FD->setPure(Record.readInt()); |
| 867 | FD->setHasInheritedPrototype(Record.readInt()); |
| 868 | FD->setHasWrittenPrototype(Record.readInt()); |
| 869 | FD->setDeletedAsWritten(Record.readInt()); |
| 870 | FD->setTrivial(Record.readInt()); |
| 871 | FD->setTrivialForCall(Record.readInt()); |
| 872 | FD->setDefaulted(Record.readInt()); |
| 873 | FD->setExplicitlyDefaulted(Record.readInt()); |
| 874 | FD->setHasImplicitReturnZero(Record.readInt()); |
Gauthier Harnisch | 796ed03 | 2019-06-14 08:56:20 +0000 | [diff] [blame] | 875 | FD->setConstexprKind(static_cast<ConstexprSpecKind>(Record.readInt())); |
Erich Keane | 9c66506 | 2018-08-01 21:02:40 +0000 | [diff] [blame] | 876 | FD->setUsesSEHTry(Record.readInt()); |
| 877 | FD->setHasSkippedBody(Record.readInt()); |
| 878 | FD->setIsMultiVersion(Record.readInt()); |
| 879 | FD->setLateTemplateParsed(Record.readInt()); |
| 880 | |
| 881 | FD->setCachedLinkage(static_cast<Linkage>(Record.readInt())); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 882 | FD->EndRangeLoc = ReadSourceLocation(); |
Douglas Gregor | b258569 | 2012-01-04 17:13:46 +0000 | [diff] [blame] | 883 | |
Richard Trieu | e6caa26 | 2017-12-23 00:41:01 +0000 | [diff] [blame] | 884 | FD->ODRHash = Record.readInt(); |
Erich Keane | 9c66506 | 2018-08-01 21:02:40 +0000 | [diff] [blame] | 885 | FD->setHasODRHash(true); |
Richard Trieu | e6caa26 | 2017-12-23 00:41:01 +0000 | [diff] [blame] | 886 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 887 | switch ((FunctionDecl::TemplatedKind)Record.readInt()) { |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 888 | case FunctionDecl::TK_NonTemplate: |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 889 | mergeRedeclarable(FD, Redecl); |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 890 | break; |
| 891 | case FunctionDecl::TK_FunctionTemplate: |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 892 | // Merged when we merge the template. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 893 | FD->setDescribedFunctionTemplate(ReadDeclAs<FunctionTemplateDecl>()); |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 894 | break; |
| 895 | case FunctionDecl::TK_MemberSpecialization: { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 896 | auto *InstFD = ReadDeclAs<FunctionDecl>(); |
| 897 | auto TSK = (TemplateSpecializationKind)Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 898 | SourceLocation POI = ReadSourceLocation(); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 899 | FD->setInstantiationOfMemberFunction(Reader.getContext(), InstFD, TSK); |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 900 | FD->getMemberSpecializationInfo()->setPointOfInstantiation(POI); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 901 | mergeRedeclarable(FD, Redecl); |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 902 | break; |
| 903 | } |
| 904 | case FunctionDecl::TK_FunctionTemplateSpecialization: { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 905 | auto *Template = ReadDeclAs<FunctionTemplateDecl>(); |
| 906 | auto TSK = (TemplateSpecializationKind)Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 907 | |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 908 | // Template arguments. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 909 | SmallVector<TemplateArgument, 8> TemplArgs; |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 910 | Record.readTemplateArgumentList(TemplArgs, /*Canonicalize*/ true); |
Richard Smith | 2bb3c34 | 2015-08-09 01:05:31 +0000 | [diff] [blame] | 911 | |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 912 | // Template args as written. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 913 | SmallVector<TemplateArgumentLoc, 8> TemplArgLocs; |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 914 | SourceLocation LAngleLoc, RAngleLoc; |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 915 | bool HasTemplateArgumentsAsWritten = Record.readInt(); |
Argyrios Kyrtzidis | e9a2443 | 2011-09-22 20:07:09 +0000 | [diff] [blame] | 916 | if (HasTemplateArgumentsAsWritten) { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 917 | unsigned NumTemplateArgLocs = Record.readInt(); |
Argyrios Kyrtzidis | 373a83a | 2010-07-02 11:55:40 +0000 | [diff] [blame] | 918 | TemplArgLocs.reserve(NumTemplateArgLocs); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 919 | for (unsigned i = 0; i != NumTemplateArgLocs; ++i) |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 920 | TemplArgLocs.push_back(Record.readTemplateArgumentLoc()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 921 | |
| 922 | LAngleLoc = ReadSourceLocation(); |
| 923 | RAngleLoc = ReadSourceLocation(); |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 924 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 925 | |
| 926 | SourceLocation POI = ReadSourceLocation(); |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 927 | |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 928 | ASTContext &C = Reader.getContext(); |
Argyrios Kyrtzidis | e262a95 | 2010-09-09 11:28:23 +0000 | [diff] [blame] | 929 | TemplateArgumentList *TemplArgList |
David Majnemer | 8b62269 | 2016-07-03 21:17:51 +0000 | [diff] [blame] | 930 | = TemplateArgumentList::CreateCopy(C, TemplArgs); |
Argyrios Kyrtzidis | e9a2443 | 2011-09-22 20:07:09 +0000 | [diff] [blame] | 931 | TemplateArgumentListInfo TemplArgsInfo(LAngleLoc, RAngleLoc); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 932 | for (unsigned i = 0, e = TemplArgLocs.size(); i != e; ++i) |
Argyrios Kyrtzidis | e9a2443 | 2011-09-22 20:07:09 +0000 | [diff] [blame] | 933 | TemplArgsInfo.addArgument(TemplArgLocs[i]); |
Richard Smith | f19a8b0 | 2019-05-02 00:49:14 +0000 | [diff] [blame] | 934 | |
| 935 | MemberSpecializationInfo *MSInfo = nullptr; |
| 936 | if (Record.readInt()) { |
| 937 | auto *FD = ReadDeclAs<FunctionDecl>(); |
| 938 | auto TSK = (TemplateSpecializationKind)Record.readInt(); |
| 939 | SourceLocation POI = ReadSourceLocation(); |
| 940 | |
| 941 | MSInfo = new (C) MemberSpecializationInfo(FD, TSK); |
| 942 | MSInfo->setPointOfInstantiation(POI); |
| 943 | } |
| 944 | |
| 945 | FunctionTemplateSpecializationInfo *FTInfo = |
| 946 | FunctionTemplateSpecializationInfo::Create( |
| 947 | C, FD, Template, TSK, TemplArgList, |
| 948 | HasTemplateArgumentsAsWritten ? &TemplArgsInfo : nullptr, POI, |
| 949 | MSInfo); |
Argyrios Kyrtzidis | e262a95 | 2010-09-09 11:28:23 +0000 | [diff] [blame] | 950 | FD->TemplateOrSpecialization = FTInfo; |
Argyrios Kyrtzidis | f4bc0d8 | 2010-09-08 19:31:22 +0000 | [diff] [blame] | 951 | |
Argyrios Kyrtzidis | e262a95 | 2010-09-09 11:28:23 +0000 | [diff] [blame] | 952 | if (FD->isCanonicalDecl()) { // if canonical add to template's set. |
Argyrios Kyrtzidis | f24d569 | 2010-09-13 11:45:48 +0000 | [diff] [blame] | 953 | // The template that contains the specializations set. It's not safe to |
| 954 | // use getCanonicalDecl on Template since it may still be initializing. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 955 | auto *CanonTemplate = ReadDeclAs<FunctionTemplateDecl>(); |
Argyrios Kyrtzidis | e262a95 | 2010-09-09 11:28:23 +0000 | [diff] [blame] | 956 | // Get the InsertPos by FindNodeOrInsertPos() instead of calling |
| 957 | // InsertNode(FTInfo) directly to avoid the getASTContext() call in |
| 958 | // FunctionTemplateSpecializationInfo's Profile(). |
| 959 | // We avoid getASTContext because a decl in the parent hierarchy may |
| 960 | // be initializing. |
Argyrios Kyrtzidis | f4bc0d8 | 2010-09-08 19:31:22 +0000 | [diff] [blame] | 961 | llvm::FoldingSetNodeID ID; |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 962 | FunctionTemplateSpecializationInfo::Profile(ID, TemplArgs, C); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 963 | void *InsertPos = nullptr; |
Richard Smith | feb3e1a | 2013-06-28 04:37:53 +0000 | [diff] [blame] | 964 | FunctionTemplateDecl::Common *CommonPtr = CanonTemplate->getCommonPtr(); |
Richard Smith | da6c234 | 2015-07-01 23:19:58 +0000 | [diff] [blame] | 965 | FunctionTemplateSpecializationInfo *ExistingInfo = |
| 966 | CommonPtr->Specializations.FindNodeOrInsertPos(ID, InsertPos); |
Argyrios Kyrtzidis | e60e408 | 2012-09-10 23:28:22 +0000 | [diff] [blame] | 967 | if (InsertPos) |
Richard Smith | feb3e1a | 2013-06-28 04:37:53 +0000 | [diff] [blame] | 968 | CommonPtr->Specializations.InsertNode(FTInfo, InsertPos); |
| 969 | else { |
| 970 | assert(Reader.getContext().getLangOpts().Modules && |
| 971 | "already deserialized this template specialization"); |
Richard Smith | f19a8b0 | 2019-05-02 00:49:14 +0000 | [diff] [blame] | 972 | mergeRedeclarable(FD, ExistingInfo->getFunction(), Redecl); |
Richard Smith | feb3e1a | 2013-06-28 04:37:53 +0000 | [diff] [blame] | 973 | } |
Argyrios Kyrtzidis | f4bc0d8 | 2010-09-08 19:31:22 +0000 | [diff] [blame] | 974 | } |
Argyrios Kyrtzidis | 0b0369a | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 975 | break; |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 976 | } |
| 977 | case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { |
| 978 | // Templates. |
| 979 | UnresolvedSet<8> TemplDecls; |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 980 | unsigned NumTemplates = Record.readInt(); |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 981 | while (NumTemplates--) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 982 | TemplDecls.addDecl(ReadDeclAs<NamedDecl>()); |
| 983 | |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 984 | // Templates args. |
| 985 | TemplateArgumentListInfo TemplArgs; |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 986 | unsigned NumArgs = Record.readInt(); |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 987 | while (NumArgs--) |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 988 | TemplArgs.addArgument(Record.readTemplateArgumentLoc()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 989 | TemplArgs.setLAngleLoc(ReadSourceLocation()); |
| 990 | TemplArgs.setRAngleLoc(ReadSourceLocation()); |
| 991 | |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 992 | FD->setDependentTemplateSpecialization(Reader.getContext(), |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 993 | TemplDecls, TemplArgs); |
Richard Smith | da6c234 | 2015-07-01 23:19:58 +0000 | [diff] [blame] | 994 | // These are not merged; we don't need to merge redeclarations of dependent |
| 995 | // template friends. |
Argyrios Kyrtzidis | 0b0369a | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 996 | break; |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 997 | } |
| 998 | } |
Argyrios Kyrtzidis | 373a83a | 2010-07-02 11:55:40 +0000 | [diff] [blame] | 999 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1000 | // Read in the parameters. |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1001 | unsigned NumParams = Record.readInt(); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1002 | SmallVector<ParmVarDecl *, 16> Params; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1003 | Params.reserve(NumParams); |
| 1004 | for (unsigned I = 0; I != NumParams; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1005 | Params.push_back(ReadDeclAs<ParmVarDecl>()); |
David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 1006 | FD->setParams(Reader.getContext(), Params); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1007 | } |
| 1008 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1009 | void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1010 | VisitNamedDecl(MD); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1011 | if (Record.readInt()) { |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 1012 | // Load the body on-demand. Most clients won't care, because method |
| 1013 | // definitions rarely show up in headers. |
| 1014 | Reader.PendingBodies[MD] = GetCurrentCursorOffset(); |
| 1015 | HasPendingBody = true; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1016 | MD->setSelfDecl(ReadDeclAs<ImplicitParamDecl>()); |
| 1017 | MD->setCmdDecl(ReadDeclAs<ImplicitParamDecl>()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1018 | } |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1019 | MD->setInstanceMethod(Record.readInt()); |
| 1020 | MD->setVariadic(Record.readInt()); |
| 1021 | MD->setPropertyAccessor(Record.readInt()); |
Adrian Prantl | 2073dd2 | 2019-11-04 14:28:14 -0800 | [diff] [blame^] | 1022 | MD->setSynthesizedAccessorStub(Record.readInt()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1023 | MD->setDefined(Record.readInt()); |
Erich Keane | 9b18eca | 2018-08-01 21:31:08 +0000 | [diff] [blame] | 1024 | MD->setOverriding(Record.readInt()); |
| 1025 | MD->setHasSkippedBody(Record.readInt()); |
Argyrios Kyrtzidis | db21596 | 2011-10-14 17:41:52 +0000 | [diff] [blame] | 1026 | |
Erich Keane | 9b18eca | 2018-08-01 21:31:08 +0000 | [diff] [blame] | 1027 | MD->setIsRedeclaration(Record.readInt()); |
| 1028 | MD->setHasRedeclaration(Record.readInt()); |
| 1029 | if (MD->hasRedeclaration()) |
Argyrios Kyrtzidis | db21596 | 2011-10-14 17:41:52 +0000 | [diff] [blame] | 1030 | Reader.getContext().setObjCMethodRedeclaration(MD, |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1031 | ReadDeclAs<ObjCMethodDecl>()); |
Argyrios Kyrtzidis | db21596 | 2011-10-14 17:41:52 +0000 | [diff] [blame] | 1032 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1033 | MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record.readInt()); |
| 1034 | MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record.readInt()); |
Erich Keane | 9b18eca | 2018-08-01 21:31:08 +0000 | [diff] [blame] | 1035 | MD->setRelatedResultType(Record.readInt()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1036 | MD->setReturnType(Record.readType()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1037 | MD->setReturnTypeSourceInfo(GetTypeSourceInfo()); |
| 1038 | MD->DeclEndLoc = ReadSourceLocation(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1039 | unsigned NumParams = Record.readInt(); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1040 | SmallVector<ParmVarDecl *, 16> Params; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1041 | Params.reserve(NumParams); |
| 1042 | for (unsigned I = 0; I != NumParams; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1043 | Params.push_back(ReadDeclAs<ParmVarDecl>()); |
Argyrios Kyrtzidis | b8c3aaf | 2011-10-03 06:37:04 +0000 | [diff] [blame] | 1044 | |
Erich Keane | 9b18eca | 2018-08-01 21:31:08 +0000 | [diff] [blame] | 1045 | MD->setSelLocsKind((SelectorLocationsKind)Record.readInt()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1046 | unsigned NumStoredSelLocs = Record.readInt(); |
Argyrios Kyrtzidis | b8c3aaf | 2011-10-03 06:37:04 +0000 | [diff] [blame] | 1047 | SmallVector<SourceLocation, 16> SelLocs; |
| 1048 | SelLocs.reserve(NumStoredSelLocs); |
| 1049 | for (unsigned i = 0; i != NumStoredSelLocs; ++i) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1050 | SelLocs.push_back(ReadSourceLocation()); |
Argyrios Kyrtzidis | b8c3aaf | 2011-10-03 06:37:04 +0000 | [diff] [blame] | 1051 | |
| 1052 | MD->setParamsAndSelLocs(Reader.getContext(), Params, SelLocs); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1053 | } |
| 1054 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 1055 | void ASTDeclReader::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { |
David Blaikie | 27a1bc0 | 2015-09-28 23:48:49 +0000 | [diff] [blame] | 1056 | VisitTypedefNameDecl(D); |
Richard Smith | 9b88a4c | 2015-07-27 05:40:23 +0000 | [diff] [blame] | 1057 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1058 | D->Variance = Record.readInt(); |
| 1059 | D->Index = Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1060 | D->VarianceLoc = ReadSourceLocation(); |
| 1061 | D->ColonLoc = ReadSourceLocation(); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 1062 | } |
| 1063 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1064 | void ASTDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1065 | VisitNamedDecl(CD); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1066 | CD->setAtStartLoc(ReadSourceLocation()); |
| 1067 | CD->setAtEndRange(ReadSourceRange()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1068 | } |
| 1069 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 1070 | ObjCTypeParamList *ASTDeclReader::ReadObjCTypeParamList() { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1071 | unsigned numParams = Record.readInt(); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 1072 | if (numParams == 0) |
| 1073 | return nullptr; |
| 1074 | |
| 1075 | SmallVector<ObjCTypeParamDecl *, 4> typeParams; |
| 1076 | typeParams.reserve(numParams); |
| 1077 | for (unsigned i = 0; i != numParams; ++i) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1078 | auto *typeParam = ReadDeclAs<ObjCTypeParamDecl>(); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 1079 | if (!typeParam) |
| 1080 | return nullptr; |
| 1081 | |
| 1082 | typeParams.push_back(typeParam); |
| 1083 | } |
| 1084 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1085 | SourceLocation lAngleLoc = ReadSourceLocation(); |
| 1086 | SourceLocation rAngleLoc = ReadSourceLocation(); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 1087 | |
| 1088 | return ObjCTypeParamList::create(Reader.getContext(), lAngleLoc, |
| 1089 | typeParams, rAngleLoc); |
| 1090 | } |
| 1091 | |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 1092 | void ASTDeclReader::ReadObjCDefinitionData( |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1093 | struct ObjCInterfaceDecl::DefinitionData &Data) { |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 1094 | // Read the superclass. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1095 | Data.SuperClassTInfo = GetTypeSourceInfo(); |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 1096 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1097 | Data.EndLoc = ReadSourceLocation(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1098 | Data.HasDesignatedInitializers = Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1099 | |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 1100 | // Read the directly referenced protocols and their SourceLocations. |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1101 | unsigned NumProtocols = Record.readInt(); |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 1102 | SmallVector<ObjCProtocolDecl *, 16> Protocols; |
| 1103 | Protocols.reserve(NumProtocols); |
| 1104 | for (unsigned I = 0; I != NumProtocols; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1105 | Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>()); |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 1106 | SmallVector<SourceLocation, 16> ProtoLocs; |
| 1107 | ProtoLocs.reserve(NumProtocols); |
| 1108 | for (unsigned I = 0; I != NumProtocols; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1109 | ProtoLocs.push_back(ReadSourceLocation()); |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 1110 | Data.ReferencedProtocols.set(Protocols.data(), NumProtocols, ProtoLocs.data(), |
| 1111 | Reader.getContext()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1112 | |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 1113 | // Read the transitive closure of protocols referenced by this class. |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1114 | NumProtocols = Record.readInt(); |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 1115 | Protocols.clear(); |
| 1116 | Protocols.reserve(NumProtocols); |
| 1117 | for (unsigned I = 0; I != NumProtocols; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1118 | Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>()); |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 1119 | Data.AllReferencedProtocols.set(Protocols.data(), NumProtocols, |
| 1120 | Reader.getContext()); |
| 1121 | } |
| 1122 | |
| 1123 | void ASTDeclReader::MergeDefinitionData(ObjCInterfaceDecl *D, |
| 1124 | struct ObjCInterfaceDecl::DefinitionData &&NewDD) { |
| 1125 | // FIXME: odr checking? |
| 1126 | } |
| 1127 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1128 | void ASTDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) { |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 1129 | RedeclarableResult Redecl = VisitRedeclarable(ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1130 | VisitObjCContainerDecl(ID); |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 1131 | DeferredTypeID = Record.getGlobalTypeID(Record.readInt()); |
Douglas Gregor | 2c46b5b | 2012-01-03 17:27:13 +0000 | [diff] [blame] | 1132 | mergeRedeclarable(ID, Redecl); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 1133 | |
| 1134 | ID->TypeParamList = ReadObjCTypeParamList(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1135 | if (Record.readInt()) { |
Douglas Gregor | c0ac7d6 | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 1136 | // Read the definition. |
| 1137 | ID->allocateDefinitionData(); |
Douglas Gregor | c0ac7d6 | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 1138 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1139 | ReadObjCDefinitionData(ID->data()); |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 1140 | ObjCInterfaceDecl *Canon = ID->getCanonicalDecl(); |
| 1141 | if (Canon->Data.getPointer()) { |
| 1142 | // If we already have a definition, keep the definition invariant and |
| 1143 | // merge the data. |
| 1144 | MergeDefinitionData(Canon, std::move(ID->data())); |
| 1145 | ID->Data = Canon->Data; |
| 1146 | } else { |
| 1147 | // Set the definition data of the canonical declaration, so other |
| 1148 | // redeclarations will see it. |
| 1149 | ID->getCanonicalDecl()->Data = ID->Data; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1150 | |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 1151 | // We will rebuild this list lazily. |
| 1152 | ID->setIvarList(nullptr); |
| 1153 | } |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 1154 | |
Douglas Gregor | c1a61fe | 2011-12-19 20:51:16 +0000 | [diff] [blame] | 1155 | // Note that we have deserialized a definition. |
| 1156 | Reader.PendingDefinitions.insert(ID); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1157 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 1158 | // Note that we've loaded this Objective-C class. |
| 1159 | Reader.ObjCClassesLoaded.push_back(ID); |
Douglas Gregor | c03c52e | 2012-01-15 18:08:05 +0000 | [diff] [blame] | 1160 | } else { |
| 1161 | ID->Data = ID->getCanonicalDecl()->Data; |
Douglas Gregor | c0ac7d6 | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 1162 | } |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1163 | } |
| 1164 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1165 | void ASTDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1166 | VisitFieldDecl(IVD); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1167 | IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record.readInt()); |
Fariborz Jahanian | a50b3a2 | 2010-08-20 21:21:08 +0000 | [diff] [blame] | 1168 | // This field will be built lazily. |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 1169 | IVD->setNextIvar(nullptr); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1170 | bool synth = Record.readInt(); |
Fariborz Jahanian | aea8e1e | 2010-07-17 18:35:47 +0000 | [diff] [blame] | 1171 | IVD->setSynthesize(synth); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1172 | } |
| 1173 | |
Graydon Hoare | e0a6835 | 2017-06-28 18:36:27 +0000 | [diff] [blame] | 1174 | void ASTDeclReader::ReadObjCDefinitionData( |
| 1175 | struct ObjCProtocolDecl::DefinitionData &Data) { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1176 | unsigned NumProtoRefs = Record.readInt(); |
Douglas Gregor | e6e48b1 | 2012-01-01 19:29:29 +0000 | [diff] [blame] | 1177 | SmallVector<ObjCProtocolDecl *, 16> ProtoRefs; |
| 1178 | ProtoRefs.reserve(NumProtoRefs); |
| 1179 | for (unsigned I = 0; I != NumProtoRefs; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1180 | ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>()); |
Douglas Gregor | e6e48b1 | 2012-01-01 19:29:29 +0000 | [diff] [blame] | 1181 | SmallVector<SourceLocation, 16> ProtoLocs; |
| 1182 | ProtoLocs.reserve(NumProtoRefs); |
| 1183 | for (unsigned I = 0; I != NumProtoRefs; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1184 | ProtoLocs.push_back(ReadSourceLocation()); |
Graydon Hoare | e0a6835 | 2017-06-28 18:36:27 +0000 | [diff] [blame] | 1185 | Data.ReferencedProtocols.set(ProtoRefs.data(), NumProtoRefs, |
| 1186 | ProtoLocs.data(), Reader.getContext()); |
| 1187 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1188 | |
Graydon Hoare | e0a6835 | 2017-06-28 18:36:27 +0000 | [diff] [blame] | 1189 | void ASTDeclReader::MergeDefinitionData(ObjCProtocolDecl *D, |
| 1190 | struct ObjCProtocolDecl::DefinitionData &&NewDD) { |
| 1191 | // FIXME: odr checking? |
| 1192 | } |
| 1193 | |
| 1194 | void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) { |
| 1195 | RedeclarableResult Redecl = VisitRedeclarable(PD); |
| 1196 | VisitObjCContainerDecl(PD); |
| 1197 | mergeRedeclarable(PD, Redecl); |
| 1198 | |
| 1199 | if (Record.readInt()) { |
| 1200 | // Read the definition. |
| 1201 | PD->allocateDefinitionData(); |
| 1202 | |
| 1203 | ReadObjCDefinitionData(PD->data()); |
| 1204 | |
| 1205 | ObjCProtocolDecl *Canon = PD->getCanonicalDecl(); |
| 1206 | if (Canon->Data.getPointer()) { |
| 1207 | // If we already have a definition, keep the definition invariant and |
| 1208 | // merge the data. |
| 1209 | MergeDefinitionData(Canon, std::move(PD->data())); |
| 1210 | PD->Data = Canon->Data; |
| 1211 | } else { |
| 1212 | // Set the definition data of the canonical declaration, so other |
| 1213 | // redeclarations will see it. |
| 1214 | PD->getCanonicalDecl()->Data = PD->Data; |
| 1215 | } |
Douglas Gregor | a715bff | 2012-01-01 19:51:50 +0000 | [diff] [blame] | 1216 | // Note that we have deserialized a definition. |
| 1217 | Reader.PendingDefinitions.insert(PD); |
Douglas Gregor | c03c52e | 2012-01-15 18:08:05 +0000 | [diff] [blame] | 1218 | } else { |
| 1219 | PD->Data = PD->getCanonicalDecl()->Data; |
Douglas Gregor | e6e48b1 | 2012-01-01 19:29:29 +0000 | [diff] [blame] | 1220 | } |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1221 | } |
| 1222 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1223 | void ASTDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1224 | VisitFieldDecl(FD); |
| 1225 | } |
| 1226 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1227 | void ASTDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1228 | VisitObjCContainerDecl(CD); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1229 | CD->setCategoryNameLoc(ReadSourceLocation()); |
| 1230 | CD->setIvarLBraceLoc(ReadSourceLocation()); |
| 1231 | CD->setIvarRBraceLoc(ReadSourceLocation()); |
| 1232 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 1233 | // Note that this category has been deserialized. We do this before |
| 1234 | // deserializing the interface declaration, so that it will consider this |
| 1235 | /// category. |
| 1236 | Reader.CategoriesDeserialized.insert(CD); |
| 1237 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1238 | CD->ClassInterface = ReadDeclAs<ObjCInterfaceDecl>(); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 1239 | CD->TypeParamList = ReadObjCTypeParamList(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1240 | unsigned NumProtoRefs = Record.readInt(); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1241 | SmallVector<ObjCProtocolDecl *, 16> ProtoRefs; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1242 | ProtoRefs.reserve(NumProtoRefs); |
| 1243 | for (unsigned I = 0; I != NumProtoRefs; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1244 | ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>()); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1245 | SmallVector<SourceLocation, 16> ProtoLocs; |
Douglas Gregor | 002b671 | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 1246 | ProtoLocs.reserve(NumProtoRefs); |
| 1247 | for (unsigned I = 0; I != NumProtoRefs; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1248 | ProtoLocs.push_back(ReadSourceLocation()); |
Douglas Gregor | 002b671 | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 1249 | CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(), |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1250 | Reader.getContext()); |
Bruno Cardoso Lopes | fbff2fa | 2018-04-27 18:01:23 +0000 | [diff] [blame] | 1251 | |
| 1252 | // Protocols in the class extension belong to the class. |
| 1253 | if (NumProtoRefs > 0 && CD->ClassInterface && CD->IsClassExtension()) |
| 1254 | CD->ClassInterface->mergeClassExtensionProtocolList( |
| 1255 | (ObjCProtocolDecl *const *)ProtoRefs.data(), NumProtoRefs, |
| 1256 | Reader.getContext()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1257 | } |
| 1258 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1259 | void ASTDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1260 | VisitNamedDecl(CAD); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1261 | CAD->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1262 | } |
| 1263 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1264 | void ASTDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1265 | VisitNamedDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1266 | D->setAtLoc(ReadSourceLocation()); |
| 1267 | D->setLParenLoc(ReadSourceLocation()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1268 | QualType T = Record.readType(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1269 | TypeSourceInfo *TSI = GetTypeSourceInfo(); |
Douglas Gregor | 813a066 | 2015-06-19 18:14:38 +0000 | [diff] [blame] | 1270 | D->setType(T, TSI); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1271 | D->setPropertyAttributes( |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1272 | (ObjCPropertyDecl::PropertyAttributeKind)Record.readInt()); |
Fariborz Jahanian | 3bf0ded | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 1273 | D->setPropertyAttributesAsWritten( |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1274 | (ObjCPropertyDecl::PropertyAttributeKind)Record.readInt()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1275 | D->setPropertyImplementation( |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1276 | (ObjCPropertyDecl::PropertyControl)Record.readInt()); |
Argyrios Kyrtzidis | c6c4ec8 | 2017-03-17 00:49:42 +0000 | [diff] [blame] | 1277 | DeclarationName GetterName = Record.readDeclarationName(); |
| 1278 | SourceLocation GetterLoc = ReadSourceLocation(); |
| 1279 | D->setGetterName(GetterName.getObjCSelector(), GetterLoc); |
| 1280 | DeclarationName SetterName = Record.readDeclarationName(); |
| 1281 | SourceLocation SetterLoc = ReadSourceLocation(); |
| 1282 | D->setSetterName(SetterName.getObjCSelector(), SetterLoc); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1283 | D->setGetterMethodDecl(ReadDeclAs<ObjCMethodDecl>()); |
| 1284 | D->setSetterMethodDecl(ReadDeclAs<ObjCMethodDecl>()); |
| 1285 | D->setPropertyIvarDecl(ReadDeclAs<ObjCIvarDecl>()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1286 | } |
| 1287 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1288 | void ASTDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) { |
Argyrios Kyrtzidis | 067c407 | 2009-07-27 19:04:32 +0000 | [diff] [blame] | 1289 | VisitObjCContainerDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1290 | D->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1291 | } |
| 1292 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1293 | void ASTDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1294 | VisitObjCImplDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1295 | D->CategoryNameLoc = ReadSourceLocation(); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1296 | } |
| 1297 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1298 | void ASTDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1299 | VisitObjCImplDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1300 | D->setSuperClass(ReadDeclAs<ObjCInterfaceDecl>()); |
| 1301 | D->SuperLoc = ReadSourceLocation(); |
| 1302 | D->setIvarLBraceLoc(ReadSourceLocation()); |
| 1303 | D->setIvarRBraceLoc(ReadSourceLocation()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1304 | D->setHasNonZeroConstructors(Record.readInt()); |
| 1305 | D->setHasDestructors(Record.readInt()); |
| 1306 | D->NumIvarInitializers = Record.readInt(); |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 1307 | if (D->NumIvarInitializers) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1308 | D->IvarInitializers = ReadGlobalOffset(); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1309 | } |
| 1310 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1311 | void ASTDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1312 | VisitDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1313 | D->setAtLoc(ReadSourceLocation()); |
| 1314 | D->setPropertyDecl(ReadDeclAs<ObjCPropertyDecl>()); |
| 1315 | D->PropertyIvarDecl = ReadDeclAs<ObjCIvarDecl>(); |
| 1316 | D->IvarLoc = ReadSourceLocation(); |
Adrian Prantl | 2073dd2 | 2019-11-04 14:28:14 -0800 | [diff] [blame^] | 1317 | D->setGetterMethodDecl(ReadDeclAs<ObjCMethodDecl>()); |
| 1318 | D->setSetterMethodDecl(ReadDeclAs<ObjCMethodDecl>()); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1319 | D->setGetterCXXConstructor(Record.readExpr()); |
| 1320 | D->setSetterCXXAssignment(Record.readExpr()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1321 | } |
| 1322 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1323 | void ASTDeclReader::VisitFieldDecl(FieldDecl *FD) { |
Argyrios Kyrtzidis | 560ac97 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 1324 | VisitDeclaratorDecl(FD); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1325 | FD->Mutable = Record.readInt(); |
Richard Smith | 6b8e3c0 | 2017-08-28 00:28:14 +0000 | [diff] [blame] | 1326 | |
| 1327 | if (auto ISK = static_cast<FieldDecl::InitStorageKind>(Record.readInt())) { |
| 1328 | FD->InitStorage.setInt(ISK); |
| 1329 | FD->InitStorage.setPointer(ISK == FieldDecl::ISK_CapturedVLAType |
| 1330 | ? Record.readType().getAsOpaquePtr() |
| 1331 | : Record.readExpr()); |
Richard Smith | 2b01318 | 2012-06-10 03:12:00 +0000 | [diff] [blame] | 1332 | } |
Richard Smith | 6b8e3c0 | 2017-08-28 00:28:14 +0000 | [diff] [blame] | 1333 | |
| 1334 | if (auto *BW = Record.readExpr()) |
| 1335 | FD->setBitWidth(BW); |
| 1336 | |
Argyrios Kyrtzidis | 6685e8a | 2010-07-04 21:44:35 +0000 | [diff] [blame] | 1337 | if (!FD->getDeclName()) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1338 | if (auto *Tmpl = ReadDeclAs<FieldDecl>()) |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1339 | Reader.getContext().setInstantiatedFromUnnamedFieldDecl(FD, Tmpl); |
Argyrios Kyrtzidis | 6685e8a | 2010-07-04 21:44:35 +0000 | [diff] [blame] | 1340 | } |
Richard Smith | 0b87e07 | 2013-10-07 08:02:11 +0000 | [diff] [blame] | 1341 | mergeMergeable(FD); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1342 | } |
| 1343 | |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 1344 | void ASTDeclReader::VisitMSPropertyDecl(MSPropertyDecl *PD) { |
| 1345 | VisitDeclaratorDecl(PD); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1346 | PD->GetterId = Record.getIdentifierInfo(); |
| 1347 | PD->SetterId = Record.getIdentifierInfo(); |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 1348 | } |
| 1349 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 1350 | void ASTDeclReader::VisitIndirectFieldDecl(IndirectFieldDecl *FD) { |
| 1351 | VisitValueDecl(FD); |
| 1352 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1353 | FD->ChainingSize = Record.readInt(); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 1354 | assert(FD->ChainingSize >= 2 && "Anonymous chaining must be >= 2"); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1355 | FD->Chaining = new (Reader.getContext())NamedDecl*[FD->ChainingSize]; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 1356 | |
| 1357 | for (unsigned I = 0; I != FD->ChainingSize; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1358 | FD->Chaining[I] = ReadDeclAs<NamedDecl>(); |
Richard Smith | 8cbd895 | 2015-08-04 02:05:09 +0000 | [diff] [blame] | 1359 | |
| 1360 | mergeMergeable(FD); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 1361 | } |
| 1362 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1363 | ASTDeclReader::RedeclarableResult ASTDeclReader::VisitVarDeclImpl(VarDecl *VD) { |
Douglas Gregor | b8c6f1e | 2012-01-04 17:21:36 +0000 | [diff] [blame] | 1364 | RedeclarableResult Redecl = VisitRedeclarable(VD); |
Douglas Gregor | 3e30010 | 2011-10-26 17:53:41 +0000 | [diff] [blame] | 1365 | VisitDeclaratorDecl(VD); |
Rafael Espindola | 6ae7e50 | 2013-04-03 19:27:57 +0000 | [diff] [blame] | 1366 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1367 | VD->VarDeclBits.SClass = (StorageClass)Record.readInt(); |
| 1368 | VD->VarDeclBits.TSCSpec = Record.readInt(); |
| 1369 | VD->VarDeclBits.InitStyle = Record.readInt(); |
Erik Pilkington | 1e36882 | 2019-01-04 18:33:06 +0000 | [diff] [blame] | 1370 | VD->VarDeclBits.ARCPseudoStrong = Record.readInt(); |
David Majnemer | fa7bc78 | 2015-05-19 00:57:16 +0000 | [diff] [blame] | 1371 | if (!isa<ParmVarDecl>(VD)) { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1372 | VD->NonParmVarDeclBits.IsThisDeclarationADemotedDefinition = |
| 1373 | Record.readInt(); |
| 1374 | VD->NonParmVarDeclBits.ExceptionVar = Record.readInt(); |
Taiju Tsuiki | 3be68e1 | 2018-06-19 05:35:30 +0000 | [diff] [blame] | 1375 | VD->NonParmVarDeclBits.NRVOVariable = Record.readInt(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1376 | VD->NonParmVarDeclBits.CXXForRangeDecl = Record.readInt(); |
George Karpenkov | ec38cf7 | 2018-03-29 00:56:24 +0000 | [diff] [blame] | 1377 | VD->NonParmVarDeclBits.ObjCForDecl = Record.readInt(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1378 | VD->NonParmVarDeclBits.IsInline = Record.readInt(); |
| 1379 | VD->NonParmVarDeclBits.IsInlineSpecified = Record.readInt(); |
| 1380 | VD->NonParmVarDeclBits.IsConstexpr = Record.readInt(); |
| 1381 | VD->NonParmVarDeclBits.IsInitCapture = Record.readInt(); |
| 1382 | VD->NonParmVarDeclBits.PreviousDeclInSameBlockScope = Record.readInt(); |
Alexey Bataev | 5622323 | 2017-06-09 13:40:18 +0000 | [diff] [blame] | 1383 | VD->NonParmVarDeclBits.ImplicitParamKind = Record.readInt(); |
Akira Hatanaka | 8e57b07 | 2018-10-01 21:51:28 +0000 | [diff] [blame] | 1384 | VD->NonParmVarDeclBits.EscapingByref = Record.readInt(); |
David Majnemer | fa7bc78 | 2015-05-19 00:57:16 +0000 | [diff] [blame] | 1385 | } |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1386 | auto VarLinkage = Linkage(Record.readInt()); |
Richard Smith | 541b38b | 2013-09-20 01:15:31 +0000 | [diff] [blame] | 1387 | VD->setCachedLinkage(VarLinkage); |
| 1388 | |
| 1389 | // Reconstruct the one piece of the IdentifierNamespace that we need. |
Ted Kremenek | a683f63 | 2014-02-11 06:29:29 +0000 | [diff] [blame] | 1390 | if (VD->getStorageClass() == SC_Extern && VarLinkage != NoLinkage && |
Richard Smith | 541b38b | 2013-09-20 01:15:31 +0000 | [diff] [blame] | 1391 | VD->getLexicalDeclContext()->isFunctionOrMethod()) |
| 1392 | VD->setLocalExternDecl(); |
Rafael Espindola | 50df3a0 | 2013-05-25 17:16:20 +0000 | [diff] [blame] | 1393 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1394 | if (uint64_t Val = Record.readInt()) { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1395 | VD->setInit(Record.readExpr()); |
Richard Smith | 2b4fa53 | 2019-09-29 05:08:46 +0000 | [diff] [blame] | 1396 | if (Val > 1) { |
Richard Smith | d0b4dd6 | 2011-12-19 06:19:21 +0000 | [diff] [blame] | 1397 | EvaluatedStmt *Eval = VD->ensureEvaluatedStmt(); |
| 1398 | Eval->CheckedICE = true; |
Richard Smith | 2b4fa53 | 2019-09-29 05:08:46 +0000 | [diff] [blame] | 1399 | Eval->IsICE = (Val & 1) != 0; |
| 1400 | Eval->HasConstantDestruction = (Val & 4) != 0; |
Richard Smith | d0b4dd6 | 2011-12-19 06:19:21 +0000 | [diff] [blame] | 1401 | } |
| 1402 | } |
Argyrios Kyrtzidis | cdb8b3f | 2010-07-04 21:44:00 +0000 | [diff] [blame] | 1403 | |
Akira Hatanaka | 9978da3 | 2018-08-10 15:09:24 +0000 | [diff] [blame] | 1404 | if (VD->hasAttr<BlocksAttr>() && VD->getType()->getAsCXXRecordDecl()) { |
| 1405 | Expr *CopyExpr = Record.readExpr(); |
| 1406 | if (CopyExpr) |
| 1407 | Reader.getContext().setBlockVarCopyInit(VD, CopyExpr, Record.readInt()); |
| 1408 | } |
| 1409 | |
Richard Smith | a465362 | 2017-09-06 20:01:14 +0000 | [diff] [blame] | 1410 | if (VD->getStorageDuration() == SD_Static && Record.readInt()) |
| 1411 | Reader.DefinitionSource[VD] = Loc.F->Kind == ModuleKind::MK_MainFile; |
| 1412 | |
Larisse Voufo | d8dd97c | 2013-08-14 03:09:19 +0000 | [diff] [blame] | 1413 | enum VarKind { |
| 1414 | VarNotTemplate = 0, VarTemplate, StaticDataMemberSpecialization |
| 1415 | }; |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1416 | switch ((VarKind)Record.readInt()) { |
Larisse Voufo | d8dd97c | 2013-08-14 03:09:19 +0000 | [diff] [blame] | 1417 | case VarNotTemplate: |
Richard Smith | 9b88a4c | 2015-07-27 05:40:23 +0000 | [diff] [blame] | 1418 | // Only true variables (not parameters or implicit parameters) can be |
| 1419 | // merged; the other kinds are not really redeclarable at all. |
Richard Smith | 0144f51 | 2015-08-22 02:09:38 +0000 | [diff] [blame] | 1420 | if (!isa<ParmVarDecl>(VD) && !isa<ImplicitParamDecl>(VD) && |
| 1421 | !isa<VarTemplateSpecializationDecl>(VD)) |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 1422 | mergeRedeclarable(VD, Redecl); |
Larisse Voufo | d8dd97c | 2013-08-14 03:09:19 +0000 | [diff] [blame] | 1423 | break; |
| 1424 | case VarTemplate: |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 1425 | // Merged when we merge the template. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1426 | VD->setDescribedVarTemplate(ReadDeclAs<VarTemplateDecl>()); |
Larisse Voufo | d8dd97c | 2013-08-14 03:09:19 +0000 | [diff] [blame] | 1427 | break; |
| 1428 | case StaticDataMemberSpecialization: { // HasMemberSpecializationInfo. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1429 | auto *Tmpl = ReadDeclAs<VarDecl>(); |
| 1430 | auto TSK = (TemplateSpecializationKind)Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1431 | SourceLocation POI = ReadSourceLocation(); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1432 | Reader.getContext().setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI); |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 1433 | mergeRedeclarable(VD, Redecl); |
Larisse Voufo | d8dd97c | 2013-08-14 03:09:19 +0000 | [diff] [blame] | 1434 | break; |
| 1435 | } |
Argyrios Kyrtzidis | cdb8b3f | 2010-07-04 21:44:00 +0000 | [diff] [blame] | 1436 | } |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1437 | |
| 1438 | return Redecl; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1439 | } |
| 1440 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1441 | void ASTDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1442 | VisitVarDecl(PD); |
| 1443 | } |
| 1444 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1445 | void ASTDeclReader::VisitParmVarDecl(ParmVarDecl *PD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1446 | VisitVarDecl(PD); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1447 | unsigned isObjCMethodParam = Record.readInt(); |
| 1448 | unsigned scopeDepth = Record.readInt(); |
| 1449 | unsigned scopeIndex = Record.readInt(); |
| 1450 | unsigned declQualifier = Record.readInt(); |
John McCall | 8249083 | 2011-05-02 00:30:12 +0000 | [diff] [blame] | 1451 | if (isObjCMethodParam) { |
| 1452 | assert(scopeDepth == 0); |
| 1453 | PD->setObjCMethodScopeInfo(scopeIndex); |
| 1454 | PD->ParmVarDeclBits.ScopeDepthOrObjCQuals = declQualifier; |
| 1455 | } else { |
| 1456 | PD->setScopeInfo(scopeDepth, scopeIndex); |
| 1457 | } |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1458 | PD->ParmVarDeclBits.IsKNRPromoted = Record.readInt(); |
| 1459 | PD->ParmVarDeclBits.HasInheritedDefaultArg = Record.readInt(); |
| 1460 | if (Record.readInt()) // hasUninstantiatedDefaultArg. |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1461 | PD->setUninstantiatedDefaultArg(Record.readExpr()); |
Richard Smith | bf78e64 | 2013-06-24 22:51:00 +0000 | [diff] [blame] | 1462 | |
| 1463 | // FIXME: If this is a redeclaration of a function from another module, handle |
| 1464 | // inheritance of default arguments. |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1465 | } |
| 1466 | |
Richard Smith | 7b76d81 | 2016-08-12 02:21:25 +0000 | [diff] [blame] | 1467 | void ASTDeclReader::VisitDecompositionDecl(DecompositionDecl *DD) { |
| 1468 | VisitVarDecl(DD); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1469 | auto **BDs = DD->getTrailingObjects<BindingDecl *>(); |
Richard Smith | 0353e5a | 2019-05-25 01:04:17 +0000 | [diff] [blame] | 1470 | for (unsigned I = 0; I != DD->NumBindings; ++I) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1471 | BDs[I] = ReadDeclAs<BindingDecl>(); |
Richard Smith | 0353e5a | 2019-05-25 01:04:17 +0000 | [diff] [blame] | 1472 | BDs[I]->setDecomposedDecl(DD); |
| 1473 | } |
Richard Smith | 7b76d81 | 2016-08-12 02:21:25 +0000 | [diff] [blame] | 1474 | } |
| 1475 | |
| 1476 | void ASTDeclReader::VisitBindingDecl(BindingDecl *BD) { |
| 1477 | VisitValueDecl(BD); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1478 | BD->Binding = Record.readExpr(); |
Richard Smith | 7b76d81 | 2016-08-12 02:21:25 +0000 | [diff] [blame] | 1479 | } |
| 1480 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1481 | void ASTDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1482 | VisitDecl(AD); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1483 | AD->setAsmString(cast<StringLiteral>(Record.readExpr())); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1484 | AD->setRParenLoc(ReadSourceLocation()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1485 | } |
| 1486 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1487 | void ASTDeclReader::VisitBlockDecl(BlockDecl *BD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1488 | VisitDecl(BD); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1489 | BD->setBody(cast_or_null<CompoundStmt>(Record.readStmt())); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1490 | BD->setSignatureAsWritten(GetTypeSourceInfo()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1491 | unsigned NumParams = Record.readInt(); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1492 | SmallVector<ParmVarDecl *, 16> Params; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1493 | Params.reserve(NumParams); |
| 1494 | for (unsigned I = 0; I != NumParams; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1495 | Params.push_back(ReadDeclAs<ParmVarDecl>()); |
David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 1496 | BD->setParams(Params); |
John McCall | c63de66 | 2011-02-02 13:00:07 +0000 | [diff] [blame] | 1497 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1498 | BD->setIsVariadic(Record.readInt()); |
| 1499 | BD->setBlockMissingReturnType(Record.readInt()); |
| 1500 | BD->setIsConversionFromLambda(Record.readInt()); |
Akira Hatanaka | db49a1f | 2018-08-01 23:51:53 +0000 | [diff] [blame] | 1501 | BD->setDoesNotEscape(Record.readInt()); |
Akira Hatanaka | c5792aa | 2019-02-27 18:17:16 +0000 | [diff] [blame] | 1502 | BD->setCanAvoidCopyToHeap(Record.readInt()); |
John McCall | cf6ce28 | 2012-04-13 17:33:29 +0000 | [diff] [blame] | 1503 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1504 | bool capturesCXXThis = Record.readInt(); |
| 1505 | unsigned numCaptures = Record.readInt(); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1506 | SmallVector<BlockDecl::Capture, 16> captures; |
John McCall | 351762c | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 1507 | captures.reserve(numCaptures); |
| 1508 | for (unsigned i = 0; i != numCaptures; ++i) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1509 | auto *decl = ReadDeclAs<VarDecl>(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1510 | unsigned flags = Record.readInt(); |
John McCall | 351762c | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 1511 | bool byRef = (flags & 1); |
| 1512 | bool nested = (flags & 2); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1513 | Expr *copyExpr = ((flags & 4) ? Record.readExpr() : nullptr); |
John McCall | 351762c | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 1514 | |
| 1515 | captures.push_back(BlockDecl::Capture(decl, byRef, nested, copyExpr)); |
| 1516 | } |
Benjamin Kramer | b40e4af | 2015-08-05 09:40:35 +0000 | [diff] [blame] | 1517 | BD->setCaptures(Reader.getContext(), captures, capturesCXXThis); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1518 | } |
| 1519 | |
Ben Langmuir | ce914fc | 2013-05-03 19:20:19 +0000 | [diff] [blame] | 1520 | void ASTDeclReader::VisitCapturedDecl(CapturedDecl *CD) { |
| 1521 | VisitDecl(CD); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1522 | unsigned ContextParamPos = Record.readInt(); |
| 1523 | CD->setNothrow(Record.readInt() != 0); |
Ben Langmuir | ce914fc | 2013-05-03 19:20:19 +0000 | [diff] [blame] | 1524 | // Body is set by VisitCapturedStmt. |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1525 | for (unsigned I = 0; I < CD->NumParams; ++I) { |
| 1526 | if (I != ContextParamPos) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1527 | CD->setParam(I, ReadDeclAs<ImplicitParamDecl>()); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1528 | else |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1529 | CD->setContextParam(I, ReadDeclAs<ImplicitParamDecl>()); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1530 | } |
Tareq A. Siraj | 6dfa25a | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 1531 | } |
| 1532 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1533 | void ASTDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1534 | VisitDecl(D); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1535 | D->setLanguage((LinkageSpecDecl::LanguageIDs)Record.readInt()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1536 | D->setExternLoc(ReadSourceLocation()); |
| 1537 | D->setRBraceLoc(ReadSourceLocation()); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1538 | } |
| 1539 | |
Richard Smith | 8df390f | 2016-09-08 23:14:54 +0000 | [diff] [blame] | 1540 | void ASTDeclReader::VisitExportDecl(ExportDecl *D) { |
| 1541 | VisitDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1542 | D->RBraceLoc = ReadSourceLocation(); |
Richard Smith | 8df390f | 2016-09-08 23:14:54 +0000 | [diff] [blame] | 1543 | } |
| 1544 | |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1545 | void ASTDeclReader::VisitLabelDecl(LabelDecl *D) { |
| 1546 | VisitNamedDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1547 | D->setLocStart(ReadSourceLocation()); |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1548 | } |
| 1549 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1550 | void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl *D) { |
Douglas Gregor | e57e752 | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 1551 | RedeclarableResult Redecl = VisitRedeclarable(D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1552 | VisitNamedDecl(D); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1553 | D->setInline(Record.readInt()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1554 | D->LocStart = ReadSourceLocation(); |
| 1555 | D->RBraceLoc = ReadSourceLocation(); |
Douglas Gregor | cfe7dc6 | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 1556 | |
Richard Smith | 15e32fd | 2015-03-17 02:23:11 +0000 | [diff] [blame] | 1557 | // Defer loading the anonymous namespace until we've finished merging |
| 1558 | // this namespace; loading it might load a later declaration of the |
| 1559 | // same namespace, and we have an invariant that older declarations |
| 1560 | // get merged before newer ones try to merge. |
| 1561 | GlobalDeclID AnonNamespace = 0; |
Douglas Gregor | e57e752 | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 1562 | if (Redecl.getFirstID() == ThisDeclID) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1563 | AnonNamespace = ReadDeclID(); |
Douglas Gregor | e57e752 | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 1564 | } else { |
| 1565 | // Link this namespace back to the first declaration, which has already |
| 1566 | // been deserialized. |
Rafael Espindola | 8db352d | 2013-10-17 15:37:26 +0000 | [diff] [blame] | 1567 | D->AnonOrFirstNamespaceAndInline.setPointer(D->getFirstDecl()); |
Douglas Gregor | e57e752 | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 1568 | } |
Richard Smith | 5e9e56a | 2014-07-15 03:37:06 +0000 | [diff] [blame] | 1569 | |
| 1570 | mergeRedeclarable(D, Redecl); |
Richard Smith | 15e32fd | 2015-03-17 02:23:11 +0000 | [diff] [blame] | 1571 | |
| 1572 | if (AnonNamespace) { |
| 1573 | // Each module has its own anonymous namespace, which is disjoint from |
| 1574 | // any other module's anonymous namespaces, so don't attach the anonymous |
| 1575 | // namespace at all. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1576 | auto *Anon = cast<NamespaceDecl>(Reader.GetDecl(AnonNamespace)); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1577 | if (!Record.isModule()) |
Richard Smith | 15e32fd | 2015-03-17 02:23:11 +0000 | [diff] [blame] | 1578 | D->setAnonymousNamespace(Anon); |
| 1579 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1580 | } |
| 1581 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1582 | void ASTDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { |
Richard Smith | f463436 | 2014-09-03 23:11:22 +0000 | [diff] [blame] | 1583 | RedeclarableResult Redecl = VisitRedeclarable(D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1584 | VisitNamedDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1585 | D->NamespaceLoc = ReadSourceLocation(); |
| 1586 | D->IdentLoc = ReadSourceLocation(); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1587 | D->QualifierLoc = Record.readNestedNameSpecifierLoc(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1588 | D->Namespace = ReadDeclAs<NamedDecl>(); |
Richard Smith | f463436 | 2014-09-03 23:11:22 +0000 | [diff] [blame] | 1589 | mergeRedeclarable(D, Redecl); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1590 | } |
| 1591 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1592 | void ASTDeclReader::VisitUsingDecl(UsingDecl *D) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1593 | VisitNamedDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1594 | D->setUsingLoc(ReadSourceLocation()); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1595 | D->QualifierLoc = Record.readNestedNameSpecifierLoc(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1596 | ReadDeclarationNameLoc(D->DNLoc, D->getDeclName()); |
| 1597 | D->FirstUsingShadow.setPointer(ReadDeclAs<UsingShadowDecl>()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1598 | D->setTypename(Record.readInt()); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1599 | if (auto *Pattern = ReadDeclAs<NamedDecl>()) |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1600 | Reader.getContext().setInstantiatedFromUsingDecl(D, Pattern); |
Richard Smith | 32952e1 | 2014-10-14 02:00:47 +0000 | [diff] [blame] | 1601 | mergeMergeable(D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1602 | } |
| 1603 | |
Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 1604 | void ASTDeclReader::VisitUsingPackDecl(UsingPackDecl *D) { |
| 1605 | VisitNamedDecl(D); |
| 1606 | D->InstantiatedFrom = ReadDeclAs<NamedDecl>(); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1607 | auto **Expansions = D->getTrailingObjects<NamedDecl *>(); |
Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 1608 | for (unsigned I = 0; I != D->NumExpansions; ++I) |
| 1609 | Expansions[I] = ReadDeclAs<NamedDecl>(); |
| 1610 | mergeMergeable(D); |
| 1611 | } |
| 1612 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1613 | void ASTDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) { |
Richard Smith | fd8634a | 2013-10-23 02:17:46 +0000 | [diff] [blame] | 1614 | RedeclarableResult Redecl = VisitRedeclarable(D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1615 | VisitNamedDecl(D); |
Richard Smith | a263c34 | 2018-01-06 01:07:05 +0000 | [diff] [blame] | 1616 | D->Underlying = ReadDeclAs<NamedDecl>(); |
| 1617 | D->IdentifierNamespace = Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1618 | D->UsingOrNextShadow = ReadDeclAs<NamedDecl>(); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1619 | auto *Pattern = ReadDeclAs<UsingShadowDecl>(); |
Argyrios Kyrtzidis | 6685e8a | 2010-07-04 21:44:35 +0000 | [diff] [blame] | 1620 | if (Pattern) |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1621 | Reader.getContext().setInstantiatedFromUsingShadowDecl(D, Pattern); |
Richard Smith | fd8634a | 2013-10-23 02:17:46 +0000 | [diff] [blame] | 1622 | mergeRedeclarable(D, Redecl); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1623 | } |
| 1624 | |
Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 1625 | void ASTDeclReader::VisitConstructorUsingShadowDecl( |
| 1626 | ConstructorUsingShadowDecl *D) { |
| 1627 | VisitUsingShadowDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1628 | D->NominatedBaseClassShadowDecl = ReadDeclAs<ConstructorUsingShadowDecl>(); |
| 1629 | D->ConstructedBaseClassShadowDecl = ReadDeclAs<ConstructorUsingShadowDecl>(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1630 | D->IsVirtual = Record.readInt(); |
Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 1631 | } |
| 1632 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1633 | void ASTDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1634 | VisitNamedDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1635 | D->UsingLoc = ReadSourceLocation(); |
| 1636 | D->NamespaceLoc = ReadSourceLocation(); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1637 | D->QualifierLoc = Record.readNestedNameSpecifierLoc(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1638 | D->NominatedNamespace = ReadDeclAs<NamedDecl>(); |
| 1639 | D->CommonAncestor = ReadDeclAs<DeclContext>(); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1640 | } |
| 1641 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1642 | void ASTDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1643 | VisitValueDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1644 | D->setUsingLoc(ReadSourceLocation()); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1645 | D->QualifierLoc = Record.readNestedNameSpecifierLoc(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1646 | ReadDeclarationNameLoc(D->DNLoc, D->getDeclName()); |
Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 1647 | D->EllipsisLoc = ReadSourceLocation(); |
Richard Smith | 32952e1 | 2014-10-14 02:00:47 +0000 | [diff] [blame] | 1648 | mergeMergeable(D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1649 | } |
| 1650 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1651 | void ASTDeclReader::VisitUnresolvedUsingTypenameDecl( |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1652 | UnresolvedUsingTypenameDecl *D) { |
| 1653 | VisitTypeDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1654 | D->TypenameLocation = ReadSourceLocation(); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1655 | D->QualifierLoc = Record.readNestedNameSpecifierLoc(); |
Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 1656 | D->EllipsisLoc = ReadSourceLocation(); |
Richard Smith | 32952e1 | 2014-10-14 02:00:47 +0000 | [diff] [blame] | 1657 | mergeMergeable(D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1658 | } |
| 1659 | |
Argyrios Kyrtzidis | 8b200a5 | 2010-10-24 17:26:27 +0000 | [diff] [blame] | 1660 | void ASTDeclReader::ReadCXXDefinitionData( |
David Blaikie | 1ac9c98 | 2017-04-11 21:13:37 +0000 | [diff] [blame] | 1661 | struct CXXRecordDecl::DefinitionData &Data, const CXXRecordDecl *D) { |
Richard Smith | 91aeacc | 2019-10-11 00:29:04 +0000 | [diff] [blame] | 1662 | #define FIELD(Name, Width, Merge) \ |
| 1663 | Data.Name = Record.readInt(); |
| 1664 | #include "clang/AST/CXXRecordDeclDefinitionBits.def" |
| 1665 | |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 1666 | // Note: the caller has deserialized the IsLambda bit already. |
Richard Trieu | b6adf54 | 2017-02-18 02:09:28 +0000 | [diff] [blame] | 1667 | Data.ODRHash = Record.readInt(); |
Richard Trieu | fd1acbb | 2017-04-11 21:31:00 +0000 | [diff] [blame] | 1668 | Data.HasODRHash = true; |
Anders Carlsson | 703d6e6 | 2011-01-22 18:11:02 +0000 | [diff] [blame] | 1669 | |
Richard Smith | cd4a7a4 | 2017-09-07 00:55:55 +0000 | [diff] [blame] | 1670 | if (Record.readInt()) |
| 1671 | Reader.DefinitionSource[D] = Loc.F->Kind == ModuleKind::MK_MainFile; |
David Blaikie | 1ac9c98 | 2017-04-11 21:13:37 +0000 | [diff] [blame] | 1672 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1673 | Data.NumBases = Record.readInt(); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 1674 | if (Data.NumBases) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1675 | Data.Bases = ReadGlobalOffset(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1676 | Data.NumVBases = Record.readInt(); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 1677 | if (Data.NumVBases) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1678 | Data.VBases = ReadGlobalOffset(); |
| 1679 | |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1680 | Record.readUnresolvedSet(Data.Conversions); |
Richard Smith | 91aeacc | 2019-10-11 00:29:04 +0000 | [diff] [blame] | 1681 | Data.ComputedVisibleConversions = Record.readInt(); |
| 1682 | if (Data.ComputedVisibleConversions) |
| 1683 | Record.readUnresolvedSet(Data.VisibleConversions); |
Argyrios Kyrtzidis | 8b200a5 | 2010-10-24 17:26:27 +0000 | [diff] [blame] | 1684 | assert(Data.Definition && "Data.Definition should be already set!"); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1685 | Data.FirstFriend = ReadDeclID(); |
Richard Smith | 9dd9f03 | 2013-08-30 00:23:29 +0000 | [diff] [blame] | 1686 | |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 1687 | if (Data.IsLambda) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1688 | using Capture = LambdaCapture; |
| 1689 | |
| 1690 | auto &Lambda = static_cast<CXXRecordDecl::LambdaDefinitionData &>(Data); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1691 | Lambda.Dependent = Record.readInt(); |
| 1692 | Lambda.IsGenericLambda = Record.readInt(); |
| 1693 | Lambda.CaptureDefault = Record.readInt(); |
| 1694 | Lambda.NumCaptures = Record.readInt(); |
| 1695 | Lambda.NumExplicitCaptures = Record.readInt(); |
Michael Liao | 243ebfb | 2019-10-19 00:15:19 +0000 | [diff] [blame] | 1696 | Lambda.HasKnownInternalLinkage = Record.readInt(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1697 | Lambda.ManglingNumber = Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1698 | Lambda.ContextDecl = ReadDeclID(); |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 1699 | Lambda.Captures = (Capture *)Reader.getContext().Allocate( |
| 1700 | sizeof(Capture) * Lambda.NumCaptures); |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 1701 | Capture *ToCapture = Lambda.Captures; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1702 | Lambda.MethodTyInfo = GetTypeSourceInfo(); |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 1703 | for (unsigned I = 0, N = Lambda.NumCaptures; I != N; ++I) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1704 | SourceLocation Loc = ReadSourceLocation(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1705 | bool IsImplicit = Record.readInt(); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1706 | auto Kind = static_cast<LambdaCaptureKind>(Record.readInt()); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 1707 | switch (Kind) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1708 | case LCK_StarThis: |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 1709 | case LCK_This: |
Alexey Bataev | 39c81e2 | 2014-08-28 04:28:19 +0000 | [diff] [blame] | 1710 | case LCK_VLAType: |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 1711 | *ToCapture++ = Capture(Loc, IsImplicit, Kind, nullptr,SourceLocation()); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 1712 | break; |
| 1713 | case LCK_ByCopy: |
Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 1714 | case LCK_ByRef: |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1715 | auto *Var = ReadDeclAs<VarDecl>(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1716 | SourceLocation EllipsisLoc = ReadSourceLocation(); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 1717 | *ToCapture++ = Capture(Loc, IsImplicit, Kind, Var, EllipsisLoc); |
| 1718 | break; |
| 1719 | } |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 1720 | } |
| 1721 | } |
Argyrios Kyrtzidis | 8b200a5 | 2010-10-24 17:26:27 +0000 | [diff] [blame] | 1722 | } |
| 1723 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1724 | void ASTDeclReader::MergeDefinitionData( |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 1725 | CXXRecordDecl *D, struct CXXRecordDecl::DefinitionData &&MergeDD) { |
Richard Smith | b648399 | 2016-05-17 22:44:15 +0000 | [diff] [blame] | 1726 | assert(D->DefinitionData && |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 1727 | "merging class definition into non-definition"); |
Richard Smith | b648399 | 2016-05-17 22:44:15 +0000 | [diff] [blame] | 1728 | auto &DD = *D->DefinitionData; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1729 | |
Richard Smith | 0279375 | 2015-03-27 21:16:39 +0000 | [diff] [blame] | 1730 | if (DD.Definition != MergeDD.Definition) { |
Richard Smith | 97100e3 | 2015-06-20 00:22:34 +0000 | [diff] [blame] | 1731 | // Track that we merged the definitions. |
| 1732 | Reader.MergedDeclContexts.insert(std::make_pair(MergeDD.Definition, |
| 1733 | DD.Definition)); |
| 1734 | Reader.PendingDefinitions.erase(MergeDD.Definition); |
Erich Keane | f92f31c | 2018-08-01 20:48:16 +0000 | [diff] [blame] | 1735 | MergeDD.Definition->setCompleteDefinition(false); |
Richard Smith | 6561f92 | 2016-09-12 21:06:40 +0000 | [diff] [blame] | 1736 | Reader.mergeDefinitionVisibility(DD.Definition, MergeDD.Definition); |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 1737 | assert(Reader.Lookups.find(MergeDD.Definition) == Reader.Lookups.end() && |
| 1738 | "already loaded pending lookups for merged definition"); |
Richard Smith | 0279375 | 2015-03-27 21:16:39 +0000 | [diff] [blame] | 1739 | } |
| 1740 | |
Richard Smith | 2a9e5c5 | 2015-02-03 03:32:14 +0000 | [diff] [blame] | 1741 | auto PFDI = Reader.PendingFakeDefinitionData.find(&DD); |
| 1742 | if (PFDI != Reader.PendingFakeDefinitionData.end() && |
| 1743 | PFDI->second == ASTReader::PendingFakeDefinitionKind::Fake) { |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 1744 | // We faked up this definition data because we found a class for which we'd |
| 1745 | // not yet loaded the definition. Replace it with the real thing now. |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 1746 | assert(!DD.IsLambda && !MergeDD.IsLambda && "faked up lambda definition?"); |
Richard Smith | 2a9e5c5 | 2015-02-03 03:32:14 +0000 | [diff] [blame] | 1747 | PFDI->second = ASTReader::PendingFakeDefinitionKind::FakeLoaded; |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 1748 | |
| 1749 | // Don't change which declaration is the definition; that is required |
| 1750 | // to be invariant once we select it. |
| 1751 | auto *Def = DD.Definition; |
| 1752 | DD = std::move(MergeDD); |
| 1753 | DD.Definition = Def; |
| 1754 | return; |
| 1755 | } |
| 1756 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1757 | bool DetectedOdrViolation = false; |
Richard Smith | 91aeacc | 2019-10-11 00:29:04 +0000 | [diff] [blame] | 1758 | |
| 1759 | #define FIELD(Name, Width, Merge) Merge(Name) |
| 1760 | #define MERGE_OR(Field) DD.Field |= MergeDD.Field; |
| 1761 | #define NO_MERGE(Field) \ |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1762 | DetectedOdrViolation |= DD.Field != MergeDD.Field; \ |
Richard Smith | 91aeacc | 2019-10-11 00:29:04 +0000 | [diff] [blame] | 1763 | MERGE_OR(Field) |
| 1764 | #include "clang/AST/CXXRecordDeclDefinitionBits.def" |
| 1765 | NO_MERGE(IsLambda) |
| 1766 | #undef NO_MERGE |
| 1767 | #undef MERGE_OR |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1768 | |
| 1769 | if (DD.NumBases != MergeDD.NumBases || DD.NumVBases != MergeDD.NumVBases) |
| 1770 | DetectedOdrViolation = true; |
| 1771 | // FIXME: Issue a diagnostic if the base classes don't match when we come |
| 1772 | // to lazily load them. |
| 1773 | |
| 1774 | // FIXME: Issue a diagnostic if the list of conversion functions doesn't |
| 1775 | // match when we come to lazily load them. |
| 1776 | if (MergeDD.ComputedVisibleConversions && !DD.ComputedVisibleConversions) { |
| 1777 | DD.VisibleConversions = std::move(MergeDD.VisibleConversions); |
| 1778 | DD.ComputedVisibleConversions = true; |
| 1779 | } |
| 1780 | |
| 1781 | // FIXME: Issue a diagnostic if FirstFriend doesn't match when we come to |
| 1782 | // lazily load it. |
| 1783 | |
| 1784 | if (DD.IsLambda) { |
| 1785 | // FIXME: ODR-checking for merging lambdas (this happens, for instance, |
| 1786 | // when they occur within the body of a function template specialization). |
| 1787 | } |
| 1788 | |
Richard Trieu | fd1acbb | 2017-04-11 21:31:00 +0000 | [diff] [blame] | 1789 | if (D->getODRHash() != MergeDD.ODRHash) { |
| 1790 | DetectedOdrViolation = true; |
| 1791 | } |
| 1792 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1793 | if (DetectedOdrViolation) |
Richard Trieu | e13eabe | 2017-09-30 02:19:17 +0000 | [diff] [blame] | 1794 | Reader.PendingOdrMergeFailures[DD.Definition].push_back( |
| 1795 | {MergeDD.Definition, &MergeDD}); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1796 | } |
| 1797 | |
Richard Smith | 2a9e5c5 | 2015-02-03 03:32:14 +0000 | [diff] [blame] | 1798 | void ASTDeclReader::ReadCXXRecordDefinition(CXXRecordDecl *D, bool Update) { |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1799 | struct CXXRecordDecl::DefinitionData *DD; |
| 1800 | ASTContext &C = Reader.getContext(); |
| 1801 | |
| 1802 | // Determine whether this is a lambda closure type, so that we can |
| 1803 | // allocate the appropriate DefinitionData structure. |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1804 | bool IsLambda = Record.readInt(); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1805 | if (IsLambda) |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 1806 | DD = new (C) CXXRecordDecl::LambdaDefinitionData(D, nullptr, false, false, |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1807 | LCD_None); |
| 1808 | else |
| 1809 | DD = new (C) struct CXXRecordDecl::DefinitionData(D); |
| 1810 | |
Volodymyr Sapsai | 8a5943f | 2018-03-21 21:28:54 +0000 | [diff] [blame] | 1811 | CXXRecordDecl *Canon = D->getCanonicalDecl(); |
| 1812 | // Set decl definition data before reading it, so that during deserialization |
| 1813 | // when we read CXXRecordDecl, it already has definition data and we don't |
| 1814 | // set fake one. |
| 1815 | if (!Canon->DefinitionData) |
| 1816 | Canon->DefinitionData = DD; |
| 1817 | D->DefinitionData = Canon->DefinitionData; |
David Blaikie | 1ac9c98 | 2017-04-11 21:13:37 +0000 | [diff] [blame] | 1818 | ReadCXXDefinitionData(*DD, D); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1819 | |
Volodymyr Sapsai | 8a5943f | 2018-03-21 21:28:54 +0000 | [diff] [blame] | 1820 | // We might already have a different definition for this record. This can |
| 1821 | // happen either because we're reading an update record, or because we've |
| 1822 | // already done some merging. Either way, just merge into it. |
| 1823 | if (Canon->DefinitionData != DD) { |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 1824 | MergeDefinitionData(Canon, std::move(*DD)); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1825 | return; |
| 1826 | } |
| 1827 | |
Richard Smith | 97100e3 | 2015-06-20 00:22:34 +0000 | [diff] [blame] | 1828 | // Mark this declaration as being a definition. |
Erich Keane | f92f31c | 2018-08-01 20:48:16 +0000 | [diff] [blame] | 1829 | D->setCompleteDefinition(true); |
Richard Smith | 2a9e5c5 | 2015-02-03 03:32:14 +0000 | [diff] [blame] | 1830 | |
Richard Smith | 97100e3 | 2015-06-20 00:22:34 +0000 | [diff] [blame] | 1831 | // If this is not the first declaration or is an update record, we can have |
| 1832 | // other redeclarations already. Make a note that we need to propagate the |
| 1833 | // DefinitionData pointer onto them. |
Volodymyr Sapsai | 8a5943f | 2018-03-21 21:28:54 +0000 | [diff] [blame] | 1834 | if (Update || Canon != D) |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1835 | Reader.PendingDefinitions.insert(D); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1836 | } |
| 1837 | |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 1838 | ASTDeclReader::RedeclarableResult |
| 1839 | ASTDeclReader::VisitCXXRecordDeclImpl(CXXRecordDecl *D) { |
| 1840 | RedeclarableResult Redecl = VisitRecordDeclImpl(D); |
Argyrios Kyrtzidis | a41f660 | 2010-10-20 00:11:15 +0000 | [diff] [blame] | 1841 | |
Douglas Gregor | 3a5ae56 | 2012-01-15 18:17:48 +0000 | [diff] [blame] | 1842 | ASTContext &C = Reader.getContext(); |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 1843 | |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 1844 | enum CXXRecKind { |
| 1845 | CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization |
| 1846 | }; |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1847 | switch ((CXXRecKind)Record.readInt()) { |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 1848 | case CXXRecNotTemplate: |
Richard Smith | dc5523d | 2014-07-11 00:20:06 +0000 | [diff] [blame] | 1849 | // Merged when we merge the folding set entry in the primary template. |
| 1850 | if (!isa<ClassTemplateSpecializationDecl>(D)) |
| 1851 | mergeRedeclarable(D, Redecl); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 1852 | break; |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 1853 | case CXXRecTemplate: { |
| 1854 | // Merged when we merge the template. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1855 | auto *Template = ReadDeclAs<ClassTemplateDecl>(); |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 1856 | D->TemplateOrInstantiation = Template; |
| 1857 | if (!Template->getTemplatedDecl()) { |
| 1858 | // We've not actually loaded the ClassTemplateDecl yet, because we're |
| 1859 | // currently being loaded as its pattern. Rely on it to set up our |
| 1860 | // TypeForDecl (see VisitClassTemplateDecl). |
| 1861 | // |
| 1862 | // Beware: we do not yet know our canonical declaration, and may still |
| 1863 | // get merged once the surrounding class template has got off the ground. |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 1864 | DeferredTypeID = 0; |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 1865 | } |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 1866 | break; |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 1867 | } |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 1868 | case CXXRecMemberSpecialization: { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1869 | auto *RD = ReadDeclAs<CXXRecordDecl>(); |
| 1870 | auto TSK = (TemplateSpecializationKind)Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1871 | SourceLocation POI = ReadSourceLocation(); |
Argyrios Kyrtzidis | caf8248 | 2010-09-13 11:45:25 +0000 | [diff] [blame] | 1872 | MemberSpecializationInfo *MSI = new (C) MemberSpecializationInfo(RD, TSK); |
| 1873 | MSI->setPointOfInstantiation(POI); |
| 1874 | D->TemplateOrInstantiation = MSI; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1875 | mergeRedeclarable(D, Redecl); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 1876 | break; |
| 1877 | } |
| 1878 | } |
Argyrios Kyrtzidis | 6843141 | 2010-10-14 20:14:38 +0000 | [diff] [blame] | 1879 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1880 | bool WasDefinition = Record.readInt(); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1881 | if (WasDefinition) |
Richard Smith | 2a9e5c5 | 2015-02-03 03:32:14 +0000 | [diff] [blame] | 1882 | ReadCXXRecordDefinition(D, /*Update*/false); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1883 | else |
| 1884 | // Propagate DefinitionData pointer from the canonical declaration. |
| 1885 | D->DefinitionData = D->getCanonicalDecl()->DefinitionData; |
| 1886 | |
Richard Smith | 676c404 | 2013-08-29 23:59:27 +0000 | [diff] [blame] | 1887 | // Lazily load the key function to avoid deserializing every method so we can |
Argyrios Kyrtzidis | 6843141 | 2010-10-14 20:14:38 +0000 | [diff] [blame] | 1888 | // compute it. |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 1889 | if (WasDefinition) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1890 | DeclID KeyFn = ReadDeclID(); |
Erich Keane | f92f31c | 2018-08-01 20:48:16 +0000 | [diff] [blame] | 1891 | if (KeyFn && D->isCompleteDefinition()) |
Richard Smith | a9a1c68 | 2014-07-07 06:38:20 +0000 | [diff] [blame] | 1892 | // FIXME: This is wrong for the ARM ABI, where some other module may have |
| 1893 | // made this function no longer be a key function. We need an update |
| 1894 | // record or similar for that case. |
Richard Smith | 676c404 | 2013-08-29 23:59:27 +0000 | [diff] [blame] | 1895 | C.KeyFunctions[D] = KeyFn; |
Argyrios Kyrtzidis | 6843141 | 2010-10-14 20:14:38 +0000 | [diff] [blame] | 1896 | } |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 1897 | |
| 1898 | return Redecl; |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1899 | } |
| 1900 | |
Richard Smith | bc49120 | 2017-02-17 20:05:37 +0000 | [diff] [blame] | 1901 | void ASTDeclReader::VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D) { |
Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 1902 | D->setExplicitSpecifier(Record.readExplicitSpec()); |
Richard Smith | bc49120 | 2017-02-17 20:05:37 +0000 | [diff] [blame] | 1903 | VisitFunctionDecl(D); |
Erich Keane | 9c66506 | 2018-08-01 21:02:40 +0000 | [diff] [blame] | 1904 | D->setIsCopyDeductionCandidate(Record.readInt()); |
Richard Smith | bc49120 | 2017-02-17 20:05:37 +0000 | [diff] [blame] | 1905 | } |
| 1906 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1907 | void ASTDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1908 | VisitFunctionDecl(D); |
Richard Smith | b110873 | 2014-08-26 23:29:11 +0000 | [diff] [blame] | 1909 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1910 | unsigned NumOverridenMethods = Record.readInt(); |
Richard Smith | b110873 | 2014-08-26 23:29:11 +0000 | [diff] [blame] | 1911 | if (D->isCanonicalDecl()) { |
| 1912 | while (NumOverridenMethods--) { |
| 1913 | // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod, |
| 1914 | // MD may be initializing. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1915 | if (auto *MD = ReadDeclAs<CXXMethodDecl>()) |
Richard Smith | b110873 | 2014-08-26 23:29:11 +0000 | [diff] [blame] | 1916 | Reader.getContext().addOverriddenMethod(D, MD->getCanonicalDecl()); |
| 1917 | } |
| 1918 | } else { |
| 1919 | // We don't care about which declarations this used to override; we get |
| 1920 | // the relevant information from the canonical declaration. |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1921 | Record.skipInts(NumOverridenMethods); |
Argyrios Kyrtzidis | 6685e8a | 2010-07-04 21:44:35 +0000 | [diff] [blame] | 1922 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1923 | } |
| 1924 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1925 | void ASTDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) { |
Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 1926 | // We need the inherited constructor information to merge the declaration, |
| 1927 | // so we have to read it before we call VisitCXXMethodDecl. |
Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 1928 | D->setExplicitSpecifier(Record.readExplicitSpec()); |
Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 1929 | if (D->isInheritingConstructor()) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1930 | auto *Shadow = ReadDeclAs<ConstructorUsingShadowDecl>(); |
| 1931 | auto *Ctor = ReadDeclAs<CXXConstructorDecl>(); |
Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 1932 | *D->getTrailingObjects<InheritedConstructor>() = |
| 1933 | InheritedConstructor(Shadow, Ctor); |
| 1934 | } |
| 1935 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1936 | VisitCXXMethodDecl(D); |
| 1937 | } |
| 1938 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1939 | void ASTDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1940 | VisitCXXMethodDecl(D); |
Argyrios Kyrtzidis | 3357516 | 2010-07-02 15:58:43 +0000 | [diff] [blame] | 1941 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1942 | if (auto *OperatorDelete = ReadDeclAs<FunctionDecl>()) { |
George Burgess IV | 00f70bd | 2018-03-01 05:43:23 +0000 | [diff] [blame] | 1943 | CXXDestructorDecl *Canon = D->getCanonicalDecl(); |
Richard Smith | 5b34958 | 2017-10-13 01:55:36 +0000 | [diff] [blame] | 1944 | auto *ThisArg = Record.readExpr(); |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 1945 | // FIXME: Check consistency if we have an old and new operator delete. |
Richard Smith | 5b34958 | 2017-10-13 01:55:36 +0000 | [diff] [blame] | 1946 | if (!Canon->OperatorDelete) { |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 1947 | Canon->OperatorDelete = OperatorDelete; |
Richard Smith | 5b34958 | 2017-10-13 01:55:36 +0000 | [diff] [blame] | 1948 | Canon->OperatorDeleteThisArg = ThisArg; |
| 1949 | } |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 1950 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1951 | } |
| 1952 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1953 | void ASTDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) { |
Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 1954 | D->setExplicitSpecifier(Record.readExplicitSpec()); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1955 | VisitCXXMethodDecl(D); |
| 1956 | } |
| 1957 | |
Douglas Gregor | ba34552 | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 1958 | void ASTDeclReader::VisitImportDecl(ImportDecl *D) { |
| 1959 | VisitDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1960 | D->ImportedAndComplete.setPointer(readModule()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1961 | D->ImportedAndComplete.setInt(Record.readInt()); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1962 | auto *StoredLocs = D->getTrailingObjects<SourceLocation>(); |
Douglas Gregor | ba34552 | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 1963 | for (unsigned I = 0, N = Record.back(); I != N; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1964 | StoredLocs[I] = ReadSourceLocation(); |
David L. Jones | 267b884 | 2017-01-24 01:04:30 +0000 | [diff] [blame] | 1965 | Record.skipInts(1); // The number of stored source locations. |
Douglas Gregor | ba34552 | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 1966 | } |
| 1967 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1968 | void ASTDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) { |
Abramo Bagnara | d734058 | 2010-06-05 05:09:32 +0000 | [diff] [blame] | 1969 | VisitDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1970 | D->setColonLoc(ReadSourceLocation()); |
Abramo Bagnara | d734058 | 2010-06-05 05:09:32 +0000 | [diff] [blame] | 1971 | } |
| 1972 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1973 | void ASTDeclReader::VisitFriendDecl(FriendDecl *D) { |
Argyrios Kyrtzidis | a95d019 | 2010-07-05 10:38:01 +0000 | [diff] [blame] | 1974 | VisitDecl(D); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1975 | if (Record.readInt()) // hasFriendDecl |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1976 | D->Friend = ReadDeclAs<NamedDecl>(); |
Enea Zaffanella | eb22c87 | 2013-01-31 09:54:08 +0000 | [diff] [blame] | 1977 | else |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1978 | D->Friend = GetTypeSourceInfo(); |
Enea Zaffanella | eb22c87 | 2013-01-31 09:54:08 +0000 | [diff] [blame] | 1979 | for (unsigned i = 0; i != D->NumTPLists; ++i) |
James Y Knight | 967eb20 | 2015-12-29 22:13:13 +0000 | [diff] [blame] | 1980 | D->getTrailingObjects<TemplateParameterList *>()[i] = |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1981 | Record.readTemplateParameterList(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1982 | D->NextFriend = ReadDeclID(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1983 | D->UnsupportedFriend = (Record.readInt() != 0); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1984 | D->FriendLoc = ReadSourceLocation(); |
Argyrios Kyrtzidis | 74d28bd | 2010-06-29 22:47:00 +0000 | [diff] [blame] | 1985 | } |
| 1986 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1987 | void ASTDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) { |
Argyrios Kyrtzidis | 165b581 | 2010-07-22 16:04:10 +0000 | [diff] [blame] | 1988 | VisitDecl(D); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1989 | unsigned NumParams = Record.readInt(); |
Argyrios Kyrtzidis | 165b581 | 2010-07-22 16:04:10 +0000 | [diff] [blame] | 1990 | D->NumParams = NumParams; |
| 1991 | D->Params = new TemplateParameterList*[NumParams]; |
| 1992 | for (unsigned i = 0; i != NumParams; ++i) |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1993 | D->Params[i] = Record.readTemplateParameterList(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1994 | if (Record.readInt()) // HasFriendDecl |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1995 | D->Friend = ReadDeclAs<NamedDecl>(); |
Argyrios Kyrtzidis | 165b581 | 2010-07-22 16:04:10 +0000 | [diff] [blame] | 1996 | else |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1997 | D->Friend = GetTypeSourceInfo(); |
| 1998 | D->FriendLoc = ReadSourceLocation(); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1999 | } |
| 2000 | |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2001 | DeclID ASTDeclReader::VisitTemplateDecl(TemplateDecl *D) { |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 2002 | VisitNamedDecl(D); |
| 2003 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2004 | DeclID PatternID = ReadDeclID(); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2005 | auto *TemplatedDecl = cast_or_null<NamedDecl>(Reader.GetDecl(PatternID)); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2006 | TemplateParameterList *TemplateParams = Record.readTemplateParameterList(); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 2007 | D->init(TemplatedDecl, TemplateParams); |
Richard Smith | bf78e64 | 2013-06-24 22:51:00 +0000 | [diff] [blame] | 2008 | |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2009 | return PatternID; |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 2010 | } |
| 2011 | |
Saar Raz | d7aae33 | 2019-07-10 21:25:49 +0000 | [diff] [blame] | 2012 | void ASTDeclReader::VisitConceptDecl(ConceptDecl *D) { |
| 2013 | VisitTemplateDecl(D); |
| 2014 | D->ConstraintExpr = Record.readExpr(); |
| 2015 | mergeMergeable(D); |
| 2016 | } |
| 2017 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2018 | ASTDeclReader::RedeclarableResult |
Douglas Gregor | 5407920 | 2012-01-06 22:05:37 +0000 | [diff] [blame] | 2019 | ASTDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) { |
Douglas Gregor | 68444de | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 2020 | RedeclarableResult Redecl = VisitRedeclarable(D); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 2021 | |
Douglas Gregor | 68444de | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 2022 | // Make sure we've allocated the Common pointer first. We do this before |
| 2023 | // VisitTemplateDecl so that getCommonPtr() can be used during initialization. |
| 2024 | RedeclarableTemplateDecl *CanonD = D->getCanonicalDecl(); |
| 2025 | if (!CanonD->Common) { |
| 2026 | CanonD->Common = CanonD->newCommon(Reader.getContext()); |
| 2027 | Reader.PendingDefinitions.insert(CanonD); |
| 2028 | } |
| 2029 | D->Common = CanonD->Common; |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 2030 | |
Douglas Gregor | 68444de | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 2031 | // If this is the first declaration of the template, fill in the information |
| 2032 | // for the 'common' pointer. |
| 2033 | if (ThisDeclID == Redecl.getFirstID()) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2034 | if (auto *RTD = ReadDeclAs<RedeclarableTemplateDecl>()) { |
Peter Collingbourne | 91b25b7 | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 2035 | assert(RTD->getKind() == D->getKind() && |
| 2036 | "InstantiatedFromMemberTemplate kind mismatch"); |
Douglas Gregor | 68444de | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 2037 | D->setInstantiatedFromMemberTemplate(RTD); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2038 | if (Record.readInt()) |
Peter Collingbourne | 91b25b7 | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 2039 | D->setMemberSpecialization(); |
| 2040 | } |
| 2041 | } |
Axel Naumann | 866ba3e | 2012-10-01 09:18:00 +0000 | [diff] [blame] | 2042 | |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2043 | DeclID PatternID = VisitTemplateDecl(D); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2044 | D->IdentifierNamespace = Record.readInt(); |
Axel Naumann | 866ba3e | 2012-10-01 09:18:00 +0000 | [diff] [blame] | 2045 | |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2046 | mergeRedeclarable(D, Redecl, PatternID); |
Axel Naumann | 866ba3e | 2012-10-01 09:18:00 +0000 | [diff] [blame] | 2047 | |
Richard Smith | d46d6de | 2013-10-13 23:50:45 +0000 | [diff] [blame] | 2048 | // If we merged the template with a prior declaration chain, merge the common |
| 2049 | // pointer. |
| 2050 | // FIXME: Actually merge here, don't just overwrite. |
| 2051 | D->Common = D->getCanonicalDecl()->Common; |
| 2052 | |
Douglas Gregor | 68444de | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 2053 | return Redecl; |
Peter Collingbourne | 91b25b7 | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 2054 | } |
| 2055 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 2056 | void ASTDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
Douglas Gregor | 68444de | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 2057 | RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D); |
Peter Collingbourne | 91b25b7 | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 2058 | |
Douglas Gregor | 68444de | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 2059 | if (ThisDeclID == Redecl.getFirstID()) { |
Douglas Gregor | 7e8c4e0 | 2010-10-27 22:21:36 +0000 | [diff] [blame] | 2060 | // This ClassTemplateDecl owns a CommonPtr; read it to keep track of all of |
| 2061 | // the specializations. |
Richard Smith | 0b88437 | 2015-02-27 00:25:58 +0000 | [diff] [blame] | 2062 | SmallVector<serialization::DeclID, 32> SpecIDs; |
Richard Smith | 0b88437 | 2015-02-27 00:25:58 +0000 | [diff] [blame] | 2063 | ReadDeclIDList(SpecIDs); |
Vassil Vassilev | 7d26462 | 2017-06-30 22:40:17 +0000 | [diff] [blame] | 2064 | ASTDeclReader::AddLazySpecializations(D, SpecIDs); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 2065 | } |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2066 | |
| 2067 | if (D->getTemplatedDecl()->TemplateOrInstantiation) { |
| 2068 | // We were loaded before our templated declaration was. We've not set up |
| 2069 | // its corresponding type yet (see VisitCXXRecordDeclImpl), so reconstruct |
| 2070 | // it now. |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 2071 | Reader.getContext().getInjectedClassNameType( |
Richard Smith | a1406fa | 2014-05-23 21:31:59 +0000 | [diff] [blame] | 2072 | D->getTemplatedDecl(), D->getInjectedClassNameSpecialization()); |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2073 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 2074 | } |
| 2075 | |
David Majnemer | d9b1a4f | 2015-11-04 03:40:30 +0000 | [diff] [blame] | 2076 | void ASTDeclReader::VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D) { |
| 2077 | llvm_unreachable("BuiltinTemplates are not serialized"); |
| 2078 | } |
| 2079 | |
Larisse Voufo | 3061638 | 2013-08-23 22:21:36 +0000 | [diff] [blame] | 2080 | /// TODO: Unify with ClassTemplateDecl version? |
| 2081 | /// May require unifying ClassTemplateDecl and |
| 2082 | /// VarTemplateDecl beyond TemplateDecl... |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2083 | void ASTDeclReader::VisitVarTemplateDecl(VarTemplateDecl *D) { |
| 2084 | RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D); |
| 2085 | |
| 2086 | if (ThisDeclID == Redecl.getFirstID()) { |
Larisse Voufo | d8dd97c | 2013-08-14 03:09:19 +0000 | [diff] [blame] | 2087 | // This VarTemplateDecl owns a CommonPtr; read it to keep track of all of |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2088 | // the specializations. |
Richard Smith | 0b88437 | 2015-02-27 00:25:58 +0000 | [diff] [blame] | 2089 | SmallVector<serialization::DeclID, 32> SpecIDs; |
Richard Smith | 0b88437 | 2015-02-27 00:25:58 +0000 | [diff] [blame] | 2090 | ReadDeclIDList(SpecIDs); |
Vassil Vassilev | 7d26462 | 2017-06-30 22:40:17 +0000 | [diff] [blame] | 2091 | ASTDeclReader::AddLazySpecializations(D, SpecIDs); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2092 | } |
| 2093 | } |
| 2094 | |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 2095 | ASTDeclReader::RedeclarableResult |
| 2096 | ASTDeclReader::VisitClassTemplateSpecializationDeclImpl( |
| 2097 | ClassTemplateSpecializationDecl *D) { |
| 2098 | RedeclarableResult Redecl = VisitCXXRecordDeclImpl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2099 | |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2100 | ASTContext &C = Reader.getContext(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2101 | if (Decl *InstD = ReadDecl()) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2102 | if (auto *CTD = dyn_cast<ClassTemplateDecl>(InstD)) { |
Argyrios Kyrtzidis | b4c659b | 2010-09-13 11:45:32 +0000 | [diff] [blame] | 2103 | D->SpecializedTemplate = CTD; |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 2104 | } else { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2105 | SmallVector<TemplateArgument, 8> TemplArgs; |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2106 | Record.readTemplateArgumentList(TemplArgs); |
Argyrios Kyrtzidis | b4c659b | 2010-09-13 11:45:32 +0000 | [diff] [blame] | 2107 | TemplateArgumentList *ArgList |
David Majnemer | 8b62269 | 2016-07-03 21:17:51 +0000 | [diff] [blame] | 2108 | = TemplateArgumentList::CreateCopy(C, TemplArgs); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2109 | auto *PS = |
| 2110 | new (C) ClassTemplateSpecializationDecl:: |
Argyrios Kyrtzidis | b4c659b | 2010-09-13 11:45:32 +0000 | [diff] [blame] | 2111 | SpecializedPartialSpecialization(); |
| 2112 | PS->PartialSpecialization |
| 2113 | = cast<ClassTemplatePartialSpecializationDecl>(InstD); |
| 2114 | PS->TemplateArgs = ArgList; |
| 2115 | D->SpecializedTemplate = PS; |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 2116 | } |
| 2117 | } |
| 2118 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2119 | SmallVector<TemplateArgument, 8> TemplArgs; |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2120 | Record.readTemplateArgumentList(TemplArgs, /*Canonicalize*/ true); |
David Majnemer | 8b62269 | 2016-07-03 21:17:51 +0000 | [diff] [blame] | 2121 | D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2122 | D->PointOfInstantiation = ReadSourceLocation(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2123 | D->SpecializationKind = (TemplateSpecializationKind)Record.readInt(); |
Axel Naumann | a31dee2 | 2012-10-01 07:34:47 +0000 | [diff] [blame] | 2124 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2125 | bool writtenAsCanonicalDecl = Record.readInt(); |
Axel Naumann | a31dee2 | 2012-10-01 07:34:47 +0000 | [diff] [blame] | 2126 | if (writtenAsCanonicalDecl) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2127 | auto *CanonPattern = ReadDeclAs<ClassTemplateDecl>(); |
Axel Naumann | a31dee2 | 2012-10-01 07:34:47 +0000 | [diff] [blame] | 2128 | if (D->isCanonicalDecl()) { // It's kept in the folding set. |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2129 | // Set this as, or find, the canonical declaration for this specialization |
| 2130 | ClassTemplateSpecializationDecl *CanonSpec; |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2131 | if (auto *Partial = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) { |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2132 | CanonSpec = CanonPattern->getCommonPtr()->PartialSpecializations |
Richard Smith | 5de91b5 | 2013-06-25 01:25:15 +0000 | [diff] [blame] | 2133 | .GetOrInsertNode(Partial); |
Axel Naumann | a31dee2 | 2012-10-01 07:34:47 +0000 | [diff] [blame] | 2134 | } else { |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2135 | CanonSpec = |
| 2136 | CanonPattern->getCommonPtr()->Specializations.GetOrInsertNode(D); |
| 2137 | } |
| 2138 | // If there was already a canonical specialization, merge into it. |
| 2139 | if (CanonSpec != D) { |
| 2140 | mergeRedeclarable<TagDecl>(D, CanonSpec, Redecl); |
| 2141 | |
| 2142 | // This declaration might be a definition. Merge with any existing |
| 2143 | // definition. |
Richard Smith | b648399 | 2016-05-17 22:44:15 +0000 | [diff] [blame] | 2144 | if (auto *DDD = D->DefinitionData) { |
| 2145 | if (CanonSpec->DefinitionData) |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 2146 | MergeDefinitionData(CanonSpec, std::move(*DDD)); |
Richard Smith | 97100e3 | 2015-06-20 00:22:34 +0000 | [diff] [blame] | 2147 | else |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 2148 | CanonSpec->DefinitionData = D->DefinitionData; |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2149 | } |
Richard Smith | 547864d | 2014-07-11 18:22:58 +0000 | [diff] [blame] | 2150 | D->DefinitionData = CanonSpec->DefinitionData; |
Axel Naumann | a31dee2 | 2012-10-01 07:34:47 +0000 | [diff] [blame] | 2151 | } |
Argyrios Kyrtzidis | 8704057 | 2010-07-09 21:11:43 +0000 | [diff] [blame] | 2152 | } |
| 2153 | } |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 2154 | |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2155 | // Explicit info. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2156 | if (TypeSourceInfo *TyInfo = GetTypeSourceInfo()) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2157 | auto *ExplicitInfo = |
| 2158 | new (C) ClassTemplateSpecializationDecl::ExplicitSpecializationInfo; |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2159 | ExplicitInfo->TypeAsWritten = TyInfo; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2160 | ExplicitInfo->ExternLoc = ReadSourceLocation(); |
| 2161 | ExplicitInfo->TemplateKeywordLoc = ReadSourceLocation(); |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2162 | D->ExplicitInfo = ExplicitInfo; |
| 2163 | } |
| 2164 | |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 2165 | return Redecl; |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 2166 | } |
| 2167 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 2168 | void ASTDeclReader::VisitClassTemplatePartialSpecializationDecl( |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 2169 | ClassTemplatePartialSpecializationDecl *D) { |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 2170 | RedeclarableResult Redecl = VisitClassTemplateSpecializationDeclImpl(D); |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 2171 | |
Saar Raz | 0330fba | 2019-10-15 18:44:06 +0000 | [diff] [blame] | 2172 | TemplateParameterList *Params = Record.readTemplateParameterList(); |
| 2173 | D->TemplateParams = Params; |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2174 | D->ArgsAsWritten = Record.readASTTemplateArgumentListInfo(); |
Argyrios Kyrtzidis | 0e8b3ce | 2010-09-13 11:45:41 +0000 | [diff] [blame] | 2175 | |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 2176 | // These are read/set from/to the first declaration. |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 2177 | if (ThisDeclID == Redecl.getFirstID()) { |
Argyrios Kyrtzidis | 0e8b3ce | 2010-09-13 11:45:41 +0000 | [diff] [blame] | 2178 | D->InstantiatedFromMember.setPointer( |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2179 | ReadDeclAs<ClassTemplatePartialSpecializationDecl>()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2180 | D->InstantiatedFromMember.setInt(Record.readInt()); |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 2181 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 2182 | } |
| 2183 | |
Sebastian Redl | b744863 | 2011-08-31 13:59:56 +0000 | [diff] [blame] | 2184 | void ASTDeclReader::VisitClassScopeFunctionSpecializationDecl( |
| 2185 | ClassScopeFunctionSpecializationDecl *D) { |
Francois Pichet | 09af8c3 | 2011-08-17 01:06:54 +0000 | [diff] [blame] | 2186 | VisitDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2187 | D->Specialization = ReadDeclAs<CXXMethodDecl>(); |
Richard Smith | f19a8b0 | 2019-05-02 00:49:14 +0000 | [diff] [blame] | 2188 | if (Record.readInt()) |
| 2189 | D->TemplateArgs = Record.readASTTemplateArgumentListInfo(); |
Francois Pichet | 09af8c3 | 2011-08-17 01:06:54 +0000 | [diff] [blame] | 2190 | } |
| 2191 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 2192 | void ASTDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
Douglas Gregor | 68444de | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 2193 | RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D); |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 2194 | |
Douglas Gregor | 68444de | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 2195 | if (ThisDeclID == Redecl.getFirstID()) { |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 2196 | // This FunctionTemplateDecl owns a CommonPtr; read it. |
Richard Smith | 0b88437 | 2015-02-27 00:25:58 +0000 | [diff] [blame] | 2197 | SmallVector<serialization::DeclID, 32> SpecIDs; |
| 2198 | ReadDeclIDList(SpecIDs); |
Vassil Vassilev | 7d26462 | 2017-06-30 22:40:17 +0000 | [diff] [blame] | 2199 | ASTDeclReader::AddLazySpecializations(D, SpecIDs); |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 2200 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 2201 | } |
| 2202 | |
Larisse Voufo | 3061638 | 2013-08-23 22:21:36 +0000 | [diff] [blame] | 2203 | /// TODO: Unify with ClassTemplateSpecializationDecl version? |
| 2204 | /// May require unifying ClassTemplate(Partial)SpecializationDecl and |
| 2205 | /// VarTemplate(Partial)SpecializationDecl with a new data |
| 2206 | /// structure Template(Partial)SpecializationDecl, and |
| 2207 | /// using Template(Partial)SpecializationDecl as input type. |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2208 | ASTDeclReader::RedeclarableResult |
| 2209 | ASTDeclReader::VisitVarTemplateSpecializationDeclImpl( |
| 2210 | VarTemplateSpecializationDecl *D) { |
| 2211 | RedeclarableResult Redecl = VisitVarDeclImpl(D); |
| 2212 | |
| 2213 | ASTContext &C = Reader.getContext(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2214 | if (Decl *InstD = ReadDecl()) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2215 | if (auto *VTD = dyn_cast<VarTemplateDecl>(InstD)) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2216 | D->SpecializedTemplate = VTD; |
| 2217 | } else { |
| 2218 | SmallVector<TemplateArgument, 8> TemplArgs; |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2219 | Record.readTemplateArgumentList(TemplArgs); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2220 | TemplateArgumentList *ArgList = TemplateArgumentList::CreateCopy( |
David Majnemer | 8b62269 | 2016-07-03 21:17:51 +0000 | [diff] [blame] | 2221 | C, TemplArgs); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2222 | auto *PS = |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2223 | new (C) |
| 2224 | VarTemplateSpecializationDecl::SpecializedPartialSpecialization(); |
| 2225 | PS->PartialSpecialization = |
| 2226 | cast<VarTemplatePartialSpecializationDecl>(InstD); |
| 2227 | PS->TemplateArgs = ArgList; |
| 2228 | D->SpecializedTemplate = PS; |
| 2229 | } |
| 2230 | } |
| 2231 | |
| 2232 | // Explicit info. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2233 | if (TypeSourceInfo *TyInfo = GetTypeSourceInfo()) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2234 | auto *ExplicitInfo = |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2235 | new (C) VarTemplateSpecializationDecl::ExplicitSpecializationInfo; |
| 2236 | ExplicitInfo->TypeAsWritten = TyInfo; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2237 | ExplicitInfo->ExternLoc = ReadSourceLocation(); |
| 2238 | ExplicitInfo->TemplateKeywordLoc = ReadSourceLocation(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2239 | D->ExplicitInfo = ExplicitInfo; |
| 2240 | } |
| 2241 | |
| 2242 | SmallVector<TemplateArgument, 8> TemplArgs; |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2243 | Record.readTemplateArgumentList(TemplArgs, /*Canonicalize*/ true); |
David Majnemer | 8b62269 | 2016-07-03 21:17:51 +0000 | [diff] [blame] | 2244 | D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2245 | D->PointOfInstantiation = ReadSourceLocation(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2246 | D->SpecializationKind = (TemplateSpecializationKind)Record.readInt(); |
Richard Smith | 435e647 | 2017-12-02 02:48:42 +0000 | [diff] [blame] | 2247 | D->IsCompleteDefinition = Record.readInt(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2248 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2249 | bool writtenAsCanonicalDecl = Record.readInt(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2250 | if (writtenAsCanonicalDecl) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2251 | auto *CanonPattern = ReadDeclAs<VarTemplateDecl>(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2252 | if (D->isCanonicalDecl()) { // It's kept in the folding set. |
Richard Smith | 9b88a4c | 2015-07-27 05:40:23 +0000 | [diff] [blame] | 2253 | // FIXME: If it's already present, merge it. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2254 | if (auto *Partial = dyn_cast<VarTemplatePartialSpecializationDecl>(D)) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2255 | CanonPattern->getCommonPtr()->PartialSpecializations |
| 2256 | .GetOrInsertNode(Partial); |
| 2257 | } else { |
| 2258 | CanonPattern->getCommonPtr()->Specializations.GetOrInsertNode(D); |
| 2259 | } |
| 2260 | } |
| 2261 | } |
| 2262 | |
| 2263 | return Redecl; |
| 2264 | } |
| 2265 | |
Larisse Voufo | 3061638 | 2013-08-23 22:21:36 +0000 | [diff] [blame] | 2266 | /// TODO: Unify with ClassTemplatePartialSpecializationDecl version? |
| 2267 | /// May require unifying ClassTemplate(Partial)SpecializationDecl and |
| 2268 | /// VarTemplate(Partial)SpecializationDecl with a new data |
| 2269 | /// structure Template(Partial)SpecializationDecl, and |
| 2270 | /// using Template(Partial)SpecializationDecl as input type. |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2271 | void ASTDeclReader::VisitVarTemplatePartialSpecializationDecl( |
| 2272 | VarTemplatePartialSpecializationDecl *D) { |
| 2273 | RedeclarableResult Redecl = VisitVarTemplateSpecializationDeclImpl(D); |
| 2274 | |
Saar Raz | 0330fba | 2019-10-15 18:44:06 +0000 | [diff] [blame] | 2275 | TemplateParameterList *Params = Record.readTemplateParameterList(); |
| 2276 | D->TemplateParams = Params; |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2277 | D->ArgsAsWritten = Record.readASTTemplateArgumentListInfo(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2278 | |
| 2279 | // These are read/set from/to the first declaration. |
| 2280 | if (ThisDeclID == Redecl.getFirstID()) { |
| 2281 | D->InstantiatedFromMember.setPointer( |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2282 | ReadDeclAs<VarTemplatePartialSpecializationDecl>()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2283 | D->InstantiatedFromMember.setInt(Record.readInt()); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2284 | } |
| 2285 | } |
| 2286 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 2287 | void ASTDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 2288 | VisitTypeDecl(D); |
| 2289 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2290 | D->setDeclaredWithTypename(Record.readInt()); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 2291 | |
Saar Raz | 0330fba | 2019-10-15 18:44:06 +0000 | [diff] [blame] | 2292 | // TODO: Concepts: Immediately introduced constraint |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2293 | if (Record.readInt()) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2294 | D->setDefaultArgument(GetTypeSourceInfo()); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 2295 | } |
| 2296 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 2297 | void ASTDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { |
John McCall | f4cd4f9 | 2011-02-09 01:13:10 +0000 | [diff] [blame] | 2298 | VisitDeclaratorDecl(D); |
Argyrios Kyrtzidis | b1d38e3 | 2010-06-25 16:25:09 +0000 | [diff] [blame] | 2299 | // TemplateParmPosition. |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2300 | D->setDepth(Record.readInt()); |
| 2301 | D->setPosition(Record.readInt()); |
Douglas Gregor | 0231d8d | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 2302 | if (D->isExpandedParameterPack()) { |
James Y Knight | 967eb20 | 2015-12-29 22:13:13 +0000 | [diff] [blame] | 2303 | auto TypesAndInfos = |
| 2304 | D->getTrailingObjects<std::pair<QualType, TypeSourceInfo *>>(); |
Douglas Gregor | 0231d8d | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 2305 | for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2306 | new (&TypesAndInfos[I].first) QualType(Record.readType()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2307 | TypesAndInfos[I].second = GetTypeSourceInfo(); |
Douglas Gregor | 0231d8d | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 2308 | } |
| 2309 | } else { |
| 2310 | // Rest of NonTypeTemplateParmDecl. |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2311 | D->ParameterPack = Record.readInt(); |
| 2312 | if (Record.readInt()) |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2313 | D->setDefaultArgument(Record.readExpr()); |
Douglas Gregor | 0231d8d | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 2314 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 2315 | } |
| 2316 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 2317 | void ASTDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { |
Argyrios Kyrtzidis | 9f2d24a | 2010-07-08 17:12:57 +0000 | [diff] [blame] | 2318 | VisitTemplateDecl(D); |
| 2319 | // TemplateParmPosition. |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2320 | D->setDepth(Record.readInt()); |
| 2321 | D->setPosition(Record.readInt()); |
Richard Smith | 1fde8ec | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 2322 | if (D->isExpandedParameterPack()) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2323 | auto **Data = D->getTrailingObjects<TemplateParameterList *>(); |
Richard Smith | 1fde8ec | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 2324 | for (unsigned I = 0, N = D->getNumExpansionTemplateParameters(); |
| 2325 | I != N; ++I) |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2326 | Data[I] = Record.readTemplateParameterList(); |
Richard Smith | 1fde8ec | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 2327 | } else { |
| 2328 | // Rest of TemplateTemplateParmDecl. |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2329 | D->ParameterPack = Record.readInt(); |
| 2330 | if (Record.readInt()) |
Richard Smith | 1469b91 | 2015-06-10 00:29:03 +0000 | [diff] [blame] | 2331 | D->setDefaultArgument(Reader.getContext(), |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2332 | Record.readTemplateArgumentLoc()); |
Richard Smith | 1fde8ec | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 2333 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 2334 | } |
| 2335 | |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 2336 | void ASTDeclReader::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { |
| 2337 | VisitRedeclarableTemplateDecl(D); |
| 2338 | } |
| 2339 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 2340 | void ASTDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) { |
Argyrios Kyrtzidis | 2d8891c | 2010-07-22 17:28:12 +0000 | [diff] [blame] | 2341 | VisitDecl(D); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2342 | D->AssertExprAndFailed.setPointer(Record.readExpr()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2343 | D->AssertExprAndFailed.setInt(Record.readInt()); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2344 | D->Message = cast_or_null<StringLiteral>(Record.readExpr()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2345 | D->RParenLoc = ReadSourceLocation(); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 2346 | } |
| 2347 | |
Michael Han | 8432435 | 2013-02-22 17:15:32 +0000 | [diff] [blame] | 2348 | void ASTDeclReader::VisitEmptyDecl(EmptyDecl *D) { |
| 2349 | VisitDecl(D); |
| 2350 | } |
| 2351 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2352 | std::pair<uint64_t, uint64_t> |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 2353 | ASTDeclReader::VisitDeclContext(DeclContext *DC) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2354 | uint64_t LexicalOffset = ReadLocalOffset(); |
| 2355 | uint64_t VisibleOffset = ReadLocalOffset(); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 2356 | return std::make_pair(LexicalOffset, VisibleOffset); |
| 2357 | } |
| 2358 | |
Argyrios Kyrtzidis | 839bbac | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 2359 | template <typename T> |
Richard Smith | 5a4737c | 2015-02-06 02:42:59 +0000 | [diff] [blame] | 2360 | ASTDeclReader::RedeclarableResult |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 2361 | ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2362 | DeclID FirstDeclID = ReadDeclID(); |
Richard Smith | 5a4737c | 2015-02-06 02:42:59 +0000 | [diff] [blame] | 2363 | Decl *MergeWith = nullptr; |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 2364 | |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 2365 | bool IsKeyDecl = ThisDeclID == FirstDeclID; |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 2366 | bool IsFirstLocalDecl = false; |
Richard Smith | 5a4737c | 2015-02-06 02:42:59 +0000 | [diff] [blame] | 2367 | |
Richard Smith | d61d4ac | 2015-08-22 20:13:39 +0000 | [diff] [blame] | 2368 | uint64_t RedeclOffset = 0; |
| 2369 | |
Douglas Gregor | 358cd44 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 2370 | // 0 indicates that this declaration was the only declaration of its entity, |
| 2371 | // and is used for space optimization. |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 2372 | if (FirstDeclID == 0) { |
Douglas Gregor | 074a409 | 2011-12-19 18:19:24 +0000 | [diff] [blame] | 2373 | FirstDeclID = ThisDeclID; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 2374 | IsKeyDecl = true; |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 2375 | IsFirstLocalDecl = true; |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2376 | } else if (unsigned N = Record.readInt()) { |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 2377 | // This declaration was the first local declaration, but may have imported |
| 2378 | // other declarations. |
| 2379 | IsKeyDecl = N == 1; |
| 2380 | IsFirstLocalDecl = true; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 2381 | |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 2382 | // We have some declarations that must be before us in our redeclaration |
| 2383 | // chain. Read them now, and remember that we ought to merge with one of |
| 2384 | // them. |
| 2385 | // FIXME: Provide a known merge target to the second and subsequent such |
| 2386 | // declaration. |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 2387 | for (unsigned I = 0; I != N - 1; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2388 | MergeWith = ReadDecl(); |
Richard Smith | d61d4ac | 2015-08-22 20:13:39 +0000 | [diff] [blame] | 2389 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2390 | RedeclOffset = ReadLocalOffset(); |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 2391 | } else { |
| 2392 | // This declaration was not the first local declaration. Read the first |
| 2393 | // local declaration now, to trigger the import of other redeclarations. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2394 | (void)ReadDecl(); |
Richard Smith | 5a4737c | 2015-02-06 02:42:59 +0000 | [diff] [blame] | 2395 | } |
| 2396 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2397 | auto *FirstDecl = cast_or_null<T>(Reader.GetDecl(FirstDeclID)); |
Douglas Gregor | 358cd44 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 2398 | if (FirstDecl != D) { |
Argyrios Kyrtzidis | 9fdd254 | 2011-02-12 07:50:47 +0000 | [diff] [blame] | 2399 | // We delay loading of the redeclaration chain to avoid deeply nested calls. |
| 2400 | // We temporarily set the first (canonical) declaration as the previous one |
| 2401 | // which is the one that matters and mark the real previous DeclID to be |
| 2402 | // loaded & attached later on. |
David Blaikie | 7e64fd9 | 2012-05-28 19:38:42 +0000 | [diff] [blame] | 2403 | D->RedeclLink = Redeclarable<T>::PreviousDeclLink(FirstDecl); |
Manuel Klimek | 093b2d4 | 2015-03-25 23:18:30 +0000 | [diff] [blame] | 2404 | D->First = FirstDecl->getCanonicalDecl(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2405 | } |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 2406 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2407 | auto *DAsT = static_cast<T *>(D); |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 2408 | |
| 2409 | // Note that we need to load local redeclarations of this decl and build a |
| 2410 | // decl chain for them. This must happen *after* we perform the preloading |
| 2411 | // above; this ensures that the redeclaration chain is built in the correct |
| 2412 | // order. |
| 2413 | if (IsFirstLocalDecl) |
Richard Smith | d61d4ac | 2015-08-22 20:13:39 +0000 | [diff] [blame] | 2414 | Reader.PendingDeclChains.push_back(std::make_pair(DAsT, RedeclOffset)); |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 2415 | |
Alexander Shaposhnikov | fbc4d68 | 2016-09-24 04:21:53 +0000 | [diff] [blame] | 2416 | return RedeclarableResult(MergeWith, FirstDeclID, IsKeyDecl); |
Argyrios Kyrtzidis | 839bbac | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 2417 | } |
| 2418 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2419 | /// Attempts to merge the given declaration (D) with another declaration |
Douglas Gregor | 2c46b5b | 2012-01-03 17:27:13 +0000 | [diff] [blame] | 2420 | /// of the same entity. |
| 2421 | template<typename T> |
Richard Smith | 5e9e56a | 2014-07-15 03:37:06 +0000 | [diff] [blame] | 2422 | void ASTDeclReader::mergeRedeclarable(Redeclarable<T> *DBase, |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2423 | RedeclarableResult &Redecl, |
| 2424 | DeclID TemplatePatternID) { |
Douglas Gregor | e097d4b | 2012-01-03 17:31:38 +0000 | [diff] [blame] | 2425 | // If modules are not available, there is no reason to perform this merge. |
David Blaikie | bbafb8a | 2012-03-11 07:00:24 +0000 | [diff] [blame] | 2426 | if (!Reader.getContext().getLangOpts().Modules) |
Douglas Gregor | e097d4b | 2012-01-03 17:31:38 +0000 | [diff] [blame] | 2427 | return; |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2428 | |
Richard Smith | 202850a | 2015-03-10 02:57:50 +0000 | [diff] [blame] | 2429 | // If we're not the canonical declaration, we don't need to merge. |
| 2430 | if (!DBase->isFirstDecl()) |
| 2431 | return; |
| 2432 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2433 | auto *D = static_cast<T *>(DBase); |
Vassil Vassilev | 916d8be | 2016-10-06 13:18:06 +0000 | [diff] [blame] | 2434 | |
Richard Smith | 5a4737c | 2015-02-06 02:42:59 +0000 | [diff] [blame] | 2435 | if (auto *Existing = Redecl.getKnownMergeTarget()) |
| 2436 | // We already know of an existing declaration we should merge with. |
| 2437 | mergeRedeclarable(D, cast<T>(Existing), Redecl, TemplatePatternID); |
| 2438 | else if (FindExistingResult ExistingRes = findExisting(D)) |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2439 | if (T *Existing = ExistingRes) |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2440 | mergeRedeclarable(D, Existing, Redecl, TemplatePatternID); |
| 2441 | } |
| 2442 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2443 | /// "Cast" to type T, asserting if we don't have an implicit conversion. |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2444 | /// We use this to put code in a template that will only be valid for certain |
| 2445 | /// instantiations. |
| 2446 | template<typename T> static T assert_cast(T t) { return t; } |
| 2447 | template<typename T> static T assert_cast(...) { |
| 2448 | llvm_unreachable("bad assert_cast"); |
| 2449 | } |
| 2450 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2451 | /// Merge together the pattern declarations from two template |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2452 | /// declarations. |
| 2453 | void ASTDeclReader::mergeTemplatePattern(RedeclarableTemplateDecl *D, |
| 2454 | RedeclarableTemplateDecl *Existing, |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 2455 | DeclID DsID, bool IsKeyDecl) { |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2456 | auto *DPattern = D->getTemplatedDecl(); |
| 2457 | auto *ExistingPattern = Existing->getTemplatedDecl(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2458 | RedeclarableResult Result(/*MergeWith*/ ExistingPattern, |
| 2459 | DPattern->getCanonicalDecl()->getGlobalID(), |
Alexander Shaposhnikov | fbc4d68 | 2016-09-24 04:21:53 +0000 | [diff] [blame] | 2460 | IsKeyDecl); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2461 | |
Richard Smith | 547864d | 2014-07-11 18:22:58 +0000 | [diff] [blame] | 2462 | if (auto *DClass = dyn_cast<CXXRecordDecl>(DPattern)) { |
| 2463 | // Merge with any existing definition. |
| 2464 | // FIXME: This is duplicated in several places. Refactor. |
| 2465 | auto *ExistingClass = |
| 2466 | cast<CXXRecordDecl>(ExistingPattern)->getCanonicalDecl(); |
Richard Smith | b648399 | 2016-05-17 22:44:15 +0000 | [diff] [blame] | 2467 | if (auto *DDD = DClass->DefinitionData) { |
| 2468 | if (ExistingClass->DefinitionData) { |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 2469 | MergeDefinitionData(ExistingClass, std::move(*DDD)); |
Richard Smith | 547864d | 2014-07-11 18:22:58 +0000 | [diff] [blame] | 2470 | } else { |
| 2471 | ExistingClass->DefinitionData = DClass->DefinitionData; |
Richard Smith | 97100e3 | 2015-06-20 00:22:34 +0000 | [diff] [blame] | 2472 | // We may have skipped this before because we thought that DClass |
| 2473 | // was the canonical declaration. |
Richard Smith | 7474dd92 | 2015-03-11 18:21:02 +0000 | [diff] [blame] | 2474 | Reader.PendingDefinitions.insert(DClass); |
Richard Smith | 547864d | 2014-07-11 18:22:58 +0000 | [diff] [blame] | 2475 | } |
| 2476 | } |
| 2477 | DClass->DefinitionData = ExistingClass->DefinitionData; |
| 2478 | |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2479 | return mergeRedeclarable(DClass, cast<TagDecl>(ExistingPattern), |
| 2480 | Result); |
Richard Smith | 547864d | 2014-07-11 18:22:58 +0000 | [diff] [blame] | 2481 | } |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2482 | if (auto *DFunction = dyn_cast<FunctionDecl>(DPattern)) |
| 2483 | return mergeRedeclarable(DFunction, cast<FunctionDecl>(ExistingPattern), |
| 2484 | Result); |
| 2485 | if (auto *DVar = dyn_cast<VarDecl>(DPattern)) |
| 2486 | return mergeRedeclarable(DVar, cast<VarDecl>(ExistingPattern), Result); |
Richard Smith | f59b735 | 2014-07-28 21:16:37 +0000 | [diff] [blame] | 2487 | if (auto *DAlias = dyn_cast<TypeAliasDecl>(DPattern)) |
| 2488 | return mergeRedeclarable(DAlias, cast<TypedefNameDecl>(ExistingPattern), |
| 2489 | Result); |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2490 | llvm_unreachable("merged an unknown kind of redeclarable template"); |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2491 | } |
| 2492 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2493 | /// Attempts to merge the given declaration (D) with another declaration |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2494 | /// of the same entity. |
| 2495 | template<typename T> |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2496 | void ASTDeclReader::mergeRedeclarable(Redeclarable<T> *DBase, T *Existing, |
| 2497 | RedeclarableResult &Redecl, |
| 2498 | DeclID TemplatePatternID) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2499 | auto *D = static_cast<T *>(DBase); |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2500 | T *ExistingCanon = Existing->getCanonicalDecl(); |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2501 | T *DCanon = D->getCanonicalDecl(); |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2502 | if (ExistingCanon != DCanon) { |
Richard Smith | 202850a | 2015-03-10 02:57:50 +0000 | [diff] [blame] | 2503 | assert(DCanon->getGlobalID() == Redecl.getFirstID() && |
| 2504 | "already merged this declaration"); |
Richard Smith | 5e9e56a | 2014-07-15 03:37:06 +0000 | [diff] [blame] | 2505 | |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2506 | // Have our redeclaration link point back at the canonical declaration |
Richard Smith | 5e9e56a | 2014-07-15 03:37:06 +0000 | [diff] [blame] | 2507 | // of the existing declaration, so that this declaration has the |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2508 | // appropriate canonical declaration. |
| 2509 | D->RedeclLink = Redeclarable<T>::PreviousDeclLink(ExistingCanon); |
Manuel Klimek | 093b2d4 | 2015-03-25 23:18:30 +0000 | [diff] [blame] | 2510 | D->First = ExistingCanon; |
Vassil Vassilev | 928c825 | 2016-04-28 14:13:28 +0000 | [diff] [blame] | 2511 | ExistingCanon->Used |= D->Used; |
| 2512 | D->Used = false; |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2513 | |
| 2514 | // When we merge a namespace, update its pointer to the first namespace. |
Richard Smith | 15e32fd | 2015-03-17 02:23:11 +0000 | [diff] [blame] | 2515 | // We cannot have loaded any redeclarations of this declaration yet, so |
| 2516 | // there's nothing else that needs to be updated. |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2517 | if (auto *Namespace = dyn_cast<NamespaceDecl>(D)) |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2518 | Namespace->AnonOrFirstNamespaceAndInline.setPointer( |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2519 | assert_cast<NamespaceDecl*>(ExistingCanon)); |
| 2520 | |
| 2521 | // When we merge a template, merge its pattern. |
| 2522 | if (auto *DTemplate = dyn_cast<RedeclarableTemplateDecl>(D)) |
| 2523 | mergeTemplatePattern( |
| 2524 | DTemplate, assert_cast<RedeclarableTemplateDecl*>(ExistingCanon), |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 2525 | TemplatePatternID, Redecl.isKeyDecl()); |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2526 | |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 2527 | // If this declaration is a key declaration, make a note of that. |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 2528 | if (Redecl.isKeyDecl()) |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 2529 | Reader.KeyDecls[ExistingCanon].push_back(Redecl.getFirstID()); |
Douglas Gregor | 2c46b5b | 2012-01-03 17:27:13 +0000 | [diff] [blame] | 2530 | } |
| 2531 | } |
| 2532 | |
Bruno Cardoso Lopes | 85f87dd | 2018-04-30 22:14:29 +0000 | [diff] [blame] | 2533 | /// ODR-like semantics for C/ObjC allow us to merge tag types and a structural |
| 2534 | /// check in Sema guarantees the types can be merged (see C11 6.2.7/1 or C89 |
| 2535 | /// 6.1.2.6/1). Although most merging is done in Sema, we need to guarantee |
| 2536 | /// that some types are mergeable during deserialization, otherwise name |
| 2537 | /// lookup fails. This is the case for EnumConstantDecl. |
Benjamin Kramer | 651d0bf | 2018-05-15 21:26:47 +0000 | [diff] [blame] | 2538 | static bool allowODRLikeMergeInC(NamedDecl *ND) { |
Bruno Cardoso Lopes | 85f87dd | 2018-04-30 22:14:29 +0000 | [diff] [blame] | 2539 | if (!ND) |
| 2540 | return false; |
| 2541 | // TODO: implement merge for other necessary decls. |
Benjamin Kramer | 651d0bf | 2018-05-15 21:26:47 +0000 | [diff] [blame] | 2542 | if (isa<EnumConstantDecl>(ND)) |
Bruno Cardoso Lopes | 85f87dd | 2018-04-30 22:14:29 +0000 | [diff] [blame] | 2543 | return true; |
| 2544 | return false; |
| 2545 | } |
| 2546 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2547 | /// Attempts to merge the given declaration (D) with another declaration |
Richard Smith | 0b87e07 | 2013-10-07 08:02:11 +0000 | [diff] [blame] | 2548 | /// of the same entity, for the case where the entity is not actually |
| 2549 | /// redeclarable. This happens, for instance, when merging the fields of |
| 2550 | /// identical class definitions from two different modules. |
| 2551 | template<typename T> |
| 2552 | void ASTDeclReader::mergeMergeable(Mergeable<T> *D) { |
| 2553 | // If modules are not available, there is no reason to perform this merge. |
| 2554 | if (!Reader.getContext().getLangOpts().Modules) |
| 2555 | return; |
| 2556 | |
Bruno Cardoso Lopes | 85f87dd | 2018-04-30 22:14:29 +0000 | [diff] [blame] | 2557 | // ODR-based merging is performed in C++ and in some cases (tag types) in C. |
| 2558 | // Note that C identically-named things in different translation units are |
| 2559 | // not redeclarations, but may still have compatible types, where ODR-like |
| 2560 | // semantics may apply. |
| 2561 | if (!Reader.getContext().getLangOpts().CPlusPlus && |
| 2562 | !allowODRLikeMergeInC(dyn_cast<NamedDecl>(static_cast<T*>(D)))) |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame] | 2563 | return; |
| 2564 | |
Richard Smith | 0b87e07 | 2013-10-07 08:02:11 +0000 | [diff] [blame] | 2565 | if (FindExistingResult ExistingRes = findExisting(static_cast<T*>(D))) |
| 2566 | if (T *Existing = ExistingRes) |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 2567 | Reader.getContext().setPrimaryMergedDecl(static_cast<T *>(D), |
| 2568 | Existing->getCanonicalDecl()); |
Richard Smith | 0b87e07 | 2013-10-07 08:02:11 +0000 | [diff] [blame] | 2569 | } |
| 2570 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2571 | void ASTDeclReader::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) { |
| 2572 | VisitDecl(D); |
| 2573 | unsigned NumVars = D->varlist_size(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2574 | SmallVector<Expr *, 16> Vars; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2575 | Vars.reserve(NumVars); |
| 2576 | for (unsigned i = 0; i != NumVars; ++i) { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2577 | Vars.push_back(Record.readExpr()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2578 | } |
| 2579 | D->setVars(Vars); |
| 2580 | } |
| 2581 | |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 2582 | void ASTDeclReader::VisitOMPAllocateDecl(OMPAllocateDecl *D) { |
| 2583 | VisitDecl(D); |
| 2584 | unsigned NumVars = D->varlist_size(); |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 2585 | unsigned NumClauses = D->clauselist_size(); |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 2586 | SmallVector<Expr *, 16> Vars; |
| 2587 | Vars.reserve(NumVars); |
| 2588 | for (unsigned i = 0; i != NumVars; ++i) { |
| 2589 | Vars.push_back(Record.readExpr()); |
| 2590 | } |
| 2591 | D->setVars(Vars); |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 2592 | SmallVector<OMPClause *, 8> Clauses; |
| 2593 | Clauses.reserve(NumClauses); |
| 2594 | OMPClauseReader ClauseReader(Record); |
| 2595 | for (unsigned I = 0; I != NumClauses; ++I) |
| 2596 | Clauses.push_back(ClauseReader.readClause()); |
| 2597 | D->setClauses(Clauses); |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 2598 | } |
| 2599 | |
Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 2600 | void ASTDeclReader::VisitOMPRequiresDecl(OMPRequiresDecl * D) { |
| 2601 | VisitDecl(D); |
| 2602 | unsigned NumClauses = D->clauselist_size(); |
| 2603 | SmallVector<OMPClause *, 8> Clauses; |
| 2604 | Clauses.reserve(NumClauses); |
| 2605 | OMPClauseReader ClauseReader(Record); |
| 2606 | for (unsigned I = 0; I != NumClauses; ++I) |
| 2607 | Clauses.push_back(ClauseReader.readClause()); |
| 2608 | D->setClauses(Clauses); |
| 2609 | } |
| 2610 | |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 2611 | void ASTDeclReader::VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D) { |
Alexey Bataev | c5b1d32 | 2016-03-04 09:22:22 +0000 | [diff] [blame] | 2612 | VisitValueDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2613 | D->setLocation(ReadSourceLocation()); |
Alexey Bataev | e6aa469 | 2018-09-13 16:54:05 +0000 | [diff] [blame] | 2614 | Expr *In = Record.readExpr(); |
| 2615 | Expr *Out = Record.readExpr(); |
| 2616 | D->setCombinerData(In, Out); |
| 2617 | Expr *Combiner = Record.readExpr(); |
| 2618 | D->setCombiner(Combiner); |
| 2619 | Expr *Orig = Record.readExpr(); |
| 2620 | Expr *Priv = Record.readExpr(); |
| 2621 | D->setInitializerData(Orig, Priv); |
| 2622 | Expr *Init = Record.readExpr(); |
| 2623 | auto IK = static_cast<OMPDeclareReductionDecl::InitKind>(Record.readInt()); |
| 2624 | D->setInitializer(Init, IK); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2625 | D->PrevDeclInScope = ReadDeclID(); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 2626 | } |
| 2627 | |
Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 2628 | void ASTDeclReader::VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D) { |
| 2629 | VisitValueDecl(D); |
| 2630 | D->setLocation(ReadSourceLocation()); |
| 2631 | Expr *MapperVarRefE = Record.readExpr(); |
| 2632 | D->setMapperVarRef(MapperVarRefE); |
| 2633 | D->VarName = Record.readDeclarationName(); |
| 2634 | D->PrevDeclInScope = ReadDeclID(); |
| 2635 | unsigned NumClauses = D->clauselist_size(); |
| 2636 | SmallVector<OMPClause *, 8> Clauses; |
| 2637 | Clauses.reserve(NumClauses); |
| 2638 | OMPClauseReader ClauseReader(Record); |
| 2639 | for (unsigned I = 0; I != NumClauses; ++I) |
| 2640 | Clauses.push_back(ClauseReader.readClause()); |
| 2641 | D->setClauses(Clauses); |
| 2642 | } |
| 2643 | |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 2644 | void ASTDeclReader::VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D) { |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 2645 | VisitVarDecl(D); |
| 2646 | } |
| 2647 | |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 2648 | //===----------------------------------------------------------------------===// |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 2649 | // Attribute Reading |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 2650 | //===----------------------------------------------------------------------===// |
| 2651 | |
Richard Smith | e43e2b3 | 2018-08-20 21:47:29 +0000 | [diff] [blame] | 2652 | namespace { |
| 2653 | class AttrReader { |
| 2654 | ModuleFile *F; |
| 2655 | ASTReader *Reader; |
| 2656 | const ASTReader::RecordData &Record; |
| 2657 | unsigned &Idx; |
| 2658 | |
| 2659 | public: |
| 2660 | AttrReader(ModuleFile &F, ASTReader &Reader, |
| 2661 | const ASTReader::RecordData &Record, unsigned &Idx) |
| 2662 | : F(&F), Reader(&Reader), Record(Record), Idx(Idx) {} |
| 2663 | |
| 2664 | const uint64_t &readInt() { return Record[Idx++]; } |
| 2665 | |
| 2666 | SourceRange readSourceRange() { |
| 2667 | return Reader->ReadSourceRange(*F, Record, Idx); |
| 2668 | } |
| 2669 | |
Erich Keane | 6a24e80 | 2019-09-13 17:39:31 +0000 | [diff] [blame] | 2670 | SourceLocation readSourceLocation() { |
| 2671 | return Reader->ReadSourceLocation(*F, Record, Idx); |
| 2672 | } |
| 2673 | |
Richard Smith | e43e2b3 | 2018-08-20 21:47:29 +0000 | [diff] [blame] | 2674 | Expr *readExpr() { return Reader->ReadExpr(*F); } |
| 2675 | |
| 2676 | std::string readString() { |
| 2677 | return Reader->ReadString(Record, Idx); |
| 2678 | } |
| 2679 | |
| 2680 | TypeSourceInfo *getTypeSourceInfo() { |
| 2681 | return Reader->GetTypeSourceInfo(*F, Record, Idx); |
| 2682 | } |
| 2683 | |
| 2684 | IdentifierInfo *getIdentifierInfo() { |
| 2685 | return Reader->GetIdentifierInfo(*F, Record, Idx); |
| 2686 | } |
| 2687 | |
| 2688 | VersionTuple readVersionTuple() { |
| 2689 | return ASTReader::ReadVersionTuple(Record, Idx); |
| 2690 | } |
| 2691 | |
| 2692 | template <typename T> T *GetLocalDeclAs(uint32_t LocalID) { |
| 2693 | return cast_or_null<T>(Reader->GetLocalDecl(*F, LocalID)); |
| 2694 | } |
| 2695 | }; |
| 2696 | } |
| 2697 | |
| 2698 | Attr *ASTReader::ReadAttr(ModuleFile &M, const RecordData &Rec, |
| 2699 | unsigned &Idx) { |
| 2700 | AttrReader Record(M, *this, Rec, Idx); |
| 2701 | auto V = Record.readInt(); |
| 2702 | if (!V) |
| 2703 | return nullptr; |
| 2704 | |
| 2705 | Attr *New = nullptr; |
| 2706 | // Kind is stored as a 1-based integer because 0 is used to indicate a null |
| 2707 | // Attr pointer. |
| 2708 | auto Kind = static_cast<attr::Kind>(V - 1); |
Richard Smith | e43e2b3 | 2018-08-20 21:47:29 +0000 | [diff] [blame] | 2709 | ASTContext &Context = getContext(); |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 2710 | |
Erich Keane | 6a24e80 | 2019-09-13 17:39:31 +0000 | [diff] [blame] | 2711 | IdentifierInfo *AttrName = Record.getIdentifierInfo(); |
| 2712 | IdentifierInfo *ScopeName = Record.getIdentifierInfo(); |
| 2713 | SourceRange AttrRange = Record.readSourceRange(); |
| 2714 | SourceLocation ScopeLoc = Record.readSourceLocation(); |
| 2715 | unsigned ParsedKind = Record.readInt(); |
| 2716 | unsigned Syntax = Record.readInt(); |
| 2717 | unsigned SpellingIndex = Record.readInt(); |
| 2718 | |
| 2719 | AttributeCommonInfo Info(AttrName, ScopeName, AttrRange, ScopeLoc, |
| 2720 | AttributeCommonInfo::Kind(ParsedKind), |
| 2721 | AttributeCommonInfo::Syntax(Syntax), SpellingIndex); |
| 2722 | |
Alexis Hunt | dcfba7b | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 2723 | #include "clang/Serialization/AttrPCHRead.inc" |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 2724 | |
Richard Smith | e43e2b3 | 2018-08-20 21:47:29 +0000 | [diff] [blame] | 2725 | assert(New && "Unable to decode attribute?"); |
| 2726 | return New; |
| 2727 | } |
| 2728 | |
| 2729 | /// Reads attributes from the current stream position. |
| 2730 | void ASTReader::ReadAttributes(ASTRecordReader &Record, AttrVec &Attrs) { |
| 2731 | for (unsigned I = 0, E = Record.readInt(); I != E; ++I) |
| 2732 | Attrs.push_back(Record.readAttr()); |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 2733 | } |
| 2734 | |
| 2735 | //===----------------------------------------------------------------------===// |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2736 | // ASTReader Implementation |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 2737 | //===----------------------------------------------------------------------===// |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 2738 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2739 | /// Note that we have loaded the declaration with the given |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 2740 | /// Index. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2741 | /// |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 2742 | /// This routine notes that this declaration has already been loaded, |
| 2743 | /// so that future GetDecl calls will return this declaration rather |
| 2744 | /// than trying to load a new declaration. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2745 | inline void ASTReader::LoadedDecl(unsigned Index, Decl *D) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 2746 | assert(!DeclsLoaded[Index] && "Decl loaded twice?"); |
| 2747 | DeclsLoaded[Index] = D; |
| 2748 | } |
| 2749 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2750 | /// Determine whether the consumer will be interested in seeing |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 2751 | /// this declaration (via HandleTopLevelDecl). |
| 2752 | /// |
| 2753 | /// This routine should return true for anything that might affect |
| 2754 | /// code generation, e.g., inline function definitions, Objective-C |
| 2755 | /// declarations with metadata, etc. |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 2756 | static bool isConsumerInterestedIn(ASTContext &Ctx, Decl *D, bool HasBody) { |
Argyrios Kyrtzidis | a98e861 | 2011-09-13 21:35:00 +0000 | [diff] [blame] | 2757 | // An ObjCMethodDecl is never considered as "interesting" because its |
| 2758 | // implementation container always is. |
| 2759 | |
Richard Smith | cd4a7a4 | 2017-09-07 00:55:55 +0000 | [diff] [blame] | 2760 | // An ImportDecl or VarDecl imported from a module map module will get |
| 2761 | // emitted when we import the relevant module. |
Richard Smith | 520a37f | 2019-02-05 23:37:13 +0000 | [diff] [blame] | 2762 | if (isPartOfPerModuleInitializer(D)) { |
Richard Smith | cd4a7a4 | 2017-09-07 00:55:55 +0000 | [diff] [blame] | 2763 | auto *M = D->getImportedOwningModule(); |
| 2764 | if (M && M->Kind == Module::ModuleMapModule && |
| 2765 | Ctx.DeclMustBeEmitted(D)) |
| 2766 | return false; |
| 2767 | } |
Richard Smith | dc1f042 | 2016-07-20 19:10:16 +0000 | [diff] [blame] | 2768 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2769 | if (isa<FileScopeAsmDecl>(D) || |
| 2770 | isa<ObjCProtocolDecl>(D) || |
Ben Langmuir | 332aafe | 2014-01-31 01:06:56 +0000 | [diff] [blame] | 2771 | isa<ObjCImplDecl>(D) || |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 2772 | isa<ImportDecl>(D) || |
Nico Weber | 6622029 | 2016-03-02 17:28:48 +0000 | [diff] [blame] | 2773 | isa<PragmaCommentDecl>(D) || |
Alexey Bataev | c5b1d32 | 2016-03-04 09:22:22 +0000 | [diff] [blame] | 2774 | isa<PragmaDetectMismatchDecl>(D)) |
Daniel Dunbar | 865c2a7 | 2009-09-17 03:06:44 +0000 | [diff] [blame] | 2775 | return true; |
Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 2776 | if (isa<OMPThreadPrivateDecl>(D) || isa<OMPDeclareReductionDecl>(D) || |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 2777 | isa<OMPDeclareMapperDecl>(D) || isa<OMPAllocateDecl>(D)) |
Alexey Bataev | c5b1d32 | 2016-03-04 09:22:22 +0000 | [diff] [blame] | 2778 | return !D->getDeclContext()->isFunctionOrMethod(); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2779 | if (const auto *Var = dyn_cast<VarDecl>(D)) |
Argyrios Kyrtzidis | 4ba81b2 | 2010-08-05 09:47:59 +0000 | [diff] [blame] | 2780 | return Var->isFileVarDecl() && |
Alexey Bataev | d01b749 | 2018-08-15 19:45:12 +0000 | [diff] [blame] | 2781 | (Var->isThisDeclarationADefinition() == VarDecl::Definition || |
| 2782 | OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(Var)); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2783 | if (const auto *Func = dyn_cast<FunctionDecl>(D)) |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 2784 | return Func->doesThisDeclarationHaveABody() || HasBody; |
David Blaikie | 1ac9c98 | 2017-04-11 21:13:37 +0000 | [diff] [blame] | 2785 | |
| 2786 | if (auto *ES = D->getASTContext().getExternalSource()) |
| 2787 | if (ES->hasExternalDefinitions(D) == ExternalASTSource::EK_Never) |
| 2788 | return true; |
| 2789 | |
Douglas Gregor | 87d8124 | 2011-09-10 00:22:34 +0000 | [diff] [blame] | 2790 | return false; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 2791 | } |
| 2792 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2793 | /// Get the correct cursor and offset for loading a declaration. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2794 | ASTReader::RecordLocation |
Richard Smith | cb34bd3 | 2016-03-27 07:28:06 +0000 | [diff] [blame] | 2795 | ASTReader::DeclCursorForID(DeclID ID, SourceLocation &Loc) { |
Douglas Gregor | 047d2ef | 2011-07-20 00:27:43 +0000 | [diff] [blame] | 2796 | GlobalDeclMapType::iterator I = GlobalDeclMap.find(ID); |
| 2797 | assert(I != GlobalDeclMap.end() && "Corrupted global declaration map"); |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2798 | ModuleFile *M = I->second; |
Richard Smith | 34da751 | 2016-03-27 05:52:25 +0000 | [diff] [blame] | 2799 | const DeclOffset &DOffs = |
| 2800 | M->DeclOffsets[ID - M->BaseDeclID - NUM_PREDEF_DECL_IDS]; |
Richard Smith | cb34bd3 | 2016-03-27 07:28:06 +0000 | [diff] [blame] | 2801 | Loc = TranslateSourceLocation(*M, DOffs.getLocation()); |
Argyrios Kyrtzidis | 81ddd18 | 2011-10-27 18:47:35 +0000 | [diff] [blame] | 2802 | return RecordLocation(M, DOffs.BitOffset); |
Sebastian Redl | 3462779 | 2010-07-20 22:46:15 +0000 | [diff] [blame] | 2803 | } |
| 2804 | |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 2805 | ASTReader::RecordLocation ASTReader::getLocalBitOffset(uint64_t GlobalOffset) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2806 | auto I = GlobalBitOffsetsMap.find(GlobalOffset); |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 2807 | |
| 2808 | assert(I != GlobalBitOffsetsMap.end() && "Corrupted global bit offsets map"); |
| 2809 | return RecordLocation(I->second, GlobalOffset - I->second->GlobalBitOffset); |
| 2810 | } |
| 2811 | |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2812 | uint64_t ASTReader::getGlobalBitOffset(ModuleFile &M, uint32_t LocalOffset) { |
Douglas Gregor | c27b287 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 2813 | return LocalOffset + M.GlobalBitOffset; |
| 2814 | } |
| 2815 | |
Richard Smith | bf78e64 | 2013-06-24 22:51:00 +0000 | [diff] [blame] | 2816 | static bool isSameTemplateParameterList(const TemplateParameterList *X, |
| 2817 | const TemplateParameterList *Y); |
| 2818 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2819 | /// Determine whether two template parameters are similar enough |
Richard Smith | bf78e64 | 2013-06-24 22:51:00 +0000 | [diff] [blame] | 2820 | /// that they may be used in declarations of the same template. |
| 2821 | static bool isSameTemplateParameter(const NamedDecl *X, |
| 2822 | const NamedDecl *Y) { |
| 2823 | if (X->getKind() != Y->getKind()) |
| 2824 | return false; |
| 2825 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2826 | if (const auto *TX = dyn_cast<TemplateTypeParmDecl>(X)) { |
| 2827 | const auto *TY = cast<TemplateTypeParmDecl>(Y); |
Richard Smith | bf78e64 | 2013-06-24 22:51:00 +0000 | [diff] [blame] | 2828 | return TX->isParameterPack() == TY->isParameterPack(); |
| 2829 | } |
| 2830 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2831 | if (const auto *TX = dyn_cast<NonTypeTemplateParmDecl>(X)) { |
| 2832 | const auto *TY = cast<NonTypeTemplateParmDecl>(Y); |
Richard Smith | bf78e64 | 2013-06-24 22:51:00 +0000 | [diff] [blame] | 2833 | return TX->isParameterPack() == TY->isParameterPack() && |
| 2834 | TX->getASTContext().hasSameType(TX->getType(), TY->getType()); |
| 2835 | } |
| 2836 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2837 | const auto *TX = cast<TemplateTemplateParmDecl>(X); |
| 2838 | const auto *TY = cast<TemplateTemplateParmDecl>(Y); |
Richard Smith | bf78e64 | 2013-06-24 22:51:00 +0000 | [diff] [blame] | 2839 | return TX->isParameterPack() == TY->isParameterPack() && |
| 2840 | isSameTemplateParameterList(TX->getTemplateParameters(), |
| 2841 | TY->getTemplateParameters()); |
| 2842 | } |
| 2843 | |
Richard Smith | 32952e1 | 2014-10-14 02:00:47 +0000 | [diff] [blame] | 2844 | static NamespaceDecl *getNamespace(const NestedNameSpecifier *X) { |
| 2845 | if (auto *NS = X->getAsNamespace()) |
| 2846 | return NS; |
| 2847 | if (auto *NAS = X->getAsNamespaceAlias()) |
| 2848 | return NAS->getNamespace(); |
| 2849 | return nullptr; |
| 2850 | } |
| 2851 | |
| 2852 | static bool isSameQualifier(const NestedNameSpecifier *X, |
| 2853 | const NestedNameSpecifier *Y) { |
| 2854 | if (auto *NSX = getNamespace(X)) { |
| 2855 | auto *NSY = getNamespace(Y); |
| 2856 | if (!NSY || NSX->getCanonicalDecl() != NSY->getCanonicalDecl()) |
| 2857 | return false; |
| 2858 | } else if (X->getKind() != Y->getKind()) |
| 2859 | return false; |
| 2860 | |
| 2861 | // FIXME: For namespaces and types, we're permitted to check that the entity |
| 2862 | // is named via the same tokens. We should probably do so. |
| 2863 | switch (X->getKind()) { |
| 2864 | case NestedNameSpecifier::Identifier: |
| 2865 | if (X->getAsIdentifier() != Y->getAsIdentifier()) |
| 2866 | return false; |
| 2867 | break; |
| 2868 | case NestedNameSpecifier::Namespace: |
| 2869 | case NestedNameSpecifier::NamespaceAlias: |
| 2870 | // We've already checked that we named the same namespace. |
| 2871 | break; |
| 2872 | case NestedNameSpecifier::TypeSpec: |
| 2873 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 2874 | if (X->getAsType()->getCanonicalTypeInternal() != |
| 2875 | Y->getAsType()->getCanonicalTypeInternal()) |
| 2876 | return false; |
| 2877 | break; |
| 2878 | case NestedNameSpecifier::Global: |
| 2879 | case NestedNameSpecifier::Super: |
| 2880 | return true; |
| 2881 | } |
| 2882 | |
| 2883 | // Recurse into earlier portion of NNS, if any. |
| 2884 | auto *PX = X->getPrefix(); |
| 2885 | auto *PY = Y->getPrefix(); |
| 2886 | if (PX && PY) |
| 2887 | return isSameQualifier(PX, PY); |
| 2888 | return !PX && !PY; |
| 2889 | } |
| 2890 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2891 | /// Determine whether two template parameter lists are similar enough |
Richard Smith | bf78e64 | 2013-06-24 22:51:00 +0000 | [diff] [blame] | 2892 | /// that they may be used in declarations of the same template. |
| 2893 | static bool isSameTemplateParameterList(const TemplateParameterList *X, |
| 2894 | const TemplateParameterList *Y) { |
| 2895 | if (X->size() != Y->size()) |
| 2896 | return false; |
| 2897 | |
| 2898 | for (unsigned I = 0, N = X->size(); I != N; ++I) |
| 2899 | if (!isSameTemplateParameter(X->getParam(I), Y->getParam(I))) |
| 2900 | return false; |
| 2901 | |
| 2902 | return true; |
| 2903 | } |
| 2904 | |
George Burgess IV | 9584508 | 2017-02-15 22:43:27 +0000 | [diff] [blame] | 2905 | /// Determine whether the attributes we can overload on are identical for A and |
George Burgess IV | b776021 | 2017-02-24 02:49:47 +0000 | [diff] [blame] | 2906 | /// B. Will ignore any overloadable attrs represented in the type of A and B. |
George Burgess IV | 9584508 | 2017-02-15 22:43:27 +0000 | [diff] [blame] | 2907 | static bool hasSameOverloadableAttrs(const FunctionDecl *A, |
| 2908 | const FunctionDecl *B) { |
George Burgess IV | b776021 | 2017-02-24 02:49:47 +0000 | [diff] [blame] | 2909 | // Note that pass_object_size attributes are represented in the function's |
| 2910 | // ExtParameterInfo, so we don't need to check them here. |
| 2911 | |
George Burgess IV | 9584508 | 2017-02-15 22:43:27 +0000 | [diff] [blame] | 2912 | llvm::FoldingSetNodeID Cand1ID, Cand2ID; |
Michael Kruse | dc5ce72 | 2018-08-03 01:21:16 +0000 | [diff] [blame] | 2913 | auto AEnableIfAttrs = A->specific_attrs<EnableIfAttr>(); |
| 2914 | auto BEnableIfAttrs = B->specific_attrs<EnableIfAttr>(); |
Michael Kruse | 157a355 | 2018-12-10 15:16:37 +0000 | [diff] [blame] | 2915 | |
| 2916 | for (auto Pair : zip_longest(AEnableIfAttrs, BEnableIfAttrs)) { |
| 2917 | Optional<EnableIfAttr *> Cand1A = std::get<0>(Pair); |
| 2918 | Optional<EnableIfAttr *> Cand2A = std::get<1>(Pair); |
| 2919 | |
| 2920 | // Return false if the number of enable_if attributes is different. |
| 2921 | if (!Cand1A || !Cand2A) |
| 2922 | return false; |
| 2923 | |
George Burgess IV | 9584508 | 2017-02-15 22:43:27 +0000 | [diff] [blame] | 2924 | Cand1ID.clear(); |
| 2925 | Cand2ID.clear(); |
| 2926 | |
Michael Kruse | 157a355 | 2018-12-10 15:16:37 +0000 | [diff] [blame] | 2927 | (*Cand1A)->getCond()->Profile(Cand1ID, A->getASTContext(), true); |
| 2928 | (*Cand2A)->getCond()->Profile(Cand2ID, B->getASTContext(), true); |
| 2929 | |
| 2930 | // Return false if any of the enable_if expressions of A and B are |
| 2931 | // different. |
George Burgess IV | 9584508 | 2017-02-15 22:43:27 +0000 | [diff] [blame] | 2932 | if (Cand1ID != Cand2ID) |
| 2933 | return false; |
| 2934 | } |
Michael Kruse | 157a355 | 2018-12-10 15:16:37 +0000 | [diff] [blame] | 2935 | return true; |
George Burgess IV | 9584508 | 2017-02-15 22:43:27 +0000 | [diff] [blame] | 2936 | } |
| 2937 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2938 | /// Determine whether the two declarations refer to the same entity. |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 2939 | static bool isSameEntity(NamedDecl *X, NamedDecl *Y) { |
| 2940 | assert(X->getDeclName() == Y->getDeclName() && "Declaration name mismatch!"); |
Richard Smith | f463436 | 2014-09-03 23:11:22 +0000 | [diff] [blame] | 2941 | |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 2942 | if (X == Y) |
| 2943 | return true; |
Richard Smith | f463436 | 2014-09-03 23:11:22 +0000 | [diff] [blame] | 2944 | |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 2945 | // Must be in the same context. |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 2946 | // |
| 2947 | // Note that we can't use DeclContext::Equals here, because the DeclContexts |
| 2948 | // could be two different declarations of the same function. (We will fix the |
| 2949 | // semantic DC to refer to the primary definition after merging.) |
| 2950 | if (!declaresSameEntity(cast<Decl>(X->getDeclContext()->getRedeclContext()), |
| 2951 | cast<Decl>(Y->getDeclContext()->getRedeclContext()))) |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 2952 | return false; |
Douglas Gregor | 9b7b391 | 2012-01-04 16:44:10 +0000 | [diff] [blame] | 2953 | |
| 2954 | // Two typedefs refer to the same entity if they have the same underlying |
| 2955 | // type. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2956 | if (const auto *TypedefX = dyn_cast<TypedefNameDecl>(X)) |
| 2957 | if (const auto *TypedefY = dyn_cast<TypedefNameDecl>(Y)) |
Douglas Gregor | 9b7b391 | 2012-01-04 16:44:10 +0000 | [diff] [blame] | 2958 | return X->getASTContext().hasSameType(TypedefX->getUnderlyingType(), |
| 2959 | TypedefY->getUnderlyingType()); |
Richard Smith | f463436 | 2014-09-03 23:11:22 +0000 | [diff] [blame] | 2960 | |
Douglas Gregor | 9b7b391 | 2012-01-04 16:44:10 +0000 | [diff] [blame] | 2961 | // Must have the same kind. |
| 2962 | if (X->getKind() != Y->getKind()) |
| 2963 | return false; |
Richard Smith | f463436 | 2014-09-03 23:11:22 +0000 | [diff] [blame] | 2964 | |
Douglas Gregor | da38930 | 2012-01-01 21:47:52 +0000 | [diff] [blame] | 2965 | // Objective-C classes and protocols with the same name always match. |
| 2966 | if (isa<ObjCInterfaceDecl>(X) || isa<ObjCProtocolDecl>(X)) |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 2967 | return true; |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 2968 | |
| 2969 | if (isa<ClassTemplateSpecializationDecl>(X)) { |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2970 | // No need to handle these here: we merge them when adding them to the |
| 2971 | // template. |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 2972 | return false; |
| 2973 | } |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2974 | |
Douglas Gregor | 2009cee | 2012-01-03 22:46:00 +0000 | [diff] [blame] | 2975 | // Compatible tags match. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2976 | if (const auto *TagX = dyn_cast<TagDecl>(X)) { |
| 2977 | const auto *TagY = cast<TagDecl>(Y); |
Joao Matos | e9a3ed4 | 2012-08-31 22:18:20 +0000 | [diff] [blame] | 2978 | return (TagX->getTagKind() == TagY->getTagKind()) || |
| 2979 | ((TagX->getTagKind() == TTK_Struct || TagX->getTagKind() == TTK_Class || |
| 2980 | TagX->getTagKind() == TTK_Interface) && |
| 2981 | (TagY->getTagKind() == TTK_Struct || TagY->getTagKind() == TTK_Class || |
| 2982 | TagY->getTagKind() == TTK_Interface)); |
| 2983 | } |
Richard Smith | 8f8f05c | 2013-06-24 04:45:28 +0000 | [diff] [blame] | 2984 | |
Joao Matos | e9a3ed4 | 2012-08-31 22:18:20 +0000 | [diff] [blame] | 2985 | // Functions with the same type and linkage match. |
Richard Smith | f463436 | 2014-09-03 23:11:22 +0000 | [diff] [blame] | 2986 | // FIXME: This needs to cope with merging of prototyped/non-prototyped |
| 2987 | // functions, etc. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2988 | if (const auto *FuncX = dyn_cast<FunctionDecl>(X)) { |
| 2989 | const auto *FuncY = cast<FunctionDecl>(Y); |
| 2990 | if (const auto *CtorX = dyn_cast<CXXConstructorDecl>(X)) { |
| 2991 | const auto *CtorY = cast<CXXConstructorDecl>(Y); |
Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 2992 | if (CtorX->getInheritedConstructor() && |
| 2993 | !isSameEntity(CtorX->getInheritedConstructor().getConstructor(), |
| 2994 | CtorY->getInheritedConstructor().getConstructor())) |
| 2995 | return false; |
| 2996 | } |
Erich Keane | 281d20b | 2018-01-08 21:34:17 +0000 | [diff] [blame] | 2997 | |
| 2998 | if (FuncX->isMultiVersion() != FuncY->isMultiVersion()) |
| 2999 | return false; |
| 3000 | |
| 3001 | // Multiversioned functions with different feature strings are represented |
| 3002 | // as separate declarations. |
| 3003 | if (FuncX->isMultiVersion()) { |
| 3004 | const auto *TAX = FuncX->getAttr<TargetAttr>(); |
| 3005 | const auto *TAY = FuncY->getAttr<TargetAttr>(); |
| 3006 | assert(TAX && TAY && "Multiversion Function without target attribute"); |
| 3007 | |
| 3008 | if (TAX->getFeaturesStr() != TAY->getFeaturesStr()) |
| 3009 | return false; |
| 3010 | } |
| 3011 | |
Richard Smith | a54d324 | 2017-03-08 23:00:26 +0000 | [diff] [blame] | 3012 | ASTContext &C = FuncX->getASTContext(); |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 3013 | auto GetTypeAsWritten = [](const FunctionDecl *FD) { |
| 3014 | // Map to the first declaration that we've already merged into this one. |
| 3015 | // The TSI of redeclarations might not match (due to calling conventions |
| 3016 | // being inherited onto the type but not the TSI), but the TSI type of |
| 3017 | // the first declaration of the function should match across modules. |
| 3018 | FD = FD->getCanonicalDecl(); |
| 3019 | return FD->getTypeSourceInfo() ? FD->getTypeSourceInfo()->getType() |
| 3020 | : FD->getType(); |
| 3021 | }; |
| 3022 | QualType XT = GetTypeAsWritten(FuncX), YT = GetTypeAsWritten(FuncY); |
| 3023 | if (!C.hasSameType(XT, YT)) { |
Richard Smith | a54d324 | 2017-03-08 23:00:26 +0000 | [diff] [blame] | 3024 | // We can get functions with different types on the redecl chain in C++17 |
| 3025 | // if they have differing exception specifications and at least one of |
| 3026 | // the excpetion specs is unresolved. |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 3027 | auto *XFPT = XT->getAs<FunctionProtoType>(); |
| 3028 | auto *YFPT = YT->getAs<FunctionProtoType>(); |
Aaron Ballman | c351fba | 2017-12-04 20:27:34 +0000 | [diff] [blame] | 3029 | if (C.getLangOpts().CPlusPlus17 && XFPT && YFPT && |
Richard Smith | a54d324 | 2017-03-08 23:00:26 +0000 | [diff] [blame] | 3030 | (isUnresolvedExceptionSpec(XFPT->getExceptionSpecType()) || |
| 3031 | isUnresolvedExceptionSpec(YFPT->getExceptionSpecType())) && |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 3032 | C.hasSameFunctionTypeIgnoringExceptionSpec(XT, YT)) |
Richard Smith | a54d324 | 2017-03-08 23:00:26 +0000 | [diff] [blame] | 3033 | return true; |
| 3034 | return false; |
| 3035 | } |
George Burgess IV | 9584508 | 2017-02-15 22:43:27 +0000 | [diff] [blame] | 3036 | return FuncX->getLinkageInternal() == FuncY->getLinkageInternal() && |
George Burgess IV | 9584508 | 2017-02-15 22:43:27 +0000 | [diff] [blame] | 3037 | hasSameOverloadableAttrs(FuncX, FuncY); |
Douglas Gregor | b258569 | 2012-01-04 17:13:46 +0000 | [diff] [blame] | 3038 | } |
Axel Naumann | 866ba3e | 2012-10-01 09:18:00 +0000 | [diff] [blame] | 3039 | |
Douglas Gregor | b8c6f1e | 2012-01-04 17:21:36 +0000 | [diff] [blame] | 3040 | // Variables with the same type and linkage match. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3041 | if (const auto *VarX = dyn_cast<VarDecl>(X)) { |
| 3042 | const auto *VarY = cast<VarDecl>(Y); |
Yaron Keren | e94da64 | 2016-01-22 19:03:27 +0000 | [diff] [blame] | 3043 | if (VarX->getLinkageInternal() == VarY->getLinkageInternal()) { |
| 3044 | ASTContext &C = VarX->getASTContext(); |
| 3045 | if (C.hasSameType(VarX->getType(), VarY->getType())) |
| 3046 | return true; |
| 3047 | |
| 3048 | // We can get decls with different types on the redecl chain. Eg. |
| 3049 | // template <typename T> struct S { static T Var[]; }; // #1 |
| 3050 | // template <typename T> T S<T>::Var[sizeof(T)]; // #2 |
| 3051 | // Only? happens when completing an incomplete array type. In this case |
Vassil Vassilev | 4d75e8d | 2016-02-28 19:08:24 +0000 | [diff] [blame] | 3052 | // when comparing #1 and #2 we should go through their element type. |
Yaron Keren | e94da64 | 2016-01-22 19:03:27 +0000 | [diff] [blame] | 3053 | const ArrayType *VarXTy = C.getAsArrayType(VarX->getType()); |
| 3054 | const ArrayType *VarYTy = C.getAsArrayType(VarY->getType()); |
| 3055 | if (!VarXTy || !VarYTy) |
| 3056 | return false; |
| 3057 | if (VarXTy->isIncompleteArrayType() || VarYTy->isIncompleteArrayType()) |
| 3058 | return C.hasSameType(VarXTy->getElementType(), VarYTy->getElementType()); |
| 3059 | } |
| 3060 | return false; |
Douglas Gregor | b8c6f1e | 2012-01-04 17:21:36 +0000 | [diff] [blame] | 3061 | } |
Richard Smith | 8f8f05c | 2013-06-24 04:45:28 +0000 | [diff] [blame] | 3062 | |
Douglas Gregor | cfe7dc6 | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 3063 | // Namespaces with the same name and inlinedness match. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3064 | if (const auto *NamespaceX = dyn_cast<NamespaceDecl>(X)) { |
| 3065 | const auto *NamespaceY = cast<NamespaceDecl>(Y); |
Douglas Gregor | cfe7dc6 | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 3066 | return NamespaceX->isInline() == NamespaceY->isInline(); |
| 3067 | } |
Axel Naumann | 866ba3e | 2012-10-01 09:18:00 +0000 | [diff] [blame] | 3068 | |
Richard Smith | 8f8f05c | 2013-06-24 04:45:28 +0000 | [diff] [blame] | 3069 | // Identical template names and kinds match if their template parameter lists |
| 3070 | // and patterns match. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3071 | if (const auto *TemplateX = dyn_cast<TemplateDecl>(X)) { |
| 3072 | const auto *TemplateY = cast<TemplateDecl>(Y); |
Richard Smith | 8f8f05c | 2013-06-24 04:45:28 +0000 | [diff] [blame] | 3073 | return isSameEntity(TemplateX->getTemplatedDecl(), |
Richard Smith | bf78e64 | 2013-06-24 22:51:00 +0000 | [diff] [blame] | 3074 | TemplateY->getTemplatedDecl()) && |
| 3075 | isSameTemplateParameterList(TemplateX->getTemplateParameters(), |
| 3076 | TemplateY->getTemplateParameters()); |
Richard Smith | 8f8f05c | 2013-06-24 04:45:28 +0000 | [diff] [blame] | 3077 | } |
Axel Naumann | 866ba3e | 2012-10-01 09:18:00 +0000 | [diff] [blame] | 3078 | |
Richard Smith | 0b87e07 | 2013-10-07 08:02:11 +0000 | [diff] [blame] | 3079 | // Fields with the same name and the same type match. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3080 | if (const auto *FDX = dyn_cast<FieldDecl>(X)) { |
| 3081 | const auto *FDY = cast<FieldDecl>(Y); |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame] | 3082 | // FIXME: Also check the bitwidth is odr-equivalent, if any. |
Richard Smith | 0b87e07 | 2013-10-07 08:02:11 +0000 | [diff] [blame] | 3083 | return X->getASTContext().hasSameType(FDX->getType(), FDY->getType()); |
| 3084 | } |
| 3085 | |
Richard Smith | 8cbd895 | 2015-08-04 02:05:09 +0000 | [diff] [blame] | 3086 | // Indirect fields with the same target field match. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3087 | if (const auto *IFDX = dyn_cast<IndirectFieldDecl>(X)) { |
| 3088 | const auto *IFDY = cast<IndirectFieldDecl>(Y); |
Richard Smith | 8cbd895 | 2015-08-04 02:05:09 +0000 | [diff] [blame] | 3089 | return IFDX->getAnonField()->getCanonicalDecl() == |
| 3090 | IFDY->getAnonField()->getCanonicalDecl(); |
| 3091 | } |
| 3092 | |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame] | 3093 | // Enumerators with the same name match. |
| 3094 | if (isa<EnumConstantDecl>(X)) |
| 3095 | // FIXME: Also check the value is odr-equivalent. |
| 3096 | return true; |
| 3097 | |
Richard Smith | fd8634a | 2013-10-23 02:17:46 +0000 | [diff] [blame] | 3098 | // Using shadow declarations with the same target match. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3099 | if (const auto *USX = dyn_cast<UsingShadowDecl>(X)) { |
| 3100 | const auto *USY = cast<UsingShadowDecl>(Y); |
Richard Smith | fd8634a | 2013-10-23 02:17:46 +0000 | [diff] [blame] | 3101 | return USX->getTargetDecl() == USY->getTargetDecl(); |
| 3102 | } |
| 3103 | |
Richard Smith | 32952e1 | 2014-10-14 02:00:47 +0000 | [diff] [blame] | 3104 | // Using declarations with the same qualifier match. (We already know that |
| 3105 | // the name matches.) |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3106 | if (const auto *UX = dyn_cast<UsingDecl>(X)) { |
| 3107 | const auto *UY = cast<UsingDecl>(Y); |
Richard Smith | 32952e1 | 2014-10-14 02:00:47 +0000 | [diff] [blame] | 3108 | return isSameQualifier(UX->getQualifier(), UY->getQualifier()) && |
| 3109 | UX->hasTypename() == UY->hasTypename() && |
| 3110 | UX->isAccessDeclaration() == UY->isAccessDeclaration(); |
| 3111 | } |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3112 | if (const auto *UX = dyn_cast<UnresolvedUsingValueDecl>(X)) { |
| 3113 | const auto *UY = cast<UnresolvedUsingValueDecl>(Y); |
Richard Smith | 32952e1 | 2014-10-14 02:00:47 +0000 | [diff] [blame] | 3114 | return isSameQualifier(UX->getQualifier(), UY->getQualifier()) && |
| 3115 | UX->isAccessDeclaration() == UY->isAccessDeclaration(); |
| 3116 | } |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3117 | if (const auto *UX = dyn_cast<UnresolvedUsingTypenameDecl>(X)) |
Richard Smith | 32952e1 | 2014-10-14 02:00:47 +0000 | [diff] [blame] | 3118 | return isSameQualifier( |
| 3119 | UX->getQualifier(), |
| 3120 | cast<UnresolvedUsingTypenameDecl>(Y)->getQualifier()); |
| 3121 | |
Richard Smith | f463436 | 2014-09-03 23:11:22 +0000 | [diff] [blame] | 3122 | // Namespace alias definitions with the same target match. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3123 | if (const auto *NAX = dyn_cast<NamespaceAliasDecl>(X)) { |
| 3124 | const auto *NAY = cast<NamespaceAliasDecl>(Y); |
Richard Smith | f463436 | 2014-09-03 23:11:22 +0000 | [diff] [blame] | 3125 | return NAX->getNamespace()->Equals(NAY->getNamespace()); |
| 3126 | } |
| 3127 | |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 3128 | return false; |
| 3129 | } |
| 3130 | |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 3131 | /// Find the context in which we should search for previous declarations when |
| 3132 | /// looking for declarations to merge. |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 3133 | DeclContext *ASTDeclReader::getPrimaryContextForMerging(ASTReader &Reader, |
| 3134 | DeclContext *DC) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3135 | if (auto *ND = dyn_cast<NamespaceDecl>(DC)) |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 3136 | return ND->getOriginalNamespace(); |
| 3137 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3138 | if (auto *RD = dyn_cast<CXXRecordDecl>(DC)) { |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 3139 | // Try to dig out the definition. |
Richard Smith | b648399 | 2016-05-17 22:44:15 +0000 | [diff] [blame] | 3140 | auto *DD = RD->DefinitionData; |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 3141 | if (!DD) |
Richard Smith | b648399 | 2016-05-17 22:44:15 +0000 | [diff] [blame] | 3142 | DD = RD->getCanonicalDecl()->DefinitionData; |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 3143 | |
| 3144 | // If there's no definition yet, then DC's definition is added by an update |
| 3145 | // record, but we've not yet loaded that update record. In this case, we |
| 3146 | // commit to DC being the canonical definition now, and will fix this when |
| 3147 | // we load the update record. |
| 3148 | if (!DD) { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 3149 | DD = new (Reader.getContext()) struct CXXRecordDecl::DefinitionData(RD); |
Erich Keane | f92f31c | 2018-08-01 20:48:16 +0000 | [diff] [blame] | 3150 | RD->setCompleteDefinition(true); |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 3151 | RD->DefinitionData = DD; |
| 3152 | RD->getCanonicalDecl()->DefinitionData = DD; |
| 3153 | |
| 3154 | // Track that we did this horrible thing so that we can fix it later. |
Richard Smith | 2a9e5c5 | 2015-02-03 03:32:14 +0000 | [diff] [blame] | 3155 | Reader.PendingFakeDefinitionData.insert( |
| 3156 | std::make_pair(DD, ASTReader::PendingFakeDefinitionKind::Fake)); |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 3157 | } |
| 3158 | |
| 3159 | return DD->Definition; |
| 3160 | } |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 3161 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3162 | if (auto *ED = dyn_cast<EnumDecl>(DC)) |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 3163 | return ED->getASTContext().getLangOpts().CPlusPlus? ED->getDefinition() |
| 3164 | : nullptr; |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame] | 3165 | |
Richard Smith | 4eca9b9 | 2015-02-04 23:37:59 +0000 | [diff] [blame] | 3166 | // We can see the TU here only if we have no Sema object. In that case, |
| 3167 | // there's no TU scope to look in, so using the DC alone is sufficient. |
| 3168 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) |
| 3169 | return TU; |
| 3170 | |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 3171 | return nullptr; |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 3172 | } |
| 3173 | |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 3174 | ASTDeclReader::FindExistingResult::~FindExistingResult() { |
Richard Smith | f1f4bc2 | 2015-01-22 02:21:23 +0000 | [diff] [blame] | 3175 | // Record that we had a typedef name for linkage whether or not we merge |
| 3176 | // with that declaration. |
| 3177 | if (TypedefNameForLinkage) { |
| 3178 | DeclContext *DC = New->getDeclContext()->getRedeclContext(); |
| 3179 | Reader.ImportedTypedefNamesForLinkage.insert( |
| 3180 | std::make_pair(std::make_pair(DC, TypedefNameForLinkage), New)); |
| 3181 | return; |
| 3182 | } |
| 3183 | |
Douglas Gregor | 9b47f94 | 2012-01-09 17:38:47 +0000 | [diff] [blame] | 3184 | if (!AddResult || Existing) |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 3185 | return; |
Richard Smith | 95d9930 | 2013-07-13 02:00:19 +0000 | [diff] [blame] | 3186 | |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 3187 | DeclarationName Name = New->getDeclName(); |
Richard Smith | 95d9930 | 2013-07-13 02:00:19 +0000 | [diff] [blame] | 3188 | DeclContext *DC = New->getDeclContext()->getRedeclContext(); |
Richard Smith | 2b56057 | 2015-02-07 03:11:11 +0000 | [diff] [blame] | 3189 | if (needsAnonymousDeclarationNumber(New)) { |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3190 | setAnonymousDeclForMerging(Reader, New->getLexicalDeclContext(), |
| 3191 | AnonymousDeclNumber, New); |
Richard Smith | 1037909 | 2016-05-06 23:14:07 +0000 | [diff] [blame] | 3192 | } else if (DC->isTranslationUnit() && |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 3193 | !Reader.getContext().getLangOpts().CPlusPlus) { |
Richard Smith | 1037909 | 2016-05-06 23:14:07 +0000 | [diff] [blame] | 3194 | if (Reader.getIdResolver().tryAddTopLevelDecl(New, Name)) |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 3195 | Reader.PendingFakeLookupResults[Name.getAsIdentifierInfo()] |
| 3196 | .push_back(New); |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 3197 | } else if (DeclContext *MergeDC = getPrimaryContextForMerging(Reader, DC)) { |
Richard Smith | 95d9930 | 2013-07-13 02:00:19 +0000 | [diff] [blame] | 3198 | // Add the declaration to its redeclaration context so later merging |
| 3199 | // lookups will find it. |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 3200 | MergeDC->makeDeclVisibleInContextImpl(New, /*Internal*/true); |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 3201 | } |
| 3202 | } |
| 3203 | |
Richard Smith | 88ebade | 2014-08-23 01:45:27 +0000 | [diff] [blame] | 3204 | /// Find the declaration that should be merged into, given the declaration found |
| 3205 | /// by name lookup. If we're merging an anonymous declaration within a typedef, |
| 3206 | /// we need a matching typedef, and we merge with the type inside it. |
| 3207 | static NamedDecl *getDeclForMerging(NamedDecl *Found, |
| 3208 | bool IsTypedefNameForLinkage) { |
| 3209 | if (!IsTypedefNameForLinkage) |
| 3210 | return Found; |
| 3211 | |
| 3212 | // If we found a typedef declaration that gives a name to some other |
| 3213 | // declaration, then we want that inner declaration. Declarations from |
| 3214 | // AST files are handled via ImportedTypedefNamesForLinkage. |
Richard Smith | a523022 | 2015-03-27 01:37:43 +0000 | [diff] [blame] | 3215 | if (Found->isFromASTFile()) |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 3216 | return nullptr; |
Richard Smith | a523022 | 2015-03-27 01:37:43 +0000 | [diff] [blame] | 3217 | |
| 3218 | if (auto *TND = dyn_cast<TypedefNameDecl>(Found)) |
Richard Smith | 3fb1a85 | 2016-08-30 19:13:18 +0000 | [diff] [blame] | 3219 | return TND->getAnonDeclWithTypedefName(/*AnyRedecl*/true); |
Richard Smith | 88ebade | 2014-08-23 01:45:27 +0000 | [diff] [blame] | 3220 | |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 3221 | return nullptr; |
Richard Smith | 88ebade | 2014-08-23 01:45:27 +0000 | [diff] [blame] | 3222 | } |
| 3223 | |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 3224 | /// Find the declaration to use to populate the anonymous declaration table |
| 3225 | /// for the given lexical DeclContext. We only care about finding local |
| 3226 | /// definitions of the context; we'll merge imported ones as we go. |
| 3227 | DeclContext * |
| 3228 | ASTDeclReader::getPrimaryDCForAnonymousDecl(DeclContext *LexicalDC) { |
| 3229 | // For classes, we track the definition as we merge. |
| 3230 | if (auto *RD = dyn_cast<CXXRecordDecl>(LexicalDC)) { |
| 3231 | auto *DD = RD->getCanonicalDecl()->DefinitionData; |
| 3232 | return DD ? DD->Definition : nullptr; |
| 3233 | } |
| 3234 | |
| 3235 | // For anything else, walk its merged redeclarations looking for a definition. |
| 3236 | // Note that we can't just call getDefinition here because the redeclaration |
| 3237 | // chain isn't wired up. |
| 3238 | for (auto *D : merged_redecls(cast<Decl>(LexicalDC))) { |
| 3239 | if (auto *FD = dyn_cast<FunctionDecl>(D)) |
| 3240 | if (FD->isThisDeclarationADefinition()) |
| 3241 | return FD; |
| 3242 | if (auto *MD = dyn_cast<ObjCMethodDecl>(D)) |
| 3243 | if (MD->isThisDeclarationADefinition()) |
| 3244 | return MD; |
| 3245 | } |
| 3246 | |
| 3247 | // No merged definition yet. |
| 3248 | return nullptr; |
| 3249 | } |
| 3250 | |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3251 | NamedDecl *ASTDeclReader::getAnonymousDeclForMerging(ASTReader &Reader, |
| 3252 | DeclContext *DC, |
| 3253 | unsigned Index) { |
| 3254 | // If the lexical context has been merged, look into the now-canonical |
| 3255 | // definition. |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 3256 | auto *CanonDC = cast<Decl>(DC)->getCanonicalDecl(); |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3257 | |
| 3258 | // If we've seen this before, return the canonical declaration. |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 3259 | auto &Previous = Reader.AnonymousDeclarationsForMerging[CanonDC]; |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3260 | if (Index < Previous.size() && Previous[Index]) |
| 3261 | return Previous[Index]; |
| 3262 | |
| 3263 | // If this is the first time, but we have parsed a declaration of the context, |
| 3264 | // build the anonymous declaration list from the parsed declaration. |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 3265 | auto *PrimaryDC = getPrimaryDCForAnonymousDecl(DC); |
| 3266 | if (PrimaryDC && !cast<Decl>(PrimaryDC)->isFromASTFile()) { |
| 3267 | numberAnonymousDeclsWithin(PrimaryDC, [&](NamedDecl *ND, unsigned Number) { |
Richard Smith | 2b56057 | 2015-02-07 03:11:11 +0000 | [diff] [blame] | 3268 | if (Previous.size() == Number) |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3269 | Previous.push_back(cast<NamedDecl>(ND->getCanonicalDecl())); |
| 3270 | else |
Richard Smith | 2b56057 | 2015-02-07 03:11:11 +0000 | [diff] [blame] | 3271 | Previous[Number] = cast<NamedDecl>(ND->getCanonicalDecl()); |
| 3272 | }); |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3273 | } |
| 3274 | |
| 3275 | return Index < Previous.size() ? Previous[Index] : nullptr; |
| 3276 | } |
| 3277 | |
| 3278 | void ASTDeclReader::setAnonymousDeclForMerging(ASTReader &Reader, |
| 3279 | DeclContext *DC, unsigned Index, |
| 3280 | NamedDecl *D) { |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 3281 | auto *CanonDC = cast<Decl>(DC)->getCanonicalDecl(); |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3282 | |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 3283 | auto &Previous = Reader.AnonymousDeclarationsForMerging[CanonDC]; |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3284 | if (Index >= Previous.size()) |
| 3285 | Previous.resize(Index + 1); |
| 3286 | if (!Previous[Index]) |
| 3287 | Previous[Index] = D; |
| 3288 | } |
| 3289 | |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 3290 | ASTDeclReader::FindExistingResult ASTDeclReader::findExisting(NamedDecl *D) { |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 3291 | DeclarationName Name = TypedefNameForLinkage ? TypedefNameForLinkage |
| 3292 | : D->getDeclName(); |
Richard Smith | 88ebade | 2014-08-23 01:45:27 +0000 | [diff] [blame] | 3293 | |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3294 | if (!Name && !needsAnonymousDeclarationNumber(D)) { |
| 3295 | // Don't bother trying to find unnamed declarations that are in |
| 3296 | // unmergeable contexts. |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 3297 | FindExistingResult Result(Reader, D, /*Existing=*/nullptr, |
| 3298 | AnonymousDeclNumber, TypedefNameForLinkage); |
Douglas Gregor | 2009cee | 2012-01-03 22:46:00 +0000 | [diff] [blame] | 3299 | Result.suppress(); |
| 3300 | return Result; |
| 3301 | } |
Richard Smith | 95d9930 | 2013-07-13 02:00:19 +0000 | [diff] [blame] | 3302 | |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 3303 | DeclContext *DC = D->getDeclContext()->getRedeclContext(); |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 3304 | if (TypedefNameForLinkage) { |
Richard Smith | 88ebade | 2014-08-23 01:45:27 +0000 | [diff] [blame] | 3305 | auto It = Reader.ImportedTypedefNamesForLinkage.find( |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 3306 | std::make_pair(DC, TypedefNameForLinkage)); |
Richard Smith | 88ebade | 2014-08-23 01:45:27 +0000 | [diff] [blame] | 3307 | if (It != Reader.ImportedTypedefNamesForLinkage.end()) |
| 3308 | if (isSameEntity(It->second, D)) |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 3309 | return FindExistingResult(Reader, D, It->second, AnonymousDeclNumber, |
| 3310 | TypedefNameForLinkage); |
Richard Smith | 88ebade | 2014-08-23 01:45:27 +0000 | [diff] [blame] | 3311 | // Go on to check in other places in case an existing typedef name |
| 3312 | // was not imported. |
| 3313 | } |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3314 | |
Richard Smith | 2b56057 | 2015-02-07 03:11:11 +0000 | [diff] [blame] | 3315 | if (needsAnonymousDeclarationNumber(D)) { |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3316 | // This is an anonymous declaration that we may need to merge. Look it up |
| 3317 | // in its context by number. |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3318 | if (auto *Existing = getAnonymousDeclForMerging( |
| 3319 | Reader, D->getLexicalDeclContext(), AnonymousDeclNumber)) |
| 3320 | if (isSameEntity(Existing, D)) |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 3321 | return FindExistingResult(Reader, D, Existing, AnonymousDeclNumber, |
| 3322 | TypedefNameForLinkage); |
Richard Smith | 1037909 | 2016-05-06 23:14:07 +0000 | [diff] [blame] | 3323 | } else if (DC->isTranslationUnit() && |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 3324 | !Reader.getContext().getLangOpts().CPlusPlus) { |
Richard Smith | 1037909 | 2016-05-06 23:14:07 +0000 | [diff] [blame] | 3325 | IdentifierResolver &IdResolver = Reader.getIdResolver(); |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 3326 | |
| 3327 | // Temporarily consider the identifier to be up-to-date. We don't want to |
| 3328 | // cause additional lookups here. |
| 3329 | class UpToDateIdentifierRAII { |
| 3330 | IdentifierInfo *II; |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3331 | bool WasOutToDate = false; |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 3332 | |
| 3333 | public: |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3334 | explicit UpToDateIdentifierRAII(IdentifierInfo *II) : II(II) { |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 3335 | if (II) { |
| 3336 | WasOutToDate = II->isOutOfDate(); |
| 3337 | if (WasOutToDate) |
| 3338 | II->setOutOfDate(false); |
| 3339 | } |
| 3340 | } |
| 3341 | |
| 3342 | ~UpToDateIdentifierRAII() { |
| 3343 | if (WasOutToDate) |
| 3344 | II->setOutOfDate(true); |
| 3345 | } |
| 3346 | } UpToDate(Name.getAsIdentifierInfo()); |
| 3347 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3348 | for (IdentifierResolver::iterator I = IdResolver.begin(Name), |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 3349 | IEnd = IdResolver.end(); |
| 3350 | I != IEnd; ++I) { |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 3351 | if (NamedDecl *Existing = getDeclForMerging(*I, TypedefNameForLinkage)) |
Richard Smith | 87dacc7 | 2014-08-25 23:33:46 +0000 | [diff] [blame] | 3352 | if (isSameEntity(Existing, D)) |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 3353 | return FindExistingResult(Reader, D, Existing, AnonymousDeclNumber, |
| 3354 | TypedefNameForLinkage); |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 3355 | } |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 3356 | } else if (DeclContext *MergeDC = getPrimaryContextForMerging(Reader, DC)) { |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 3357 | DeclContext::lookup_result R = MergeDC->noload_lookup(Name); |
Richard Smith | 95d9930 | 2013-07-13 02:00:19 +0000 | [diff] [blame] | 3358 | for (DeclContext::lookup_iterator I = R.begin(), E = R.end(); I != E; ++I) { |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 3359 | if (NamedDecl *Existing = getDeclForMerging(*I, TypedefNameForLinkage)) |
Richard Smith | 88ebade | 2014-08-23 01:45:27 +0000 | [diff] [blame] | 3360 | if (isSameEntity(Existing, D)) |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 3361 | return FindExistingResult(Reader, D, Existing, AnonymousDeclNumber, |
| 3362 | TypedefNameForLinkage); |
Douglas Gregor | 9b47f94 | 2012-01-09 17:38:47 +0000 | [diff] [blame] | 3363 | } |
Richard Smith | 2b9e3e3 | 2013-10-18 06:05:18 +0000 | [diff] [blame] | 3364 | } else { |
| 3365 | // Not in a mergeable context. |
| 3366 | return FindExistingResult(Reader); |
Douglas Gregor | 9b47f94 | 2012-01-09 17:38:47 +0000 | [diff] [blame] | 3367 | } |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 3368 | |
Richard Smith | 2b9e3e3 | 2013-10-18 06:05:18 +0000 | [diff] [blame] | 3369 | // If this declaration is from a merged context, make a note that we need to |
| 3370 | // check that the canonical definition of that context contains the decl. |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3371 | // |
| 3372 | // FIXME: We should do something similar if we merge two definitions of the |
| 3373 | // same template specialization into the same CXXRecordDecl. |
Richard Smith | 88126a2 | 2014-08-25 02:10:01 +0000 | [diff] [blame] | 3374 | auto MergedDCIt = Reader.MergedDeclContexts.find(D->getLexicalDeclContext()); |
| 3375 | if (MergedDCIt != Reader.MergedDeclContexts.end() && |
| 3376 | MergedDCIt->second == D->getDeclContext()) |
Richard Smith | 2b9e3e3 | 2013-10-18 06:05:18 +0000 | [diff] [blame] | 3377 | Reader.PendingOdrMergeChecks.push_back(D); |
| 3378 | |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3379 | return FindExistingResult(Reader, D, /*Existing=*/nullptr, |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 3380 | AnonymousDeclNumber, TypedefNameForLinkage); |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 3381 | } |
| 3382 | |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 3383 | template<typename DeclT> |
Richard Smith | c3a5325 | 2015-02-28 05:57:02 +0000 | [diff] [blame] | 3384 | Decl *ASTDeclReader::getMostRecentDeclImpl(Redeclarable<DeclT> *D) { |
| 3385 | return D->RedeclLink.getLatestNotUpdated(); |
| 3386 | } |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3387 | |
Richard Smith | c3a5325 | 2015-02-28 05:57:02 +0000 | [diff] [blame] | 3388 | Decl *ASTDeclReader::getMostRecentDeclImpl(...) { |
| 3389 | llvm_unreachable("getMostRecentDecl on non-redeclarable declaration"); |
| 3390 | } |
| 3391 | |
| 3392 | Decl *ASTDeclReader::getMostRecentDecl(Decl *D) { |
| 3393 | assert(D); |
| 3394 | |
| 3395 | switch (D->getKind()) { |
| 3396 | #define ABSTRACT_DECL(TYPE) |
| 3397 | #define DECL(TYPE, BASE) \ |
| 3398 | case Decl::TYPE: \ |
| 3399 | return getMostRecentDeclImpl(cast<TYPE##Decl>(D)); |
| 3400 | #include "clang/AST/DeclNodes.inc" |
| 3401 | } |
| 3402 | llvm_unreachable("unknown decl kind"); |
| 3403 | } |
| 3404 | |
Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 3405 | Decl *ASTReader::getMostRecentExistingDecl(Decl *D) { |
| 3406 | return ASTDeclReader::getMostRecentDecl(D->getCanonicalDecl()); |
| 3407 | } |
| 3408 | |
Richard Smith | c3a5325 | 2015-02-28 05:57:02 +0000 | [diff] [blame] | 3409 | template<typename DeclT> |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 3410 | void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader, |
| 3411 | Redeclarable<DeclT> *D, |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 3412 | Decl *Previous, Decl *Canon) { |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 3413 | D->RedeclLink.setPrevious(cast<DeclT>(Previous)); |
Manuel Klimek | 093b2d4 | 2015-03-25 23:18:30 +0000 | [diff] [blame] | 3414 | D->First = cast<DeclT>(Previous)->First; |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 3415 | } |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 3416 | |
Richard Smith | 24d166c | 2014-07-31 23:52:38 +0000 | [diff] [blame] | 3417 | namespace clang { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3418 | |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 3419 | template<> |
| 3420 | void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader, |
Richard Smith | edbc6e9 | 2016-10-14 21:41:24 +0000 | [diff] [blame] | 3421 | Redeclarable<VarDecl> *D, |
| 3422 | Decl *Previous, Decl *Canon) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3423 | auto *VD = static_cast<VarDecl *>(D); |
| 3424 | auto *PrevVD = cast<VarDecl>(Previous); |
Richard Smith | edbc6e9 | 2016-10-14 21:41:24 +0000 | [diff] [blame] | 3425 | D->RedeclLink.setPrevious(PrevVD); |
| 3426 | D->First = PrevVD->First; |
| 3427 | |
| 3428 | // We should keep at most one definition on the chain. |
| 3429 | // FIXME: Cache the definition once we've found it. Building a chain with |
| 3430 | // N definitions currently takes O(N^2) time here. |
| 3431 | if (VD->isThisDeclarationADefinition() == VarDecl::Definition) { |
| 3432 | for (VarDecl *CurD = PrevVD; CurD; CurD = CurD->getPreviousDecl()) { |
| 3433 | if (CurD->isThisDeclarationADefinition() == VarDecl::Definition) { |
| 3434 | Reader.mergeDefinitionVisibility(CurD, VD); |
| 3435 | VD->demoteThisDefinitionToDeclaration(); |
| 3436 | break; |
| 3437 | } |
| 3438 | } |
| 3439 | } |
| 3440 | } |
| 3441 | |
Richard Smith | a62d198 | 2018-08-03 01:00:01 +0000 | [diff] [blame] | 3442 | static bool isUndeducedReturnType(QualType T) { |
| 3443 | auto *DT = T->getContainedDeducedType(); |
| 3444 | return DT && !DT->isDeduced(); |
| 3445 | } |
| 3446 | |
Richard Smith | edbc6e9 | 2016-10-14 21:41:24 +0000 | [diff] [blame] | 3447 | template<> |
| 3448 | void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader, |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 3449 | Redeclarable<FunctionDecl> *D, |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 3450 | Decl *Previous, Decl *Canon) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3451 | auto *FD = static_cast<FunctionDecl *>(D); |
| 3452 | auto *PrevFD = cast<FunctionDecl>(Previous); |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 3453 | |
| 3454 | FD->RedeclLink.setPrevious(PrevFD); |
Manuel Klimek | 093b2d4 | 2015-03-25 23:18:30 +0000 | [diff] [blame] | 3455 | FD->First = PrevFD->First; |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 3456 | |
| 3457 | // If the previous declaration is an inline function declaration, then this |
| 3458 | // declaration is too. |
Erich Keane | 9c66506 | 2018-08-01 21:02:40 +0000 | [diff] [blame] | 3459 | if (PrevFD->isInlined() != FD->isInlined()) { |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 3460 | // FIXME: [dcl.fct.spec]p4: |
| 3461 | // If a function with external linkage is declared inline in one |
| 3462 | // translation unit, it shall be declared inline in all translation |
| 3463 | // units in which it appears. |
| 3464 | // |
| 3465 | // Be careful of this case: |
| 3466 | // |
| 3467 | // module A: |
| 3468 | // template<typename T> struct X { void f(); }; |
| 3469 | // template<typename T> inline void X<T>::f() {} |
| 3470 | // |
| 3471 | // module B instantiates the declaration of X<int>::f |
| 3472 | // module C instantiates the definition of X<int>::f |
| 3473 | // |
| 3474 | // If module B and C are merged, we do not have a violation of this rule. |
Erich Keane | 9c66506 | 2018-08-01 21:02:40 +0000 | [diff] [blame] | 3475 | FD->setImplicitlyInline(true); |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 3476 | } |
| 3477 | |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 3478 | auto *FPT = FD->getType()->getAs<FunctionProtoType>(); |
| 3479 | auto *PrevFPT = PrevFD->getType()->getAs<FunctionProtoType>(); |
Richard Smith | 8096975 | 2015-03-10 02:00:53 +0000 | [diff] [blame] | 3480 | if (FPT && PrevFPT) { |
Richard Smith | a62d198 | 2018-08-03 01:00:01 +0000 | [diff] [blame] | 3481 | // If we need to propagate an exception specification along the redecl |
| 3482 | // chain, make a note of that so that we can do so later. |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 3483 | bool IsUnresolved = isUnresolvedExceptionSpec(FPT->getExceptionSpecType()); |
| 3484 | bool WasUnresolved = |
| 3485 | isUnresolvedExceptionSpec(PrevFPT->getExceptionSpecType()); |
| 3486 | if (IsUnresolved != WasUnresolved) |
| 3487 | Reader.PendingExceptionSpecUpdates.insert( |
Richard Smith | a62d198 | 2018-08-03 01:00:01 +0000 | [diff] [blame] | 3488 | {Canon, IsUnresolved ? PrevFD : FD}); |
| 3489 | |
| 3490 | // If we need to propagate a deduced return type along the redecl chain, |
| 3491 | // make a note of that so that we can do it later. |
| 3492 | bool IsUndeduced = isUndeducedReturnType(FPT->getReturnType()); |
| 3493 | bool WasUndeduced = isUndeducedReturnType(PrevFPT->getReturnType()); |
| 3494 | if (IsUndeduced != WasUndeduced) |
| 3495 | Reader.PendingDeducedTypeUpdates.insert( |
| 3496 | {cast<FunctionDecl>(Canon), |
| 3497 | (IsUndeduced ? PrevFPT : FPT)->getReturnType()}); |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 3498 | } |
| 3499 | } |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3500 | |
| 3501 | } // namespace clang |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 3502 | |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 3503 | void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader, ...) { |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 3504 | llvm_unreachable("attachPreviousDecl on non-redeclarable declaration"); |
| 3505 | } |
| 3506 | |
Richard Smith | 8346e52 | 2015-06-10 01:47:58 +0000 | [diff] [blame] | 3507 | /// Inherit the default template argument from \p From to \p To. Returns |
| 3508 | /// \c false if there is no default template for \p From. |
| 3509 | template <typename ParmDecl> |
| 3510 | static bool inheritDefaultTemplateArgument(ASTContext &Context, ParmDecl *From, |
| 3511 | Decl *ToD) { |
| 3512 | auto *To = cast<ParmDecl>(ToD); |
| 3513 | if (!From->hasDefaultArgument()) |
| 3514 | return false; |
Richard Smith | e7bd6de | 2015-06-10 20:30:23 +0000 | [diff] [blame] | 3515 | To->setInheritedDefaultArgument(Context, From); |
Richard Smith | 8346e52 | 2015-06-10 01:47:58 +0000 | [diff] [blame] | 3516 | return true; |
| 3517 | } |
| 3518 | |
| 3519 | static void inheritDefaultTemplateArguments(ASTContext &Context, |
| 3520 | TemplateDecl *From, |
| 3521 | TemplateDecl *To) { |
| 3522 | auto *FromTP = From->getTemplateParameters(); |
| 3523 | auto *ToTP = To->getTemplateParameters(); |
| 3524 | assert(FromTP->size() == ToTP->size() && "merged mismatched templates?"); |
| 3525 | |
| 3526 | for (unsigned I = 0, N = FromTP->size(); I != N; ++I) { |
Richard Smith | 559cc69 | 2018-07-31 21:01:53 +0000 | [diff] [blame] | 3527 | NamedDecl *FromParam = FromTP->getParam(I); |
| 3528 | NamedDecl *ToParam = ToTP->getParam(I); |
Richard Smith | 8346e52 | 2015-06-10 01:47:58 +0000 | [diff] [blame] | 3529 | |
Richard Smith | 559cc69 | 2018-07-31 21:01:53 +0000 | [diff] [blame] | 3530 | if (auto *FTTP = dyn_cast<TemplateTypeParmDecl>(FromParam)) |
| 3531 | inheritDefaultTemplateArgument(Context, FTTP, ToParam); |
| 3532 | else if (auto *FNTTP = dyn_cast<NonTypeTemplateParmDecl>(FromParam)) |
| 3533 | inheritDefaultTemplateArgument(Context, FNTTP, ToParam); |
| 3534 | else |
| 3535 | inheritDefaultTemplateArgument( |
| 3536 | Context, cast<TemplateTemplateParmDecl>(FromParam), ToParam); |
Richard Smith | 8346e52 | 2015-06-10 01:47:58 +0000 | [diff] [blame] | 3537 | } |
| 3538 | } |
| 3539 | |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 3540 | void ASTDeclReader::attachPreviousDecl(ASTReader &Reader, Decl *D, |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 3541 | Decl *Previous, Decl *Canon) { |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 3542 | assert(D && Previous); |
| 3543 | |
| 3544 | switch (D->getKind()) { |
| 3545 | #define ABSTRACT_DECL(TYPE) |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 3546 | #define DECL(TYPE, BASE) \ |
| 3547 | case Decl::TYPE: \ |
| 3548 | attachPreviousDeclImpl(Reader, cast<TYPE##Decl>(D), Previous, Canon); \ |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 3549 | break; |
| 3550 | #include "clang/AST/DeclNodes.inc" |
Argyrios Kyrtzidis | 9fdd254 | 2011-02-12 07:50:47 +0000 | [diff] [blame] | 3551 | } |
Richard Smith | 7ecc31b | 2013-08-02 01:09:12 +0000 | [diff] [blame] | 3552 | |
| 3553 | // If the declaration was visible in one module, a redeclaration of it in |
| 3554 | // another module remains visible even if it wouldn't be visible by itself. |
| 3555 | // |
| 3556 | // FIXME: In this case, the declaration should only be visible if a module |
| 3557 | // that makes it visible has been imported. |
Richard Smith | 7ecc31b | 2013-08-02 01:09:12 +0000 | [diff] [blame] | 3558 | D->IdentifierNamespace |= |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 3559 | Previous->IdentifierNamespace & |
Richard Smith | 7ecc31b | 2013-08-02 01:09:12 +0000 | [diff] [blame] | 3560 | (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type); |
Richard Smith | 195d8ef | 2014-05-29 03:15:31 +0000 | [diff] [blame] | 3561 | |
Richard Smith | 8346e52 | 2015-06-10 01:47:58 +0000 | [diff] [blame] | 3562 | // If the declaration declares a template, it may inherit default arguments |
| 3563 | // from the previous declaration. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3564 | if (auto *TD = dyn_cast<TemplateDecl>(D)) |
Richard Smith | 8346e52 | 2015-06-10 01:47:58 +0000 | [diff] [blame] | 3565 | inheritDefaultTemplateArguments(Reader.getContext(), |
| 3566 | cast<TemplateDecl>(Previous), TD); |
Argyrios Kyrtzidis | 9fdd254 | 2011-02-12 07:50:47 +0000 | [diff] [blame] | 3567 | } |
| 3568 | |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 3569 | template<typename DeclT> |
| 3570 | void ASTDeclReader::attachLatestDeclImpl(Redeclarable<DeclT> *D, Decl *Latest) { |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 3571 | D->RedeclLink.setLatest(cast<DeclT>(Latest)); |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 3572 | } |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3573 | |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 3574 | void ASTDeclReader::attachLatestDeclImpl(...) { |
| 3575 | llvm_unreachable("attachLatestDecl on non-redeclarable declaration"); |
| 3576 | } |
| 3577 | |
Douglas Gregor | 05f1035 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 3578 | void ASTDeclReader::attachLatestDecl(Decl *D, Decl *Latest) { |
| 3579 | assert(D && Latest); |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 3580 | |
| 3581 | switch (D->getKind()) { |
| 3582 | #define ABSTRACT_DECL(TYPE) |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 3583 | #define DECL(TYPE, BASE) \ |
| 3584 | case Decl::TYPE: \ |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 3585 | attachLatestDeclImpl(cast<TYPE##Decl>(D), Latest); \ |
| 3586 | break; |
| 3587 | #include "clang/AST/DeclNodes.inc" |
Douglas Gregor | 05f1035 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 3588 | } |
| 3589 | } |
| 3590 | |
Richard Smith | 851072e | 2014-05-19 20:59:20 +0000 | [diff] [blame] | 3591 | template<typename DeclT> |
| 3592 | void ASTDeclReader::markIncompleteDeclChainImpl(Redeclarable<DeclT> *D) { |
| 3593 | D->RedeclLink.markIncomplete(); |
| 3594 | } |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3595 | |
Richard Smith | 851072e | 2014-05-19 20:59:20 +0000 | [diff] [blame] | 3596 | void ASTDeclReader::markIncompleteDeclChainImpl(...) { |
| 3597 | llvm_unreachable("markIncompleteDeclChain on non-redeclarable declaration"); |
| 3598 | } |
| 3599 | |
| 3600 | void ASTReader::markIncompleteDeclChain(Decl *D) { |
| 3601 | switch (D->getKind()) { |
| 3602 | #define ABSTRACT_DECL(TYPE) |
| 3603 | #define DECL(TYPE, BASE) \ |
| 3604 | case Decl::TYPE: \ |
| 3605 | ASTDeclReader::markIncompleteDeclChainImpl(cast<TYPE##Decl>(D)); \ |
| 3606 | break; |
| 3607 | #include "clang/AST/DeclNodes.inc" |
| 3608 | } |
| 3609 | } |
| 3610 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3611 | /// Read the declaration at the given offset from the AST file. |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 3612 | Decl *ASTReader::ReadDeclRecord(DeclID ID) { |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 3613 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; |
Richard Smith | cb34bd3 | 2016-03-27 07:28:06 +0000 | [diff] [blame] | 3614 | SourceLocation DeclLoc; |
| 3615 | RecordLocation Loc = DeclCursorForID(ID, DeclLoc); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3616 | llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3617 | // Keep track of where we are in the stream, then jump back there |
| 3618 | // after reading this declaration. |
Chris Lattner | 1de76db | 2009-04-27 05:58:23 +0000 | [diff] [blame] | 3619 | SavedStreamPosition SavedPosition(DeclsCursor); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3620 | |
Argyrios Kyrtzidis | d0795b2 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3621 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 3622 | |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 3623 | // Note that we are loading a declaration record. |
Argyrios Kyrtzidis | b24355a | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 3624 | Deserializing ADecl(this); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3625 | |
JF Bastien | 0e82895 | 2019-06-26 19:50:12 +0000 | [diff] [blame] | 3626 | auto Fail = [](const char *what, llvm::Error &&Err) { |
| 3627 | llvm::report_fatal_error(Twine("ASTReader::ReadDeclRecord failed ") + what + |
| 3628 | ": " + toString(std::move(Err))); |
| 3629 | }; |
| 3630 | |
| 3631 | if (llvm::Error JumpFailed = DeclsCursor.JumpToBit(Loc.Offset)) |
| 3632 | Fail("jumping", std::move(JumpFailed)); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3633 | ASTRecordReader Record(*this, *Loc.F); |
| 3634 | ASTDeclReader Reader(*this, Record, Loc, ID, DeclLoc); |
JF Bastien | 0e82895 | 2019-06-26 19:50:12 +0000 | [diff] [blame] | 3635 | Expected<unsigned> MaybeCode = DeclsCursor.ReadCode(); |
| 3636 | if (!MaybeCode) |
| 3637 | Fail("reading code", MaybeCode.takeError()); |
| 3638 | unsigned Code = MaybeCode.get(); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3639 | |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 3640 | ASTContext &Context = getContext(); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 3641 | Decl *D = nullptr; |
JF Bastien | 0e82895 | 2019-06-26 19:50:12 +0000 | [diff] [blame] | 3642 | Expected<unsigned> MaybeDeclCode = Record.readRecord(DeclsCursor, Code); |
| 3643 | if (!MaybeDeclCode) |
| 3644 | llvm::report_fatal_error( |
| 3645 | "ASTReader::ReadDeclRecord failed reading decl code: " + |
| 3646 | toString(MaybeDeclCode.takeError())); |
| 3647 | switch ((DeclCode)MaybeDeclCode.get()) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3648 | case DECL_CONTEXT_LEXICAL: |
| 3649 | case DECL_CONTEXT_VISIBLE: |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 3650 | llvm_unreachable("Record cannot be de-serialized with ReadDeclRecord"); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3651 | case DECL_TYPEDEF: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3652 | D = TypedefDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3653 | break; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 3654 | case DECL_TYPEALIAS: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3655 | D = TypeAliasDecl::CreateDeserialized(Context, ID); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 3656 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3657 | case DECL_ENUM: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3658 | D = EnumDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3659 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3660 | case DECL_RECORD: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3661 | D = RecordDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3662 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3663 | case DECL_ENUM_CONSTANT: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3664 | D = EnumConstantDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3665 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3666 | case DECL_FUNCTION: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3667 | D = FunctionDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3668 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3669 | case DECL_LINKAGE_SPEC: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3670 | D = LinkageSpecDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3671 | break; |
Richard Smith | 8df390f | 2016-09-08 23:14:54 +0000 | [diff] [blame] | 3672 | case DECL_EXPORT: |
| 3673 | D = ExportDecl::CreateDeserialized(Context, ID); |
| 3674 | break; |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 3675 | case DECL_LABEL: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3676 | D = LabelDecl::CreateDeserialized(Context, ID); |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 3677 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3678 | case DECL_NAMESPACE: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3679 | D = NamespaceDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3680 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3681 | case DECL_NAMESPACE_ALIAS: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3682 | D = NamespaceAliasDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3683 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3684 | case DECL_USING: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3685 | D = UsingDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3686 | break; |
Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 3687 | case DECL_USING_PACK: |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3688 | D = UsingPackDecl::CreateDeserialized(Context, ID, Record.readInt()); |
Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 3689 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3690 | case DECL_USING_SHADOW: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3691 | D = UsingShadowDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3692 | break; |
Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 3693 | case DECL_CONSTRUCTOR_USING_SHADOW: |
| 3694 | D = ConstructorUsingShadowDecl::CreateDeserialized(Context, ID); |
| 3695 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3696 | case DECL_USING_DIRECTIVE: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3697 | D = UsingDirectiveDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3698 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3699 | case DECL_UNRESOLVED_USING_VALUE: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3700 | D = UnresolvedUsingValueDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3701 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3702 | case DECL_UNRESOLVED_USING_TYPENAME: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3703 | D = UnresolvedUsingTypenameDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3704 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3705 | case DECL_CXX_RECORD: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3706 | D = CXXRecordDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3707 | break; |
Richard Smith | bc49120 | 2017-02-17 20:05:37 +0000 | [diff] [blame] | 3708 | case DECL_CXX_DEDUCTION_GUIDE: |
| 3709 | D = CXXDeductionGuideDecl::CreateDeserialized(Context, ID); |
| 3710 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3711 | case DECL_CXX_METHOD: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3712 | D = CXXMethodDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3713 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3714 | case DECL_CXX_CONSTRUCTOR: |
Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3715 | D = CXXConstructorDecl::CreateDeserialized(Context, ID, Record.readInt()); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3716 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3717 | case DECL_CXX_DESTRUCTOR: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3718 | D = CXXDestructorDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3719 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3720 | case DECL_CXX_CONVERSION: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3721 | D = CXXConversionDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3722 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3723 | case DECL_ACCESS_SPEC: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3724 | D = AccessSpecDecl::CreateDeserialized(Context, ID); |
Abramo Bagnara | d734058 | 2010-06-05 05:09:32 +0000 | [diff] [blame] | 3725 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3726 | case DECL_FRIEND: |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3727 | D = FriendDecl::CreateDeserialized(Context, ID, Record.readInt()); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3728 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3729 | case DECL_FRIEND_TEMPLATE: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3730 | D = FriendTemplateDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3731 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3732 | case DECL_CLASS_TEMPLATE: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3733 | D = ClassTemplateDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3734 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3735 | case DECL_CLASS_TEMPLATE_SPECIALIZATION: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3736 | D = ClassTemplateSpecializationDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3737 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3738 | case DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3739 | D = ClassTemplatePartialSpecializationDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3740 | break; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3741 | case DECL_VAR_TEMPLATE: |
| 3742 | D = VarTemplateDecl::CreateDeserialized(Context, ID); |
| 3743 | break; |
| 3744 | case DECL_VAR_TEMPLATE_SPECIALIZATION: |
| 3745 | D = VarTemplateSpecializationDecl::CreateDeserialized(Context, ID); |
| 3746 | break; |
| 3747 | case DECL_VAR_TEMPLATE_PARTIAL_SPECIALIZATION: |
| 3748 | D = VarTemplatePartialSpecializationDecl::CreateDeserialized(Context, ID); |
| 3749 | break; |
Francois Pichet | 00c7e6c | 2011-08-14 03:52:19 +0000 | [diff] [blame] | 3750 | case DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3751 | D = ClassScopeFunctionSpecializationDecl::CreateDeserialized(Context, ID); |
Francois Pichet | 00c7e6c | 2011-08-14 03:52:19 +0000 | [diff] [blame] | 3752 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3753 | case DECL_FUNCTION_TEMPLATE: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3754 | D = FunctionTemplateDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3755 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3756 | case DECL_TEMPLATE_TYPE_PARM: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3757 | D = TemplateTypeParmDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3758 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3759 | case DECL_NON_TYPE_TEMPLATE_PARM: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3760 | D = NonTypeTemplateParmDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3761 | break; |
Douglas Gregor | 0231d8d | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 3762 | case DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK: |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3763 | D = NonTypeTemplateParmDecl::CreateDeserialized(Context, ID, |
| 3764 | Record.readInt()); |
Douglas Gregor | 0231d8d | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 3765 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3766 | case DECL_TEMPLATE_TEMPLATE_PARM: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3767 | D = TemplateTemplateParmDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3768 | break; |
Richard Smith | 1fde8ec | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 3769 | case DECL_EXPANDED_TEMPLATE_TEMPLATE_PARM_PACK: |
| 3770 | D = TemplateTemplateParmDecl::CreateDeserialized(Context, ID, |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3771 | Record.readInt()); |
Richard Smith | 1fde8ec | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 3772 | break; |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 3773 | case DECL_TYPE_ALIAS_TEMPLATE: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3774 | D = TypeAliasTemplateDecl::CreateDeserialized(Context, ID); |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 3775 | break; |
Saar Raz | d7aae33 | 2019-07-10 21:25:49 +0000 | [diff] [blame] | 3776 | case DECL_CONCEPT: |
| 3777 | D = ConceptDecl::CreateDeserialized(Context, ID); |
| 3778 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3779 | case DECL_STATIC_ASSERT: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3780 | D = StaticAssertDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3781 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3782 | case DECL_OBJC_METHOD: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3783 | D = ObjCMethodDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3784 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3785 | case DECL_OBJC_INTERFACE: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3786 | D = ObjCInterfaceDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3787 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3788 | case DECL_OBJC_IVAR: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3789 | D = ObjCIvarDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3790 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3791 | case DECL_OBJC_PROTOCOL: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3792 | D = ObjCProtocolDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3793 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3794 | case DECL_OBJC_AT_DEFS_FIELD: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3795 | D = ObjCAtDefsFieldDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3796 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3797 | case DECL_OBJC_CATEGORY: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3798 | D = ObjCCategoryDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3799 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3800 | case DECL_OBJC_CATEGORY_IMPL: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3801 | D = ObjCCategoryImplDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3802 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3803 | case DECL_OBJC_IMPLEMENTATION: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3804 | D = ObjCImplementationDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3805 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3806 | case DECL_OBJC_COMPATIBLE_ALIAS: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3807 | D = ObjCCompatibleAliasDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3808 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3809 | case DECL_OBJC_PROPERTY: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3810 | D = ObjCPropertyDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3811 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3812 | case DECL_OBJC_PROPERTY_IMPL: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3813 | D = ObjCPropertyImplDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3814 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3815 | case DECL_FIELD: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3816 | D = FieldDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3817 | break; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3818 | case DECL_INDIRECTFIELD: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3819 | D = IndirectFieldDecl::CreateDeserialized(Context, ID); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3820 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3821 | case DECL_VAR: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3822 | D = VarDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3823 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3824 | case DECL_IMPLICIT_PARAM: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3825 | D = ImplicitParamDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3826 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3827 | case DECL_PARM_VAR: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3828 | D = ParmVarDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3829 | break; |
Richard Smith | 7b76d81 | 2016-08-12 02:21:25 +0000 | [diff] [blame] | 3830 | case DECL_DECOMPOSITION: |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3831 | D = DecompositionDecl::CreateDeserialized(Context, ID, Record.readInt()); |
Richard Smith | 7b76d81 | 2016-08-12 02:21:25 +0000 | [diff] [blame] | 3832 | break; |
| 3833 | case DECL_BINDING: |
| 3834 | D = BindingDecl::CreateDeserialized(Context, ID); |
| 3835 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3836 | case DECL_FILE_SCOPE_ASM: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3837 | D = FileScopeAsmDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3838 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3839 | case DECL_BLOCK: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3840 | D = BlockDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3841 | break; |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 3842 | case DECL_MS_PROPERTY: |
| 3843 | D = MSPropertyDecl::CreateDeserialized(Context, ID); |
| 3844 | break; |
Tareq A. Siraj | 6dfa25a | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 3845 | case DECL_CAPTURED: |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3846 | D = CapturedDecl::CreateDeserialized(Context, ID, Record.readInt()); |
Tareq A. Siraj | 6dfa25a | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 3847 | break; |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3848 | case DECL_CXX_BASE_SPECIFIERS: |
| 3849 | Error("attempt to read a C++ base-specifier record as a declaration"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 3850 | return nullptr; |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 3851 | case DECL_CXX_CTOR_INITIALIZERS: |
| 3852 | Error("attempt to read a C++ ctor initializer record as a declaration"); |
| 3853 | return nullptr; |
Douglas Gregor | ba34552 | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 3854 | case DECL_IMPORT: |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3855 | // Note: last entry of the ImportDecl record is the number of stored source |
Douglas Gregor | ba34552 | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 3856 | // locations. |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3857 | D = ImportDecl::CreateDeserialized(Context, ID, Record.back()); |
Douglas Gregor | ba34552 | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 3858 | break; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 3859 | case DECL_OMP_THREADPRIVATE: |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3860 | D = OMPThreadPrivateDecl::CreateDeserialized(Context, ID, Record.readInt()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 3861 | break; |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 3862 | case DECL_OMP_ALLOCATE: { |
| 3863 | unsigned NumVars = Record.readInt(); |
| 3864 | unsigned NumClauses = Record.readInt(); |
| 3865 | D = OMPAllocateDecl::CreateDeserialized(Context, ID, NumVars, NumClauses); |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 3866 | break; |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 3867 | } |
Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 3868 | case DECL_OMP_REQUIRES: |
| 3869 | D = OMPRequiresDecl::CreateDeserialized(Context, ID, Record.readInt()); |
| 3870 | break; |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 3871 | case DECL_OMP_DECLARE_REDUCTION: |
| 3872 | D = OMPDeclareReductionDecl::CreateDeserialized(Context, ID); |
| 3873 | break; |
Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 3874 | case DECL_OMP_DECLARE_MAPPER: |
| 3875 | D = OMPDeclareMapperDecl::CreateDeserialized(Context, ID, Record.readInt()); |
| 3876 | break; |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 3877 | case DECL_OMP_CAPTUREDEXPR: |
| 3878 | D = OMPCapturedExprDecl::CreateDeserialized(Context, ID); |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 3879 | break; |
Nico Weber | 6622029 | 2016-03-02 17:28:48 +0000 | [diff] [blame] | 3880 | case DECL_PRAGMA_COMMENT: |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3881 | D = PragmaCommentDecl::CreateDeserialized(Context, ID, Record.readInt()); |
Nico Weber | 6622029 | 2016-03-02 17:28:48 +0000 | [diff] [blame] | 3882 | break; |
Nico Weber | cbbaeb1 | 2016-03-02 19:28:54 +0000 | [diff] [blame] | 3883 | case DECL_PRAGMA_DETECT_MISMATCH: |
| 3884 | D = PragmaDetectMismatchDecl::CreateDeserialized(Context, ID, |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3885 | Record.readInt()); |
Nico Weber | cbbaeb1 | 2016-03-02 19:28:54 +0000 | [diff] [blame] | 3886 | break; |
Michael Han | 8432435 | 2013-02-22 17:15:32 +0000 | [diff] [blame] | 3887 | case DECL_EMPTY: |
| 3888 | D = EmptyDecl::CreateDeserialized(Context, ID); |
| 3889 | break; |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3890 | case DECL_OBJC_TYPE_PARAM: |
| 3891 | D = ObjCTypeParamDecl::CreateDeserialized(Context, ID); |
| 3892 | break; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3893 | } |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3894 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 3895 | assert(D && "Unknown declaration reading AST file"); |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 3896 | LoadedDecl(Index, D); |
Argyrios Kyrtzidis | 6c07547 | 2012-02-09 06:02:44 +0000 | [diff] [blame] | 3897 | // Set the DeclContext before doing any deserialization, to make sure internal |
| 3898 | // calls to Decl::getASTContext() by Decl's methods will find the |
| 3899 | // TranslationUnitDecl without crashing. |
| 3900 | D->setDeclContext(Context.getTranslationUnitDecl()); |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 3901 | Reader.Visit(D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3902 | |
| 3903 | // If this declaration is also a declaration context, get the |
| 3904 | // offsets for its tables of lexical and visible declarations. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3905 | if (auto *DC = dyn_cast<DeclContext>(D)) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3906 | std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC); |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 3907 | if (Offsets.first && |
| 3908 | ReadLexicalDeclContextStorage(*Loc.F, DeclsCursor, Offsets.first, DC)) |
| 3909 | return nullptr; |
| 3910 | if (Offsets.second && |
| 3911 | ReadVisibleDeclContextStorage(*Loc.F, DeclsCursor, Offsets.second, ID)) |
| 3912 | return nullptr; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3913 | } |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3914 | assert(Record.getIdx() == Record.size()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3915 | |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 3916 | // Load any relevant update records. |
Vassil Vassilev | 74c3e8c | 2017-05-19 16:46:06 +0000 | [diff] [blame] | 3917 | PendingUpdateRecords.push_back( |
| 3918 | PendingUpdateRecord(ID, D, /*JustLoaded=*/true)); |
Argyrios Kyrtzidis | 7d268c3 | 2011-11-14 07:07:59 +0000 | [diff] [blame] | 3919 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3920 | // Load the categories after recursive loading is finished. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3921 | if (auto *Class = dyn_cast<ObjCInterfaceDecl>(D)) |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 3922 | // If we already have a definition when deserializing the ObjCInterfaceDecl, |
| 3923 | // we put the Decl in PendingDefinitions so we can pull the categories here. |
| 3924 | if (Class->isThisDeclarationADefinition() || |
| 3925 | PendingDefinitions.count(Class)) |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3926 | loadObjCCategories(ID, Class); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3927 | |
Richard Smith | 13fb860 | 2016-07-15 21:33:46 +0000 | [diff] [blame] | 3928 | // If we have deserialized a declaration that has a definition the |
| 3929 | // AST consumer might need to know about, queue it. |
| 3930 | // We don't pass it to the consumer immediately because we may be in recursive |
| 3931 | // loading, and some declarations may still be initializing. |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 3932 | PotentiallyInterestingDecls.push_back( |
| 3933 | InterestingDecl(D, Reader.hasPendingBody())); |
Richard Smith | 13fb860 | 2016-07-15 21:33:46 +0000 | [diff] [blame] | 3934 | |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 3935 | return D; |
| 3936 | } |
| 3937 | |
Vassil Vassilev | 46afbbb | 2017-04-12 21:56:05 +0000 | [diff] [blame] | 3938 | void ASTReader::PassInterestingDeclsToConsumer() { |
| 3939 | assert(Consumer); |
| 3940 | |
| 3941 | if (PassingDeclsToConsumer) |
| 3942 | return; |
| 3943 | |
| 3944 | // Guard variable to avoid recursively redoing the process of passing |
| 3945 | // decls to consumer. |
| 3946 | SaveAndRestore<bool> GuardPassingDeclsToConsumer(PassingDeclsToConsumer, |
| 3947 | true); |
| 3948 | |
| 3949 | // Ensure that we've loaded all potentially-interesting declarations |
| 3950 | // that need to be eagerly loaded. |
| 3951 | for (auto ID : EagerlyDeserializedDecls) |
| 3952 | GetDecl(ID); |
| 3953 | EagerlyDeserializedDecls.clear(); |
| 3954 | |
| 3955 | while (!PotentiallyInterestingDecls.empty()) { |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 3956 | InterestingDecl D = PotentiallyInterestingDecls.front(); |
Vassil Vassilev | 46afbbb | 2017-04-12 21:56:05 +0000 | [diff] [blame] | 3957 | PotentiallyInterestingDecls.pop_front(); |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 3958 | if (isConsumerInterestedIn(getContext(), D.getDecl(), D.hasPendingBody())) |
| 3959 | PassInterestingDeclToConsumer(D.getDecl()); |
Vassil Vassilev | 46afbbb | 2017-04-12 21:56:05 +0000 | [diff] [blame] | 3960 | } |
| 3961 | } |
| 3962 | |
Vassil Vassilev | 74c3e8c | 2017-05-19 16:46:06 +0000 | [diff] [blame] | 3963 | void ASTReader::loadDeclUpdateRecords(PendingUpdateRecord &Record) { |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3964 | // The declaration may have been modified by files later in the chain. |
| 3965 | // If this is the case, read the record containing the updates from each file |
| 3966 | // and pass it to ASTDeclReader to make the modifications. |
Vassil Vassilev | 74c3e8c | 2017-05-19 16:46:06 +0000 | [diff] [blame] | 3967 | serialization::GlobalDeclID ID = Record.ID; |
| 3968 | Decl *D = Record.D; |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 3969 | ProcessingUpdatesRAIIObj ProcessingUpdates(*this); |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3970 | DeclUpdateOffsetsMap::iterator UpdI = DeclUpdateOffsets.find(ID); |
Vassil Vassilev | 7d26462 | 2017-06-30 22:40:17 +0000 | [diff] [blame] | 3971 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3972 | SmallVector<serialization::DeclID, 8> PendingLazySpecializationIDs; |
Vassil Vassilev | 7d26462 | 2017-06-30 22:40:17 +0000 | [diff] [blame] | 3973 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3974 | if (UpdI != DeclUpdateOffsets.end()) { |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 3975 | auto UpdateOffsets = std::move(UpdI->second); |
| 3976 | DeclUpdateOffsets.erase(UpdI); |
| 3977 | |
Vassil Vassilev | 74c3e8c | 2017-05-19 16:46:06 +0000 | [diff] [blame] | 3978 | // Check if this decl was interesting to the consumer. If we just loaded |
| 3979 | // the declaration, then we know it was interesting and we skip the call |
| 3980 | // to isConsumerInterestedIn because it is unsafe to call in the |
| 3981 | // current ASTReader state. |
| 3982 | bool WasInteresting = |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 3983 | Record.JustLoaded || isConsumerInterestedIn(getContext(), D, false); |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 3984 | for (auto &FileAndOffset : UpdateOffsets) { |
| 3985 | ModuleFile *F = FileAndOffset.first; |
| 3986 | uint64_t Offset = FileAndOffset.second; |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3987 | llvm::BitstreamCursor &Cursor = F->DeclsCursor; |
| 3988 | SavedStreamPosition SavedPosition(Cursor); |
JF Bastien | 0e82895 | 2019-06-26 19:50:12 +0000 | [diff] [blame] | 3989 | if (llvm::Error JumpFailed = Cursor.JumpToBit(Offset)) |
| 3990 | // FIXME don't do a fatal error. |
| 3991 | llvm::report_fatal_error( |
| 3992 | "ASTReader::loadDeclUpdateRecords failed jumping: " + |
| 3993 | toString(std::move(JumpFailed))); |
| 3994 | Expected<unsigned> MaybeCode = Cursor.ReadCode(); |
| 3995 | if (!MaybeCode) |
| 3996 | llvm::report_fatal_error( |
| 3997 | "ASTReader::loadDeclUpdateRecords failed reading code: " + |
| 3998 | toString(MaybeCode.takeError())); |
| 3999 | unsigned Code = MaybeCode.get(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 4000 | ASTRecordReader Record(*this, *F); |
JF Bastien | 0e82895 | 2019-06-26 19:50:12 +0000 | [diff] [blame] | 4001 | if (Expected<unsigned> MaybeRecCode = Record.readRecord(Cursor, Code)) |
| 4002 | assert(MaybeRecCode.get() == DECL_UPDATES && |
| 4003 | "Expected DECL_UPDATES record!"); |
| 4004 | else |
| 4005 | llvm::report_fatal_error( |
| 4006 | "ASTReader::loadDeclUpdateRecords failed reading rec code: " + |
| 4007 | toString(MaybeCode.takeError())); |
Richard Smith | 04d05b5 | 2014-03-23 00:27:18 +0000 | [diff] [blame] | 4008 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 4009 | ASTDeclReader Reader(*this, Record, RecordLocation(F, Offset), ID, |
| 4010 | SourceLocation()); |
Vassil Vassilev | 7d26462 | 2017-06-30 22:40:17 +0000 | [diff] [blame] | 4011 | Reader.UpdateDecl(D, PendingLazySpecializationIDs); |
Richard Smith | 04d05b5 | 2014-03-23 00:27:18 +0000 | [diff] [blame] | 4012 | |
| 4013 | // We might have made this declaration interesting. If so, remember that |
| 4014 | // we need to hand it off to the consumer. |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 4015 | if (!WasInteresting && |
| 4016 | isConsumerInterestedIn(getContext(), D, Reader.hasPendingBody())) { |
| 4017 | PotentiallyInterestingDecls.push_back( |
| 4018 | InterestingDecl(D, Reader.hasPendingBody())); |
Richard Smith | 04d05b5 | 2014-03-23 00:27:18 +0000 | [diff] [blame] | 4019 | WasInteresting = true; |
| 4020 | } |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4021 | } |
| 4022 | } |
Vassil Vassilev | 7d26462 | 2017-06-30 22:40:17 +0000 | [diff] [blame] | 4023 | // Add the lazy specializations to the template. |
| 4024 | assert((PendingLazySpecializationIDs.empty() || isa<ClassTemplateDecl>(D) || |
| 4025 | isa<FunctionTemplateDecl>(D) || isa<VarTemplateDecl>(D)) && |
| 4026 | "Must not have pending specializations"); |
| 4027 | if (auto *CTD = dyn_cast<ClassTemplateDecl>(D)) |
| 4028 | ASTDeclReader::AddLazySpecializations(CTD, PendingLazySpecializationIDs); |
| 4029 | else if (auto *FTD = dyn_cast<FunctionTemplateDecl>(D)) |
| 4030 | ASTDeclReader::AddLazySpecializations(FTD, PendingLazySpecializationIDs); |
| 4031 | else if (auto *VTD = dyn_cast<VarTemplateDecl>(D)) |
| 4032 | ASTDeclReader::AddLazySpecializations(VTD, PendingLazySpecializationIDs); |
| 4033 | PendingLazySpecializationIDs.clear(); |
Richard Smith | 1e8e91b | 2016-04-08 20:53:26 +0000 | [diff] [blame] | 4034 | |
| 4035 | // Load the pending visible updates for this decl context, if it has any. |
| 4036 | auto I = PendingVisibleUpdates.find(ID); |
| 4037 | if (I != PendingVisibleUpdates.end()) { |
| 4038 | auto VisibleUpdates = std::move(I->second); |
| 4039 | PendingVisibleUpdates.erase(I); |
| 4040 | |
| 4041 | auto *DC = cast<DeclContext>(D)->getPrimaryContext(); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4042 | for (const auto &Update : VisibleUpdates) |
Richard Smith | 1e8e91b | 2016-04-08 20:53:26 +0000 | [diff] [blame] | 4043 | Lookups[DC].Table.add( |
| 4044 | Update.Mod, Update.Data, |
| 4045 | reader::ASTDeclContextNameLookupTrait(*this, *Update.Mod)); |
| 4046 | DC->setHasExternalVisibleStorage(true); |
| 4047 | } |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 4048 | } |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4049 | |
Richard Smith | d61d4ac | 2015-08-22 20:13:39 +0000 | [diff] [blame] | 4050 | void ASTReader::loadPendingDeclChain(Decl *FirstLocal, uint64_t LocalOffset) { |
| 4051 | // Attach FirstLocal to the end of the decl chain. |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 4052 | Decl *CanonDecl = FirstLocal->getCanonicalDecl(); |
Richard Smith | d61d4ac | 2015-08-22 20:13:39 +0000 | [diff] [blame] | 4053 | if (FirstLocal != CanonDecl) { |
| 4054 | Decl *PrevMostRecent = ASTDeclReader::getMostRecentDecl(CanonDecl); |
| 4055 | ASTDeclReader::attachPreviousDecl( |
| 4056 | *this, FirstLocal, PrevMostRecent ? PrevMostRecent : CanonDecl, |
| 4057 | CanonDecl); |
| 4058 | } |
| 4059 | |
| 4060 | if (!LocalOffset) { |
| 4061 | ASTDeclReader::attachLatestDecl(CanonDecl, FirstLocal); |
| 4062 | return; |
| 4063 | } |
| 4064 | |
| 4065 | // Load the list of other redeclarations from this module file. |
| 4066 | ModuleFile *M = getOwningModuleFile(FirstLocal); |
| 4067 | assert(M && "imported decl from no module file"); |
| 4068 | |
| 4069 | llvm::BitstreamCursor &Cursor = M->DeclsCursor; |
| 4070 | SavedStreamPosition SavedPosition(Cursor); |
JF Bastien | 0e82895 | 2019-06-26 19:50:12 +0000 | [diff] [blame] | 4071 | if (llvm::Error JumpFailed = Cursor.JumpToBit(LocalOffset)) |
| 4072 | llvm::report_fatal_error( |
| 4073 | "ASTReader::loadPendingDeclChain failed jumping: " + |
| 4074 | toString(std::move(JumpFailed))); |
Richard Smith | d61d4ac | 2015-08-22 20:13:39 +0000 | [diff] [blame] | 4075 | |
| 4076 | RecordData Record; |
JF Bastien | 0e82895 | 2019-06-26 19:50:12 +0000 | [diff] [blame] | 4077 | Expected<unsigned> MaybeCode = Cursor.ReadCode(); |
| 4078 | if (!MaybeCode) |
| 4079 | llvm::report_fatal_error( |
| 4080 | "ASTReader::loadPendingDeclChain failed reading code: " + |
| 4081 | toString(MaybeCode.takeError())); |
| 4082 | unsigned Code = MaybeCode.get(); |
| 4083 | if (Expected<unsigned> MaybeRecCode = Cursor.readRecord(Code, Record)) |
| 4084 | assert(MaybeRecCode.get() == LOCAL_REDECLARATIONS && |
| 4085 | "expected LOCAL_REDECLARATIONS record!"); |
| 4086 | else |
| 4087 | llvm::report_fatal_error( |
| 4088 | "ASTReader::loadPendingDeclChain failed reading rec code: " + |
| 4089 | toString(MaybeCode.takeError())); |
Richard Smith | d61d4ac | 2015-08-22 20:13:39 +0000 | [diff] [blame] | 4090 | |
| 4091 | // FIXME: We have several different dispatches on decl kind here; maybe |
| 4092 | // we should instead generate one loop per kind and dispatch up-front? |
| 4093 | Decl *MostRecent = FirstLocal; |
| 4094 | for (unsigned I = 0, N = Record.size(); I != N; ++I) { |
| 4095 | auto *D = GetLocalDecl(*M, Record[N - I - 1]); |
Richard Smith | e2f8ce9 | 2015-07-15 00:02:40 +0000 | [diff] [blame] | 4096 | ASTDeclReader::attachPreviousDecl(*this, D, MostRecent, CanonDecl); |
| 4097 | MostRecent = D; |
Douglas Gregor | 05f1035 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 4098 | } |
Richard Smith | c3a5325 | 2015-02-28 05:57:02 +0000 | [diff] [blame] | 4099 | ASTDeclReader::attachLatestDecl(CanonDecl, MostRecent); |
Douglas Gregor | 05f1035 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 4100 | } |
| 4101 | |
| 4102 | namespace { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4103 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4104 | /// Given an ObjC interface, goes through the modules and links to the |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4105 | /// interface all the categories for it. |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4106 | class ObjCCategoriesVisitor { |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4107 | ASTReader &Reader; |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4108 | ObjCInterfaceDecl *Interface; |
Craig Topper | 4dd9b43 | 2014-08-17 23:49:53 +0000 | [diff] [blame] | 4109 | llvm::SmallPtrSetImpl<ObjCCategoryDecl *> &Deserialized; |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4110 | ObjCCategoryDecl *Tail = nullptr; |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4111 | llvm::DenseMap<DeclarationName, ObjCCategoryDecl *> NameCategoryMap; |
Alexander Shaposhnikov | 96cbe7b | 2016-09-24 02:07:19 +0000 | [diff] [blame] | 4112 | serialization::GlobalDeclID InterfaceID; |
| 4113 | unsigned PreviousGeneration; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4114 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4115 | void add(ObjCCategoryDecl *Cat) { |
| 4116 | // Only process each category once. |
Benjamin Kramer | fc6eb7d | 2012-08-22 15:37:55 +0000 | [diff] [blame] | 4117 | if (!Deserialized.erase(Cat)) |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4118 | return; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4119 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4120 | // Check for duplicate categories. |
| 4121 | if (Cat->getDeclName()) { |
| 4122 | ObjCCategoryDecl *&Existing = NameCategoryMap[Cat->getDeclName()]; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4123 | if (Existing && |
| 4124 | Reader.getOwningModuleFile(Existing) |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4125 | != Reader.getOwningModuleFile(Cat)) { |
| 4126 | // FIXME: We should not warn for duplicates in diamond: |
| 4127 | // |
| 4128 | // MT // |
| 4129 | // / \ // |
| 4130 | // ML MR // |
| 4131 | // \ / // |
| 4132 | // MB // |
| 4133 | // |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4134 | // If there are duplicates in ML/MR, there will be warning when |
| 4135 | // creating MB *and* when importing MB. We should not warn when |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4136 | // importing. |
| 4137 | Reader.Diag(Cat->getLocation(), diag::warn_dup_category_def) |
| 4138 | << Interface->getDeclName() << Cat->getDeclName(); |
| 4139 | Reader.Diag(Existing->getLocation(), diag::note_previous_definition); |
| 4140 | } else if (!Existing) { |
| 4141 | // Record this category. |
| 4142 | Existing = Cat; |
| 4143 | } |
| 4144 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4145 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4146 | // Add this category to the end of the chain. |
| 4147 | if (Tail) |
| 4148 | ASTDeclReader::setNextObjCCategory(Tail, Cat); |
| 4149 | else |
Douglas Gregor | 048fbfa | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 4150 | Interface->setCategoryListRaw(Cat); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4151 | Tail = Cat; |
| 4152 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4153 | |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4154 | public: |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4155 | ObjCCategoriesVisitor(ASTReader &Reader, |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4156 | ObjCInterfaceDecl *Interface, |
Alexander Shaposhnikov | 96cbe7b | 2016-09-24 02:07:19 +0000 | [diff] [blame] | 4157 | llvm::SmallPtrSetImpl<ObjCCategoryDecl *> &Deserialized, |
| 4158 | serialization::GlobalDeclID InterfaceID, |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4159 | unsigned PreviousGeneration) |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4160 | : Reader(Reader), Interface(Interface), Deserialized(Deserialized), |
| 4161 | InterfaceID(InterfaceID), PreviousGeneration(PreviousGeneration) { |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4162 | // Populate the name -> category map with the set of known categories. |
Aaron Ballman | 15063e1 | 2014-03-13 21:35:02 +0000 | [diff] [blame] | 4163 | for (auto *Cat : Interface->known_categories()) { |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4164 | if (Cat->getDeclName()) |
Aaron Ballman | 15063e1 | 2014-03-13 21:35:02 +0000 | [diff] [blame] | 4165 | NameCategoryMap[Cat->getDeclName()] = Cat; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4166 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4167 | // Keep track of the tail of the category list. |
Aaron Ballman | 15063e1 | 2014-03-13 21:35:02 +0000 | [diff] [blame] | 4168 | Tail = Cat; |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4169 | } |
| 4170 | } |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4171 | |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 4172 | bool operator()(ModuleFile &M) { |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4173 | // If we've loaded all of the category information we care about from |
| 4174 | // this module file, we're done. |
| 4175 | if (M.Generation <= PreviousGeneration) |
| 4176 | return true; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4177 | |
| 4178 | // Map global ID of the definition down to the local ID used in this |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4179 | // module file. If there is no such mapping, we'll find nothing here |
| 4180 | // (or in any module it imports). |
| 4181 | DeclID LocalID = Reader.mapGlobalIDToModuleFileGlobalID(M, InterfaceID); |
| 4182 | if (!LocalID) |
| 4183 | return true; |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4184 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4185 | // Perform a binary search to find the local redeclarations for this |
| 4186 | // declaration (if any). |
Benjamin Kramer | a6f3950 | 2014-03-15 14:21:58 +0000 | [diff] [blame] | 4187 | const ObjCCategoriesInfo Compare = { LocalID, 0 }; |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4188 | const ObjCCategoriesInfo *Result |
| 4189 | = std::lower_bound(M.ObjCCategoriesMap, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4190 | M.ObjCCategoriesMap + M.LocalNumObjCCategoriesInMap, |
Benjamin Kramer | a6f3950 | 2014-03-15 14:21:58 +0000 | [diff] [blame] | 4191 | Compare); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4192 | if (Result == M.ObjCCategoriesMap + M.LocalNumObjCCategoriesInMap || |
| 4193 | Result->DefinitionID != LocalID) { |
| 4194 | // We didn't find anything. If the class definition is in this module |
| 4195 | // file, then the module files it depends on cannot have any categories, |
| 4196 | // so suppress further lookup. |
| 4197 | return Reader.isDeclIDFromModule(InterfaceID, M); |
| 4198 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4199 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4200 | // We found something. Dig out all of the categories. |
| 4201 | unsigned Offset = Result->Offset; |
| 4202 | unsigned N = M.ObjCCategories[Offset]; |
| 4203 | M.ObjCCategories[Offset++] = 0; // Don't try to deserialize again |
| 4204 | for (unsigned I = 0; I != N; ++I) |
| 4205 | add(cast_or_null<ObjCCategoryDecl>( |
| 4206 | Reader.GetLocalDecl(M, M.ObjCCategories[Offset++]))); |
| 4207 | return true; |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4208 | } |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4209 | }; |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4210 | |
| 4211 | } // namespace |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4212 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4213 | void ASTReader::loadObjCCategories(serialization::GlobalDeclID ID, |
| 4214 | ObjCInterfaceDecl *D, |
| 4215 | unsigned PreviousGeneration) { |
Alexander Shaposhnikov | 96cbe7b | 2016-09-24 02:07:19 +0000 | [diff] [blame] | 4216 | ObjCCategoriesVisitor Visitor(*this, D, CategoriesDeserialized, ID, |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4217 | PreviousGeneration); |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 4218 | ModuleMgr.visit(Visitor); |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4219 | } |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4220 | |
Richard Smith | d6db68c | 2014-08-07 20:58:41 +0000 | [diff] [blame] | 4221 | template<typename DeclT, typename Fn> |
| 4222 | static void forAllLaterRedecls(DeclT *D, Fn F) { |
| 4223 | F(D); |
| 4224 | |
| 4225 | // Check whether we've already merged D into its redeclaration chain. |
| 4226 | // MostRecent may or may not be nullptr if D has not been merged. If |
| 4227 | // not, walk the merged redecl chain and see if it's there. |
| 4228 | auto *MostRecent = D->getMostRecentDecl(); |
| 4229 | bool Found = false; |
| 4230 | for (auto *Redecl = MostRecent; Redecl && !Found; |
| 4231 | Redecl = Redecl->getPreviousDecl()) |
| 4232 | Found = (Redecl == D); |
| 4233 | |
| 4234 | // If this declaration is merged, apply the functor to all later decls. |
| 4235 | if (Found) { |
| 4236 | for (auto *Redecl = MostRecent; Redecl != D; |
| 4237 | Redecl = Redecl->getPreviousDecl()) |
| 4238 | F(Redecl); |
| 4239 | } |
| 4240 | } |
| 4241 | |
Vassil Vassilev | 7d26462 | 2017-06-30 22:40:17 +0000 | [diff] [blame] | 4242 | void ASTDeclReader::UpdateDecl(Decl *D, |
| 4243 | llvm::SmallVectorImpl<serialization::DeclID> &PendingLazySpecializationIDs) { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 4244 | while (Record.getIdx() < Record.size()) { |
| 4245 | switch ((DeclUpdateKind)Record.readInt()) { |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4246 | case UPD_CXX_ADDED_IMPLICIT_MEMBER: { |
Richard Smith | 1b65dbc | 2015-01-22 03:50:31 +0000 | [diff] [blame] | 4247 | auto *RD = cast<CXXRecordDecl>(D); |
Richard Smith | d6db68c | 2014-08-07 20:58:41 +0000 | [diff] [blame] | 4248 | // FIXME: If we also have an update record for instantiating the |
| 4249 | // definition of D, we need that to happen before we get here. |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 4250 | Decl *MD = Record.readDecl(); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4251 | assert(MD && "couldn't read decl from update record"); |
Richard Smith | 46bb581 | 2014-08-01 01:56:39 +0000 | [diff] [blame] | 4252 | // FIXME: We should call addHiddenDecl instead, to add the member |
| 4253 | // to its DeclContext. |
Richard Smith | 1b65dbc | 2015-01-22 03:50:31 +0000 | [diff] [blame] | 4254 | RD->addedMember(MD); |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 4255 | break; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4256 | } |
Argyrios Kyrtzidis | 402dbbb | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 4257 | |
| 4258 | case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION: |
Vassil Vassilev | 7d26462 | 2017-06-30 22:40:17 +0000 | [diff] [blame] | 4259 | // It will be added to the template's lazy specialization set. |
| 4260 | PendingLazySpecializationIDs.push_back(ReadDeclID()); |
Sebastian Redl | fa1f370 | 2011-04-24 16:28:13 +0000 | [diff] [blame] | 4261 | break; |
| 4262 | |
| 4263 | case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4264 | auto *Anon = ReadDeclAs<NamespaceDecl>(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4265 | |
Douglas Gregor | 540fd81 | 2012-01-09 18:07:24 +0000 | [diff] [blame] | 4266 | // Each module has its own anonymous namespace, which is disjoint from |
| 4267 | // any other module's anonymous namespaces, so don't attach the anonymous |
| 4268 | // namespace at all. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4269 | if (!Record.isModule()) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4270 | if (auto *TU = dyn_cast<TranslationUnitDecl>(D)) |
Douglas Gregor | 540fd81 | 2012-01-09 18:07:24 +0000 | [diff] [blame] | 4271 | TU->setAnonymousNamespace(Anon); |
| 4272 | else |
| 4273 | cast<NamespaceDecl>(D)->setAnonymousNamespace(Anon); |
| 4274 | } |
Sebastian Redl | fa1f370 | 2011-04-24 16:28:13 +0000 | [diff] [blame] | 4275 | break; |
| 4276 | } |
Sebastian Redl | 2ac2c72 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 4277 | |
Richard Smith | 891fc7f | 2017-12-05 01:31:47 +0000 | [diff] [blame] | 4278 | case UPD_CXX_ADDED_VAR_DEFINITION: { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4279 | auto *VD = cast<VarDecl>(D); |
Richard Smith | f501759 | 2017-11-02 01:06:00 +0000 | [diff] [blame] | 4280 | VD->NonParmVarDeclBits.IsInline = Record.readInt(); |
| 4281 | VD->NonParmVarDeclBits.IsInlineSpecified = Record.readInt(); |
Richard Smith | 05a2135 | 2017-06-22 22:18:46 +0000 | [diff] [blame] | 4282 | uint64_t Val = Record.readInt(); |
| 4283 | if (Val && !VD->getInit()) { |
| 4284 | VD->setInit(Record.readExpr()); |
| 4285 | if (Val > 1) { // IsInitKnownICE = 1, IsInitNotICE = 2, IsInitICE = 3 |
| 4286 | EvaluatedStmt *Eval = VD->ensureEvaluatedStmt(); |
| 4287 | Eval->CheckedICE = true; |
| 4288 | Eval->IsICE = Val == 3; |
| 4289 | } |
| 4290 | } |
Sebastian Redl | 2ac2c72 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 4291 | break; |
Richard Smith | 05a2135 | 2017-06-22 22:18:46 +0000 | [diff] [blame] | 4292 | } |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 4293 | |
Richard Smith | 891fc7f | 2017-12-05 01:31:47 +0000 | [diff] [blame] | 4294 | case UPD_CXX_POINT_OF_INSTANTIATION: { |
| 4295 | SourceLocation POI = Record.readSourceLocation(); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4296 | if (auto *VTSD = dyn_cast<VarTemplateSpecializationDecl>(D)) { |
Richard Smith | 891fc7f | 2017-12-05 01:31:47 +0000 | [diff] [blame] | 4297 | VTSD->setPointOfInstantiation(POI); |
| 4298 | } else if (auto *VD = dyn_cast<VarDecl>(D)) { |
| 4299 | VD->getMemberSpecializationInfo()->setPointOfInstantiation(POI); |
| 4300 | } else { |
| 4301 | auto *FD = cast<FunctionDecl>(D); |
| 4302 | if (auto *FTSInfo = FD->TemplateOrSpecialization |
| 4303 | .dyn_cast<FunctionTemplateSpecializationInfo *>()) |
| 4304 | FTSInfo->setPointOfInstantiation(POI); |
| 4305 | else |
| 4306 | FD->TemplateOrSpecialization.get<MemberSpecializationInfo *>() |
| 4307 | ->setPointOfInstantiation(POI); |
| 4308 | } |
| 4309 | break; |
| 4310 | } |
| 4311 | |
John McCall | 32791cc | 2016-01-06 22:34:54 +0000 | [diff] [blame] | 4312 | case UPD_CXX_INSTANTIATED_DEFAULT_ARGUMENT: { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4313 | auto *Param = cast<ParmVarDecl>(D); |
John McCall | 32791cc | 2016-01-06 22:34:54 +0000 | [diff] [blame] | 4314 | |
| 4315 | // We have to read the default argument regardless of whether we use it |
| 4316 | // so that hypothetical further update records aren't messed up. |
| 4317 | // TODO: Add a function to skip over the next expr record. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4318 | auto *DefaultArg = Record.readExpr(); |
John McCall | 32791cc | 2016-01-06 22:34:54 +0000 | [diff] [blame] | 4319 | |
| 4320 | // Only apply the update if the parameter still has an uninstantiated |
| 4321 | // default argument. |
| 4322 | if (Param->hasUninstantiatedDefaultArg()) |
| 4323 | Param->setDefaultArg(DefaultArg); |
| 4324 | break; |
| 4325 | } |
| 4326 | |
Richard Smith | 4b054b2 | 2016-08-24 21:25:37 +0000 | [diff] [blame] | 4327 | case UPD_CXX_INSTANTIATED_DEFAULT_MEMBER_INITIALIZER: { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4328 | auto *FD = cast<FieldDecl>(D); |
| 4329 | auto *DefaultInit = Record.readExpr(); |
Richard Smith | 4b054b2 | 2016-08-24 21:25:37 +0000 | [diff] [blame] | 4330 | |
| 4331 | // Only apply the update if the field still has an uninstantiated |
| 4332 | // default member initializer. |
| 4333 | if (FD->hasInClassInitializer() && !FD->getInClassInitializer()) { |
| 4334 | if (DefaultInit) |
| 4335 | FD->setInClassInitializer(DefaultInit); |
| 4336 | else |
| 4337 | // Instantiation failed. We can get here if we serialized an AST for |
| 4338 | // an invalid program. |
| 4339 | FD->removeInClassInitializer(); |
| 4340 | } |
| 4341 | break; |
| 4342 | } |
| 4343 | |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 4344 | case UPD_CXX_ADDED_FUNCTION_DEFINITION: { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4345 | auto *FD = cast<FunctionDecl>(D); |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 4346 | if (Reader.PendingBodies[FD]) { |
| 4347 | // FIXME: Maybe check for ODR violations. |
| 4348 | // It's safe to stop now because this update record is always last. |
| 4349 | return; |
| 4350 | } |
| 4351 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 4352 | if (Record.readInt()) { |
Richard Smith | 195d8ef | 2014-05-29 03:15:31 +0000 | [diff] [blame] | 4353 | // Maintain AST consistency: any later redeclarations of this function |
| 4354 | // are inline if this one is. (We might have merged another declaration |
| 4355 | // into this one.) |
Richard Smith | d6db68c | 2014-08-07 20:58:41 +0000 | [diff] [blame] | 4356 | forAllLaterRedecls(FD, [](FunctionDecl *FD) { |
| 4357 | FD->setImplicitlyInline(); |
| 4358 | }); |
Richard Smith | 195d8ef | 2014-05-29 03:15:31 +0000 | [diff] [blame] | 4359 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4360 | FD->setInnerLocStart(ReadSourceLocation()); |
David Blaikie | ac4345c | 2017-02-12 18:45:31 +0000 | [diff] [blame] | 4361 | ReadFunctionDefinition(FD); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 4362 | assert(Record.getIdx() == Record.size() && "lazy body must be last"); |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 4363 | break; |
| 4364 | } |
| 4365 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4366 | case UPD_CXX_INSTANTIATED_CLASS_DEFINITION: { |
| 4367 | auto *RD = cast<CXXRecordDecl>(D); |
Richard Smith | b648399 | 2016-05-17 22:44:15 +0000 | [diff] [blame] | 4368 | auto *OldDD = RD->getCanonicalDecl()->DefinitionData; |
Richard Smith | 2a9e5c5 | 2015-02-03 03:32:14 +0000 | [diff] [blame] | 4369 | bool HadRealDefinition = |
Richard Smith | 7483d20 | 2015-02-04 01:23:46 +0000 | [diff] [blame] | 4370 | OldDD && (OldDD->Definition != RD || |
| 4371 | !Reader.PendingFakeDefinitionData.count(OldDD)); |
Akira Hatanaka | fcbe17c | 2018-03-28 21:13:14 +0000 | [diff] [blame] | 4372 | RD->setParamDestroyedInCallee(Record.readInt()); |
Akira Hatanaka | e6313ac | 2018-04-09 22:48:22 +0000 | [diff] [blame] | 4373 | RD->setArgPassingRestrictions( |
| 4374 | (RecordDecl::ArgPassingKind)Record.readInt()); |
Richard Smith | 2a9e5c5 | 2015-02-03 03:32:14 +0000 | [diff] [blame] | 4375 | ReadCXXRecordDefinition(RD, /*Update*/true); |
| 4376 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4377 | // Visible update is handled separately. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4378 | uint64_t LexicalOffset = ReadLocalOffset(); |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 4379 | if (!HadRealDefinition && LexicalOffset) { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 4380 | Record.readLexicalDeclContextStorage(LexicalOffset, RD); |
Richard Smith | 2a9e5c5 | 2015-02-03 03:32:14 +0000 | [diff] [blame] | 4381 | Reader.PendingFakeDefinitionData.erase(OldDD); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4382 | } |
| 4383 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 4384 | auto TSK = (TemplateSpecializationKind)Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4385 | SourceLocation POI = ReadSourceLocation(); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4386 | if (MemberSpecializationInfo *MSInfo = |
| 4387 | RD->getMemberSpecializationInfo()) { |
| 4388 | MSInfo->setTemplateSpecializationKind(TSK); |
| 4389 | MSInfo->setPointOfInstantiation(POI); |
| 4390 | } else { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4391 | auto *Spec = cast<ClassTemplateSpecializationDecl>(RD); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4392 | Spec->setTemplateSpecializationKind(TSK); |
| 4393 | Spec->setPointOfInstantiation(POI); |
Richard Smith | df35205 | 2014-05-22 20:59:29 +0000 | [diff] [blame] | 4394 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 4395 | if (Record.readInt()) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4396 | auto *PartialSpec = |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4397 | ReadDeclAs<ClassTemplatePartialSpecializationDecl>(); |
Richard Smith | df35205 | 2014-05-22 20:59:29 +0000 | [diff] [blame] | 4398 | SmallVector<TemplateArgument, 8> TemplArgs; |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 4399 | Record.readTemplateArgumentList(TemplArgs); |
Richard Smith | df35205 | 2014-05-22 20:59:29 +0000 | [diff] [blame] | 4400 | auto *TemplArgList = TemplateArgumentList::CreateCopy( |
David Majnemer | 8b62269 | 2016-07-03 21:17:51 +0000 | [diff] [blame] | 4401 | Reader.getContext(), TemplArgs); |
Richard Smith | 72544f8 | 2014-08-14 03:30:27 +0000 | [diff] [blame] | 4402 | |
| 4403 | // FIXME: If we already have a partial specialization set, |
| 4404 | // check that it matches. |
| 4405 | if (!Spec->getSpecializedTemplateOrPartial() |
| 4406 | .is<ClassTemplatePartialSpecializationDecl *>()) |
| 4407 | Spec->setInstantiationOf(PartialSpec, TemplArgList); |
Richard Smith | df35205 | 2014-05-22 20:59:29 +0000 | [diff] [blame] | 4408 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4409 | } |
| 4410 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 4411 | RD->setTagKind((TagTypeKind)Record.readInt()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4412 | RD->setLocation(ReadSourceLocation()); |
| 4413 | RD->setLocStart(ReadSourceLocation()); |
| 4414 | RD->setBraceRange(ReadSourceRange()); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4415 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 4416 | if (Record.readInt()) { |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4417 | AttrVec Attrs; |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 4418 | Record.readAttributes(Attrs); |
Richard Smith | 842e46e | 2016-10-26 02:31:56 +0000 | [diff] [blame] | 4419 | // If the declaration already has attributes, we assume that some other |
| 4420 | // AST file already loaded them. |
| 4421 | if (!D->hasAttrs()) |
| 4422 | D->setAttrsImpl(Attrs, Reader.getContext()); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4423 | } |
| 4424 | break; |
| 4425 | } |
| 4426 | |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 4427 | case UPD_CXX_RESOLVED_DTOR_DELETE: { |
| 4428 | // Set the 'operator delete' directly to avoid emitting another update |
| 4429 | // record. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4430 | auto *Del = ReadDeclAs<FunctionDecl>(); |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 4431 | auto *First = cast<CXXDestructorDecl>(D->getCanonicalDecl()); |
Richard Smith | 5b34958 | 2017-10-13 01:55:36 +0000 | [diff] [blame] | 4432 | auto *ThisArg = Record.readExpr(); |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 4433 | // FIXME: Check consistency if we have an old and new operator delete. |
Richard Smith | 5b34958 | 2017-10-13 01:55:36 +0000 | [diff] [blame] | 4434 | if (!First->OperatorDelete) { |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 4435 | First->OperatorDelete = Del; |
Richard Smith | 5b34958 | 2017-10-13 01:55:36 +0000 | [diff] [blame] | 4436 | First->OperatorDeleteThisArg = ThisArg; |
| 4437 | } |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 4438 | break; |
| 4439 | } |
| 4440 | |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 4441 | case UPD_CXX_RESOLVED_EXCEPTION_SPEC: { |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 4442 | FunctionProtoType::ExceptionSpecInfo ESI; |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 4443 | SmallVector<QualType, 8> ExceptionStorage; |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 4444 | Record.readExceptionSpec(ExceptionStorage, ESI); |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 4445 | |
| 4446 | // Update this declaration's exception specification, if needed. |
| 4447 | auto *FD = cast<FunctionDecl>(D); |
| 4448 | auto *FPT = FD->getType()->castAs<FunctionProtoType>(); |
| 4449 | // FIXME: If the exception specification is already present, check that it |
| 4450 | // matches. |
| 4451 | if (isUnresolvedExceptionSpec(FPT->getExceptionSpecType())) { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 4452 | FD->setType(Reader.getContext().getFunctionType( |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 4453 | FPT->getReturnType(), FPT->getParamTypes(), |
| 4454 | FPT->getExtProtoInfo().withExceptionSpec(ESI))); |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 4455 | |
| 4456 | // When we get to the end of deserializing, see if there are other decls |
| 4457 | // that we need to propagate this exception specification onto. |
| 4458 | Reader.PendingExceptionSpecUpdates.insert( |
| 4459 | std::make_pair(FD->getCanonicalDecl(), FD)); |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 4460 | } |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 4461 | break; |
| 4462 | } |
| 4463 | |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 4464 | case UPD_CXX_DEDUCED_RETURN_TYPE: { |
Richard Smith | a62d198 | 2018-08-03 01:00:01 +0000 | [diff] [blame] | 4465 | auto *FD = cast<FunctionDecl>(D); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 4466 | QualType DeducedResultType = Record.readType(); |
Richard Smith | a62d198 | 2018-08-03 01:00:01 +0000 | [diff] [blame] | 4467 | Reader.PendingDeducedTypeUpdates.insert( |
| 4468 | {FD->getCanonicalDecl(), DeducedResultType}); |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 4469 | break; |
| 4470 | } |
Eli Friedman | 276dd18 | 2013-09-05 00:02:25 +0000 | [diff] [blame] | 4471 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4472 | case UPD_DECL_MARKED_USED: |
Richard Smith | 675d279 | 2014-06-16 20:26:19 +0000 | [diff] [blame] | 4473 | // Maintain AST consistency: any later redeclarations are used too. |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 4474 | D->markUsed(Reader.getContext()); |
Eli Friedman | 276dd18 | 2013-09-05 00:02:25 +0000 | [diff] [blame] | 4475 | break; |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4476 | |
| 4477 | case UPD_MANGLING_NUMBER: |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 4478 | Reader.getContext().setManglingNumber(cast<NamedDecl>(D), |
| 4479 | Record.readInt()); |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4480 | break; |
| 4481 | |
| 4482 | case UPD_STATIC_LOCAL_NUMBER: |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 4483 | Reader.getContext().setStaticLocalNumber(cast<VarDecl>(D), |
| 4484 | Record.readInt()); |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4485 | break; |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 4486 | |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 4487 | case UPD_DECL_MARKED_OPENMP_THREADPRIVATE: |
Erich Keane | 6a24e80 | 2019-09-13 17:39:31 +0000 | [diff] [blame] | 4488 | D->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit( |
| 4489 | Reader.getContext(), ReadSourceRange(), |
| 4490 | AttributeCommonInfo::AS_Pragma)); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 4491 | break; |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 4492 | |
Alexey Bataev | 27ef951 | 2019-03-20 20:14:22 +0000 | [diff] [blame] | 4493 | case UPD_DECL_MARKED_OPENMP_ALLOCATE: { |
| 4494 | auto AllocatorKind = |
| 4495 | static_cast<OMPAllocateDeclAttr::AllocatorTypeTy>(Record.readInt()); |
| 4496 | Expr *Allocator = Record.readExpr(); |
| 4497 | SourceRange SR = ReadSourceRange(); |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 4498 | D->addAttr(OMPAllocateDeclAttr::CreateImplicit( |
Erich Keane | 6a24e80 | 2019-09-13 17:39:31 +0000 | [diff] [blame] | 4499 | Reader.getContext(), AllocatorKind, Allocator, SR, |
| 4500 | AttributeCommonInfo::AS_Pragma)); |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 4501 | break; |
Alexey Bataev | 27ef951 | 2019-03-20 20:14:22 +0000 | [diff] [blame] | 4502 | } |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 4503 | |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 4504 | case UPD_DECL_EXPORTED: { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4505 | unsigned SubmoduleID = readSubmoduleID(); |
Richard Smith | beb4478 | 2015-06-20 01:05:19 +0000 | [diff] [blame] | 4506 | auto *Exported = cast<NamedDecl>(D); |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 4507 | Module *Owner = SubmoduleID ? Reader.getSubmodule(SubmoduleID) : nullptr; |
Richard Smith | 13897eb | 2018-09-12 23:37:00 +0000 | [diff] [blame] | 4508 | Reader.getContext().mergeDefinitionIntoModule(Exported, Owner); |
| 4509 | Reader.PendingMergedDefinitionsToDeduplicate.insert(Exported); |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 4510 | break; |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 4511 | } |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 4512 | |
Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 4513 | case UPD_DECL_MARKED_OPENMP_DECLARETARGET: { |
| 4514 | OMPDeclareTargetDeclAttr::MapTypeTy MapType = |
| 4515 | static_cast<OMPDeclareTargetDeclAttr::MapTypeTy>(Record.readInt()); |
| 4516 | OMPDeclareTargetDeclAttr::DevTypeTy DevType = |
| 4517 | static_cast<OMPDeclareTargetDeclAttr::DevTypeTy>(Record.readInt()); |
Alexey Bataev | d01b749 | 2018-08-15 19:45:12 +0000 | [diff] [blame] | 4518 | D->addAttr(OMPDeclareTargetDeclAttr::CreateImplicit( |
Erich Keane | 6a24e80 | 2019-09-13 17:39:31 +0000 | [diff] [blame] | 4519 | Reader.getContext(), MapType, DevType, ReadSourceRange(), |
| 4520 | AttributeCommonInfo::AS_Pragma)); |
Alexey Bataev | d01b749 | 2018-08-15 19:45:12 +0000 | [diff] [blame] | 4521 | break; |
Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 4522 | } |
Alexey Bataev | d01b749 | 2018-08-15 19:45:12 +0000 | [diff] [blame] | 4523 | |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 4524 | case UPD_ADDED_ATTR_TO_RECORD: |
| 4525 | AttrVec Attrs; |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 4526 | Record.readAttributes(Attrs); |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 4527 | assert(Attrs.size() == 1); |
| 4528 | D->addAttr(Attrs[0]); |
| 4529 | break; |
| 4530 | } |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 4531 | } |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4532 | } |