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 | // |
| 3 | // The LLVM Compiler Infrastructure |
| 4 | // |
| 5 | // This file is distributed under the University of Illinois Open Source |
| 6 | // License. See LICENSE.TXT for details. |
| 7 | // |
| 8 | //===----------------------------------------------------------------------===// |
| 9 | // |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 10 | // This file implements the ASTReader::ReadDeclRecord method, which is the |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 11 | // entrypoint for loading a decl. |
| 12 | // |
| 13 | //===----------------------------------------------------------------------===// |
| 14 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 15 | #include "ASTCommon.h" |
Benjamin Kramer | 89f0b2d | 2012-04-15 12:36:49 +0000 | [diff] [blame] | 16 | #include "ASTReaderInternals.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 17 | #include "clang/AST/ASTContext.h" |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 18 | #include "clang/AST/Attr.h" |
| 19 | #include "clang/AST/AttrIterator.h" |
| 20 | #include "clang/AST/Decl.h" |
| 21 | #include "clang/AST/DeclBase.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 22 | #include "clang/AST/DeclCXX.h" |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 23 | #include "clang/AST/DeclFriend.h" |
| 24 | #include "clang/AST/DeclObjC.h" |
| 25 | #include "clang/AST/DeclOpenMP.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 26 | #include "clang/AST/DeclTemplate.h" |
| 27 | #include "clang/AST/DeclVisitor.h" |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 28 | #include "clang/AST/DeclarationName.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 29 | #include "clang/AST/Expr.h" |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 30 | #include "clang/AST/ExternalASTSource.h" |
| 31 | #include "clang/AST/LambdaCapture.h" |
| 32 | #include "clang/AST/NestedNameSpecifier.h" |
Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 33 | #include "clang/AST/OpenMPClause.h" |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 34 | #include "clang/AST/Redeclarable.h" |
| 35 | #include "clang/AST/Stmt.h" |
| 36 | #include "clang/AST/TemplateBase.h" |
| 37 | #include "clang/AST/Type.h" |
| 38 | #include "clang/AST/UnresolvedSet.h" |
| 39 | #include "clang/Basic/AttrKinds.h" |
| 40 | #include "clang/Basic/ExceptionSpecificationType.h" |
| 41 | #include "clang/Basic/IdentifierTable.h" |
| 42 | #include "clang/Basic/LLVM.h" |
| 43 | #include "clang/Basic/Lambda.h" |
| 44 | #include "clang/Basic/LangOptions.h" |
| 45 | #include "clang/Basic/Linkage.h" |
| 46 | #include "clang/Basic/Module.h" |
| 47 | #include "clang/Basic/PragmaKinds.h" |
| 48 | #include "clang/Basic/SourceLocation.h" |
| 49 | #include "clang/Basic/Specifiers.h" |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 50 | #include "clang/Sema/IdentifierResolver.h" |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 51 | #include "clang/Sema/SemaDiagnostic.h" |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 52 | #include "clang/Serialization/ASTBitCodes.h" |
Mehdi Amini | 9670f84 | 2016-07-18 19:02:11 +0000 | [diff] [blame] | 53 | #include "clang/Serialization/ASTReader.h" |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 54 | #include "clang/Serialization/ContinuousRangeMap.h" |
| 55 | #include "clang/Serialization/Module.h" |
| 56 | #include "llvm/ADT/DenseMap.h" |
| 57 | #include "llvm/ADT/FoldingSet.h" |
| 58 | #include "llvm/ADT/STLExtras.h" |
| 59 | #include "llvm/ADT/SmallPtrSet.h" |
| 60 | #include "llvm/ADT/SmallVector.h" |
| 61 | #include "llvm/ADT/iterator_range.h" |
| 62 | #include "llvm/Bitcode/BitstreamReader.h" |
| 63 | #include "llvm/Support/Casting.h" |
| 64 | #include "llvm/Support/ErrorHandling.h" |
Argyrios Kyrtzidis | 0f7d7ab | 2012-05-04 01:49:36 +0000 | [diff] [blame] | 65 | #include "llvm/Support/SaveAndRestore.h" |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 66 | #include <algorithm> |
| 67 | #include <cassert> |
| 68 | #include <cstdint> |
| 69 | #include <cstring> |
| 70 | #include <string> |
| 71 | #include <utility> |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 72 | |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 73 | using namespace clang; |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 74 | using namespace serialization; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 75 | |
| 76 | //===----------------------------------------------------------------------===// |
| 77 | // Declaration deserialization |
| 78 | //===----------------------------------------------------------------------===// |
| 79 | |
Argyrios Kyrtzidis | 74d28bd | 2010-06-29 22:47:00 +0000 | [diff] [blame] | 80 | namespace clang { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 81 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 82 | class ASTDeclReader : public DeclVisitor<ASTDeclReader, void> { |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 83 | ASTReader &Reader; |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 84 | ASTRecordReader &Record; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 85 | ASTReader::RecordLocation Loc; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 86 | const DeclID ThisDeclID; |
Richard Smith | cb34bd3 | 2016-03-27 07:28:06 +0000 | [diff] [blame] | 87 | const SourceLocation ThisDeclLoc; |
Vassil Vassilev | 6565dfc | 2016-02-26 10:43:34 +0000 | [diff] [blame] | 88 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 89 | using RecordData = ASTReader::RecordData; |
| 90 | |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 91 | TypeID DeferredTypeID = 0; |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 92 | unsigned AnonymousDeclNumber; |
| 93 | GlobalDeclID NamedDeclForTagDecl = 0; |
| 94 | IdentifierInfo *TypedefNameForLinkage = nullptr; |
| 95 | |
| 96 | bool HasPendingBody = false; |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 97 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 98 | ///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] | 99 | /// used. We use it to delay the marking of the canonical decl as used until |
| 100 | /// the entire declaration is deserialized and merged. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 101 | bool IsDeclMarkedUsed = false; |
Vassil Vassilev | 928c825 | 2016-04-28 14:13:28 +0000 | [diff] [blame] | 102 | |
Sebastian Redl | c67764e | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 103 | uint64_t GetCurrentCursorOffset(); |
Vassil Vassilev | 6565dfc | 2016-02-26 10:43:34 +0000 | [diff] [blame] | 104 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 105 | uint64_t ReadLocalOffset() { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 106 | uint64_t LocalOffset = Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 107 | assert(LocalOffset < Loc.Offset && "offset point after current record"); |
| 108 | return LocalOffset ? Loc.Offset - LocalOffset : 0; |
Richard Smith | e37e9f4 | 2016-03-25 01:17:43 +0000 | [diff] [blame] | 109 | } |
| 110 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 111 | uint64_t ReadGlobalOffset() { |
| 112 | uint64_t Local = ReadLocalOffset(); |
| 113 | return Local ? Record.getGlobalBitOffset(Local) : 0; |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 114 | } |
| 115 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 116 | SourceLocation ReadSourceLocation() { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 117 | return Record.readSourceLocation(); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 118 | } |
Vassil Vassilev | 6565dfc | 2016-02-26 10:43:34 +0000 | [diff] [blame] | 119 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 120 | SourceRange ReadSourceRange() { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 121 | return Record.readSourceRange(); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 122 | } |
Vassil Vassilev | 6565dfc | 2016-02-26 10:43:34 +0000 | [diff] [blame] | 123 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 124 | TypeSourceInfo *GetTypeSourceInfo() { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 125 | return Record.getTypeSourceInfo(); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 126 | } |
Vassil Vassilev | 6565dfc | 2016-02-26 10:43:34 +0000 | [diff] [blame] | 127 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 128 | serialization::DeclID ReadDeclID() { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 129 | return Record.readDeclID(); |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 130 | } |
Richard Smith | 0b88437 | 2015-02-27 00:25:58 +0000 | [diff] [blame] | 131 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 132 | std::string ReadString() { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 133 | return Record.readString(); |
Nico Weber | 6622029 | 2016-03-02 17:28:48 +0000 | [diff] [blame] | 134 | } |
| 135 | |
Richard Smith | 0b88437 | 2015-02-27 00:25:58 +0000 | [diff] [blame] | 136 | void ReadDeclIDList(SmallVectorImpl<DeclID> &IDs) { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 137 | for (unsigned I = 0, Size = Record.readInt(); I != Size; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 138 | IDs.push_back(ReadDeclID()); |
Richard Smith | 0b88437 | 2015-02-27 00:25:58 +0000 | [diff] [blame] | 139 | } |
| 140 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 141 | Decl *ReadDecl() { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 142 | return Record.readDecl(); |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | template<typename T> |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 146 | T *ReadDeclAs() { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 147 | return Record.readDeclAs<T>(); |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 148 | } |
| 149 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 150 | void ReadQualifierInfo(QualifierInfo &Info) { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 151 | Record.readQualifierInfo(Info); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 152 | } |
Sebastian Redl | c67764e | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 153 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 154 | void ReadDeclarationNameLoc(DeclarationNameLoc &DNLoc, DeclarationName Name) { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 155 | Record.readDeclarationNameLoc(DNLoc, Name); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | serialization::SubmoduleID readSubmoduleID() { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 159 | if (Record.getIdx() == Record.size()) |
Douglas Gregor | cf68c58 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 160 | return 0; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 161 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 162 | return Record.getGlobalSubmoduleID(Record.readInt()); |
Douglas Gregor | cf68c58 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 163 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 164 | |
| 165 | Module *readModule() { |
| 166 | return Record.getSubmodule(readSubmoduleID()); |
Douglas Gregor | ba34552 | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 167 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 168 | |
Richard Smith | 2a9e5c5 | 2015-02-03 03:32:14 +0000 | [diff] [blame] | 169 | void ReadCXXRecordDefinition(CXXRecordDecl *D, bool Update); |
David Blaikie | 1ac9c98 | 2017-04-11 21:13:37 +0000 | [diff] [blame] | 170 | void ReadCXXDefinitionData(struct CXXRecordDecl::DefinitionData &Data, |
| 171 | const CXXRecordDecl *D); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 172 | void MergeDefinitionData(CXXRecordDecl *D, |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 173 | struct CXXRecordDecl::DefinitionData &&NewDD); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 174 | void ReadObjCDefinitionData(struct ObjCInterfaceDecl::DefinitionData &Data); |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 175 | void MergeDefinitionData(ObjCInterfaceDecl *D, |
| 176 | struct ObjCInterfaceDecl::DefinitionData &&NewDD); |
Graydon Hoare | e0a6835 | 2017-06-28 18:36:27 +0000 | [diff] [blame] | 177 | void ReadObjCDefinitionData(struct ObjCProtocolDecl::DefinitionData &Data); |
| 178 | void MergeDefinitionData(ObjCProtocolDecl *D, |
| 179 | struct ObjCProtocolDecl::DefinitionData &&NewDD); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 180 | |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 181 | static DeclContext *getPrimaryDCForAnonymousDecl(DeclContext *LexicalDC); |
| 182 | |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 183 | static NamedDecl *getAnonymousDeclForMerging(ASTReader &Reader, |
| 184 | DeclContext *DC, |
| 185 | unsigned Index); |
| 186 | static void setAnonymousDeclForMerging(ASTReader &Reader, DeclContext *DC, |
| 187 | unsigned Index, NamedDecl *D); |
| 188 | |
Richard Smith | 0144f51 | 2015-08-22 02:09:38 +0000 | [diff] [blame] | 189 | /// Results from loading a RedeclarableDecl. |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 190 | class RedeclarableResult { |
Richard Smith | 5a4737c | 2015-02-06 02:42:59 +0000 | [diff] [blame] | 191 | Decl *MergeWith; |
Alexander Shaposhnikov | fbc4d68 | 2016-09-24 04:21:53 +0000 | [diff] [blame] | 192 | GlobalDeclID FirstID; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 193 | bool IsKeyDecl; |
Richard Smith | c89bb9d | 2015-02-25 01:11:29 +0000 | [diff] [blame] | 194 | |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 195 | public: |
Alexander Shaposhnikov | fbc4d68 | 2016-09-24 04:21:53 +0000 | [diff] [blame] | 196 | RedeclarableResult(Decl *MergeWith, GlobalDeclID FirstID, bool IsKeyDecl) |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 197 | : MergeWith(MergeWith), FirstID(FirstID), IsKeyDecl(IsKeyDecl) {} |
Richard Smith | 9b88a4c | 2015-07-27 05:40:23 +0000 | [diff] [blame] | 198 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 199 | /// Retrieve the first ID. |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 200 | GlobalDeclID getFirstID() const { return FirstID; } |
Richard Smith | 5a4737c | 2015-02-06 02:42:59 +0000 | [diff] [blame] | 201 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 202 | /// Is this declaration a key declaration? |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 203 | bool isKeyDecl() const { return IsKeyDecl; } |
| 204 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 205 | /// Get a known declaration that this should be merged with, if |
Richard Smith | 5a4737c | 2015-02-06 02:42:59 +0000 | [diff] [blame] | 206 | /// any. |
| 207 | Decl *getKnownMergeTarget() const { return MergeWith; } |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 208 | }; |
Douglas Gregor | fe732d5 | 2013-01-21 16:16:40 +0000 | [diff] [blame] | 209 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 210 | /// Class used to capture the result of searching for an existing |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 211 | /// declaration of a specific kind and name, along with the ability |
| 212 | /// to update the place where this result was found (the declaration |
| 213 | /// chain hanging off an identifier or the DeclContext we searched in) |
| 214 | /// if requested. |
| 215 | class FindExistingResult { |
| 216 | ASTReader &Reader; |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 217 | NamedDecl *New = nullptr; |
| 218 | NamedDecl *Existing = nullptr; |
| 219 | bool AddResult = false; |
| 220 | unsigned AnonymousDeclNumber = 0; |
| 221 | IdentifierInfo *TypedefNameForLinkage = nullptr; |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 222 | |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 223 | public: |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 224 | FindExistingResult(ASTReader &Reader) : Reader(Reader) {} |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 225 | |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 226 | FindExistingResult(ASTReader &Reader, NamedDecl *New, NamedDecl *Existing, |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 227 | unsigned AnonymousDeclNumber, |
| 228 | IdentifierInfo *TypedefNameForLinkage) |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 229 | : Reader(Reader), New(New), Existing(Existing), AddResult(true), |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 230 | AnonymousDeclNumber(AnonymousDeclNumber), |
| 231 | TypedefNameForLinkage(TypedefNameForLinkage) {} |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 232 | |
Benjamin Kramer | b6aadc1 | 2016-08-06 12:45:16 +0000 | [diff] [blame] | 233 | FindExistingResult(FindExistingResult &&Other) |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 234 | : Reader(Other.Reader), New(Other.New), Existing(Other.Existing), |
| 235 | AddResult(Other.AddResult), |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 236 | AnonymousDeclNumber(Other.AnonymousDeclNumber), |
| 237 | TypedefNameForLinkage(Other.TypedefNameForLinkage) { |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 238 | Other.AddResult = false; |
| 239 | } |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 240 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 241 | FindExistingResult &operator=(FindExistingResult &&) = delete; |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 242 | ~FindExistingResult(); |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 243 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 244 | /// Suppress the addition of this result into the known set of |
Douglas Gregor | 2009cee | 2012-01-03 22:46:00 +0000 | [diff] [blame] | 245 | /// names. |
| 246 | void suppress() { AddResult = false; } |
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 | operator NamedDecl*() const { return Existing; } |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 249 | |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 250 | template<typename T> |
| 251 | operator T*() const { return dyn_cast_or_null<T>(Existing); } |
| 252 | }; |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 253 | |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 254 | static DeclContext *getPrimaryContextForMerging(ASTReader &Reader, |
| 255 | DeclContext *DC); |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 256 | FindExistingResult findExisting(NamedDecl *D); |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 257 | |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 258 | public: |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 259 | ASTDeclReader(ASTReader &Reader, ASTRecordReader &Record, |
| 260 | ASTReader::RecordLocation Loc, |
| 261 | DeclID thisDeclID, SourceLocation ThisDeclLoc) |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 262 | : Reader(Reader), Record(Record), Loc(Loc), ThisDeclID(thisDeclID), |
| 263 | ThisDeclLoc(ThisDeclLoc) {} |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 264 | |
Vassil Vassilev | 7d26462 | 2017-06-30 22:40:17 +0000 | [diff] [blame] | 265 | template <typename T> static |
| 266 | void AddLazySpecializations(T *D, |
| 267 | SmallVectorImpl<serialization::DeclID>& IDs) { |
| 268 | if (IDs.empty()) |
| 269 | return; |
| 270 | |
| 271 | // FIXME: We should avoid this pattern of getting the ASTContext. |
| 272 | ASTContext &C = D->getASTContext(); |
| 273 | |
| 274 | auto *&LazySpecializations = D->getCommonPtr()->LazySpecializations; |
| 275 | |
| 276 | if (auto &Old = LazySpecializations) { |
| 277 | IDs.insert(IDs.end(), Old + 1, Old + 1 + Old[0]); |
Fangrui Song | 55fab26 | 2018-09-26 22:16:28 +0000 | [diff] [blame] | 278 | llvm::sort(IDs); |
Vassil Vassilev | 7d26462 | 2017-06-30 22:40:17 +0000 | [diff] [blame] | 279 | IDs.erase(std::unique(IDs.begin(), IDs.end()), IDs.end()); |
| 280 | } |
| 281 | |
| 282 | auto *Result = new (C) serialization::DeclID[1 + IDs.size()]; |
| 283 | *Result = IDs.size(); |
| 284 | std::copy(IDs.begin(), IDs.end(), Result + 1); |
| 285 | |
| 286 | LazySpecializations = Result; |
| 287 | } |
| 288 | |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 289 | template <typename DeclT> |
Richard Smith | c3a5325 | 2015-02-28 05:57:02 +0000 | [diff] [blame] | 290 | static Decl *getMostRecentDeclImpl(Redeclarable<DeclT> *D); |
| 291 | static Decl *getMostRecentDeclImpl(...); |
| 292 | static Decl *getMostRecentDecl(Decl *D); |
| 293 | |
| 294 | template <typename DeclT> |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 295 | static void attachPreviousDeclImpl(ASTReader &Reader, |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 296 | Redeclarable<DeclT> *D, Decl *Previous, |
| 297 | Decl *Canon); |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 298 | static void attachPreviousDeclImpl(ASTReader &Reader, ...); |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 299 | static void attachPreviousDecl(ASTReader &Reader, Decl *D, Decl *Previous, |
| 300 | Decl *Canon); |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 301 | |
| 302 | template <typename DeclT> |
| 303 | static void attachLatestDeclImpl(Redeclarable<DeclT> *D, Decl *Latest); |
| 304 | static void attachLatestDeclImpl(...); |
Douglas Gregor | 05f1035 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 305 | static void attachLatestDecl(Decl *D, Decl *latest); |
Argyrios Kyrtzidis | 9fdd254 | 2011-02-12 07:50:47 +0000 | [diff] [blame] | 306 | |
Richard Smith | 851072e | 2014-05-19 20:59:20 +0000 | [diff] [blame] | 307 | template <typename DeclT> |
| 308 | static void markIncompleteDeclChainImpl(Redeclarable<DeclT> *D); |
| 309 | static void markIncompleteDeclChainImpl(...); |
| 310 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 311 | /// Determine whether this declaration has a pending body. |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 312 | bool hasPendingBody() const { return HasPendingBody; } |
| 313 | |
David Blaikie | ac4345c | 2017-02-12 18:45:31 +0000 | [diff] [blame] | 314 | void ReadFunctionDefinition(FunctionDecl *FD); |
Argyrios Kyrtzidis | 318b0e7 | 2010-07-02 11:55:01 +0000 | [diff] [blame] | 315 | void Visit(Decl *D); |
| 316 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 317 | void UpdateDecl(Decl *D, SmallVectorImpl<serialization::DeclID> &); |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 318 | |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 319 | static void setNextObjCCategory(ObjCCategoryDecl *Cat, |
| 320 | ObjCCategoryDecl *Next) { |
| 321 | Cat->NextClassCategory = Next; |
| 322 | } |
| 323 | |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 324 | void VisitDecl(Decl *D); |
Nico Weber | 6622029 | 2016-03-02 17:28:48 +0000 | [diff] [blame] | 325 | void VisitPragmaCommentDecl(PragmaCommentDecl *D); |
Nico Weber | cbbaeb1 | 2016-03-02 19:28:54 +0000 | [diff] [blame] | 326 | void VisitPragmaDetectMismatchDecl(PragmaDetectMismatchDecl *D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 327 | void VisitTranslationUnitDecl(TranslationUnitDecl *TU); |
| 328 | void VisitNamedDecl(NamedDecl *ND); |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 329 | void VisitLabelDecl(LabelDecl *LD); |
Douglas Gregor | e31bbd9 | 2010-02-21 18:22:14 +0000 | [diff] [blame] | 330 | void VisitNamespaceDecl(NamespaceDecl *D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 331 | void VisitUsingDirectiveDecl(UsingDirectiveDecl *D); |
| 332 | void VisitNamespaceAliasDecl(NamespaceAliasDecl *D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 333 | void VisitTypeDecl(TypeDecl *TD); |
Richard Smith | 43ccec8e | 2014-08-26 03:52:16 +0000 | [diff] [blame] | 334 | RedeclarableResult VisitTypedefNameDecl(TypedefNameDecl *TD); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 335 | void VisitTypedefDecl(TypedefDecl *TD); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 336 | void VisitTypeAliasDecl(TypeAliasDecl *TD); |
Argyrios Kyrtzidis | bd8ac8c | 2010-06-30 08:49:30 +0000 | [diff] [blame] | 337 | void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D); |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 338 | RedeclarableResult VisitTagDecl(TagDecl *TD); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 339 | void VisitEnumDecl(EnumDecl *ED); |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 340 | RedeclarableResult VisitRecordDeclImpl(RecordDecl *RD); |
| 341 | void VisitRecordDecl(RecordDecl *RD) { VisitRecordDeclImpl(RD); } |
| 342 | RedeclarableResult VisitCXXRecordDeclImpl(CXXRecordDecl *D); |
| 343 | void VisitCXXRecordDecl(CXXRecordDecl *D) { VisitCXXRecordDeclImpl(D); } |
| 344 | RedeclarableResult VisitClassTemplateSpecializationDeclImpl( |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 345 | ClassTemplateSpecializationDecl *D); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 346 | |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 347 | void VisitClassTemplateSpecializationDecl( |
| 348 | ClassTemplateSpecializationDecl *D) { |
| 349 | VisitClassTemplateSpecializationDeclImpl(D); |
| 350 | } |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 351 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 352 | void VisitClassTemplatePartialSpecializationDecl( |
| 353 | ClassTemplatePartialSpecializationDecl *D); |
Sebastian Redl | b744863 | 2011-08-31 13:59:56 +0000 | [diff] [blame] | 354 | void VisitClassScopeFunctionSpecializationDecl( |
| 355 | ClassScopeFunctionSpecializationDecl *D); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 356 | RedeclarableResult |
| 357 | VisitVarTemplateSpecializationDeclImpl(VarTemplateSpecializationDecl *D); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 358 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 359 | void VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D) { |
| 360 | VisitVarTemplateSpecializationDeclImpl(D); |
| 361 | } |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 362 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 363 | void VisitVarTemplatePartialSpecializationDecl( |
| 364 | VarTemplatePartialSpecializationDecl *D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 365 | void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 366 | void VisitValueDecl(ValueDecl *VD); |
| 367 | void VisitEnumConstantDecl(EnumConstantDecl *ECD); |
Argyrios Kyrtzidis | bd8ac8c | 2010-06-30 08:49:30 +0000 | [diff] [blame] | 368 | void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); |
Argyrios Kyrtzidis | 560ac97 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 369 | void VisitDeclaratorDecl(DeclaratorDecl *DD); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 370 | void VisitFunctionDecl(FunctionDecl *FD); |
Richard Smith | bc49120 | 2017-02-17 20:05:37 +0000 | [diff] [blame] | 371 | void VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *GD); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 372 | void VisitCXXMethodDecl(CXXMethodDecl *D); |
| 373 | void VisitCXXConstructorDecl(CXXConstructorDecl *D); |
| 374 | void VisitCXXDestructorDecl(CXXDestructorDecl *D); |
| 375 | void VisitCXXConversionDecl(CXXConversionDecl *D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 376 | void VisitFieldDecl(FieldDecl *FD); |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 377 | void VisitMSPropertyDecl(MSPropertyDecl *FD); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 378 | void VisitIndirectFieldDecl(IndirectFieldDecl *FD); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 379 | RedeclarableResult VisitVarDeclImpl(VarDecl *D); |
| 380 | void VisitVarDecl(VarDecl *VD) { VisitVarDeclImpl(VD); } |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 381 | void VisitImplicitParamDecl(ImplicitParamDecl *PD); |
| 382 | void VisitParmVarDecl(ParmVarDecl *PD); |
Richard Smith | 7b76d81 | 2016-08-12 02:21:25 +0000 | [diff] [blame] | 383 | void VisitDecompositionDecl(DecompositionDecl *DD); |
| 384 | void VisitBindingDecl(BindingDecl *BD); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 385 | void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 386 | DeclID VisitTemplateDecl(TemplateDecl *D); |
Douglas Gregor | 5407920 | 2012-01-06 22:05:37 +0000 | [diff] [blame] | 387 | RedeclarableResult VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 388 | void VisitClassTemplateDecl(ClassTemplateDecl *D); |
David Majnemer | d9b1a4f | 2015-11-04 03:40:30 +0000 | [diff] [blame] | 389 | void VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 390 | void VisitVarTemplateDecl(VarTemplateDecl *D); |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 391 | void VisitFunctionTemplateDecl(FunctionTemplateDecl *D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 392 | void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 393 | void VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D); |
Argyrios Kyrtzidis | 41d4562 | 2010-06-20 14:40:59 +0000 | [diff] [blame] | 394 | void VisitUsingDecl(UsingDecl *D); |
Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 395 | void VisitUsingPackDecl(UsingPackDecl *D); |
Argyrios Kyrtzidis | 41d4562 | 2010-06-20 14:40:59 +0000 | [diff] [blame] | 396 | void VisitUsingShadowDecl(UsingShadowDecl *D); |
Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 397 | void VisitConstructorUsingShadowDecl(ConstructorUsingShadowDecl *D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 398 | void VisitLinkageSpecDecl(LinkageSpecDecl *D); |
Richard Smith | 8df390f | 2016-09-08 23:14:54 +0000 | [diff] [blame] | 399 | void VisitExportDecl(ExportDecl *D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 400 | void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD); |
Douglas Gregor | ba34552 | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 401 | void VisitImportDecl(ImportDecl *D); |
Abramo Bagnara | d734058 | 2010-06-05 05:09:32 +0000 | [diff] [blame] | 402 | void VisitAccessSpecDecl(AccessSpecDecl *D); |
Argyrios Kyrtzidis | 74d28bd | 2010-06-29 22:47:00 +0000 | [diff] [blame] | 403 | void VisitFriendDecl(FriendDecl *D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 404 | void VisitFriendTemplateDecl(FriendTemplateDecl *D); |
| 405 | void VisitStaticAssertDecl(StaticAssertDecl *D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 406 | void VisitBlockDecl(BlockDecl *BD); |
Tareq A. Siraj | 6dfa25a | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 407 | void VisitCapturedDecl(CapturedDecl *CD); |
Michael Han | 8432435 | 2013-02-22 17:15:32 +0000 | [diff] [blame] | 408 | void VisitEmptyDecl(EmptyDecl *D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 409 | |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 410 | std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC); |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 411 | |
| 412 | template<typename T> |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 413 | RedeclarableResult VisitRedeclarable(Redeclarable<T> *D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 414 | |
Douglas Gregor | 2c46b5b | 2012-01-03 17:27:13 +0000 | [diff] [blame] | 415 | template<typename T> |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 416 | void mergeRedeclarable(Redeclarable<T> *D, RedeclarableResult &Redecl, |
| 417 | DeclID TemplatePatternID = 0); |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 418 | |
| 419 | template<typename T> |
| 420 | void mergeRedeclarable(Redeclarable<T> *D, T *Existing, |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 421 | RedeclarableResult &Redecl, |
| 422 | DeclID TemplatePatternID = 0); |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 423 | |
Richard Smith | 0b87e07 | 2013-10-07 08:02:11 +0000 | [diff] [blame] | 424 | template<typename T> |
| 425 | void mergeMergeable(Mergeable<T> *D); |
| 426 | |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 427 | void mergeTemplatePattern(RedeclarableTemplateDecl *D, |
| 428 | RedeclarableTemplateDecl *Existing, |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 429 | DeclID DsID, bool IsKeyDecl); |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 430 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 431 | ObjCTypeParamList *ReadObjCTypeParamList(); |
| 432 | |
Alexis Hunt | ed05325 | 2010-05-30 07:21:58 +0000 | [diff] [blame] | 433 | // FIXME: Reorder according to DeclNodes.td? |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 434 | void VisitObjCMethodDecl(ObjCMethodDecl *D); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 435 | void VisitObjCTypeParamDecl(ObjCTypeParamDecl *D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 436 | void VisitObjCContainerDecl(ObjCContainerDecl *D); |
| 437 | void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); |
| 438 | void VisitObjCIvarDecl(ObjCIvarDecl *D); |
| 439 | void VisitObjCProtocolDecl(ObjCProtocolDecl *D); |
| 440 | void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 441 | void VisitObjCCategoryDecl(ObjCCategoryDecl *D); |
| 442 | void VisitObjCImplDecl(ObjCImplDecl *D); |
| 443 | void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); |
| 444 | void VisitObjCImplementationDecl(ObjCImplementationDecl *D); |
| 445 | void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D); |
| 446 | void VisitObjCPropertyDecl(ObjCPropertyDecl *D); |
| 447 | void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 448 | void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 449 | void VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D); |
Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 450 | void VisitOMPRequiresDecl(OMPRequiresDecl *D); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 451 | void VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 452 | }; |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 453 | |
| 454 | } // namespace clang |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 455 | |
Richard Smith | 86dfc1e | 2015-06-18 22:07:00 +0000 | [diff] [blame] | 456 | namespace { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 457 | |
Richard Smith | 86dfc1e | 2015-06-18 22:07:00 +0000 | [diff] [blame] | 458 | /// Iterator over the redeclarations of a declaration that have already |
| 459 | /// been merged into the same redeclaration chain. |
| 460 | template<typename DeclT> |
| 461 | class MergedRedeclIterator { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 462 | DeclT *Start; |
| 463 | DeclT *Canonical = nullptr; |
| 464 | DeclT *Current = nullptr; |
| 465 | |
Richard Smith | 86dfc1e | 2015-06-18 22:07:00 +0000 | [diff] [blame] | 466 | public: |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 467 | MergedRedeclIterator() = default; |
| 468 | MergedRedeclIterator(DeclT *Start) : Start(Start), Current(Start) {} |
Richard Smith | 86dfc1e | 2015-06-18 22:07:00 +0000 | [diff] [blame] | 469 | |
| 470 | DeclT *operator*() { return Current; } |
| 471 | |
| 472 | MergedRedeclIterator &operator++() { |
| 473 | if (Current->isFirstDecl()) { |
| 474 | Canonical = Current; |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 475 | Current = Current->getMostRecentDecl(); |
Richard Smith | 86dfc1e | 2015-06-18 22:07:00 +0000 | [diff] [blame] | 476 | } else |
| 477 | Current = Current->getPreviousDecl(); |
| 478 | |
| 479 | // If we started in the merged portion, we'll reach our start position |
| 480 | // eventually. Otherwise, we'll never reach it, but the second declaration |
| 481 | // we reached was the canonical declaration, so stop when we see that one |
| 482 | // again. |
| 483 | if (Current == Start || Current == Canonical) |
| 484 | Current = nullptr; |
| 485 | return *this; |
| 486 | } |
| 487 | |
| 488 | friend bool operator!=(const MergedRedeclIterator &A, |
| 489 | const MergedRedeclIterator &B) { |
| 490 | return A.Current != B.Current; |
| 491 | } |
| 492 | }; |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 493 | |
| 494 | } // namespace |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 495 | |
Benjamin Kramer | a0a13c3 | 2016-08-06 11:21:04 +0000 | [diff] [blame] | 496 | template <typename DeclT> |
| 497 | static llvm::iterator_range<MergedRedeclIterator<DeclT>> |
| 498 | merged_redecls(DeclT *D) { |
Craig Topper | 59c2ada | 2015-12-06 05:07:12 +0000 | [diff] [blame] | 499 | return llvm::make_range(MergedRedeclIterator<DeclT>(D), |
| 500 | MergedRedeclIterator<DeclT>()); |
Richard Smith | 86dfc1e | 2015-06-18 22:07:00 +0000 | [diff] [blame] | 501 | } |
| 502 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 503 | uint64_t ASTDeclReader::GetCurrentCursorOffset() { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 504 | return Loc.F->DeclsCursor.GetCurrentBitNo() + Loc.F->GlobalBitOffset; |
Sebastian Redl | c67764e | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 505 | } |
| 506 | |
David Blaikie | ac4345c | 2017-02-12 18:45:31 +0000 | [diff] [blame] | 507 | void ASTDeclReader::ReadFunctionDefinition(FunctionDecl *FD) { |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 508 | if (Record.readInt()) |
Richard Smith | a465362 | 2017-09-06 20:01:14 +0000 | [diff] [blame] | 509 | Reader.DefinitionSource[FD] = Loc.F->Kind == ModuleKind::MK_MainFile; |
David Blaikie | ac4345c | 2017-02-12 18:45:31 +0000 | [diff] [blame] | 510 | if (auto *CD = dyn_cast<CXXConstructorDecl>(FD)) { |
Erich Keane | 9c66506 | 2018-08-01 21:02:40 +0000 | [diff] [blame] | 511 | CD->setNumCtorInitializers(Record.readInt()); |
| 512 | if (CD->getNumCtorInitializers()) |
David Blaikie | ac4345c | 2017-02-12 18:45:31 +0000 | [diff] [blame] | 513 | CD->CtorInitializers = ReadGlobalOffset(); |
| 514 | } |
| 515 | // 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] | 516 | Reader.PendingBodies[FD] = GetCurrentCursorOffset(); |
| 517 | HasPendingBody = true; |
David Blaikie | ac4345c | 2017-02-12 18:45:31 +0000 | [diff] [blame] | 518 | } |
| 519 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 520 | void ASTDeclReader::Visit(Decl *D) { |
| 521 | DeclVisitor<ASTDeclReader, void>::Visit(D); |
Argyrios Kyrtzidis | 318b0e7 | 2010-07-02 11:55:01 +0000 | [diff] [blame] | 522 | |
Vassil Vassilev | 928c825 | 2016-04-28 14:13:28 +0000 | [diff] [blame] | 523 | // At this point we have deserialized and merged the decl and it is safe to |
| 524 | // update its canonical decl to signal that the entire entity is used. |
| 525 | D->getCanonicalDecl()->Used |= IsDeclMarkedUsed; |
| 526 | IsDeclMarkedUsed = false; |
| 527 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 528 | if (auto *DD = dyn_cast<DeclaratorDecl>(D)) { |
Richard Smith | c23d734 | 2018-06-29 20:46:25 +0000 | [diff] [blame] | 529 | if (auto *TInfo = DD->getTypeSourceInfo()) |
| 530 | Record.readTypeLoc(TInfo->getTypeLoc()); |
Jonathan D. Turner | 205c7d5 | 2011-06-03 23:11:16 +0000 | [diff] [blame] | 531 | } |
| 532 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 533 | if (auto *TD = dyn_cast<TypeDecl>(D)) { |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 534 | // We have a fully initialized TypeDecl. Read its type now. |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 535 | TD->setTypeForDecl(Reader.GetType(DeferredTypeID).getTypePtrOrNull()); |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 536 | |
| 537 | // If this is a tag declaration with a typedef name for linkage, it's safe |
| 538 | // to load that typedef now. |
| 539 | if (NamedDeclForTagDecl) |
David Majnemer | 0035052 | 2015-08-31 18:48:39 +0000 | [diff] [blame] | 540 | cast<TagDecl>(D)->TypedefNameDeclOrQualifier = |
| 541 | cast<TypedefNameDecl>(Reader.GetDecl(NamedDeclForTagDecl)); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 542 | } else if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) { |
Douglas Gregor | ab1ec82e | 2011-12-16 03:12:41 +0000 | [diff] [blame] | 543 | // 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] | 544 | ID->TypeForDecl = Reader.GetType(DeferredTypeID).getTypePtrOrNull(); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 545 | } else if (auto *FD = dyn_cast<FunctionDecl>(D)) { |
Argyrios Kyrtzidis | 3357516 | 2010-07-02 15:58:43 +0000 | [diff] [blame] | 546 | // FunctionDecl's body was written last after all other Stmts/Exprs. |
Douglas Gregor | 559458c | 2012-10-03 18:34:48 +0000 | [diff] [blame] | 547 | // We only read it if FD doesn't already have a body (e.g., from another |
| 548 | // module). |
Douglas Gregor | e4a838a | 2012-10-03 18:36:10 +0000 | [diff] [blame] | 549 | // FIXME: Can we diagnose ODR violations somehow? |
David Blaikie | ac4345c | 2017-02-12 18:45:31 +0000 | [diff] [blame] | 550 | if (Record.readInt()) |
| 551 | ReadFunctionDefinition(FD); |
Argyrios Kyrtzidis | 3357516 | 2010-07-02 15:58:43 +0000 | [diff] [blame] | 552 | } |
Argyrios Kyrtzidis | 318b0e7 | 2010-07-02 11:55:01 +0000 | [diff] [blame] | 553 | } |
| 554 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 555 | void ASTDeclReader::VisitDecl(Decl *D) { |
Dmitri Gribenko | b353ee1 | 2013-12-19 02:05:20 +0000 | [diff] [blame] | 556 | if (D->isTemplateParameter() || D->isTemplateParameterPack() || |
| 557 | isa<ParmVarDecl>(D)) { |
Douglas Gregor | 250ffb1 | 2011-03-05 01:35:54 +0000 | [diff] [blame] | 558 | // We don't want to deserialize the DeclContext of a template |
Dmitri Gribenko | b353ee1 | 2013-12-19 02:05:20 +0000 | [diff] [blame] | 559 | // parameter or of a parameter of a function template immediately. These |
| 560 | // entities might be used in the formulation of its DeclContext (for |
| 561 | // example, a function parameter can be used in decltype() in trailing |
| 562 | // return type of the function). Use the translation unit DeclContext as a |
| 563 | // placeholder. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 564 | GlobalDeclID SemaDCIDForTemplateParmDecl = ReadDeclID(); |
| 565 | GlobalDeclID LexicalDCIDForTemplateParmDecl = ReadDeclID(); |
Richard Smith | 8aed422 | 2015-12-11 22:41:00 +0000 | [diff] [blame] | 566 | if (!LexicalDCIDForTemplateParmDecl) |
| 567 | LexicalDCIDForTemplateParmDecl = SemaDCIDForTemplateParmDecl; |
Argyrios Kyrtzidis | 83a6e3b | 2013-02-16 00:48:59 +0000 | [diff] [blame] | 568 | Reader.addPendingDeclContextInfo(D, |
| 569 | SemaDCIDForTemplateParmDecl, |
| 570 | LexicalDCIDForTemplateParmDecl); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 571 | D->setDeclContext(Reader.getContext().getTranslationUnitDecl()); |
Douglas Gregor | 250ffb1 | 2011-03-05 01:35:54 +0000 | [diff] [blame] | 572 | } else { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 573 | auto *SemaDC = ReadDeclAs<DeclContext>(); |
| 574 | auto *LexicalDC = ReadDeclAs<DeclContext>(); |
Richard Smith | 8aed422 | 2015-12-11 22:41:00 +0000 | [diff] [blame] | 575 | if (!LexicalDC) |
| 576 | LexicalDC = SemaDC; |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 577 | DeclContext *MergedSemaDC = Reader.MergedDeclContexts.lookup(SemaDC); |
Argyrios Kyrtzidis | 7456ac4 | 2012-02-09 07:46:54 +0000 | [diff] [blame] | 578 | // Avoid calling setLexicalDeclContext() directly because it uses |
| 579 | // Decl::getASTContext() internally which is unsafe during derialization. |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 580 | D->setDeclContextsImpl(MergedSemaDC ? MergedSemaDC : SemaDC, LexicalDC, |
| 581 | Reader.getContext()); |
Douglas Gregor | 250ffb1 | 2011-03-05 01:35:54 +0000 | [diff] [blame] | 582 | } |
Richard Smith | cb34bd3 | 2016-03-27 07:28:06 +0000 | [diff] [blame] | 583 | D->setLocation(ThisDeclLoc); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 584 | D->setInvalidDecl(Record.readInt()); |
| 585 | if (Record.readInt()) { // hasAttrs |
Alexis Hunt | dcfba7b | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 586 | AttrVec Attrs; |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 587 | Record.readAttributes(Attrs); |
Argyrios Kyrtzidis | 7456ac4 | 2012-02-09 07:46:54 +0000 | [diff] [blame] | 588 | // Avoid calling setAttrs() directly because it uses Decl::getASTContext() |
| 589 | // internally which is unsafe during derialization. |
Argyrios Kyrtzidis | 6f40eb7 | 2012-02-09 02:44:08 +0000 | [diff] [blame] | 590 | D->setAttrsImpl(Attrs, Reader.getContext()); |
Alexis Hunt | dcfba7b | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 591 | } |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 592 | D->setImplicit(Record.readInt()); |
| 593 | D->Used = Record.readInt(); |
Vassil Vassilev | 928c825 | 2016-04-28 14:13:28 +0000 | [diff] [blame] | 594 | IsDeclMarkedUsed |= D->Used; |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 595 | D->setReferenced(Record.readInt()); |
| 596 | D->setTopLevelDeclInObjCContainer(Record.readInt()); |
| 597 | D->setAccess((AccessSpecifier)Record.readInt()); |
Douglas Gregor | 98c05b2 | 2011-09-10 00:09:20 +0000 | [diff] [blame] | 598 | D->FromASTFile = true; |
Richard Smith | 90dc525 | 2017-06-23 01:04:34 +0000 | [diff] [blame] | 599 | bool ModulePrivate = Record.readInt(); |
Richard Smith | 4241314 | 2015-05-15 20:05:43 +0000 | [diff] [blame] | 600 | |
Douglas Gregor | cf68c58 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 601 | // Determine whether this declaration is part of a (sub)module. If so, it |
| 602 | // may not yet be visible. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 603 | if (unsigned SubmoduleID = readSubmoduleID()) { |
Douglas Gregor | cfe7dc6 | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 604 | // Store the owning submodule ID in the declaration. |
Richard Smith | 90dc525 | 2017-06-23 01:04:34 +0000 | [diff] [blame] | 605 | D->setModuleOwnershipKind( |
| 606 | ModulePrivate ? Decl::ModuleOwnershipKind::ModulePrivate |
| 607 | : Decl::ModuleOwnershipKind::VisibleWhenImported); |
Douglas Gregor | cfe7dc6 | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 608 | D->setOwningModuleID(SubmoduleID); |
Richard Smith | 4241314 | 2015-05-15 20:05:43 +0000 | [diff] [blame] | 609 | |
Richard Smith | 90dc525 | 2017-06-23 01:04:34 +0000 | [diff] [blame] | 610 | if (ModulePrivate) { |
| 611 | // Module-private declarations are never visible, so there is no work to |
| 612 | // do. |
Richard Smith | 4241314 | 2015-05-15 20:05:43 +0000 | [diff] [blame] | 613 | } else if (Reader.getContext().getLangOpts().ModulesLocalVisibility) { |
| 614 | // If local visibility is being tracked, this declaration will become |
Richard Smith | 90dc525 | 2017-06-23 01:04:34 +0000 | [diff] [blame] | 615 | // hidden and visible as the owning module does. |
Richard Smith | 4241314 | 2015-05-15 20:05:43 +0000 | [diff] [blame] | 616 | } else if (Module *Owner = Reader.getSubmodule(SubmoduleID)) { |
Richard Smith | 90dc525 | 2017-06-23 01:04:34 +0000 | [diff] [blame] | 617 | // Mark the declaration as visible when its owning module becomes visible. |
| 618 | if (Owner->NameVisibility == Module::AllVisible) |
| 619 | D->setVisibleDespiteOwningModule(); |
| 620 | else |
Richard Smith | 4241314 | 2015-05-15 20:05:43 +0000 | [diff] [blame] | 621 | Reader.HiddenNamesMap[Owner].push_back(D); |
Douglas Gregor | cf68c58 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 622 | } |
Richard Smith | d19389a | 2017-07-05 07:47:11 +0000 | [diff] [blame] | 623 | } else if (ModulePrivate) { |
| 624 | D->setModuleOwnershipKind(Decl::ModuleOwnershipKind::ModulePrivate); |
Douglas Gregor | cf68c58 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 625 | } |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 626 | } |
| 627 | |
Nico Weber | 6622029 | 2016-03-02 17:28:48 +0000 | [diff] [blame] | 628 | void ASTDeclReader::VisitPragmaCommentDecl(PragmaCommentDecl *D) { |
| 629 | VisitDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 630 | D->setLocation(ReadSourceLocation()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 631 | D->CommentKind = (PragmaMSCommentKind)Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 632 | std::string Arg = ReadString(); |
Nico Weber | 6622029 | 2016-03-02 17:28:48 +0000 | [diff] [blame] | 633 | memcpy(D->getTrailingObjects<char>(), Arg.data(), Arg.size()); |
| 634 | D->getTrailingObjects<char>()[Arg.size()] = '\0'; |
| 635 | } |
| 636 | |
Nico Weber | cbbaeb1 | 2016-03-02 19:28:54 +0000 | [diff] [blame] | 637 | void ASTDeclReader::VisitPragmaDetectMismatchDecl(PragmaDetectMismatchDecl *D) { |
| 638 | VisitDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 639 | D->setLocation(ReadSourceLocation()); |
| 640 | std::string Name = ReadString(); |
Nico Weber | cbbaeb1 | 2016-03-02 19:28:54 +0000 | [diff] [blame] | 641 | memcpy(D->getTrailingObjects<char>(), Name.data(), Name.size()); |
| 642 | D->getTrailingObjects<char>()[Name.size()] = '\0'; |
| 643 | |
| 644 | D->ValueStart = Name.size() + 1; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 645 | std::string Value = ReadString(); |
Nico Weber | cbbaeb1 | 2016-03-02 19:28:54 +0000 | [diff] [blame] | 646 | memcpy(D->getTrailingObjects<char>() + D->ValueStart, Value.data(), |
| 647 | Value.size()); |
| 648 | D->getTrailingObjects<char>()[D->ValueStart + Value.size()] = '\0'; |
| 649 | } |
| 650 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 651 | void ASTDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) { |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 652 | llvm_unreachable("Translation units are not serialized"); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 653 | } |
| 654 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 655 | void ASTDeclReader::VisitNamedDecl(NamedDecl *ND) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 656 | VisitDecl(ND); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 657 | ND->setDeclName(Record.readDeclarationName()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 658 | AnonymousDeclNumber = Record.readInt(); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 659 | } |
| 660 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 661 | void ASTDeclReader::VisitTypeDecl(TypeDecl *TD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 662 | VisitNamedDecl(TD); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 663 | TD->setLocStart(ReadSourceLocation()); |
Argyrios Kyrtzidis | 318b0e7 | 2010-07-02 11:55:01 +0000 | [diff] [blame] | 664 | // Delay type reading until after we have fully initialized the decl. |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 665 | DeferredTypeID = Record.getGlobalTypeID(Record.readInt()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 666 | } |
| 667 | |
Richard Smith | 43ccec8e | 2014-08-26 03:52:16 +0000 | [diff] [blame] | 668 | ASTDeclReader::RedeclarableResult |
| 669 | ASTDeclReader::VisitTypedefNameDecl(TypedefNameDecl *TD) { |
Douglas Gregor | 9b7b391 | 2012-01-04 16:44:10 +0000 | [diff] [blame] | 670 | RedeclarableResult Redecl = VisitRedeclarable(TD); |
Argyrios Kyrtzidis | 318b0e7 | 2010-07-02 11:55:01 +0000 | [diff] [blame] | 671 | VisitTypeDecl(TD); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 672 | TypeSourceInfo *TInfo = GetTypeSourceInfo(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 673 | if (Record.readInt()) { // isModed |
| 674 | QualType modedT = Record.readType(); |
Enea Zaffanella | a86d88c | 2013-06-20 12:46:19 +0000 | [diff] [blame] | 675 | TD->setModedTypeSourceInfo(TInfo, modedT); |
| 676 | } else |
| 677 | TD->setTypeSourceInfo(TInfo); |
Richard Smith | c0ca4c2 | 2017-01-26 22:39:55 +0000 | [diff] [blame] | 678 | // Read and discard the declaration for which this is a typedef name for |
| 679 | // linkage, if it exists. We cannot rely on our type to pull in this decl, |
| 680 | // because it might have been merged with a type from another module and |
| 681 | // thus might not refer to our version of the declaration. |
| 682 | ReadDecl(); |
Richard Smith | 43ccec8e | 2014-08-26 03:52:16 +0000 | [diff] [blame] | 683 | return Redecl; |
Douglas Gregor | 1f17906 | 2011-12-19 14:40:25 +0000 | [diff] [blame] | 684 | } |
| 685 | |
| 686 | void ASTDeclReader::VisitTypedefDecl(TypedefDecl *TD) { |
Richard Smith | 43ccec8e | 2014-08-26 03:52:16 +0000 | [diff] [blame] | 687 | RedeclarableResult Redecl = VisitTypedefNameDecl(TD); |
| 688 | mergeRedeclarable(TD, Redecl); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 689 | } |
| 690 | |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 691 | void ASTDeclReader::VisitTypeAliasDecl(TypeAliasDecl *TD) { |
Richard Smith | 43ccec8e | 2014-08-26 03:52:16 +0000 | [diff] [blame] | 692 | RedeclarableResult Redecl = VisitTypedefNameDecl(TD); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 693 | if (auto *Template = ReadDeclAs<TypeAliasTemplateDecl>()) |
Richard Smith | 43ccec8e | 2014-08-26 03:52:16 +0000 | [diff] [blame] | 694 | // Merged when we merge the template. |
| 695 | TD->setDescribedAliasTemplate(Template); |
| 696 | else |
| 697 | mergeRedeclarable(TD, Redecl); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 698 | } |
| 699 | |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 700 | ASTDeclReader::RedeclarableResult ASTDeclReader::VisitTagDecl(TagDecl *TD) { |
Douglas Gregor | 2009cee | 2012-01-03 22:46:00 +0000 | [diff] [blame] | 701 | RedeclarableResult Redecl = VisitRedeclarable(TD); |
Douglas Gregor | 3e30010 | 2011-10-26 17:53:41 +0000 | [diff] [blame] | 702 | VisitTypeDecl(TD); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 703 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 704 | TD->IdentifierNamespace = Record.readInt(); |
| 705 | TD->setTagKind((TagDecl::TagKind)Record.readInt()); |
Richard Smith | 2c38164 | 2014-08-27 23:11:59 +0000 | [diff] [blame] | 706 | if (!isa<CXXRecordDecl>(TD)) |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 707 | TD->setCompleteDefinition(Record.readInt()); |
| 708 | TD->setEmbeddedInDeclarator(Record.readInt()); |
| 709 | TD->setFreeStanding(Record.readInt()); |
| 710 | TD->setCompleteDefinitionRequired(Record.readInt()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 711 | TD->setBraceRange(ReadSourceRange()); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 712 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 713 | switch (Record.readInt()) { |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 714 | case 0: |
| 715 | break; |
| 716 | case 1: { // ExtInfo |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 717 | auto *Info = new (Reader.getContext()) TagDecl::ExtInfo(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 718 | ReadQualifierInfo(*Info); |
David Majnemer | 0035052 | 2015-08-31 18:48:39 +0000 | [diff] [blame] | 719 | TD->TypedefNameDeclOrQualifier = Info; |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 720 | break; |
| 721 | } |
| 722 | case 2: // TypedefNameForAnonDecl |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 723 | NamedDeclForTagDecl = ReadDeclID(); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 724 | TypedefNameForLinkage = Record.getIdentifierInfo(); |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 725 | break; |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 726 | default: |
| 727 | llvm_unreachable("unexpected tag info kind"); |
| 728 | } |
Douglas Gregor | 2009cee | 2012-01-03 22:46:00 +0000 | [diff] [blame] | 729 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 730 | if (!isa<CXXRecordDecl>(TD)) |
| 731 | mergeRedeclarable(TD, Redecl); |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 732 | return Redecl; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 733 | } |
| 734 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 735 | void ASTDeclReader::VisitEnumDecl(EnumDecl *ED) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 736 | VisitTagDecl(ED); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 737 | if (TypeSourceInfo *TI = GetTypeSourceInfo()) |
Douglas Gregor | 0bf3140 | 2010-10-08 23:50:27 +0000 | [diff] [blame] | 738 | ED->setIntegerTypeSourceInfo(TI); |
| 739 | else |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 740 | ED->setIntegerType(Record.readType()); |
| 741 | ED->setPromotionType(Record.readType()); |
| 742 | ED->setNumPositiveBits(Record.readInt()); |
| 743 | ED->setNumNegativeBits(Record.readInt()); |
Erich Keane | f92f31c | 2018-08-01 20:48:16 +0000 | [diff] [blame] | 744 | ED->setScoped(Record.readInt()); |
| 745 | ED->setScopedUsingClassTag(Record.readInt()); |
| 746 | ED->setFixed(Record.readInt()); |
Richard Smith | 4b38ded | 2012-03-14 23:13:10 +0000 | [diff] [blame] | 747 | |
Erich Keane | f92f31c | 2018-08-01 20:48:16 +0000 | [diff] [blame] | 748 | ED->setHasODRHash(true); |
Richard Trieu | ab4d730 | 2018-07-25 22:52:05 +0000 | [diff] [blame] | 749 | ED->ODRHash = Record.readInt(); |
| 750 | |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame] | 751 | // If this is a definition subject to the ODR, and we already have a |
| 752 | // definition, merge this one into it. |
Erich Keane | f92f31c | 2018-08-01 20:48:16 +0000 | [diff] [blame] | 753 | if (ED->isCompleteDefinition() && |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame] | 754 | Reader.getContext().getLangOpts().Modules && |
| 755 | Reader.getContext().getLangOpts().CPlusPlus) { |
Richard Smith | 86dfc1e | 2015-06-18 22:07:00 +0000 | [diff] [blame] | 756 | EnumDecl *&OldDef = Reader.EnumDefinitions[ED->getCanonicalDecl()]; |
| 757 | if (!OldDef) { |
| 758 | // This is the first time we've seen an imported definition. Look for a |
| 759 | // local definition before deciding that we are the first definition. |
| 760 | for (auto *D : merged_redecls(ED->getCanonicalDecl())) { |
| 761 | if (!D->isFromASTFile() && D->isCompleteDefinition()) { |
| 762 | OldDef = D; |
| 763 | break; |
| 764 | } |
| 765 | } |
| 766 | } |
| 767 | if (OldDef) { |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame] | 768 | Reader.MergedDeclContexts.insert(std::make_pair(ED, OldDef)); |
Erich Keane | f92f31c | 2018-08-01 20:48:16 +0000 | [diff] [blame] | 769 | ED->setCompleteDefinition(false); |
Richard Smith | 6561f92 | 2016-09-12 21:06:40 +0000 | [diff] [blame] | 770 | Reader.mergeDefinitionVisibility(OldDef, ED); |
Richard Trieu | ab4d730 | 2018-07-25 22:52:05 +0000 | [diff] [blame] | 771 | if (OldDef->getODRHash() != ED->getODRHash()) |
| 772 | Reader.PendingEnumOdrMergeFailures[OldDef].push_back(ED); |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame] | 773 | } else { |
| 774 | OldDef = ED; |
| 775 | } |
| 776 | } |
| 777 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 778 | if (auto *InstED = ReadDeclAs<EnumDecl>()) { |
| 779 | auto TSK = (TemplateSpecializationKind)Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 780 | SourceLocation POI = ReadSourceLocation(); |
Richard Smith | 4b38ded | 2012-03-14 23:13:10 +0000 | [diff] [blame] | 781 | ED->setInstantiationOfMemberEnum(Reader.getContext(), InstED, TSK); |
| 782 | ED->getMemberSpecializationInfo()->setPointOfInstantiation(POI); |
| 783 | } |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 784 | } |
| 785 | |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 786 | ASTDeclReader::RedeclarableResult |
| 787 | ASTDeclReader::VisitRecordDeclImpl(RecordDecl *RD) { |
| 788 | RedeclarableResult Redecl = VisitTagDecl(RD); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 789 | RD->setHasFlexibleArrayMember(Record.readInt()); |
| 790 | RD->setAnonymousStructOrUnion(Record.readInt()); |
| 791 | RD->setHasObjectMember(Record.readInt()); |
| 792 | RD->setHasVolatileMember(Record.readInt()); |
Akira Hatanaka | 34fb264 | 2018-03-13 18:58:25 +0000 | [diff] [blame] | 793 | RD->setNonTrivialToPrimitiveDefaultInitialize(Record.readInt()); |
| 794 | RD->setNonTrivialToPrimitiveCopy(Record.readInt()); |
| 795 | RD->setNonTrivialToPrimitiveDestroy(Record.readInt()); |
Akira Hatanaka | fcbe17c | 2018-03-28 21:13:14 +0000 | [diff] [blame] | 796 | RD->setParamDestroyedInCallee(Record.readInt()); |
Akira Hatanaka | e6313ac | 2018-04-09 22:48:22 +0000 | [diff] [blame] | 797 | RD->setArgPassingRestrictions((RecordDecl::ArgPassingKind)Record.readInt()); |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 798 | return Redecl; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 799 | } |
| 800 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 801 | void ASTDeclReader::VisitValueDecl(ValueDecl *VD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 802 | VisitNamedDecl(VD); |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 803 | // For function declarations, defer reading the type in case the function has |
| 804 | // a deduced return type that references an entity declared within the |
| 805 | // function. |
| 806 | if (isa<FunctionDecl>(VD)) |
| 807 | DeferredTypeID = Record.getGlobalTypeID(Record.readInt()); |
| 808 | else |
| 809 | VD->setType(Record.readType()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 810 | } |
| 811 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 812 | void ASTDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 813 | VisitValueDecl(ECD); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 814 | if (Record.readInt()) |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 815 | ECD->setInitExpr(Record.readExpr()); |
| 816 | ECD->setInitVal(Record.readAPSInt()); |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame] | 817 | mergeMergeable(ECD); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 818 | } |
| 819 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 820 | void ASTDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) { |
Argyrios Kyrtzidis | 560ac97 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 821 | VisitValueDecl(DD); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 822 | DD->setInnerLocStart(ReadSourceLocation()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 823 | if (Record.readInt()) { // hasExtInfo |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 824 | auto *Info = new (Reader.getContext()) DeclaratorDecl::ExtInfo(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 825 | ReadQualifierInfo(*Info); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 826 | DD->DeclInfo = Info; |
Jonathan D. Turner | 205c7d5 | 2011-06-03 23:11:16 +0000 | [diff] [blame] | 827 | } |
Richard Smith | c23d734 | 2018-06-29 20:46:25 +0000 | [diff] [blame] | 828 | QualType TSIType = Record.readType(); |
| 829 | DD->setTypeSourceInfo( |
| 830 | TSIType.isNull() ? nullptr |
| 831 | : Reader.getContext().CreateTypeSourceInfo(TSIType)); |
Argyrios Kyrtzidis | 560ac97 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 832 | } |
| 833 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 834 | void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) { |
Douglas Gregor | b258569 | 2012-01-04 17:13:46 +0000 | [diff] [blame] | 835 | RedeclarableResult Redecl = VisitRedeclarable(FD); |
Douglas Gregor | 3e30010 | 2011-10-26 17:53:41 +0000 | [diff] [blame] | 836 | VisitDeclaratorDecl(FD); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 837 | |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 838 | // Attach a type to this function. Use the real type if possible, but fall |
| 839 | // back to the type as written if it involves a deduced return type. |
| 840 | if (FD->getTypeSourceInfo() && |
| 841 | FD->getTypeSourceInfo()->getType()->castAs<FunctionType>() |
| 842 | ->getReturnType()->getContainedAutoType()) { |
| 843 | // We'll set up the real type in Visit, once we've finished loading the |
| 844 | // function. |
| 845 | FD->setType(FD->getTypeSourceInfo()->getType()); |
Richard Smith | a62d198 | 2018-08-03 01:00:01 +0000 | [diff] [blame] | 846 | Reader.PendingFunctionTypes.push_back({FD, DeferredTypeID}); |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 847 | } else { |
| 848 | FD->setType(Reader.GetType(DeferredTypeID)); |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 849 | } |
Richard Smith | a62d198 | 2018-08-03 01:00:01 +0000 | [diff] [blame] | 850 | DeferredTypeID = 0; |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 851 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 852 | ReadDeclarationNameLoc(FD->DNLoc, FD->getDeclName()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 853 | FD->IdentifierNamespace = Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 854 | |
Douglas Gregor | b258569 | 2012-01-04 17:13:46 +0000 | [diff] [blame] | 855 | // FunctionDecl's body is handled last at ASTDeclReader::Visit, |
| 856 | // after everything else is read. |
Rafael Espindola | 6ae7e50 | 2013-04-03 19:27:57 +0000 | [diff] [blame] | 857 | |
Erich Keane | 9c66506 | 2018-08-01 21:02:40 +0000 | [diff] [blame] | 858 | FD->setStorageClass(static_cast<StorageClass>(Record.readInt())); |
| 859 | FD->setInlineSpecified(Record.readInt()); |
| 860 | FD->setImplicitlyInline(Record.readInt()); |
| 861 | FD->setExplicitSpecified(Record.readInt()); |
| 862 | FD->setVirtualAsWritten(Record.readInt()); |
| 863 | FD->setPure(Record.readInt()); |
| 864 | FD->setHasInheritedPrototype(Record.readInt()); |
| 865 | FD->setHasWrittenPrototype(Record.readInt()); |
| 866 | FD->setDeletedAsWritten(Record.readInt()); |
| 867 | FD->setTrivial(Record.readInt()); |
| 868 | FD->setTrivialForCall(Record.readInt()); |
| 869 | FD->setDefaulted(Record.readInt()); |
| 870 | FD->setExplicitlyDefaulted(Record.readInt()); |
| 871 | FD->setHasImplicitReturnZero(Record.readInt()); |
| 872 | FD->setConstexpr(Record.readInt()); |
| 873 | FD->setUsesSEHTry(Record.readInt()); |
| 874 | FD->setHasSkippedBody(Record.readInt()); |
| 875 | FD->setIsMultiVersion(Record.readInt()); |
| 876 | FD->setLateTemplateParsed(Record.readInt()); |
| 877 | |
| 878 | FD->setCachedLinkage(static_cast<Linkage>(Record.readInt())); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 879 | FD->EndRangeLoc = ReadSourceLocation(); |
Douglas Gregor | b258569 | 2012-01-04 17:13:46 +0000 | [diff] [blame] | 880 | |
Richard Trieu | e6caa26 | 2017-12-23 00:41:01 +0000 | [diff] [blame] | 881 | FD->ODRHash = Record.readInt(); |
Erich Keane | 9c66506 | 2018-08-01 21:02:40 +0000 | [diff] [blame] | 882 | FD->setHasODRHash(true); |
Richard Trieu | e6caa26 | 2017-12-23 00:41:01 +0000 | [diff] [blame] | 883 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 884 | switch ((FunctionDecl::TemplatedKind)Record.readInt()) { |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 885 | case FunctionDecl::TK_NonTemplate: |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 886 | mergeRedeclarable(FD, Redecl); |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 887 | break; |
| 888 | case FunctionDecl::TK_FunctionTemplate: |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 889 | // Merged when we merge the template. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 890 | FD->setDescribedFunctionTemplate(ReadDeclAs<FunctionTemplateDecl>()); |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 891 | break; |
| 892 | case FunctionDecl::TK_MemberSpecialization: { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 893 | auto *InstFD = ReadDeclAs<FunctionDecl>(); |
| 894 | auto TSK = (TemplateSpecializationKind)Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 895 | SourceLocation POI = ReadSourceLocation(); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 896 | FD->setInstantiationOfMemberFunction(Reader.getContext(), InstFD, TSK); |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 897 | FD->getMemberSpecializationInfo()->setPointOfInstantiation(POI); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 898 | mergeRedeclarable(FD, Redecl); |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 899 | break; |
| 900 | } |
| 901 | case FunctionDecl::TK_FunctionTemplateSpecialization: { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 902 | auto *Template = ReadDeclAs<FunctionTemplateDecl>(); |
| 903 | auto TSK = (TemplateSpecializationKind)Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 904 | |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 905 | // Template arguments. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 906 | SmallVector<TemplateArgument, 8> TemplArgs; |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 907 | Record.readTemplateArgumentList(TemplArgs, /*Canonicalize*/ true); |
Richard Smith | 2bb3c34 | 2015-08-09 01:05:31 +0000 | [diff] [blame] | 908 | |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 909 | // Template args as written. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 910 | SmallVector<TemplateArgumentLoc, 8> TemplArgLocs; |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 911 | SourceLocation LAngleLoc, RAngleLoc; |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 912 | bool HasTemplateArgumentsAsWritten = Record.readInt(); |
Argyrios Kyrtzidis | e9a2443 | 2011-09-22 20:07:09 +0000 | [diff] [blame] | 913 | if (HasTemplateArgumentsAsWritten) { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 914 | unsigned NumTemplateArgLocs = Record.readInt(); |
Argyrios Kyrtzidis | 373a83a | 2010-07-02 11:55:40 +0000 | [diff] [blame] | 915 | TemplArgLocs.reserve(NumTemplateArgLocs); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 916 | for (unsigned i = 0; i != NumTemplateArgLocs; ++i) |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 917 | TemplArgLocs.push_back(Record.readTemplateArgumentLoc()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 918 | |
| 919 | LAngleLoc = ReadSourceLocation(); |
| 920 | RAngleLoc = ReadSourceLocation(); |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 921 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 922 | |
| 923 | SourceLocation POI = ReadSourceLocation(); |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 924 | |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 925 | ASTContext &C = Reader.getContext(); |
Argyrios Kyrtzidis | e262a95 | 2010-09-09 11:28:23 +0000 | [diff] [blame] | 926 | TemplateArgumentList *TemplArgList |
David Majnemer | 8b62269 | 2016-07-03 21:17:51 +0000 | [diff] [blame] | 927 | = TemplateArgumentList::CreateCopy(C, TemplArgs); |
Argyrios Kyrtzidis | e9a2443 | 2011-09-22 20:07:09 +0000 | [diff] [blame] | 928 | TemplateArgumentListInfo TemplArgsInfo(LAngleLoc, RAngleLoc); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 929 | for (unsigned i = 0, e = TemplArgLocs.size(); i != e; ++i) |
Argyrios Kyrtzidis | e9a2443 | 2011-09-22 20:07:09 +0000 | [diff] [blame] | 930 | TemplArgsInfo.addArgument(TemplArgLocs[i]); |
Argyrios Kyrtzidis | e262a95 | 2010-09-09 11:28:23 +0000 | [diff] [blame] | 931 | FunctionTemplateSpecializationInfo *FTInfo |
| 932 | = FunctionTemplateSpecializationInfo::Create(C, FD, Template, TSK, |
| 933 | TemplArgList, |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 934 | HasTemplateArgumentsAsWritten ? &TemplArgsInfo |
| 935 | : nullptr, |
Argyrios Kyrtzidis | e9a2443 | 2011-09-22 20:07:09 +0000 | [diff] [blame] | 936 | POI); |
Argyrios Kyrtzidis | e262a95 | 2010-09-09 11:28:23 +0000 | [diff] [blame] | 937 | FD->TemplateOrSpecialization = FTInfo; |
Argyrios Kyrtzidis | f4bc0d8 | 2010-09-08 19:31:22 +0000 | [diff] [blame] | 938 | |
Argyrios Kyrtzidis | e262a95 | 2010-09-09 11:28:23 +0000 | [diff] [blame] | 939 | if (FD->isCanonicalDecl()) { // if canonical add to template's set. |
Argyrios Kyrtzidis | f24d569 | 2010-09-13 11:45:48 +0000 | [diff] [blame] | 940 | // The template that contains the specializations set. It's not safe to |
| 941 | // use getCanonicalDecl on Template since it may still be initializing. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 942 | auto *CanonTemplate = ReadDeclAs<FunctionTemplateDecl>(); |
Argyrios Kyrtzidis | e262a95 | 2010-09-09 11:28:23 +0000 | [diff] [blame] | 943 | // Get the InsertPos by FindNodeOrInsertPos() instead of calling |
| 944 | // InsertNode(FTInfo) directly to avoid the getASTContext() call in |
| 945 | // FunctionTemplateSpecializationInfo's Profile(). |
| 946 | // We avoid getASTContext because a decl in the parent hierarchy may |
| 947 | // be initializing. |
Argyrios Kyrtzidis | f4bc0d8 | 2010-09-08 19:31:22 +0000 | [diff] [blame] | 948 | llvm::FoldingSetNodeID ID; |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 949 | FunctionTemplateSpecializationInfo::Profile(ID, TemplArgs, C); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 950 | void *InsertPos = nullptr; |
Richard Smith | feb3e1a | 2013-06-28 04:37:53 +0000 | [diff] [blame] | 951 | FunctionTemplateDecl::Common *CommonPtr = CanonTemplate->getCommonPtr(); |
Richard Smith | da6c234 | 2015-07-01 23:19:58 +0000 | [diff] [blame] | 952 | FunctionTemplateSpecializationInfo *ExistingInfo = |
| 953 | CommonPtr->Specializations.FindNodeOrInsertPos(ID, InsertPos); |
Argyrios Kyrtzidis | e60e408 | 2012-09-10 23:28:22 +0000 | [diff] [blame] | 954 | if (InsertPos) |
Richard Smith | feb3e1a | 2013-06-28 04:37:53 +0000 | [diff] [blame] | 955 | CommonPtr->Specializations.InsertNode(FTInfo, InsertPos); |
| 956 | else { |
| 957 | assert(Reader.getContext().getLangOpts().Modules && |
| 958 | "already deserialized this template specialization"); |
Richard Smith | da6c234 | 2015-07-01 23:19:58 +0000 | [diff] [blame] | 959 | mergeRedeclarable(FD, ExistingInfo->Function, Redecl); |
Richard Smith | feb3e1a | 2013-06-28 04:37:53 +0000 | [diff] [blame] | 960 | } |
Argyrios Kyrtzidis | f4bc0d8 | 2010-09-08 19:31:22 +0000 | [diff] [blame] | 961 | } |
Argyrios Kyrtzidis | 0b0369a | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 962 | break; |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 963 | } |
| 964 | case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { |
| 965 | // Templates. |
| 966 | UnresolvedSet<8> TemplDecls; |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 967 | unsigned NumTemplates = Record.readInt(); |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 968 | while (NumTemplates--) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 969 | TemplDecls.addDecl(ReadDeclAs<NamedDecl>()); |
| 970 | |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 971 | // Templates args. |
| 972 | TemplateArgumentListInfo TemplArgs; |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 973 | unsigned NumArgs = Record.readInt(); |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 974 | while (NumArgs--) |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 975 | TemplArgs.addArgument(Record.readTemplateArgumentLoc()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 976 | TemplArgs.setLAngleLoc(ReadSourceLocation()); |
| 977 | TemplArgs.setRAngleLoc(ReadSourceLocation()); |
| 978 | |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 979 | FD->setDependentTemplateSpecialization(Reader.getContext(), |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 980 | TemplDecls, TemplArgs); |
Richard Smith | da6c234 | 2015-07-01 23:19:58 +0000 | [diff] [blame] | 981 | // These are not merged; we don't need to merge redeclarations of dependent |
| 982 | // template friends. |
Argyrios Kyrtzidis | 0b0369a | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 983 | break; |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 984 | } |
| 985 | } |
Argyrios Kyrtzidis | 373a83a | 2010-07-02 11:55:40 +0000 | [diff] [blame] | 986 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 987 | // Read in the parameters. |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 988 | unsigned NumParams = Record.readInt(); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 989 | SmallVector<ParmVarDecl *, 16> Params; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 990 | Params.reserve(NumParams); |
| 991 | for (unsigned I = 0; I != NumParams; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 992 | Params.push_back(ReadDeclAs<ParmVarDecl>()); |
David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 993 | FD->setParams(Reader.getContext(), Params); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 994 | } |
| 995 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 996 | void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 997 | VisitNamedDecl(MD); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 998 | if (Record.readInt()) { |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 999 | // Load the body on-demand. Most clients won't care, because method |
| 1000 | // definitions rarely show up in headers. |
| 1001 | Reader.PendingBodies[MD] = GetCurrentCursorOffset(); |
| 1002 | HasPendingBody = true; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1003 | MD->setSelfDecl(ReadDeclAs<ImplicitParamDecl>()); |
| 1004 | MD->setCmdDecl(ReadDeclAs<ImplicitParamDecl>()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1005 | } |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1006 | MD->setInstanceMethod(Record.readInt()); |
| 1007 | MD->setVariadic(Record.readInt()); |
| 1008 | MD->setPropertyAccessor(Record.readInt()); |
| 1009 | MD->setDefined(Record.readInt()); |
Erich Keane | 9b18eca | 2018-08-01 21:31:08 +0000 | [diff] [blame] | 1010 | MD->setOverriding(Record.readInt()); |
| 1011 | MD->setHasSkippedBody(Record.readInt()); |
Argyrios Kyrtzidis | db21596 | 2011-10-14 17:41:52 +0000 | [diff] [blame] | 1012 | |
Erich Keane | 9b18eca | 2018-08-01 21:31:08 +0000 | [diff] [blame] | 1013 | MD->setIsRedeclaration(Record.readInt()); |
| 1014 | MD->setHasRedeclaration(Record.readInt()); |
| 1015 | if (MD->hasRedeclaration()) |
Argyrios Kyrtzidis | db21596 | 2011-10-14 17:41:52 +0000 | [diff] [blame] | 1016 | Reader.getContext().setObjCMethodRedeclaration(MD, |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1017 | ReadDeclAs<ObjCMethodDecl>()); |
Argyrios Kyrtzidis | db21596 | 2011-10-14 17:41:52 +0000 | [diff] [blame] | 1018 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1019 | MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record.readInt()); |
| 1020 | MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record.readInt()); |
Erich Keane | 9b18eca | 2018-08-01 21:31:08 +0000 | [diff] [blame] | 1021 | MD->setRelatedResultType(Record.readInt()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1022 | MD->setReturnType(Record.readType()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1023 | MD->setReturnTypeSourceInfo(GetTypeSourceInfo()); |
| 1024 | MD->DeclEndLoc = ReadSourceLocation(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1025 | unsigned NumParams = Record.readInt(); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1026 | SmallVector<ParmVarDecl *, 16> Params; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1027 | Params.reserve(NumParams); |
| 1028 | for (unsigned I = 0; I != NumParams; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1029 | Params.push_back(ReadDeclAs<ParmVarDecl>()); |
Argyrios Kyrtzidis | b8c3aaf | 2011-10-03 06:37:04 +0000 | [diff] [blame] | 1030 | |
Erich Keane | 9b18eca | 2018-08-01 21:31:08 +0000 | [diff] [blame] | 1031 | MD->setSelLocsKind((SelectorLocationsKind)Record.readInt()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1032 | unsigned NumStoredSelLocs = Record.readInt(); |
Argyrios Kyrtzidis | b8c3aaf | 2011-10-03 06:37:04 +0000 | [diff] [blame] | 1033 | SmallVector<SourceLocation, 16> SelLocs; |
| 1034 | SelLocs.reserve(NumStoredSelLocs); |
| 1035 | for (unsigned i = 0; i != NumStoredSelLocs; ++i) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1036 | SelLocs.push_back(ReadSourceLocation()); |
Argyrios Kyrtzidis | b8c3aaf | 2011-10-03 06:37:04 +0000 | [diff] [blame] | 1037 | |
| 1038 | MD->setParamsAndSelLocs(Reader.getContext(), Params, SelLocs); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1039 | } |
| 1040 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 1041 | void ASTDeclReader::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { |
David Blaikie | 27a1bc0 | 2015-09-28 23:48:49 +0000 | [diff] [blame] | 1042 | VisitTypedefNameDecl(D); |
Richard Smith | 9b88a4c | 2015-07-27 05:40:23 +0000 | [diff] [blame] | 1043 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1044 | D->Variance = Record.readInt(); |
| 1045 | D->Index = Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1046 | D->VarianceLoc = ReadSourceLocation(); |
| 1047 | D->ColonLoc = ReadSourceLocation(); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 1048 | } |
| 1049 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1050 | void ASTDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1051 | VisitNamedDecl(CD); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1052 | CD->setAtStartLoc(ReadSourceLocation()); |
| 1053 | CD->setAtEndRange(ReadSourceRange()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1054 | } |
| 1055 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 1056 | ObjCTypeParamList *ASTDeclReader::ReadObjCTypeParamList() { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1057 | unsigned numParams = Record.readInt(); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 1058 | if (numParams == 0) |
| 1059 | return nullptr; |
| 1060 | |
| 1061 | SmallVector<ObjCTypeParamDecl *, 4> typeParams; |
| 1062 | typeParams.reserve(numParams); |
| 1063 | for (unsigned i = 0; i != numParams; ++i) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1064 | auto *typeParam = ReadDeclAs<ObjCTypeParamDecl>(); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 1065 | if (!typeParam) |
| 1066 | return nullptr; |
| 1067 | |
| 1068 | typeParams.push_back(typeParam); |
| 1069 | } |
| 1070 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1071 | SourceLocation lAngleLoc = ReadSourceLocation(); |
| 1072 | SourceLocation rAngleLoc = ReadSourceLocation(); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 1073 | |
| 1074 | return ObjCTypeParamList::create(Reader.getContext(), lAngleLoc, |
| 1075 | typeParams, rAngleLoc); |
| 1076 | } |
| 1077 | |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 1078 | void ASTDeclReader::ReadObjCDefinitionData( |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1079 | struct ObjCInterfaceDecl::DefinitionData &Data) { |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 1080 | // Read the superclass. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1081 | Data.SuperClassTInfo = GetTypeSourceInfo(); |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 1082 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1083 | Data.EndLoc = ReadSourceLocation(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1084 | Data.HasDesignatedInitializers = Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1085 | |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 1086 | // Read the directly referenced protocols and their SourceLocations. |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1087 | unsigned NumProtocols = Record.readInt(); |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 1088 | SmallVector<ObjCProtocolDecl *, 16> Protocols; |
| 1089 | Protocols.reserve(NumProtocols); |
| 1090 | for (unsigned I = 0; I != NumProtocols; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1091 | Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>()); |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 1092 | SmallVector<SourceLocation, 16> ProtoLocs; |
| 1093 | ProtoLocs.reserve(NumProtocols); |
| 1094 | for (unsigned I = 0; I != NumProtocols; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1095 | ProtoLocs.push_back(ReadSourceLocation()); |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 1096 | Data.ReferencedProtocols.set(Protocols.data(), NumProtocols, ProtoLocs.data(), |
| 1097 | Reader.getContext()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1098 | |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 1099 | // Read the transitive closure of protocols referenced by this class. |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1100 | NumProtocols = Record.readInt(); |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 1101 | Protocols.clear(); |
| 1102 | Protocols.reserve(NumProtocols); |
| 1103 | for (unsigned I = 0; I != NumProtocols; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1104 | Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>()); |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 1105 | Data.AllReferencedProtocols.set(Protocols.data(), NumProtocols, |
| 1106 | Reader.getContext()); |
| 1107 | } |
| 1108 | |
| 1109 | void ASTDeclReader::MergeDefinitionData(ObjCInterfaceDecl *D, |
| 1110 | struct ObjCInterfaceDecl::DefinitionData &&NewDD) { |
| 1111 | // FIXME: odr checking? |
| 1112 | } |
| 1113 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1114 | void ASTDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) { |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 1115 | RedeclarableResult Redecl = VisitRedeclarable(ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1116 | VisitObjCContainerDecl(ID); |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 1117 | DeferredTypeID = Record.getGlobalTypeID(Record.readInt()); |
Douglas Gregor | 2c46b5b | 2012-01-03 17:27:13 +0000 | [diff] [blame] | 1118 | mergeRedeclarable(ID, Redecl); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 1119 | |
| 1120 | ID->TypeParamList = ReadObjCTypeParamList(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1121 | if (Record.readInt()) { |
Douglas Gregor | c0ac7d6 | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 1122 | // Read the definition. |
| 1123 | ID->allocateDefinitionData(); |
Douglas Gregor | c0ac7d6 | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 1124 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1125 | ReadObjCDefinitionData(ID->data()); |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 1126 | ObjCInterfaceDecl *Canon = ID->getCanonicalDecl(); |
| 1127 | if (Canon->Data.getPointer()) { |
| 1128 | // If we already have a definition, keep the definition invariant and |
| 1129 | // merge the data. |
| 1130 | MergeDefinitionData(Canon, std::move(ID->data())); |
| 1131 | ID->Data = Canon->Data; |
| 1132 | } else { |
| 1133 | // Set the definition data of the canonical declaration, so other |
| 1134 | // redeclarations will see it. |
| 1135 | ID->getCanonicalDecl()->Data = ID->Data; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1136 | |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 1137 | // We will rebuild this list lazily. |
| 1138 | ID->setIvarList(nullptr); |
| 1139 | } |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 1140 | |
Douglas Gregor | c1a61fe | 2011-12-19 20:51:16 +0000 | [diff] [blame] | 1141 | // Note that we have deserialized a definition. |
| 1142 | Reader.PendingDefinitions.insert(ID); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1143 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 1144 | // Note that we've loaded this Objective-C class. |
| 1145 | Reader.ObjCClassesLoaded.push_back(ID); |
Douglas Gregor | c03c52e | 2012-01-15 18:08:05 +0000 | [diff] [blame] | 1146 | } else { |
| 1147 | ID->Data = ID->getCanonicalDecl()->Data; |
Douglas Gregor | c0ac7d6 | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 1148 | } |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1149 | } |
| 1150 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1151 | void ASTDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1152 | VisitFieldDecl(IVD); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1153 | IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record.readInt()); |
Fariborz Jahanian | a50b3a2 | 2010-08-20 21:21:08 +0000 | [diff] [blame] | 1154 | // This field will be built lazily. |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 1155 | IVD->setNextIvar(nullptr); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1156 | bool synth = Record.readInt(); |
Fariborz Jahanian | aea8e1e | 2010-07-17 18:35:47 +0000 | [diff] [blame] | 1157 | IVD->setSynthesize(synth); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1158 | } |
| 1159 | |
Graydon Hoare | e0a6835 | 2017-06-28 18:36:27 +0000 | [diff] [blame] | 1160 | void ASTDeclReader::ReadObjCDefinitionData( |
| 1161 | struct ObjCProtocolDecl::DefinitionData &Data) { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1162 | unsigned NumProtoRefs = Record.readInt(); |
Douglas Gregor | e6e48b1 | 2012-01-01 19:29:29 +0000 | [diff] [blame] | 1163 | SmallVector<ObjCProtocolDecl *, 16> ProtoRefs; |
| 1164 | ProtoRefs.reserve(NumProtoRefs); |
| 1165 | for (unsigned I = 0; I != NumProtoRefs; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1166 | ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>()); |
Douglas Gregor | e6e48b1 | 2012-01-01 19:29:29 +0000 | [diff] [blame] | 1167 | SmallVector<SourceLocation, 16> ProtoLocs; |
| 1168 | ProtoLocs.reserve(NumProtoRefs); |
| 1169 | for (unsigned I = 0; I != NumProtoRefs; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1170 | ProtoLocs.push_back(ReadSourceLocation()); |
Graydon Hoare | e0a6835 | 2017-06-28 18:36:27 +0000 | [diff] [blame] | 1171 | Data.ReferencedProtocols.set(ProtoRefs.data(), NumProtoRefs, |
| 1172 | ProtoLocs.data(), Reader.getContext()); |
| 1173 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1174 | |
Graydon Hoare | e0a6835 | 2017-06-28 18:36:27 +0000 | [diff] [blame] | 1175 | void ASTDeclReader::MergeDefinitionData(ObjCProtocolDecl *D, |
| 1176 | struct ObjCProtocolDecl::DefinitionData &&NewDD) { |
| 1177 | // FIXME: odr checking? |
| 1178 | } |
| 1179 | |
| 1180 | void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) { |
| 1181 | RedeclarableResult Redecl = VisitRedeclarable(PD); |
| 1182 | VisitObjCContainerDecl(PD); |
| 1183 | mergeRedeclarable(PD, Redecl); |
| 1184 | |
| 1185 | if (Record.readInt()) { |
| 1186 | // Read the definition. |
| 1187 | PD->allocateDefinitionData(); |
| 1188 | |
| 1189 | ReadObjCDefinitionData(PD->data()); |
| 1190 | |
| 1191 | ObjCProtocolDecl *Canon = PD->getCanonicalDecl(); |
| 1192 | if (Canon->Data.getPointer()) { |
| 1193 | // If we already have a definition, keep the definition invariant and |
| 1194 | // merge the data. |
| 1195 | MergeDefinitionData(Canon, std::move(PD->data())); |
| 1196 | PD->Data = Canon->Data; |
| 1197 | } else { |
| 1198 | // Set the definition data of the canonical declaration, so other |
| 1199 | // redeclarations will see it. |
| 1200 | PD->getCanonicalDecl()->Data = PD->Data; |
| 1201 | } |
Douglas Gregor | a715bff | 2012-01-01 19:51:50 +0000 | [diff] [blame] | 1202 | // Note that we have deserialized a definition. |
| 1203 | Reader.PendingDefinitions.insert(PD); |
Douglas Gregor | c03c52e | 2012-01-15 18:08:05 +0000 | [diff] [blame] | 1204 | } else { |
| 1205 | PD->Data = PD->getCanonicalDecl()->Data; |
Douglas Gregor | e6e48b1 | 2012-01-01 19:29:29 +0000 | [diff] [blame] | 1206 | } |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1207 | } |
| 1208 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1209 | void ASTDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1210 | VisitFieldDecl(FD); |
| 1211 | } |
| 1212 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1213 | void ASTDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1214 | VisitObjCContainerDecl(CD); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1215 | CD->setCategoryNameLoc(ReadSourceLocation()); |
| 1216 | CD->setIvarLBraceLoc(ReadSourceLocation()); |
| 1217 | CD->setIvarRBraceLoc(ReadSourceLocation()); |
| 1218 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 1219 | // Note that this category has been deserialized. We do this before |
| 1220 | // deserializing the interface declaration, so that it will consider this |
| 1221 | /// category. |
| 1222 | Reader.CategoriesDeserialized.insert(CD); |
| 1223 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1224 | CD->ClassInterface = ReadDeclAs<ObjCInterfaceDecl>(); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 1225 | CD->TypeParamList = ReadObjCTypeParamList(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1226 | unsigned NumProtoRefs = Record.readInt(); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1227 | SmallVector<ObjCProtocolDecl *, 16> ProtoRefs; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1228 | ProtoRefs.reserve(NumProtoRefs); |
| 1229 | for (unsigned I = 0; I != NumProtoRefs; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1230 | ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>()); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1231 | SmallVector<SourceLocation, 16> ProtoLocs; |
Douglas Gregor | 002b671 | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 1232 | ProtoLocs.reserve(NumProtoRefs); |
| 1233 | for (unsigned I = 0; I != NumProtoRefs; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1234 | ProtoLocs.push_back(ReadSourceLocation()); |
Douglas Gregor | 002b671 | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 1235 | CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(), |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1236 | Reader.getContext()); |
Bruno Cardoso Lopes | fbff2fa | 2018-04-27 18:01:23 +0000 | [diff] [blame] | 1237 | |
| 1238 | // Protocols in the class extension belong to the class. |
| 1239 | if (NumProtoRefs > 0 && CD->ClassInterface && CD->IsClassExtension()) |
| 1240 | CD->ClassInterface->mergeClassExtensionProtocolList( |
| 1241 | (ObjCProtocolDecl *const *)ProtoRefs.data(), NumProtoRefs, |
| 1242 | Reader.getContext()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1243 | } |
| 1244 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1245 | void ASTDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1246 | VisitNamedDecl(CAD); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1247 | CAD->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1248 | } |
| 1249 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1250 | void ASTDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1251 | VisitNamedDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1252 | D->setAtLoc(ReadSourceLocation()); |
| 1253 | D->setLParenLoc(ReadSourceLocation()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1254 | QualType T = Record.readType(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1255 | TypeSourceInfo *TSI = GetTypeSourceInfo(); |
Douglas Gregor | 813a066 | 2015-06-19 18:14:38 +0000 | [diff] [blame] | 1256 | D->setType(T, TSI); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1257 | D->setPropertyAttributes( |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1258 | (ObjCPropertyDecl::PropertyAttributeKind)Record.readInt()); |
Fariborz Jahanian | 3bf0ded | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 1259 | D->setPropertyAttributesAsWritten( |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1260 | (ObjCPropertyDecl::PropertyAttributeKind)Record.readInt()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1261 | D->setPropertyImplementation( |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1262 | (ObjCPropertyDecl::PropertyControl)Record.readInt()); |
Argyrios Kyrtzidis | c6c4ec8 | 2017-03-17 00:49:42 +0000 | [diff] [blame] | 1263 | DeclarationName GetterName = Record.readDeclarationName(); |
| 1264 | SourceLocation GetterLoc = ReadSourceLocation(); |
| 1265 | D->setGetterName(GetterName.getObjCSelector(), GetterLoc); |
| 1266 | DeclarationName SetterName = Record.readDeclarationName(); |
| 1267 | SourceLocation SetterLoc = ReadSourceLocation(); |
| 1268 | D->setSetterName(SetterName.getObjCSelector(), SetterLoc); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1269 | D->setGetterMethodDecl(ReadDeclAs<ObjCMethodDecl>()); |
| 1270 | D->setSetterMethodDecl(ReadDeclAs<ObjCMethodDecl>()); |
| 1271 | D->setPropertyIvarDecl(ReadDeclAs<ObjCIvarDecl>()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1272 | } |
| 1273 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1274 | void ASTDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) { |
Argyrios Kyrtzidis | 067c407 | 2009-07-27 19:04:32 +0000 | [diff] [blame] | 1275 | VisitObjCContainerDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1276 | D->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1277 | } |
| 1278 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1279 | void ASTDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1280 | VisitObjCImplDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1281 | D->CategoryNameLoc = ReadSourceLocation(); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1282 | } |
| 1283 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1284 | void ASTDeclReader::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1285 | VisitObjCImplDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1286 | D->setSuperClass(ReadDeclAs<ObjCInterfaceDecl>()); |
| 1287 | D->SuperLoc = ReadSourceLocation(); |
| 1288 | D->setIvarLBraceLoc(ReadSourceLocation()); |
| 1289 | D->setIvarRBraceLoc(ReadSourceLocation()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1290 | D->setHasNonZeroConstructors(Record.readInt()); |
| 1291 | D->setHasDestructors(Record.readInt()); |
| 1292 | D->NumIvarInitializers = Record.readInt(); |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 1293 | if (D->NumIvarInitializers) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1294 | D->IvarInitializers = ReadGlobalOffset(); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1295 | } |
| 1296 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1297 | void ASTDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1298 | VisitDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1299 | D->setAtLoc(ReadSourceLocation()); |
| 1300 | D->setPropertyDecl(ReadDeclAs<ObjCPropertyDecl>()); |
| 1301 | D->PropertyIvarDecl = ReadDeclAs<ObjCIvarDecl>(); |
| 1302 | D->IvarLoc = ReadSourceLocation(); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1303 | D->setGetterCXXConstructor(Record.readExpr()); |
| 1304 | D->setSetterCXXAssignment(Record.readExpr()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1305 | } |
| 1306 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1307 | void ASTDeclReader::VisitFieldDecl(FieldDecl *FD) { |
Argyrios Kyrtzidis | 560ac97 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 1308 | VisitDeclaratorDecl(FD); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1309 | FD->Mutable = Record.readInt(); |
Richard Smith | 6b8e3c0 | 2017-08-28 00:28:14 +0000 | [diff] [blame] | 1310 | |
| 1311 | if (auto ISK = static_cast<FieldDecl::InitStorageKind>(Record.readInt())) { |
| 1312 | FD->InitStorage.setInt(ISK); |
| 1313 | FD->InitStorage.setPointer(ISK == FieldDecl::ISK_CapturedVLAType |
| 1314 | ? Record.readType().getAsOpaquePtr() |
| 1315 | : Record.readExpr()); |
Richard Smith | 2b01318 | 2012-06-10 03:12:00 +0000 | [diff] [blame] | 1316 | } |
Richard Smith | 6b8e3c0 | 2017-08-28 00:28:14 +0000 | [diff] [blame] | 1317 | |
| 1318 | if (auto *BW = Record.readExpr()) |
| 1319 | FD->setBitWidth(BW); |
| 1320 | |
Argyrios Kyrtzidis | 6685e8a | 2010-07-04 21:44:35 +0000 | [diff] [blame] | 1321 | if (!FD->getDeclName()) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1322 | if (auto *Tmpl = ReadDeclAs<FieldDecl>()) |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1323 | Reader.getContext().setInstantiatedFromUnnamedFieldDecl(FD, Tmpl); |
Argyrios Kyrtzidis | 6685e8a | 2010-07-04 21:44:35 +0000 | [diff] [blame] | 1324 | } |
Richard Smith | 0b87e07 | 2013-10-07 08:02:11 +0000 | [diff] [blame] | 1325 | mergeMergeable(FD); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1326 | } |
| 1327 | |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 1328 | void ASTDeclReader::VisitMSPropertyDecl(MSPropertyDecl *PD) { |
| 1329 | VisitDeclaratorDecl(PD); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1330 | PD->GetterId = Record.getIdentifierInfo(); |
| 1331 | PD->SetterId = Record.getIdentifierInfo(); |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 1332 | } |
| 1333 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 1334 | void ASTDeclReader::VisitIndirectFieldDecl(IndirectFieldDecl *FD) { |
| 1335 | VisitValueDecl(FD); |
| 1336 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1337 | FD->ChainingSize = Record.readInt(); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 1338 | assert(FD->ChainingSize >= 2 && "Anonymous chaining must be >= 2"); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1339 | FD->Chaining = new (Reader.getContext())NamedDecl*[FD->ChainingSize]; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 1340 | |
| 1341 | for (unsigned I = 0; I != FD->ChainingSize; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1342 | FD->Chaining[I] = ReadDeclAs<NamedDecl>(); |
Richard Smith | 8cbd895 | 2015-08-04 02:05:09 +0000 | [diff] [blame] | 1343 | |
| 1344 | mergeMergeable(FD); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 1345 | } |
| 1346 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1347 | ASTDeclReader::RedeclarableResult ASTDeclReader::VisitVarDeclImpl(VarDecl *VD) { |
Douglas Gregor | b8c6f1e | 2012-01-04 17:21:36 +0000 | [diff] [blame] | 1348 | RedeclarableResult Redecl = VisitRedeclarable(VD); |
Douglas Gregor | 3e30010 | 2011-10-26 17:53:41 +0000 | [diff] [blame] | 1349 | VisitDeclaratorDecl(VD); |
Rafael Espindola | 6ae7e50 | 2013-04-03 19:27:57 +0000 | [diff] [blame] | 1350 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1351 | VD->VarDeclBits.SClass = (StorageClass)Record.readInt(); |
| 1352 | VD->VarDeclBits.TSCSpec = Record.readInt(); |
| 1353 | VD->VarDeclBits.InitStyle = Record.readInt(); |
David Majnemer | fa7bc78 | 2015-05-19 00:57:16 +0000 | [diff] [blame] | 1354 | if (!isa<ParmVarDecl>(VD)) { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1355 | VD->NonParmVarDeclBits.IsThisDeclarationADemotedDefinition = |
| 1356 | Record.readInt(); |
| 1357 | VD->NonParmVarDeclBits.ExceptionVar = Record.readInt(); |
Taiju Tsuiki | 3be68e1 | 2018-06-19 05:35:30 +0000 | [diff] [blame] | 1358 | VD->NonParmVarDeclBits.NRVOVariable = Record.readInt(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1359 | VD->NonParmVarDeclBits.CXXForRangeDecl = Record.readInt(); |
George Karpenkov | ec38cf7 | 2018-03-29 00:56:24 +0000 | [diff] [blame] | 1360 | VD->NonParmVarDeclBits.ObjCForDecl = Record.readInt(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1361 | VD->NonParmVarDeclBits.ARCPseudoStrong = Record.readInt(); |
| 1362 | VD->NonParmVarDeclBits.IsInline = Record.readInt(); |
| 1363 | VD->NonParmVarDeclBits.IsInlineSpecified = Record.readInt(); |
| 1364 | VD->NonParmVarDeclBits.IsConstexpr = Record.readInt(); |
| 1365 | VD->NonParmVarDeclBits.IsInitCapture = Record.readInt(); |
| 1366 | VD->NonParmVarDeclBits.PreviousDeclInSameBlockScope = Record.readInt(); |
Alexey Bataev | 5622323 | 2017-06-09 13:40:18 +0000 | [diff] [blame] | 1367 | VD->NonParmVarDeclBits.ImplicitParamKind = Record.readInt(); |
Akira Hatanaka | 8e57b07 | 2018-10-01 21:51:28 +0000 | [diff] [blame] | 1368 | VD->NonParmVarDeclBits.EscapingByref = Record.readInt(); |
David Majnemer | fa7bc78 | 2015-05-19 00:57:16 +0000 | [diff] [blame] | 1369 | } |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1370 | auto VarLinkage = Linkage(Record.readInt()); |
Richard Smith | 541b38b | 2013-09-20 01:15:31 +0000 | [diff] [blame] | 1371 | VD->setCachedLinkage(VarLinkage); |
| 1372 | |
| 1373 | // Reconstruct the one piece of the IdentifierNamespace that we need. |
Ted Kremenek | a683f63 | 2014-02-11 06:29:29 +0000 | [diff] [blame] | 1374 | if (VD->getStorageClass() == SC_Extern && VarLinkage != NoLinkage && |
Richard Smith | 541b38b | 2013-09-20 01:15:31 +0000 | [diff] [blame] | 1375 | VD->getLexicalDeclContext()->isFunctionOrMethod()) |
| 1376 | VD->setLocalExternDecl(); |
Rafael Espindola | 50df3a0 | 2013-05-25 17:16:20 +0000 | [diff] [blame] | 1377 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1378 | if (uint64_t Val = Record.readInt()) { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1379 | VD->setInit(Record.readExpr()); |
Vassil Vassilev | d1a8813 | 2016-10-06 13:04:54 +0000 | [diff] [blame] | 1380 | if (Val > 1) { // IsInitKnownICE = 1, IsInitNotICE = 2, IsInitICE = 3 |
Richard Smith | d0b4dd6 | 2011-12-19 06:19:21 +0000 | [diff] [blame] | 1381 | EvaluatedStmt *Eval = VD->ensureEvaluatedStmt(); |
| 1382 | Eval->CheckedICE = true; |
| 1383 | Eval->IsICE = Val == 3; |
| 1384 | } |
| 1385 | } |
Argyrios Kyrtzidis | cdb8b3f | 2010-07-04 21:44:00 +0000 | [diff] [blame] | 1386 | |
Akira Hatanaka | 9978da3 | 2018-08-10 15:09:24 +0000 | [diff] [blame] | 1387 | if (VD->hasAttr<BlocksAttr>() && VD->getType()->getAsCXXRecordDecl()) { |
| 1388 | Expr *CopyExpr = Record.readExpr(); |
| 1389 | if (CopyExpr) |
| 1390 | Reader.getContext().setBlockVarCopyInit(VD, CopyExpr, Record.readInt()); |
| 1391 | } |
| 1392 | |
Richard Smith | a465362 | 2017-09-06 20:01:14 +0000 | [diff] [blame] | 1393 | if (VD->getStorageDuration() == SD_Static && Record.readInt()) |
| 1394 | Reader.DefinitionSource[VD] = Loc.F->Kind == ModuleKind::MK_MainFile; |
| 1395 | |
Larisse Voufo | d8dd97c | 2013-08-14 03:09:19 +0000 | [diff] [blame] | 1396 | enum VarKind { |
| 1397 | VarNotTemplate = 0, VarTemplate, StaticDataMemberSpecialization |
| 1398 | }; |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1399 | switch ((VarKind)Record.readInt()) { |
Larisse Voufo | d8dd97c | 2013-08-14 03:09:19 +0000 | [diff] [blame] | 1400 | case VarNotTemplate: |
Richard Smith | 9b88a4c | 2015-07-27 05:40:23 +0000 | [diff] [blame] | 1401 | // Only true variables (not parameters or implicit parameters) can be |
| 1402 | // merged; the other kinds are not really redeclarable at all. |
Richard Smith | 0144f51 | 2015-08-22 02:09:38 +0000 | [diff] [blame] | 1403 | if (!isa<ParmVarDecl>(VD) && !isa<ImplicitParamDecl>(VD) && |
| 1404 | !isa<VarTemplateSpecializationDecl>(VD)) |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 1405 | mergeRedeclarable(VD, Redecl); |
Larisse Voufo | d8dd97c | 2013-08-14 03:09:19 +0000 | [diff] [blame] | 1406 | break; |
| 1407 | case VarTemplate: |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 1408 | // Merged when we merge the template. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1409 | VD->setDescribedVarTemplate(ReadDeclAs<VarTemplateDecl>()); |
Larisse Voufo | d8dd97c | 2013-08-14 03:09:19 +0000 | [diff] [blame] | 1410 | break; |
| 1411 | case StaticDataMemberSpecialization: { // HasMemberSpecializationInfo. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1412 | auto *Tmpl = ReadDeclAs<VarDecl>(); |
| 1413 | auto TSK = (TemplateSpecializationKind)Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1414 | SourceLocation POI = ReadSourceLocation(); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1415 | Reader.getContext().setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI); |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 1416 | mergeRedeclarable(VD, Redecl); |
Larisse Voufo | d8dd97c | 2013-08-14 03:09:19 +0000 | [diff] [blame] | 1417 | break; |
| 1418 | } |
Argyrios Kyrtzidis | cdb8b3f | 2010-07-04 21:44:00 +0000 | [diff] [blame] | 1419 | } |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1420 | |
| 1421 | return Redecl; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1422 | } |
| 1423 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1424 | void ASTDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1425 | VisitVarDecl(PD); |
| 1426 | } |
| 1427 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1428 | void ASTDeclReader::VisitParmVarDecl(ParmVarDecl *PD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1429 | VisitVarDecl(PD); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1430 | unsigned isObjCMethodParam = Record.readInt(); |
| 1431 | unsigned scopeDepth = Record.readInt(); |
| 1432 | unsigned scopeIndex = Record.readInt(); |
| 1433 | unsigned declQualifier = Record.readInt(); |
John McCall | 8249083 | 2011-05-02 00:30:12 +0000 | [diff] [blame] | 1434 | if (isObjCMethodParam) { |
| 1435 | assert(scopeDepth == 0); |
| 1436 | PD->setObjCMethodScopeInfo(scopeIndex); |
| 1437 | PD->ParmVarDeclBits.ScopeDepthOrObjCQuals = declQualifier; |
| 1438 | } else { |
| 1439 | PD->setScopeInfo(scopeDepth, scopeIndex); |
| 1440 | } |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1441 | PD->ParmVarDeclBits.IsKNRPromoted = Record.readInt(); |
| 1442 | PD->ParmVarDeclBits.HasInheritedDefaultArg = Record.readInt(); |
| 1443 | if (Record.readInt()) // hasUninstantiatedDefaultArg. |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1444 | PD->setUninstantiatedDefaultArg(Record.readExpr()); |
Richard Smith | bf78e64 | 2013-06-24 22:51:00 +0000 | [diff] [blame] | 1445 | |
| 1446 | // FIXME: If this is a redeclaration of a function from another module, handle |
| 1447 | // inheritance of default arguments. |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1448 | } |
| 1449 | |
Richard Smith | 7b76d81 | 2016-08-12 02:21:25 +0000 | [diff] [blame] | 1450 | void ASTDeclReader::VisitDecompositionDecl(DecompositionDecl *DD) { |
| 1451 | VisitVarDecl(DD); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1452 | auto **BDs = DD->getTrailingObjects<BindingDecl *>(); |
Richard Smith | 7b76d81 | 2016-08-12 02:21:25 +0000 | [diff] [blame] | 1453 | for (unsigned I = 0; I != DD->NumBindings; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1454 | BDs[I] = ReadDeclAs<BindingDecl>(); |
Richard Smith | 7b76d81 | 2016-08-12 02:21:25 +0000 | [diff] [blame] | 1455 | } |
| 1456 | |
| 1457 | void ASTDeclReader::VisitBindingDecl(BindingDecl *BD) { |
| 1458 | VisitValueDecl(BD); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1459 | BD->Binding = Record.readExpr(); |
Richard Smith | 7b76d81 | 2016-08-12 02:21:25 +0000 | [diff] [blame] | 1460 | } |
| 1461 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1462 | void ASTDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1463 | VisitDecl(AD); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1464 | AD->setAsmString(cast<StringLiteral>(Record.readExpr())); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1465 | AD->setRParenLoc(ReadSourceLocation()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1466 | } |
| 1467 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1468 | void ASTDeclReader::VisitBlockDecl(BlockDecl *BD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1469 | VisitDecl(BD); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1470 | BD->setBody(cast_or_null<CompoundStmt>(Record.readStmt())); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1471 | BD->setSignatureAsWritten(GetTypeSourceInfo()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1472 | unsigned NumParams = Record.readInt(); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1473 | SmallVector<ParmVarDecl *, 16> Params; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1474 | Params.reserve(NumParams); |
| 1475 | for (unsigned I = 0; I != NumParams; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1476 | Params.push_back(ReadDeclAs<ParmVarDecl>()); |
David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 1477 | BD->setParams(Params); |
John McCall | c63de66 | 2011-02-02 13:00:07 +0000 | [diff] [blame] | 1478 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1479 | BD->setIsVariadic(Record.readInt()); |
| 1480 | BD->setBlockMissingReturnType(Record.readInt()); |
| 1481 | BD->setIsConversionFromLambda(Record.readInt()); |
Akira Hatanaka | db49a1f | 2018-08-01 23:51:53 +0000 | [diff] [blame] | 1482 | BD->setDoesNotEscape(Record.readInt()); |
John McCall | cf6ce28 | 2012-04-13 17:33:29 +0000 | [diff] [blame] | 1483 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1484 | bool capturesCXXThis = Record.readInt(); |
| 1485 | unsigned numCaptures = Record.readInt(); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1486 | SmallVector<BlockDecl::Capture, 16> captures; |
John McCall | 351762c | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 1487 | captures.reserve(numCaptures); |
| 1488 | for (unsigned i = 0; i != numCaptures; ++i) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1489 | auto *decl = ReadDeclAs<VarDecl>(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1490 | unsigned flags = Record.readInt(); |
John McCall | 351762c | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 1491 | bool byRef = (flags & 1); |
| 1492 | bool nested = (flags & 2); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1493 | Expr *copyExpr = ((flags & 4) ? Record.readExpr() : nullptr); |
John McCall | 351762c | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 1494 | |
| 1495 | captures.push_back(BlockDecl::Capture(decl, byRef, nested, copyExpr)); |
| 1496 | } |
Benjamin Kramer | b40e4af | 2015-08-05 09:40:35 +0000 | [diff] [blame] | 1497 | BD->setCaptures(Reader.getContext(), captures, capturesCXXThis); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1498 | } |
| 1499 | |
Ben Langmuir | ce914fc | 2013-05-03 19:20:19 +0000 | [diff] [blame] | 1500 | void ASTDeclReader::VisitCapturedDecl(CapturedDecl *CD) { |
| 1501 | VisitDecl(CD); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1502 | unsigned ContextParamPos = Record.readInt(); |
| 1503 | CD->setNothrow(Record.readInt() != 0); |
Ben Langmuir | ce914fc | 2013-05-03 19:20:19 +0000 | [diff] [blame] | 1504 | // Body is set by VisitCapturedStmt. |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1505 | for (unsigned I = 0; I < CD->NumParams; ++I) { |
| 1506 | if (I != ContextParamPos) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1507 | CD->setParam(I, ReadDeclAs<ImplicitParamDecl>()); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1508 | else |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1509 | CD->setContextParam(I, ReadDeclAs<ImplicitParamDecl>()); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1510 | } |
Tareq A. Siraj | 6dfa25a | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 1511 | } |
| 1512 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1513 | void ASTDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1514 | VisitDecl(D); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1515 | D->setLanguage((LinkageSpecDecl::LanguageIDs)Record.readInt()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1516 | D->setExternLoc(ReadSourceLocation()); |
| 1517 | D->setRBraceLoc(ReadSourceLocation()); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1518 | } |
| 1519 | |
Richard Smith | 8df390f | 2016-09-08 23:14:54 +0000 | [diff] [blame] | 1520 | void ASTDeclReader::VisitExportDecl(ExportDecl *D) { |
| 1521 | VisitDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1522 | D->RBraceLoc = ReadSourceLocation(); |
Richard Smith | 8df390f | 2016-09-08 23:14:54 +0000 | [diff] [blame] | 1523 | } |
| 1524 | |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1525 | void ASTDeclReader::VisitLabelDecl(LabelDecl *D) { |
| 1526 | VisitNamedDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1527 | D->setLocStart(ReadSourceLocation()); |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1528 | } |
| 1529 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1530 | void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl *D) { |
Douglas Gregor | e57e752 | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 1531 | RedeclarableResult Redecl = VisitRedeclarable(D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1532 | VisitNamedDecl(D); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1533 | D->setInline(Record.readInt()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1534 | D->LocStart = ReadSourceLocation(); |
| 1535 | D->RBraceLoc = ReadSourceLocation(); |
Douglas Gregor | cfe7dc6 | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 1536 | |
Richard Smith | 15e32fd | 2015-03-17 02:23:11 +0000 | [diff] [blame] | 1537 | // Defer loading the anonymous namespace until we've finished merging |
| 1538 | // this namespace; loading it might load a later declaration of the |
| 1539 | // same namespace, and we have an invariant that older declarations |
| 1540 | // get merged before newer ones try to merge. |
| 1541 | GlobalDeclID AnonNamespace = 0; |
Douglas Gregor | e57e752 | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 1542 | if (Redecl.getFirstID() == ThisDeclID) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1543 | AnonNamespace = ReadDeclID(); |
Douglas Gregor | e57e752 | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 1544 | } else { |
| 1545 | // Link this namespace back to the first declaration, which has already |
| 1546 | // been deserialized. |
Rafael Espindola | 8db352d | 2013-10-17 15:37:26 +0000 | [diff] [blame] | 1547 | D->AnonOrFirstNamespaceAndInline.setPointer(D->getFirstDecl()); |
Douglas Gregor | e57e752 | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 1548 | } |
Richard Smith | 5e9e56a | 2014-07-15 03:37:06 +0000 | [diff] [blame] | 1549 | |
| 1550 | mergeRedeclarable(D, Redecl); |
Richard Smith | 15e32fd | 2015-03-17 02:23:11 +0000 | [diff] [blame] | 1551 | |
| 1552 | if (AnonNamespace) { |
| 1553 | // Each module has its own anonymous namespace, which is disjoint from |
| 1554 | // any other module's anonymous namespaces, so don't attach the anonymous |
| 1555 | // namespace at all. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1556 | auto *Anon = cast<NamespaceDecl>(Reader.GetDecl(AnonNamespace)); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1557 | if (!Record.isModule()) |
Richard Smith | 15e32fd | 2015-03-17 02:23:11 +0000 | [diff] [blame] | 1558 | D->setAnonymousNamespace(Anon); |
| 1559 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1560 | } |
| 1561 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1562 | void ASTDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { |
Richard Smith | f463436 | 2014-09-03 23:11:22 +0000 | [diff] [blame] | 1563 | RedeclarableResult Redecl = VisitRedeclarable(D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1564 | VisitNamedDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1565 | D->NamespaceLoc = ReadSourceLocation(); |
| 1566 | D->IdentLoc = ReadSourceLocation(); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1567 | D->QualifierLoc = Record.readNestedNameSpecifierLoc(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1568 | D->Namespace = ReadDeclAs<NamedDecl>(); |
Richard Smith | f463436 | 2014-09-03 23:11:22 +0000 | [diff] [blame] | 1569 | mergeRedeclarable(D, Redecl); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1570 | } |
| 1571 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1572 | void ASTDeclReader::VisitUsingDecl(UsingDecl *D) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1573 | VisitNamedDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1574 | D->setUsingLoc(ReadSourceLocation()); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1575 | D->QualifierLoc = Record.readNestedNameSpecifierLoc(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1576 | ReadDeclarationNameLoc(D->DNLoc, D->getDeclName()); |
| 1577 | D->FirstUsingShadow.setPointer(ReadDeclAs<UsingShadowDecl>()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1578 | D->setTypename(Record.readInt()); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1579 | if (auto *Pattern = ReadDeclAs<NamedDecl>()) |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1580 | Reader.getContext().setInstantiatedFromUsingDecl(D, Pattern); |
Richard Smith | 32952e1 | 2014-10-14 02:00:47 +0000 | [diff] [blame] | 1581 | mergeMergeable(D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1582 | } |
| 1583 | |
Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 1584 | void ASTDeclReader::VisitUsingPackDecl(UsingPackDecl *D) { |
| 1585 | VisitNamedDecl(D); |
| 1586 | D->InstantiatedFrom = ReadDeclAs<NamedDecl>(); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1587 | auto **Expansions = D->getTrailingObjects<NamedDecl *>(); |
Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 1588 | for (unsigned I = 0; I != D->NumExpansions; ++I) |
| 1589 | Expansions[I] = ReadDeclAs<NamedDecl>(); |
| 1590 | mergeMergeable(D); |
| 1591 | } |
| 1592 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1593 | void ASTDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) { |
Richard Smith | fd8634a | 2013-10-23 02:17:46 +0000 | [diff] [blame] | 1594 | RedeclarableResult Redecl = VisitRedeclarable(D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1595 | VisitNamedDecl(D); |
Richard Smith | a263c34 | 2018-01-06 01:07:05 +0000 | [diff] [blame] | 1596 | D->Underlying = ReadDeclAs<NamedDecl>(); |
| 1597 | D->IdentifierNamespace = Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1598 | D->UsingOrNextShadow = ReadDeclAs<NamedDecl>(); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1599 | auto *Pattern = ReadDeclAs<UsingShadowDecl>(); |
Argyrios Kyrtzidis | 6685e8a | 2010-07-04 21:44:35 +0000 | [diff] [blame] | 1600 | if (Pattern) |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1601 | Reader.getContext().setInstantiatedFromUsingShadowDecl(D, Pattern); |
Richard Smith | fd8634a | 2013-10-23 02:17:46 +0000 | [diff] [blame] | 1602 | mergeRedeclarable(D, Redecl); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1603 | } |
| 1604 | |
Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 1605 | void ASTDeclReader::VisitConstructorUsingShadowDecl( |
| 1606 | ConstructorUsingShadowDecl *D) { |
| 1607 | VisitUsingShadowDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1608 | D->NominatedBaseClassShadowDecl = ReadDeclAs<ConstructorUsingShadowDecl>(); |
| 1609 | D->ConstructedBaseClassShadowDecl = ReadDeclAs<ConstructorUsingShadowDecl>(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1610 | D->IsVirtual = Record.readInt(); |
Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 1611 | } |
| 1612 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1613 | void ASTDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1614 | VisitNamedDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1615 | D->UsingLoc = ReadSourceLocation(); |
| 1616 | D->NamespaceLoc = ReadSourceLocation(); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1617 | D->QualifierLoc = Record.readNestedNameSpecifierLoc(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1618 | D->NominatedNamespace = ReadDeclAs<NamedDecl>(); |
| 1619 | D->CommonAncestor = ReadDeclAs<DeclContext>(); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1620 | } |
| 1621 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1622 | void ASTDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1623 | VisitValueDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1624 | D->setUsingLoc(ReadSourceLocation()); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1625 | D->QualifierLoc = Record.readNestedNameSpecifierLoc(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1626 | ReadDeclarationNameLoc(D->DNLoc, D->getDeclName()); |
Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 1627 | D->EllipsisLoc = ReadSourceLocation(); |
Richard Smith | 32952e1 | 2014-10-14 02:00:47 +0000 | [diff] [blame] | 1628 | mergeMergeable(D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1629 | } |
| 1630 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1631 | void ASTDeclReader::VisitUnresolvedUsingTypenameDecl( |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1632 | UnresolvedUsingTypenameDecl *D) { |
| 1633 | VisitTypeDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1634 | D->TypenameLocation = ReadSourceLocation(); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1635 | D->QualifierLoc = Record.readNestedNameSpecifierLoc(); |
Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 1636 | D->EllipsisLoc = ReadSourceLocation(); |
Richard Smith | 32952e1 | 2014-10-14 02:00:47 +0000 | [diff] [blame] | 1637 | mergeMergeable(D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1638 | } |
| 1639 | |
Argyrios Kyrtzidis | 8b200a5 | 2010-10-24 17:26:27 +0000 | [diff] [blame] | 1640 | void ASTDeclReader::ReadCXXDefinitionData( |
David Blaikie | 1ac9c98 | 2017-04-11 21:13:37 +0000 | [diff] [blame] | 1641 | struct CXXRecordDecl::DefinitionData &Data, const CXXRecordDecl *D) { |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 1642 | // Note: the caller has deserialized the IsLambda bit already. |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1643 | Data.UserDeclaredConstructor = Record.readInt(); |
| 1644 | Data.UserDeclaredSpecialMembers = Record.readInt(); |
| 1645 | Data.Aggregate = Record.readInt(); |
| 1646 | Data.PlainOldData = Record.readInt(); |
| 1647 | Data.Empty = Record.readInt(); |
| 1648 | Data.Polymorphic = Record.readInt(); |
| 1649 | Data.Abstract = Record.readInt(); |
| 1650 | Data.IsStandardLayout = Record.readInt(); |
Richard Smith | b6070db | 2018-04-05 18:55:37 +0000 | [diff] [blame] | 1651 | Data.IsCXX11StandardLayout = Record.readInt(); |
| 1652 | Data.HasBasesWithFields = Record.readInt(); |
| 1653 | Data.HasBasesWithNonStaticDataMembers = Record.readInt(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1654 | Data.HasPrivateFields = Record.readInt(); |
| 1655 | Data.HasProtectedFields = Record.readInt(); |
| 1656 | Data.HasPublicFields = Record.readInt(); |
| 1657 | Data.HasMutableFields = Record.readInt(); |
| 1658 | Data.HasVariantMembers = Record.readInt(); |
| 1659 | Data.HasOnlyCMembers = Record.readInt(); |
| 1660 | Data.HasInClassInitializer = Record.readInt(); |
| 1661 | Data.HasUninitializedReferenceMember = Record.readInt(); |
| 1662 | Data.HasUninitializedFields = Record.readInt(); |
| 1663 | Data.HasInheritedConstructor = Record.readInt(); |
| 1664 | Data.HasInheritedAssignment = Record.readInt(); |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1665 | Data.NeedOverloadResolutionForCopyConstructor = Record.readInt(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1666 | Data.NeedOverloadResolutionForMoveConstructor = Record.readInt(); |
| 1667 | Data.NeedOverloadResolutionForMoveAssignment = Record.readInt(); |
| 1668 | Data.NeedOverloadResolutionForDestructor = Record.readInt(); |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1669 | Data.DefaultedCopyConstructorIsDeleted = Record.readInt(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1670 | Data.DefaultedMoveConstructorIsDeleted = Record.readInt(); |
| 1671 | Data.DefaultedMoveAssignmentIsDeleted = Record.readInt(); |
| 1672 | Data.DefaultedDestructorIsDeleted = Record.readInt(); |
| 1673 | Data.HasTrivialSpecialMembers = Record.readInt(); |
Akira Hatanaka | 02914dc | 2018-02-05 20:23:22 +0000 | [diff] [blame] | 1674 | Data.HasTrivialSpecialMembersForCall = Record.readInt(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1675 | Data.DeclaredNonTrivialSpecialMembers = Record.readInt(); |
Akira Hatanaka | 02914dc | 2018-02-05 20:23:22 +0000 | [diff] [blame] | 1676 | Data.DeclaredNonTrivialSpecialMembersForCall = Record.readInt(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1677 | Data.HasIrrelevantDestructor = Record.readInt(); |
| 1678 | Data.HasConstexprNonCopyMoveConstructor = Record.readInt(); |
| 1679 | Data.HasDefaultedDefaultConstructor = Record.readInt(); |
| 1680 | Data.DefaultedDefaultConstructorIsConstexpr = Record.readInt(); |
| 1681 | Data.HasConstexprDefaultConstructor = Record.readInt(); |
| 1682 | Data.HasNonLiteralTypeFieldsOrBases = Record.readInt(); |
| 1683 | Data.ComputedVisibleConversions = Record.readInt(); |
| 1684 | Data.UserProvidedDefaultConstructor = Record.readInt(); |
| 1685 | Data.DeclaredSpecialMembers = Record.readInt(); |
Richard Smith | df054d3 | 2017-02-25 23:53:05 +0000 | [diff] [blame] | 1686 | Data.ImplicitCopyConstructorCanHaveConstParamForVBase = Record.readInt(); |
| 1687 | Data.ImplicitCopyConstructorCanHaveConstParamForNonVBase = Record.readInt(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1688 | Data.ImplicitCopyAssignmentHasConstParam = Record.readInt(); |
| 1689 | Data.HasDeclaredCopyConstructorWithConstParam = Record.readInt(); |
| 1690 | Data.HasDeclaredCopyAssignmentWithConstParam = Record.readInt(); |
Richard Trieu | b6adf54 | 2017-02-18 02:09:28 +0000 | [diff] [blame] | 1691 | Data.ODRHash = Record.readInt(); |
Richard Trieu | fd1acbb | 2017-04-11 21:31:00 +0000 | [diff] [blame] | 1692 | Data.HasODRHash = true; |
Anders Carlsson | 703d6e6 | 2011-01-22 18:11:02 +0000 | [diff] [blame] | 1693 | |
Richard Smith | cd4a7a4 | 2017-09-07 00:55:55 +0000 | [diff] [blame] | 1694 | if (Record.readInt()) |
| 1695 | Reader.DefinitionSource[D] = Loc.F->Kind == ModuleKind::MK_MainFile; |
David Blaikie | 1ac9c98 | 2017-04-11 21:13:37 +0000 | [diff] [blame] | 1696 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1697 | Data.NumBases = Record.readInt(); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 1698 | if (Data.NumBases) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1699 | Data.Bases = ReadGlobalOffset(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1700 | Data.NumVBases = Record.readInt(); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 1701 | if (Data.NumVBases) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1702 | Data.VBases = ReadGlobalOffset(); |
| 1703 | |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1704 | Record.readUnresolvedSet(Data.Conversions); |
| 1705 | Record.readUnresolvedSet(Data.VisibleConversions); |
Argyrios Kyrtzidis | 8b200a5 | 2010-10-24 17:26:27 +0000 | [diff] [blame] | 1706 | assert(Data.Definition && "Data.Definition should be already set!"); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1707 | Data.FirstFriend = ReadDeclID(); |
Richard Smith | 9dd9f03 | 2013-08-30 00:23:29 +0000 | [diff] [blame] | 1708 | |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 1709 | if (Data.IsLambda) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1710 | using Capture = LambdaCapture; |
| 1711 | |
| 1712 | auto &Lambda = static_cast<CXXRecordDecl::LambdaDefinitionData &>(Data); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1713 | Lambda.Dependent = Record.readInt(); |
| 1714 | Lambda.IsGenericLambda = Record.readInt(); |
| 1715 | Lambda.CaptureDefault = Record.readInt(); |
| 1716 | Lambda.NumCaptures = Record.readInt(); |
| 1717 | Lambda.NumExplicitCaptures = Record.readInt(); |
| 1718 | Lambda.ManglingNumber = Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1719 | Lambda.ContextDecl = ReadDeclID(); |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 1720 | Lambda.Captures = (Capture *)Reader.getContext().Allocate( |
| 1721 | sizeof(Capture) * Lambda.NumCaptures); |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 1722 | Capture *ToCapture = Lambda.Captures; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1723 | Lambda.MethodTyInfo = GetTypeSourceInfo(); |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 1724 | for (unsigned I = 0, N = Lambda.NumCaptures; I != N; ++I) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1725 | SourceLocation Loc = ReadSourceLocation(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1726 | bool IsImplicit = Record.readInt(); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1727 | auto Kind = static_cast<LambdaCaptureKind>(Record.readInt()); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 1728 | switch (Kind) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1729 | case LCK_StarThis: |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 1730 | case LCK_This: |
Alexey Bataev | 39c81e2 | 2014-08-28 04:28:19 +0000 | [diff] [blame] | 1731 | case LCK_VLAType: |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 1732 | *ToCapture++ = Capture(Loc, IsImplicit, Kind, nullptr,SourceLocation()); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 1733 | break; |
| 1734 | case LCK_ByCopy: |
Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 1735 | case LCK_ByRef: |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1736 | auto *Var = ReadDeclAs<VarDecl>(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1737 | SourceLocation EllipsisLoc = ReadSourceLocation(); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 1738 | *ToCapture++ = Capture(Loc, IsImplicit, Kind, Var, EllipsisLoc); |
| 1739 | break; |
| 1740 | } |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 1741 | } |
| 1742 | } |
Argyrios Kyrtzidis | 8b200a5 | 2010-10-24 17:26:27 +0000 | [diff] [blame] | 1743 | } |
| 1744 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1745 | void ASTDeclReader::MergeDefinitionData( |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 1746 | CXXRecordDecl *D, struct CXXRecordDecl::DefinitionData &&MergeDD) { |
Richard Smith | b648399 | 2016-05-17 22:44:15 +0000 | [diff] [blame] | 1747 | assert(D->DefinitionData && |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 1748 | "merging class definition into non-definition"); |
Richard Smith | b648399 | 2016-05-17 22:44:15 +0000 | [diff] [blame] | 1749 | auto &DD = *D->DefinitionData; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1750 | |
Richard Smith | 0279375 | 2015-03-27 21:16:39 +0000 | [diff] [blame] | 1751 | if (DD.Definition != MergeDD.Definition) { |
Richard Smith | 97100e3 | 2015-06-20 00:22:34 +0000 | [diff] [blame] | 1752 | // Track that we merged the definitions. |
| 1753 | Reader.MergedDeclContexts.insert(std::make_pair(MergeDD.Definition, |
| 1754 | DD.Definition)); |
| 1755 | Reader.PendingDefinitions.erase(MergeDD.Definition); |
Erich Keane | f92f31c | 2018-08-01 20:48:16 +0000 | [diff] [blame] | 1756 | MergeDD.Definition->setCompleteDefinition(false); |
Richard Smith | 6561f92 | 2016-09-12 21:06:40 +0000 | [diff] [blame] | 1757 | Reader.mergeDefinitionVisibility(DD.Definition, MergeDD.Definition); |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 1758 | assert(Reader.Lookups.find(MergeDD.Definition) == Reader.Lookups.end() && |
| 1759 | "already loaded pending lookups for merged definition"); |
Richard Smith | 0279375 | 2015-03-27 21:16:39 +0000 | [diff] [blame] | 1760 | } |
| 1761 | |
Richard Smith | 2a9e5c5 | 2015-02-03 03:32:14 +0000 | [diff] [blame] | 1762 | auto PFDI = Reader.PendingFakeDefinitionData.find(&DD); |
| 1763 | if (PFDI != Reader.PendingFakeDefinitionData.end() && |
| 1764 | PFDI->second == ASTReader::PendingFakeDefinitionKind::Fake) { |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 1765 | // We faked up this definition data because we found a class for which we'd |
| 1766 | // not yet loaded the definition. Replace it with the real thing now. |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 1767 | assert(!DD.IsLambda && !MergeDD.IsLambda && "faked up lambda definition?"); |
Richard Smith | 2a9e5c5 | 2015-02-03 03:32:14 +0000 | [diff] [blame] | 1768 | PFDI->second = ASTReader::PendingFakeDefinitionKind::FakeLoaded; |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 1769 | |
| 1770 | // Don't change which declaration is the definition; that is required |
| 1771 | // to be invariant once we select it. |
| 1772 | auto *Def = DD.Definition; |
| 1773 | DD = std::move(MergeDD); |
| 1774 | DD.Definition = Def; |
| 1775 | return; |
| 1776 | } |
| 1777 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1778 | // FIXME: Move this out into a .def file? |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1779 | bool DetectedOdrViolation = false; |
| 1780 | #define OR_FIELD(Field) DD.Field |= MergeDD.Field; |
| 1781 | #define MATCH_FIELD(Field) \ |
| 1782 | DetectedOdrViolation |= DD.Field != MergeDD.Field; \ |
| 1783 | OR_FIELD(Field) |
| 1784 | MATCH_FIELD(UserDeclaredConstructor) |
| 1785 | MATCH_FIELD(UserDeclaredSpecialMembers) |
| 1786 | MATCH_FIELD(Aggregate) |
| 1787 | MATCH_FIELD(PlainOldData) |
| 1788 | MATCH_FIELD(Empty) |
| 1789 | MATCH_FIELD(Polymorphic) |
| 1790 | MATCH_FIELD(Abstract) |
| 1791 | MATCH_FIELD(IsStandardLayout) |
Richard Smith | b6070db | 2018-04-05 18:55:37 +0000 | [diff] [blame] | 1792 | MATCH_FIELD(IsCXX11StandardLayout) |
| 1793 | MATCH_FIELD(HasBasesWithFields) |
| 1794 | MATCH_FIELD(HasBasesWithNonStaticDataMembers) |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1795 | MATCH_FIELD(HasPrivateFields) |
| 1796 | MATCH_FIELD(HasProtectedFields) |
| 1797 | MATCH_FIELD(HasPublicFields) |
| 1798 | MATCH_FIELD(HasMutableFields) |
| 1799 | MATCH_FIELD(HasVariantMembers) |
| 1800 | MATCH_FIELD(HasOnlyCMembers) |
| 1801 | MATCH_FIELD(HasInClassInitializer) |
| 1802 | MATCH_FIELD(HasUninitializedReferenceMember) |
Nico Weber | 6a6376b | 2016-02-19 01:52:46 +0000 | [diff] [blame] | 1803 | MATCH_FIELD(HasUninitializedFields) |
Richard Smith | 12e7931 | 2016-05-13 06:47:56 +0000 | [diff] [blame] | 1804 | MATCH_FIELD(HasInheritedConstructor) |
| 1805 | MATCH_FIELD(HasInheritedAssignment) |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1806 | MATCH_FIELD(NeedOverloadResolutionForCopyConstructor) |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1807 | MATCH_FIELD(NeedOverloadResolutionForMoveConstructor) |
| 1808 | MATCH_FIELD(NeedOverloadResolutionForMoveAssignment) |
| 1809 | MATCH_FIELD(NeedOverloadResolutionForDestructor) |
Richard Smith | 96cd671 | 2017-08-16 01:49:53 +0000 | [diff] [blame] | 1810 | MATCH_FIELD(DefaultedCopyConstructorIsDeleted) |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1811 | MATCH_FIELD(DefaultedMoveConstructorIsDeleted) |
| 1812 | MATCH_FIELD(DefaultedMoveAssignmentIsDeleted) |
| 1813 | MATCH_FIELD(DefaultedDestructorIsDeleted) |
| 1814 | OR_FIELD(HasTrivialSpecialMembers) |
Akira Hatanaka | 02914dc | 2018-02-05 20:23:22 +0000 | [diff] [blame] | 1815 | OR_FIELD(HasTrivialSpecialMembersForCall) |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1816 | OR_FIELD(DeclaredNonTrivialSpecialMembers) |
Akira Hatanaka | 02914dc | 2018-02-05 20:23:22 +0000 | [diff] [blame] | 1817 | OR_FIELD(DeclaredNonTrivialSpecialMembersForCall) |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1818 | MATCH_FIELD(HasIrrelevantDestructor) |
| 1819 | OR_FIELD(HasConstexprNonCopyMoveConstructor) |
Nico Weber | 72c57f4 | 2016-02-24 20:58:14 +0000 | [diff] [blame] | 1820 | OR_FIELD(HasDefaultedDefaultConstructor) |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1821 | MATCH_FIELD(DefaultedDefaultConstructorIsConstexpr) |
| 1822 | OR_FIELD(HasConstexprDefaultConstructor) |
| 1823 | MATCH_FIELD(HasNonLiteralTypeFieldsOrBases) |
| 1824 | // ComputedVisibleConversions is handled below. |
| 1825 | MATCH_FIELD(UserProvidedDefaultConstructor) |
| 1826 | OR_FIELD(DeclaredSpecialMembers) |
Richard Smith | df054d3 | 2017-02-25 23:53:05 +0000 | [diff] [blame] | 1827 | MATCH_FIELD(ImplicitCopyConstructorCanHaveConstParamForVBase) |
| 1828 | MATCH_FIELD(ImplicitCopyConstructorCanHaveConstParamForNonVBase) |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1829 | MATCH_FIELD(ImplicitCopyAssignmentHasConstParam) |
| 1830 | OR_FIELD(HasDeclaredCopyConstructorWithConstParam) |
| 1831 | OR_FIELD(HasDeclaredCopyAssignmentWithConstParam) |
| 1832 | MATCH_FIELD(IsLambda) |
| 1833 | #undef OR_FIELD |
| 1834 | #undef MATCH_FIELD |
| 1835 | |
| 1836 | if (DD.NumBases != MergeDD.NumBases || DD.NumVBases != MergeDD.NumVBases) |
| 1837 | DetectedOdrViolation = true; |
| 1838 | // FIXME: Issue a diagnostic if the base classes don't match when we come |
| 1839 | // to lazily load them. |
| 1840 | |
| 1841 | // FIXME: Issue a diagnostic if the list of conversion functions doesn't |
| 1842 | // match when we come to lazily load them. |
| 1843 | if (MergeDD.ComputedVisibleConversions && !DD.ComputedVisibleConversions) { |
| 1844 | DD.VisibleConversions = std::move(MergeDD.VisibleConversions); |
| 1845 | DD.ComputedVisibleConversions = true; |
| 1846 | } |
| 1847 | |
| 1848 | // FIXME: Issue a diagnostic if FirstFriend doesn't match when we come to |
| 1849 | // lazily load it. |
| 1850 | |
| 1851 | if (DD.IsLambda) { |
| 1852 | // FIXME: ODR-checking for merging lambdas (this happens, for instance, |
| 1853 | // when they occur within the body of a function template specialization). |
| 1854 | } |
| 1855 | |
Richard Trieu | fd1acbb | 2017-04-11 21:31:00 +0000 | [diff] [blame] | 1856 | if (D->getODRHash() != MergeDD.ODRHash) { |
| 1857 | DetectedOdrViolation = true; |
| 1858 | } |
| 1859 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1860 | if (DetectedOdrViolation) |
Richard Trieu | e13eabe | 2017-09-30 02:19:17 +0000 | [diff] [blame] | 1861 | Reader.PendingOdrMergeFailures[DD.Definition].push_back( |
| 1862 | {MergeDD.Definition, &MergeDD}); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1863 | } |
| 1864 | |
Richard Smith | 2a9e5c5 | 2015-02-03 03:32:14 +0000 | [diff] [blame] | 1865 | void ASTDeclReader::ReadCXXRecordDefinition(CXXRecordDecl *D, bool Update) { |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1866 | struct CXXRecordDecl::DefinitionData *DD; |
| 1867 | ASTContext &C = Reader.getContext(); |
| 1868 | |
| 1869 | // Determine whether this is a lambda closure type, so that we can |
| 1870 | // allocate the appropriate DefinitionData structure. |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1871 | bool IsLambda = Record.readInt(); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1872 | if (IsLambda) |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 1873 | DD = new (C) CXXRecordDecl::LambdaDefinitionData(D, nullptr, false, false, |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1874 | LCD_None); |
| 1875 | else |
| 1876 | DD = new (C) struct CXXRecordDecl::DefinitionData(D); |
| 1877 | |
Volodymyr Sapsai | 8a5943f | 2018-03-21 21:28:54 +0000 | [diff] [blame] | 1878 | CXXRecordDecl *Canon = D->getCanonicalDecl(); |
| 1879 | // Set decl definition data before reading it, so that during deserialization |
| 1880 | // when we read CXXRecordDecl, it already has definition data and we don't |
| 1881 | // set fake one. |
| 1882 | if (!Canon->DefinitionData) |
| 1883 | Canon->DefinitionData = DD; |
| 1884 | D->DefinitionData = Canon->DefinitionData; |
David Blaikie | 1ac9c98 | 2017-04-11 21:13:37 +0000 | [diff] [blame] | 1885 | ReadCXXDefinitionData(*DD, D); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1886 | |
Volodymyr Sapsai | 8a5943f | 2018-03-21 21:28:54 +0000 | [diff] [blame] | 1887 | // We might already have a different definition for this record. This can |
| 1888 | // happen either because we're reading an update record, or because we've |
| 1889 | // already done some merging. Either way, just merge into it. |
| 1890 | if (Canon->DefinitionData != DD) { |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 1891 | MergeDefinitionData(Canon, std::move(*DD)); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1892 | return; |
| 1893 | } |
| 1894 | |
Richard Smith | 97100e3 | 2015-06-20 00:22:34 +0000 | [diff] [blame] | 1895 | // Mark this declaration as being a definition. |
Erich Keane | f92f31c | 2018-08-01 20:48:16 +0000 | [diff] [blame] | 1896 | D->setCompleteDefinition(true); |
Richard Smith | 2a9e5c5 | 2015-02-03 03:32:14 +0000 | [diff] [blame] | 1897 | |
Richard Smith | 97100e3 | 2015-06-20 00:22:34 +0000 | [diff] [blame] | 1898 | // If this is not the first declaration or is an update record, we can have |
| 1899 | // other redeclarations already. Make a note that we need to propagate the |
| 1900 | // DefinitionData pointer onto them. |
Volodymyr Sapsai | 8a5943f | 2018-03-21 21:28:54 +0000 | [diff] [blame] | 1901 | if (Update || Canon != D) |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1902 | Reader.PendingDefinitions.insert(D); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1903 | } |
| 1904 | |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 1905 | ASTDeclReader::RedeclarableResult |
| 1906 | ASTDeclReader::VisitCXXRecordDeclImpl(CXXRecordDecl *D) { |
| 1907 | RedeclarableResult Redecl = VisitRecordDeclImpl(D); |
Argyrios Kyrtzidis | a41f660 | 2010-10-20 00:11:15 +0000 | [diff] [blame] | 1908 | |
Douglas Gregor | 3a5ae56 | 2012-01-15 18:17:48 +0000 | [diff] [blame] | 1909 | ASTContext &C = Reader.getContext(); |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 1910 | |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 1911 | enum CXXRecKind { |
| 1912 | CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization |
| 1913 | }; |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1914 | switch ((CXXRecKind)Record.readInt()) { |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 1915 | case CXXRecNotTemplate: |
Richard Smith | dc5523d | 2014-07-11 00:20:06 +0000 | [diff] [blame] | 1916 | // Merged when we merge the folding set entry in the primary template. |
| 1917 | if (!isa<ClassTemplateSpecializationDecl>(D)) |
| 1918 | mergeRedeclarable(D, Redecl); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 1919 | break; |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 1920 | case CXXRecTemplate: { |
| 1921 | // Merged when we merge the template. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1922 | auto *Template = ReadDeclAs<ClassTemplateDecl>(); |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 1923 | D->TemplateOrInstantiation = Template; |
| 1924 | if (!Template->getTemplatedDecl()) { |
| 1925 | // We've not actually loaded the ClassTemplateDecl yet, because we're |
| 1926 | // currently being loaded as its pattern. Rely on it to set up our |
| 1927 | // TypeForDecl (see VisitClassTemplateDecl). |
| 1928 | // |
| 1929 | // Beware: we do not yet know our canonical declaration, and may still |
| 1930 | // get merged once the surrounding class template has got off the ground. |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 1931 | DeferredTypeID = 0; |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 1932 | } |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 1933 | break; |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 1934 | } |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 1935 | case CXXRecMemberSpecialization: { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1936 | auto *RD = ReadDeclAs<CXXRecordDecl>(); |
| 1937 | auto TSK = (TemplateSpecializationKind)Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1938 | SourceLocation POI = ReadSourceLocation(); |
Argyrios Kyrtzidis | caf8248 | 2010-09-13 11:45:25 +0000 | [diff] [blame] | 1939 | MemberSpecializationInfo *MSI = new (C) MemberSpecializationInfo(RD, TSK); |
| 1940 | MSI->setPointOfInstantiation(POI); |
| 1941 | D->TemplateOrInstantiation = MSI; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1942 | mergeRedeclarable(D, Redecl); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 1943 | break; |
| 1944 | } |
| 1945 | } |
Argyrios Kyrtzidis | 6843141 | 2010-10-14 20:14:38 +0000 | [diff] [blame] | 1946 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1947 | bool WasDefinition = Record.readInt(); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1948 | if (WasDefinition) |
Richard Smith | 2a9e5c5 | 2015-02-03 03:32:14 +0000 | [diff] [blame] | 1949 | ReadCXXRecordDefinition(D, /*Update*/false); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1950 | else |
| 1951 | // Propagate DefinitionData pointer from the canonical declaration. |
| 1952 | D->DefinitionData = D->getCanonicalDecl()->DefinitionData; |
| 1953 | |
Richard Smith | 676c404 | 2013-08-29 23:59:27 +0000 | [diff] [blame] | 1954 | // 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] | 1955 | // compute it. |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 1956 | if (WasDefinition) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1957 | DeclID KeyFn = ReadDeclID(); |
Erich Keane | f92f31c | 2018-08-01 20:48:16 +0000 | [diff] [blame] | 1958 | if (KeyFn && D->isCompleteDefinition()) |
Richard Smith | a9a1c68 | 2014-07-07 06:38:20 +0000 | [diff] [blame] | 1959 | // FIXME: This is wrong for the ARM ABI, where some other module may have |
| 1960 | // made this function no longer be a key function. We need an update |
| 1961 | // record or similar for that case. |
Richard Smith | 676c404 | 2013-08-29 23:59:27 +0000 | [diff] [blame] | 1962 | C.KeyFunctions[D] = KeyFn; |
Argyrios Kyrtzidis | 6843141 | 2010-10-14 20:14:38 +0000 | [diff] [blame] | 1963 | } |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 1964 | |
| 1965 | return Redecl; |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1966 | } |
| 1967 | |
Richard Smith | bc49120 | 2017-02-17 20:05:37 +0000 | [diff] [blame] | 1968 | void ASTDeclReader::VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D) { |
| 1969 | VisitFunctionDecl(D); |
Erich Keane | 9c66506 | 2018-08-01 21:02:40 +0000 | [diff] [blame] | 1970 | D->setIsCopyDeductionCandidate(Record.readInt()); |
Richard Smith | bc49120 | 2017-02-17 20:05:37 +0000 | [diff] [blame] | 1971 | } |
| 1972 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1973 | void ASTDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1974 | VisitFunctionDecl(D); |
Richard Smith | b110873 | 2014-08-26 23:29:11 +0000 | [diff] [blame] | 1975 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1976 | unsigned NumOverridenMethods = Record.readInt(); |
Richard Smith | b110873 | 2014-08-26 23:29:11 +0000 | [diff] [blame] | 1977 | if (D->isCanonicalDecl()) { |
| 1978 | while (NumOverridenMethods--) { |
| 1979 | // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod, |
| 1980 | // MD may be initializing. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1981 | if (auto *MD = ReadDeclAs<CXXMethodDecl>()) |
Richard Smith | b110873 | 2014-08-26 23:29:11 +0000 | [diff] [blame] | 1982 | Reader.getContext().addOverriddenMethod(D, MD->getCanonicalDecl()); |
| 1983 | } |
| 1984 | } else { |
| 1985 | // We don't care about which declarations this used to override; we get |
| 1986 | // the relevant information from the canonical declaration. |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1987 | Record.skipInts(NumOverridenMethods); |
Argyrios Kyrtzidis | 6685e8a | 2010-07-04 21:44:35 +0000 | [diff] [blame] | 1988 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1989 | } |
| 1990 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1991 | void ASTDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) { |
Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 1992 | // We need the inherited constructor information to merge the declaration, |
| 1993 | // so we have to read it before we call VisitCXXMethodDecl. |
| 1994 | if (D->isInheritingConstructor()) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1995 | auto *Shadow = ReadDeclAs<ConstructorUsingShadowDecl>(); |
| 1996 | auto *Ctor = ReadDeclAs<CXXConstructorDecl>(); |
Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 1997 | *D->getTrailingObjects<InheritedConstructor>() = |
| 1998 | InheritedConstructor(Shadow, Ctor); |
| 1999 | } |
| 2000 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 2001 | VisitCXXMethodDecl(D); |
| 2002 | } |
| 2003 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 2004 | void ASTDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 2005 | VisitCXXMethodDecl(D); |
Argyrios Kyrtzidis | 3357516 | 2010-07-02 15:58:43 +0000 | [diff] [blame] | 2006 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2007 | if (auto *OperatorDelete = ReadDeclAs<FunctionDecl>()) { |
George Burgess IV | 00f70bd | 2018-03-01 05:43:23 +0000 | [diff] [blame] | 2008 | CXXDestructorDecl *Canon = D->getCanonicalDecl(); |
Richard Smith | 5b34958 | 2017-10-13 01:55:36 +0000 | [diff] [blame] | 2009 | auto *ThisArg = Record.readExpr(); |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 2010 | // FIXME: Check consistency if we have an old and new operator delete. |
Richard Smith | 5b34958 | 2017-10-13 01:55:36 +0000 | [diff] [blame] | 2011 | if (!Canon->OperatorDelete) { |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 2012 | Canon->OperatorDelete = OperatorDelete; |
Richard Smith | 5b34958 | 2017-10-13 01:55:36 +0000 | [diff] [blame] | 2013 | Canon->OperatorDeleteThisArg = ThisArg; |
| 2014 | } |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 2015 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 2016 | } |
| 2017 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 2018 | void ASTDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 2019 | VisitCXXMethodDecl(D); |
| 2020 | } |
| 2021 | |
Douglas Gregor | ba34552 | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 2022 | void ASTDeclReader::VisitImportDecl(ImportDecl *D) { |
| 2023 | VisitDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2024 | D->ImportedAndComplete.setPointer(readModule()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2025 | D->ImportedAndComplete.setInt(Record.readInt()); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2026 | auto *StoredLocs = D->getTrailingObjects<SourceLocation>(); |
Douglas Gregor | ba34552 | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 2027 | for (unsigned I = 0, N = Record.back(); I != N; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2028 | StoredLocs[I] = ReadSourceLocation(); |
David L. Jones | 267b884 | 2017-01-24 01:04:30 +0000 | [diff] [blame] | 2029 | Record.skipInts(1); // The number of stored source locations. |
Douglas Gregor | ba34552 | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 2030 | } |
| 2031 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 2032 | void ASTDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) { |
Abramo Bagnara | d734058 | 2010-06-05 05:09:32 +0000 | [diff] [blame] | 2033 | VisitDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2034 | D->setColonLoc(ReadSourceLocation()); |
Abramo Bagnara | d734058 | 2010-06-05 05:09:32 +0000 | [diff] [blame] | 2035 | } |
| 2036 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 2037 | void ASTDeclReader::VisitFriendDecl(FriendDecl *D) { |
Argyrios Kyrtzidis | a95d019 | 2010-07-05 10:38:01 +0000 | [diff] [blame] | 2038 | VisitDecl(D); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2039 | if (Record.readInt()) // hasFriendDecl |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2040 | D->Friend = ReadDeclAs<NamedDecl>(); |
Enea Zaffanella | eb22c87 | 2013-01-31 09:54:08 +0000 | [diff] [blame] | 2041 | else |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2042 | D->Friend = GetTypeSourceInfo(); |
Enea Zaffanella | eb22c87 | 2013-01-31 09:54:08 +0000 | [diff] [blame] | 2043 | for (unsigned i = 0; i != D->NumTPLists; ++i) |
James Y Knight | 967eb20 | 2015-12-29 22:13:13 +0000 | [diff] [blame] | 2044 | D->getTrailingObjects<TemplateParameterList *>()[i] = |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2045 | Record.readTemplateParameterList(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2046 | D->NextFriend = ReadDeclID(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2047 | D->UnsupportedFriend = (Record.readInt() != 0); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2048 | D->FriendLoc = ReadSourceLocation(); |
Argyrios Kyrtzidis | 74d28bd | 2010-06-29 22:47:00 +0000 | [diff] [blame] | 2049 | } |
| 2050 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 2051 | void ASTDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) { |
Argyrios Kyrtzidis | 165b581 | 2010-07-22 16:04:10 +0000 | [diff] [blame] | 2052 | VisitDecl(D); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2053 | unsigned NumParams = Record.readInt(); |
Argyrios Kyrtzidis | 165b581 | 2010-07-22 16:04:10 +0000 | [diff] [blame] | 2054 | D->NumParams = NumParams; |
| 2055 | D->Params = new TemplateParameterList*[NumParams]; |
| 2056 | for (unsigned i = 0; i != NumParams; ++i) |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2057 | D->Params[i] = Record.readTemplateParameterList(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2058 | if (Record.readInt()) // HasFriendDecl |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2059 | D->Friend = ReadDeclAs<NamedDecl>(); |
Argyrios Kyrtzidis | 165b581 | 2010-07-22 16:04:10 +0000 | [diff] [blame] | 2060 | else |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2061 | D->Friend = GetTypeSourceInfo(); |
| 2062 | D->FriendLoc = ReadSourceLocation(); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 2063 | } |
| 2064 | |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2065 | DeclID ASTDeclReader::VisitTemplateDecl(TemplateDecl *D) { |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 2066 | VisitNamedDecl(D); |
| 2067 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2068 | DeclID PatternID = ReadDeclID(); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2069 | auto *TemplatedDecl = cast_or_null<NamedDecl>(Reader.GetDecl(PatternID)); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2070 | TemplateParameterList *TemplateParams = Record.readTemplateParameterList(); |
Hubert Tong | 5a8ec4e | 2017-02-10 02:46:19 +0000 | [diff] [blame] | 2071 | // FIXME handle associated constraints |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 2072 | D->init(TemplatedDecl, TemplateParams); |
Richard Smith | bf78e64 | 2013-06-24 22:51:00 +0000 | [diff] [blame] | 2073 | |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2074 | return PatternID; |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 2075 | } |
| 2076 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2077 | ASTDeclReader::RedeclarableResult |
Douglas Gregor | 5407920 | 2012-01-06 22:05:37 +0000 | [diff] [blame] | 2078 | ASTDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) { |
Douglas Gregor | 68444de | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 2079 | RedeclarableResult Redecl = VisitRedeclarable(D); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 2080 | |
Douglas Gregor | 68444de | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 2081 | // Make sure we've allocated the Common pointer first. We do this before |
| 2082 | // VisitTemplateDecl so that getCommonPtr() can be used during initialization. |
| 2083 | RedeclarableTemplateDecl *CanonD = D->getCanonicalDecl(); |
| 2084 | if (!CanonD->Common) { |
| 2085 | CanonD->Common = CanonD->newCommon(Reader.getContext()); |
| 2086 | Reader.PendingDefinitions.insert(CanonD); |
| 2087 | } |
| 2088 | D->Common = CanonD->Common; |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 2089 | |
Douglas Gregor | 68444de | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 2090 | // If this is the first declaration of the template, fill in the information |
| 2091 | // for the 'common' pointer. |
| 2092 | if (ThisDeclID == Redecl.getFirstID()) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2093 | if (auto *RTD = ReadDeclAs<RedeclarableTemplateDecl>()) { |
Peter Collingbourne | 91b25b7 | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 2094 | assert(RTD->getKind() == D->getKind() && |
| 2095 | "InstantiatedFromMemberTemplate kind mismatch"); |
Douglas Gregor | 68444de | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 2096 | D->setInstantiatedFromMemberTemplate(RTD); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2097 | if (Record.readInt()) |
Peter Collingbourne | 91b25b7 | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 2098 | D->setMemberSpecialization(); |
| 2099 | } |
| 2100 | } |
Axel Naumann | 866ba3e | 2012-10-01 09:18:00 +0000 | [diff] [blame] | 2101 | |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2102 | DeclID PatternID = VisitTemplateDecl(D); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2103 | D->IdentifierNamespace = Record.readInt(); |
Axel Naumann | 866ba3e | 2012-10-01 09:18:00 +0000 | [diff] [blame] | 2104 | |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2105 | mergeRedeclarable(D, Redecl, PatternID); |
Axel Naumann | 866ba3e | 2012-10-01 09:18:00 +0000 | [diff] [blame] | 2106 | |
Richard Smith | d46d6de | 2013-10-13 23:50:45 +0000 | [diff] [blame] | 2107 | // If we merged the template with a prior declaration chain, merge the common |
| 2108 | // pointer. |
| 2109 | // FIXME: Actually merge here, don't just overwrite. |
| 2110 | D->Common = D->getCanonicalDecl()->Common; |
| 2111 | |
Douglas Gregor | 68444de | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 2112 | return Redecl; |
Peter Collingbourne | 91b25b7 | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 2113 | } |
| 2114 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 2115 | void ASTDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
Douglas Gregor | 68444de | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 2116 | RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D); |
Peter Collingbourne | 91b25b7 | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 2117 | |
Douglas Gregor | 68444de | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 2118 | if (ThisDeclID == Redecl.getFirstID()) { |
Douglas Gregor | 7e8c4e0 | 2010-10-27 22:21:36 +0000 | [diff] [blame] | 2119 | // This ClassTemplateDecl owns a CommonPtr; read it to keep track of all of |
| 2120 | // the specializations. |
Richard Smith | 0b88437 | 2015-02-27 00:25:58 +0000 | [diff] [blame] | 2121 | SmallVector<serialization::DeclID, 32> SpecIDs; |
Richard Smith | 0b88437 | 2015-02-27 00:25:58 +0000 | [diff] [blame] | 2122 | ReadDeclIDList(SpecIDs); |
Vassil Vassilev | 7d26462 | 2017-06-30 22:40:17 +0000 | [diff] [blame] | 2123 | ASTDeclReader::AddLazySpecializations(D, SpecIDs); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 2124 | } |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2125 | |
| 2126 | if (D->getTemplatedDecl()->TemplateOrInstantiation) { |
| 2127 | // We were loaded before our templated declaration was. We've not set up |
| 2128 | // its corresponding type yet (see VisitCXXRecordDeclImpl), so reconstruct |
| 2129 | // it now. |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 2130 | Reader.getContext().getInjectedClassNameType( |
Richard Smith | a1406fa | 2014-05-23 21:31:59 +0000 | [diff] [blame] | 2131 | D->getTemplatedDecl(), D->getInjectedClassNameSpecialization()); |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2132 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 2133 | } |
| 2134 | |
David Majnemer | d9b1a4f | 2015-11-04 03:40:30 +0000 | [diff] [blame] | 2135 | void ASTDeclReader::VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D) { |
| 2136 | llvm_unreachable("BuiltinTemplates are not serialized"); |
| 2137 | } |
| 2138 | |
Larisse Voufo | 3061638 | 2013-08-23 22:21:36 +0000 | [diff] [blame] | 2139 | /// TODO: Unify with ClassTemplateDecl version? |
| 2140 | /// May require unifying ClassTemplateDecl and |
| 2141 | /// VarTemplateDecl beyond TemplateDecl... |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2142 | void ASTDeclReader::VisitVarTemplateDecl(VarTemplateDecl *D) { |
| 2143 | RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D); |
| 2144 | |
| 2145 | if (ThisDeclID == Redecl.getFirstID()) { |
Larisse Voufo | d8dd97c | 2013-08-14 03:09:19 +0000 | [diff] [blame] | 2146 | // 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] | 2147 | // the specializations. |
Richard Smith | 0b88437 | 2015-02-27 00:25:58 +0000 | [diff] [blame] | 2148 | SmallVector<serialization::DeclID, 32> SpecIDs; |
Richard Smith | 0b88437 | 2015-02-27 00:25:58 +0000 | [diff] [blame] | 2149 | ReadDeclIDList(SpecIDs); |
Vassil Vassilev | 7d26462 | 2017-06-30 22:40:17 +0000 | [diff] [blame] | 2150 | ASTDeclReader::AddLazySpecializations(D, SpecIDs); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2151 | } |
| 2152 | } |
| 2153 | |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 2154 | ASTDeclReader::RedeclarableResult |
| 2155 | ASTDeclReader::VisitClassTemplateSpecializationDeclImpl( |
| 2156 | ClassTemplateSpecializationDecl *D) { |
| 2157 | RedeclarableResult Redecl = VisitCXXRecordDeclImpl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2158 | |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2159 | ASTContext &C = Reader.getContext(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2160 | if (Decl *InstD = ReadDecl()) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2161 | if (auto *CTD = dyn_cast<ClassTemplateDecl>(InstD)) { |
Argyrios Kyrtzidis | b4c659b | 2010-09-13 11:45:32 +0000 | [diff] [blame] | 2162 | D->SpecializedTemplate = CTD; |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 2163 | } else { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2164 | SmallVector<TemplateArgument, 8> TemplArgs; |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2165 | Record.readTemplateArgumentList(TemplArgs); |
Argyrios Kyrtzidis | b4c659b | 2010-09-13 11:45:32 +0000 | [diff] [blame] | 2166 | TemplateArgumentList *ArgList |
David Majnemer | 8b62269 | 2016-07-03 21:17:51 +0000 | [diff] [blame] | 2167 | = TemplateArgumentList::CreateCopy(C, TemplArgs); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2168 | auto *PS = |
| 2169 | new (C) ClassTemplateSpecializationDecl:: |
Argyrios Kyrtzidis | b4c659b | 2010-09-13 11:45:32 +0000 | [diff] [blame] | 2170 | SpecializedPartialSpecialization(); |
| 2171 | PS->PartialSpecialization |
| 2172 | = cast<ClassTemplatePartialSpecializationDecl>(InstD); |
| 2173 | PS->TemplateArgs = ArgList; |
| 2174 | D->SpecializedTemplate = PS; |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 2175 | } |
| 2176 | } |
| 2177 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2178 | SmallVector<TemplateArgument, 8> TemplArgs; |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2179 | Record.readTemplateArgumentList(TemplArgs, /*Canonicalize*/ true); |
David Majnemer | 8b62269 | 2016-07-03 21:17:51 +0000 | [diff] [blame] | 2180 | D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2181 | D->PointOfInstantiation = ReadSourceLocation(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2182 | D->SpecializationKind = (TemplateSpecializationKind)Record.readInt(); |
Axel Naumann | a31dee2 | 2012-10-01 07:34:47 +0000 | [diff] [blame] | 2183 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2184 | bool writtenAsCanonicalDecl = Record.readInt(); |
Axel Naumann | a31dee2 | 2012-10-01 07:34:47 +0000 | [diff] [blame] | 2185 | if (writtenAsCanonicalDecl) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2186 | auto *CanonPattern = ReadDeclAs<ClassTemplateDecl>(); |
Axel Naumann | a31dee2 | 2012-10-01 07:34:47 +0000 | [diff] [blame] | 2187 | if (D->isCanonicalDecl()) { // It's kept in the folding set. |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2188 | // Set this as, or find, the canonical declaration for this specialization |
| 2189 | ClassTemplateSpecializationDecl *CanonSpec; |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2190 | if (auto *Partial = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) { |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2191 | CanonSpec = CanonPattern->getCommonPtr()->PartialSpecializations |
Richard Smith | 5de91b5 | 2013-06-25 01:25:15 +0000 | [diff] [blame] | 2192 | .GetOrInsertNode(Partial); |
Axel Naumann | a31dee2 | 2012-10-01 07:34:47 +0000 | [diff] [blame] | 2193 | } else { |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2194 | CanonSpec = |
| 2195 | CanonPattern->getCommonPtr()->Specializations.GetOrInsertNode(D); |
| 2196 | } |
| 2197 | // If there was already a canonical specialization, merge into it. |
| 2198 | if (CanonSpec != D) { |
| 2199 | mergeRedeclarable<TagDecl>(D, CanonSpec, Redecl); |
| 2200 | |
| 2201 | // This declaration might be a definition. Merge with any existing |
| 2202 | // definition. |
Richard Smith | b648399 | 2016-05-17 22:44:15 +0000 | [diff] [blame] | 2203 | if (auto *DDD = D->DefinitionData) { |
| 2204 | if (CanonSpec->DefinitionData) |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 2205 | MergeDefinitionData(CanonSpec, std::move(*DDD)); |
Richard Smith | 97100e3 | 2015-06-20 00:22:34 +0000 | [diff] [blame] | 2206 | else |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 2207 | CanonSpec->DefinitionData = D->DefinitionData; |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2208 | } |
Richard Smith | 547864d | 2014-07-11 18:22:58 +0000 | [diff] [blame] | 2209 | D->DefinitionData = CanonSpec->DefinitionData; |
Axel Naumann | a31dee2 | 2012-10-01 07:34:47 +0000 | [diff] [blame] | 2210 | } |
Argyrios Kyrtzidis | 8704057 | 2010-07-09 21:11:43 +0000 | [diff] [blame] | 2211 | } |
| 2212 | } |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 2213 | |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2214 | // Explicit info. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2215 | if (TypeSourceInfo *TyInfo = GetTypeSourceInfo()) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2216 | auto *ExplicitInfo = |
| 2217 | new (C) ClassTemplateSpecializationDecl::ExplicitSpecializationInfo; |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2218 | ExplicitInfo->TypeAsWritten = TyInfo; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2219 | ExplicitInfo->ExternLoc = ReadSourceLocation(); |
| 2220 | ExplicitInfo->TemplateKeywordLoc = ReadSourceLocation(); |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2221 | D->ExplicitInfo = ExplicitInfo; |
| 2222 | } |
| 2223 | |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 2224 | return Redecl; |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 2225 | } |
| 2226 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 2227 | void ASTDeclReader::VisitClassTemplatePartialSpecializationDecl( |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 2228 | ClassTemplatePartialSpecializationDecl *D) { |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 2229 | RedeclarableResult Redecl = VisitClassTemplateSpecializationDeclImpl(D); |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 2230 | |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2231 | D->TemplateParams = Record.readTemplateParameterList(); |
| 2232 | D->ArgsAsWritten = Record.readASTTemplateArgumentListInfo(); |
Argyrios Kyrtzidis | 0e8b3ce | 2010-09-13 11:45:41 +0000 | [diff] [blame] | 2233 | |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 2234 | // These are read/set from/to the first declaration. |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 2235 | if (ThisDeclID == Redecl.getFirstID()) { |
Argyrios Kyrtzidis | 0e8b3ce | 2010-09-13 11:45:41 +0000 | [diff] [blame] | 2236 | D->InstantiatedFromMember.setPointer( |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2237 | ReadDeclAs<ClassTemplatePartialSpecializationDecl>()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2238 | D->InstantiatedFromMember.setInt(Record.readInt()); |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 2239 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 2240 | } |
| 2241 | |
Sebastian Redl | b744863 | 2011-08-31 13:59:56 +0000 | [diff] [blame] | 2242 | void ASTDeclReader::VisitClassScopeFunctionSpecializationDecl( |
| 2243 | ClassScopeFunctionSpecializationDecl *D) { |
Francois Pichet | 09af8c3 | 2011-08-17 01:06:54 +0000 | [diff] [blame] | 2244 | VisitDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2245 | D->Specialization = ReadDeclAs<CXXMethodDecl>(); |
Francois Pichet | 09af8c3 | 2011-08-17 01:06:54 +0000 | [diff] [blame] | 2246 | } |
| 2247 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 2248 | void ASTDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
Douglas Gregor | 68444de | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 2249 | RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D); |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 2250 | |
Douglas Gregor | 68444de | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 2251 | if (ThisDeclID == Redecl.getFirstID()) { |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 2252 | // This FunctionTemplateDecl owns a CommonPtr; read it. |
Richard Smith | 0b88437 | 2015-02-27 00:25:58 +0000 | [diff] [blame] | 2253 | SmallVector<serialization::DeclID, 32> SpecIDs; |
| 2254 | ReadDeclIDList(SpecIDs); |
Vassil Vassilev | 7d26462 | 2017-06-30 22:40:17 +0000 | [diff] [blame] | 2255 | ASTDeclReader::AddLazySpecializations(D, SpecIDs); |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 2256 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 2257 | } |
| 2258 | |
Larisse Voufo | 3061638 | 2013-08-23 22:21:36 +0000 | [diff] [blame] | 2259 | /// TODO: Unify with ClassTemplateSpecializationDecl version? |
| 2260 | /// May require unifying ClassTemplate(Partial)SpecializationDecl and |
| 2261 | /// VarTemplate(Partial)SpecializationDecl with a new data |
| 2262 | /// structure Template(Partial)SpecializationDecl, and |
| 2263 | /// using Template(Partial)SpecializationDecl as input type. |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2264 | ASTDeclReader::RedeclarableResult |
| 2265 | ASTDeclReader::VisitVarTemplateSpecializationDeclImpl( |
| 2266 | VarTemplateSpecializationDecl *D) { |
| 2267 | RedeclarableResult Redecl = VisitVarDeclImpl(D); |
| 2268 | |
| 2269 | ASTContext &C = Reader.getContext(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2270 | if (Decl *InstD = ReadDecl()) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2271 | if (auto *VTD = dyn_cast<VarTemplateDecl>(InstD)) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2272 | D->SpecializedTemplate = VTD; |
| 2273 | } else { |
| 2274 | SmallVector<TemplateArgument, 8> TemplArgs; |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2275 | Record.readTemplateArgumentList(TemplArgs); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2276 | TemplateArgumentList *ArgList = TemplateArgumentList::CreateCopy( |
David Majnemer | 8b62269 | 2016-07-03 21:17:51 +0000 | [diff] [blame] | 2277 | C, TemplArgs); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2278 | auto *PS = |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2279 | new (C) |
| 2280 | VarTemplateSpecializationDecl::SpecializedPartialSpecialization(); |
| 2281 | PS->PartialSpecialization = |
| 2282 | cast<VarTemplatePartialSpecializationDecl>(InstD); |
| 2283 | PS->TemplateArgs = ArgList; |
| 2284 | D->SpecializedTemplate = PS; |
| 2285 | } |
| 2286 | } |
| 2287 | |
| 2288 | // Explicit info. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2289 | if (TypeSourceInfo *TyInfo = GetTypeSourceInfo()) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2290 | auto *ExplicitInfo = |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2291 | new (C) VarTemplateSpecializationDecl::ExplicitSpecializationInfo; |
| 2292 | ExplicitInfo->TypeAsWritten = TyInfo; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2293 | ExplicitInfo->ExternLoc = ReadSourceLocation(); |
| 2294 | ExplicitInfo->TemplateKeywordLoc = ReadSourceLocation(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2295 | D->ExplicitInfo = ExplicitInfo; |
| 2296 | } |
| 2297 | |
| 2298 | SmallVector<TemplateArgument, 8> TemplArgs; |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2299 | Record.readTemplateArgumentList(TemplArgs, /*Canonicalize*/ true); |
David Majnemer | 8b62269 | 2016-07-03 21:17:51 +0000 | [diff] [blame] | 2300 | D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2301 | D->PointOfInstantiation = ReadSourceLocation(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2302 | D->SpecializationKind = (TemplateSpecializationKind)Record.readInt(); |
Richard Smith | 435e647 | 2017-12-02 02:48:42 +0000 | [diff] [blame] | 2303 | D->IsCompleteDefinition = Record.readInt(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2304 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2305 | bool writtenAsCanonicalDecl = Record.readInt(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2306 | if (writtenAsCanonicalDecl) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2307 | auto *CanonPattern = ReadDeclAs<VarTemplateDecl>(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2308 | if (D->isCanonicalDecl()) { // It's kept in the folding set. |
Richard Smith | 9b88a4c | 2015-07-27 05:40:23 +0000 | [diff] [blame] | 2309 | // FIXME: If it's already present, merge it. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2310 | if (auto *Partial = dyn_cast<VarTemplatePartialSpecializationDecl>(D)) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2311 | CanonPattern->getCommonPtr()->PartialSpecializations |
| 2312 | .GetOrInsertNode(Partial); |
| 2313 | } else { |
| 2314 | CanonPattern->getCommonPtr()->Specializations.GetOrInsertNode(D); |
| 2315 | } |
| 2316 | } |
| 2317 | } |
| 2318 | |
| 2319 | return Redecl; |
| 2320 | } |
| 2321 | |
Larisse Voufo | 3061638 | 2013-08-23 22:21:36 +0000 | [diff] [blame] | 2322 | /// TODO: Unify with ClassTemplatePartialSpecializationDecl version? |
| 2323 | /// May require unifying ClassTemplate(Partial)SpecializationDecl and |
| 2324 | /// VarTemplate(Partial)SpecializationDecl with a new data |
| 2325 | /// structure Template(Partial)SpecializationDecl, and |
| 2326 | /// using Template(Partial)SpecializationDecl as input type. |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2327 | void ASTDeclReader::VisitVarTemplatePartialSpecializationDecl( |
| 2328 | VarTemplatePartialSpecializationDecl *D) { |
| 2329 | RedeclarableResult Redecl = VisitVarTemplateSpecializationDeclImpl(D); |
| 2330 | |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2331 | D->TemplateParams = Record.readTemplateParameterList(); |
| 2332 | D->ArgsAsWritten = Record.readASTTemplateArgumentListInfo(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2333 | |
| 2334 | // These are read/set from/to the first declaration. |
| 2335 | if (ThisDeclID == Redecl.getFirstID()) { |
| 2336 | D->InstantiatedFromMember.setPointer( |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2337 | ReadDeclAs<VarTemplatePartialSpecializationDecl>()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2338 | D->InstantiatedFromMember.setInt(Record.readInt()); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2339 | } |
| 2340 | } |
| 2341 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 2342 | void ASTDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 2343 | VisitTypeDecl(D); |
| 2344 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2345 | D->setDeclaredWithTypename(Record.readInt()); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 2346 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2347 | if (Record.readInt()) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2348 | D->setDefaultArgument(GetTypeSourceInfo()); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 2349 | } |
| 2350 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 2351 | void ASTDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { |
John McCall | f4cd4f9 | 2011-02-09 01:13:10 +0000 | [diff] [blame] | 2352 | VisitDeclaratorDecl(D); |
Argyrios Kyrtzidis | b1d38e3 | 2010-06-25 16:25:09 +0000 | [diff] [blame] | 2353 | // TemplateParmPosition. |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2354 | D->setDepth(Record.readInt()); |
| 2355 | D->setPosition(Record.readInt()); |
Douglas Gregor | 0231d8d | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 2356 | if (D->isExpandedParameterPack()) { |
James Y Knight | 967eb20 | 2015-12-29 22:13:13 +0000 | [diff] [blame] | 2357 | auto TypesAndInfos = |
| 2358 | D->getTrailingObjects<std::pair<QualType, TypeSourceInfo *>>(); |
Douglas Gregor | 0231d8d | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 2359 | for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2360 | new (&TypesAndInfos[I].first) QualType(Record.readType()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2361 | TypesAndInfos[I].second = GetTypeSourceInfo(); |
Douglas Gregor | 0231d8d | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 2362 | } |
| 2363 | } else { |
| 2364 | // Rest of NonTypeTemplateParmDecl. |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2365 | D->ParameterPack = Record.readInt(); |
| 2366 | if (Record.readInt()) |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2367 | D->setDefaultArgument(Record.readExpr()); |
Douglas Gregor | 0231d8d | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 2368 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 2369 | } |
| 2370 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 2371 | void ASTDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { |
Argyrios Kyrtzidis | 9f2d24a | 2010-07-08 17:12:57 +0000 | [diff] [blame] | 2372 | VisitTemplateDecl(D); |
| 2373 | // TemplateParmPosition. |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2374 | D->setDepth(Record.readInt()); |
| 2375 | D->setPosition(Record.readInt()); |
Richard Smith | 1fde8ec | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 2376 | if (D->isExpandedParameterPack()) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2377 | auto **Data = D->getTrailingObjects<TemplateParameterList *>(); |
Richard Smith | 1fde8ec | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 2378 | for (unsigned I = 0, N = D->getNumExpansionTemplateParameters(); |
| 2379 | I != N; ++I) |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2380 | Data[I] = Record.readTemplateParameterList(); |
Richard Smith | 1fde8ec | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 2381 | } else { |
| 2382 | // Rest of TemplateTemplateParmDecl. |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2383 | D->ParameterPack = Record.readInt(); |
| 2384 | if (Record.readInt()) |
Richard Smith | 1469b91 | 2015-06-10 00:29:03 +0000 | [diff] [blame] | 2385 | D->setDefaultArgument(Reader.getContext(), |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2386 | Record.readTemplateArgumentLoc()); |
Richard Smith | 1fde8ec | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 2387 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 2388 | } |
| 2389 | |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 2390 | void ASTDeclReader::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { |
| 2391 | VisitRedeclarableTemplateDecl(D); |
| 2392 | } |
| 2393 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 2394 | void ASTDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) { |
Argyrios Kyrtzidis | 2d8891c | 2010-07-22 17:28:12 +0000 | [diff] [blame] | 2395 | VisitDecl(D); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2396 | D->AssertExprAndFailed.setPointer(Record.readExpr()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2397 | D->AssertExprAndFailed.setInt(Record.readInt()); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2398 | D->Message = cast_or_null<StringLiteral>(Record.readExpr()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2399 | D->RParenLoc = ReadSourceLocation(); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 2400 | } |
| 2401 | |
Michael Han | 8432435 | 2013-02-22 17:15:32 +0000 | [diff] [blame] | 2402 | void ASTDeclReader::VisitEmptyDecl(EmptyDecl *D) { |
| 2403 | VisitDecl(D); |
| 2404 | } |
| 2405 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2406 | std::pair<uint64_t, uint64_t> |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 2407 | ASTDeclReader::VisitDeclContext(DeclContext *DC) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2408 | uint64_t LexicalOffset = ReadLocalOffset(); |
| 2409 | uint64_t VisibleOffset = ReadLocalOffset(); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 2410 | return std::make_pair(LexicalOffset, VisibleOffset); |
| 2411 | } |
| 2412 | |
Argyrios Kyrtzidis | 839bbac | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 2413 | template <typename T> |
Richard Smith | 5a4737c | 2015-02-06 02:42:59 +0000 | [diff] [blame] | 2414 | ASTDeclReader::RedeclarableResult |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 2415 | ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2416 | DeclID FirstDeclID = ReadDeclID(); |
Richard Smith | 5a4737c | 2015-02-06 02:42:59 +0000 | [diff] [blame] | 2417 | Decl *MergeWith = nullptr; |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 2418 | |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 2419 | bool IsKeyDecl = ThisDeclID == FirstDeclID; |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 2420 | bool IsFirstLocalDecl = false; |
Richard Smith | 5a4737c | 2015-02-06 02:42:59 +0000 | [diff] [blame] | 2421 | |
Richard Smith | d61d4ac | 2015-08-22 20:13:39 +0000 | [diff] [blame] | 2422 | uint64_t RedeclOffset = 0; |
| 2423 | |
Douglas Gregor | 358cd44 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 2424 | // 0 indicates that this declaration was the only declaration of its entity, |
| 2425 | // and is used for space optimization. |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 2426 | if (FirstDeclID == 0) { |
Douglas Gregor | 074a409 | 2011-12-19 18:19:24 +0000 | [diff] [blame] | 2427 | FirstDeclID = ThisDeclID; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 2428 | IsKeyDecl = true; |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 2429 | IsFirstLocalDecl = true; |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2430 | } else if (unsigned N = Record.readInt()) { |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 2431 | // This declaration was the first local declaration, but may have imported |
| 2432 | // other declarations. |
| 2433 | IsKeyDecl = N == 1; |
| 2434 | IsFirstLocalDecl = true; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 2435 | |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 2436 | // We have some declarations that must be before us in our redeclaration |
| 2437 | // chain. Read them now, and remember that we ought to merge with one of |
| 2438 | // them. |
| 2439 | // FIXME: Provide a known merge target to the second and subsequent such |
| 2440 | // declaration. |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 2441 | for (unsigned I = 0; I != N - 1; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2442 | MergeWith = ReadDecl(); |
Richard Smith | d61d4ac | 2015-08-22 20:13:39 +0000 | [diff] [blame] | 2443 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2444 | RedeclOffset = ReadLocalOffset(); |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 2445 | } else { |
| 2446 | // This declaration was not the first local declaration. Read the first |
| 2447 | // local declaration now, to trigger the import of other redeclarations. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2448 | (void)ReadDecl(); |
Richard Smith | 5a4737c | 2015-02-06 02:42:59 +0000 | [diff] [blame] | 2449 | } |
| 2450 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2451 | auto *FirstDecl = cast_or_null<T>(Reader.GetDecl(FirstDeclID)); |
Douglas Gregor | 358cd44 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 2452 | if (FirstDecl != D) { |
Argyrios Kyrtzidis | 9fdd254 | 2011-02-12 07:50:47 +0000 | [diff] [blame] | 2453 | // We delay loading of the redeclaration chain to avoid deeply nested calls. |
| 2454 | // We temporarily set the first (canonical) declaration as the previous one |
| 2455 | // which is the one that matters and mark the real previous DeclID to be |
| 2456 | // loaded & attached later on. |
David Blaikie | 7e64fd9 | 2012-05-28 19:38:42 +0000 | [diff] [blame] | 2457 | D->RedeclLink = Redeclarable<T>::PreviousDeclLink(FirstDecl); |
Manuel Klimek | 093b2d4 | 2015-03-25 23:18:30 +0000 | [diff] [blame] | 2458 | D->First = FirstDecl->getCanonicalDecl(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2459 | } |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 2460 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2461 | auto *DAsT = static_cast<T *>(D); |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 2462 | |
| 2463 | // Note that we need to load local redeclarations of this decl and build a |
| 2464 | // decl chain for them. This must happen *after* we perform the preloading |
| 2465 | // above; this ensures that the redeclaration chain is built in the correct |
| 2466 | // order. |
| 2467 | if (IsFirstLocalDecl) |
Richard Smith | d61d4ac | 2015-08-22 20:13:39 +0000 | [diff] [blame] | 2468 | Reader.PendingDeclChains.push_back(std::make_pair(DAsT, RedeclOffset)); |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 2469 | |
Alexander Shaposhnikov | fbc4d68 | 2016-09-24 04:21:53 +0000 | [diff] [blame] | 2470 | return RedeclarableResult(MergeWith, FirstDeclID, IsKeyDecl); |
Argyrios Kyrtzidis | 839bbac | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 2471 | } |
| 2472 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2473 | /// Attempts to merge the given declaration (D) with another declaration |
Douglas Gregor | 2c46b5b | 2012-01-03 17:27:13 +0000 | [diff] [blame] | 2474 | /// of the same entity. |
| 2475 | template<typename T> |
Richard Smith | 5e9e56a | 2014-07-15 03:37:06 +0000 | [diff] [blame] | 2476 | void ASTDeclReader::mergeRedeclarable(Redeclarable<T> *DBase, |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2477 | RedeclarableResult &Redecl, |
| 2478 | DeclID TemplatePatternID) { |
Douglas Gregor | e097d4b | 2012-01-03 17:31:38 +0000 | [diff] [blame] | 2479 | // 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] | 2480 | if (!Reader.getContext().getLangOpts().Modules) |
Douglas Gregor | e097d4b | 2012-01-03 17:31:38 +0000 | [diff] [blame] | 2481 | return; |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2482 | |
Richard Smith | 202850a | 2015-03-10 02:57:50 +0000 | [diff] [blame] | 2483 | // If we're not the canonical declaration, we don't need to merge. |
| 2484 | if (!DBase->isFirstDecl()) |
| 2485 | return; |
| 2486 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2487 | auto *D = static_cast<T *>(DBase); |
Vassil Vassilev | 916d8be | 2016-10-06 13:18:06 +0000 | [diff] [blame] | 2488 | |
Richard Smith | 5a4737c | 2015-02-06 02:42:59 +0000 | [diff] [blame] | 2489 | if (auto *Existing = Redecl.getKnownMergeTarget()) |
| 2490 | // We already know of an existing declaration we should merge with. |
| 2491 | mergeRedeclarable(D, cast<T>(Existing), Redecl, TemplatePatternID); |
| 2492 | else if (FindExistingResult ExistingRes = findExisting(D)) |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2493 | if (T *Existing = ExistingRes) |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2494 | mergeRedeclarable(D, Existing, Redecl, TemplatePatternID); |
| 2495 | } |
| 2496 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2497 | /// "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] | 2498 | /// We use this to put code in a template that will only be valid for certain |
| 2499 | /// instantiations. |
| 2500 | template<typename T> static T assert_cast(T t) { return t; } |
| 2501 | template<typename T> static T assert_cast(...) { |
| 2502 | llvm_unreachable("bad assert_cast"); |
| 2503 | } |
| 2504 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2505 | /// Merge together the pattern declarations from two template |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2506 | /// declarations. |
| 2507 | void ASTDeclReader::mergeTemplatePattern(RedeclarableTemplateDecl *D, |
| 2508 | RedeclarableTemplateDecl *Existing, |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 2509 | DeclID DsID, bool IsKeyDecl) { |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2510 | auto *DPattern = D->getTemplatedDecl(); |
| 2511 | auto *ExistingPattern = Existing->getTemplatedDecl(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2512 | RedeclarableResult Result(/*MergeWith*/ ExistingPattern, |
| 2513 | DPattern->getCanonicalDecl()->getGlobalID(), |
Alexander Shaposhnikov | fbc4d68 | 2016-09-24 04:21:53 +0000 | [diff] [blame] | 2514 | IsKeyDecl); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2515 | |
Richard Smith | 547864d | 2014-07-11 18:22:58 +0000 | [diff] [blame] | 2516 | if (auto *DClass = dyn_cast<CXXRecordDecl>(DPattern)) { |
| 2517 | // Merge with any existing definition. |
| 2518 | // FIXME: This is duplicated in several places. Refactor. |
| 2519 | auto *ExistingClass = |
| 2520 | cast<CXXRecordDecl>(ExistingPattern)->getCanonicalDecl(); |
Richard Smith | b648399 | 2016-05-17 22:44:15 +0000 | [diff] [blame] | 2521 | if (auto *DDD = DClass->DefinitionData) { |
| 2522 | if (ExistingClass->DefinitionData) { |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 2523 | MergeDefinitionData(ExistingClass, std::move(*DDD)); |
Richard Smith | 547864d | 2014-07-11 18:22:58 +0000 | [diff] [blame] | 2524 | } else { |
| 2525 | ExistingClass->DefinitionData = DClass->DefinitionData; |
Richard Smith | 97100e3 | 2015-06-20 00:22:34 +0000 | [diff] [blame] | 2526 | // We may have skipped this before because we thought that DClass |
| 2527 | // was the canonical declaration. |
Richard Smith | 7474dd92 | 2015-03-11 18:21:02 +0000 | [diff] [blame] | 2528 | Reader.PendingDefinitions.insert(DClass); |
Richard Smith | 547864d | 2014-07-11 18:22:58 +0000 | [diff] [blame] | 2529 | } |
| 2530 | } |
| 2531 | DClass->DefinitionData = ExistingClass->DefinitionData; |
| 2532 | |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2533 | return mergeRedeclarable(DClass, cast<TagDecl>(ExistingPattern), |
| 2534 | Result); |
Richard Smith | 547864d | 2014-07-11 18:22:58 +0000 | [diff] [blame] | 2535 | } |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2536 | if (auto *DFunction = dyn_cast<FunctionDecl>(DPattern)) |
| 2537 | return mergeRedeclarable(DFunction, cast<FunctionDecl>(ExistingPattern), |
| 2538 | Result); |
| 2539 | if (auto *DVar = dyn_cast<VarDecl>(DPattern)) |
| 2540 | return mergeRedeclarable(DVar, cast<VarDecl>(ExistingPattern), Result); |
Richard Smith | f59b735 | 2014-07-28 21:16:37 +0000 | [diff] [blame] | 2541 | if (auto *DAlias = dyn_cast<TypeAliasDecl>(DPattern)) |
| 2542 | return mergeRedeclarable(DAlias, cast<TypedefNameDecl>(ExistingPattern), |
| 2543 | Result); |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2544 | llvm_unreachable("merged an unknown kind of redeclarable template"); |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 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 | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2548 | /// of the same entity. |
| 2549 | template<typename T> |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2550 | void ASTDeclReader::mergeRedeclarable(Redeclarable<T> *DBase, T *Existing, |
| 2551 | RedeclarableResult &Redecl, |
| 2552 | DeclID TemplatePatternID) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2553 | auto *D = static_cast<T *>(DBase); |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2554 | T *ExistingCanon = Existing->getCanonicalDecl(); |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2555 | T *DCanon = D->getCanonicalDecl(); |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2556 | if (ExistingCanon != DCanon) { |
Richard Smith | 202850a | 2015-03-10 02:57:50 +0000 | [diff] [blame] | 2557 | assert(DCanon->getGlobalID() == Redecl.getFirstID() && |
| 2558 | "already merged this declaration"); |
Richard Smith | 5e9e56a | 2014-07-15 03:37:06 +0000 | [diff] [blame] | 2559 | |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2560 | // Have our redeclaration link point back at the canonical declaration |
Richard Smith | 5e9e56a | 2014-07-15 03:37:06 +0000 | [diff] [blame] | 2561 | // of the existing declaration, so that this declaration has the |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2562 | // appropriate canonical declaration. |
| 2563 | D->RedeclLink = Redeclarable<T>::PreviousDeclLink(ExistingCanon); |
Manuel Klimek | 093b2d4 | 2015-03-25 23:18:30 +0000 | [diff] [blame] | 2564 | D->First = ExistingCanon; |
Vassil Vassilev | 928c825 | 2016-04-28 14:13:28 +0000 | [diff] [blame] | 2565 | ExistingCanon->Used |= D->Used; |
| 2566 | D->Used = false; |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2567 | |
| 2568 | // When we merge a namespace, update its pointer to the first namespace. |
Richard Smith | 15e32fd | 2015-03-17 02:23:11 +0000 | [diff] [blame] | 2569 | // We cannot have loaded any redeclarations of this declaration yet, so |
| 2570 | // there's nothing else that needs to be updated. |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2571 | if (auto *Namespace = dyn_cast<NamespaceDecl>(D)) |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2572 | Namespace->AnonOrFirstNamespaceAndInline.setPointer( |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2573 | assert_cast<NamespaceDecl*>(ExistingCanon)); |
| 2574 | |
| 2575 | // When we merge a template, merge its pattern. |
| 2576 | if (auto *DTemplate = dyn_cast<RedeclarableTemplateDecl>(D)) |
| 2577 | mergeTemplatePattern( |
| 2578 | DTemplate, assert_cast<RedeclarableTemplateDecl*>(ExistingCanon), |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 2579 | TemplatePatternID, Redecl.isKeyDecl()); |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2580 | |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 2581 | // If this declaration is a key declaration, make a note of that. |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 2582 | if (Redecl.isKeyDecl()) |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 2583 | Reader.KeyDecls[ExistingCanon].push_back(Redecl.getFirstID()); |
Douglas Gregor | 2c46b5b | 2012-01-03 17:27:13 +0000 | [diff] [blame] | 2584 | } |
| 2585 | } |
| 2586 | |
Bruno Cardoso Lopes | 85f87dd | 2018-04-30 22:14:29 +0000 | [diff] [blame] | 2587 | /// ODR-like semantics for C/ObjC allow us to merge tag types and a structural |
| 2588 | /// check in Sema guarantees the types can be merged (see C11 6.2.7/1 or C89 |
| 2589 | /// 6.1.2.6/1). Although most merging is done in Sema, we need to guarantee |
| 2590 | /// that some types are mergeable during deserialization, otherwise name |
| 2591 | /// lookup fails. This is the case for EnumConstantDecl. |
Benjamin Kramer | 651d0bf | 2018-05-15 21:26:47 +0000 | [diff] [blame] | 2592 | static bool allowODRLikeMergeInC(NamedDecl *ND) { |
Bruno Cardoso Lopes | 85f87dd | 2018-04-30 22:14:29 +0000 | [diff] [blame] | 2593 | if (!ND) |
| 2594 | return false; |
| 2595 | // TODO: implement merge for other necessary decls. |
Benjamin Kramer | 651d0bf | 2018-05-15 21:26:47 +0000 | [diff] [blame] | 2596 | if (isa<EnumConstantDecl>(ND)) |
Bruno Cardoso Lopes | 85f87dd | 2018-04-30 22:14:29 +0000 | [diff] [blame] | 2597 | return true; |
| 2598 | return false; |
| 2599 | } |
| 2600 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2601 | /// Attempts to merge the given declaration (D) with another declaration |
Richard Smith | 0b87e07 | 2013-10-07 08:02:11 +0000 | [diff] [blame] | 2602 | /// of the same entity, for the case where the entity is not actually |
| 2603 | /// redeclarable. This happens, for instance, when merging the fields of |
| 2604 | /// identical class definitions from two different modules. |
| 2605 | template<typename T> |
| 2606 | void ASTDeclReader::mergeMergeable(Mergeable<T> *D) { |
| 2607 | // If modules are not available, there is no reason to perform this merge. |
| 2608 | if (!Reader.getContext().getLangOpts().Modules) |
| 2609 | return; |
| 2610 | |
Bruno Cardoso Lopes | 85f87dd | 2018-04-30 22:14:29 +0000 | [diff] [blame] | 2611 | // ODR-based merging is performed in C++ and in some cases (tag types) in C. |
| 2612 | // Note that C identically-named things in different translation units are |
| 2613 | // not redeclarations, but may still have compatible types, where ODR-like |
| 2614 | // semantics may apply. |
| 2615 | if (!Reader.getContext().getLangOpts().CPlusPlus && |
| 2616 | !allowODRLikeMergeInC(dyn_cast<NamedDecl>(static_cast<T*>(D)))) |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame] | 2617 | return; |
| 2618 | |
Richard Smith | 0b87e07 | 2013-10-07 08:02:11 +0000 | [diff] [blame] | 2619 | if (FindExistingResult ExistingRes = findExisting(static_cast<T*>(D))) |
| 2620 | if (T *Existing = ExistingRes) |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 2621 | Reader.getContext().setPrimaryMergedDecl(static_cast<T *>(D), |
| 2622 | Existing->getCanonicalDecl()); |
Richard Smith | 0b87e07 | 2013-10-07 08:02:11 +0000 | [diff] [blame] | 2623 | } |
| 2624 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2625 | void ASTDeclReader::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) { |
| 2626 | VisitDecl(D); |
| 2627 | unsigned NumVars = D->varlist_size(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2628 | SmallVector<Expr *, 16> Vars; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2629 | Vars.reserve(NumVars); |
| 2630 | for (unsigned i = 0; i != NumVars; ++i) { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2631 | Vars.push_back(Record.readExpr()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2632 | } |
| 2633 | D->setVars(Vars); |
| 2634 | } |
| 2635 | |
Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 2636 | void ASTDeclReader::VisitOMPRequiresDecl(OMPRequiresDecl * D) { |
| 2637 | VisitDecl(D); |
| 2638 | unsigned NumClauses = D->clauselist_size(); |
| 2639 | SmallVector<OMPClause *, 8> Clauses; |
| 2640 | Clauses.reserve(NumClauses); |
| 2641 | OMPClauseReader ClauseReader(Record); |
| 2642 | for (unsigned I = 0; I != NumClauses; ++I) |
| 2643 | Clauses.push_back(ClauseReader.readClause()); |
| 2644 | D->setClauses(Clauses); |
| 2645 | } |
| 2646 | |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 2647 | void ASTDeclReader::VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D) { |
Alexey Bataev | c5b1d32 | 2016-03-04 09:22:22 +0000 | [diff] [blame] | 2648 | VisitValueDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2649 | D->setLocation(ReadSourceLocation()); |
Alexey Bataev | e6aa469 | 2018-09-13 16:54:05 +0000 | [diff] [blame] | 2650 | Expr *In = Record.readExpr(); |
| 2651 | Expr *Out = Record.readExpr(); |
| 2652 | D->setCombinerData(In, Out); |
| 2653 | Expr *Combiner = Record.readExpr(); |
| 2654 | D->setCombiner(Combiner); |
| 2655 | Expr *Orig = Record.readExpr(); |
| 2656 | Expr *Priv = Record.readExpr(); |
| 2657 | D->setInitializerData(Orig, Priv); |
| 2658 | Expr *Init = Record.readExpr(); |
| 2659 | auto IK = static_cast<OMPDeclareReductionDecl::InitKind>(Record.readInt()); |
| 2660 | D->setInitializer(Init, IK); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2661 | D->PrevDeclInScope = ReadDeclID(); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 2662 | } |
| 2663 | |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 2664 | void ASTDeclReader::VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D) { |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 2665 | VisitVarDecl(D); |
| 2666 | } |
| 2667 | |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 2668 | //===----------------------------------------------------------------------===// |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 2669 | // Attribute Reading |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 2670 | //===----------------------------------------------------------------------===// |
| 2671 | |
Richard Smith | e43e2b3 | 2018-08-20 21:47:29 +0000 | [diff] [blame] | 2672 | namespace { |
| 2673 | class AttrReader { |
| 2674 | ModuleFile *F; |
| 2675 | ASTReader *Reader; |
| 2676 | const ASTReader::RecordData &Record; |
| 2677 | unsigned &Idx; |
| 2678 | |
| 2679 | public: |
| 2680 | AttrReader(ModuleFile &F, ASTReader &Reader, |
| 2681 | const ASTReader::RecordData &Record, unsigned &Idx) |
| 2682 | : F(&F), Reader(&Reader), Record(Record), Idx(Idx) {} |
| 2683 | |
| 2684 | const uint64_t &readInt() { return Record[Idx++]; } |
| 2685 | |
| 2686 | SourceRange readSourceRange() { |
| 2687 | return Reader->ReadSourceRange(*F, Record, Idx); |
| 2688 | } |
| 2689 | |
| 2690 | Expr *readExpr() { return Reader->ReadExpr(*F); } |
| 2691 | |
| 2692 | std::string readString() { |
| 2693 | return Reader->ReadString(Record, Idx); |
| 2694 | } |
| 2695 | |
| 2696 | TypeSourceInfo *getTypeSourceInfo() { |
| 2697 | return Reader->GetTypeSourceInfo(*F, Record, Idx); |
| 2698 | } |
| 2699 | |
| 2700 | IdentifierInfo *getIdentifierInfo() { |
| 2701 | return Reader->GetIdentifierInfo(*F, Record, Idx); |
| 2702 | } |
| 2703 | |
| 2704 | VersionTuple readVersionTuple() { |
| 2705 | return ASTReader::ReadVersionTuple(Record, Idx); |
| 2706 | } |
| 2707 | |
| 2708 | template <typename T> T *GetLocalDeclAs(uint32_t LocalID) { |
| 2709 | return cast_or_null<T>(Reader->GetLocalDecl(*F, LocalID)); |
| 2710 | } |
| 2711 | }; |
| 2712 | } |
| 2713 | |
| 2714 | Attr *ASTReader::ReadAttr(ModuleFile &M, const RecordData &Rec, |
| 2715 | unsigned &Idx) { |
| 2716 | AttrReader Record(M, *this, Rec, Idx); |
| 2717 | auto V = Record.readInt(); |
| 2718 | if (!V) |
| 2719 | return nullptr; |
| 2720 | |
| 2721 | Attr *New = nullptr; |
| 2722 | // Kind is stored as a 1-based integer because 0 is used to indicate a null |
| 2723 | // Attr pointer. |
| 2724 | auto Kind = static_cast<attr::Kind>(V - 1); |
| 2725 | SourceRange Range = Record.readSourceRange(); |
| 2726 | ASTContext &Context = getContext(); |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 2727 | |
Alexis Hunt | dcfba7b | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 2728 | #include "clang/Serialization/AttrPCHRead.inc" |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 2729 | |
Richard Smith | e43e2b3 | 2018-08-20 21:47:29 +0000 | [diff] [blame] | 2730 | assert(New && "Unable to decode attribute?"); |
| 2731 | return New; |
| 2732 | } |
| 2733 | |
| 2734 | /// Reads attributes from the current stream position. |
| 2735 | void ASTReader::ReadAttributes(ASTRecordReader &Record, AttrVec &Attrs) { |
| 2736 | for (unsigned I = 0, E = Record.readInt(); I != E; ++I) |
| 2737 | Attrs.push_back(Record.readAttr()); |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 2738 | } |
| 2739 | |
| 2740 | //===----------------------------------------------------------------------===// |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2741 | // ASTReader Implementation |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 2742 | //===----------------------------------------------------------------------===// |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 2743 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2744 | /// Note that we have loaded the declaration with the given |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 2745 | /// Index. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2746 | /// |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 2747 | /// This routine notes that this declaration has already been loaded, |
| 2748 | /// so that future GetDecl calls will return this declaration rather |
| 2749 | /// than trying to load a new declaration. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2750 | inline void ASTReader::LoadedDecl(unsigned Index, Decl *D) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 2751 | assert(!DeclsLoaded[Index] && "Decl loaded twice?"); |
| 2752 | DeclsLoaded[Index] = D; |
| 2753 | } |
| 2754 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2755 | /// Determine whether the consumer will be interested in seeing |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 2756 | /// this declaration (via HandleTopLevelDecl). |
| 2757 | /// |
| 2758 | /// This routine should return true for anything that might affect |
| 2759 | /// code generation, e.g., inline function definitions, Objective-C |
| 2760 | /// declarations with metadata, etc. |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 2761 | static bool isConsumerInterestedIn(ASTContext &Ctx, Decl *D, bool HasBody) { |
Argyrios Kyrtzidis | a98e861 | 2011-09-13 21:35:00 +0000 | [diff] [blame] | 2762 | // An ObjCMethodDecl is never considered as "interesting" because its |
| 2763 | // implementation container always is. |
| 2764 | |
Richard Smith | cd4a7a4 | 2017-09-07 00:55:55 +0000 | [diff] [blame] | 2765 | // An ImportDecl or VarDecl imported from a module map module will get |
| 2766 | // emitted when we import the relevant module. |
| 2767 | if (isa<ImportDecl>(D) || isa<VarDecl>(D)) { |
| 2768 | auto *M = D->getImportedOwningModule(); |
| 2769 | if (M && M->Kind == Module::ModuleMapModule && |
| 2770 | Ctx.DeclMustBeEmitted(D)) |
| 2771 | return false; |
| 2772 | } |
Richard Smith | dc1f042 | 2016-07-20 19:10:16 +0000 | [diff] [blame] | 2773 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2774 | if (isa<FileScopeAsmDecl>(D) || |
| 2775 | isa<ObjCProtocolDecl>(D) || |
Ben Langmuir | 332aafe | 2014-01-31 01:06:56 +0000 | [diff] [blame] | 2776 | isa<ObjCImplDecl>(D) || |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 2777 | isa<ImportDecl>(D) || |
Nico Weber | 6622029 | 2016-03-02 17:28:48 +0000 | [diff] [blame] | 2778 | isa<PragmaCommentDecl>(D) || |
Alexey Bataev | c5b1d32 | 2016-03-04 09:22:22 +0000 | [diff] [blame] | 2779 | isa<PragmaDetectMismatchDecl>(D)) |
Daniel Dunbar | 865c2a7 | 2009-09-17 03:06:44 +0000 | [diff] [blame] | 2780 | return true; |
Alexey Bataev | c5b1d32 | 2016-03-04 09:22:22 +0000 | [diff] [blame] | 2781 | if (isa<OMPThreadPrivateDecl>(D) || isa<OMPDeclareReductionDecl>(D)) |
| 2782 | return !D->getDeclContext()->isFunctionOrMethod(); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2783 | if (const auto *Var = dyn_cast<VarDecl>(D)) |
Argyrios Kyrtzidis | 4ba81b2 | 2010-08-05 09:47:59 +0000 | [diff] [blame] | 2784 | return Var->isFileVarDecl() && |
Alexey Bataev | d01b749 | 2018-08-15 19:45:12 +0000 | [diff] [blame] | 2785 | (Var->isThisDeclarationADefinition() == VarDecl::Definition || |
| 2786 | OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(Var)); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2787 | if (const auto *Func = dyn_cast<FunctionDecl>(D)) |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 2788 | return Func->doesThisDeclarationHaveABody() || HasBody; |
David Blaikie | 1ac9c98 | 2017-04-11 21:13:37 +0000 | [diff] [blame] | 2789 | |
| 2790 | if (auto *ES = D->getASTContext().getExternalSource()) |
| 2791 | if (ES->hasExternalDefinitions(D) == ExternalASTSource::EK_Never) |
| 2792 | return true; |
| 2793 | |
Douglas Gregor | 87d8124 | 2011-09-10 00:22:34 +0000 | [diff] [blame] | 2794 | return false; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 2795 | } |
| 2796 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2797 | /// Get the correct cursor and offset for loading a declaration. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2798 | ASTReader::RecordLocation |
Richard Smith | cb34bd3 | 2016-03-27 07:28:06 +0000 | [diff] [blame] | 2799 | ASTReader::DeclCursorForID(DeclID ID, SourceLocation &Loc) { |
Douglas Gregor | 047d2ef | 2011-07-20 00:27:43 +0000 | [diff] [blame] | 2800 | GlobalDeclMapType::iterator I = GlobalDeclMap.find(ID); |
| 2801 | assert(I != GlobalDeclMap.end() && "Corrupted global declaration map"); |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2802 | ModuleFile *M = I->second; |
Richard Smith | 34da751 | 2016-03-27 05:52:25 +0000 | [diff] [blame] | 2803 | const DeclOffset &DOffs = |
| 2804 | M->DeclOffsets[ID - M->BaseDeclID - NUM_PREDEF_DECL_IDS]; |
Richard Smith | cb34bd3 | 2016-03-27 07:28:06 +0000 | [diff] [blame] | 2805 | Loc = TranslateSourceLocation(*M, DOffs.getLocation()); |
Argyrios Kyrtzidis | 81ddd18 | 2011-10-27 18:47:35 +0000 | [diff] [blame] | 2806 | return RecordLocation(M, DOffs.BitOffset); |
Sebastian Redl | 3462779 | 2010-07-20 22:46:15 +0000 | [diff] [blame] | 2807 | } |
| 2808 | |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 2809 | ASTReader::RecordLocation ASTReader::getLocalBitOffset(uint64_t GlobalOffset) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2810 | auto I = GlobalBitOffsetsMap.find(GlobalOffset); |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 2811 | |
| 2812 | assert(I != GlobalBitOffsetsMap.end() && "Corrupted global bit offsets map"); |
| 2813 | return RecordLocation(I->second, GlobalOffset - I->second->GlobalBitOffset); |
| 2814 | } |
| 2815 | |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2816 | uint64_t ASTReader::getGlobalBitOffset(ModuleFile &M, uint32_t LocalOffset) { |
Douglas Gregor | c27b287 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 2817 | return LocalOffset + M.GlobalBitOffset; |
| 2818 | } |
| 2819 | |
Richard Smith | bf78e64 | 2013-06-24 22:51:00 +0000 | [diff] [blame] | 2820 | static bool isSameTemplateParameterList(const TemplateParameterList *X, |
| 2821 | const TemplateParameterList *Y); |
| 2822 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2823 | /// Determine whether two template parameters are similar enough |
Richard Smith | bf78e64 | 2013-06-24 22:51:00 +0000 | [diff] [blame] | 2824 | /// that they may be used in declarations of the same template. |
| 2825 | static bool isSameTemplateParameter(const NamedDecl *X, |
| 2826 | const NamedDecl *Y) { |
| 2827 | if (X->getKind() != Y->getKind()) |
| 2828 | return false; |
| 2829 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2830 | if (const auto *TX = dyn_cast<TemplateTypeParmDecl>(X)) { |
| 2831 | const auto *TY = cast<TemplateTypeParmDecl>(Y); |
Richard Smith | bf78e64 | 2013-06-24 22:51:00 +0000 | [diff] [blame] | 2832 | return TX->isParameterPack() == TY->isParameterPack(); |
| 2833 | } |
| 2834 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2835 | if (const auto *TX = dyn_cast<NonTypeTemplateParmDecl>(X)) { |
| 2836 | const auto *TY = cast<NonTypeTemplateParmDecl>(Y); |
Richard Smith | bf78e64 | 2013-06-24 22:51:00 +0000 | [diff] [blame] | 2837 | return TX->isParameterPack() == TY->isParameterPack() && |
| 2838 | TX->getASTContext().hasSameType(TX->getType(), TY->getType()); |
| 2839 | } |
| 2840 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2841 | const auto *TX = cast<TemplateTemplateParmDecl>(X); |
| 2842 | const auto *TY = cast<TemplateTemplateParmDecl>(Y); |
Richard Smith | bf78e64 | 2013-06-24 22:51:00 +0000 | [diff] [blame] | 2843 | return TX->isParameterPack() == TY->isParameterPack() && |
| 2844 | isSameTemplateParameterList(TX->getTemplateParameters(), |
| 2845 | TY->getTemplateParameters()); |
| 2846 | } |
| 2847 | |
Richard Smith | 32952e1 | 2014-10-14 02:00:47 +0000 | [diff] [blame] | 2848 | static NamespaceDecl *getNamespace(const NestedNameSpecifier *X) { |
| 2849 | if (auto *NS = X->getAsNamespace()) |
| 2850 | return NS; |
| 2851 | if (auto *NAS = X->getAsNamespaceAlias()) |
| 2852 | return NAS->getNamespace(); |
| 2853 | return nullptr; |
| 2854 | } |
| 2855 | |
| 2856 | static bool isSameQualifier(const NestedNameSpecifier *X, |
| 2857 | const NestedNameSpecifier *Y) { |
| 2858 | if (auto *NSX = getNamespace(X)) { |
| 2859 | auto *NSY = getNamespace(Y); |
| 2860 | if (!NSY || NSX->getCanonicalDecl() != NSY->getCanonicalDecl()) |
| 2861 | return false; |
| 2862 | } else if (X->getKind() != Y->getKind()) |
| 2863 | return false; |
| 2864 | |
| 2865 | // FIXME: For namespaces and types, we're permitted to check that the entity |
| 2866 | // is named via the same tokens. We should probably do so. |
| 2867 | switch (X->getKind()) { |
| 2868 | case NestedNameSpecifier::Identifier: |
| 2869 | if (X->getAsIdentifier() != Y->getAsIdentifier()) |
| 2870 | return false; |
| 2871 | break; |
| 2872 | case NestedNameSpecifier::Namespace: |
| 2873 | case NestedNameSpecifier::NamespaceAlias: |
| 2874 | // We've already checked that we named the same namespace. |
| 2875 | break; |
| 2876 | case NestedNameSpecifier::TypeSpec: |
| 2877 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 2878 | if (X->getAsType()->getCanonicalTypeInternal() != |
| 2879 | Y->getAsType()->getCanonicalTypeInternal()) |
| 2880 | return false; |
| 2881 | break; |
| 2882 | case NestedNameSpecifier::Global: |
| 2883 | case NestedNameSpecifier::Super: |
| 2884 | return true; |
| 2885 | } |
| 2886 | |
| 2887 | // Recurse into earlier portion of NNS, if any. |
| 2888 | auto *PX = X->getPrefix(); |
| 2889 | auto *PY = Y->getPrefix(); |
| 2890 | if (PX && PY) |
| 2891 | return isSameQualifier(PX, PY); |
| 2892 | return !PX && !PY; |
| 2893 | } |
| 2894 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2895 | /// Determine whether two template parameter lists are similar enough |
Richard Smith | bf78e64 | 2013-06-24 22:51:00 +0000 | [diff] [blame] | 2896 | /// that they may be used in declarations of the same template. |
| 2897 | static bool isSameTemplateParameterList(const TemplateParameterList *X, |
| 2898 | const TemplateParameterList *Y) { |
| 2899 | if (X->size() != Y->size()) |
| 2900 | return false; |
| 2901 | |
| 2902 | for (unsigned I = 0, N = X->size(); I != N; ++I) |
| 2903 | if (!isSameTemplateParameter(X->getParam(I), Y->getParam(I))) |
| 2904 | return false; |
| 2905 | |
| 2906 | return true; |
| 2907 | } |
| 2908 | |
George Burgess IV | 9584508 | 2017-02-15 22:43:27 +0000 | [diff] [blame] | 2909 | /// 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] | 2910 | /// 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] | 2911 | static bool hasSameOverloadableAttrs(const FunctionDecl *A, |
| 2912 | const FunctionDecl *B) { |
George Burgess IV | b776021 | 2017-02-24 02:49:47 +0000 | [diff] [blame] | 2913 | // Note that pass_object_size attributes are represented in the function's |
| 2914 | // ExtParameterInfo, so we don't need to check them here. |
| 2915 | |
Michael Kruse | dc5ce72 | 2018-08-03 01:21:16 +0000 | [diff] [blame] | 2916 | // Return false if any of the enable_if expressions of A and B are different. |
George Burgess IV | 9584508 | 2017-02-15 22:43:27 +0000 | [diff] [blame] | 2917 | llvm::FoldingSetNodeID Cand1ID, Cand2ID; |
Michael Kruse | dc5ce72 | 2018-08-03 01:21:16 +0000 | [diff] [blame] | 2918 | auto AEnableIfAttrs = A->specific_attrs<EnableIfAttr>(); |
| 2919 | auto BEnableIfAttrs = B->specific_attrs<EnableIfAttr>(); |
| 2920 | auto AEnableIf = AEnableIfAttrs.begin(); |
| 2921 | auto BEnableIf = BEnableIfAttrs.begin(); |
| 2922 | for (; AEnableIf != AEnableIfAttrs.end() && BEnableIf != BEnableIfAttrs.end(); |
| 2923 | ++BEnableIf, ++AEnableIf) { |
George Burgess IV | 9584508 | 2017-02-15 22:43:27 +0000 | [diff] [blame] | 2924 | Cand1ID.clear(); |
| 2925 | Cand2ID.clear(); |
| 2926 | |
Michael Kruse | dc5ce72 | 2018-08-03 01:21:16 +0000 | [diff] [blame] | 2927 | AEnableIf->getCond()->Profile(Cand1ID, A->getASTContext(), true); |
| 2928 | BEnableIf->getCond()->Profile(Cand2ID, B->getASTContext(), true); |
George Burgess IV | 9584508 | 2017-02-15 22:43:27 +0000 | [diff] [blame] | 2929 | if (Cand1ID != Cand2ID) |
| 2930 | return false; |
| 2931 | } |
| 2932 | |
Michael Kruse | dc5ce72 | 2018-08-03 01:21:16 +0000 | [diff] [blame] | 2933 | // Return false if the number of enable_if attributes was different. |
| 2934 | return AEnableIf == AEnableIfAttrs.end() && BEnableIf == BEnableIfAttrs.end(); |
George Burgess IV | 9584508 | 2017-02-15 22:43:27 +0000 | [diff] [blame] | 2935 | } |
| 2936 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2937 | /// Determine whether the two declarations refer to the same entity. |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 2938 | static bool isSameEntity(NamedDecl *X, NamedDecl *Y) { |
| 2939 | assert(X->getDeclName() == Y->getDeclName() && "Declaration name mismatch!"); |
Richard Smith | f463436 | 2014-09-03 23:11:22 +0000 | [diff] [blame] | 2940 | |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 2941 | if (X == Y) |
| 2942 | return true; |
Richard Smith | f463436 | 2014-09-03 23:11:22 +0000 | [diff] [blame] | 2943 | |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 2944 | // Must be in the same context. |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 2945 | // |
| 2946 | // Note that we can't use DeclContext::Equals here, because the DeclContexts |
| 2947 | // could be two different declarations of the same function. (We will fix the |
| 2948 | // semantic DC to refer to the primary definition after merging.) |
| 2949 | if (!declaresSameEntity(cast<Decl>(X->getDeclContext()->getRedeclContext()), |
| 2950 | cast<Decl>(Y->getDeclContext()->getRedeclContext()))) |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 2951 | return false; |
Douglas Gregor | 9b7b391 | 2012-01-04 16:44:10 +0000 | [diff] [blame] | 2952 | |
| 2953 | // Two typedefs refer to the same entity if they have the same underlying |
| 2954 | // type. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2955 | if (const auto *TypedefX = dyn_cast<TypedefNameDecl>(X)) |
| 2956 | if (const auto *TypedefY = dyn_cast<TypedefNameDecl>(Y)) |
Douglas Gregor | 9b7b391 | 2012-01-04 16:44:10 +0000 | [diff] [blame] | 2957 | return X->getASTContext().hasSameType(TypedefX->getUnderlyingType(), |
| 2958 | TypedefY->getUnderlyingType()); |
Richard Smith | f463436 | 2014-09-03 23:11:22 +0000 | [diff] [blame] | 2959 | |
Douglas Gregor | 9b7b391 | 2012-01-04 16:44:10 +0000 | [diff] [blame] | 2960 | // Must have the same kind. |
| 2961 | if (X->getKind() != Y->getKind()) |
| 2962 | return false; |
Richard Smith | f463436 | 2014-09-03 23:11:22 +0000 | [diff] [blame] | 2963 | |
Douglas Gregor | da38930 | 2012-01-01 21:47:52 +0000 | [diff] [blame] | 2964 | // Objective-C classes and protocols with the same name always match. |
| 2965 | if (isa<ObjCInterfaceDecl>(X) || isa<ObjCProtocolDecl>(X)) |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 2966 | return true; |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 2967 | |
| 2968 | if (isa<ClassTemplateSpecializationDecl>(X)) { |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2969 | // No need to handle these here: we merge them when adding them to the |
| 2970 | // template. |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 2971 | return false; |
| 2972 | } |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2973 | |
Douglas Gregor | 2009cee | 2012-01-03 22:46:00 +0000 | [diff] [blame] | 2974 | // Compatible tags match. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2975 | if (const auto *TagX = dyn_cast<TagDecl>(X)) { |
| 2976 | const auto *TagY = cast<TagDecl>(Y); |
Joao Matos | e9a3ed4 | 2012-08-31 22:18:20 +0000 | [diff] [blame] | 2977 | return (TagX->getTagKind() == TagY->getTagKind()) || |
| 2978 | ((TagX->getTagKind() == TTK_Struct || TagX->getTagKind() == TTK_Class || |
| 2979 | TagX->getTagKind() == TTK_Interface) && |
| 2980 | (TagY->getTagKind() == TTK_Struct || TagY->getTagKind() == TTK_Class || |
| 2981 | TagY->getTagKind() == TTK_Interface)); |
| 2982 | } |
Richard Smith | 8f8f05c | 2013-06-24 04:45:28 +0000 | [diff] [blame] | 2983 | |
Joao Matos | e9a3ed4 | 2012-08-31 22:18:20 +0000 | [diff] [blame] | 2984 | // Functions with the same type and linkage match. |
Richard Smith | f463436 | 2014-09-03 23:11:22 +0000 | [diff] [blame] | 2985 | // FIXME: This needs to cope with merging of prototyped/non-prototyped |
| 2986 | // functions, etc. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2987 | if (const auto *FuncX = dyn_cast<FunctionDecl>(X)) { |
| 2988 | const auto *FuncY = cast<FunctionDecl>(Y); |
| 2989 | if (const auto *CtorX = dyn_cast<CXXConstructorDecl>(X)) { |
| 2990 | const auto *CtorY = cast<CXXConstructorDecl>(Y); |
Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 2991 | if (CtorX->getInheritedConstructor() && |
| 2992 | !isSameEntity(CtorX->getInheritedConstructor().getConstructor(), |
| 2993 | CtorY->getInheritedConstructor().getConstructor())) |
| 2994 | return false; |
| 2995 | } |
Erich Keane | 281d20b | 2018-01-08 21:34:17 +0000 | [diff] [blame] | 2996 | |
| 2997 | if (FuncX->isMultiVersion() != FuncY->isMultiVersion()) |
| 2998 | return false; |
| 2999 | |
| 3000 | // Multiversioned functions with different feature strings are represented |
| 3001 | // as separate declarations. |
| 3002 | if (FuncX->isMultiVersion()) { |
| 3003 | const auto *TAX = FuncX->getAttr<TargetAttr>(); |
| 3004 | const auto *TAY = FuncY->getAttr<TargetAttr>(); |
| 3005 | assert(TAX && TAY && "Multiversion Function without target attribute"); |
| 3006 | |
| 3007 | if (TAX->getFeaturesStr() != TAY->getFeaturesStr()) |
| 3008 | return false; |
| 3009 | } |
| 3010 | |
Richard Smith | a54d324 | 2017-03-08 23:00:26 +0000 | [diff] [blame] | 3011 | ASTContext &C = FuncX->getASTContext(); |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 3012 | auto GetTypeAsWritten = [](const FunctionDecl *FD) { |
| 3013 | // Map to the first declaration that we've already merged into this one. |
| 3014 | // The TSI of redeclarations might not match (due to calling conventions |
| 3015 | // being inherited onto the type but not the TSI), but the TSI type of |
| 3016 | // the first declaration of the function should match across modules. |
| 3017 | FD = FD->getCanonicalDecl(); |
| 3018 | return FD->getTypeSourceInfo() ? FD->getTypeSourceInfo()->getType() |
| 3019 | : FD->getType(); |
| 3020 | }; |
| 3021 | QualType XT = GetTypeAsWritten(FuncX), YT = GetTypeAsWritten(FuncY); |
| 3022 | if (!C.hasSameType(XT, YT)) { |
Richard Smith | a54d324 | 2017-03-08 23:00:26 +0000 | [diff] [blame] | 3023 | // We can get functions with different types on the redecl chain in C++17 |
| 3024 | // if they have differing exception specifications and at least one of |
| 3025 | // the excpetion specs is unresolved. |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 3026 | auto *XFPT = XT->getAs<FunctionProtoType>(); |
| 3027 | auto *YFPT = YT->getAs<FunctionProtoType>(); |
Aaron Ballman | c351fba | 2017-12-04 20:27:34 +0000 | [diff] [blame] | 3028 | if (C.getLangOpts().CPlusPlus17 && XFPT && YFPT && |
Richard Smith | a54d324 | 2017-03-08 23:00:26 +0000 | [diff] [blame] | 3029 | (isUnresolvedExceptionSpec(XFPT->getExceptionSpecType()) || |
| 3030 | isUnresolvedExceptionSpec(YFPT->getExceptionSpecType())) && |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 3031 | C.hasSameFunctionTypeIgnoringExceptionSpec(XT, YT)) |
Richard Smith | a54d324 | 2017-03-08 23:00:26 +0000 | [diff] [blame] | 3032 | return true; |
| 3033 | return false; |
| 3034 | } |
George Burgess IV | 9584508 | 2017-02-15 22:43:27 +0000 | [diff] [blame] | 3035 | return FuncX->getLinkageInternal() == FuncY->getLinkageInternal() && |
George Burgess IV | 9584508 | 2017-02-15 22:43:27 +0000 | [diff] [blame] | 3036 | hasSameOverloadableAttrs(FuncX, FuncY); |
Douglas Gregor | b258569 | 2012-01-04 17:13:46 +0000 | [diff] [blame] | 3037 | } |
Axel Naumann | 866ba3e | 2012-10-01 09:18:00 +0000 | [diff] [blame] | 3038 | |
Douglas Gregor | b8c6f1e | 2012-01-04 17:21:36 +0000 | [diff] [blame] | 3039 | // Variables with the same type and linkage match. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3040 | if (const auto *VarX = dyn_cast<VarDecl>(X)) { |
| 3041 | const auto *VarY = cast<VarDecl>(Y); |
Yaron Keren | e94da64 | 2016-01-22 19:03:27 +0000 | [diff] [blame] | 3042 | if (VarX->getLinkageInternal() == VarY->getLinkageInternal()) { |
| 3043 | ASTContext &C = VarX->getASTContext(); |
| 3044 | if (C.hasSameType(VarX->getType(), VarY->getType())) |
| 3045 | return true; |
| 3046 | |
| 3047 | // We can get decls with different types on the redecl chain. Eg. |
| 3048 | // template <typename T> struct S { static T Var[]; }; // #1 |
| 3049 | // template <typename T> T S<T>::Var[sizeof(T)]; // #2 |
| 3050 | // Only? happens when completing an incomplete array type. In this case |
Vassil Vassilev | 4d75e8d | 2016-02-28 19:08:24 +0000 | [diff] [blame] | 3051 | // when comparing #1 and #2 we should go through their element type. |
Yaron Keren | e94da64 | 2016-01-22 19:03:27 +0000 | [diff] [blame] | 3052 | const ArrayType *VarXTy = C.getAsArrayType(VarX->getType()); |
| 3053 | const ArrayType *VarYTy = C.getAsArrayType(VarY->getType()); |
| 3054 | if (!VarXTy || !VarYTy) |
| 3055 | return false; |
| 3056 | if (VarXTy->isIncompleteArrayType() || VarYTy->isIncompleteArrayType()) |
| 3057 | return C.hasSameType(VarXTy->getElementType(), VarYTy->getElementType()); |
| 3058 | } |
| 3059 | return false; |
Douglas Gregor | b8c6f1e | 2012-01-04 17:21:36 +0000 | [diff] [blame] | 3060 | } |
Richard Smith | 8f8f05c | 2013-06-24 04:45:28 +0000 | [diff] [blame] | 3061 | |
Douglas Gregor | cfe7dc6 | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 3062 | // Namespaces with the same name and inlinedness match. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3063 | if (const auto *NamespaceX = dyn_cast<NamespaceDecl>(X)) { |
| 3064 | const auto *NamespaceY = cast<NamespaceDecl>(Y); |
Douglas Gregor | cfe7dc6 | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 3065 | return NamespaceX->isInline() == NamespaceY->isInline(); |
| 3066 | } |
Axel Naumann | 866ba3e | 2012-10-01 09:18:00 +0000 | [diff] [blame] | 3067 | |
Richard Smith | 8f8f05c | 2013-06-24 04:45:28 +0000 | [diff] [blame] | 3068 | // Identical template names and kinds match if their template parameter lists |
| 3069 | // and patterns match. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3070 | if (const auto *TemplateX = dyn_cast<TemplateDecl>(X)) { |
| 3071 | const auto *TemplateY = cast<TemplateDecl>(Y); |
Richard Smith | 8f8f05c | 2013-06-24 04:45:28 +0000 | [diff] [blame] | 3072 | return isSameEntity(TemplateX->getTemplatedDecl(), |
Richard Smith | bf78e64 | 2013-06-24 22:51:00 +0000 | [diff] [blame] | 3073 | TemplateY->getTemplatedDecl()) && |
| 3074 | isSameTemplateParameterList(TemplateX->getTemplateParameters(), |
| 3075 | TemplateY->getTemplateParameters()); |
Richard Smith | 8f8f05c | 2013-06-24 04:45:28 +0000 | [diff] [blame] | 3076 | } |
Axel Naumann | 866ba3e | 2012-10-01 09:18:00 +0000 | [diff] [blame] | 3077 | |
Richard Smith | 0b87e07 | 2013-10-07 08:02:11 +0000 | [diff] [blame] | 3078 | // Fields with the same name and the same type match. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3079 | if (const auto *FDX = dyn_cast<FieldDecl>(X)) { |
| 3080 | const auto *FDY = cast<FieldDecl>(Y); |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame] | 3081 | // FIXME: Also check the bitwidth is odr-equivalent, if any. |
Richard Smith | 0b87e07 | 2013-10-07 08:02:11 +0000 | [diff] [blame] | 3082 | return X->getASTContext().hasSameType(FDX->getType(), FDY->getType()); |
| 3083 | } |
| 3084 | |
Richard Smith | 8cbd895 | 2015-08-04 02:05:09 +0000 | [diff] [blame] | 3085 | // Indirect fields with the same target field match. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3086 | if (const auto *IFDX = dyn_cast<IndirectFieldDecl>(X)) { |
| 3087 | const auto *IFDY = cast<IndirectFieldDecl>(Y); |
Richard Smith | 8cbd895 | 2015-08-04 02:05:09 +0000 | [diff] [blame] | 3088 | return IFDX->getAnonField()->getCanonicalDecl() == |
| 3089 | IFDY->getAnonField()->getCanonicalDecl(); |
| 3090 | } |
| 3091 | |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame] | 3092 | // Enumerators with the same name match. |
| 3093 | if (isa<EnumConstantDecl>(X)) |
| 3094 | // FIXME: Also check the value is odr-equivalent. |
| 3095 | return true; |
| 3096 | |
Richard Smith | fd8634a | 2013-10-23 02:17:46 +0000 | [diff] [blame] | 3097 | // Using shadow declarations with the same target match. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3098 | if (const auto *USX = dyn_cast<UsingShadowDecl>(X)) { |
| 3099 | const auto *USY = cast<UsingShadowDecl>(Y); |
Richard Smith | fd8634a | 2013-10-23 02:17:46 +0000 | [diff] [blame] | 3100 | return USX->getTargetDecl() == USY->getTargetDecl(); |
| 3101 | } |
| 3102 | |
Richard Smith | 32952e1 | 2014-10-14 02:00:47 +0000 | [diff] [blame] | 3103 | // Using declarations with the same qualifier match. (We already know that |
| 3104 | // the name matches.) |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3105 | if (const auto *UX = dyn_cast<UsingDecl>(X)) { |
| 3106 | const auto *UY = cast<UsingDecl>(Y); |
Richard Smith | 32952e1 | 2014-10-14 02:00:47 +0000 | [diff] [blame] | 3107 | return isSameQualifier(UX->getQualifier(), UY->getQualifier()) && |
| 3108 | UX->hasTypename() == UY->hasTypename() && |
| 3109 | UX->isAccessDeclaration() == UY->isAccessDeclaration(); |
| 3110 | } |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3111 | if (const auto *UX = dyn_cast<UnresolvedUsingValueDecl>(X)) { |
| 3112 | const auto *UY = cast<UnresolvedUsingValueDecl>(Y); |
Richard Smith | 32952e1 | 2014-10-14 02:00:47 +0000 | [diff] [blame] | 3113 | return isSameQualifier(UX->getQualifier(), UY->getQualifier()) && |
| 3114 | UX->isAccessDeclaration() == UY->isAccessDeclaration(); |
| 3115 | } |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3116 | if (const auto *UX = dyn_cast<UnresolvedUsingTypenameDecl>(X)) |
Richard Smith | 32952e1 | 2014-10-14 02:00:47 +0000 | [diff] [blame] | 3117 | return isSameQualifier( |
| 3118 | UX->getQualifier(), |
| 3119 | cast<UnresolvedUsingTypenameDecl>(Y)->getQualifier()); |
| 3120 | |
Richard Smith | f463436 | 2014-09-03 23:11:22 +0000 | [diff] [blame] | 3121 | // Namespace alias definitions with the same target match. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3122 | if (const auto *NAX = dyn_cast<NamespaceAliasDecl>(X)) { |
| 3123 | const auto *NAY = cast<NamespaceAliasDecl>(Y); |
Richard Smith | f463436 | 2014-09-03 23:11:22 +0000 | [diff] [blame] | 3124 | return NAX->getNamespace()->Equals(NAY->getNamespace()); |
| 3125 | } |
| 3126 | |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 3127 | return false; |
| 3128 | } |
| 3129 | |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 3130 | /// Find the context in which we should search for previous declarations when |
| 3131 | /// looking for declarations to merge. |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 3132 | DeclContext *ASTDeclReader::getPrimaryContextForMerging(ASTReader &Reader, |
| 3133 | DeclContext *DC) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3134 | if (auto *ND = dyn_cast<NamespaceDecl>(DC)) |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 3135 | return ND->getOriginalNamespace(); |
| 3136 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3137 | if (auto *RD = dyn_cast<CXXRecordDecl>(DC)) { |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 3138 | // Try to dig out the definition. |
Richard Smith | b648399 | 2016-05-17 22:44:15 +0000 | [diff] [blame] | 3139 | auto *DD = RD->DefinitionData; |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 3140 | if (!DD) |
Richard Smith | b648399 | 2016-05-17 22:44:15 +0000 | [diff] [blame] | 3141 | DD = RD->getCanonicalDecl()->DefinitionData; |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 3142 | |
| 3143 | // If there's no definition yet, then DC's definition is added by an update |
| 3144 | // record, but we've not yet loaded that update record. In this case, we |
| 3145 | // commit to DC being the canonical definition now, and will fix this when |
| 3146 | // we load the update record. |
| 3147 | if (!DD) { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 3148 | DD = new (Reader.getContext()) struct CXXRecordDecl::DefinitionData(RD); |
Erich Keane | f92f31c | 2018-08-01 20:48:16 +0000 | [diff] [blame] | 3149 | RD->setCompleteDefinition(true); |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 3150 | RD->DefinitionData = DD; |
| 3151 | RD->getCanonicalDecl()->DefinitionData = DD; |
| 3152 | |
| 3153 | // 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] | 3154 | Reader.PendingFakeDefinitionData.insert( |
| 3155 | std::make_pair(DD, ASTReader::PendingFakeDefinitionKind::Fake)); |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 3156 | } |
| 3157 | |
| 3158 | return DD->Definition; |
| 3159 | } |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 3160 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3161 | if (auto *ED = dyn_cast<EnumDecl>(DC)) |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 3162 | return ED->getASTContext().getLangOpts().CPlusPlus? ED->getDefinition() |
| 3163 | : nullptr; |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame] | 3164 | |
Richard Smith | 4eca9b9 | 2015-02-04 23:37:59 +0000 | [diff] [blame] | 3165 | // We can see the TU here only if we have no Sema object. In that case, |
| 3166 | // there's no TU scope to look in, so using the DC alone is sufficient. |
| 3167 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) |
| 3168 | return TU; |
| 3169 | |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 3170 | return nullptr; |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 3171 | } |
| 3172 | |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 3173 | ASTDeclReader::FindExistingResult::~FindExistingResult() { |
Richard Smith | f1f4bc2 | 2015-01-22 02:21:23 +0000 | [diff] [blame] | 3174 | // Record that we had a typedef name for linkage whether or not we merge |
| 3175 | // with that declaration. |
| 3176 | if (TypedefNameForLinkage) { |
| 3177 | DeclContext *DC = New->getDeclContext()->getRedeclContext(); |
| 3178 | Reader.ImportedTypedefNamesForLinkage.insert( |
| 3179 | std::make_pair(std::make_pair(DC, TypedefNameForLinkage), New)); |
| 3180 | return; |
| 3181 | } |
| 3182 | |
Douglas Gregor | 9b47f94 | 2012-01-09 17:38:47 +0000 | [diff] [blame] | 3183 | if (!AddResult || Existing) |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 3184 | return; |
Richard Smith | 95d9930 | 2013-07-13 02:00:19 +0000 | [diff] [blame] | 3185 | |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 3186 | DeclarationName Name = New->getDeclName(); |
Richard Smith | 95d9930 | 2013-07-13 02:00:19 +0000 | [diff] [blame] | 3187 | DeclContext *DC = New->getDeclContext()->getRedeclContext(); |
Richard Smith | 2b56057 | 2015-02-07 03:11:11 +0000 | [diff] [blame] | 3188 | if (needsAnonymousDeclarationNumber(New)) { |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3189 | setAnonymousDeclForMerging(Reader, New->getLexicalDeclContext(), |
| 3190 | AnonymousDeclNumber, New); |
Richard Smith | 1037909 | 2016-05-06 23:14:07 +0000 | [diff] [blame] | 3191 | } else if (DC->isTranslationUnit() && |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 3192 | !Reader.getContext().getLangOpts().CPlusPlus) { |
Richard Smith | 1037909 | 2016-05-06 23:14:07 +0000 | [diff] [blame] | 3193 | if (Reader.getIdResolver().tryAddTopLevelDecl(New, Name)) |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 3194 | Reader.PendingFakeLookupResults[Name.getAsIdentifierInfo()] |
| 3195 | .push_back(New); |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 3196 | } else if (DeclContext *MergeDC = getPrimaryContextForMerging(Reader, DC)) { |
Richard Smith | 95d9930 | 2013-07-13 02:00:19 +0000 | [diff] [blame] | 3197 | // Add the declaration to its redeclaration context so later merging |
| 3198 | // lookups will find it. |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 3199 | MergeDC->makeDeclVisibleInContextImpl(New, /*Internal*/true); |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 3200 | } |
| 3201 | } |
| 3202 | |
Richard Smith | 88ebade | 2014-08-23 01:45:27 +0000 | [diff] [blame] | 3203 | /// Find the declaration that should be merged into, given the declaration found |
| 3204 | /// by name lookup. If we're merging an anonymous declaration within a typedef, |
| 3205 | /// we need a matching typedef, and we merge with the type inside it. |
| 3206 | static NamedDecl *getDeclForMerging(NamedDecl *Found, |
| 3207 | bool IsTypedefNameForLinkage) { |
| 3208 | if (!IsTypedefNameForLinkage) |
| 3209 | return Found; |
| 3210 | |
| 3211 | // If we found a typedef declaration that gives a name to some other |
| 3212 | // declaration, then we want that inner declaration. Declarations from |
| 3213 | // AST files are handled via ImportedTypedefNamesForLinkage. |
Richard Smith | a523022 | 2015-03-27 01:37:43 +0000 | [diff] [blame] | 3214 | if (Found->isFromASTFile()) |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 3215 | return nullptr; |
Richard Smith | a523022 | 2015-03-27 01:37:43 +0000 | [diff] [blame] | 3216 | |
| 3217 | if (auto *TND = dyn_cast<TypedefNameDecl>(Found)) |
Richard Smith | 3fb1a85 | 2016-08-30 19:13:18 +0000 | [diff] [blame] | 3218 | return TND->getAnonDeclWithTypedefName(/*AnyRedecl*/true); |
Richard Smith | 88ebade | 2014-08-23 01:45:27 +0000 | [diff] [blame] | 3219 | |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 3220 | return nullptr; |
Richard Smith | 88ebade | 2014-08-23 01:45:27 +0000 | [diff] [blame] | 3221 | } |
| 3222 | |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 3223 | /// Find the declaration to use to populate the anonymous declaration table |
| 3224 | /// for the given lexical DeclContext. We only care about finding local |
| 3225 | /// definitions of the context; we'll merge imported ones as we go. |
| 3226 | DeclContext * |
| 3227 | ASTDeclReader::getPrimaryDCForAnonymousDecl(DeclContext *LexicalDC) { |
| 3228 | // For classes, we track the definition as we merge. |
| 3229 | if (auto *RD = dyn_cast<CXXRecordDecl>(LexicalDC)) { |
| 3230 | auto *DD = RD->getCanonicalDecl()->DefinitionData; |
| 3231 | return DD ? DD->Definition : nullptr; |
| 3232 | } |
| 3233 | |
| 3234 | // For anything else, walk its merged redeclarations looking for a definition. |
| 3235 | // Note that we can't just call getDefinition here because the redeclaration |
| 3236 | // chain isn't wired up. |
| 3237 | for (auto *D : merged_redecls(cast<Decl>(LexicalDC))) { |
| 3238 | if (auto *FD = dyn_cast<FunctionDecl>(D)) |
| 3239 | if (FD->isThisDeclarationADefinition()) |
| 3240 | return FD; |
| 3241 | if (auto *MD = dyn_cast<ObjCMethodDecl>(D)) |
| 3242 | if (MD->isThisDeclarationADefinition()) |
| 3243 | return MD; |
| 3244 | } |
| 3245 | |
| 3246 | // No merged definition yet. |
| 3247 | return nullptr; |
| 3248 | } |
| 3249 | |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3250 | NamedDecl *ASTDeclReader::getAnonymousDeclForMerging(ASTReader &Reader, |
| 3251 | DeclContext *DC, |
| 3252 | unsigned Index) { |
| 3253 | // If the lexical context has been merged, look into the now-canonical |
| 3254 | // definition. |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 3255 | auto *CanonDC = cast<Decl>(DC)->getCanonicalDecl(); |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3256 | |
| 3257 | // If we've seen this before, return the canonical declaration. |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 3258 | auto &Previous = Reader.AnonymousDeclarationsForMerging[CanonDC]; |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3259 | if (Index < Previous.size() && Previous[Index]) |
| 3260 | return Previous[Index]; |
| 3261 | |
| 3262 | // If this is the first time, but we have parsed a declaration of the context, |
| 3263 | // build the anonymous declaration list from the parsed declaration. |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 3264 | auto *PrimaryDC = getPrimaryDCForAnonymousDecl(DC); |
| 3265 | if (PrimaryDC && !cast<Decl>(PrimaryDC)->isFromASTFile()) { |
| 3266 | numberAnonymousDeclsWithin(PrimaryDC, [&](NamedDecl *ND, unsigned Number) { |
Richard Smith | 2b56057 | 2015-02-07 03:11:11 +0000 | [diff] [blame] | 3267 | if (Previous.size() == Number) |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3268 | Previous.push_back(cast<NamedDecl>(ND->getCanonicalDecl())); |
| 3269 | else |
Richard Smith | 2b56057 | 2015-02-07 03:11:11 +0000 | [diff] [blame] | 3270 | Previous[Number] = cast<NamedDecl>(ND->getCanonicalDecl()); |
| 3271 | }); |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3272 | } |
| 3273 | |
| 3274 | return Index < Previous.size() ? Previous[Index] : nullptr; |
| 3275 | } |
| 3276 | |
| 3277 | void ASTDeclReader::setAnonymousDeclForMerging(ASTReader &Reader, |
| 3278 | DeclContext *DC, unsigned Index, |
| 3279 | NamedDecl *D) { |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 3280 | auto *CanonDC = cast<Decl>(DC)->getCanonicalDecl(); |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3281 | |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 3282 | auto &Previous = Reader.AnonymousDeclarationsForMerging[CanonDC]; |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3283 | if (Index >= Previous.size()) |
| 3284 | Previous.resize(Index + 1); |
| 3285 | if (!Previous[Index]) |
| 3286 | Previous[Index] = D; |
| 3287 | } |
| 3288 | |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 3289 | ASTDeclReader::FindExistingResult ASTDeclReader::findExisting(NamedDecl *D) { |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 3290 | DeclarationName Name = TypedefNameForLinkage ? TypedefNameForLinkage |
| 3291 | : D->getDeclName(); |
Richard Smith | 88ebade | 2014-08-23 01:45:27 +0000 | [diff] [blame] | 3292 | |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3293 | if (!Name && !needsAnonymousDeclarationNumber(D)) { |
| 3294 | // Don't bother trying to find unnamed declarations that are in |
| 3295 | // unmergeable contexts. |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 3296 | FindExistingResult Result(Reader, D, /*Existing=*/nullptr, |
| 3297 | AnonymousDeclNumber, TypedefNameForLinkage); |
Douglas Gregor | 2009cee | 2012-01-03 22:46:00 +0000 | [diff] [blame] | 3298 | Result.suppress(); |
| 3299 | return Result; |
| 3300 | } |
Richard Smith | 95d9930 | 2013-07-13 02:00:19 +0000 | [diff] [blame] | 3301 | |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 3302 | DeclContext *DC = D->getDeclContext()->getRedeclContext(); |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 3303 | if (TypedefNameForLinkage) { |
Richard Smith | 88ebade | 2014-08-23 01:45:27 +0000 | [diff] [blame] | 3304 | auto It = Reader.ImportedTypedefNamesForLinkage.find( |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 3305 | std::make_pair(DC, TypedefNameForLinkage)); |
Richard Smith | 88ebade | 2014-08-23 01:45:27 +0000 | [diff] [blame] | 3306 | if (It != Reader.ImportedTypedefNamesForLinkage.end()) |
| 3307 | if (isSameEntity(It->second, D)) |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 3308 | return FindExistingResult(Reader, D, It->second, AnonymousDeclNumber, |
| 3309 | TypedefNameForLinkage); |
Richard Smith | 88ebade | 2014-08-23 01:45:27 +0000 | [diff] [blame] | 3310 | // Go on to check in other places in case an existing typedef name |
| 3311 | // was not imported. |
| 3312 | } |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3313 | |
Richard Smith | 2b56057 | 2015-02-07 03:11:11 +0000 | [diff] [blame] | 3314 | if (needsAnonymousDeclarationNumber(D)) { |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3315 | // This is an anonymous declaration that we may need to merge. Look it up |
| 3316 | // in its context by number. |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3317 | if (auto *Existing = getAnonymousDeclForMerging( |
| 3318 | Reader, D->getLexicalDeclContext(), AnonymousDeclNumber)) |
| 3319 | if (isSameEntity(Existing, D)) |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 3320 | return FindExistingResult(Reader, D, Existing, AnonymousDeclNumber, |
| 3321 | TypedefNameForLinkage); |
Richard Smith | 1037909 | 2016-05-06 23:14:07 +0000 | [diff] [blame] | 3322 | } else if (DC->isTranslationUnit() && |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 3323 | !Reader.getContext().getLangOpts().CPlusPlus) { |
Richard Smith | 1037909 | 2016-05-06 23:14:07 +0000 | [diff] [blame] | 3324 | IdentifierResolver &IdResolver = Reader.getIdResolver(); |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 3325 | |
| 3326 | // Temporarily consider the identifier to be up-to-date. We don't want to |
| 3327 | // cause additional lookups here. |
| 3328 | class UpToDateIdentifierRAII { |
| 3329 | IdentifierInfo *II; |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3330 | bool WasOutToDate = false; |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 3331 | |
| 3332 | public: |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3333 | explicit UpToDateIdentifierRAII(IdentifierInfo *II) : II(II) { |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 3334 | if (II) { |
| 3335 | WasOutToDate = II->isOutOfDate(); |
| 3336 | if (WasOutToDate) |
| 3337 | II->setOutOfDate(false); |
| 3338 | } |
| 3339 | } |
| 3340 | |
| 3341 | ~UpToDateIdentifierRAII() { |
| 3342 | if (WasOutToDate) |
| 3343 | II->setOutOfDate(true); |
| 3344 | } |
| 3345 | } UpToDate(Name.getAsIdentifierInfo()); |
| 3346 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3347 | for (IdentifierResolver::iterator I = IdResolver.begin(Name), |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 3348 | IEnd = IdResolver.end(); |
| 3349 | I != IEnd; ++I) { |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 3350 | if (NamedDecl *Existing = getDeclForMerging(*I, TypedefNameForLinkage)) |
Richard Smith | 87dacc7 | 2014-08-25 23:33:46 +0000 | [diff] [blame] | 3351 | if (isSameEntity(Existing, D)) |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 3352 | return FindExistingResult(Reader, D, Existing, AnonymousDeclNumber, |
| 3353 | TypedefNameForLinkage); |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 3354 | } |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 3355 | } else if (DeclContext *MergeDC = getPrimaryContextForMerging(Reader, DC)) { |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 3356 | DeclContext::lookup_result R = MergeDC->noload_lookup(Name); |
Richard Smith | 95d9930 | 2013-07-13 02:00:19 +0000 | [diff] [blame] | 3357 | 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] | 3358 | if (NamedDecl *Existing = getDeclForMerging(*I, TypedefNameForLinkage)) |
Richard Smith | 88ebade | 2014-08-23 01:45:27 +0000 | [diff] [blame] | 3359 | if (isSameEntity(Existing, D)) |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 3360 | return FindExistingResult(Reader, D, Existing, AnonymousDeclNumber, |
| 3361 | TypedefNameForLinkage); |
Douglas Gregor | 9b47f94 | 2012-01-09 17:38:47 +0000 | [diff] [blame] | 3362 | } |
Richard Smith | 2b9e3e3 | 2013-10-18 06:05:18 +0000 | [diff] [blame] | 3363 | } else { |
| 3364 | // Not in a mergeable context. |
| 3365 | return FindExistingResult(Reader); |
Douglas Gregor | 9b47f94 | 2012-01-09 17:38:47 +0000 | [diff] [blame] | 3366 | } |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 3367 | |
Richard Smith | 2b9e3e3 | 2013-10-18 06:05:18 +0000 | [diff] [blame] | 3368 | // If this declaration is from a merged context, make a note that we need to |
| 3369 | // check that the canonical definition of that context contains the decl. |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3370 | // |
| 3371 | // FIXME: We should do something similar if we merge two definitions of the |
| 3372 | // same template specialization into the same CXXRecordDecl. |
Richard Smith | 88126a2 | 2014-08-25 02:10:01 +0000 | [diff] [blame] | 3373 | auto MergedDCIt = Reader.MergedDeclContexts.find(D->getLexicalDeclContext()); |
| 3374 | if (MergedDCIt != Reader.MergedDeclContexts.end() && |
| 3375 | MergedDCIt->second == D->getDeclContext()) |
Richard Smith | 2b9e3e3 | 2013-10-18 06:05:18 +0000 | [diff] [blame] | 3376 | Reader.PendingOdrMergeChecks.push_back(D); |
| 3377 | |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3378 | return FindExistingResult(Reader, D, /*Existing=*/nullptr, |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 3379 | AnonymousDeclNumber, TypedefNameForLinkage); |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 3380 | } |
| 3381 | |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 3382 | template<typename DeclT> |
Richard Smith | c3a5325 | 2015-02-28 05:57:02 +0000 | [diff] [blame] | 3383 | Decl *ASTDeclReader::getMostRecentDeclImpl(Redeclarable<DeclT> *D) { |
| 3384 | return D->RedeclLink.getLatestNotUpdated(); |
| 3385 | } |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3386 | |
Richard Smith | c3a5325 | 2015-02-28 05:57:02 +0000 | [diff] [blame] | 3387 | Decl *ASTDeclReader::getMostRecentDeclImpl(...) { |
| 3388 | llvm_unreachable("getMostRecentDecl on non-redeclarable declaration"); |
| 3389 | } |
| 3390 | |
| 3391 | Decl *ASTDeclReader::getMostRecentDecl(Decl *D) { |
| 3392 | assert(D); |
| 3393 | |
| 3394 | switch (D->getKind()) { |
| 3395 | #define ABSTRACT_DECL(TYPE) |
| 3396 | #define DECL(TYPE, BASE) \ |
| 3397 | case Decl::TYPE: \ |
| 3398 | return getMostRecentDeclImpl(cast<TYPE##Decl>(D)); |
| 3399 | #include "clang/AST/DeclNodes.inc" |
| 3400 | } |
| 3401 | llvm_unreachable("unknown decl kind"); |
| 3402 | } |
| 3403 | |
Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 3404 | Decl *ASTReader::getMostRecentExistingDecl(Decl *D) { |
| 3405 | return ASTDeclReader::getMostRecentDecl(D->getCanonicalDecl()); |
| 3406 | } |
| 3407 | |
Richard Smith | c3a5325 | 2015-02-28 05:57:02 +0000 | [diff] [blame] | 3408 | template<typename DeclT> |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 3409 | void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader, |
| 3410 | Redeclarable<DeclT> *D, |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 3411 | Decl *Previous, Decl *Canon) { |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 3412 | D->RedeclLink.setPrevious(cast<DeclT>(Previous)); |
Manuel Klimek | 093b2d4 | 2015-03-25 23:18:30 +0000 | [diff] [blame] | 3413 | D->First = cast<DeclT>(Previous)->First; |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 3414 | } |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 3415 | |
Richard Smith | 24d166c | 2014-07-31 23:52:38 +0000 | [diff] [blame] | 3416 | namespace clang { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3417 | |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 3418 | template<> |
| 3419 | void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader, |
Richard Smith | edbc6e9 | 2016-10-14 21:41:24 +0000 | [diff] [blame] | 3420 | Redeclarable<VarDecl> *D, |
| 3421 | Decl *Previous, Decl *Canon) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3422 | auto *VD = static_cast<VarDecl *>(D); |
| 3423 | auto *PrevVD = cast<VarDecl>(Previous); |
Richard Smith | edbc6e9 | 2016-10-14 21:41:24 +0000 | [diff] [blame] | 3424 | D->RedeclLink.setPrevious(PrevVD); |
| 3425 | D->First = PrevVD->First; |
| 3426 | |
| 3427 | // We should keep at most one definition on the chain. |
| 3428 | // FIXME: Cache the definition once we've found it. Building a chain with |
| 3429 | // N definitions currently takes O(N^2) time here. |
| 3430 | if (VD->isThisDeclarationADefinition() == VarDecl::Definition) { |
| 3431 | for (VarDecl *CurD = PrevVD; CurD; CurD = CurD->getPreviousDecl()) { |
| 3432 | if (CurD->isThisDeclarationADefinition() == VarDecl::Definition) { |
| 3433 | Reader.mergeDefinitionVisibility(CurD, VD); |
| 3434 | VD->demoteThisDefinitionToDeclaration(); |
| 3435 | break; |
| 3436 | } |
| 3437 | } |
| 3438 | } |
| 3439 | } |
| 3440 | |
Richard Smith | a62d198 | 2018-08-03 01:00:01 +0000 | [diff] [blame] | 3441 | static bool isUndeducedReturnType(QualType T) { |
| 3442 | auto *DT = T->getContainedDeducedType(); |
| 3443 | return DT && !DT->isDeduced(); |
| 3444 | } |
| 3445 | |
Richard Smith | edbc6e9 | 2016-10-14 21:41:24 +0000 | [diff] [blame] | 3446 | template<> |
| 3447 | void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader, |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 3448 | Redeclarable<FunctionDecl> *D, |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 3449 | Decl *Previous, Decl *Canon) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3450 | auto *FD = static_cast<FunctionDecl *>(D); |
| 3451 | auto *PrevFD = cast<FunctionDecl>(Previous); |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 3452 | |
| 3453 | FD->RedeclLink.setPrevious(PrevFD); |
Manuel Klimek | 093b2d4 | 2015-03-25 23:18:30 +0000 | [diff] [blame] | 3454 | FD->First = PrevFD->First; |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 3455 | |
| 3456 | // If the previous declaration is an inline function declaration, then this |
| 3457 | // declaration is too. |
Erich Keane | 9c66506 | 2018-08-01 21:02:40 +0000 | [diff] [blame] | 3458 | if (PrevFD->isInlined() != FD->isInlined()) { |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 3459 | // FIXME: [dcl.fct.spec]p4: |
| 3460 | // If a function with external linkage is declared inline in one |
| 3461 | // translation unit, it shall be declared inline in all translation |
| 3462 | // units in which it appears. |
| 3463 | // |
| 3464 | // Be careful of this case: |
| 3465 | // |
| 3466 | // module A: |
| 3467 | // template<typename T> struct X { void f(); }; |
| 3468 | // template<typename T> inline void X<T>::f() {} |
| 3469 | // |
| 3470 | // module B instantiates the declaration of X<int>::f |
| 3471 | // module C instantiates the definition of X<int>::f |
| 3472 | // |
| 3473 | // 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] | 3474 | FD->setImplicitlyInline(true); |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 3475 | } |
| 3476 | |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 3477 | auto *FPT = FD->getType()->getAs<FunctionProtoType>(); |
| 3478 | auto *PrevFPT = PrevFD->getType()->getAs<FunctionProtoType>(); |
Richard Smith | 8096975 | 2015-03-10 02:00:53 +0000 | [diff] [blame] | 3479 | if (FPT && PrevFPT) { |
Richard Smith | a62d198 | 2018-08-03 01:00:01 +0000 | [diff] [blame] | 3480 | // If we need to propagate an exception specification along the redecl |
| 3481 | // 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] | 3482 | bool IsUnresolved = isUnresolvedExceptionSpec(FPT->getExceptionSpecType()); |
| 3483 | bool WasUnresolved = |
| 3484 | isUnresolvedExceptionSpec(PrevFPT->getExceptionSpecType()); |
| 3485 | if (IsUnresolved != WasUnresolved) |
| 3486 | Reader.PendingExceptionSpecUpdates.insert( |
Richard Smith | a62d198 | 2018-08-03 01:00:01 +0000 | [diff] [blame] | 3487 | {Canon, IsUnresolved ? PrevFD : FD}); |
| 3488 | |
| 3489 | // If we need to propagate a deduced return type along the redecl chain, |
| 3490 | // make a note of that so that we can do it later. |
| 3491 | bool IsUndeduced = isUndeducedReturnType(FPT->getReturnType()); |
| 3492 | bool WasUndeduced = isUndeducedReturnType(PrevFPT->getReturnType()); |
| 3493 | if (IsUndeduced != WasUndeduced) |
| 3494 | Reader.PendingDeducedTypeUpdates.insert( |
| 3495 | {cast<FunctionDecl>(Canon), |
| 3496 | (IsUndeduced ? PrevFPT : FPT)->getReturnType()}); |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 3497 | } |
| 3498 | } |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3499 | |
| 3500 | } // namespace clang |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 3501 | |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 3502 | void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader, ...) { |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 3503 | llvm_unreachable("attachPreviousDecl on non-redeclarable declaration"); |
| 3504 | } |
| 3505 | |
Richard Smith | 8346e52 | 2015-06-10 01:47:58 +0000 | [diff] [blame] | 3506 | /// Inherit the default template argument from \p From to \p To. Returns |
| 3507 | /// \c false if there is no default template for \p From. |
| 3508 | template <typename ParmDecl> |
| 3509 | static bool inheritDefaultTemplateArgument(ASTContext &Context, ParmDecl *From, |
| 3510 | Decl *ToD) { |
| 3511 | auto *To = cast<ParmDecl>(ToD); |
| 3512 | if (!From->hasDefaultArgument()) |
| 3513 | return false; |
Richard Smith | e7bd6de | 2015-06-10 20:30:23 +0000 | [diff] [blame] | 3514 | To->setInheritedDefaultArgument(Context, From); |
Richard Smith | 8346e52 | 2015-06-10 01:47:58 +0000 | [diff] [blame] | 3515 | return true; |
| 3516 | } |
| 3517 | |
| 3518 | static void inheritDefaultTemplateArguments(ASTContext &Context, |
| 3519 | TemplateDecl *From, |
| 3520 | TemplateDecl *To) { |
| 3521 | auto *FromTP = From->getTemplateParameters(); |
| 3522 | auto *ToTP = To->getTemplateParameters(); |
| 3523 | assert(FromTP->size() == ToTP->size() && "merged mismatched templates?"); |
| 3524 | |
| 3525 | for (unsigned I = 0, N = FromTP->size(); I != N; ++I) { |
Richard Smith | 559cc69 | 2018-07-31 21:01:53 +0000 | [diff] [blame] | 3526 | NamedDecl *FromParam = FromTP->getParam(I); |
| 3527 | NamedDecl *ToParam = ToTP->getParam(I); |
Richard Smith | 8346e52 | 2015-06-10 01:47:58 +0000 | [diff] [blame] | 3528 | |
Richard Smith | 559cc69 | 2018-07-31 21:01:53 +0000 | [diff] [blame] | 3529 | if (auto *FTTP = dyn_cast<TemplateTypeParmDecl>(FromParam)) |
| 3530 | inheritDefaultTemplateArgument(Context, FTTP, ToParam); |
| 3531 | else if (auto *FNTTP = dyn_cast<NonTypeTemplateParmDecl>(FromParam)) |
| 3532 | inheritDefaultTemplateArgument(Context, FNTTP, ToParam); |
| 3533 | else |
| 3534 | inheritDefaultTemplateArgument( |
| 3535 | Context, cast<TemplateTemplateParmDecl>(FromParam), ToParam); |
Richard Smith | 8346e52 | 2015-06-10 01:47:58 +0000 | [diff] [blame] | 3536 | } |
| 3537 | } |
| 3538 | |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 3539 | void ASTDeclReader::attachPreviousDecl(ASTReader &Reader, Decl *D, |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 3540 | Decl *Previous, Decl *Canon) { |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 3541 | assert(D && Previous); |
| 3542 | |
| 3543 | switch (D->getKind()) { |
| 3544 | #define ABSTRACT_DECL(TYPE) |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 3545 | #define DECL(TYPE, BASE) \ |
| 3546 | case Decl::TYPE: \ |
| 3547 | attachPreviousDeclImpl(Reader, cast<TYPE##Decl>(D), Previous, Canon); \ |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 3548 | break; |
| 3549 | #include "clang/AST/DeclNodes.inc" |
Argyrios Kyrtzidis | 9fdd254 | 2011-02-12 07:50:47 +0000 | [diff] [blame] | 3550 | } |
Richard Smith | 7ecc31b | 2013-08-02 01:09:12 +0000 | [diff] [blame] | 3551 | |
| 3552 | // If the declaration was visible in one module, a redeclaration of it in |
| 3553 | // another module remains visible even if it wouldn't be visible by itself. |
| 3554 | // |
| 3555 | // FIXME: In this case, the declaration should only be visible if a module |
| 3556 | // that makes it visible has been imported. |
Richard Smith | 7ecc31b | 2013-08-02 01:09:12 +0000 | [diff] [blame] | 3557 | D->IdentifierNamespace |= |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 3558 | Previous->IdentifierNamespace & |
Richard Smith | 7ecc31b | 2013-08-02 01:09:12 +0000 | [diff] [blame] | 3559 | (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type); |
Richard Smith | 195d8ef | 2014-05-29 03:15:31 +0000 | [diff] [blame] | 3560 | |
Richard Smith | 8346e52 | 2015-06-10 01:47:58 +0000 | [diff] [blame] | 3561 | // If the declaration declares a template, it may inherit default arguments |
| 3562 | // from the previous declaration. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3563 | if (auto *TD = dyn_cast<TemplateDecl>(D)) |
Richard Smith | 8346e52 | 2015-06-10 01:47:58 +0000 | [diff] [blame] | 3564 | inheritDefaultTemplateArguments(Reader.getContext(), |
| 3565 | cast<TemplateDecl>(Previous), TD); |
Argyrios Kyrtzidis | 9fdd254 | 2011-02-12 07:50:47 +0000 | [diff] [blame] | 3566 | } |
| 3567 | |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 3568 | template<typename DeclT> |
| 3569 | void ASTDeclReader::attachLatestDeclImpl(Redeclarable<DeclT> *D, Decl *Latest) { |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 3570 | D->RedeclLink.setLatest(cast<DeclT>(Latest)); |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 3571 | } |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3572 | |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 3573 | void ASTDeclReader::attachLatestDeclImpl(...) { |
| 3574 | llvm_unreachable("attachLatestDecl on non-redeclarable declaration"); |
| 3575 | } |
| 3576 | |
Douglas Gregor | 05f1035 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 3577 | void ASTDeclReader::attachLatestDecl(Decl *D, Decl *Latest) { |
| 3578 | assert(D && Latest); |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 3579 | |
| 3580 | switch (D->getKind()) { |
| 3581 | #define ABSTRACT_DECL(TYPE) |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 3582 | #define DECL(TYPE, BASE) \ |
| 3583 | case Decl::TYPE: \ |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 3584 | attachLatestDeclImpl(cast<TYPE##Decl>(D), Latest); \ |
| 3585 | break; |
| 3586 | #include "clang/AST/DeclNodes.inc" |
Douglas Gregor | 05f1035 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 3587 | } |
| 3588 | } |
| 3589 | |
Richard Smith | 851072e | 2014-05-19 20:59:20 +0000 | [diff] [blame] | 3590 | template<typename DeclT> |
| 3591 | void ASTDeclReader::markIncompleteDeclChainImpl(Redeclarable<DeclT> *D) { |
| 3592 | D->RedeclLink.markIncomplete(); |
| 3593 | } |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3594 | |
Richard Smith | 851072e | 2014-05-19 20:59:20 +0000 | [diff] [blame] | 3595 | void ASTDeclReader::markIncompleteDeclChainImpl(...) { |
| 3596 | llvm_unreachable("markIncompleteDeclChain on non-redeclarable declaration"); |
| 3597 | } |
| 3598 | |
| 3599 | void ASTReader::markIncompleteDeclChain(Decl *D) { |
| 3600 | switch (D->getKind()) { |
| 3601 | #define ABSTRACT_DECL(TYPE) |
| 3602 | #define DECL(TYPE, BASE) \ |
| 3603 | case Decl::TYPE: \ |
| 3604 | ASTDeclReader::markIncompleteDeclChainImpl(cast<TYPE##Decl>(D)); \ |
| 3605 | break; |
| 3606 | #include "clang/AST/DeclNodes.inc" |
| 3607 | } |
| 3608 | } |
| 3609 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3610 | /// Read the declaration at the given offset from the AST file. |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 3611 | Decl *ASTReader::ReadDeclRecord(DeclID ID) { |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 3612 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; |
Richard Smith | cb34bd3 | 2016-03-27 07:28:06 +0000 | [diff] [blame] | 3613 | SourceLocation DeclLoc; |
| 3614 | RecordLocation Loc = DeclCursorForID(ID, DeclLoc); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3615 | llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3616 | // Keep track of where we are in the stream, then jump back there |
| 3617 | // after reading this declaration. |
Chris Lattner | 1de76db | 2009-04-27 05:58:23 +0000 | [diff] [blame] | 3618 | SavedStreamPosition SavedPosition(DeclsCursor); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3619 | |
Argyrios Kyrtzidis | d0795b2 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3620 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 3621 | |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 3622 | // Note that we are loading a declaration record. |
Argyrios Kyrtzidis | b24355a | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 3623 | Deserializing ADecl(this); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3624 | |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3625 | DeclsCursor.JumpToBit(Loc.Offset); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3626 | ASTRecordReader Record(*this, *Loc.F); |
| 3627 | ASTDeclReader Reader(*this, Record, Loc, ID, DeclLoc); |
Chris Lattner | 1de76db | 2009-04-27 05:58:23 +0000 | [diff] [blame] | 3628 | unsigned Code = DeclsCursor.ReadCode(); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3629 | |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 3630 | ASTContext &Context = getContext(); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 3631 | Decl *D = nullptr; |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3632 | switch ((DeclCode)Record.readRecord(DeclsCursor, Code)) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3633 | case DECL_CONTEXT_LEXICAL: |
| 3634 | case DECL_CONTEXT_VISIBLE: |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 3635 | llvm_unreachable("Record cannot be de-serialized with ReadDeclRecord"); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3636 | case DECL_TYPEDEF: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3637 | D = TypedefDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3638 | break; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 3639 | case DECL_TYPEALIAS: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3640 | D = TypeAliasDecl::CreateDeserialized(Context, ID); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 3641 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3642 | case DECL_ENUM: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3643 | D = EnumDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3644 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3645 | case DECL_RECORD: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3646 | D = RecordDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3647 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3648 | case DECL_ENUM_CONSTANT: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3649 | D = EnumConstantDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3650 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3651 | case DECL_FUNCTION: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3652 | D = FunctionDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3653 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3654 | case DECL_LINKAGE_SPEC: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3655 | D = LinkageSpecDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3656 | break; |
Richard Smith | 8df390f | 2016-09-08 23:14:54 +0000 | [diff] [blame] | 3657 | case DECL_EXPORT: |
| 3658 | D = ExportDecl::CreateDeserialized(Context, ID); |
| 3659 | break; |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 3660 | case DECL_LABEL: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3661 | D = LabelDecl::CreateDeserialized(Context, ID); |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 3662 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3663 | case DECL_NAMESPACE: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3664 | D = NamespaceDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3665 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3666 | case DECL_NAMESPACE_ALIAS: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3667 | D = NamespaceAliasDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3668 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3669 | case DECL_USING: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3670 | D = UsingDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3671 | break; |
Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 3672 | case DECL_USING_PACK: |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3673 | D = UsingPackDecl::CreateDeserialized(Context, ID, Record.readInt()); |
Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 3674 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3675 | case DECL_USING_SHADOW: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3676 | D = UsingShadowDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3677 | break; |
Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 3678 | case DECL_CONSTRUCTOR_USING_SHADOW: |
| 3679 | D = ConstructorUsingShadowDecl::CreateDeserialized(Context, ID); |
| 3680 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3681 | case DECL_USING_DIRECTIVE: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3682 | D = UsingDirectiveDecl::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_UNRESOLVED_USING_VALUE: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3685 | D = UnresolvedUsingValueDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3686 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3687 | case DECL_UNRESOLVED_USING_TYPENAME: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3688 | D = UnresolvedUsingTypenameDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3689 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3690 | case DECL_CXX_RECORD: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3691 | D = CXXRecordDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3692 | break; |
Richard Smith | bc49120 | 2017-02-17 20:05:37 +0000 | [diff] [blame] | 3693 | case DECL_CXX_DEDUCTION_GUIDE: |
| 3694 | D = CXXDeductionGuideDecl::CreateDeserialized(Context, ID); |
| 3695 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3696 | case DECL_CXX_METHOD: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3697 | D = CXXMethodDecl::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_CXX_CONSTRUCTOR: |
Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 3700 | D = CXXConstructorDecl::CreateDeserialized(Context, ID, false); |
| 3701 | break; |
| 3702 | case DECL_CXX_INHERITED_CONSTRUCTOR: |
| 3703 | D = CXXConstructorDecl::CreateDeserialized(Context, ID, true); |
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_DESTRUCTOR: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3706 | D = CXXDestructorDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3707 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3708 | case DECL_CXX_CONVERSION: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3709 | D = CXXConversionDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3710 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3711 | case DECL_ACCESS_SPEC: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3712 | D = AccessSpecDecl::CreateDeserialized(Context, ID); |
Abramo Bagnara | d734058 | 2010-06-05 05:09:32 +0000 | [diff] [blame] | 3713 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3714 | case DECL_FRIEND: |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3715 | D = FriendDecl::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_FRIEND_TEMPLATE: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3718 | D = FriendTemplateDecl::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_CLASS_TEMPLATE: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3721 | D = ClassTemplateDecl::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_CLASS_TEMPLATE_SPECIALIZATION: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3724 | D = ClassTemplateSpecializationDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3725 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3726 | case DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3727 | D = ClassTemplatePartialSpecializationDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3728 | break; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3729 | case DECL_VAR_TEMPLATE: |
| 3730 | D = VarTemplateDecl::CreateDeserialized(Context, ID); |
| 3731 | break; |
| 3732 | case DECL_VAR_TEMPLATE_SPECIALIZATION: |
| 3733 | D = VarTemplateSpecializationDecl::CreateDeserialized(Context, ID); |
| 3734 | break; |
| 3735 | case DECL_VAR_TEMPLATE_PARTIAL_SPECIALIZATION: |
| 3736 | D = VarTemplatePartialSpecializationDecl::CreateDeserialized(Context, ID); |
| 3737 | break; |
Francois Pichet | 00c7e6c | 2011-08-14 03:52:19 +0000 | [diff] [blame] | 3738 | case DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3739 | D = ClassScopeFunctionSpecializationDecl::CreateDeserialized(Context, ID); |
Francois Pichet | 00c7e6c | 2011-08-14 03:52:19 +0000 | [diff] [blame] | 3740 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3741 | case DECL_FUNCTION_TEMPLATE: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3742 | D = FunctionTemplateDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3743 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3744 | case DECL_TEMPLATE_TYPE_PARM: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3745 | D = TemplateTypeParmDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3746 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3747 | case DECL_NON_TYPE_TEMPLATE_PARM: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3748 | D = NonTypeTemplateParmDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3749 | break; |
Douglas Gregor | 0231d8d | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 3750 | case DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK: |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3751 | D = NonTypeTemplateParmDecl::CreateDeserialized(Context, ID, |
| 3752 | Record.readInt()); |
Douglas Gregor | 0231d8d | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 3753 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3754 | case DECL_TEMPLATE_TEMPLATE_PARM: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3755 | D = TemplateTemplateParmDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3756 | break; |
Richard Smith | 1fde8ec | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 3757 | case DECL_EXPANDED_TEMPLATE_TEMPLATE_PARM_PACK: |
| 3758 | D = TemplateTemplateParmDecl::CreateDeserialized(Context, ID, |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3759 | Record.readInt()); |
Richard Smith | 1fde8ec | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 3760 | break; |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 3761 | case DECL_TYPE_ALIAS_TEMPLATE: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3762 | D = TypeAliasTemplateDecl::CreateDeserialized(Context, ID); |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 3763 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3764 | case DECL_STATIC_ASSERT: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3765 | D = StaticAssertDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3766 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3767 | case DECL_OBJC_METHOD: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3768 | D = ObjCMethodDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3769 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3770 | case DECL_OBJC_INTERFACE: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3771 | D = ObjCInterfaceDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3772 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3773 | case DECL_OBJC_IVAR: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3774 | D = ObjCIvarDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3775 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3776 | case DECL_OBJC_PROTOCOL: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3777 | D = ObjCProtocolDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3778 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3779 | case DECL_OBJC_AT_DEFS_FIELD: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3780 | D = ObjCAtDefsFieldDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3781 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3782 | case DECL_OBJC_CATEGORY: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3783 | D = ObjCCategoryDecl::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_CATEGORY_IMPL: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3786 | D = ObjCCategoryImplDecl::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_IMPLEMENTATION: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3789 | D = ObjCImplementationDecl::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_COMPATIBLE_ALIAS: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3792 | D = ObjCCompatibleAliasDecl::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_PROPERTY: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3795 | D = ObjCPropertyDecl::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_PROPERTY_IMPL: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3798 | D = ObjCPropertyImplDecl::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_FIELD: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3801 | D = FieldDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3802 | break; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3803 | case DECL_INDIRECTFIELD: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3804 | D = IndirectFieldDecl::CreateDeserialized(Context, ID); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3805 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3806 | case DECL_VAR: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3807 | D = VarDecl::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_IMPLICIT_PARAM: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3810 | D = ImplicitParamDecl::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_PARM_VAR: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3813 | D = ParmVarDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3814 | break; |
Richard Smith | 7b76d81 | 2016-08-12 02:21:25 +0000 | [diff] [blame] | 3815 | case DECL_DECOMPOSITION: |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3816 | D = DecompositionDecl::CreateDeserialized(Context, ID, Record.readInt()); |
Richard Smith | 7b76d81 | 2016-08-12 02:21:25 +0000 | [diff] [blame] | 3817 | break; |
| 3818 | case DECL_BINDING: |
| 3819 | D = BindingDecl::CreateDeserialized(Context, ID); |
| 3820 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3821 | case DECL_FILE_SCOPE_ASM: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3822 | D = FileScopeAsmDecl::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_BLOCK: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3825 | D = BlockDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3826 | break; |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 3827 | case DECL_MS_PROPERTY: |
| 3828 | D = MSPropertyDecl::CreateDeserialized(Context, ID); |
| 3829 | break; |
Tareq A. Siraj | 6dfa25a | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 3830 | case DECL_CAPTURED: |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3831 | D = CapturedDecl::CreateDeserialized(Context, ID, Record.readInt()); |
Tareq A. Siraj | 6dfa25a | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 3832 | break; |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3833 | case DECL_CXX_BASE_SPECIFIERS: |
| 3834 | Error("attempt to read a C++ base-specifier record as a declaration"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 3835 | return nullptr; |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 3836 | case DECL_CXX_CTOR_INITIALIZERS: |
| 3837 | Error("attempt to read a C++ ctor initializer record as a declaration"); |
| 3838 | return nullptr; |
Douglas Gregor | ba34552 | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 3839 | case DECL_IMPORT: |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3840 | // 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] | 3841 | // locations. |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3842 | D = ImportDecl::CreateDeserialized(Context, ID, Record.back()); |
Douglas Gregor | ba34552 | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 3843 | break; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 3844 | case DECL_OMP_THREADPRIVATE: |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3845 | D = OMPThreadPrivateDecl::CreateDeserialized(Context, ID, Record.readInt()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 3846 | break; |
Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 3847 | case DECL_OMP_REQUIRES: |
| 3848 | D = OMPRequiresDecl::CreateDeserialized(Context, ID, Record.readInt()); |
| 3849 | break; |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 3850 | case DECL_OMP_DECLARE_REDUCTION: |
| 3851 | D = OMPDeclareReductionDecl::CreateDeserialized(Context, ID); |
| 3852 | break; |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 3853 | case DECL_OMP_CAPTUREDEXPR: |
| 3854 | D = OMPCapturedExprDecl::CreateDeserialized(Context, ID); |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 3855 | break; |
Nico Weber | 6622029 | 2016-03-02 17:28:48 +0000 | [diff] [blame] | 3856 | case DECL_PRAGMA_COMMENT: |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3857 | D = PragmaCommentDecl::CreateDeserialized(Context, ID, Record.readInt()); |
Nico Weber | 6622029 | 2016-03-02 17:28:48 +0000 | [diff] [blame] | 3858 | break; |
Nico Weber | cbbaeb1 | 2016-03-02 19:28:54 +0000 | [diff] [blame] | 3859 | case DECL_PRAGMA_DETECT_MISMATCH: |
| 3860 | D = PragmaDetectMismatchDecl::CreateDeserialized(Context, ID, |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3861 | Record.readInt()); |
Nico Weber | cbbaeb1 | 2016-03-02 19:28:54 +0000 | [diff] [blame] | 3862 | break; |
Michael Han | 8432435 | 2013-02-22 17:15:32 +0000 | [diff] [blame] | 3863 | case DECL_EMPTY: |
| 3864 | D = EmptyDecl::CreateDeserialized(Context, ID); |
| 3865 | break; |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3866 | case DECL_OBJC_TYPE_PARAM: |
| 3867 | D = ObjCTypeParamDecl::CreateDeserialized(Context, ID); |
| 3868 | break; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3869 | } |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3870 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 3871 | assert(D && "Unknown declaration reading AST file"); |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 3872 | LoadedDecl(Index, D); |
Argyrios Kyrtzidis | 6c07547 | 2012-02-09 06:02:44 +0000 | [diff] [blame] | 3873 | // Set the DeclContext before doing any deserialization, to make sure internal |
| 3874 | // calls to Decl::getASTContext() by Decl's methods will find the |
| 3875 | // TranslationUnitDecl without crashing. |
| 3876 | D->setDeclContext(Context.getTranslationUnitDecl()); |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 3877 | Reader.Visit(D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3878 | |
| 3879 | // If this declaration is also a declaration context, get the |
| 3880 | // offsets for its tables of lexical and visible declarations. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3881 | if (auto *DC = dyn_cast<DeclContext>(D)) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3882 | std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC); |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 3883 | if (Offsets.first && |
| 3884 | ReadLexicalDeclContextStorage(*Loc.F, DeclsCursor, Offsets.first, DC)) |
| 3885 | return nullptr; |
| 3886 | if (Offsets.second && |
| 3887 | ReadVisibleDeclContextStorage(*Loc.F, DeclsCursor, Offsets.second, ID)) |
| 3888 | return nullptr; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3889 | } |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3890 | assert(Record.getIdx() == Record.size()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3891 | |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 3892 | // Load any relevant update records. |
Vassil Vassilev | 74c3e8c | 2017-05-19 16:46:06 +0000 | [diff] [blame] | 3893 | PendingUpdateRecords.push_back( |
| 3894 | PendingUpdateRecord(ID, D, /*JustLoaded=*/true)); |
Argyrios Kyrtzidis | 7d268c3 | 2011-11-14 07:07:59 +0000 | [diff] [blame] | 3895 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3896 | // Load the categories after recursive loading is finished. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3897 | if (auto *Class = dyn_cast<ObjCInterfaceDecl>(D)) |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 3898 | // If we already have a definition when deserializing the ObjCInterfaceDecl, |
| 3899 | // we put the Decl in PendingDefinitions so we can pull the categories here. |
| 3900 | if (Class->isThisDeclarationADefinition() || |
| 3901 | PendingDefinitions.count(Class)) |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3902 | loadObjCCategories(ID, Class); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3903 | |
Richard Smith | 13fb860 | 2016-07-15 21:33:46 +0000 | [diff] [blame] | 3904 | // If we have deserialized a declaration that has a definition the |
| 3905 | // AST consumer might need to know about, queue it. |
| 3906 | // We don't pass it to the consumer immediately because we may be in recursive |
| 3907 | // loading, and some declarations may still be initializing. |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 3908 | PotentiallyInterestingDecls.push_back( |
| 3909 | InterestingDecl(D, Reader.hasPendingBody())); |
Richard Smith | 13fb860 | 2016-07-15 21:33:46 +0000 | [diff] [blame] | 3910 | |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 3911 | return D; |
| 3912 | } |
| 3913 | |
Vassil Vassilev | 46afbbb | 2017-04-12 21:56:05 +0000 | [diff] [blame] | 3914 | void ASTReader::PassInterestingDeclsToConsumer() { |
| 3915 | assert(Consumer); |
| 3916 | |
| 3917 | if (PassingDeclsToConsumer) |
| 3918 | return; |
| 3919 | |
| 3920 | // Guard variable to avoid recursively redoing the process of passing |
| 3921 | // decls to consumer. |
| 3922 | SaveAndRestore<bool> GuardPassingDeclsToConsumer(PassingDeclsToConsumer, |
| 3923 | true); |
| 3924 | |
| 3925 | // Ensure that we've loaded all potentially-interesting declarations |
| 3926 | // that need to be eagerly loaded. |
| 3927 | for (auto ID : EagerlyDeserializedDecls) |
| 3928 | GetDecl(ID); |
| 3929 | EagerlyDeserializedDecls.clear(); |
| 3930 | |
| 3931 | while (!PotentiallyInterestingDecls.empty()) { |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 3932 | InterestingDecl D = PotentiallyInterestingDecls.front(); |
Vassil Vassilev | 46afbbb | 2017-04-12 21:56:05 +0000 | [diff] [blame] | 3933 | PotentiallyInterestingDecls.pop_front(); |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 3934 | if (isConsumerInterestedIn(getContext(), D.getDecl(), D.hasPendingBody())) |
| 3935 | PassInterestingDeclToConsumer(D.getDecl()); |
Vassil Vassilev | 46afbbb | 2017-04-12 21:56:05 +0000 | [diff] [blame] | 3936 | } |
| 3937 | } |
| 3938 | |
Vassil Vassilev | 74c3e8c | 2017-05-19 16:46:06 +0000 | [diff] [blame] | 3939 | void ASTReader::loadDeclUpdateRecords(PendingUpdateRecord &Record) { |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3940 | // The declaration may have been modified by files later in the chain. |
| 3941 | // If this is the case, read the record containing the updates from each file |
| 3942 | // and pass it to ASTDeclReader to make the modifications. |
Vassil Vassilev | 74c3e8c | 2017-05-19 16:46:06 +0000 | [diff] [blame] | 3943 | serialization::GlobalDeclID ID = Record.ID; |
| 3944 | Decl *D = Record.D; |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 3945 | ProcessingUpdatesRAIIObj ProcessingUpdates(*this); |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3946 | DeclUpdateOffsetsMap::iterator UpdI = DeclUpdateOffsets.find(ID); |
Vassil Vassilev | 7d26462 | 2017-06-30 22:40:17 +0000 | [diff] [blame] | 3947 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3948 | SmallVector<serialization::DeclID, 8> PendingLazySpecializationIDs; |
Vassil Vassilev | 7d26462 | 2017-06-30 22:40:17 +0000 | [diff] [blame] | 3949 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3950 | if (UpdI != DeclUpdateOffsets.end()) { |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 3951 | auto UpdateOffsets = std::move(UpdI->second); |
| 3952 | DeclUpdateOffsets.erase(UpdI); |
| 3953 | |
Vassil Vassilev | 74c3e8c | 2017-05-19 16:46:06 +0000 | [diff] [blame] | 3954 | // Check if this decl was interesting to the consumer. If we just loaded |
| 3955 | // the declaration, then we know it was interesting and we skip the call |
| 3956 | // to isConsumerInterestedIn because it is unsafe to call in the |
| 3957 | // current ASTReader state. |
| 3958 | bool WasInteresting = |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 3959 | Record.JustLoaded || isConsumerInterestedIn(getContext(), D, false); |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 3960 | for (auto &FileAndOffset : UpdateOffsets) { |
| 3961 | ModuleFile *F = FileAndOffset.first; |
| 3962 | uint64_t Offset = FileAndOffset.second; |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3963 | llvm::BitstreamCursor &Cursor = F->DeclsCursor; |
| 3964 | SavedStreamPosition SavedPosition(Cursor); |
| 3965 | Cursor.JumpToBit(Offset); |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3966 | unsigned Code = Cursor.ReadCode(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3967 | ASTRecordReader Record(*this, *F); |
| 3968 | unsigned RecCode = Record.readRecord(Cursor, Code); |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3969 | (void)RecCode; |
| 3970 | assert(RecCode == DECL_UPDATES && "Expected DECL_UPDATES record!"); |
Richard Smith | 04d05b5 | 2014-03-23 00:27:18 +0000 | [diff] [blame] | 3971 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3972 | ASTDeclReader Reader(*this, Record, RecordLocation(F, Offset), ID, |
| 3973 | SourceLocation()); |
Vassil Vassilev | 7d26462 | 2017-06-30 22:40:17 +0000 | [diff] [blame] | 3974 | Reader.UpdateDecl(D, PendingLazySpecializationIDs); |
Richard Smith | 04d05b5 | 2014-03-23 00:27:18 +0000 | [diff] [blame] | 3975 | |
| 3976 | // We might have made this declaration interesting. If so, remember that |
| 3977 | // we need to hand it off to the consumer. |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 3978 | if (!WasInteresting && |
| 3979 | isConsumerInterestedIn(getContext(), D, Reader.hasPendingBody())) { |
| 3980 | PotentiallyInterestingDecls.push_back( |
| 3981 | InterestingDecl(D, Reader.hasPendingBody())); |
Richard Smith | 04d05b5 | 2014-03-23 00:27:18 +0000 | [diff] [blame] | 3982 | WasInteresting = true; |
| 3983 | } |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3984 | } |
| 3985 | } |
Vassil Vassilev | 7d26462 | 2017-06-30 22:40:17 +0000 | [diff] [blame] | 3986 | // Add the lazy specializations to the template. |
| 3987 | assert((PendingLazySpecializationIDs.empty() || isa<ClassTemplateDecl>(D) || |
| 3988 | isa<FunctionTemplateDecl>(D) || isa<VarTemplateDecl>(D)) && |
| 3989 | "Must not have pending specializations"); |
| 3990 | if (auto *CTD = dyn_cast<ClassTemplateDecl>(D)) |
| 3991 | ASTDeclReader::AddLazySpecializations(CTD, PendingLazySpecializationIDs); |
| 3992 | else if (auto *FTD = dyn_cast<FunctionTemplateDecl>(D)) |
| 3993 | ASTDeclReader::AddLazySpecializations(FTD, PendingLazySpecializationIDs); |
| 3994 | else if (auto *VTD = dyn_cast<VarTemplateDecl>(D)) |
| 3995 | ASTDeclReader::AddLazySpecializations(VTD, PendingLazySpecializationIDs); |
| 3996 | PendingLazySpecializationIDs.clear(); |
Richard Smith | 1e8e91b | 2016-04-08 20:53:26 +0000 | [diff] [blame] | 3997 | |
| 3998 | // Load the pending visible updates for this decl context, if it has any. |
| 3999 | auto I = PendingVisibleUpdates.find(ID); |
| 4000 | if (I != PendingVisibleUpdates.end()) { |
| 4001 | auto VisibleUpdates = std::move(I->second); |
| 4002 | PendingVisibleUpdates.erase(I); |
| 4003 | |
| 4004 | auto *DC = cast<DeclContext>(D)->getPrimaryContext(); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4005 | for (const auto &Update : VisibleUpdates) |
Richard Smith | 1e8e91b | 2016-04-08 20:53:26 +0000 | [diff] [blame] | 4006 | Lookups[DC].Table.add( |
| 4007 | Update.Mod, Update.Data, |
| 4008 | reader::ASTDeclContextNameLookupTrait(*this, *Update.Mod)); |
| 4009 | DC->setHasExternalVisibleStorage(true); |
| 4010 | } |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 4011 | } |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4012 | |
Richard Smith | d61d4ac | 2015-08-22 20:13:39 +0000 | [diff] [blame] | 4013 | void ASTReader::loadPendingDeclChain(Decl *FirstLocal, uint64_t LocalOffset) { |
| 4014 | // Attach FirstLocal to the end of the decl chain. |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 4015 | Decl *CanonDecl = FirstLocal->getCanonicalDecl(); |
Richard Smith | d61d4ac | 2015-08-22 20:13:39 +0000 | [diff] [blame] | 4016 | if (FirstLocal != CanonDecl) { |
| 4017 | Decl *PrevMostRecent = ASTDeclReader::getMostRecentDecl(CanonDecl); |
| 4018 | ASTDeclReader::attachPreviousDecl( |
| 4019 | *this, FirstLocal, PrevMostRecent ? PrevMostRecent : CanonDecl, |
| 4020 | CanonDecl); |
| 4021 | } |
| 4022 | |
| 4023 | if (!LocalOffset) { |
| 4024 | ASTDeclReader::attachLatestDecl(CanonDecl, FirstLocal); |
| 4025 | return; |
| 4026 | } |
| 4027 | |
| 4028 | // Load the list of other redeclarations from this module file. |
| 4029 | ModuleFile *M = getOwningModuleFile(FirstLocal); |
| 4030 | assert(M && "imported decl from no module file"); |
| 4031 | |
| 4032 | llvm::BitstreamCursor &Cursor = M->DeclsCursor; |
| 4033 | SavedStreamPosition SavedPosition(Cursor); |
| 4034 | Cursor.JumpToBit(LocalOffset); |
| 4035 | |
| 4036 | RecordData Record; |
| 4037 | unsigned Code = Cursor.ReadCode(); |
| 4038 | unsigned RecCode = Cursor.readRecord(Code, Record); |
| 4039 | (void)RecCode; |
| 4040 | assert(RecCode == LOCAL_REDECLARATIONS && "expected LOCAL_REDECLARATIONS record!"); |
| 4041 | |
| 4042 | // FIXME: We have several different dispatches on decl kind here; maybe |
| 4043 | // we should instead generate one loop per kind and dispatch up-front? |
| 4044 | Decl *MostRecent = FirstLocal; |
| 4045 | for (unsigned I = 0, N = Record.size(); I != N; ++I) { |
| 4046 | auto *D = GetLocalDecl(*M, Record[N - I - 1]); |
Richard Smith | e2f8ce9 | 2015-07-15 00:02:40 +0000 | [diff] [blame] | 4047 | ASTDeclReader::attachPreviousDecl(*this, D, MostRecent, CanonDecl); |
| 4048 | MostRecent = D; |
Douglas Gregor | 05f1035 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 4049 | } |
Richard Smith | c3a5325 | 2015-02-28 05:57:02 +0000 | [diff] [blame] | 4050 | ASTDeclReader::attachLatestDecl(CanonDecl, MostRecent); |
Douglas Gregor | 05f1035 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 4051 | } |
| 4052 | |
| 4053 | namespace { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4054 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4055 | /// Given an ObjC interface, goes through the modules and links to the |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4056 | /// interface all the categories for it. |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4057 | class ObjCCategoriesVisitor { |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4058 | ASTReader &Reader; |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4059 | ObjCInterfaceDecl *Interface; |
Craig Topper | 4dd9b43 | 2014-08-17 23:49:53 +0000 | [diff] [blame] | 4060 | llvm::SmallPtrSetImpl<ObjCCategoryDecl *> &Deserialized; |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4061 | ObjCCategoryDecl *Tail = nullptr; |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4062 | llvm::DenseMap<DeclarationName, ObjCCategoryDecl *> NameCategoryMap; |
Alexander Shaposhnikov | 96cbe7b | 2016-09-24 02:07:19 +0000 | [diff] [blame] | 4063 | serialization::GlobalDeclID InterfaceID; |
| 4064 | unsigned PreviousGeneration; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4065 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4066 | void add(ObjCCategoryDecl *Cat) { |
| 4067 | // Only process each category once. |
Benjamin Kramer | fc6eb7d | 2012-08-22 15:37:55 +0000 | [diff] [blame] | 4068 | if (!Deserialized.erase(Cat)) |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4069 | return; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4070 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4071 | // Check for duplicate categories. |
| 4072 | if (Cat->getDeclName()) { |
| 4073 | ObjCCategoryDecl *&Existing = NameCategoryMap[Cat->getDeclName()]; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4074 | if (Existing && |
| 4075 | Reader.getOwningModuleFile(Existing) |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4076 | != Reader.getOwningModuleFile(Cat)) { |
| 4077 | // FIXME: We should not warn for duplicates in diamond: |
| 4078 | // |
| 4079 | // MT // |
| 4080 | // / \ // |
| 4081 | // ML MR // |
| 4082 | // \ / // |
| 4083 | // MB // |
| 4084 | // |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4085 | // If there are duplicates in ML/MR, there will be warning when |
| 4086 | // creating MB *and* when importing MB. We should not warn when |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4087 | // importing. |
| 4088 | Reader.Diag(Cat->getLocation(), diag::warn_dup_category_def) |
| 4089 | << Interface->getDeclName() << Cat->getDeclName(); |
| 4090 | Reader.Diag(Existing->getLocation(), diag::note_previous_definition); |
| 4091 | } else if (!Existing) { |
| 4092 | // Record this category. |
| 4093 | Existing = Cat; |
| 4094 | } |
| 4095 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4096 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4097 | // Add this category to the end of the chain. |
| 4098 | if (Tail) |
| 4099 | ASTDeclReader::setNextObjCCategory(Tail, Cat); |
| 4100 | else |
Douglas Gregor | 048fbfa | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 4101 | Interface->setCategoryListRaw(Cat); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4102 | Tail = Cat; |
| 4103 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4104 | |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4105 | public: |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4106 | ObjCCategoriesVisitor(ASTReader &Reader, |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4107 | ObjCInterfaceDecl *Interface, |
Alexander Shaposhnikov | 96cbe7b | 2016-09-24 02:07:19 +0000 | [diff] [blame] | 4108 | llvm::SmallPtrSetImpl<ObjCCategoryDecl *> &Deserialized, |
| 4109 | serialization::GlobalDeclID InterfaceID, |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4110 | unsigned PreviousGeneration) |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4111 | : Reader(Reader), Interface(Interface), Deserialized(Deserialized), |
| 4112 | InterfaceID(InterfaceID), PreviousGeneration(PreviousGeneration) { |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4113 | // Populate the name -> category map with the set of known categories. |
Aaron Ballman | 15063e1 | 2014-03-13 21:35:02 +0000 | [diff] [blame] | 4114 | for (auto *Cat : Interface->known_categories()) { |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4115 | if (Cat->getDeclName()) |
Aaron Ballman | 15063e1 | 2014-03-13 21:35:02 +0000 | [diff] [blame] | 4116 | NameCategoryMap[Cat->getDeclName()] = Cat; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4117 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4118 | // Keep track of the tail of the category list. |
Aaron Ballman | 15063e1 | 2014-03-13 21:35:02 +0000 | [diff] [blame] | 4119 | Tail = Cat; |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4120 | } |
| 4121 | } |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4122 | |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 4123 | bool operator()(ModuleFile &M) { |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4124 | // If we've loaded all of the category information we care about from |
| 4125 | // this module file, we're done. |
| 4126 | if (M.Generation <= PreviousGeneration) |
| 4127 | return true; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4128 | |
| 4129 | // 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] | 4130 | // module file. If there is no such mapping, we'll find nothing here |
| 4131 | // (or in any module it imports). |
| 4132 | DeclID LocalID = Reader.mapGlobalIDToModuleFileGlobalID(M, InterfaceID); |
| 4133 | if (!LocalID) |
| 4134 | return true; |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4135 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4136 | // Perform a binary search to find the local redeclarations for this |
| 4137 | // declaration (if any). |
Benjamin Kramer | a6f3950 | 2014-03-15 14:21:58 +0000 | [diff] [blame] | 4138 | const ObjCCategoriesInfo Compare = { LocalID, 0 }; |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4139 | const ObjCCategoriesInfo *Result |
| 4140 | = std::lower_bound(M.ObjCCategoriesMap, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4141 | M.ObjCCategoriesMap + M.LocalNumObjCCategoriesInMap, |
Benjamin Kramer | a6f3950 | 2014-03-15 14:21:58 +0000 | [diff] [blame] | 4142 | Compare); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4143 | if (Result == M.ObjCCategoriesMap + M.LocalNumObjCCategoriesInMap || |
| 4144 | Result->DefinitionID != LocalID) { |
| 4145 | // We didn't find anything. If the class definition is in this module |
| 4146 | // file, then the module files it depends on cannot have any categories, |
| 4147 | // so suppress further lookup. |
| 4148 | return Reader.isDeclIDFromModule(InterfaceID, M); |
| 4149 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4150 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4151 | // We found something. Dig out all of the categories. |
| 4152 | unsigned Offset = Result->Offset; |
| 4153 | unsigned N = M.ObjCCategories[Offset]; |
| 4154 | M.ObjCCategories[Offset++] = 0; // Don't try to deserialize again |
| 4155 | for (unsigned I = 0; I != N; ++I) |
| 4156 | add(cast_or_null<ObjCCategoryDecl>( |
| 4157 | Reader.GetLocalDecl(M, M.ObjCCategories[Offset++]))); |
| 4158 | return true; |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4159 | } |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4160 | }; |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4161 | |
| 4162 | } // namespace |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4163 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4164 | void ASTReader::loadObjCCategories(serialization::GlobalDeclID ID, |
| 4165 | ObjCInterfaceDecl *D, |
| 4166 | unsigned PreviousGeneration) { |
Alexander Shaposhnikov | 96cbe7b | 2016-09-24 02:07:19 +0000 | [diff] [blame] | 4167 | ObjCCategoriesVisitor Visitor(*this, D, CategoriesDeserialized, ID, |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4168 | PreviousGeneration); |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 4169 | ModuleMgr.visit(Visitor); |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4170 | } |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4171 | |
Richard Smith | d6db68c | 2014-08-07 20:58:41 +0000 | [diff] [blame] | 4172 | template<typename DeclT, typename Fn> |
| 4173 | static void forAllLaterRedecls(DeclT *D, Fn F) { |
| 4174 | F(D); |
| 4175 | |
| 4176 | // Check whether we've already merged D into its redeclaration chain. |
| 4177 | // MostRecent may or may not be nullptr if D has not been merged. If |
| 4178 | // not, walk the merged redecl chain and see if it's there. |
| 4179 | auto *MostRecent = D->getMostRecentDecl(); |
| 4180 | bool Found = false; |
| 4181 | for (auto *Redecl = MostRecent; Redecl && !Found; |
| 4182 | Redecl = Redecl->getPreviousDecl()) |
| 4183 | Found = (Redecl == D); |
| 4184 | |
| 4185 | // If this declaration is merged, apply the functor to all later decls. |
| 4186 | if (Found) { |
| 4187 | for (auto *Redecl = MostRecent; Redecl != D; |
| 4188 | Redecl = Redecl->getPreviousDecl()) |
| 4189 | F(Redecl); |
| 4190 | } |
| 4191 | } |
| 4192 | |
Vassil Vassilev | 7d26462 | 2017-06-30 22:40:17 +0000 | [diff] [blame] | 4193 | void ASTDeclReader::UpdateDecl(Decl *D, |
| 4194 | llvm::SmallVectorImpl<serialization::DeclID> &PendingLazySpecializationIDs) { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 4195 | while (Record.getIdx() < Record.size()) { |
| 4196 | switch ((DeclUpdateKind)Record.readInt()) { |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4197 | case UPD_CXX_ADDED_IMPLICIT_MEMBER: { |
Richard Smith | 1b65dbc | 2015-01-22 03:50:31 +0000 | [diff] [blame] | 4198 | auto *RD = cast<CXXRecordDecl>(D); |
Richard Smith | d6db68c | 2014-08-07 20:58:41 +0000 | [diff] [blame] | 4199 | // FIXME: If we also have an update record for instantiating the |
| 4200 | // 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] | 4201 | Decl *MD = Record.readDecl(); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4202 | assert(MD && "couldn't read decl from update record"); |
Richard Smith | 46bb581 | 2014-08-01 01:56:39 +0000 | [diff] [blame] | 4203 | // FIXME: We should call addHiddenDecl instead, to add the member |
| 4204 | // to its DeclContext. |
Richard Smith | 1b65dbc | 2015-01-22 03:50:31 +0000 | [diff] [blame] | 4205 | RD->addedMember(MD); |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 4206 | break; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4207 | } |
Argyrios Kyrtzidis | 402dbbb | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 4208 | |
| 4209 | case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION: |
Vassil Vassilev | 7d26462 | 2017-06-30 22:40:17 +0000 | [diff] [blame] | 4210 | // It will be added to the template's lazy specialization set. |
| 4211 | PendingLazySpecializationIDs.push_back(ReadDeclID()); |
Sebastian Redl | fa1f370 | 2011-04-24 16:28:13 +0000 | [diff] [blame] | 4212 | break; |
| 4213 | |
| 4214 | case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4215 | auto *Anon = ReadDeclAs<NamespaceDecl>(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4216 | |
Douglas Gregor | 540fd81 | 2012-01-09 18:07:24 +0000 | [diff] [blame] | 4217 | // Each module has its own anonymous namespace, which is disjoint from |
| 4218 | // any other module's anonymous namespaces, so don't attach the anonymous |
| 4219 | // namespace at all. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4220 | if (!Record.isModule()) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4221 | if (auto *TU = dyn_cast<TranslationUnitDecl>(D)) |
Douglas Gregor | 540fd81 | 2012-01-09 18:07:24 +0000 | [diff] [blame] | 4222 | TU->setAnonymousNamespace(Anon); |
| 4223 | else |
| 4224 | cast<NamespaceDecl>(D)->setAnonymousNamespace(Anon); |
| 4225 | } |
Sebastian Redl | fa1f370 | 2011-04-24 16:28:13 +0000 | [diff] [blame] | 4226 | break; |
| 4227 | } |
Sebastian Redl | 2ac2c72 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 4228 | |
Richard Smith | 891fc7f | 2017-12-05 01:31:47 +0000 | [diff] [blame] | 4229 | case UPD_CXX_ADDED_VAR_DEFINITION: { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4230 | auto *VD = cast<VarDecl>(D); |
Richard Smith | f501759 | 2017-11-02 01:06:00 +0000 | [diff] [blame] | 4231 | VD->NonParmVarDeclBits.IsInline = Record.readInt(); |
| 4232 | VD->NonParmVarDeclBits.IsInlineSpecified = Record.readInt(); |
Richard Smith | 05a2135 | 2017-06-22 22:18:46 +0000 | [diff] [blame] | 4233 | uint64_t Val = Record.readInt(); |
| 4234 | if (Val && !VD->getInit()) { |
| 4235 | VD->setInit(Record.readExpr()); |
| 4236 | if (Val > 1) { // IsInitKnownICE = 1, IsInitNotICE = 2, IsInitICE = 3 |
| 4237 | EvaluatedStmt *Eval = VD->ensureEvaluatedStmt(); |
| 4238 | Eval->CheckedICE = true; |
| 4239 | Eval->IsICE = Val == 3; |
| 4240 | } |
| 4241 | } |
Sebastian Redl | 2ac2c72 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 4242 | break; |
Richard Smith | 05a2135 | 2017-06-22 22:18:46 +0000 | [diff] [blame] | 4243 | } |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 4244 | |
Richard Smith | 891fc7f | 2017-12-05 01:31:47 +0000 | [diff] [blame] | 4245 | case UPD_CXX_POINT_OF_INSTANTIATION: { |
| 4246 | SourceLocation POI = Record.readSourceLocation(); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4247 | if (auto *VTSD = dyn_cast<VarTemplateSpecializationDecl>(D)) { |
Richard Smith | 891fc7f | 2017-12-05 01:31:47 +0000 | [diff] [blame] | 4248 | VTSD->setPointOfInstantiation(POI); |
| 4249 | } else if (auto *VD = dyn_cast<VarDecl>(D)) { |
| 4250 | VD->getMemberSpecializationInfo()->setPointOfInstantiation(POI); |
| 4251 | } else { |
| 4252 | auto *FD = cast<FunctionDecl>(D); |
| 4253 | if (auto *FTSInfo = FD->TemplateOrSpecialization |
| 4254 | .dyn_cast<FunctionTemplateSpecializationInfo *>()) |
| 4255 | FTSInfo->setPointOfInstantiation(POI); |
| 4256 | else |
| 4257 | FD->TemplateOrSpecialization.get<MemberSpecializationInfo *>() |
| 4258 | ->setPointOfInstantiation(POI); |
| 4259 | } |
| 4260 | break; |
| 4261 | } |
| 4262 | |
John McCall | 32791cc | 2016-01-06 22:34:54 +0000 | [diff] [blame] | 4263 | case UPD_CXX_INSTANTIATED_DEFAULT_ARGUMENT: { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4264 | auto *Param = cast<ParmVarDecl>(D); |
John McCall | 32791cc | 2016-01-06 22:34:54 +0000 | [diff] [blame] | 4265 | |
| 4266 | // We have to read the default argument regardless of whether we use it |
| 4267 | // so that hypothetical further update records aren't messed up. |
| 4268 | // TODO: Add a function to skip over the next expr record. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4269 | auto *DefaultArg = Record.readExpr(); |
John McCall | 32791cc | 2016-01-06 22:34:54 +0000 | [diff] [blame] | 4270 | |
| 4271 | // Only apply the update if the parameter still has an uninstantiated |
| 4272 | // default argument. |
| 4273 | if (Param->hasUninstantiatedDefaultArg()) |
| 4274 | Param->setDefaultArg(DefaultArg); |
| 4275 | break; |
| 4276 | } |
| 4277 | |
Richard Smith | 4b054b2 | 2016-08-24 21:25:37 +0000 | [diff] [blame] | 4278 | case UPD_CXX_INSTANTIATED_DEFAULT_MEMBER_INITIALIZER: { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4279 | auto *FD = cast<FieldDecl>(D); |
| 4280 | auto *DefaultInit = Record.readExpr(); |
Richard Smith | 4b054b2 | 2016-08-24 21:25:37 +0000 | [diff] [blame] | 4281 | |
| 4282 | // Only apply the update if the field still has an uninstantiated |
| 4283 | // default member initializer. |
| 4284 | if (FD->hasInClassInitializer() && !FD->getInClassInitializer()) { |
| 4285 | if (DefaultInit) |
| 4286 | FD->setInClassInitializer(DefaultInit); |
| 4287 | else |
| 4288 | // Instantiation failed. We can get here if we serialized an AST for |
| 4289 | // an invalid program. |
| 4290 | FD->removeInClassInitializer(); |
| 4291 | } |
| 4292 | break; |
| 4293 | } |
| 4294 | |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 4295 | case UPD_CXX_ADDED_FUNCTION_DEFINITION: { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4296 | auto *FD = cast<FunctionDecl>(D); |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 4297 | if (Reader.PendingBodies[FD]) { |
| 4298 | // FIXME: Maybe check for ODR violations. |
| 4299 | // It's safe to stop now because this update record is always last. |
| 4300 | return; |
| 4301 | } |
| 4302 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 4303 | if (Record.readInt()) { |
Richard Smith | 195d8ef | 2014-05-29 03:15:31 +0000 | [diff] [blame] | 4304 | // Maintain AST consistency: any later redeclarations of this function |
| 4305 | // are inline if this one is. (We might have merged another declaration |
| 4306 | // into this one.) |
Richard Smith | d6db68c | 2014-08-07 20:58:41 +0000 | [diff] [blame] | 4307 | forAllLaterRedecls(FD, [](FunctionDecl *FD) { |
| 4308 | FD->setImplicitlyInline(); |
| 4309 | }); |
Richard Smith | 195d8ef | 2014-05-29 03:15:31 +0000 | [diff] [blame] | 4310 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4311 | FD->setInnerLocStart(ReadSourceLocation()); |
David Blaikie | ac4345c | 2017-02-12 18:45:31 +0000 | [diff] [blame] | 4312 | ReadFunctionDefinition(FD); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 4313 | assert(Record.getIdx() == Record.size() && "lazy body must be last"); |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 4314 | break; |
| 4315 | } |
| 4316 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4317 | case UPD_CXX_INSTANTIATED_CLASS_DEFINITION: { |
| 4318 | auto *RD = cast<CXXRecordDecl>(D); |
Richard Smith | b648399 | 2016-05-17 22:44:15 +0000 | [diff] [blame] | 4319 | auto *OldDD = RD->getCanonicalDecl()->DefinitionData; |
Richard Smith | 2a9e5c5 | 2015-02-03 03:32:14 +0000 | [diff] [blame] | 4320 | bool HadRealDefinition = |
Richard Smith | 7483d20 | 2015-02-04 01:23:46 +0000 | [diff] [blame] | 4321 | OldDD && (OldDD->Definition != RD || |
| 4322 | !Reader.PendingFakeDefinitionData.count(OldDD)); |
Akira Hatanaka | fcbe17c | 2018-03-28 21:13:14 +0000 | [diff] [blame] | 4323 | RD->setParamDestroyedInCallee(Record.readInt()); |
Akira Hatanaka | e6313ac | 2018-04-09 22:48:22 +0000 | [diff] [blame] | 4324 | RD->setArgPassingRestrictions( |
| 4325 | (RecordDecl::ArgPassingKind)Record.readInt()); |
Richard Smith | 2a9e5c5 | 2015-02-03 03:32:14 +0000 | [diff] [blame] | 4326 | ReadCXXRecordDefinition(RD, /*Update*/true); |
| 4327 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4328 | // Visible update is handled separately. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4329 | uint64_t LexicalOffset = ReadLocalOffset(); |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 4330 | if (!HadRealDefinition && LexicalOffset) { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 4331 | Record.readLexicalDeclContextStorage(LexicalOffset, RD); |
Richard Smith | 2a9e5c5 | 2015-02-03 03:32:14 +0000 | [diff] [blame] | 4332 | Reader.PendingFakeDefinitionData.erase(OldDD); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4333 | } |
| 4334 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 4335 | auto TSK = (TemplateSpecializationKind)Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4336 | SourceLocation POI = ReadSourceLocation(); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4337 | if (MemberSpecializationInfo *MSInfo = |
| 4338 | RD->getMemberSpecializationInfo()) { |
| 4339 | MSInfo->setTemplateSpecializationKind(TSK); |
| 4340 | MSInfo->setPointOfInstantiation(POI); |
| 4341 | } else { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4342 | auto *Spec = cast<ClassTemplateSpecializationDecl>(RD); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4343 | Spec->setTemplateSpecializationKind(TSK); |
| 4344 | Spec->setPointOfInstantiation(POI); |
Richard Smith | df35205 | 2014-05-22 20:59:29 +0000 | [diff] [blame] | 4345 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 4346 | if (Record.readInt()) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4347 | auto *PartialSpec = |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4348 | ReadDeclAs<ClassTemplatePartialSpecializationDecl>(); |
Richard Smith | df35205 | 2014-05-22 20:59:29 +0000 | [diff] [blame] | 4349 | SmallVector<TemplateArgument, 8> TemplArgs; |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 4350 | Record.readTemplateArgumentList(TemplArgs); |
Richard Smith | df35205 | 2014-05-22 20:59:29 +0000 | [diff] [blame] | 4351 | auto *TemplArgList = TemplateArgumentList::CreateCopy( |
David Majnemer | 8b62269 | 2016-07-03 21:17:51 +0000 | [diff] [blame] | 4352 | Reader.getContext(), TemplArgs); |
Richard Smith | 72544f8 | 2014-08-14 03:30:27 +0000 | [diff] [blame] | 4353 | |
| 4354 | // FIXME: If we already have a partial specialization set, |
| 4355 | // check that it matches. |
| 4356 | if (!Spec->getSpecializedTemplateOrPartial() |
| 4357 | .is<ClassTemplatePartialSpecializationDecl *>()) |
| 4358 | Spec->setInstantiationOf(PartialSpec, TemplArgList); |
Richard Smith | df35205 | 2014-05-22 20:59:29 +0000 | [diff] [blame] | 4359 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4360 | } |
| 4361 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 4362 | RD->setTagKind((TagTypeKind)Record.readInt()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4363 | RD->setLocation(ReadSourceLocation()); |
| 4364 | RD->setLocStart(ReadSourceLocation()); |
| 4365 | RD->setBraceRange(ReadSourceRange()); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4366 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 4367 | if (Record.readInt()) { |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4368 | AttrVec Attrs; |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 4369 | Record.readAttributes(Attrs); |
Richard Smith | 842e46e | 2016-10-26 02:31:56 +0000 | [diff] [blame] | 4370 | // If the declaration already has attributes, we assume that some other |
| 4371 | // AST file already loaded them. |
| 4372 | if (!D->hasAttrs()) |
| 4373 | D->setAttrsImpl(Attrs, Reader.getContext()); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4374 | } |
| 4375 | break; |
| 4376 | } |
| 4377 | |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 4378 | case UPD_CXX_RESOLVED_DTOR_DELETE: { |
| 4379 | // Set the 'operator delete' directly to avoid emitting another update |
| 4380 | // record. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4381 | auto *Del = ReadDeclAs<FunctionDecl>(); |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 4382 | auto *First = cast<CXXDestructorDecl>(D->getCanonicalDecl()); |
Richard Smith | 5b34958 | 2017-10-13 01:55:36 +0000 | [diff] [blame] | 4383 | auto *ThisArg = Record.readExpr(); |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 4384 | // FIXME: Check consistency if we have an old and new operator delete. |
Richard Smith | 5b34958 | 2017-10-13 01:55:36 +0000 | [diff] [blame] | 4385 | if (!First->OperatorDelete) { |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 4386 | First->OperatorDelete = Del; |
Richard Smith | 5b34958 | 2017-10-13 01:55:36 +0000 | [diff] [blame] | 4387 | First->OperatorDeleteThisArg = ThisArg; |
| 4388 | } |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 4389 | break; |
| 4390 | } |
| 4391 | |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 4392 | case UPD_CXX_RESOLVED_EXCEPTION_SPEC: { |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 4393 | FunctionProtoType::ExceptionSpecInfo ESI; |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 4394 | SmallVector<QualType, 8> ExceptionStorage; |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 4395 | Record.readExceptionSpec(ExceptionStorage, ESI); |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 4396 | |
| 4397 | // Update this declaration's exception specification, if needed. |
| 4398 | auto *FD = cast<FunctionDecl>(D); |
| 4399 | auto *FPT = FD->getType()->castAs<FunctionProtoType>(); |
| 4400 | // FIXME: If the exception specification is already present, check that it |
| 4401 | // matches. |
| 4402 | if (isUnresolvedExceptionSpec(FPT->getExceptionSpecType())) { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 4403 | FD->setType(Reader.getContext().getFunctionType( |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 4404 | FPT->getReturnType(), FPT->getParamTypes(), |
| 4405 | FPT->getExtProtoInfo().withExceptionSpec(ESI))); |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 4406 | |
| 4407 | // When we get to the end of deserializing, see if there are other decls |
| 4408 | // that we need to propagate this exception specification onto. |
| 4409 | Reader.PendingExceptionSpecUpdates.insert( |
| 4410 | std::make_pair(FD->getCanonicalDecl(), FD)); |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 4411 | } |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 4412 | break; |
| 4413 | } |
| 4414 | |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 4415 | case UPD_CXX_DEDUCED_RETURN_TYPE: { |
Richard Smith | a62d198 | 2018-08-03 01:00:01 +0000 | [diff] [blame] | 4416 | auto *FD = cast<FunctionDecl>(D); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 4417 | QualType DeducedResultType = Record.readType(); |
Richard Smith | a62d198 | 2018-08-03 01:00:01 +0000 | [diff] [blame] | 4418 | Reader.PendingDeducedTypeUpdates.insert( |
| 4419 | {FD->getCanonicalDecl(), DeducedResultType}); |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 4420 | break; |
| 4421 | } |
Eli Friedman | 276dd18 | 2013-09-05 00:02:25 +0000 | [diff] [blame] | 4422 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4423 | case UPD_DECL_MARKED_USED: |
Richard Smith | 675d279 | 2014-06-16 20:26:19 +0000 | [diff] [blame] | 4424 | // Maintain AST consistency: any later redeclarations are used too. |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 4425 | D->markUsed(Reader.getContext()); |
Eli Friedman | 276dd18 | 2013-09-05 00:02:25 +0000 | [diff] [blame] | 4426 | break; |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4427 | |
| 4428 | case UPD_MANGLING_NUMBER: |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 4429 | Reader.getContext().setManglingNumber(cast<NamedDecl>(D), |
| 4430 | Record.readInt()); |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4431 | break; |
| 4432 | |
| 4433 | case UPD_STATIC_LOCAL_NUMBER: |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 4434 | Reader.getContext().setStaticLocalNumber(cast<VarDecl>(D), |
| 4435 | Record.readInt()); |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4436 | break; |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 4437 | |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 4438 | case UPD_DECL_MARKED_OPENMP_THREADPRIVATE: |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 4439 | D->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit(Reader.getContext(), |
| 4440 | ReadSourceRange())); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 4441 | break; |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 4442 | |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 4443 | case UPD_DECL_EXPORTED: { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4444 | unsigned SubmoduleID = readSubmoduleID(); |
Richard Smith | beb4478 | 2015-06-20 01:05:19 +0000 | [diff] [blame] | 4445 | auto *Exported = cast<NamedDecl>(D); |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 4446 | Module *Owner = SubmoduleID ? Reader.getSubmodule(SubmoduleID) : nullptr; |
Richard Smith | 13897eb | 2018-09-12 23:37:00 +0000 | [diff] [blame] | 4447 | Reader.getContext().mergeDefinitionIntoModule(Exported, Owner); |
| 4448 | Reader.PendingMergedDefinitionsToDeduplicate.insert(Exported); |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 4449 | break; |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 4450 | } |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 4451 | |
Dmitry Polukhin | d69b505 | 2016-05-09 14:59:13 +0000 | [diff] [blame] | 4452 | case UPD_DECL_MARKED_OPENMP_DECLARETARGET: |
Alexey Bataev | d01b749 | 2018-08-15 19:45:12 +0000 | [diff] [blame] | 4453 | D->addAttr(OMPDeclareTargetDeclAttr::CreateImplicit( |
| 4454 | Reader.getContext(), |
| 4455 | static_cast<OMPDeclareTargetDeclAttr::MapTypeTy>(Record.readInt()), |
| 4456 | ReadSourceRange())); |
| 4457 | break; |
| 4458 | |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 4459 | case UPD_ADDED_ATTR_TO_RECORD: |
| 4460 | AttrVec Attrs; |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 4461 | Record.readAttributes(Attrs); |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 4462 | assert(Attrs.size() == 1); |
| 4463 | D->addAttr(Attrs[0]); |
| 4464 | break; |
| 4465 | } |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 4466 | } |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4467 | } |