Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1 | //===- ASTReaderDecl.cpp - Decl Deserialization ---------------------------===// |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 2 | // |
Chandler Carruth | 2946cd7 | 2019-01-19 08:50:56 +0000 | [diff] [blame] | 3 | // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. |
| 4 | // See https://llvm.org/LICENSE.txt for license information. |
| 5 | // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | // |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 9 | // This file implements the ASTReader::ReadDeclRecord method, which is the |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 10 | // entrypoint for loading a decl. |
| 11 | // |
| 12 | //===----------------------------------------------------------------------===// |
| 13 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 14 | #include "ASTCommon.h" |
Benjamin Kramer | 89f0b2d | 2012-04-15 12:36:49 +0000 | [diff] [blame] | 15 | #include "ASTReaderInternals.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 16 | #include "clang/AST/ASTContext.h" |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 17 | #include "clang/AST/Attr.h" |
| 18 | #include "clang/AST/AttrIterator.h" |
| 19 | #include "clang/AST/Decl.h" |
| 20 | #include "clang/AST/DeclBase.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 21 | #include "clang/AST/DeclCXX.h" |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 22 | #include "clang/AST/DeclFriend.h" |
| 23 | #include "clang/AST/DeclObjC.h" |
| 24 | #include "clang/AST/DeclOpenMP.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 25 | #include "clang/AST/DeclTemplate.h" |
| 26 | #include "clang/AST/DeclVisitor.h" |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 27 | #include "clang/AST/DeclarationName.h" |
Chandler Carruth | 3a02247 | 2012-12-04 09:13:33 +0000 | [diff] [blame] | 28 | #include "clang/AST/Expr.h" |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 29 | #include "clang/AST/ExternalASTSource.h" |
| 30 | #include "clang/AST/LambdaCapture.h" |
| 31 | #include "clang/AST/NestedNameSpecifier.h" |
Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 32 | #include "clang/AST/OpenMPClause.h" |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 33 | #include "clang/AST/Redeclarable.h" |
| 34 | #include "clang/AST/Stmt.h" |
| 35 | #include "clang/AST/TemplateBase.h" |
| 36 | #include "clang/AST/Type.h" |
| 37 | #include "clang/AST/UnresolvedSet.h" |
| 38 | #include "clang/Basic/AttrKinds.h" |
| 39 | #include "clang/Basic/ExceptionSpecificationType.h" |
| 40 | #include "clang/Basic/IdentifierTable.h" |
| 41 | #include "clang/Basic/LLVM.h" |
| 42 | #include "clang/Basic/Lambda.h" |
| 43 | #include "clang/Basic/LangOptions.h" |
| 44 | #include "clang/Basic/Linkage.h" |
| 45 | #include "clang/Basic/Module.h" |
| 46 | #include "clang/Basic/PragmaKinds.h" |
| 47 | #include "clang/Basic/SourceLocation.h" |
| 48 | #include "clang/Basic/Specifiers.h" |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 49 | #include "clang/Sema/IdentifierResolver.h" |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 50 | #include "clang/Serialization/ASTBitCodes.h" |
Mehdi Amini | 9670f84 | 2016-07-18 19:02:11 +0000 | [diff] [blame] | 51 | #include "clang/Serialization/ASTReader.h" |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 52 | #include "clang/Serialization/ContinuousRangeMap.h" |
| 53 | #include "clang/Serialization/Module.h" |
| 54 | #include "llvm/ADT/DenseMap.h" |
| 55 | #include "llvm/ADT/FoldingSet.h" |
| 56 | #include "llvm/ADT/STLExtras.h" |
| 57 | #include "llvm/ADT/SmallPtrSet.h" |
| 58 | #include "llvm/ADT/SmallVector.h" |
| 59 | #include "llvm/ADT/iterator_range.h" |
Francis Visoiu Mistrih | e030827 | 2019-07-03 22:40:07 +0000 | [diff] [blame] | 60 | #include "llvm/Bitstream/BitstreamReader.h" |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 61 | #include "llvm/Support/Casting.h" |
| 62 | #include "llvm/Support/ErrorHandling.h" |
Argyrios Kyrtzidis | 0f7d7ab | 2012-05-04 01:49:36 +0000 | [diff] [blame] | 63 | #include "llvm/Support/SaveAndRestore.h" |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 64 | #include <algorithm> |
| 65 | #include <cassert> |
| 66 | #include <cstdint> |
| 67 | #include <cstring> |
| 68 | #include <string> |
| 69 | #include <utility> |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 70 | |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 71 | using namespace clang; |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 72 | using namespace serialization; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 73 | |
| 74 | //===----------------------------------------------------------------------===// |
| 75 | // Declaration deserialization |
| 76 | //===----------------------------------------------------------------------===// |
| 77 | |
Argyrios Kyrtzidis | 74d28bd | 2010-06-29 22:47:00 +0000 | [diff] [blame] | 78 | namespace clang { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 79 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 80 | class ASTDeclReader : public DeclVisitor<ASTDeclReader, void> { |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 81 | ASTReader &Reader; |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 82 | ASTRecordReader &Record; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 83 | ASTReader::RecordLocation Loc; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 84 | const DeclID ThisDeclID; |
Richard Smith | cb34bd3 | 2016-03-27 07:28:06 +0000 | [diff] [blame] | 85 | const SourceLocation ThisDeclLoc; |
Vassil Vassilev | 6565dfc | 2016-02-26 10:43:34 +0000 | [diff] [blame] | 86 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 87 | using RecordData = ASTReader::RecordData; |
| 88 | |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 89 | TypeID DeferredTypeID = 0; |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 90 | unsigned AnonymousDeclNumber; |
| 91 | GlobalDeclID NamedDeclForTagDecl = 0; |
| 92 | IdentifierInfo *TypedefNameForLinkage = nullptr; |
| 93 | |
| 94 | bool HasPendingBody = false; |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 95 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 96 | ///A flag to carry the information for a decl from the entity is |
Vassil Vassilev | 928c825 | 2016-04-28 14:13:28 +0000 | [diff] [blame] | 97 | /// used. We use it to delay the marking of the canonical decl as used until |
| 98 | /// the entire declaration is deserialized and merged. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 99 | bool IsDeclMarkedUsed = false; |
Vassil Vassilev | 928c825 | 2016-04-28 14:13:28 +0000 | [diff] [blame] | 100 | |
Sebastian Redl | c67764e | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 101 | uint64_t GetCurrentCursorOffset(); |
Vassil Vassilev | 6565dfc | 2016-02-26 10:43:34 +0000 | [diff] [blame] | 102 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 103 | uint64_t ReadLocalOffset() { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 104 | uint64_t LocalOffset = Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 105 | assert(LocalOffset < Loc.Offset && "offset point after current record"); |
| 106 | return LocalOffset ? Loc.Offset - LocalOffset : 0; |
Richard Smith | e37e9f4 | 2016-03-25 01:17:43 +0000 | [diff] [blame] | 107 | } |
| 108 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 109 | uint64_t ReadGlobalOffset() { |
| 110 | uint64_t Local = ReadLocalOffset(); |
| 111 | return Local ? Record.getGlobalBitOffset(Local) : 0; |
Richard Smith | aa165cf | 2016-04-13 21:57:08 +0000 | [diff] [blame] | 112 | } |
| 113 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 114 | SourceLocation ReadSourceLocation() { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 115 | return Record.readSourceLocation(); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 116 | } |
Vassil Vassilev | 6565dfc | 2016-02-26 10:43:34 +0000 | [diff] [blame] | 117 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 118 | SourceRange ReadSourceRange() { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 119 | return Record.readSourceRange(); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 120 | } |
Vassil Vassilev | 6565dfc | 2016-02-26 10:43:34 +0000 | [diff] [blame] | 121 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 122 | TypeSourceInfo *GetTypeSourceInfo() { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 123 | return Record.getTypeSourceInfo(); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 124 | } |
Vassil Vassilev | 6565dfc | 2016-02-26 10:43:34 +0000 | [diff] [blame] | 125 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 126 | serialization::DeclID ReadDeclID() { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 127 | return Record.readDeclID(); |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 128 | } |
Richard Smith | 0b88437 | 2015-02-27 00:25:58 +0000 | [diff] [blame] | 129 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 130 | std::string ReadString() { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 131 | return Record.readString(); |
Nico Weber | 6622029 | 2016-03-02 17:28:48 +0000 | [diff] [blame] | 132 | } |
| 133 | |
Richard Smith | 0b88437 | 2015-02-27 00:25:58 +0000 | [diff] [blame] | 134 | void ReadDeclIDList(SmallVectorImpl<DeclID> &IDs) { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 135 | for (unsigned I = 0, Size = Record.readInt(); I != Size; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 136 | IDs.push_back(ReadDeclID()); |
Richard Smith | 0b88437 | 2015-02-27 00:25:58 +0000 | [diff] [blame] | 137 | } |
| 138 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 139 | Decl *ReadDecl() { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 140 | return Record.readDecl(); |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | template<typename T> |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 144 | T *ReadDeclAs() { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 145 | return Record.readDeclAs<T>(); |
Douglas Gregor | 7fb0919 | 2011-07-21 22:35:25 +0000 | [diff] [blame] | 146 | } |
| 147 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 148 | void ReadQualifierInfo(QualifierInfo &Info) { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 149 | Record.readQualifierInfo(Info); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 150 | } |
Sebastian Redl | c67764e | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 151 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 152 | void ReadDeclarationNameLoc(DeclarationNameLoc &DNLoc, DeclarationName Name) { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 153 | Record.readDeclarationNameLoc(DNLoc, Name); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | serialization::SubmoduleID readSubmoduleID() { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 157 | if (Record.getIdx() == Record.size()) |
Douglas Gregor | cf68c58 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 158 | return 0; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 159 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 160 | return Record.getGlobalSubmoduleID(Record.readInt()); |
Douglas Gregor | cf68c58 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 161 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 162 | |
| 163 | Module *readModule() { |
| 164 | return Record.getSubmodule(readSubmoduleID()); |
Douglas Gregor | ba34552 | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 165 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 166 | |
Richard Smith | 2a9e5c5 | 2015-02-03 03:32:14 +0000 | [diff] [blame] | 167 | void ReadCXXRecordDefinition(CXXRecordDecl *D, bool Update); |
David Blaikie | 1ac9c98 | 2017-04-11 21:13:37 +0000 | [diff] [blame] | 168 | void ReadCXXDefinitionData(struct CXXRecordDecl::DefinitionData &Data, |
| 169 | const CXXRecordDecl *D); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 170 | void MergeDefinitionData(CXXRecordDecl *D, |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 171 | struct CXXRecordDecl::DefinitionData &&NewDD); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 172 | void ReadObjCDefinitionData(struct ObjCInterfaceDecl::DefinitionData &Data); |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 173 | void MergeDefinitionData(ObjCInterfaceDecl *D, |
| 174 | struct ObjCInterfaceDecl::DefinitionData &&NewDD); |
Graydon Hoare | e0a6835 | 2017-06-28 18:36:27 +0000 | [diff] [blame] | 175 | void ReadObjCDefinitionData(struct ObjCProtocolDecl::DefinitionData &Data); |
| 176 | void MergeDefinitionData(ObjCProtocolDecl *D, |
| 177 | struct ObjCProtocolDecl::DefinitionData &&NewDD); |
Argyrios Kyrtzidis | eb39d9a | 2010-10-24 17:26:40 +0000 | [diff] [blame] | 178 | |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 179 | static DeclContext *getPrimaryDCForAnonymousDecl(DeclContext *LexicalDC); |
| 180 | |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 181 | static NamedDecl *getAnonymousDeclForMerging(ASTReader &Reader, |
| 182 | DeclContext *DC, |
| 183 | unsigned Index); |
| 184 | static void setAnonymousDeclForMerging(ASTReader &Reader, DeclContext *DC, |
| 185 | unsigned Index, NamedDecl *D); |
| 186 | |
Richard Smith | 0144f51 | 2015-08-22 02:09:38 +0000 | [diff] [blame] | 187 | /// Results from loading a RedeclarableDecl. |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 188 | class RedeclarableResult { |
Richard Smith | 5a4737c | 2015-02-06 02:42:59 +0000 | [diff] [blame] | 189 | Decl *MergeWith; |
Alexander Shaposhnikov | fbc4d68 | 2016-09-24 04:21:53 +0000 | [diff] [blame] | 190 | GlobalDeclID FirstID; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 191 | bool IsKeyDecl; |
Richard Smith | c89bb9d | 2015-02-25 01:11:29 +0000 | [diff] [blame] | 192 | |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 193 | public: |
Alexander Shaposhnikov | fbc4d68 | 2016-09-24 04:21:53 +0000 | [diff] [blame] | 194 | RedeclarableResult(Decl *MergeWith, GlobalDeclID FirstID, bool IsKeyDecl) |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 195 | : MergeWith(MergeWith), FirstID(FirstID), IsKeyDecl(IsKeyDecl) {} |
Richard Smith | 9b88a4c | 2015-07-27 05:40:23 +0000 | [diff] [blame] | 196 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 197 | /// Retrieve the first ID. |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 198 | GlobalDeclID getFirstID() const { return FirstID; } |
Richard Smith | 5a4737c | 2015-02-06 02:42:59 +0000 | [diff] [blame] | 199 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 200 | /// Is this declaration a key declaration? |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 201 | bool isKeyDecl() const { return IsKeyDecl; } |
| 202 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 203 | /// Get a known declaration that this should be merged with, if |
Richard Smith | 5a4737c | 2015-02-06 02:42:59 +0000 | [diff] [blame] | 204 | /// any. |
| 205 | Decl *getKnownMergeTarget() const { return MergeWith; } |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 206 | }; |
Douglas Gregor | fe732d5 | 2013-01-21 16:16:40 +0000 | [diff] [blame] | 207 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 208 | /// Class used to capture the result of searching for an existing |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 209 | /// declaration of a specific kind and name, along with the ability |
| 210 | /// to update the place where this result was found (the declaration |
| 211 | /// chain hanging off an identifier or the DeclContext we searched in) |
| 212 | /// if requested. |
| 213 | class FindExistingResult { |
| 214 | ASTReader &Reader; |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 215 | NamedDecl *New = nullptr; |
| 216 | NamedDecl *Existing = nullptr; |
| 217 | bool AddResult = false; |
| 218 | unsigned AnonymousDeclNumber = 0; |
| 219 | IdentifierInfo *TypedefNameForLinkage = nullptr; |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 220 | |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 221 | public: |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 222 | FindExistingResult(ASTReader &Reader) : Reader(Reader) {} |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 223 | |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 224 | FindExistingResult(ASTReader &Reader, NamedDecl *New, NamedDecl *Existing, |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 225 | unsigned AnonymousDeclNumber, |
| 226 | IdentifierInfo *TypedefNameForLinkage) |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 227 | : Reader(Reader), New(New), Existing(Existing), AddResult(true), |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 228 | AnonymousDeclNumber(AnonymousDeclNumber), |
| 229 | TypedefNameForLinkage(TypedefNameForLinkage) {} |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 230 | |
Benjamin Kramer | b6aadc1 | 2016-08-06 12:45:16 +0000 | [diff] [blame] | 231 | FindExistingResult(FindExistingResult &&Other) |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 232 | : Reader(Other.Reader), New(Other.New), Existing(Other.Existing), |
| 233 | AddResult(Other.AddResult), |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 234 | AnonymousDeclNumber(Other.AnonymousDeclNumber), |
| 235 | TypedefNameForLinkage(Other.TypedefNameForLinkage) { |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 236 | Other.AddResult = false; |
| 237 | } |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 238 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 239 | FindExistingResult &operator=(FindExistingResult &&) = delete; |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 240 | ~FindExistingResult(); |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 241 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 242 | /// Suppress the addition of this result into the known set of |
Douglas Gregor | 2009cee | 2012-01-03 22:46:00 +0000 | [diff] [blame] | 243 | /// names. |
| 244 | void suppress() { AddResult = false; } |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 245 | |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 246 | operator NamedDecl*() const { return Existing; } |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 247 | |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 248 | template<typename T> |
| 249 | operator T*() const { return dyn_cast_or_null<T>(Existing); } |
| 250 | }; |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 251 | |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 252 | static DeclContext *getPrimaryContextForMerging(ASTReader &Reader, |
| 253 | DeclContext *DC); |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 254 | FindExistingResult findExisting(NamedDecl *D); |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 255 | |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 256 | public: |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 257 | ASTDeclReader(ASTReader &Reader, ASTRecordReader &Record, |
| 258 | ASTReader::RecordLocation Loc, |
| 259 | DeclID thisDeclID, SourceLocation ThisDeclLoc) |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 260 | : Reader(Reader), Record(Record), Loc(Loc), ThisDeclID(thisDeclID), |
| 261 | ThisDeclLoc(ThisDeclLoc) {} |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 262 | |
Vassil Vassilev | 7d26462 | 2017-06-30 22:40:17 +0000 | [diff] [blame] | 263 | template <typename T> static |
| 264 | void AddLazySpecializations(T *D, |
| 265 | SmallVectorImpl<serialization::DeclID>& IDs) { |
| 266 | if (IDs.empty()) |
| 267 | return; |
| 268 | |
| 269 | // FIXME: We should avoid this pattern of getting the ASTContext. |
| 270 | ASTContext &C = D->getASTContext(); |
| 271 | |
| 272 | auto *&LazySpecializations = D->getCommonPtr()->LazySpecializations; |
| 273 | |
| 274 | if (auto &Old = LazySpecializations) { |
| 275 | IDs.insert(IDs.end(), Old + 1, Old + 1 + Old[0]); |
Fangrui Song | 55fab26 | 2018-09-26 22:16:28 +0000 | [diff] [blame] | 276 | llvm::sort(IDs); |
Vassil Vassilev | 7d26462 | 2017-06-30 22:40:17 +0000 | [diff] [blame] | 277 | IDs.erase(std::unique(IDs.begin(), IDs.end()), IDs.end()); |
| 278 | } |
| 279 | |
| 280 | auto *Result = new (C) serialization::DeclID[1 + IDs.size()]; |
| 281 | *Result = IDs.size(); |
| 282 | std::copy(IDs.begin(), IDs.end(), Result + 1); |
| 283 | |
| 284 | LazySpecializations = Result; |
| 285 | } |
| 286 | |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 287 | template <typename DeclT> |
Richard Smith | c3a5325 | 2015-02-28 05:57:02 +0000 | [diff] [blame] | 288 | static Decl *getMostRecentDeclImpl(Redeclarable<DeclT> *D); |
| 289 | static Decl *getMostRecentDeclImpl(...); |
| 290 | static Decl *getMostRecentDecl(Decl *D); |
| 291 | |
| 292 | template <typename DeclT> |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 293 | static void attachPreviousDeclImpl(ASTReader &Reader, |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 294 | Redeclarable<DeclT> *D, Decl *Previous, |
| 295 | Decl *Canon); |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 296 | static void attachPreviousDeclImpl(ASTReader &Reader, ...); |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 297 | static void attachPreviousDecl(ASTReader &Reader, Decl *D, Decl *Previous, |
| 298 | Decl *Canon); |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 299 | |
| 300 | template <typename DeclT> |
| 301 | static void attachLatestDeclImpl(Redeclarable<DeclT> *D, Decl *Latest); |
| 302 | static void attachLatestDeclImpl(...); |
Douglas Gregor | 05f1035 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 303 | static void attachLatestDecl(Decl *D, Decl *latest); |
Argyrios Kyrtzidis | 9fdd254 | 2011-02-12 07:50:47 +0000 | [diff] [blame] | 304 | |
Richard Smith | 851072e | 2014-05-19 20:59:20 +0000 | [diff] [blame] | 305 | template <typename DeclT> |
| 306 | static void markIncompleteDeclChainImpl(Redeclarable<DeclT> *D); |
| 307 | static void markIncompleteDeclChainImpl(...); |
| 308 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 309 | /// Determine whether this declaration has a pending body. |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 310 | bool hasPendingBody() const { return HasPendingBody; } |
| 311 | |
David Blaikie | ac4345c | 2017-02-12 18:45:31 +0000 | [diff] [blame] | 312 | void ReadFunctionDefinition(FunctionDecl *FD); |
Argyrios Kyrtzidis | 318b0e7 | 2010-07-02 11:55:01 +0000 | [diff] [blame] | 313 | void Visit(Decl *D); |
| 314 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 315 | void UpdateDecl(Decl *D, SmallVectorImpl<serialization::DeclID> &); |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 316 | |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 317 | static void setNextObjCCategory(ObjCCategoryDecl *Cat, |
| 318 | ObjCCategoryDecl *Next) { |
| 319 | Cat->NextClassCategory = Next; |
| 320 | } |
| 321 | |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 322 | void VisitDecl(Decl *D); |
Nico Weber | 6622029 | 2016-03-02 17:28:48 +0000 | [diff] [blame] | 323 | void VisitPragmaCommentDecl(PragmaCommentDecl *D); |
Nico Weber | cbbaeb1 | 2016-03-02 19:28:54 +0000 | [diff] [blame] | 324 | void VisitPragmaDetectMismatchDecl(PragmaDetectMismatchDecl *D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 325 | void VisitTranslationUnitDecl(TranslationUnitDecl *TU); |
| 326 | void VisitNamedDecl(NamedDecl *ND); |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 327 | void VisitLabelDecl(LabelDecl *LD); |
Douglas Gregor | e31bbd9 | 2010-02-21 18:22:14 +0000 | [diff] [blame] | 328 | void VisitNamespaceDecl(NamespaceDecl *D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 329 | void VisitUsingDirectiveDecl(UsingDirectiveDecl *D); |
| 330 | void VisitNamespaceAliasDecl(NamespaceAliasDecl *D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 331 | void VisitTypeDecl(TypeDecl *TD); |
Richard Smith | 43ccec8e | 2014-08-26 03:52:16 +0000 | [diff] [blame] | 332 | RedeclarableResult VisitTypedefNameDecl(TypedefNameDecl *TD); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 333 | void VisitTypedefDecl(TypedefDecl *TD); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 334 | void VisitTypeAliasDecl(TypeAliasDecl *TD); |
Argyrios Kyrtzidis | bd8ac8c | 2010-06-30 08:49:30 +0000 | [diff] [blame] | 335 | void VisitUnresolvedUsingTypenameDecl(UnresolvedUsingTypenameDecl *D); |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 336 | RedeclarableResult VisitTagDecl(TagDecl *TD); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 337 | void VisitEnumDecl(EnumDecl *ED); |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 338 | RedeclarableResult VisitRecordDeclImpl(RecordDecl *RD); |
| 339 | void VisitRecordDecl(RecordDecl *RD) { VisitRecordDeclImpl(RD); } |
| 340 | RedeclarableResult VisitCXXRecordDeclImpl(CXXRecordDecl *D); |
| 341 | void VisitCXXRecordDecl(CXXRecordDecl *D) { VisitCXXRecordDeclImpl(D); } |
| 342 | RedeclarableResult VisitClassTemplateSpecializationDeclImpl( |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 343 | ClassTemplateSpecializationDecl *D); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 344 | |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 345 | void VisitClassTemplateSpecializationDecl( |
| 346 | ClassTemplateSpecializationDecl *D) { |
| 347 | VisitClassTemplateSpecializationDeclImpl(D); |
| 348 | } |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 349 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 350 | void VisitClassTemplatePartialSpecializationDecl( |
| 351 | ClassTemplatePartialSpecializationDecl *D); |
Sebastian Redl | b744863 | 2011-08-31 13:59:56 +0000 | [diff] [blame] | 352 | void VisitClassScopeFunctionSpecializationDecl( |
| 353 | ClassScopeFunctionSpecializationDecl *D); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 354 | RedeclarableResult |
| 355 | VisitVarTemplateSpecializationDeclImpl(VarTemplateSpecializationDecl *D); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 356 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 357 | void VisitVarTemplateSpecializationDecl(VarTemplateSpecializationDecl *D) { |
| 358 | VisitVarTemplateSpecializationDeclImpl(D); |
| 359 | } |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 360 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 361 | void VisitVarTemplatePartialSpecializationDecl( |
| 362 | VarTemplatePartialSpecializationDecl *D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 363 | void VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 364 | void VisitValueDecl(ValueDecl *VD); |
| 365 | void VisitEnumConstantDecl(EnumConstantDecl *ECD); |
Argyrios Kyrtzidis | bd8ac8c | 2010-06-30 08:49:30 +0000 | [diff] [blame] | 366 | void VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D); |
Argyrios Kyrtzidis | 560ac97 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 367 | void VisitDeclaratorDecl(DeclaratorDecl *DD); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 368 | void VisitFunctionDecl(FunctionDecl *FD); |
Richard Smith | bc49120 | 2017-02-17 20:05:37 +0000 | [diff] [blame] | 369 | void VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *GD); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 370 | void VisitCXXMethodDecl(CXXMethodDecl *D); |
| 371 | void VisitCXXConstructorDecl(CXXConstructorDecl *D); |
| 372 | void VisitCXXDestructorDecl(CXXDestructorDecl *D); |
| 373 | void VisitCXXConversionDecl(CXXConversionDecl *D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 374 | void VisitFieldDecl(FieldDecl *FD); |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 375 | void VisitMSPropertyDecl(MSPropertyDecl *FD); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 376 | void VisitIndirectFieldDecl(IndirectFieldDecl *FD); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 377 | RedeclarableResult VisitVarDeclImpl(VarDecl *D); |
| 378 | void VisitVarDecl(VarDecl *VD) { VisitVarDeclImpl(VD); } |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 379 | void VisitImplicitParamDecl(ImplicitParamDecl *PD); |
| 380 | void VisitParmVarDecl(ParmVarDecl *PD); |
Richard Smith | 7b76d81 | 2016-08-12 02:21:25 +0000 | [diff] [blame] | 381 | void VisitDecompositionDecl(DecompositionDecl *DD); |
| 382 | void VisitBindingDecl(BindingDecl *BD); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 383 | void VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D); |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 384 | DeclID VisitTemplateDecl(TemplateDecl *D); |
Saar Raz | d7aae33 | 2019-07-10 21:25:49 +0000 | [diff] [blame] | 385 | void VisitConceptDecl(ConceptDecl *D); |
Douglas Gregor | 5407920 | 2012-01-06 22:05:37 +0000 | [diff] [blame] | 386 | RedeclarableResult VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 387 | void VisitClassTemplateDecl(ClassTemplateDecl *D); |
David Majnemer | d9b1a4f | 2015-11-04 03:40:30 +0000 | [diff] [blame] | 388 | void VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 389 | void VisitVarTemplateDecl(VarTemplateDecl *D); |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 390 | void VisitFunctionTemplateDecl(FunctionTemplateDecl *D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 391 | void VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D); |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 392 | void VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D); |
Argyrios Kyrtzidis | 41d4562 | 2010-06-20 14:40:59 +0000 | [diff] [blame] | 393 | void VisitUsingDecl(UsingDecl *D); |
Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 394 | void VisitUsingPackDecl(UsingPackDecl *D); |
Argyrios Kyrtzidis | 41d4562 | 2010-06-20 14:40:59 +0000 | [diff] [blame] | 395 | void VisitUsingShadowDecl(UsingShadowDecl *D); |
Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 396 | void VisitConstructorUsingShadowDecl(ConstructorUsingShadowDecl *D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 397 | void VisitLinkageSpecDecl(LinkageSpecDecl *D); |
Richard Smith | 8df390f | 2016-09-08 23:14:54 +0000 | [diff] [blame] | 398 | void VisitExportDecl(ExportDecl *D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 399 | void VisitFileScopeAsmDecl(FileScopeAsmDecl *AD); |
Douglas Gregor | ba34552 | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 400 | void VisitImportDecl(ImportDecl *D); |
Abramo Bagnara | d734058 | 2010-06-05 05:09:32 +0000 | [diff] [blame] | 401 | void VisitAccessSpecDecl(AccessSpecDecl *D); |
Argyrios Kyrtzidis | 74d28bd | 2010-06-29 22:47:00 +0000 | [diff] [blame] | 402 | void VisitFriendDecl(FriendDecl *D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 403 | void VisitFriendTemplateDecl(FriendTemplateDecl *D); |
| 404 | void VisitStaticAssertDecl(StaticAssertDecl *D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 405 | void VisitBlockDecl(BlockDecl *BD); |
Tareq A. Siraj | 6dfa25a | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 406 | void VisitCapturedDecl(CapturedDecl *CD); |
Michael Han | 8432435 | 2013-02-22 17:15:32 +0000 | [diff] [blame] | 407 | void VisitEmptyDecl(EmptyDecl *D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 408 | |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 409 | std::pair<uint64_t, uint64_t> VisitDeclContext(DeclContext *DC); |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 410 | |
| 411 | template<typename T> |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 412 | RedeclarableResult VisitRedeclarable(Redeclarable<T> *D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 413 | |
Douglas Gregor | 2c46b5b | 2012-01-03 17:27:13 +0000 | [diff] [blame] | 414 | template<typename T> |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 415 | void mergeRedeclarable(Redeclarable<T> *D, RedeclarableResult &Redecl, |
| 416 | DeclID TemplatePatternID = 0); |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 417 | |
| 418 | template<typename T> |
| 419 | void mergeRedeclarable(Redeclarable<T> *D, T *Existing, |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 420 | RedeclarableResult &Redecl, |
| 421 | DeclID TemplatePatternID = 0); |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 422 | |
Richard Smith | 0b87e07 | 2013-10-07 08:02:11 +0000 | [diff] [blame] | 423 | template<typename T> |
| 424 | void mergeMergeable(Mergeable<T> *D); |
| 425 | |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 426 | void mergeTemplatePattern(RedeclarableTemplateDecl *D, |
| 427 | RedeclarableTemplateDecl *Existing, |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 428 | DeclID DsID, bool IsKeyDecl); |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 429 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 430 | ObjCTypeParamList *ReadObjCTypeParamList(); |
| 431 | |
Alexis Hunt | ed05325 | 2010-05-30 07:21:58 +0000 | [diff] [blame] | 432 | // FIXME: Reorder according to DeclNodes.td? |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 433 | void VisitObjCMethodDecl(ObjCMethodDecl *D); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 434 | void VisitObjCTypeParamDecl(ObjCTypeParamDecl *D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 435 | void VisitObjCContainerDecl(ObjCContainerDecl *D); |
| 436 | void VisitObjCInterfaceDecl(ObjCInterfaceDecl *D); |
| 437 | void VisitObjCIvarDecl(ObjCIvarDecl *D); |
| 438 | void VisitObjCProtocolDecl(ObjCProtocolDecl *D); |
| 439 | void VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 440 | void VisitObjCCategoryDecl(ObjCCategoryDecl *D); |
| 441 | void VisitObjCImplDecl(ObjCImplDecl *D); |
| 442 | void VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D); |
| 443 | void VisitObjCImplementationDecl(ObjCImplementationDecl *D); |
| 444 | void VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *D); |
| 445 | void VisitObjCPropertyDecl(ObjCPropertyDecl *D); |
| 446 | void VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 447 | void VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D); |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 448 | void VisitOMPAllocateDecl(OMPAllocateDecl *D); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 449 | void VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D); |
Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 450 | void VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D); |
Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 451 | void VisitOMPRequiresDecl(OMPRequiresDecl *D); |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 452 | void VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 453 | }; |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 454 | |
| 455 | } // namespace clang |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 456 | |
Richard Smith | 86dfc1e | 2015-06-18 22:07:00 +0000 | [diff] [blame] | 457 | namespace { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 458 | |
Richard Smith | 86dfc1e | 2015-06-18 22:07:00 +0000 | [diff] [blame] | 459 | /// Iterator over the redeclarations of a declaration that have already |
| 460 | /// been merged into the same redeclaration chain. |
| 461 | template<typename DeclT> |
| 462 | class MergedRedeclIterator { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 463 | DeclT *Start; |
| 464 | DeclT *Canonical = nullptr; |
| 465 | DeclT *Current = nullptr; |
| 466 | |
Richard Smith | 86dfc1e | 2015-06-18 22:07:00 +0000 | [diff] [blame] | 467 | public: |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 468 | MergedRedeclIterator() = default; |
| 469 | MergedRedeclIterator(DeclT *Start) : Start(Start), Current(Start) {} |
Richard Smith | 86dfc1e | 2015-06-18 22:07:00 +0000 | [diff] [blame] | 470 | |
| 471 | DeclT *operator*() { return Current; } |
| 472 | |
| 473 | MergedRedeclIterator &operator++() { |
| 474 | if (Current->isFirstDecl()) { |
| 475 | Canonical = Current; |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 476 | Current = Current->getMostRecentDecl(); |
Richard Smith | 86dfc1e | 2015-06-18 22:07:00 +0000 | [diff] [blame] | 477 | } else |
| 478 | Current = Current->getPreviousDecl(); |
| 479 | |
| 480 | // If we started in the merged portion, we'll reach our start position |
| 481 | // eventually. Otherwise, we'll never reach it, but the second declaration |
| 482 | // we reached was the canonical declaration, so stop when we see that one |
| 483 | // again. |
| 484 | if (Current == Start || Current == Canonical) |
| 485 | Current = nullptr; |
| 486 | return *this; |
| 487 | } |
| 488 | |
| 489 | friend bool operator!=(const MergedRedeclIterator &A, |
| 490 | const MergedRedeclIterator &B) { |
| 491 | return A.Current != B.Current; |
| 492 | } |
| 493 | }; |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 494 | |
| 495 | } // namespace |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 496 | |
Benjamin Kramer | a0a13c3 | 2016-08-06 11:21:04 +0000 | [diff] [blame] | 497 | template <typename DeclT> |
| 498 | static llvm::iterator_range<MergedRedeclIterator<DeclT>> |
| 499 | merged_redecls(DeclT *D) { |
Craig Topper | 59c2ada | 2015-12-06 05:07:12 +0000 | [diff] [blame] | 500 | return llvm::make_range(MergedRedeclIterator<DeclT>(D), |
| 501 | MergedRedeclIterator<DeclT>()); |
Richard Smith | 86dfc1e | 2015-06-18 22:07:00 +0000 | [diff] [blame] | 502 | } |
| 503 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 504 | uint64_t ASTDeclReader::GetCurrentCursorOffset() { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 505 | return Loc.F->DeclsCursor.GetCurrentBitNo() + Loc.F->GlobalBitOffset; |
Sebastian Redl | c67764e | 2010-07-22 22:43:28 +0000 | [diff] [blame] | 506 | } |
| 507 | |
David Blaikie | ac4345c | 2017-02-12 18:45:31 +0000 | [diff] [blame] | 508 | void ASTDeclReader::ReadFunctionDefinition(FunctionDecl *FD) { |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 509 | if (Record.readInt()) |
Richard Smith | a465362 | 2017-09-06 20:01:14 +0000 | [diff] [blame] | 510 | Reader.DefinitionSource[FD] = Loc.F->Kind == ModuleKind::MK_MainFile; |
David Blaikie | ac4345c | 2017-02-12 18:45:31 +0000 | [diff] [blame] | 511 | if (auto *CD = dyn_cast<CXXConstructorDecl>(FD)) { |
Erich Keane | 9c66506 | 2018-08-01 21:02:40 +0000 | [diff] [blame] | 512 | CD->setNumCtorInitializers(Record.readInt()); |
| 513 | if (CD->getNumCtorInitializers()) |
David Blaikie | ac4345c | 2017-02-12 18:45:31 +0000 | [diff] [blame] | 514 | CD->CtorInitializers = ReadGlobalOffset(); |
| 515 | } |
| 516 | // Store the offset of the body so we can lazily load it later. |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 517 | Reader.PendingBodies[FD] = GetCurrentCursorOffset(); |
| 518 | HasPendingBody = true; |
David Blaikie | ac4345c | 2017-02-12 18:45:31 +0000 | [diff] [blame] | 519 | } |
| 520 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 521 | void ASTDeclReader::Visit(Decl *D) { |
| 522 | DeclVisitor<ASTDeclReader, void>::Visit(D); |
Argyrios Kyrtzidis | 318b0e7 | 2010-07-02 11:55:01 +0000 | [diff] [blame] | 523 | |
Vassil Vassilev | 928c825 | 2016-04-28 14:13:28 +0000 | [diff] [blame] | 524 | // At this point we have deserialized and merged the decl and it is safe to |
| 525 | // update its canonical decl to signal that the entire entity is used. |
| 526 | D->getCanonicalDecl()->Used |= IsDeclMarkedUsed; |
| 527 | IsDeclMarkedUsed = false; |
| 528 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 529 | if (auto *DD = dyn_cast<DeclaratorDecl>(D)) { |
Richard Smith | c23d734 | 2018-06-29 20:46:25 +0000 | [diff] [blame] | 530 | if (auto *TInfo = DD->getTypeSourceInfo()) |
| 531 | Record.readTypeLoc(TInfo->getTypeLoc()); |
Jonathan D. Turner | 205c7d5 | 2011-06-03 23:11:16 +0000 | [diff] [blame] | 532 | } |
| 533 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 534 | if (auto *TD = dyn_cast<TypeDecl>(D)) { |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 535 | // We have a fully initialized TypeDecl. Read its type now. |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 536 | TD->setTypeForDecl(Reader.GetType(DeferredTypeID).getTypePtrOrNull()); |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 537 | |
| 538 | // If this is a tag declaration with a typedef name for linkage, it's safe |
| 539 | // to load that typedef now. |
| 540 | if (NamedDeclForTagDecl) |
David Majnemer | 0035052 | 2015-08-31 18:48:39 +0000 | [diff] [blame] | 541 | cast<TagDecl>(D)->TypedefNameDeclOrQualifier = |
| 542 | cast<TypedefNameDecl>(Reader.GetDecl(NamedDeclForTagDecl)); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 543 | } else if (auto *ID = dyn_cast<ObjCInterfaceDecl>(D)) { |
Douglas Gregor | ab1ec82e | 2011-12-16 03:12:41 +0000 | [diff] [blame] | 544 | // if we have a fully initialized TypeDecl, we can safely read its type now. |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 545 | ID->TypeForDecl = Reader.GetType(DeferredTypeID).getTypePtrOrNull(); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 546 | } else if (auto *FD = dyn_cast<FunctionDecl>(D)) { |
Argyrios Kyrtzidis | 3357516 | 2010-07-02 15:58:43 +0000 | [diff] [blame] | 547 | // FunctionDecl's body was written last after all other Stmts/Exprs. |
Douglas Gregor | 559458c | 2012-10-03 18:34:48 +0000 | [diff] [blame] | 548 | // We only read it if FD doesn't already have a body (e.g., from another |
| 549 | // module). |
Douglas Gregor | e4a838a | 2012-10-03 18:36:10 +0000 | [diff] [blame] | 550 | // FIXME: Can we diagnose ODR violations somehow? |
David Blaikie | ac4345c | 2017-02-12 18:45:31 +0000 | [diff] [blame] | 551 | if (Record.readInt()) |
| 552 | ReadFunctionDefinition(FD); |
Argyrios Kyrtzidis | 3357516 | 2010-07-02 15:58:43 +0000 | [diff] [blame] | 553 | } |
Argyrios Kyrtzidis | 318b0e7 | 2010-07-02 11:55:01 +0000 | [diff] [blame] | 554 | } |
| 555 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 556 | void ASTDeclReader::VisitDecl(Decl *D) { |
Dmitri Gribenko | b353ee1 | 2013-12-19 02:05:20 +0000 | [diff] [blame] | 557 | if (D->isTemplateParameter() || D->isTemplateParameterPack() || |
| 558 | isa<ParmVarDecl>(D)) { |
Douglas Gregor | 250ffb1 | 2011-03-05 01:35:54 +0000 | [diff] [blame] | 559 | // We don't want to deserialize the DeclContext of a template |
Dmitri Gribenko | b353ee1 | 2013-12-19 02:05:20 +0000 | [diff] [blame] | 560 | // parameter or of a parameter of a function template immediately. These |
| 561 | // entities might be used in the formulation of its DeclContext (for |
| 562 | // example, a function parameter can be used in decltype() in trailing |
| 563 | // return type of the function). Use the translation unit DeclContext as a |
| 564 | // placeholder. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 565 | GlobalDeclID SemaDCIDForTemplateParmDecl = ReadDeclID(); |
| 566 | GlobalDeclID LexicalDCIDForTemplateParmDecl = ReadDeclID(); |
Richard Smith | 8aed422 | 2015-12-11 22:41:00 +0000 | [diff] [blame] | 567 | if (!LexicalDCIDForTemplateParmDecl) |
| 568 | LexicalDCIDForTemplateParmDecl = SemaDCIDForTemplateParmDecl; |
Argyrios Kyrtzidis | 83a6e3b | 2013-02-16 00:48:59 +0000 | [diff] [blame] | 569 | Reader.addPendingDeclContextInfo(D, |
| 570 | SemaDCIDForTemplateParmDecl, |
| 571 | LexicalDCIDForTemplateParmDecl); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 572 | D->setDeclContext(Reader.getContext().getTranslationUnitDecl()); |
Douglas Gregor | 250ffb1 | 2011-03-05 01:35:54 +0000 | [diff] [blame] | 573 | } else { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 574 | auto *SemaDC = ReadDeclAs<DeclContext>(); |
| 575 | auto *LexicalDC = ReadDeclAs<DeclContext>(); |
Richard Smith | 8aed422 | 2015-12-11 22:41:00 +0000 | [diff] [blame] | 576 | if (!LexicalDC) |
| 577 | LexicalDC = SemaDC; |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 578 | DeclContext *MergedSemaDC = Reader.MergedDeclContexts.lookup(SemaDC); |
Argyrios Kyrtzidis | 7456ac4 | 2012-02-09 07:46:54 +0000 | [diff] [blame] | 579 | // Avoid calling setLexicalDeclContext() directly because it uses |
| 580 | // Decl::getASTContext() internally which is unsafe during derialization. |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 581 | D->setDeclContextsImpl(MergedSemaDC ? MergedSemaDC : SemaDC, LexicalDC, |
| 582 | Reader.getContext()); |
Douglas Gregor | 250ffb1 | 2011-03-05 01:35:54 +0000 | [diff] [blame] | 583 | } |
Richard Smith | cb34bd3 | 2016-03-27 07:28:06 +0000 | [diff] [blame] | 584 | D->setLocation(ThisDeclLoc); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 585 | D->setInvalidDecl(Record.readInt()); |
| 586 | if (Record.readInt()) { // hasAttrs |
Alexis Hunt | dcfba7b | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 587 | AttrVec Attrs; |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 588 | Record.readAttributes(Attrs); |
Argyrios Kyrtzidis | 7456ac4 | 2012-02-09 07:46:54 +0000 | [diff] [blame] | 589 | // Avoid calling setAttrs() directly because it uses Decl::getASTContext() |
| 590 | // internally which is unsafe during derialization. |
Argyrios Kyrtzidis | 6f40eb7 | 2012-02-09 02:44:08 +0000 | [diff] [blame] | 591 | D->setAttrsImpl(Attrs, Reader.getContext()); |
Alexis Hunt | dcfba7b | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 592 | } |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 593 | D->setImplicit(Record.readInt()); |
| 594 | D->Used = Record.readInt(); |
Vassil Vassilev | 928c825 | 2016-04-28 14:13:28 +0000 | [diff] [blame] | 595 | IsDeclMarkedUsed |= D->Used; |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 596 | D->setReferenced(Record.readInt()); |
| 597 | D->setTopLevelDeclInObjCContainer(Record.readInt()); |
| 598 | D->setAccess((AccessSpecifier)Record.readInt()); |
Douglas Gregor | 98c05b2 | 2011-09-10 00:09:20 +0000 | [diff] [blame] | 599 | D->FromASTFile = true; |
Richard Smith | 90dc525 | 2017-06-23 01:04:34 +0000 | [diff] [blame] | 600 | bool ModulePrivate = Record.readInt(); |
Richard Smith | 4241314 | 2015-05-15 20:05:43 +0000 | [diff] [blame] | 601 | |
Douglas Gregor | cf68c58 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 602 | // Determine whether this declaration is part of a (sub)module. If so, it |
| 603 | // may not yet be visible. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 604 | if (unsigned SubmoduleID = readSubmoduleID()) { |
Douglas Gregor | cfe7dc6 | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 605 | // Store the owning submodule ID in the declaration. |
Richard Smith | 90dc525 | 2017-06-23 01:04:34 +0000 | [diff] [blame] | 606 | D->setModuleOwnershipKind( |
| 607 | ModulePrivate ? Decl::ModuleOwnershipKind::ModulePrivate |
| 608 | : Decl::ModuleOwnershipKind::VisibleWhenImported); |
Douglas Gregor | cfe7dc6 | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 609 | D->setOwningModuleID(SubmoduleID); |
Richard Smith | 4241314 | 2015-05-15 20:05:43 +0000 | [diff] [blame] | 610 | |
Richard Smith | 90dc525 | 2017-06-23 01:04:34 +0000 | [diff] [blame] | 611 | if (ModulePrivate) { |
| 612 | // Module-private declarations are never visible, so there is no work to |
| 613 | // do. |
Richard Smith | 4241314 | 2015-05-15 20:05:43 +0000 | [diff] [blame] | 614 | } else if (Reader.getContext().getLangOpts().ModulesLocalVisibility) { |
| 615 | // If local visibility is being tracked, this declaration will become |
Richard Smith | 90dc525 | 2017-06-23 01:04:34 +0000 | [diff] [blame] | 616 | // hidden and visible as the owning module does. |
Richard Smith | 4241314 | 2015-05-15 20:05:43 +0000 | [diff] [blame] | 617 | } else if (Module *Owner = Reader.getSubmodule(SubmoduleID)) { |
Richard Smith | 90dc525 | 2017-06-23 01:04:34 +0000 | [diff] [blame] | 618 | // Mark the declaration as visible when its owning module becomes visible. |
| 619 | if (Owner->NameVisibility == Module::AllVisible) |
| 620 | D->setVisibleDespiteOwningModule(); |
| 621 | else |
Richard Smith | 4241314 | 2015-05-15 20:05:43 +0000 | [diff] [blame] | 622 | Reader.HiddenNamesMap[Owner].push_back(D); |
Douglas Gregor | cf68c58 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 623 | } |
Richard Smith | d19389a | 2017-07-05 07:47:11 +0000 | [diff] [blame] | 624 | } else if (ModulePrivate) { |
| 625 | D->setModuleOwnershipKind(Decl::ModuleOwnershipKind::ModulePrivate); |
Douglas Gregor | cf68c58 | 2011-12-01 22:20:10 +0000 | [diff] [blame] | 626 | } |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 627 | } |
| 628 | |
Nico Weber | 6622029 | 2016-03-02 17:28:48 +0000 | [diff] [blame] | 629 | void ASTDeclReader::VisitPragmaCommentDecl(PragmaCommentDecl *D) { |
| 630 | VisitDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 631 | D->setLocation(ReadSourceLocation()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 632 | D->CommentKind = (PragmaMSCommentKind)Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 633 | std::string Arg = ReadString(); |
Nico Weber | 6622029 | 2016-03-02 17:28:48 +0000 | [diff] [blame] | 634 | memcpy(D->getTrailingObjects<char>(), Arg.data(), Arg.size()); |
| 635 | D->getTrailingObjects<char>()[Arg.size()] = '\0'; |
| 636 | } |
| 637 | |
Nico Weber | cbbaeb1 | 2016-03-02 19:28:54 +0000 | [diff] [blame] | 638 | void ASTDeclReader::VisitPragmaDetectMismatchDecl(PragmaDetectMismatchDecl *D) { |
| 639 | VisitDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 640 | D->setLocation(ReadSourceLocation()); |
| 641 | std::string Name = ReadString(); |
Nico Weber | cbbaeb1 | 2016-03-02 19:28:54 +0000 | [diff] [blame] | 642 | memcpy(D->getTrailingObjects<char>(), Name.data(), Name.size()); |
| 643 | D->getTrailingObjects<char>()[Name.size()] = '\0'; |
| 644 | |
| 645 | D->ValueStart = Name.size() + 1; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 646 | std::string Value = ReadString(); |
Nico Weber | cbbaeb1 | 2016-03-02 19:28:54 +0000 | [diff] [blame] | 647 | memcpy(D->getTrailingObjects<char>() + D->ValueStart, Value.data(), |
| 648 | Value.size()); |
| 649 | D->getTrailingObjects<char>()[D->ValueStart + Value.size()] = '\0'; |
| 650 | } |
| 651 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 652 | void ASTDeclReader::VisitTranslationUnitDecl(TranslationUnitDecl *TU) { |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 653 | llvm_unreachable("Translation units are not serialized"); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 654 | } |
| 655 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 656 | void ASTDeclReader::VisitNamedDecl(NamedDecl *ND) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 657 | VisitDecl(ND); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 658 | ND->setDeclName(Record.readDeclarationName()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 659 | AnonymousDeclNumber = Record.readInt(); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 660 | } |
| 661 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 662 | void ASTDeclReader::VisitTypeDecl(TypeDecl *TD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 663 | VisitNamedDecl(TD); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 664 | TD->setLocStart(ReadSourceLocation()); |
Argyrios Kyrtzidis | 318b0e7 | 2010-07-02 11:55:01 +0000 | [diff] [blame] | 665 | // Delay type reading until after we have fully initialized the decl. |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 666 | DeferredTypeID = Record.getGlobalTypeID(Record.readInt()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 667 | } |
| 668 | |
Richard Smith | 43ccec8e | 2014-08-26 03:52:16 +0000 | [diff] [blame] | 669 | ASTDeclReader::RedeclarableResult |
| 670 | ASTDeclReader::VisitTypedefNameDecl(TypedefNameDecl *TD) { |
Douglas Gregor | 9b7b391 | 2012-01-04 16:44:10 +0000 | [diff] [blame] | 671 | RedeclarableResult Redecl = VisitRedeclarable(TD); |
Argyrios Kyrtzidis | 318b0e7 | 2010-07-02 11:55:01 +0000 | [diff] [blame] | 672 | VisitTypeDecl(TD); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 673 | TypeSourceInfo *TInfo = GetTypeSourceInfo(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 674 | if (Record.readInt()) { // isModed |
| 675 | QualType modedT = Record.readType(); |
Enea Zaffanella | a86d88c | 2013-06-20 12:46:19 +0000 | [diff] [blame] | 676 | TD->setModedTypeSourceInfo(TInfo, modedT); |
| 677 | } else |
| 678 | TD->setTypeSourceInfo(TInfo); |
Richard Smith | c0ca4c2 | 2017-01-26 22:39:55 +0000 | [diff] [blame] | 679 | // Read and discard the declaration for which this is a typedef name for |
| 680 | // linkage, if it exists. We cannot rely on our type to pull in this decl, |
| 681 | // because it might have been merged with a type from another module and |
| 682 | // thus might not refer to our version of the declaration. |
| 683 | ReadDecl(); |
Richard Smith | 43ccec8e | 2014-08-26 03:52:16 +0000 | [diff] [blame] | 684 | return Redecl; |
Douglas Gregor | 1f17906 | 2011-12-19 14:40:25 +0000 | [diff] [blame] | 685 | } |
| 686 | |
| 687 | void ASTDeclReader::VisitTypedefDecl(TypedefDecl *TD) { |
Richard Smith | 43ccec8e | 2014-08-26 03:52:16 +0000 | [diff] [blame] | 688 | RedeclarableResult Redecl = VisitTypedefNameDecl(TD); |
| 689 | mergeRedeclarable(TD, Redecl); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 690 | } |
| 691 | |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 692 | void ASTDeclReader::VisitTypeAliasDecl(TypeAliasDecl *TD) { |
Richard Smith | 43ccec8e | 2014-08-26 03:52:16 +0000 | [diff] [blame] | 693 | RedeclarableResult Redecl = VisitTypedefNameDecl(TD); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 694 | if (auto *Template = ReadDeclAs<TypeAliasTemplateDecl>()) |
Richard Smith | 43ccec8e | 2014-08-26 03:52:16 +0000 | [diff] [blame] | 695 | // Merged when we merge the template. |
| 696 | TD->setDescribedAliasTemplate(Template); |
| 697 | else |
| 698 | mergeRedeclarable(TD, Redecl); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 699 | } |
| 700 | |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 701 | ASTDeclReader::RedeclarableResult ASTDeclReader::VisitTagDecl(TagDecl *TD) { |
Douglas Gregor | 2009cee | 2012-01-03 22:46:00 +0000 | [diff] [blame] | 702 | RedeclarableResult Redecl = VisitRedeclarable(TD); |
Douglas Gregor | 3e30010 | 2011-10-26 17:53:41 +0000 | [diff] [blame] | 703 | VisitTypeDecl(TD); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 704 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 705 | TD->IdentifierNamespace = Record.readInt(); |
| 706 | TD->setTagKind((TagDecl::TagKind)Record.readInt()); |
Richard Smith | 2c38164 | 2014-08-27 23:11:59 +0000 | [diff] [blame] | 707 | if (!isa<CXXRecordDecl>(TD)) |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 708 | TD->setCompleteDefinition(Record.readInt()); |
| 709 | TD->setEmbeddedInDeclarator(Record.readInt()); |
| 710 | TD->setFreeStanding(Record.readInt()); |
| 711 | TD->setCompleteDefinitionRequired(Record.readInt()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 712 | TD->setBraceRange(ReadSourceRange()); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 713 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 714 | switch (Record.readInt()) { |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 715 | case 0: |
| 716 | break; |
| 717 | case 1: { // ExtInfo |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 718 | auto *Info = new (Reader.getContext()) TagDecl::ExtInfo(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 719 | ReadQualifierInfo(*Info); |
David Majnemer | 0035052 | 2015-08-31 18:48:39 +0000 | [diff] [blame] | 720 | TD->TypedefNameDeclOrQualifier = Info; |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 721 | break; |
| 722 | } |
| 723 | case 2: // TypedefNameForAnonDecl |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 724 | NamedDeclForTagDecl = ReadDeclID(); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 725 | TypedefNameForLinkage = Record.getIdentifierInfo(); |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 726 | break; |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 727 | default: |
| 728 | llvm_unreachable("unexpected tag info kind"); |
| 729 | } |
Douglas Gregor | 2009cee | 2012-01-03 22:46:00 +0000 | [diff] [blame] | 730 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 731 | if (!isa<CXXRecordDecl>(TD)) |
| 732 | mergeRedeclarable(TD, Redecl); |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 733 | return Redecl; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 734 | } |
| 735 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 736 | void ASTDeclReader::VisitEnumDecl(EnumDecl *ED) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 737 | VisitTagDecl(ED); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 738 | if (TypeSourceInfo *TI = GetTypeSourceInfo()) |
Douglas Gregor | 0bf3140 | 2010-10-08 23:50:27 +0000 | [diff] [blame] | 739 | ED->setIntegerTypeSourceInfo(TI); |
| 740 | else |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 741 | ED->setIntegerType(Record.readType()); |
| 742 | ED->setPromotionType(Record.readType()); |
| 743 | ED->setNumPositiveBits(Record.readInt()); |
| 744 | ED->setNumNegativeBits(Record.readInt()); |
Erich Keane | f92f31c | 2018-08-01 20:48:16 +0000 | [diff] [blame] | 745 | ED->setScoped(Record.readInt()); |
| 746 | ED->setScopedUsingClassTag(Record.readInt()); |
| 747 | ED->setFixed(Record.readInt()); |
Richard Smith | 4b38ded | 2012-03-14 23:13:10 +0000 | [diff] [blame] | 748 | |
Erich Keane | f92f31c | 2018-08-01 20:48:16 +0000 | [diff] [blame] | 749 | ED->setHasODRHash(true); |
Richard Trieu | ab4d730 | 2018-07-25 22:52:05 +0000 | [diff] [blame] | 750 | ED->ODRHash = Record.readInt(); |
| 751 | |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame] | 752 | // If this is a definition subject to the ODR, and we already have a |
| 753 | // definition, merge this one into it. |
Erich Keane | f92f31c | 2018-08-01 20:48:16 +0000 | [diff] [blame] | 754 | if (ED->isCompleteDefinition() && |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame] | 755 | Reader.getContext().getLangOpts().Modules && |
| 756 | Reader.getContext().getLangOpts().CPlusPlus) { |
Richard Smith | 86dfc1e | 2015-06-18 22:07:00 +0000 | [diff] [blame] | 757 | EnumDecl *&OldDef = Reader.EnumDefinitions[ED->getCanonicalDecl()]; |
| 758 | if (!OldDef) { |
| 759 | // This is the first time we've seen an imported definition. Look for a |
| 760 | // local definition before deciding that we are the first definition. |
| 761 | for (auto *D : merged_redecls(ED->getCanonicalDecl())) { |
| 762 | if (!D->isFromASTFile() && D->isCompleteDefinition()) { |
| 763 | OldDef = D; |
| 764 | break; |
| 765 | } |
| 766 | } |
| 767 | } |
| 768 | if (OldDef) { |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame] | 769 | Reader.MergedDeclContexts.insert(std::make_pair(ED, OldDef)); |
Erich Keane | f92f31c | 2018-08-01 20:48:16 +0000 | [diff] [blame] | 770 | ED->setCompleteDefinition(false); |
Richard Smith | 6561f92 | 2016-09-12 21:06:40 +0000 | [diff] [blame] | 771 | Reader.mergeDefinitionVisibility(OldDef, ED); |
Richard Trieu | ab4d730 | 2018-07-25 22:52:05 +0000 | [diff] [blame] | 772 | if (OldDef->getODRHash() != ED->getODRHash()) |
| 773 | Reader.PendingEnumOdrMergeFailures[OldDef].push_back(ED); |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame] | 774 | } else { |
| 775 | OldDef = ED; |
| 776 | } |
| 777 | } |
| 778 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 779 | if (auto *InstED = ReadDeclAs<EnumDecl>()) { |
| 780 | auto TSK = (TemplateSpecializationKind)Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 781 | SourceLocation POI = ReadSourceLocation(); |
Richard Smith | 4b38ded | 2012-03-14 23:13:10 +0000 | [diff] [blame] | 782 | ED->setInstantiationOfMemberEnum(Reader.getContext(), InstED, TSK); |
| 783 | ED->getMemberSpecializationInfo()->setPointOfInstantiation(POI); |
| 784 | } |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 785 | } |
| 786 | |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 787 | ASTDeclReader::RedeclarableResult |
| 788 | ASTDeclReader::VisitRecordDeclImpl(RecordDecl *RD) { |
| 789 | RedeclarableResult Redecl = VisitTagDecl(RD); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 790 | RD->setHasFlexibleArrayMember(Record.readInt()); |
| 791 | RD->setAnonymousStructOrUnion(Record.readInt()); |
| 792 | RD->setHasObjectMember(Record.readInt()); |
| 793 | RD->setHasVolatileMember(Record.readInt()); |
Akira Hatanaka | 34fb264 | 2018-03-13 18:58:25 +0000 | [diff] [blame] | 794 | RD->setNonTrivialToPrimitiveDefaultInitialize(Record.readInt()); |
| 795 | RD->setNonTrivialToPrimitiveCopy(Record.readInt()); |
| 796 | RD->setNonTrivialToPrimitiveDestroy(Record.readInt()); |
Akira Hatanaka | 0905106 | 2019-09-07 00:34:43 +0000 | [diff] [blame] | 797 | RD->setHasNonTrivialToPrimitiveDefaultInitializeCUnion(Record.readInt()); |
| 798 | RD->setHasNonTrivialToPrimitiveDestructCUnion(Record.readInt()); |
| 799 | RD->setHasNonTrivialToPrimitiveCopyCUnion(Record.readInt()); |
Akira Hatanaka | fcbe17c | 2018-03-28 21:13:14 +0000 | [diff] [blame] | 800 | RD->setParamDestroyedInCallee(Record.readInt()); |
Akira Hatanaka | e6313ac | 2018-04-09 22:48:22 +0000 | [diff] [blame] | 801 | RD->setArgPassingRestrictions((RecordDecl::ArgPassingKind)Record.readInt()); |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 802 | return Redecl; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 803 | } |
| 804 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 805 | void ASTDeclReader::VisitValueDecl(ValueDecl *VD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 806 | VisitNamedDecl(VD); |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 807 | // For function declarations, defer reading the type in case the function has |
| 808 | // a deduced return type that references an entity declared within the |
| 809 | // function. |
| 810 | if (isa<FunctionDecl>(VD)) |
| 811 | DeferredTypeID = Record.getGlobalTypeID(Record.readInt()); |
| 812 | else |
| 813 | VD->setType(Record.readType()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 814 | } |
| 815 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 816 | void ASTDeclReader::VisitEnumConstantDecl(EnumConstantDecl *ECD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 817 | VisitValueDecl(ECD); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 818 | if (Record.readInt()) |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 819 | ECD->setInitExpr(Record.readExpr()); |
| 820 | ECD->setInitVal(Record.readAPSInt()); |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame] | 821 | mergeMergeable(ECD); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 822 | } |
| 823 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 824 | void ASTDeclReader::VisitDeclaratorDecl(DeclaratorDecl *DD) { |
Argyrios Kyrtzidis | 560ac97 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 825 | VisitValueDecl(DD); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 826 | DD->setInnerLocStart(ReadSourceLocation()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 827 | if (Record.readInt()) { // hasExtInfo |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 828 | auto *Info = new (Reader.getContext()) DeclaratorDecl::ExtInfo(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 829 | ReadQualifierInfo(*Info); |
Argyrios Kyrtzidis | 434383d | 2010-10-15 18:21:24 +0000 | [diff] [blame] | 830 | DD->DeclInfo = Info; |
Jonathan D. Turner | 205c7d5 | 2011-06-03 23:11:16 +0000 | [diff] [blame] | 831 | } |
Richard Smith | c23d734 | 2018-06-29 20:46:25 +0000 | [diff] [blame] | 832 | QualType TSIType = Record.readType(); |
| 833 | DD->setTypeSourceInfo( |
| 834 | TSIType.isNull() ? nullptr |
| 835 | : Reader.getContext().CreateTypeSourceInfo(TSIType)); |
Argyrios Kyrtzidis | 560ac97 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 836 | } |
| 837 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 838 | void ASTDeclReader::VisitFunctionDecl(FunctionDecl *FD) { |
Douglas Gregor | b258569 | 2012-01-04 17:13:46 +0000 | [diff] [blame] | 839 | RedeclarableResult Redecl = VisitRedeclarable(FD); |
Douglas Gregor | 3e30010 | 2011-10-26 17:53:41 +0000 | [diff] [blame] | 840 | VisitDeclaratorDecl(FD); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 841 | |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 842 | // Attach a type to this function. Use the real type if possible, but fall |
| 843 | // back to the type as written if it involves a deduced return type. |
| 844 | if (FD->getTypeSourceInfo() && |
| 845 | FD->getTypeSourceInfo()->getType()->castAs<FunctionType>() |
| 846 | ->getReturnType()->getContainedAutoType()) { |
| 847 | // We'll set up the real type in Visit, once we've finished loading the |
| 848 | // function. |
| 849 | FD->setType(FD->getTypeSourceInfo()->getType()); |
Richard Smith | a62d198 | 2018-08-03 01:00:01 +0000 | [diff] [blame] | 850 | Reader.PendingFunctionTypes.push_back({FD, DeferredTypeID}); |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 851 | } else { |
| 852 | FD->setType(Reader.GetType(DeferredTypeID)); |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 853 | } |
Richard Smith | a62d198 | 2018-08-03 01:00:01 +0000 | [diff] [blame] | 854 | DeferredTypeID = 0; |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 855 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 856 | ReadDeclarationNameLoc(FD->DNLoc, FD->getDeclName()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 857 | FD->IdentifierNamespace = Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 858 | |
Douglas Gregor | b258569 | 2012-01-04 17:13:46 +0000 | [diff] [blame] | 859 | // FunctionDecl's body is handled last at ASTDeclReader::Visit, |
| 860 | // after everything else is read. |
Rafael Espindola | 6ae7e50 | 2013-04-03 19:27:57 +0000 | [diff] [blame] | 861 | |
Erich Keane | 9c66506 | 2018-08-01 21:02:40 +0000 | [diff] [blame] | 862 | FD->setStorageClass(static_cast<StorageClass>(Record.readInt())); |
| 863 | FD->setInlineSpecified(Record.readInt()); |
| 864 | FD->setImplicitlyInline(Record.readInt()); |
Erich Keane | 9c66506 | 2018-08-01 21:02:40 +0000 | [diff] [blame] | 865 | FD->setVirtualAsWritten(Record.readInt()); |
| 866 | FD->setPure(Record.readInt()); |
| 867 | FD->setHasInheritedPrototype(Record.readInt()); |
| 868 | FD->setHasWrittenPrototype(Record.readInt()); |
| 869 | FD->setDeletedAsWritten(Record.readInt()); |
| 870 | FD->setTrivial(Record.readInt()); |
| 871 | FD->setTrivialForCall(Record.readInt()); |
| 872 | FD->setDefaulted(Record.readInt()); |
| 873 | FD->setExplicitlyDefaulted(Record.readInt()); |
| 874 | FD->setHasImplicitReturnZero(Record.readInt()); |
Gauthier Harnisch | 796ed03 | 2019-06-14 08:56:20 +0000 | [diff] [blame] | 875 | FD->setConstexprKind(static_cast<ConstexprSpecKind>(Record.readInt())); |
Erich Keane | 9c66506 | 2018-08-01 21:02:40 +0000 | [diff] [blame] | 876 | FD->setUsesSEHTry(Record.readInt()); |
| 877 | FD->setHasSkippedBody(Record.readInt()); |
| 878 | FD->setIsMultiVersion(Record.readInt()); |
| 879 | FD->setLateTemplateParsed(Record.readInt()); |
| 880 | |
| 881 | FD->setCachedLinkage(static_cast<Linkage>(Record.readInt())); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 882 | FD->EndRangeLoc = ReadSourceLocation(); |
Douglas Gregor | b258569 | 2012-01-04 17:13:46 +0000 | [diff] [blame] | 883 | |
Richard Trieu | e6caa26 | 2017-12-23 00:41:01 +0000 | [diff] [blame] | 884 | FD->ODRHash = Record.readInt(); |
Erich Keane | 9c66506 | 2018-08-01 21:02:40 +0000 | [diff] [blame] | 885 | FD->setHasODRHash(true); |
Richard Trieu | e6caa26 | 2017-12-23 00:41:01 +0000 | [diff] [blame] | 886 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 887 | switch ((FunctionDecl::TemplatedKind)Record.readInt()) { |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 888 | case FunctionDecl::TK_NonTemplate: |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 889 | mergeRedeclarable(FD, Redecl); |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 890 | break; |
| 891 | case FunctionDecl::TK_FunctionTemplate: |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 892 | // Merged when we merge the template. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 893 | FD->setDescribedFunctionTemplate(ReadDeclAs<FunctionTemplateDecl>()); |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 894 | break; |
| 895 | case FunctionDecl::TK_MemberSpecialization: { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 896 | auto *InstFD = ReadDeclAs<FunctionDecl>(); |
| 897 | auto TSK = (TemplateSpecializationKind)Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 898 | SourceLocation POI = ReadSourceLocation(); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 899 | FD->setInstantiationOfMemberFunction(Reader.getContext(), InstFD, TSK); |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 900 | FD->getMemberSpecializationInfo()->setPointOfInstantiation(POI); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 901 | mergeRedeclarable(FD, Redecl); |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 902 | break; |
| 903 | } |
| 904 | case FunctionDecl::TK_FunctionTemplateSpecialization: { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 905 | auto *Template = ReadDeclAs<FunctionTemplateDecl>(); |
| 906 | auto TSK = (TemplateSpecializationKind)Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 907 | |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 908 | // Template arguments. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 909 | SmallVector<TemplateArgument, 8> TemplArgs; |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 910 | Record.readTemplateArgumentList(TemplArgs, /*Canonicalize*/ true); |
Richard Smith | 2bb3c34 | 2015-08-09 01:05:31 +0000 | [diff] [blame] | 911 | |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 912 | // Template args as written. |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 913 | SmallVector<TemplateArgumentLoc, 8> TemplArgLocs; |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 914 | SourceLocation LAngleLoc, RAngleLoc; |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 915 | bool HasTemplateArgumentsAsWritten = Record.readInt(); |
Argyrios Kyrtzidis | e9a2443 | 2011-09-22 20:07:09 +0000 | [diff] [blame] | 916 | if (HasTemplateArgumentsAsWritten) { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 917 | unsigned NumTemplateArgLocs = Record.readInt(); |
Argyrios Kyrtzidis | 373a83a | 2010-07-02 11:55:40 +0000 | [diff] [blame] | 918 | TemplArgLocs.reserve(NumTemplateArgLocs); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 919 | for (unsigned i = 0; i != NumTemplateArgLocs; ++i) |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 920 | TemplArgLocs.push_back(Record.readTemplateArgumentLoc()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 921 | |
| 922 | LAngleLoc = ReadSourceLocation(); |
| 923 | RAngleLoc = ReadSourceLocation(); |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 924 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 925 | |
| 926 | SourceLocation POI = ReadSourceLocation(); |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 927 | |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 928 | ASTContext &C = Reader.getContext(); |
Argyrios Kyrtzidis | e262a95 | 2010-09-09 11:28:23 +0000 | [diff] [blame] | 929 | TemplateArgumentList *TemplArgList |
David Majnemer | 8b62269 | 2016-07-03 21:17:51 +0000 | [diff] [blame] | 930 | = TemplateArgumentList::CreateCopy(C, TemplArgs); |
Argyrios Kyrtzidis | e9a2443 | 2011-09-22 20:07:09 +0000 | [diff] [blame] | 931 | TemplateArgumentListInfo TemplArgsInfo(LAngleLoc, RAngleLoc); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 932 | for (unsigned i = 0, e = TemplArgLocs.size(); i != e; ++i) |
Argyrios Kyrtzidis | e9a2443 | 2011-09-22 20:07:09 +0000 | [diff] [blame] | 933 | TemplArgsInfo.addArgument(TemplArgLocs[i]); |
Richard Smith | f19a8b0 | 2019-05-02 00:49:14 +0000 | [diff] [blame] | 934 | |
| 935 | MemberSpecializationInfo *MSInfo = nullptr; |
| 936 | if (Record.readInt()) { |
| 937 | auto *FD = ReadDeclAs<FunctionDecl>(); |
| 938 | auto TSK = (TemplateSpecializationKind)Record.readInt(); |
| 939 | SourceLocation POI = ReadSourceLocation(); |
| 940 | |
| 941 | MSInfo = new (C) MemberSpecializationInfo(FD, TSK); |
| 942 | MSInfo->setPointOfInstantiation(POI); |
| 943 | } |
| 944 | |
| 945 | FunctionTemplateSpecializationInfo *FTInfo = |
| 946 | FunctionTemplateSpecializationInfo::Create( |
| 947 | C, FD, Template, TSK, TemplArgList, |
| 948 | HasTemplateArgumentsAsWritten ? &TemplArgsInfo : nullptr, POI, |
| 949 | MSInfo); |
Argyrios Kyrtzidis | e262a95 | 2010-09-09 11:28:23 +0000 | [diff] [blame] | 950 | FD->TemplateOrSpecialization = FTInfo; |
Argyrios Kyrtzidis | f4bc0d8 | 2010-09-08 19:31:22 +0000 | [diff] [blame] | 951 | |
Argyrios Kyrtzidis | e262a95 | 2010-09-09 11:28:23 +0000 | [diff] [blame] | 952 | if (FD->isCanonicalDecl()) { // if canonical add to template's set. |
Argyrios Kyrtzidis | f24d569 | 2010-09-13 11:45:48 +0000 | [diff] [blame] | 953 | // The template that contains the specializations set. It's not safe to |
| 954 | // use getCanonicalDecl on Template since it may still be initializing. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 955 | auto *CanonTemplate = ReadDeclAs<FunctionTemplateDecl>(); |
Argyrios Kyrtzidis | e262a95 | 2010-09-09 11:28:23 +0000 | [diff] [blame] | 956 | // Get the InsertPos by FindNodeOrInsertPos() instead of calling |
| 957 | // InsertNode(FTInfo) directly to avoid the getASTContext() call in |
| 958 | // FunctionTemplateSpecializationInfo's Profile(). |
| 959 | // We avoid getASTContext because a decl in the parent hierarchy may |
| 960 | // be initializing. |
Argyrios Kyrtzidis | f4bc0d8 | 2010-09-08 19:31:22 +0000 | [diff] [blame] | 961 | llvm::FoldingSetNodeID ID; |
Craig Topper | 7e0daca | 2014-06-26 04:58:53 +0000 | [diff] [blame] | 962 | FunctionTemplateSpecializationInfo::Profile(ID, TemplArgs, C); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 963 | void *InsertPos = nullptr; |
Richard Smith | feb3e1a | 2013-06-28 04:37:53 +0000 | [diff] [blame] | 964 | FunctionTemplateDecl::Common *CommonPtr = CanonTemplate->getCommonPtr(); |
Richard Smith | da6c234 | 2015-07-01 23:19:58 +0000 | [diff] [blame] | 965 | FunctionTemplateSpecializationInfo *ExistingInfo = |
| 966 | CommonPtr->Specializations.FindNodeOrInsertPos(ID, InsertPos); |
Argyrios Kyrtzidis | e60e408 | 2012-09-10 23:28:22 +0000 | [diff] [blame] | 967 | if (InsertPos) |
Richard Smith | feb3e1a | 2013-06-28 04:37:53 +0000 | [diff] [blame] | 968 | CommonPtr->Specializations.InsertNode(FTInfo, InsertPos); |
| 969 | else { |
| 970 | assert(Reader.getContext().getLangOpts().Modules && |
| 971 | "already deserialized this template specialization"); |
Richard Smith | f19a8b0 | 2019-05-02 00:49:14 +0000 | [diff] [blame] | 972 | mergeRedeclarable(FD, ExistingInfo->getFunction(), Redecl); |
Richard Smith | feb3e1a | 2013-06-28 04:37:53 +0000 | [diff] [blame] | 973 | } |
Argyrios Kyrtzidis | f4bc0d8 | 2010-09-08 19:31:22 +0000 | [diff] [blame] | 974 | } |
Argyrios Kyrtzidis | 0b0369a | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 975 | break; |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 976 | } |
| 977 | case FunctionDecl::TK_DependentFunctionTemplateSpecialization: { |
| 978 | // Templates. |
| 979 | UnresolvedSet<8> TemplDecls; |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 980 | unsigned NumTemplates = Record.readInt(); |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 981 | while (NumTemplates--) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 982 | TemplDecls.addDecl(ReadDeclAs<NamedDecl>()); |
| 983 | |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 984 | // Templates args. |
| 985 | TemplateArgumentListInfo TemplArgs; |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 986 | unsigned NumArgs = Record.readInt(); |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 987 | while (NumArgs--) |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 988 | TemplArgs.addArgument(Record.readTemplateArgumentLoc()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 989 | TemplArgs.setLAngleLoc(ReadSourceLocation()); |
| 990 | TemplArgs.setRAngleLoc(ReadSourceLocation()); |
| 991 | |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 992 | FD->setDependentTemplateSpecialization(Reader.getContext(), |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 993 | TemplDecls, TemplArgs); |
Richard Smith | da6c234 | 2015-07-01 23:19:58 +0000 | [diff] [blame] | 994 | // These are not merged; we don't need to merge redeclarations of dependent |
| 995 | // template friends. |
Argyrios Kyrtzidis | 0b0369a | 2010-06-28 09:31:34 +0000 | [diff] [blame] | 996 | break; |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 997 | } |
| 998 | } |
Argyrios Kyrtzidis | 373a83a | 2010-07-02 11:55:40 +0000 | [diff] [blame] | 999 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1000 | // Read in the parameters. |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1001 | unsigned NumParams = Record.readInt(); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1002 | SmallVector<ParmVarDecl *, 16> Params; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1003 | Params.reserve(NumParams); |
| 1004 | for (unsigned I = 0; I != NumParams; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1005 | Params.push_back(ReadDeclAs<ParmVarDecl>()); |
David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 1006 | FD->setParams(Reader.getContext(), Params); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1007 | } |
| 1008 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1009 | void ASTDeclReader::VisitObjCMethodDecl(ObjCMethodDecl *MD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1010 | VisitNamedDecl(MD); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1011 | if (Record.readInt()) { |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 1012 | // Load the body on-demand. Most clients won't care, because method |
| 1013 | // definitions rarely show up in headers. |
| 1014 | Reader.PendingBodies[MD] = GetCurrentCursorOffset(); |
| 1015 | HasPendingBody = true; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1016 | MD->setSelfDecl(ReadDeclAs<ImplicitParamDecl>()); |
| 1017 | MD->setCmdDecl(ReadDeclAs<ImplicitParamDecl>()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1018 | } |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1019 | MD->setInstanceMethod(Record.readInt()); |
| 1020 | MD->setVariadic(Record.readInt()); |
| 1021 | MD->setPropertyAccessor(Record.readInt()); |
| 1022 | MD->setDefined(Record.readInt()); |
Erich Keane | 9b18eca | 2018-08-01 21:31:08 +0000 | [diff] [blame] | 1023 | MD->setOverriding(Record.readInt()); |
| 1024 | MD->setHasSkippedBody(Record.readInt()); |
Argyrios Kyrtzidis | db21596 | 2011-10-14 17:41:52 +0000 | [diff] [blame] | 1025 | |
Erich Keane | 9b18eca | 2018-08-01 21:31:08 +0000 | [diff] [blame] | 1026 | MD->setIsRedeclaration(Record.readInt()); |
| 1027 | MD->setHasRedeclaration(Record.readInt()); |
| 1028 | if (MD->hasRedeclaration()) |
Argyrios Kyrtzidis | db21596 | 2011-10-14 17:41:52 +0000 | [diff] [blame] | 1029 | Reader.getContext().setObjCMethodRedeclaration(MD, |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1030 | ReadDeclAs<ObjCMethodDecl>()); |
Argyrios Kyrtzidis | db21596 | 2011-10-14 17:41:52 +0000 | [diff] [blame] | 1031 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1032 | MD->setDeclImplementation((ObjCMethodDecl::ImplementationControl)Record.readInt()); |
| 1033 | MD->setObjCDeclQualifier((Decl::ObjCDeclQualifier)Record.readInt()); |
Erich Keane | 9b18eca | 2018-08-01 21:31:08 +0000 | [diff] [blame] | 1034 | MD->setRelatedResultType(Record.readInt()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1035 | MD->setReturnType(Record.readType()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1036 | MD->setReturnTypeSourceInfo(GetTypeSourceInfo()); |
| 1037 | MD->DeclEndLoc = ReadSourceLocation(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1038 | unsigned NumParams = Record.readInt(); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1039 | SmallVector<ParmVarDecl *, 16> Params; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1040 | Params.reserve(NumParams); |
| 1041 | for (unsigned I = 0; I != NumParams; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1042 | Params.push_back(ReadDeclAs<ParmVarDecl>()); |
Argyrios Kyrtzidis | b8c3aaf | 2011-10-03 06:37:04 +0000 | [diff] [blame] | 1043 | |
Erich Keane | 9b18eca | 2018-08-01 21:31:08 +0000 | [diff] [blame] | 1044 | MD->setSelLocsKind((SelectorLocationsKind)Record.readInt()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1045 | unsigned NumStoredSelLocs = Record.readInt(); |
Argyrios Kyrtzidis | b8c3aaf | 2011-10-03 06:37:04 +0000 | [diff] [blame] | 1046 | SmallVector<SourceLocation, 16> SelLocs; |
| 1047 | SelLocs.reserve(NumStoredSelLocs); |
| 1048 | for (unsigned i = 0; i != NumStoredSelLocs; ++i) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1049 | SelLocs.push_back(ReadSourceLocation()); |
Argyrios Kyrtzidis | b8c3aaf | 2011-10-03 06:37:04 +0000 | [diff] [blame] | 1050 | |
| 1051 | MD->setParamsAndSelLocs(Reader.getContext(), Params, SelLocs); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1052 | } |
| 1053 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 1054 | void ASTDeclReader::VisitObjCTypeParamDecl(ObjCTypeParamDecl *D) { |
David Blaikie | 27a1bc0 | 2015-09-28 23:48:49 +0000 | [diff] [blame] | 1055 | VisitTypedefNameDecl(D); |
Richard Smith | 9b88a4c | 2015-07-27 05:40:23 +0000 | [diff] [blame] | 1056 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1057 | D->Variance = Record.readInt(); |
| 1058 | D->Index = Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1059 | D->VarianceLoc = ReadSourceLocation(); |
| 1060 | D->ColonLoc = ReadSourceLocation(); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 1061 | } |
| 1062 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1063 | void ASTDeclReader::VisitObjCContainerDecl(ObjCContainerDecl *CD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1064 | VisitNamedDecl(CD); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1065 | CD->setAtStartLoc(ReadSourceLocation()); |
| 1066 | CD->setAtEndRange(ReadSourceRange()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1067 | } |
| 1068 | |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 1069 | ObjCTypeParamList *ASTDeclReader::ReadObjCTypeParamList() { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1070 | unsigned numParams = Record.readInt(); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 1071 | if (numParams == 0) |
| 1072 | return nullptr; |
| 1073 | |
| 1074 | SmallVector<ObjCTypeParamDecl *, 4> typeParams; |
| 1075 | typeParams.reserve(numParams); |
| 1076 | for (unsigned i = 0; i != numParams; ++i) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1077 | auto *typeParam = ReadDeclAs<ObjCTypeParamDecl>(); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 1078 | if (!typeParam) |
| 1079 | return nullptr; |
| 1080 | |
| 1081 | typeParams.push_back(typeParam); |
| 1082 | } |
| 1083 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1084 | SourceLocation lAngleLoc = ReadSourceLocation(); |
| 1085 | SourceLocation rAngleLoc = ReadSourceLocation(); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 1086 | |
| 1087 | return ObjCTypeParamList::create(Reader.getContext(), lAngleLoc, |
| 1088 | typeParams, rAngleLoc); |
| 1089 | } |
| 1090 | |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 1091 | void ASTDeclReader::ReadObjCDefinitionData( |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1092 | struct ObjCInterfaceDecl::DefinitionData &Data) { |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 1093 | // Read the superclass. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1094 | Data.SuperClassTInfo = GetTypeSourceInfo(); |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 1095 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1096 | Data.EndLoc = ReadSourceLocation(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1097 | Data.HasDesignatedInitializers = Record.readInt(); |
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 directly referenced protocols and their SourceLocations. |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1100 | unsigned NumProtocols = Record.readInt(); |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 1101 | SmallVector<ObjCProtocolDecl *, 16> Protocols; |
| 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 | SmallVector<SourceLocation, 16> ProtoLocs; |
| 1106 | ProtoLocs.reserve(NumProtocols); |
| 1107 | for (unsigned I = 0; I != NumProtocols; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1108 | ProtoLocs.push_back(ReadSourceLocation()); |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 1109 | Data.ReferencedProtocols.set(Protocols.data(), NumProtocols, ProtoLocs.data(), |
| 1110 | Reader.getContext()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1111 | |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 1112 | // Read the transitive closure of protocols referenced by this class. |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1113 | NumProtocols = Record.readInt(); |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 1114 | Protocols.clear(); |
| 1115 | Protocols.reserve(NumProtocols); |
| 1116 | for (unsigned I = 0; I != NumProtocols; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1117 | Protocols.push_back(ReadDeclAs<ObjCProtocolDecl>()); |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 1118 | Data.AllReferencedProtocols.set(Protocols.data(), NumProtocols, |
| 1119 | Reader.getContext()); |
| 1120 | } |
| 1121 | |
| 1122 | void ASTDeclReader::MergeDefinitionData(ObjCInterfaceDecl *D, |
| 1123 | struct ObjCInterfaceDecl::DefinitionData &&NewDD) { |
| 1124 | // FIXME: odr checking? |
| 1125 | } |
| 1126 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1127 | void ASTDeclReader::VisitObjCInterfaceDecl(ObjCInterfaceDecl *ID) { |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 1128 | RedeclarableResult Redecl = VisitRedeclarable(ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1129 | VisitObjCContainerDecl(ID); |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 1130 | DeferredTypeID = Record.getGlobalTypeID(Record.readInt()); |
Douglas Gregor | 2c46b5b | 2012-01-03 17:27:13 +0000 | [diff] [blame] | 1131 | mergeRedeclarable(ID, Redecl); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 1132 | |
| 1133 | ID->TypeParamList = ReadObjCTypeParamList(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1134 | if (Record.readInt()) { |
Douglas Gregor | c0ac7d6 | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 1135 | // Read the definition. |
| 1136 | ID->allocateDefinitionData(); |
Douglas Gregor | c0ac7d6 | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 1137 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1138 | ReadObjCDefinitionData(ID->data()); |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 1139 | ObjCInterfaceDecl *Canon = ID->getCanonicalDecl(); |
| 1140 | if (Canon->Data.getPointer()) { |
| 1141 | // If we already have a definition, keep the definition invariant and |
| 1142 | // merge the data. |
| 1143 | MergeDefinitionData(Canon, std::move(ID->data())); |
| 1144 | ID->Data = Canon->Data; |
| 1145 | } else { |
| 1146 | // Set the definition data of the canonical declaration, so other |
| 1147 | // redeclarations will see it. |
| 1148 | ID->getCanonicalDecl()->Data = ID->Data; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1149 | |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 1150 | // We will rebuild this list lazily. |
| 1151 | ID->setIvarList(nullptr); |
| 1152 | } |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 1153 | |
Douglas Gregor | c1a61fe | 2011-12-19 20:51:16 +0000 | [diff] [blame] | 1154 | // Note that we have deserialized a definition. |
| 1155 | Reader.PendingDefinitions.insert(ID); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1156 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 1157 | // Note that we've loaded this Objective-C class. |
| 1158 | Reader.ObjCClassesLoaded.push_back(ID); |
Douglas Gregor | c03c52e | 2012-01-15 18:08:05 +0000 | [diff] [blame] | 1159 | } else { |
| 1160 | ID->Data = ID->getCanonicalDecl()->Data; |
Douglas Gregor | c0ac7d6 | 2011-12-15 05:27:12 +0000 | [diff] [blame] | 1161 | } |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1162 | } |
| 1163 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1164 | void ASTDeclReader::VisitObjCIvarDecl(ObjCIvarDecl *IVD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1165 | VisitFieldDecl(IVD); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1166 | IVD->setAccessControl((ObjCIvarDecl::AccessControl)Record.readInt()); |
Fariborz Jahanian | a50b3a2 | 2010-08-20 21:21:08 +0000 | [diff] [blame] | 1167 | // This field will be built lazily. |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 1168 | IVD->setNextIvar(nullptr); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1169 | bool synth = Record.readInt(); |
Fariborz Jahanian | aea8e1e | 2010-07-17 18:35:47 +0000 | [diff] [blame] | 1170 | IVD->setSynthesize(synth); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1171 | } |
| 1172 | |
Graydon Hoare | e0a6835 | 2017-06-28 18:36:27 +0000 | [diff] [blame] | 1173 | void ASTDeclReader::ReadObjCDefinitionData( |
| 1174 | struct ObjCProtocolDecl::DefinitionData &Data) { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1175 | unsigned NumProtoRefs = Record.readInt(); |
Douglas Gregor | e6e48b1 | 2012-01-01 19:29:29 +0000 | [diff] [blame] | 1176 | SmallVector<ObjCProtocolDecl *, 16> ProtoRefs; |
| 1177 | ProtoRefs.reserve(NumProtoRefs); |
| 1178 | for (unsigned I = 0; I != NumProtoRefs; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1179 | ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>()); |
Douglas Gregor | e6e48b1 | 2012-01-01 19:29:29 +0000 | [diff] [blame] | 1180 | SmallVector<SourceLocation, 16> ProtoLocs; |
| 1181 | ProtoLocs.reserve(NumProtoRefs); |
| 1182 | for (unsigned I = 0; I != NumProtoRefs; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1183 | ProtoLocs.push_back(ReadSourceLocation()); |
Graydon Hoare | e0a6835 | 2017-06-28 18:36:27 +0000 | [diff] [blame] | 1184 | Data.ReferencedProtocols.set(ProtoRefs.data(), NumProtoRefs, |
| 1185 | ProtoLocs.data(), Reader.getContext()); |
| 1186 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1187 | |
Graydon Hoare | e0a6835 | 2017-06-28 18:36:27 +0000 | [diff] [blame] | 1188 | void ASTDeclReader::MergeDefinitionData(ObjCProtocolDecl *D, |
| 1189 | struct ObjCProtocolDecl::DefinitionData &&NewDD) { |
| 1190 | // FIXME: odr checking? |
| 1191 | } |
| 1192 | |
| 1193 | void ASTDeclReader::VisitObjCProtocolDecl(ObjCProtocolDecl *PD) { |
| 1194 | RedeclarableResult Redecl = VisitRedeclarable(PD); |
| 1195 | VisitObjCContainerDecl(PD); |
| 1196 | mergeRedeclarable(PD, Redecl); |
| 1197 | |
| 1198 | if (Record.readInt()) { |
| 1199 | // Read the definition. |
| 1200 | PD->allocateDefinitionData(); |
| 1201 | |
| 1202 | ReadObjCDefinitionData(PD->data()); |
| 1203 | |
| 1204 | ObjCProtocolDecl *Canon = PD->getCanonicalDecl(); |
| 1205 | if (Canon->Data.getPointer()) { |
| 1206 | // If we already have a definition, keep the definition invariant and |
| 1207 | // merge the data. |
| 1208 | MergeDefinitionData(Canon, std::move(PD->data())); |
| 1209 | PD->Data = Canon->Data; |
| 1210 | } else { |
| 1211 | // Set the definition data of the canonical declaration, so other |
| 1212 | // redeclarations will see it. |
| 1213 | PD->getCanonicalDecl()->Data = PD->Data; |
| 1214 | } |
Douglas Gregor | a715bff | 2012-01-01 19:51:50 +0000 | [diff] [blame] | 1215 | // Note that we have deserialized a definition. |
| 1216 | Reader.PendingDefinitions.insert(PD); |
Douglas Gregor | c03c52e | 2012-01-15 18:08:05 +0000 | [diff] [blame] | 1217 | } else { |
| 1218 | PD->Data = PD->getCanonicalDecl()->Data; |
Douglas Gregor | e6e48b1 | 2012-01-01 19:29:29 +0000 | [diff] [blame] | 1219 | } |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1220 | } |
| 1221 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1222 | void ASTDeclReader::VisitObjCAtDefsFieldDecl(ObjCAtDefsFieldDecl *FD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1223 | VisitFieldDecl(FD); |
| 1224 | } |
| 1225 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1226 | void ASTDeclReader::VisitObjCCategoryDecl(ObjCCategoryDecl *CD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1227 | VisitObjCContainerDecl(CD); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1228 | CD->setCategoryNameLoc(ReadSourceLocation()); |
| 1229 | CD->setIvarLBraceLoc(ReadSourceLocation()); |
| 1230 | CD->setIvarRBraceLoc(ReadSourceLocation()); |
| 1231 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 1232 | // Note that this category has been deserialized. We do this before |
| 1233 | // deserializing the interface declaration, so that it will consider this |
| 1234 | /// category. |
| 1235 | Reader.CategoriesDeserialized.insert(CD); |
| 1236 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1237 | CD->ClassInterface = ReadDeclAs<ObjCInterfaceDecl>(); |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 1238 | CD->TypeParamList = ReadObjCTypeParamList(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1239 | unsigned NumProtoRefs = Record.readInt(); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1240 | SmallVector<ObjCProtocolDecl *, 16> ProtoRefs; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1241 | ProtoRefs.reserve(NumProtoRefs); |
| 1242 | for (unsigned I = 0; I != NumProtoRefs; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1243 | ProtoRefs.push_back(ReadDeclAs<ObjCProtocolDecl>()); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1244 | SmallVector<SourceLocation, 16> ProtoLocs; |
Douglas Gregor | 002b671 | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 1245 | ProtoLocs.reserve(NumProtoRefs); |
| 1246 | for (unsigned I = 0; I != NumProtoRefs; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1247 | ProtoLocs.push_back(ReadSourceLocation()); |
Douglas Gregor | 002b671 | 2010-01-16 15:02:53 +0000 | [diff] [blame] | 1248 | CD->setProtocolList(ProtoRefs.data(), NumProtoRefs, ProtoLocs.data(), |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1249 | Reader.getContext()); |
Bruno Cardoso Lopes | fbff2fa | 2018-04-27 18:01:23 +0000 | [diff] [blame] | 1250 | |
| 1251 | // Protocols in the class extension belong to the class. |
| 1252 | if (NumProtoRefs > 0 && CD->ClassInterface && CD->IsClassExtension()) |
| 1253 | CD->ClassInterface->mergeClassExtensionProtocolList( |
| 1254 | (ObjCProtocolDecl *const *)ProtoRefs.data(), NumProtoRefs, |
| 1255 | Reader.getContext()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1256 | } |
| 1257 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1258 | void ASTDeclReader::VisitObjCCompatibleAliasDecl(ObjCCompatibleAliasDecl *CAD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1259 | VisitNamedDecl(CAD); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1260 | CAD->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1261 | } |
| 1262 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1263 | void ASTDeclReader::VisitObjCPropertyDecl(ObjCPropertyDecl *D) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1264 | VisitNamedDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1265 | D->setAtLoc(ReadSourceLocation()); |
| 1266 | D->setLParenLoc(ReadSourceLocation()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1267 | QualType T = Record.readType(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1268 | TypeSourceInfo *TSI = GetTypeSourceInfo(); |
Douglas Gregor | 813a066 | 2015-06-19 18:14:38 +0000 | [diff] [blame] | 1269 | D->setType(T, TSI); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1270 | D->setPropertyAttributes( |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1271 | (ObjCPropertyDecl::PropertyAttributeKind)Record.readInt()); |
Fariborz Jahanian | 3bf0ded | 2010-06-22 23:20:40 +0000 | [diff] [blame] | 1272 | D->setPropertyAttributesAsWritten( |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1273 | (ObjCPropertyDecl::PropertyAttributeKind)Record.readInt()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1274 | D->setPropertyImplementation( |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1275 | (ObjCPropertyDecl::PropertyControl)Record.readInt()); |
Argyrios Kyrtzidis | c6c4ec8 | 2017-03-17 00:49:42 +0000 | [diff] [blame] | 1276 | DeclarationName GetterName = Record.readDeclarationName(); |
| 1277 | SourceLocation GetterLoc = ReadSourceLocation(); |
| 1278 | D->setGetterName(GetterName.getObjCSelector(), GetterLoc); |
| 1279 | DeclarationName SetterName = Record.readDeclarationName(); |
| 1280 | SourceLocation SetterLoc = ReadSourceLocation(); |
| 1281 | D->setSetterName(SetterName.getObjCSelector(), SetterLoc); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1282 | D->setGetterMethodDecl(ReadDeclAs<ObjCMethodDecl>()); |
| 1283 | D->setSetterMethodDecl(ReadDeclAs<ObjCMethodDecl>()); |
| 1284 | D->setPropertyIvarDecl(ReadDeclAs<ObjCIvarDecl>()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1285 | } |
| 1286 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1287 | void ASTDeclReader::VisitObjCImplDecl(ObjCImplDecl *D) { |
Argyrios Kyrtzidis | 067c407 | 2009-07-27 19:04:32 +0000 | [diff] [blame] | 1288 | VisitObjCContainerDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1289 | D->setClassInterface(ReadDeclAs<ObjCInterfaceDecl>()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1290 | } |
| 1291 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1292 | void ASTDeclReader::VisitObjCCategoryImplDecl(ObjCCategoryImplDecl *D) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1293 | VisitObjCImplDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1294 | D->CategoryNameLoc = ReadSourceLocation(); |
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::VisitObjCImplementationDecl(ObjCImplementationDecl *D) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1298 | VisitObjCImplDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1299 | D->setSuperClass(ReadDeclAs<ObjCInterfaceDecl>()); |
| 1300 | D->SuperLoc = ReadSourceLocation(); |
| 1301 | D->setIvarLBraceLoc(ReadSourceLocation()); |
| 1302 | D->setIvarRBraceLoc(ReadSourceLocation()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1303 | D->setHasNonZeroConstructors(Record.readInt()); |
| 1304 | D->setHasDestructors(Record.readInt()); |
| 1305 | D->NumIvarInitializers = Record.readInt(); |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 1306 | if (D->NumIvarInitializers) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1307 | D->IvarInitializers = ReadGlobalOffset(); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1308 | } |
| 1309 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1310 | void ASTDeclReader::VisitObjCPropertyImplDecl(ObjCPropertyImplDecl *D) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1311 | VisitDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1312 | D->setAtLoc(ReadSourceLocation()); |
| 1313 | D->setPropertyDecl(ReadDeclAs<ObjCPropertyDecl>()); |
| 1314 | D->PropertyIvarDecl = ReadDeclAs<ObjCIvarDecl>(); |
| 1315 | D->IvarLoc = ReadSourceLocation(); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1316 | D->setGetterCXXConstructor(Record.readExpr()); |
| 1317 | D->setSetterCXXAssignment(Record.readExpr()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1318 | } |
| 1319 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1320 | void ASTDeclReader::VisitFieldDecl(FieldDecl *FD) { |
Argyrios Kyrtzidis | 560ac97 | 2009-08-19 01:28:35 +0000 | [diff] [blame] | 1321 | VisitDeclaratorDecl(FD); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1322 | FD->Mutable = Record.readInt(); |
Richard Smith | 6b8e3c0 | 2017-08-28 00:28:14 +0000 | [diff] [blame] | 1323 | |
| 1324 | if (auto ISK = static_cast<FieldDecl::InitStorageKind>(Record.readInt())) { |
| 1325 | FD->InitStorage.setInt(ISK); |
| 1326 | FD->InitStorage.setPointer(ISK == FieldDecl::ISK_CapturedVLAType |
| 1327 | ? Record.readType().getAsOpaquePtr() |
| 1328 | : Record.readExpr()); |
Richard Smith | 2b01318 | 2012-06-10 03:12:00 +0000 | [diff] [blame] | 1329 | } |
Richard Smith | 6b8e3c0 | 2017-08-28 00:28:14 +0000 | [diff] [blame] | 1330 | |
| 1331 | if (auto *BW = Record.readExpr()) |
| 1332 | FD->setBitWidth(BW); |
| 1333 | |
Argyrios Kyrtzidis | 6685e8a | 2010-07-04 21:44:35 +0000 | [diff] [blame] | 1334 | if (!FD->getDeclName()) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1335 | if (auto *Tmpl = ReadDeclAs<FieldDecl>()) |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1336 | Reader.getContext().setInstantiatedFromUnnamedFieldDecl(FD, Tmpl); |
Argyrios Kyrtzidis | 6685e8a | 2010-07-04 21:44:35 +0000 | [diff] [blame] | 1337 | } |
Richard Smith | 0b87e07 | 2013-10-07 08:02:11 +0000 | [diff] [blame] | 1338 | mergeMergeable(FD); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1339 | } |
| 1340 | |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 1341 | void ASTDeclReader::VisitMSPropertyDecl(MSPropertyDecl *PD) { |
| 1342 | VisitDeclaratorDecl(PD); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1343 | PD->GetterId = Record.getIdentifierInfo(); |
| 1344 | PD->SetterId = Record.getIdentifierInfo(); |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 1345 | } |
| 1346 | |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 1347 | void ASTDeclReader::VisitIndirectFieldDecl(IndirectFieldDecl *FD) { |
| 1348 | VisitValueDecl(FD); |
| 1349 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1350 | FD->ChainingSize = Record.readInt(); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 1351 | assert(FD->ChainingSize >= 2 && "Anonymous chaining must be >= 2"); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1352 | FD->Chaining = new (Reader.getContext())NamedDecl*[FD->ChainingSize]; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 1353 | |
| 1354 | for (unsigned I = 0; I != FD->ChainingSize; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1355 | FD->Chaining[I] = ReadDeclAs<NamedDecl>(); |
Richard Smith | 8cbd895 | 2015-08-04 02:05:09 +0000 | [diff] [blame] | 1356 | |
| 1357 | mergeMergeable(FD); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 1358 | } |
| 1359 | |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1360 | ASTDeclReader::RedeclarableResult ASTDeclReader::VisitVarDeclImpl(VarDecl *VD) { |
Douglas Gregor | b8c6f1e | 2012-01-04 17:21:36 +0000 | [diff] [blame] | 1361 | RedeclarableResult Redecl = VisitRedeclarable(VD); |
Douglas Gregor | 3e30010 | 2011-10-26 17:53:41 +0000 | [diff] [blame] | 1362 | VisitDeclaratorDecl(VD); |
Rafael Espindola | 6ae7e50 | 2013-04-03 19:27:57 +0000 | [diff] [blame] | 1363 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1364 | VD->VarDeclBits.SClass = (StorageClass)Record.readInt(); |
| 1365 | VD->VarDeclBits.TSCSpec = Record.readInt(); |
| 1366 | VD->VarDeclBits.InitStyle = Record.readInt(); |
Erik Pilkington | 1e36882 | 2019-01-04 18:33:06 +0000 | [diff] [blame] | 1367 | VD->VarDeclBits.ARCPseudoStrong = Record.readInt(); |
David Majnemer | fa7bc78 | 2015-05-19 00:57:16 +0000 | [diff] [blame] | 1368 | if (!isa<ParmVarDecl>(VD)) { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1369 | VD->NonParmVarDeclBits.IsThisDeclarationADemotedDefinition = |
| 1370 | Record.readInt(); |
| 1371 | VD->NonParmVarDeclBits.ExceptionVar = Record.readInt(); |
Taiju Tsuiki | 3be68e1 | 2018-06-19 05:35:30 +0000 | [diff] [blame] | 1372 | VD->NonParmVarDeclBits.NRVOVariable = Record.readInt(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1373 | VD->NonParmVarDeclBits.CXXForRangeDecl = Record.readInt(); |
George Karpenkov | ec38cf7 | 2018-03-29 00:56:24 +0000 | [diff] [blame] | 1374 | VD->NonParmVarDeclBits.ObjCForDecl = Record.readInt(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1375 | VD->NonParmVarDeclBits.IsInline = Record.readInt(); |
| 1376 | VD->NonParmVarDeclBits.IsInlineSpecified = Record.readInt(); |
| 1377 | VD->NonParmVarDeclBits.IsConstexpr = Record.readInt(); |
| 1378 | VD->NonParmVarDeclBits.IsInitCapture = Record.readInt(); |
| 1379 | VD->NonParmVarDeclBits.PreviousDeclInSameBlockScope = Record.readInt(); |
Alexey Bataev | 5622323 | 2017-06-09 13:40:18 +0000 | [diff] [blame] | 1380 | VD->NonParmVarDeclBits.ImplicitParamKind = Record.readInt(); |
Akira Hatanaka | 8e57b07 | 2018-10-01 21:51:28 +0000 | [diff] [blame] | 1381 | VD->NonParmVarDeclBits.EscapingByref = Record.readInt(); |
David Majnemer | fa7bc78 | 2015-05-19 00:57:16 +0000 | [diff] [blame] | 1382 | } |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1383 | auto VarLinkage = Linkage(Record.readInt()); |
Richard Smith | 541b38b | 2013-09-20 01:15:31 +0000 | [diff] [blame] | 1384 | VD->setCachedLinkage(VarLinkage); |
| 1385 | |
| 1386 | // Reconstruct the one piece of the IdentifierNamespace that we need. |
Ted Kremenek | a683f63 | 2014-02-11 06:29:29 +0000 | [diff] [blame] | 1387 | if (VD->getStorageClass() == SC_Extern && VarLinkage != NoLinkage && |
Richard Smith | 541b38b | 2013-09-20 01:15:31 +0000 | [diff] [blame] | 1388 | VD->getLexicalDeclContext()->isFunctionOrMethod()) |
| 1389 | VD->setLocalExternDecl(); |
Rafael Espindola | 50df3a0 | 2013-05-25 17:16:20 +0000 | [diff] [blame] | 1390 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1391 | if (uint64_t Val = Record.readInt()) { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1392 | VD->setInit(Record.readExpr()); |
Richard Smith | 2b4fa53 | 2019-09-29 05:08:46 +0000 | [diff] [blame] | 1393 | if (Val > 1) { |
Richard Smith | d0b4dd6 | 2011-12-19 06:19:21 +0000 | [diff] [blame] | 1394 | EvaluatedStmt *Eval = VD->ensureEvaluatedStmt(); |
| 1395 | Eval->CheckedICE = true; |
Richard Smith | 2b4fa53 | 2019-09-29 05:08:46 +0000 | [diff] [blame] | 1396 | Eval->IsICE = (Val & 1) != 0; |
| 1397 | Eval->HasConstantDestruction = (Val & 4) != 0; |
Richard Smith | d0b4dd6 | 2011-12-19 06:19:21 +0000 | [diff] [blame] | 1398 | } |
| 1399 | } |
Argyrios Kyrtzidis | cdb8b3f | 2010-07-04 21:44:00 +0000 | [diff] [blame] | 1400 | |
Akira Hatanaka | 9978da3 | 2018-08-10 15:09:24 +0000 | [diff] [blame] | 1401 | if (VD->hasAttr<BlocksAttr>() && VD->getType()->getAsCXXRecordDecl()) { |
| 1402 | Expr *CopyExpr = Record.readExpr(); |
| 1403 | if (CopyExpr) |
| 1404 | Reader.getContext().setBlockVarCopyInit(VD, CopyExpr, Record.readInt()); |
| 1405 | } |
| 1406 | |
Richard Smith | a465362 | 2017-09-06 20:01:14 +0000 | [diff] [blame] | 1407 | if (VD->getStorageDuration() == SD_Static && Record.readInt()) |
| 1408 | Reader.DefinitionSource[VD] = Loc.F->Kind == ModuleKind::MK_MainFile; |
| 1409 | |
Larisse Voufo | d8dd97c | 2013-08-14 03:09:19 +0000 | [diff] [blame] | 1410 | enum VarKind { |
| 1411 | VarNotTemplate = 0, VarTemplate, StaticDataMemberSpecialization |
| 1412 | }; |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1413 | switch ((VarKind)Record.readInt()) { |
Larisse Voufo | d8dd97c | 2013-08-14 03:09:19 +0000 | [diff] [blame] | 1414 | case VarNotTemplate: |
Richard Smith | 9b88a4c | 2015-07-27 05:40:23 +0000 | [diff] [blame] | 1415 | // Only true variables (not parameters or implicit parameters) can be |
| 1416 | // merged; the other kinds are not really redeclarable at all. |
Richard Smith | 0144f51 | 2015-08-22 02:09:38 +0000 | [diff] [blame] | 1417 | if (!isa<ParmVarDecl>(VD) && !isa<ImplicitParamDecl>(VD) && |
| 1418 | !isa<VarTemplateSpecializationDecl>(VD)) |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 1419 | mergeRedeclarable(VD, Redecl); |
Larisse Voufo | d8dd97c | 2013-08-14 03:09:19 +0000 | [diff] [blame] | 1420 | break; |
| 1421 | case VarTemplate: |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 1422 | // Merged when we merge the template. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1423 | VD->setDescribedVarTemplate(ReadDeclAs<VarTemplateDecl>()); |
Larisse Voufo | d8dd97c | 2013-08-14 03:09:19 +0000 | [diff] [blame] | 1424 | break; |
| 1425 | case StaticDataMemberSpecialization: { // HasMemberSpecializationInfo. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1426 | auto *Tmpl = ReadDeclAs<VarDecl>(); |
| 1427 | auto TSK = (TemplateSpecializationKind)Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1428 | SourceLocation POI = ReadSourceLocation(); |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1429 | Reader.getContext().setInstantiatedFromStaticDataMember(VD, Tmpl, TSK,POI); |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 1430 | mergeRedeclarable(VD, Redecl); |
Larisse Voufo | d8dd97c | 2013-08-14 03:09:19 +0000 | [diff] [blame] | 1431 | break; |
| 1432 | } |
Argyrios Kyrtzidis | cdb8b3f | 2010-07-04 21:44:00 +0000 | [diff] [blame] | 1433 | } |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 1434 | |
| 1435 | return Redecl; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1436 | } |
| 1437 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1438 | void ASTDeclReader::VisitImplicitParamDecl(ImplicitParamDecl *PD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1439 | VisitVarDecl(PD); |
| 1440 | } |
| 1441 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1442 | void ASTDeclReader::VisitParmVarDecl(ParmVarDecl *PD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1443 | VisitVarDecl(PD); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1444 | unsigned isObjCMethodParam = Record.readInt(); |
| 1445 | unsigned scopeDepth = Record.readInt(); |
| 1446 | unsigned scopeIndex = Record.readInt(); |
| 1447 | unsigned declQualifier = Record.readInt(); |
John McCall | 8249083 | 2011-05-02 00:30:12 +0000 | [diff] [blame] | 1448 | if (isObjCMethodParam) { |
| 1449 | assert(scopeDepth == 0); |
| 1450 | PD->setObjCMethodScopeInfo(scopeIndex); |
| 1451 | PD->ParmVarDeclBits.ScopeDepthOrObjCQuals = declQualifier; |
| 1452 | } else { |
| 1453 | PD->setScopeInfo(scopeDepth, scopeIndex); |
| 1454 | } |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1455 | PD->ParmVarDeclBits.IsKNRPromoted = Record.readInt(); |
| 1456 | PD->ParmVarDeclBits.HasInheritedDefaultArg = Record.readInt(); |
| 1457 | if (Record.readInt()) // hasUninstantiatedDefaultArg. |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1458 | PD->setUninstantiatedDefaultArg(Record.readExpr()); |
Richard Smith | bf78e64 | 2013-06-24 22:51:00 +0000 | [diff] [blame] | 1459 | |
| 1460 | // FIXME: If this is a redeclaration of a function from another module, handle |
| 1461 | // inheritance of default arguments. |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1462 | } |
| 1463 | |
Richard Smith | 7b76d81 | 2016-08-12 02:21:25 +0000 | [diff] [blame] | 1464 | void ASTDeclReader::VisitDecompositionDecl(DecompositionDecl *DD) { |
| 1465 | VisitVarDecl(DD); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1466 | auto **BDs = DD->getTrailingObjects<BindingDecl *>(); |
Richard Smith | 0353e5a | 2019-05-25 01:04:17 +0000 | [diff] [blame] | 1467 | for (unsigned I = 0; I != DD->NumBindings; ++I) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1468 | BDs[I] = ReadDeclAs<BindingDecl>(); |
Richard Smith | 0353e5a | 2019-05-25 01:04:17 +0000 | [diff] [blame] | 1469 | BDs[I]->setDecomposedDecl(DD); |
| 1470 | } |
Richard Smith | 7b76d81 | 2016-08-12 02:21:25 +0000 | [diff] [blame] | 1471 | } |
| 1472 | |
| 1473 | void ASTDeclReader::VisitBindingDecl(BindingDecl *BD) { |
| 1474 | VisitValueDecl(BD); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1475 | BD->Binding = Record.readExpr(); |
Richard Smith | 7b76d81 | 2016-08-12 02:21:25 +0000 | [diff] [blame] | 1476 | } |
| 1477 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1478 | void ASTDeclReader::VisitFileScopeAsmDecl(FileScopeAsmDecl *AD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1479 | VisitDecl(AD); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1480 | AD->setAsmString(cast<StringLiteral>(Record.readExpr())); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1481 | AD->setRParenLoc(ReadSourceLocation()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1482 | } |
| 1483 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1484 | void ASTDeclReader::VisitBlockDecl(BlockDecl *BD) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1485 | VisitDecl(BD); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1486 | BD->setBody(cast_or_null<CompoundStmt>(Record.readStmt())); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1487 | BD->setSignatureAsWritten(GetTypeSourceInfo()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1488 | unsigned NumParams = Record.readInt(); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1489 | SmallVector<ParmVarDecl *, 16> Params; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1490 | Params.reserve(NumParams); |
| 1491 | for (unsigned I = 0; I != NumParams; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1492 | Params.push_back(ReadDeclAs<ParmVarDecl>()); |
David Blaikie | 9c70e04 | 2011-09-21 18:16:56 +0000 | [diff] [blame] | 1493 | BD->setParams(Params); |
John McCall | c63de66 | 2011-02-02 13:00:07 +0000 | [diff] [blame] | 1494 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1495 | BD->setIsVariadic(Record.readInt()); |
| 1496 | BD->setBlockMissingReturnType(Record.readInt()); |
| 1497 | BD->setIsConversionFromLambda(Record.readInt()); |
Akira Hatanaka | db49a1f | 2018-08-01 23:51:53 +0000 | [diff] [blame] | 1498 | BD->setDoesNotEscape(Record.readInt()); |
Akira Hatanaka | c5792aa | 2019-02-27 18:17:16 +0000 | [diff] [blame] | 1499 | BD->setCanAvoidCopyToHeap(Record.readInt()); |
John McCall | cf6ce28 | 2012-04-13 17:33:29 +0000 | [diff] [blame] | 1500 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1501 | bool capturesCXXThis = Record.readInt(); |
| 1502 | unsigned numCaptures = Record.readInt(); |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 1503 | SmallVector<BlockDecl::Capture, 16> captures; |
John McCall | 351762c | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 1504 | captures.reserve(numCaptures); |
| 1505 | for (unsigned i = 0; i != numCaptures; ++i) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1506 | auto *decl = ReadDeclAs<VarDecl>(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1507 | unsigned flags = Record.readInt(); |
John McCall | 351762c | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 1508 | bool byRef = (flags & 1); |
| 1509 | bool nested = (flags & 2); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1510 | Expr *copyExpr = ((flags & 4) ? Record.readExpr() : nullptr); |
John McCall | 351762c | 2011-02-07 10:33:21 +0000 | [diff] [blame] | 1511 | |
| 1512 | captures.push_back(BlockDecl::Capture(decl, byRef, nested, copyExpr)); |
| 1513 | } |
Benjamin Kramer | b40e4af | 2015-08-05 09:40:35 +0000 | [diff] [blame] | 1514 | BD->setCaptures(Reader.getContext(), captures, capturesCXXThis); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 1515 | } |
| 1516 | |
Ben Langmuir | ce914fc | 2013-05-03 19:20:19 +0000 | [diff] [blame] | 1517 | void ASTDeclReader::VisitCapturedDecl(CapturedDecl *CD) { |
| 1518 | VisitDecl(CD); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1519 | unsigned ContextParamPos = Record.readInt(); |
| 1520 | CD->setNothrow(Record.readInt() != 0); |
Ben Langmuir | ce914fc | 2013-05-03 19:20:19 +0000 | [diff] [blame] | 1521 | // Body is set by VisitCapturedStmt. |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1522 | for (unsigned I = 0; I < CD->NumParams; ++I) { |
| 1523 | if (I != ContextParamPos) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1524 | CD->setParam(I, ReadDeclAs<ImplicitParamDecl>()); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1525 | else |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1526 | CD->setContextParam(I, ReadDeclAs<ImplicitParamDecl>()); |
Alexey Bataev | 9959db5 | 2014-05-06 10:08:46 +0000 | [diff] [blame] | 1527 | } |
Tareq A. Siraj | 6dfa25a | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 1528 | } |
| 1529 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1530 | void ASTDeclReader::VisitLinkageSpecDecl(LinkageSpecDecl *D) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1531 | VisitDecl(D); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1532 | D->setLanguage((LinkageSpecDecl::LanguageIDs)Record.readInt()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1533 | D->setExternLoc(ReadSourceLocation()); |
| 1534 | D->setRBraceLoc(ReadSourceLocation()); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1535 | } |
| 1536 | |
Richard Smith | 8df390f | 2016-09-08 23:14:54 +0000 | [diff] [blame] | 1537 | void ASTDeclReader::VisitExportDecl(ExportDecl *D) { |
| 1538 | VisitDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1539 | D->RBraceLoc = ReadSourceLocation(); |
Richard Smith | 8df390f | 2016-09-08 23:14:54 +0000 | [diff] [blame] | 1540 | } |
| 1541 | |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1542 | void ASTDeclReader::VisitLabelDecl(LabelDecl *D) { |
| 1543 | VisitNamedDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1544 | D->setLocStart(ReadSourceLocation()); |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 1545 | } |
| 1546 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1547 | void ASTDeclReader::VisitNamespaceDecl(NamespaceDecl *D) { |
Douglas Gregor | e57e752 | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 1548 | RedeclarableResult Redecl = VisitRedeclarable(D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1549 | VisitNamedDecl(D); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1550 | D->setInline(Record.readInt()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1551 | D->LocStart = ReadSourceLocation(); |
| 1552 | D->RBraceLoc = ReadSourceLocation(); |
Douglas Gregor | cfe7dc6 | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 1553 | |
Richard Smith | 15e32fd | 2015-03-17 02:23:11 +0000 | [diff] [blame] | 1554 | // Defer loading the anonymous namespace until we've finished merging |
| 1555 | // this namespace; loading it might load a later declaration of the |
| 1556 | // same namespace, and we have an invariant that older declarations |
| 1557 | // get merged before newer ones try to merge. |
| 1558 | GlobalDeclID AnonNamespace = 0; |
Douglas Gregor | e57e752 | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 1559 | if (Redecl.getFirstID() == ThisDeclID) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1560 | AnonNamespace = ReadDeclID(); |
Douglas Gregor | e57e752 | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 1561 | } else { |
| 1562 | // Link this namespace back to the first declaration, which has already |
| 1563 | // been deserialized. |
Rafael Espindola | 8db352d | 2013-10-17 15:37:26 +0000 | [diff] [blame] | 1564 | D->AnonOrFirstNamespaceAndInline.setPointer(D->getFirstDecl()); |
Douglas Gregor | e57e752 | 2012-01-07 09:11:48 +0000 | [diff] [blame] | 1565 | } |
Richard Smith | 5e9e56a | 2014-07-15 03:37:06 +0000 | [diff] [blame] | 1566 | |
| 1567 | mergeRedeclarable(D, Redecl); |
Richard Smith | 15e32fd | 2015-03-17 02:23:11 +0000 | [diff] [blame] | 1568 | |
| 1569 | if (AnonNamespace) { |
| 1570 | // Each module has its own anonymous namespace, which is disjoint from |
| 1571 | // any other module's anonymous namespaces, so don't attach the anonymous |
| 1572 | // namespace at all. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1573 | auto *Anon = cast<NamespaceDecl>(Reader.GetDecl(AnonNamespace)); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1574 | if (!Record.isModule()) |
Richard Smith | 15e32fd | 2015-03-17 02:23:11 +0000 | [diff] [blame] | 1575 | D->setAnonymousNamespace(Anon); |
| 1576 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1577 | } |
| 1578 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1579 | void ASTDeclReader::VisitNamespaceAliasDecl(NamespaceAliasDecl *D) { |
Richard Smith | f463436 | 2014-09-03 23:11:22 +0000 | [diff] [blame] | 1580 | RedeclarableResult Redecl = VisitRedeclarable(D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1581 | VisitNamedDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1582 | D->NamespaceLoc = ReadSourceLocation(); |
| 1583 | D->IdentLoc = ReadSourceLocation(); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1584 | D->QualifierLoc = Record.readNestedNameSpecifierLoc(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1585 | D->Namespace = ReadDeclAs<NamedDecl>(); |
Richard Smith | f463436 | 2014-09-03 23:11:22 +0000 | [diff] [blame] | 1586 | mergeRedeclarable(D, Redecl); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1587 | } |
| 1588 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1589 | void ASTDeclReader::VisitUsingDecl(UsingDecl *D) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1590 | VisitNamedDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1591 | D->setUsingLoc(ReadSourceLocation()); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1592 | D->QualifierLoc = Record.readNestedNameSpecifierLoc(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1593 | ReadDeclarationNameLoc(D->DNLoc, D->getDeclName()); |
| 1594 | D->FirstUsingShadow.setPointer(ReadDeclAs<UsingShadowDecl>()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1595 | D->setTypename(Record.readInt()); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1596 | if (auto *Pattern = ReadDeclAs<NamedDecl>()) |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1597 | Reader.getContext().setInstantiatedFromUsingDecl(D, Pattern); |
Richard Smith | 32952e1 | 2014-10-14 02:00:47 +0000 | [diff] [blame] | 1598 | mergeMergeable(D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1599 | } |
| 1600 | |
Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 1601 | void ASTDeclReader::VisitUsingPackDecl(UsingPackDecl *D) { |
| 1602 | VisitNamedDecl(D); |
| 1603 | D->InstantiatedFrom = ReadDeclAs<NamedDecl>(); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1604 | auto **Expansions = D->getTrailingObjects<NamedDecl *>(); |
Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 1605 | for (unsigned I = 0; I != D->NumExpansions; ++I) |
| 1606 | Expansions[I] = ReadDeclAs<NamedDecl>(); |
| 1607 | mergeMergeable(D); |
| 1608 | } |
| 1609 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1610 | void ASTDeclReader::VisitUsingShadowDecl(UsingShadowDecl *D) { |
Richard Smith | fd8634a | 2013-10-23 02:17:46 +0000 | [diff] [blame] | 1611 | RedeclarableResult Redecl = VisitRedeclarable(D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1612 | VisitNamedDecl(D); |
Richard Smith | a263c34 | 2018-01-06 01:07:05 +0000 | [diff] [blame] | 1613 | D->Underlying = ReadDeclAs<NamedDecl>(); |
| 1614 | D->IdentifierNamespace = Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1615 | D->UsingOrNextShadow = ReadDeclAs<NamedDecl>(); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1616 | auto *Pattern = ReadDeclAs<UsingShadowDecl>(); |
Argyrios Kyrtzidis | 6685e8a | 2010-07-04 21:44:35 +0000 | [diff] [blame] | 1617 | if (Pattern) |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 1618 | Reader.getContext().setInstantiatedFromUsingShadowDecl(D, Pattern); |
Richard Smith | fd8634a | 2013-10-23 02:17:46 +0000 | [diff] [blame] | 1619 | mergeRedeclarable(D, Redecl); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1620 | } |
| 1621 | |
Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 1622 | void ASTDeclReader::VisitConstructorUsingShadowDecl( |
| 1623 | ConstructorUsingShadowDecl *D) { |
| 1624 | VisitUsingShadowDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1625 | D->NominatedBaseClassShadowDecl = ReadDeclAs<ConstructorUsingShadowDecl>(); |
| 1626 | D->ConstructedBaseClassShadowDecl = ReadDeclAs<ConstructorUsingShadowDecl>(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1627 | D->IsVirtual = Record.readInt(); |
Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 1628 | } |
| 1629 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1630 | void ASTDeclReader::VisitUsingDirectiveDecl(UsingDirectiveDecl *D) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1631 | VisitNamedDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1632 | D->UsingLoc = ReadSourceLocation(); |
| 1633 | D->NamespaceLoc = ReadSourceLocation(); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1634 | D->QualifierLoc = Record.readNestedNameSpecifierLoc(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1635 | D->NominatedNamespace = ReadDeclAs<NamedDecl>(); |
| 1636 | D->CommonAncestor = ReadDeclAs<DeclContext>(); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1637 | } |
| 1638 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1639 | void ASTDeclReader::VisitUnresolvedUsingValueDecl(UnresolvedUsingValueDecl *D) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1640 | VisitValueDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1641 | D->setUsingLoc(ReadSourceLocation()); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1642 | D->QualifierLoc = Record.readNestedNameSpecifierLoc(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1643 | ReadDeclarationNameLoc(D->DNLoc, D->getDeclName()); |
Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 1644 | D->EllipsisLoc = ReadSourceLocation(); |
Richard Smith | 32952e1 | 2014-10-14 02:00:47 +0000 | [diff] [blame] | 1645 | mergeMergeable(D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1646 | } |
| 1647 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1648 | void ASTDeclReader::VisitUnresolvedUsingTypenameDecl( |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1649 | UnresolvedUsingTypenameDecl *D) { |
| 1650 | VisitTypeDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1651 | D->TypenameLocation = ReadSourceLocation(); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1652 | D->QualifierLoc = Record.readNestedNameSpecifierLoc(); |
Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 1653 | D->EllipsisLoc = ReadSourceLocation(); |
Richard Smith | 32952e1 | 2014-10-14 02:00:47 +0000 | [diff] [blame] | 1654 | mergeMergeable(D); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1655 | } |
| 1656 | |
Argyrios Kyrtzidis | 8b200a5 | 2010-10-24 17:26:27 +0000 | [diff] [blame] | 1657 | void ASTDeclReader::ReadCXXDefinitionData( |
David Blaikie | 1ac9c98 | 2017-04-11 21:13:37 +0000 | [diff] [blame] | 1658 | struct CXXRecordDecl::DefinitionData &Data, const CXXRecordDecl *D) { |
Richard Smith | 91aeacc | 2019-10-11 00:29:04 +0000 | [diff] [blame] | 1659 | #define FIELD(Name, Width, Merge) \ |
| 1660 | Data.Name = Record.readInt(); |
| 1661 | #include "clang/AST/CXXRecordDeclDefinitionBits.def" |
| 1662 | |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 1663 | // Note: the caller has deserialized the IsLambda bit already. |
Richard Trieu | b6adf54 | 2017-02-18 02:09:28 +0000 | [diff] [blame] | 1664 | Data.ODRHash = Record.readInt(); |
Richard Trieu | fd1acbb | 2017-04-11 21:31:00 +0000 | [diff] [blame] | 1665 | Data.HasODRHash = true; |
Anders Carlsson | 703d6e6 | 2011-01-22 18:11:02 +0000 | [diff] [blame] | 1666 | |
Richard Smith | cd4a7a4 | 2017-09-07 00:55:55 +0000 | [diff] [blame] | 1667 | if (Record.readInt()) |
| 1668 | Reader.DefinitionSource[D] = Loc.F->Kind == ModuleKind::MK_MainFile; |
David Blaikie | 1ac9c98 | 2017-04-11 21:13:37 +0000 | [diff] [blame] | 1669 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1670 | Data.NumBases = Record.readInt(); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 1671 | if (Data.NumBases) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1672 | Data.Bases = ReadGlobalOffset(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1673 | Data.NumVBases = Record.readInt(); |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 1674 | if (Data.NumVBases) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1675 | Data.VBases = ReadGlobalOffset(); |
| 1676 | |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1677 | Record.readUnresolvedSet(Data.Conversions); |
Richard Smith | 91aeacc | 2019-10-11 00:29:04 +0000 | [diff] [blame] | 1678 | Data.ComputedVisibleConversions = Record.readInt(); |
| 1679 | if (Data.ComputedVisibleConversions) |
| 1680 | Record.readUnresolvedSet(Data.VisibleConversions); |
Argyrios Kyrtzidis | 8b200a5 | 2010-10-24 17:26:27 +0000 | [diff] [blame] | 1681 | assert(Data.Definition && "Data.Definition should be already set!"); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1682 | Data.FirstFriend = ReadDeclID(); |
Richard Smith | 9dd9f03 | 2013-08-30 00:23:29 +0000 | [diff] [blame] | 1683 | |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 1684 | if (Data.IsLambda) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1685 | using Capture = LambdaCapture; |
| 1686 | |
| 1687 | auto &Lambda = static_cast<CXXRecordDecl::LambdaDefinitionData &>(Data); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1688 | Lambda.Dependent = Record.readInt(); |
| 1689 | Lambda.IsGenericLambda = Record.readInt(); |
| 1690 | Lambda.CaptureDefault = Record.readInt(); |
| 1691 | Lambda.NumCaptures = Record.readInt(); |
| 1692 | Lambda.NumExplicitCaptures = Record.readInt(); |
| 1693 | Lambda.ManglingNumber = Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1694 | Lambda.ContextDecl = ReadDeclID(); |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 1695 | Lambda.Captures = (Capture *)Reader.getContext().Allocate( |
| 1696 | sizeof(Capture) * Lambda.NumCaptures); |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 1697 | Capture *ToCapture = Lambda.Captures; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1698 | Lambda.MethodTyInfo = GetTypeSourceInfo(); |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 1699 | for (unsigned I = 0, N = Lambda.NumCaptures; I != N; ++I) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1700 | SourceLocation Loc = ReadSourceLocation(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1701 | bool IsImplicit = Record.readInt(); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1702 | auto Kind = static_cast<LambdaCaptureKind>(Record.readInt()); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 1703 | switch (Kind) { |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 1704 | case LCK_StarThis: |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 1705 | case LCK_This: |
Alexey Bataev | 39c81e2 | 2014-08-28 04:28:19 +0000 | [diff] [blame] | 1706 | case LCK_VLAType: |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 1707 | *ToCapture++ = Capture(Loc, IsImplicit, Kind, nullptr,SourceLocation()); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 1708 | break; |
| 1709 | case LCK_ByCopy: |
Richard Smith | bb13c9a | 2013-09-28 04:02:39 +0000 | [diff] [blame] | 1710 | case LCK_ByRef: |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1711 | auto *Var = ReadDeclAs<VarDecl>(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1712 | SourceLocation EllipsisLoc = ReadSourceLocation(); |
Richard Smith | ba71c08 | 2013-05-16 06:20:58 +0000 | [diff] [blame] | 1713 | *ToCapture++ = Capture(Loc, IsImplicit, Kind, Var, EllipsisLoc); |
| 1714 | break; |
| 1715 | } |
Douglas Gregor | 99ae806 | 2012-02-14 17:54:36 +0000 | [diff] [blame] | 1716 | } |
| 1717 | } |
Argyrios Kyrtzidis | 8b200a5 | 2010-10-24 17:26:27 +0000 | [diff] [blame] | 1718 | } |
| 1719 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1720 | void ASTDeclReader::MergeDefinitionData( |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 1721 | CXXRecordDecl *D, struct CXXRecordDecl::DefinitionData &&MergeDD) { |
Richard Smith | b648399 | 2016-05-17 22:44:15 +0000 | [diff] [blame] | 1722 | assert(D->DefinitionData && |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 1723 | "merging class definition into non-definition"); |
Richard Smith | b648399 | 2016-05-17 22:44:15 +0000 | [diff] [blame] | 1724 | auto &DD = *D->DefinitionData; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1725 | |
Richard Smith | 0279375 | 2015-03-27 21:16:39 +0000 | [diff] [blame] | 1726 | if (DD.Definition != MergeDD.Definition) { |
Richard Smith | 97100e3 | 2015-06-20 00:22:34 +0000 | [diff] [blame] | 1727 | // Track that we merged the definitions. |
| 1728 | Reader.MergedDeclContexts.insert(std::make_pair(MergeDD.Definition, |
| 1729 | DD.Definition)); |
| 1730 | Reader.PendingDefinitions.erase(MergeDD.Definition); |
Erich Keane | f92f31c | 2018-08-01 20:48:16 +0000 | [diff] [blame] | 1731 | MergeDD.Definition->setCompleteDefinition(false); |
Richard Smith | 6561f92 | 2016-09-12 21:06:40 +0000 | [diff] [blame] | 1732 | Reader.mergeDefinitionVisibility(DD.Definition, MergeDD.Definition); |
Richard Smith | d88a7f1 | 2015-09-01 20:35:42 +0000 | [diff] [blame] | 1733 | assert(Reader.Lookups.find(MergeDD.Definition) == Reader.Lookups.end() && |
| 1734 | "already loaded pending lookups for merged definition"); |
Richard Smith | 0279375 | 2015-03-27 21:16:39 +0000 | [diff] [blame] | 1735 | } |
| 1736 | |
Richard Smith | 2a9e5c5 | 2015-02-03 03:32:14 +0000 | [diff] [blame] | 1737 | auto PFDI = Reader.PendingFakeDefinitionData.find(&DD); |
| 1738 | if (PFDI != Reader.PendingFakeDefinitionData.end() && |
| 1739 | PFDI->second == ASTReader::PendingFakeDefinitionKind::Fake) { |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 1740 | // We faked up this definition data because we found a class for which we'd |
| 1741 | // not yet loaded the definition. Replace it with the real thing now. |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 1742 | assert(!DD.IsLambda && !MergeDD.IsLambda && "faked up lambda definition?"); |
Richard Smith | 2a9e5c5 | 2015-02-03 03:32:14 +0000 | [diff] [blame] | 1743 | PFDI->second = ASTReader::PendingFakeDefinitionKind::FakeLoaded; |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 1744 | |
| 1745 | // Don't change which declaration is the definition; that is required |
| 1746 | // to be invariant once we select it. |
| 1747 | auto *Def = DD.Definition; |
| 1748 | DD = std::move(MergeDD); |
| 1749 | DD.Definition = Def; |
| 1750 | return; |
| 1751 | } |
| 1752 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1753 | bool DetectedOdrViolation = false; |
Richard Smith | 91aeacc | 2019-10-11 00:29:04 +0000 | [diff] [blame] | 1754 | |
| 1755 | #define FIELD(Name, Width, Merge) Merge(Name) |
| 1756 | #define MERGE_OR(Field) DD.Field |= MergeDD.Field; |
| 1757 | #define NO_MERGE(Field) \ |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1758 | DetectedOdrViolation |= DD.Field != MergeDD.Field; \ |
Richard Smith | 91aeacc | 2019-10-11 00:29:04 +0000 | [diff] [blame] | 1759 | MERGE_OR(Field) |
| 1760 | #include "clang/AST/CXXRecordDeclDefinitionBits.def" |
| 1761 | NO_MERGE(IsLambda) |
| 1762 | #undef NO_MERGE |
| 1763 | #undef MERGE_OR |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1764 | |
| 1765 | if (DD.NumBases != MergeDD.NumBases || DD.NumVBases != MergeDD.NumVBases) |
| 1766 | DetectedOdrViolation = true; |
| 1767 | // FIXME: Issue a diagnostic if the base classes don't match when we come |
| 1768 | // to lazily load them. |
| 1769 | |
| 1770 | // FIXME: Issue a diagnostic if the list of conversion functions doesn't |
| 1771 | // match when we come to lazily load them. |
| 1772 | if (MergeDD.ComputedVisibleConversions && !DD.ComputedVisibleConversions) { |
| 1773 | DD.VisibleConversions = std::move(MergeDD.VisibleConversions); |
| 1774 | DD.ComputedVisibleConversions = true; |
| 1775 | } |
| 1776 | |
| 1777 | // FIXME: Issue a diagnostic if FirstFriend doesn't match when we come to |
| 1778 | // lazily load it. |
| 1779 | |
| 1780 | if (DD.IsLambda) { |
| 1781 | // FIXME: ODR-checking for merging lambdas (this happens, for instance, |
| 1782 | // when they occur within the body of a function template specialization). |
| 1783 | } |
| 1784 | |
Richard Trieu | fd1acbb | 2017-04-11 21:31:00 +0000 | [diff] [blame] | 1785 | if (D->getODRHash() != MergeDD.ODRHash) { |
| 1786 | DetectedOdrViolation = true; |
| 1787 | } |
| 1788 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1789 | if (DetectedOdrViolation) |
Richard Trieu | e13eabe | 2017-09-30 02:19:17 +0000 | [diff] [blame] | 1790 | Reader.PendingOdrMergeFailures[DD.Definition].push_back( |
| 1791 | {MergeDD.Definition, &MergeDD}); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1792 | } |
| 1793 | |
Richard Smith | 2a9e5c5 | 2015-02-03 03:32:14 +0000 | [diff] [blame] | 1794 | void ASTDeclReader::ReadCXXRecordDefinition(CXXRecordDecl *D, bool Update) { |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1795 | struct CXXRecordDecl::DefinitionData *DD; |
| 1796 | ASTContext &C = Reader.getContext(); |
| 1797 | |
| 1798 | // Determine whether this is a lambda closure type, so that we can |
| 1799 | // allocate the appropriate DefinitionData structure. |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1800 | bool IsLambda = Record.readInt(); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1801 | if (IsLambda) |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 1802 | DD = new (C) CXXRecordDecl::LambdaDefinitionData(D, nullptr, false, false, |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1803 | LCD_None); |
| 1804 | else |
| 1805 | DD = new (C) struct CXXRecordDecl::DefinitionData(D); |
| 1806 | |
Volodymyr Sapsai | 8a5943f | 2018-03-21 21:28:54 +0000 | [diff] [blame] | 1807 | CXXRecordDecl *Canon = D->getCanonicalDecl(); |
| 1808 | // Set decl definition data before reading it, so that during deserialization |
| 1809 | // when we read CXXRecordDecl, it already has definition data and we don't |
| 1810 | // set fake one. |
| 1811 | if (!Canon->DefinitionData) |
| 1812 | Canon->DefinitionData = DD; |
| 1813 | D->DefinitionData = Canon->DefinitionData; |
David Blaikie | 1ac9c98 | 2017-04-11 21:13:37 +0000 | [diff] [blame] | 1814 | ReadCXXDefinitionData(*DD, D); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1815 | |
Volodymyr Sapsai | 8a5943f | 2018-03-21 21:28:54 +0000 | [diff] [blame] | 1816 | // We might already have a different definition for this record. This can |
| 1817 | // happen either because we're reading an update record, or because we've |
| 1818 | // already done some merging. Either way, just merge into it. |
| 1819 | if (Canon->DefinitionData != DD) { |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 1820 | MergeDefinitionData(Canon, std::move(*DD)); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1821 | return; |
| 1822 | } |
| 1823 | |
Richard Smith | 97100e3 | 2015-06-20 00:22:34 +0000 | [diff] [blame] | 1824 | // Mark this declaration as being a definition. |
Erich Keane | f92f31c | 2018-08-01 20:48:16 +0000 | [diff] [blame] | 1825 | D->setCompleteDefinition(true); |
Richard Smith | 2a9e5c5 | 2015-02-03 03:32:14 +0000 | [diff] [blame] | 1826 | |
Richard Smith | 97100e3 | 2015-06-20 00:22:34 +0000 | [diff] [blame] | 1827 | // If this is not the first declaration or is an update record, we can have |
| 1828 | // other redeclarations already. Make a note that we need to propagate the |
| 1829 | // DefinitionData pointer onto them. |
Volodymyr Sapsai | 8a5943f | 2018-03-21 21:28:54 +0000 | [diff] [blame] | 1830 | if (Update || Canon != D) |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1831 | Reader.PendingDefinitions.insert(D); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1832 | } |
| 1833 | |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 1834 | ASTDeclReader::RedeclarableResult |
| 1835 | ASTDeclReader::VisitCXXRecordDeclImpl(CXXRecordDecl *D) { |
| 1836 | RedeclarableResult Redecl = VisitRecordDeclImpl(D); |
Argyrios Kyrtzidis | a41f660 | 2010-10-20 00:11:15 +0000 | [diff] [blame] | 1837 | |
Douglas Gregor | 3a5ae56 | 2012-01-15 18:17:48 +0000 | [diff] [blame] | 1838 | ASTContext &C = Reader.getContext(); |
Argyrios Kyrtzidis | 2c2167a | 2010-07-02 11:55:32 +0000 | [diff] [blame] | 1839 | |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 1840 | enum CXXRecKind { |
| 1841 | CXXRecNotTemplate = 0, CXXRecTemplate, CXXRecMemberSpecialization |
| 1842 | }; |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1843 | switch ((CXXRecKind)Record.readInt()) { |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 1844 | case CXXRecNotTemplate: |
Richard Smith | dc5523d | 2014-07-11 00:20:06 +0000 | [diff] [blame] | 1845 | // Merged when we merge the folding set entry in the primary template. |
| 1846 | if (!isa<ClassTemplateSpecializationDecl>(D)) |
| 1847 | mergeRedeclarable(D, Redecl); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 1848 | break; |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 1849 | case CXXRecTemplate: { |
| 1850 | // Merged when we merge the template. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1851 | auto *Template = ReadDeclAs<ClassTemplateDecl>(); |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 1852 | D->TemplateOrInstantiation = Template; |
| 1853 | if (!Template->getTemplatedDecl()) { |
| 1854 | // We've not actually loaded the ClassTemplateDecl yet, because we're |
| 1855 | // currently being loaded as its pattern. Rely on it to set up our |
| 1856 | // TypeForDecl (see VisitClassTemplateDecl). |
| 1857 | // |
| 1858 | // Beware: we do not yet know our canonical declaration, and may still |
| 1859 | // get merged once the surrounding class template has got off the ground. |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 1860 | DeferredTypeID = 0; |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 1861 | } |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 1862 | break; |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 1863 | } |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 1864 | case CXXRecMemberSpecialization: { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1865 | auto *RD = ReadDeclAs<CXXRecordDecl>(); |
| 1866 | auto TSK = (TemplateSpecializationKind)Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1867 | SourceLocation POI = ReadSourceLocation(); |
Argyrios Kyrtzidis | caf8248 | 2010-09-13 11:45:25 +0000 | [diff] [blame] | 1868 | MemberSpecializationInfo *MSI = new (C) MemberSpecializationInfo(RD, TSK); |
| 1869 | MSI->setPointOfInstantiation(POI); |
| 1870 | D->TemplateOrInstantiation = MSI; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1871 | mergeRedeclarable(D, Redecl); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 1872 | break; |
| 1873 | } |
| 1874 | } |
Argyrios Kyrtzidis | 6843141 | 2010-10-14 20:14:38 +0000 | [diff] [blame] | 1875 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1876 | bool WasDefinition = Record.readInt(); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1877 | if (WasDefinition) |
Richard Smith | 2a9e5c5 | 2015-02-03 03:32:14 +0000 | [diff] [blame] | 1878 | ReadCXXRecordDefinition(D, /*Update*/false); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 1879 | else |
| 1880 | // Propagate DefinitionData pointer from the canonical declaration. |
| 1881 | D->DefinitionData = D->getCanonicalDecl()->DefinitionData; |
| 1882 | |
Richard Smith | 676c404 | 2013-08-29 23:59:27 +0000 | [diff] [blame] | 1883 | // 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] | 1884 | // compute it. |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 1885 | if (WasDefinition) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1886 | DeclID KeyFn = ReadDeclID(); |
Erich Keane | f92f31c | 2018-08-01 20:48:16 +0000 | [diff] [blame] | 1887 | if (KeyFn && D->isCompleteDefinition()) |
Richard Smith | a9a1c68 | 2014-07-07 06:38:20 +0000 | [diff] [blame] | 1888 | // FIXME: This is wrong for the ARM ABI, where some other module may have |
| 1889 | // made this function no longer be a key function. We need an update |
| 1890 | // record or similar for that case. |
Richard Smith | 676c404 | 2013-08-29 23:59:27 +0000 | [diff] [blame] | 1891 | C.KeyFunctions[D] = KeyFn; |
Argyrios Kyrtzidis | 6843141 | 2010-10-14 20:14:38 +0000 | [diff] [blame] | 1892 | } |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 1893 | |
| 1894 | return Redecl; |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1895 | } |
| 1896 | |
Richard Smith | bc49120 | 2017-02-17 20:05:37 +0000 | [diff] [blame] | 1897 | void ASTDeclReader::VisitCXXDeductionGuideDecl(CXXDeductionGuideDecl *D) { |
Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 1898 | D->setExplicitSpecifier(Record.readExplicitSpec()); |
Richard Smith | bc49120 | 2017-02-17 20:05:37 +0000 | [diff] [blame] | 1899 | VisitFunctionDecl(D); |
Erich Keane | 9c66506 | 2018-08-01 21:02:40 +0000 | [diff] [blame] | 1900 | D->setIsCopyDeductionCandidate(Record.readInt()); |
Richard Smith | bc49120 | 2017-02-17 20:05:37 +0000 | [diff] [blame] | 1901 | } |
| 1902 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1903 | void ASTDeclReader::VisitCXXMethodDecl(CXXMethodDecl *D) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1904 | VisitFunctionDecl(D); |
Richard Smith | b110873 | 2014-08-26 23:29:11 +0000 | [diff] [blame] | 1905 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1906 | unsigned NumOverridenMethods = Record.readInt(); |
Richard Smith | b110873 | 2014-08-26 23:29:11 +0000 | [diff] [blame] | 1907 | if (D->isCanonicalDecl()) { |
| 1908 | while (NumOverridenMethods--) { |
| 1909 | // Avoid invariant checking of CXXMethodDecl::addOverriddenMethod, |
| 1910 | // MD may be initializing. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1911 | if (auto *MD = ReadDeclAs<CXXMethodDecl>()) |
Richard Smith | b110873 | 2014-08-26 23:29:11 +0000 | [diff] [blame] | 1912 | Reader.getContext().addOverriddenMethod(D, MD->getCanonicalDecl()); |
| 1913 | } |
| 1914 | } else { |
| 1915 | // We don't care about which declarations this used to override; we get |
| 1916 | // the relevant information from the canonical declaration. |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1917 | Record.skipInts(NumOverridenMethods); |
Argyrios Kyrtzidis | 6685e8a | 2010-07-04 21:44:35 +0000 | [diff] [blame] | 1918 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1919 | } |
| 1920 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1921 | void ASTDeclReader::VisitCXXConstructorDecl(CXXConstructorDecl *D) { |
Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 1922 | // We need the inherited constructor information to merge the declaration, |
| 1923 | // so we have to read it before we call VisitCXXMethodDecl. |
Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 1924 | D->setExplicitSpecifier(Record.readExplicitSpec()); |
Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 1925 | if (D->isInheritingConstructor()) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1926 | auto *Shadow = ReadDeclAs<ConstructorUsingShadowDecl>(); |
| 1927 | auto *Ctor = ReadDeclAs<CXXConstructorDecl>(); |
Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 1928 | *D->getTrailingObjects<InheritedConstructor>() = |
| 1929 | InheritedConstructor(Shadow, Ctor); |
| 1930 | } |
| 1931 | |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1932 | VisitCXXMethodDecl(D); |
| 1933 | } |
| 1934 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1935 | void ASTDeclReader::VisitCXXDestructorDecl(CXXDestructorDecl *D) { |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1936 | VisitCXXMethodDecl(D); |
Argyrios Kyrtzidis | 3357516 | 2010-07-02 15:58:43 +0000 | [diff] [blame] | 1937 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1938 | if (auto *OperatorDelete = ReadDeclAs<FunctionDecl>()) { |
George Burgess IV | 00f70bd | 2018-03-01 05:43:23 +0000 | [diff] [blame] | 1939 | CXXDestructorDecl *Canon = D->getCanonicalDecl(); |
Richard Smith | 5b34958 | 2017-10-13 01:55:36 +0000 | [diff] [blame] | 1940 | auto *ThisArg = Record.readExpr(); |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 1941 | // FIXME: Check consistency if we have an old and new operator delete. |
Richard Smith | 5b34958 | 2017-10-13 01:55:36 +0000 | [diff] [blame] | 1942 | if (!Canon->OperatorDelete) { |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 1943 | Canon->OperatorDelete = OperatorDelete; |
Richard Smith | 5b34958 | 2017-10-13 01:55:36 +0000 | [diff] [blame] | 1944 | Canon->OperatorDeleteThisArg = ThisArg; |
| 1945 | } |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 1946 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1947 | } |
| 1948 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1949 | void ASTDeclReader::VisitCXXConversionDecl(CXXConversionDecl *D) { |
Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 1950 | D->setExplicitSpecifier(Record.readExplicitSpec()); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1951 | VisitCXXMethodDecl(D); |
| 1952 | } |
| 1953 | |
Douglas Gregor | ba34552 | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 1954 | void ASTDeclReader::VisitImportDecl(ImportDecl *D) { |
| 1955 | VisitDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1956 | D->ImportedAndComplete.setPointer(readModule()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1957 | D->ImportedAndComplete.setInt(Record.readInt()); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 1958 | auto *StoredLocs = D->getTrailingObjects<SourceLocation>(); |
Douglas Gregor | ba34552 | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 1959 | for (unsigned I = 0, N = Record.back(); I != N; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1960 | StoredLocs[I] = ReadSourceLocation(); |
David L. Jones | 267b884 | 2017-01-24 01:04:30 +0000 | [diff] [blame] | 1961 | Record.skipInts(1); // The number of stored source locations. |
Douglas Gregor | ba34552 | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 1962 | } |
| 1963 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1964 | void ASTDeclReader::VisitAccessSpecDecl(AccessSpecDecl *D) { |
Abramo Bagnara | d734058 | 2010-06-05 05:09:32 +0000 | [diff] [blame] | 1965 | VisitDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1966 | D->setColonLoc(ReadSourceLocation()); |
Abramo Bagnara | d734058 | 2010-06-05 05:09:32 +0000 | [diff] [blame] | 1967 | } |
| 1968 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1969 | void ASTDeclReader::VisitFriendDecl(FriendDecl *D) { |
Argyrios Kyrtzidis | a95d019 | 2010-07-05 10:38:01 +0000 | [diff] [blame] | 1970 | VisitDecl(D); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1971 | if (Record.readInt()) // hasFriendDecl |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1972 | D->Friend = ReadDeclAs<NamedDecl>(); |
Enea Zaffanella | eb22c87 | 2013-01-31 09:54:08 +0000 | [diff] [blame] | 1973 | else |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1974 | D->Friend = GetTypeSourceInfo(); |
Enea Zaffanella | eb22c87 | 2013-01-31 09:54:08 +0000 | [diff] [blame] | 1975 | for (unsigned i = 0; i != D->NumTPLists; ++i) |
James Y Knight | 967eb20 | 2015-12-29 22:13:13 +0000 | [diff] [blame] | 1976 | D->getTrailingObjects<TemplateParameterList *>()[i] = |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1977 | Record.readTemplateParameterList(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1978 | D->NextFriend = ReadDeclID(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1979 | D->UnsupportedFriend = (Record.readInt() != 0); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1980 | D->FriendLoc = ReadSourceLocation(); |
Argyrios Kyrtzidis | 74d28bd | 2010-06-29 22:47:00 +0000 | [diff] [blame] | 1981 | } |
| 1982 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 1983 | void ASTDeclReader::VisitFriendTemplateDecl(FriendTemplateDecl *D) { |
Argyrios Kyrtzidis | 165b581 | 2010-07-22 16:04:10 +0000 | [diff] [blame] | 1984 | VisitDecl(D); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1985 | unsigned NumParams = Record.readInt(); |
Argyrios Kyrtzidis | 165b581 | 2010-07-22 16:04:10 +0000 | [diff] [blame] | 1986 | D->NumParams = NumParams; |
| 1987 | D->Params = new TemplateParameterList*[NumParams]; |
| 1988 | for (unsigned i = 0; i != NumParams; ++i) |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 1989 | D->Params[i] = Record.readTemplateParameterList(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 1990 | if (Record.readInt()) // HasFriendDecl |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1991 | D->Friend = ReadDeclAs<NamedDecl>(); |
Argyrios Kyrtzidis | 165b581 | 2010-07-22 16:04:10 +0000 | [diff] [blame] | 1992 | else |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 1993 | D->Friend = GetTypeSourceInfo(); |
| 1994 | D->FriendLoc = ReadSourceLocation(); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 1995 | } |
| 1996 | |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 1997 | DeclID ASTDeclReader::VisitTemplateDecl(TemplateDecl *D) { |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 1998 | VisitNamedDecl(D); |
| 1999 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2000 | DeclID PatternID = ReadDeclID(); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2001 | auto *TemplatedDecl = cast_or_null<NamedDecl>(Reader.GetDecl(PatternID)); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2002 | TemplateParameterList *TemplateParams = Record.readTemplateParameterList(); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 2003 | D->init(TemplatedDecl, TemplateParams); |
Richard Smith | bf78e64 | 2013-06-24 22:51:00 +0000 | [diff] [blame] | 2004 | |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2005 | return PatternID; |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 2006 | } |
| 2007 | |
Saar Raz | d7aae33 | 2019-07-10 21:25:49 +0000 | [diff] [blame] | 2008 | void ASTDeclReader::VisitConceptDecl(ConceptDecl *D) { |
| 2009 | VisitTemplateDecl(D); |
| 2010 | D->ConstraintExpr = Record.readExpr(); |
| 2011 | mergeMergeable(D); |
| 2012 | } |
| 2013 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2014 | ASTDeclReader::RedeclarableResult |
Douglas Gregor | 5407920 | 2012-01-06 22:05:37 +0000 | [diff] [blame] | 2015 | ASTDeclReader::VisitRedeclarableTemplateDecl(RedeclarableTemplateDecl *D) { |
Douglas Gregor | 68444de | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 2016 | RedeclarableResult Redecl = VisitRedeclarable(D); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 2017 | |
Douglas Gregor | 68444de | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 2018 | // Make sure we've allocated the Common pointer first. We do this before |
| 2019 | // VisitTemplateDecl so that getCommonPtr() can be used during initialization. |
| 2020 | RedeclarableTemplateDecl *CanonD = D->getCanonicalDecl(); |
| 2021 | if (!CanonD->Common) { |
| 2022 | CanonD->Common = CanonD->newCommon(Reader.getContext()); |
| 2023 | Reader.PendingDefinitions.insert(CanonD); |
| 2024 | } |
| 2025 | D->Common = CanonD->Common; |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 2026 | |
Douglas Gregor | 68444de | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 2027 | // If this is the first declaration of the template, fill in the information |
| 2028 | // for the 'common' pointer. |
| 2029 | if (ThisDeclID == Redecl.getFirstID()) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2030 | if (auto *RTD = ReadDeclAs<RedeclarableTemplateDecl>()) { |
Peter Collingbourne | 91b25b7 | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 2031 | assert(RTD->getKind() == D->getKind() && |
| 2032 | "InstantiatedFromMemberTemplate kind mismatch"); |
Douglas Gregor | 68444de | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 2033 | D->setInstantiatedFromMemberTemplate(RTD); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2034 | if (Record.readInt()) |
Peter Collingbourne | 91b25b7 | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 2035 | D->setMemberSpecialization(); |
| 2036 | } |
| 2037 | } |
Axel Naumann | 866ba3e | 2012-10-01 09:18:00 +0000 | [diff] [blame] | 2038 | |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2039 | DeclID PatternID = VisitTemplateDecl(D); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2040 | D->IdentifierNamespace = Record.readInt(); |
Axel Naumann | 866ba3e | 2012-10-01 09:18:00 +0000 | [diff] [blame] | 2041 | |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2042 | mergeRedeclarable(D, Redecl, PatternID); |
Axel Naumann | 866ba3e | 2012-10-01 09:18:00 +0000 | [diff] [blame] | 2043 | |
Richard Smith | d46d6de | 2013-10-13 23:50:45 +0000 | [diff] [blame] | 2044 | // If we merged the template with a prior declaration chain, merge the common |
| 2045 | // pointer. |
| 2046 | // FIXME: Actually merge here, don't just overwrite. |
| 2047 | D->Common = D->getCanonicalDecl()->Common; |
| 2048 | |
Douglas Gregor | 68444de | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 2049 | return Redecl; |
Peter Collingbourne | 91b25b7 | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 2050 | } |
| 2051 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 2052 | void ASTDeclReader::VisitClassTemplateDecl(ClassTemplateDecl *D) { |
Douglas Gregor | 68444de | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 2053 | RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D); |
Peter Collingbourne | 91b25b7 | 2010-07-29 16:11:51 +0000 | [diff] [blame] | 2054 | |
Douglas Gregor | 68444de | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 2055 | if (ThisDeclID == Redecl.getFirstID()) { |
Douglas Gregor | 7e8c4e0 | 2010-10-27 22:21:36 +0000 | [diff] [blame] | 2056 | // This ClassTemplateDecl owns a CommonPtr; read it to keep track of all of |
| 2057 | // the specializations. |
Richard Smith | 0b88437 | 2015-02-27 00:25:58 +0000 | [diff] [blame] | 2058 | SmallVector<serialization::DeclID, 32> SpecIDs; |
Richard Smith | 0b88437 | 2015-02-27 00:25:58 +0000 | [diff] [blame] | 2059 | ReadDeclIDList(SpecIDs); |
Vassil Vassilev | 7d26462 | 2017-06-30 22:40:17 +0000 | [diff] [blame] | 2060 | ASTDeclReader::AddLazySpecializations(D, SpecIDs); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 2061 | } |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2062 | |
| 2063 | if (D->getTemplatedDecl()->TemplateOrInstantiation) { |
| 2064 | // We were loaded before our templated declaration was. We've not set up |
| 2065 | // its corresponding type yet (see VisitCXXRecordDeclImpl), so reconstruct |
| 2066 | // it now. |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 2067 | Reader.getContext().getInjectedClassNameType( |
Richard Smith | a1406fa | 2014-05-23 21:31:59 +0000 | [diff] [blame] | 2068 | D->getTemplatedDecl(), D->getInjectedClassNameSpecialization()); |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2069 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 2070 | } |
| 2071 | |
David Majnemer | d9b1a4f | 2015-11-04 03:40:30 +0000 | [diff] [blame] | 2072 | void ASTDeclReader::VisitBuiltinTemplateDecl(BuiltinTemplateDecl *D) { |
| 2073 | llvm_unreachable("BuiltinTemplates are not serialized"); |
| 2074 | } |
| 2075 | |
Larisse Voufo | 3061638 | 2013-08-23 22:21:36 +0000 | [diff] [blame] | 2076 | /// TODO: Unify with ClassTemplateDecl version? |
| 2077 | /// May require unifying ClassTemplateDecl and |
| 2078 | /// VarTemplateDecl beyond TemplateDecl... |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2079 | void ASTDeclReader::VisitVarTemplateDecl(VarTemplateDecl *D) { |
| 2080 | RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D); |
| 2081 | |
| 2082 | if (ThisDeclID == Redecl.getFirstID()) { |
Larisse Voufo | d8dd97c | 2013-08-14 03:09:19 +0000 | [diff] [blame] | 2083 | // 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] | 2084 | // the specializations. |
Richard Smith | 0b88437 | 2015-02-27 00:25:58 +0000 | [diff] [blame] | 2085 | SmallVector<serialization::DeclID, 32> SpecIDs; |
Richard Smith | 0b88437 | 2015-02-27 00:25:58 +0000 | [diff] [blame] | 2086 | ReadDeclIDList(SpecIDs); |
Vassil Vassilev | 7d26462 | 2017-06-30 22:40:17 +0000 | [diff] [blame] | 2087 | ASTDeclReader::AddLazySpecializations(D, SpecIDs); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2088 | } |
| 2089 | } |
| 2090 | |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 2091 | ASTDeclReader::RedeclarableResult |
| 2092 | ASTDeclReader::VisitClassTemplateSpecializationDeclImpl( |
| 2093 | ClassTemplateSpecializationDecl *D) { |
| 2094 | RedeclarableResult Redecl = VisitCXXRecordDeclImpl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2095 | |
Douglas Gregor | 4163aca | 2011-09-09 21:34:22 +0000 | [diff] [blame] | 2096 | ASTContext &C = Reader.getContext(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2097 | if (Decl *InstD = ReadDecl()) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2098 | if (auto *CTD = dyn_cast<ClassTemplateDecl>(InstD)) { |
Argyrios Kyrtzidis | b4c659b | 2010-09-13 11:45:32 +0000 | [diff] [blame] | 2099 | D->SpecializedTemplate = CTD; |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 2100 | } else { |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2101 | SmallVector<TemplateArgument, 8> TemplArgs; |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2102 | Record.readTemplateArgumentList(TemplArgs); |
Argyrios Kyrtzidis | b4c659b | 2010-09-13 11:45:32 +0000 | [diff] [blame] | 2103 | TemplateArgumentList *ArgList |
David Majnemer | 8b62269 | 2016-07-03 21:17:51 +0000 | [diff] [blame] | 2104 | = TemplateArgumentList::CreateCopy(C, TemplArgs); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2105 | auto *PS = |
| 2106 | new (C) ClassTemplateSpecializationDecl:: |
Argyrios Kyrtzidis | b4c659b | 2010-09-13 11:45:32 +0000 | [diff] [blame] | 2107 | SpecializedPartialSpecialization(); |
| 2108 | PS->PartialSpecialization |
| 2109 | = cast<ClassTemplatePartialSpecializationDecl>(InstD); |
| 2110 | PS->TemplateArgs = ArgList; |
| 2111 | D->SpecializedTemplate = PS; |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 2112 | } |
| 2113 | } |
| 2114 | |
Chris Lattner | 0e62c1c | 2011-07-23 10:55:15 +0000 | [diff] [blame] | 2115 | SmallVector<TemplateArgument, 8> TemplArgs; |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2116 | Record.readTemplateArgumentList(TemplArgs, /*Canonicalize*/ true); |
David Majnemer | 8b62269 | 2016-07-03 21:17:51 +0000 | [diff] [blame] | 2117 | D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2118 | D->PointOfInstantiation = ReadSourceLocation(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2119 | D->SpecializationKind = (TemplateSpecializationKind)Record.readInt(); |
Axel Naumann | a31dee2 | 2012-10-01 07:34:47 +0000 | [diff] [blame] | 2120 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2121 | bool writtenAsCanonicalDecl = Record.readInt(); |
Axel Naumann | a31dee2 | 2012-10-01 07:34:47 +0000 | [diff] [blame] | 2122 | if (writtenAsCanonicalDecl) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2123 | auto *CanonPattern = ReadDeclAs<ClassTemplateDecl>(); |
Axel Naumann | a31dee2 | 2012-10-01 07:34:47 +0000 | [diff] [blame] | 2124 | if (D->isCanonicalDecl()) { // It's kept in the folding set. |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2125 | // Set this as, or find, the canonical declaration for this specialization |
| 2126 | ClassTemplateSpecializationDecl *CanonSpec; |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2127 | if (auto *Partial = dyn_cast<ClassTemplatePartialSpecializationDecl>(D)) { |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2128 | CanonSpec = CanonPattern->getCommonPtr()->PartialSpecializations |
Richard Smith | 5de91b5 | 2013-06-25 01:25:15 +0000 | [diff] [blame] | 2129 | .GetOrInsertNode(Partial); |
Axel Naumann | a31dee2 | 2012-10-01 07:34:47 +0000 | [diff] [blame] | 2130 | } else { |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2131 | CanonSpec = |
| 2132 | CanonPattern->getCommonPtr()->Specializations.GetOrInsertNode(D); |
| 2133 | } |
| 2134 | // If there was already a canonical specialization, merge into it. |
| 2135 | if (CanonSpec != D) { |
| 2136 | mergeRedeclarable<TagDecl>(D, CanonSpec, Redecl); |
| 2137 | |
| 2138 | // This declaration might be a definition. Merge with any existing |
| 2139 | // definition. |
Richard Smith | b648399 | 2016-05-17 22:44:15 +0000 | [diff] [blame] | 2140 | if (auto *DDD = D->DefinitionData) { |
| 2141 | if (CanonSpec->DefinitionData) |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 2142 | MergeDefinitionData(CanonSpec, std::move(*DDD)); |
Richard Smith | 97100e3 | 2015-06-20 00:22:34 +0000 | [diff] [blame] | 2143 | else |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 2144 | CanonSpec->DefinitionData = D->DefinitionData; |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2145 | } |
Richard Smith | 547864d | 2014-07-11 18:22:58 +0000 | [diff] [blame] | 2146 | D->DefinitionData = CanonSpec->DefinitionData; |
Axel Naumann | a31dee2 | 2012-10-01 07:34:47 +0000 | [diff] [blame] | 2147 | } |
Argyrios Kyrtzidis | 8704057 | 2010-07-09 21:11:43 +0000 | [diff] [blame] | 2148 | } |
| 2149 | } |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 2150 | |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2151 | // Explicit info. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2152 | if (TypeSourceInfo *TyInfo = GetTypeSourceInfo()) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2153 | auto *ExplicitInfo = |
| 2154 | new (C) ClassTemplateSpecializationDecl::ExplicitSpecializationInfo; |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2155 | ExplicitInfo->TypeAsWritten = TyInfo; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2156 | ExplicitInfo->ExternLoc = ReadSourceLocation(); |
| 2157 | ExplicitInfo->TemplateKeywordLoc = ReadSourceLocation(); |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2158 | D->ExplicitInfo = ExplicitInfo; |
| 2159 | } |
| 2160 | |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 2161 | return Redecl; |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 2162 | } |
| 2163 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 2164 | void ASTDeclReader::VisitClassTemplatePartialSpecializationDecl( |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 2165 | ClassTemplatePartialSpecializationDecl *D) { |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 2166 | RedeclarableResult Redecl = VisitClassTemplateSpecializationDeclImpl(D); |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 2167 | |
Saar Raz | 0330fba | 2019-10-15 18:44:06 +0000 | [diff] [blame^] | 2168 | TemplateParameterList *Params = Record.readTemplateParameterList(); |
| 2169 | D->TemplateParams = Params; |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2170 | D->ArgsAsWritten = Record.readASTTemplateArgumentListInfo(); |
Argyrios Kyrtzidis | 0e8b3ce | 2010-09-13 11:45:41 +0000 | [diff] [blame] | 2171 | |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 2172 | // These are read/set from/to the first declaration. |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 2173 | if (ThisDeclID == Redecl.getFirstID()) { |
Argyrios Kyrtzidis | 0e8b3ce | 2010-09-13 11:45:41 +0000 | [diff] [blame] | 2174 | D->InstantiatedFromMember.setPointer( |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2175 | ReadDeclAs<ClassTemplatePartialSpecializationDecl>()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2176 | D->InstantiatedFromMember.setInt(Record.readInt()); |
Argyrios Kyrtzidis | 818c5db | 2010-06-23 13:48:30 +0000 | [diff] [blame] | 2177 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 2178 | } |
| 2179 | |
Sebastian Redl | b744863 | 2011-08-31 13:59:56 +0000 | [diff] [blame] | 2180 | void ASTDeclReader::VisitClassScopeFunctionSpecializationDecl( |
| 2181 | ClassScopeFunctionSpecializationDecl *D) { |
Francois Pichet | 09af8c3 | 2011-08-17 01:06:54 +0000 | [diff] [blame] | 2182 | VisitDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2183 | D->Specialization = ReadDeclAs<CXXMethodDecl>(); |
Richard Smith | f19a8b0 | 2019-05-02 00:49:14 +0000 | [diff] [blame] | 2184 | if (Record.readInt()) |
| 2185 | D->TemplateArgs = Record.readASTTemplateArgumentListInfo(); |
Francois Pichet | 09af8c3 | 2011-08-17 01:06:54 +0000 | [diff] [blame] | 2186 | } |
| 2187 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 2188 | void ASTDeclReader::VisitFunctionTemplateDecl(FunctionTemplateDecl *D) { |
Douglas Gregor | 68444de | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 2189 | RedeclarableResult Redecl = VisitRedeclarableTemplateDecl(D); |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 2190 | |
Douglas Gregor | 68444de | 2012-01-14 15:13:49 +0000 | [diff] [blame] | 2191 | if (ThisDeclID == Redecl.getFirstID()) { |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 2192 | // This FunctionTemplateDecl owns a CommonPtr; read it. |
Richard Smith | 0b88437 | 2015-02-27 00:25:58 +0000 | [diff] [blame] | 2193 | SmallVector<serialization::DeclID, 32> SpecIDs; |
| 2194 | ReadDeclIDList(SpecIDs); |
Vassil Vassilev | 7d26462 | 2017-06-30 22:40:17 +0000 | [diff] [blame] | 2195 | ASTDeclReader::AddLazySpecializations(D, SpecIDs); |
Argyrios Kyrtzidis | 69da4a8 | 2010-06-22 09:55:07 +0000 | [diff] [blame] | 2196 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 2197 | } |
| 2198 | |
Larisse Voufo | 3061638 | 2013-08-23 22:21:36 +0000 | [diff] [blame] | 2199 | /// TODO: Unify with ClassTemplateSpecializationDecl version? |
| 2200 | /// May require unifying ClassTemplate(Partial)SpecializationDecl and |
| 2201 | /// VarTemplate(Partial)SpecializationDecl with a new data |
| 2202 | /// structure Template(Partial)SpecializationDecl, and |
| 2203 | /// using Template(Partial)SpecializationDecl as input type. |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2204 | ASTDeclReader::RedeclarableResult |
| 2205 | ASTDeclReader::VisitVarTemplateSpecializationDeclImpl( |
| 2206 | VarTemplateSpecializationDecl *D) { |
| 2207 | RedeclarableResult Redecl = VisitVarDeclImpl(D); |
| 2208 | |
| 2209 | ASTContext &C = Reader.getContext(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2210 | if (Decl *InstD = ReadDecl()) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2211 | if (auto *VTD = dyn_cast<VarTemplateDecl>(InstD)) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2212 | D->SpecializedTemplate = VTD; |
| 2213 | } else { |
| 2214 | SmallVector<TemplateArgument, 8> TemplArgs; |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2215 | Record.readTemplateArgumentList(TemplArgs); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2216 | TemplateArgumentList *ArgList = TemplateArgumentList::CreateCopy( |
David Majnemer | 8b62269 | 2016-07-03 21:17:51 +0000 | [diff] [blame] | 2217 | C, TemplArgs); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2218 | auto *PS = |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2219 | new (C) |
| 2220 | VarTemplateSpecializationDecl::SpecializedPartialSpecialization(); |
| 2221 | PS->PartialSpecialization = |
| 2222 | cast<VarTemplatePartialSpecializationDecl>(InstD); |
| 2223 | PS->TemplateArgs = ArgList; |
| 2224 | D->SpecializedTemplate = PS; |
| 2225 | } |
| 2226 | } |
| 2227 | |
| 2228 | // Explicit info. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2229 | if (TypeSourceInfo *TyInfo = GetTypeSourceInfo()) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2230 | auto *ExplicitInfo = |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2231 | new (C) VarTemplateSpecializationDecl::ExplicitSpecializationInfo; |
| 2232 | ExplicitInfo->TypeAsWritten = TyInfo; |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2233 | ExplicitInfo->ExternLoc = ReadSourceLocation(); |
| 2234 | ExplicitInfo->TemplateKeywordLoc = ReadSourceLocation(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2235 | D->ExplicitInfo = ExplicitInfo; |
| 2236 | } |
| 2237 | |
| 2238 | SmallVector<TemplateArgument, 8> TemplArgs; |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2239 | Record.readTemplateArgumentList(TemplArgs, /*Canonicalize*/ true); |
David Majnemer | 8b62269 | 2016-07-03 21:17:51 +0000 | [diff] [blame] | 2240 | D->TemplateArgs = TemplateArgumentList::CreateCopy(C, TemplArgs); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2241 | D->PointOfInstantiation = ReadSourceLocation(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2242 | D->SpecializationKind = (TemplateSpecializationKind)Record.readInt(); |
Richard Smith | 435e647 | 2017-12-02 02:48:42 +0000 | [diff] [blame] | 2243 | D->IsCompleteDefinition = Record.readInt(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2244 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2245 | bool writtenAsCanonicalDecl = Record.readInt(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2246 | if (writtenAsCanonicalDecl) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2247 | auto *CanonPattern = ReadDeclAs<VarTemplateDecl>(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2248 | if (D->isCanonicalDecl()) { // It's kept in the folding set. |
Richard Smith | 9b88a4c | 2015-07-27 05:40:23 +0000 | [diff] [blame] | 2249 | // FIXME: If it's already present, merge it. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2250 | if (auto *Partial = dyn_cast<VarTemplatePartialSpecializationDecl>(D)) { |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2251 | CanonPattern->getCommonPtr()->PartialSpecializations |
| 2252 | .GetOrInsertNode(Partial); |
| 2253 | } else { |
| 2254 | CanonPattern->getCommonPtr()->Specializations.GetOrInsertNode(D); |
| 2255 | } |
| 2256 | } |
| 2257 | } |
| 2258 | |
| 2259 | return Redecl; |
| 2260 | } |
| 2261 | |
Larisse Voufo | 3061638 | 2013-08-23 22:21:36 +0000 | [diff] [blame] | 2262 | /// TODO: Unify with ClassTemplatePartialSpecializationDecl version? |
| 2263 | /// May require unifying ClassTemplate(Partial)SpecializationDecl and |
| 2264 | /// VarTemplate(Partial)SpecializationDecl with a new data |
| 2265 | /// structure Template(Partial)SpecializationDecl, and |
| 2266 | /// using Template(Partial)SpecializationDecl as input type. |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2267 | void ASTDeclReader::VisitVarTemplatePartialSpecializationDecl( |
| 2268 | VarTemplatePartialSpecializationDecl *D) { |
| 2269 | RedeclarableResult Redecl = VisitVarTemplateSpecializationDeclImpl(D); |
| 2270 | |
Saar Raz | 0330fba | 2019-10-15 18:44:06 +0000 | [diff] [blame^] | 2271 | TemplateParameterList *Params = Record.readTemplateParameterList(); |
| 2272 | D->TemplateParams = Params; |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2273 | D->ArgsAsWritten = Record.readASTTemplateArgumentListInfo(); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2274 | |
| 2275 | // These are read/set from/to the first declaration. |
| 2276 | if (ThisDeclID == Redecl.getFirstID()) { |
| 2277 | D->InstantiatedFromMember.setPointer( |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2278 | ReadDeclAs<VarTemplatePartialSpecializationDecl>()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2279 | D->InstantiatedFromMember.setInt(Record.readInt()); |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 2280 | } |
| 2281 | } |
| 2282 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 2283 | void ASTDeclReader::VisitTemplateTypeParmDecl(TemplateTypeParmDecl *D) { |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 2284 | VisitTypeDecl(D); |
| 2285 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2286 | D->setDeclaredWithTypename(Record.readInt()); |
Argyrios Kyrtzidis | 95c04ca | 2010-06-19 19:29:09 +0000 | [diff] [blame] | 2287 | |
Saar Raz | 0330fba | 2019-10-15 18:44:06 +0000 | [diff] [blame^] | 2288 | // TODO: Concepts: Immediately introduced constraint |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2289 | if (Record.readInt()) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2290 | D->setDefaultArgument(GetTypeSourceInfo()); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 2291 | } |
| 2292 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 2293 | void ASTDeclReader::VisitNonTypeTemplateParmDecl(NonTypeTemplateParmDecl *D) { |
John McCall | f4cd4f9 | 2011-02-09 01:13:10 +0000 | [diff] [blame] | 2294 | VisitDeclaratorDecl(D); |
Argyrios Kyrtzidis | b1d38e3 | 2010-06-25 16:25:09 +0000 | [diff] [blame] | 2295 | // TemplateParmPosition. |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2296 | D->setDepth(Record.readInt()); |
| 2297 | D->setPosition(Record.readInt()); |
Douglas Gregor | 0231d8d | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 2298 | if (D->isExpandedParameterPack()) { |
James Y Knight | 967eb20 | 2015-12-29 22:13:13 +0000 | [diff] [blame] | 2299 | auto TypesAndInfos = |
| 2300 | D->getTrailingObjects<std::pair<QualType, TypeSourceInfo *>>(); |
Douglas Gregor | 0231d8d | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 2301 | for (unsigned I = 0, N = D->getNumExpansionTypes(); I != N; ++I) { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2302 | new (&TypesAndInfos[I].first) QualType(Record.readType()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2303 | TypesAndInfos[I].second = GetTypeSourceInfo(); |
Douglas Gregor | 0231d8d | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 2304 | } |
| 2305 | } else { |
| 2306 | // Rest of NonTypeTemplateParmDecl. |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2307 | D->ParameterPack = Record.readInt(); |
| 2308 | if (Record.readInt()) |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2309 | D->setDefaultArgument(Record.readExpr()); |
Douglas Gregor | 0231d8d | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 2310 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 2311 | } |
| 2312 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 2313 | void ASTDeclReader::VisitTemplateTemplateParmDecl(TemplateTemplateParmDecl *D) { |
Argyrios Kyrtzidis | 9f2d24a | 2010-07-08 17:12:57 +0000 | [diff] [blame] | 2314 | VisitTemplateDecl(D); |
| 2315 | // TemplateParmPosition. |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2316 | D->setDepth(Record.readInt()); |
| 2317 | D->setPosition(Record.readInt()); |
Richard Smith | 1fde8ec | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 2318 | if (D->isExpandedParameterPack()) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2319 | auto **Data = D->getTrailingObjects<TemplateParameterList *>(); |
Richard Smith | 1fde8ec | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 2320 | for (unsigned I = 0, N = D->getNumExpansionTemplateParameters(); |
| 2321 | I != N; ++I) |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2322 | Data[I] = Record.readTemplateParameterList(); |
Richard Smith | 1fde8ec | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 2323 | } else { |
| 2324 | // Rest of TemplateTemplateParmDecl. |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2325 | D->ParameterPack = Record.readInt(); |
| 2326 | if (Record.readInt()) |
Richard Smith | 1469b91 | 2015-06-10 00:29:03 +0000 | [diff] [blame] | 2327 | D->setDefaultArgument(Reader.getContext(), |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2328 | Record.readTemplateArgumentLoc()); |
Richard Smith | 1fde8ec | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 2329 | } |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 2330 | } |
| 2331 | |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 2332 | void ASTDeclReader::VisitTypeAliasTemplateDecl(TypeAliasTemplateDecl *D) { |
| 2333 | VisitRedeclarableTemplateDecl(D); |
| 2334 | } |
| 2335 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 2336 | void ASTDeclReader::VisitStaticAssertDecl(StaticAssertDecl *D) { |
Argyrios Kyrtzidis | 2d8891c | 2010-07-22 17:28:12 +0000 | [diff] [blame] | 2337 | VisitDecl(D); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2338 | D->AssertExprAndFailed.setPointer(Record.readExpr()); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2339 | D->AssertExprAndFailed.setInt(Record.readInt()); |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2340 | D->Message = cast_or_null<StringLiteral>(Record.readExpr()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2341 | D->RParenLoc = ReadSourceLocation(); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 2342 | } |
| 2343 | |
Michael Han | 8432435 | 2013-02-22 17:15:32 +0000 | [diff] [blame] | 2344 | void ASTDeclReader::VisitEmptyDecl(EmptyDecl *D) { |
| 2345 | VisitDecl(D); |
| 2346 | } |
| 2347 | |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2348 | std::pair<uint64_t, uint64_t> |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 2349 | ASTDeclReader::VisitDeclContext(DeclContext *DC) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2350 | uint64_t LexicalOffset = ReadLocalOffset(); |
| 2351 | uint64_t VisibleOffset = ReadLocalOffset(); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 2352 | return std::make_pair(LexicalOffset, VisibleOffset); |
| 2353 | } |
| 2354 | |
Argyrios Kyrtzidis | 839bbac | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 2355 | template <typename T> |
Richard Smith | 5a4737c | 2015-02-06 02:42:59 +0000 | [diff] [blame] | 2356 | ASTDeclReader::RedeclarableResult |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 2357 | ASTDeclReader::VisitRedeclarable(Redeclarable<T> *D) { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2358 | DeclID FirstDeclID = ReadDeclID(); |
Richard Smith | 5a4737c | 2015-02-06 02:42:59 +0000 | [diff] [blame] | 2359 | Decl *MergeWith = nullptr; |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 2360 | |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 2361 | bool IsKeyDecl = ThisDeclID == FirstDeclID; |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 2362 | bool IsFirstLocalDecl = false; |
Richard Smith | 5a4737c | 2015-02-06 02:42:59 +0000 | [diff] [blame] | 2363 | |
Richard Smith | d61d4ac | 2015-08-22 20:13:39 +0000 | [diff] [blame] | 2364 | uint64_t RedeclOffset = 0; |
| 2365 | |
Douglas Gregor | 358cd44 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 2366 | // 0 indicates that this declaration was the only declaration of its entity, |
| 2367 | // and is used for space optimization. |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 2368 | if (FirstDeclID == 0) { |
Douglas Gregor | 074a409 | 2011-12-19 18:19:24 +0000 | [diff] [blame] | 2369 | FirstDeclID = ThisDeclID; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 2370 | IsKeyDecl = true; |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 2371 | IsFirstLocalDecl = true; |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 2372 | } else if (unsigned N = Record.readInt()) { |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 2373 | // This declaration was the first local declaration, but may have imported |
| 2374 | // other declarations. |
| 2375 | IsKeyDecl = N == 1; |
| 2376 | IsFirstLocalDecl = true; |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 2377 | |
Richard Smith | fe620d2 | 2015-03-05 23:24:12 +0000 | [diff] [blame] | 2378 | // We have some declarations that must be before us in our redeclaration |
| 2379 | // chain. Read them now, and remember that we ought to merge with one of |
| 2380 | // them. |
| 2381 | // FIXME: Provide a known merge target to the second and subsequent such |
| 2382 | // declaration. |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 2383 | for (unsigned I = 0; I != N - 1; ++I) |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2384 | MergeWith = ReadDecl(); |
Richard Smith | d61d4ac | 2015-08-22 20:13:39 +0000 | [diff] [blame] | 2385 | |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2386 | RedeclOffset = ReadLocalOffset(); |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 2387 | } else { |
| 2388 | // This declaration was not the first local declaration. Read the first |
| 2389 | // local declaration now, to trigger the import of other redeclarations. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2390 | (void)ReadDecl(); |
Richard Smith | 5a4737c | 2015-02-06 02:42:59 +0000 | [diff] [blame] | 2391 | } |
| 2392 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2393 | auto *FirstDecl = cast_or_null<T>(Reader.GetDecl(FirstDeclID)); |
Douglas Gregor | 358cd44 | 2012-01-15 16:58:34 +0000 | [diff] [blame] | 2394 | if (FirstDecl != D) { |
Argyrios Kyrtzidis | 9fdd254 | 2011-02-12 07:50:47 +0000 | [diff] [blame] | 2395 | // We delay loading of the redeclaration chain to avoid deeply nested calls. |
| 2396 | // We temporarily set the first (canonical) declaration as the previous one |
| 2397 | // which is the one that matters and mark the real previous DeclID to be |
| 2398 | // loaded & attached later on. |
David Blaikie | 7e64fd9 | 2012-05-28 19:38:42 +0000 | [diff] [blame] | 2399 | D->RedeclLink = Redeclarable<T>::PreviousDeclLink(FirstDecl); |
Manuel Klimek | 093b2d4 | 2015-03-25 23:18:30 +0000 | [diff] [blame] | 2400 | D->First = FirstDecl->getCanonicalDecl(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2401 | } |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 2402 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2403 | auto *DAsT = static_cast<T *>(D); |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 2404 | |
| 2405 | // Note that we need to load local redeclarations of this decl and build a |
| 2406 | // decl chain for them. This must happen *after* we perform the preloading |
| 2407 | // above; this ensures that the redeclaration chain is built in the correct |
| 2408 | // order. |
| 2409 | if (IsFirstLocalDecl) |
Richard Smith | d61d4ac | 2015-08-22 20:13:39 +0000 | [diff] [blame] | 2410 | Reader.PendingDeclChains.push_back(std::make_pair(DAsT, RedeclOffset)); |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 2411 | |
Alexander Shaposhnikov | fbc4d68 | 2016-09-24 04:21:53 +0000 | [diff] [blame] | 2412 | return RedeclarableResult(MergeWith, FirstDeclID, IsKeyDecl); |
Argyrios Kyrtzidis | 839bbac | 2010-08-03 17:30:10 +0000 | [diff] [blame] | 2413 | } |
| 2414 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2415 | /// Attempts to merge the given declaration (D) with another declaration |
Douglas Gregor | 2c46b5b | 2012-01-03 17:27:13 +0000 | [diff] [blame] | 2416 | /// of the same entity. |
| 2417 | template<typename T> |
Richard Smith | 5e9e56a | 2014-07-15 03:37:06 +0000 | [diff] [blame] | 2418 | void ASTDeclReader::mergeRedeclarable(Redeclarable<T> *DBase, |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2419 | RedeclarableResult &Redecl, |
| 2420 | DeclID TemplatePatternID) { |
Douglas Gregor | e097d4b | 2012-01-03 17:31:38 +0000 | [diff] [blame] | 2421 | // 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] | 2422 | if (!Reader.getContext().getLangOpts().Modules) |
Douglas Gregor | e097d4b | 2012-01-03 17:31:38 +0000 | [diff] [blame] | 2423 | return; |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2424 | |
Richard Smith | 202850a | 2015-03-10 02:57:50 +0000 | [diff] [blame] | 2425 | // If we're not the canonical declaration, we don't need to merge. |
| 2426 | if (!DBase->isFirstDecl()) |
| 2427 | return; |
| 2428 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2429 | auto *D = static_cast<T *>(DBase); |
Vassil Vassilev | 916d8be | 2016-10-06 13:18:06 +0000 | [diff] [blame] | 2430 | |
Richard Smith | 5a4737c | 2015-02-06 02:42:59 +0000 | [diff] [blame] | 2431 | if (auto *Existing = Redecl.getKnownMergeTarget()) |
| 2432 | // We already know of an existing declaration we should merge with. |
| 2433 | mergeRedeclarable(D, cast<T>(Existing), Redecl, TemplatePatternID); |
| 2434 | else if (FindExistingResult ExistingRes = findExisting(D)) |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2435 | if (T *Existing = ExistingRes) |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2436 | mergeRedeclarable(D, Existing, Redecl, TemplatePatternID); |
| 2437 | } |
| 2438 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2439 | /// "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] | 2440 | /// We use this to put code in a template that will only be valid for certain |
| 2441 | /// instantiations. |
| 2442 | template<typename T> static T assert_cast(T t) { return t; } |
| 2443 | template<typename T> static T assert_cast(...) { |
| 2444 | llvm_unreachable("bad assert_cast"); |
| 2445 | } |
| 2446 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2447 | /// Merge together the pattern declarations from two template |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2448 | /// declarations. |
| 2449 | void ASTDeclReader::mergeTemplatePattern(RedeclarableTemplateDecl *D, |
| 2450 | RedeclarableTemplateDecl *Existing, |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 2451 | DeclID DsID, bool IsKeyDecl) { |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2452 | auto *DPattern = D->getTemplatedDecl(); |
| 2453 | auto *ExistingPattern = Existing->getTemplatedDecl(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2454 | RedeclarableResult Result(/*MergeWith*/ ExistingPattern, |
| 2455 | DPattern->getCanonicalDecl()->getGlobalID(), |
Alexander Shaposhnikov | fbc4d68 | 2016-09-24 04:21:53 +0000 | [diff] [blame] | 2456 | IsKeyDecl); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2457 | |
Richard Smith | 547864d | 2014-07-11 18:22:58 +0000 | [diff] [blame] | 2458 | if (auto *DClass = dyn_cast<CXXRecordDecl>(DPattern)) { |
| 2459 | // Merge with any existing definition. |
| 2460 | // FIXME: This is duplicated in several places. Refactor. |
| 2461 | auto *ExistingClass = |
| 2462 | cast<CXXRecordDecl>(ExistingPattern)->getCanonicalDecl(); |
Richard Smith | b648399 | 2016-05-17 22:44:15 +0000 | [diff] [blame] | 2463 | if (auto *DDD = DClass->DefinitionData) { |
| 2464 | if (ExistingClass->DefinitionData) { |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 2465 | MergeDefinitionData(ExistingClass, std::move(*DDD)); |
Richard Smith | 547864d | 2014-07-11 18:22:58 +0000 | [diff] [blame] | 2466 | } else { |
| 2467 | ExistingClass->DefinitionData = DClass->DefinitionData; |
Richard Smith | 97100e3 | 2015-06-20 00:22:34 +0000 | [diff] [blame] | 2468 | // We may have skipped this before because we thought that DClass |
| 2469 | // was the canonical declaration. |
Richard Smith | 7474dd92 | 2015-03-11 18:21:02 +0000 | [diff] [blame] | 2470 | Reader.PendingDefinitions.insert(DClass); |
Richard Smith | 547864d | 2014-07-11 18:22:58 +0000 | [diff] [blame] | 2471 | } |
| 2472 | } |
| 2473 | DClass->DefinitionData = ExistingClass->DefinitionData; |
| 2474 | |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2475 | return mergeRedeclarable(DClass, cast<TagDecl>(ExistingPattern), |
| 2476 | Result); |
Richard Smith | 547864d | 2014-07-11 18:22:58 +0000 | [diff] [blame] | 2477 | } |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2478 | if (auto *DFunction = dyn_cast<FunctionDecl>(DPattern)) |
| 2479 | return mergeRedeclarable(DFunction, cast<FunctionDecl>(ExistingPattern), |
| 2480 | Result); |
| 2481 | if (auto *DVar = dyn_cast<VarDecl>(DPattern)) |
| 2482 | return mergeRedeclarable(DVar, cast<VarDecl>(ExistingPattern), Result); |
Richard Smith | f59b735 | 2014-07-28 21:16:37 +0000 | [diff] [blame] | 2483 | if (auto *DAlias = dyn_cast<TypeAliasDecl>(DPattern)) |
| 2484 | return mergeRedeclarable(DAlias, cast<TypedefNameDecl>(ExistingPattern), |
| 2485 | Result); |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2486 | llvm_unreachable("merged an unknown kind of redeclarable template"); |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2487 | } |
| 2488 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2489 | /// Attempts to merge the given declaration (D) with another declaration |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2490 | /// of the same entity. |
| 2491 | template<typename T> |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2492 | void ASTDeclReader::mergeRedeclarable(Redeclarable<T> *DBase, T *Existing, |
| 2493 | RedeclarableResult &Redecl, |
| 2494 | DeclID TemplatePatternID) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2495 | auto *D = static_cast<T *>(DBase); |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2496 | T *ExistingCanon = Existing->getCanonicalDecl(); |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2497 | T *DCanon = D->getCanonicalDecl(); |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2498 | if (ExistingCanon != DCanon) { |
Richard Smith | 202850a | 2015-03-10 02:57:50 +0000 | [diff] [blame] | 2499 | assert(DCanon->getGlobalID() == Redecl.getFirstID() && |
| 2500 | "already merged this declaration"); |
Richard Smith | 5e9e56a | 2014-07-15 03:37:06 +0000 | [diff] [blame] | 2501 | |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2502 | // Have our redeclaration link point back at the canonical declaration |
Richard Smith | 5e9e56a | 2014-07-15 03:37:06 +0000 | [diff] [blame] | 2503 | // of the existing declaration, so that this declaration has the |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2504 | // appropriate canonical declaration. |
| 2505 | D->RedeclLink = Redeclarable<T>::PreviousDeclLink(ExistingCanon); |
Manuel Klimek | 093b2d4 | 2015-03-25 23:18:30 +0000 | [diff] [blame] | 2506 | D->First = ExistingCanon; |
Vassil Vassilev | 928c825 | 2016-04-28 14:13:28 +0000 | [diff] [blame] | 2507 | ExistingCanon->Used |= D->Used; |
| 2508 | D->Used = false; |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2509 | |
| 2510 | // When we merge a namespace, update its pointer to the first namespace. |
Richard Smith | 15e32fd | 2015-03-17 02:23:11 +0000 | [diff] [blame] | 2511 | // We cannot have loaded any redeclarations of this declaration yet, so |
| 2512 | // there's nothing else that needs to be updated. |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2513 | if (auto *Namespace = dyn_cast<NamespaceDecl>(D)) |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2514 | Namespace->AnonOrFirstNamespaceAndInline.setPointer( |
Richard Smith | f17fdbd | 2014-04-24 02:25:27 +0000 | [diff] [blame] | 2515 | assert_cast<NamespaceDecl*>(ExistingCanon)); |
| 2516 | |
| 2517 | // When we merge a template, merge its pattern. |
| 2518 | if (auto *DTemplate = dyn_cast<RedeclarableTemplateDecl>(D)) |
| 2519 | mergeTemplatePattern( |
| 2520 | DTemplate, assert_cast<RedeclarableTemplateDecl*>(ExistingCanon), |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 2521 | TemplatePatternID, Redecl.isKeyDecl()); |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2522 | |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 2523 | // If this declaration is a key declaration, make a note of that. |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 2524 | if (Redecl.isKeyDecl()) |
Richard Smith | 5fc18a9 | 2015-07-12 23:43:21 +0000 | [diff] [blame] | 2525 | Reader.KeyDecls[ExistingCanon].push_back(Redecl.getFirstID()); |
Douglas Gregor | 2c46b5b | 2012-01-03 17:27:13 +0000 | [diff] [blame] | 2526 | } |
| 2527 | } |
| 2528 | |
Bruno Cardoso Lopes | 85f87dd | 2018-04-30 22:14:29 +0000 | [diff] [blame] | 2529 | /// ODR-like semantics for C/ObjC allow us to merge tag types and a structural |
| 2530 | /// check in Sema guarantees the types can be merged (see C11 6.2.7/1 or C89 |
| 2531 | /// 6.1.2.6/1). Although most merging is done in Sema, we need to guarantee |
| 2532 | /// that some types are mergeable during deserialization, otherwise name |
| 2533 | /// lookup fails. This is the case for EnumConstantDecl. |
Benjamin Kramer | 651d0bf | 2018-05-15 21:26:47 +0000 | [diff] [blame] | 2534 | static bool allowODRLikeMergeInC(NamedDecl *ND) { |
Bruno Cardoso Lopes | 85f87dd | 2018-04-30 22:14:29 +0000 | [diff] [blame] | 2535 | if (!ND) |
| 2536 | return false; |
| 2537 | // TODO: implement merge for other necessary decls. |
Benjamin Kramer | 651d0bf | 2018-05-15 21:26:47 +0000 | [diff] [blame] | 2538 | if (isa<EnumConstantDecl>(ND)) |
Bruno Cardoso Lopes | 85f87dd | 2018-04-30 22:14:29 +0000 | [diff] [blame] | 2539 | return true; |
| 2540 | return false; |
| 2541 | } |
| 2542 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2543 | /// Attempts to merge the given declaration (D) with another declaration |
Richard Smith | 0b87e07 | 2013-10-07 08:02:11 +0000 | [diff] [blame] | 2544 | /// of the same entity, for the case where the entity is not actually |
| 2545 | /// redeclarable. This happens, for instance, when merging the fields of |
| 2546 | /// identical class definitions from two different modules. |
| 2547 | template<typename T> |
| 2548 | void ASTDeclReader::mergeMergeable(Mergeable<T> *D) { |
| 2549 | // If modules are not available, there is no reason to perform this merge. |
| 2550 | if (!Reader.getContext().getLangOpts().Modules) |
| 2551 | return; |
| 2552 | |
Bruno Cardoso Lopes | 85f87dd | 2018-04-30 22:14:29 +0000 | [diff] [blame] | 2553 | // ODR-based merging is performed in C++ and in some cases (tag types) in C. |
| 2554 | // Note that C identically-named things in different translation units are |
| 2555 | // not redeclarations, but may still have compatible types, where ODR-like |
| 2556 | // semantics may apply. |
| 2557 | if (!Reader.getContext().getLangOpts().CPlusPlus && |
| 2558 | !allowODRLikeMergeInC(dyn_cast<NamedDecl>(static_cast<T*>(D)))) |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame] | 2559 | return; |
| 2560 | |
Richard Smith | 0b87e07 | 2013-10-07 08:02:11 +0000 | [diff] [blame] | 2561 | if (FindExistingResult ExistingRes = findExisting(static_cast<T*>(D))) |
| 2562 | if (T *Existing = ExistingRes) |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 2563 | Reader.getContext().setPrimaryMergedDecl(static_cast<T *>(D), |
| 2564 | Existing->getCanonicalDecl()); |
Richard Smith | 0b87e07 | 2013-10-07 08:02:11 +0000 | [diff] [blame] | 2565 | } |
| 2566 | |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2567 | void ASTDeclReader::VisitOMPThreadPrivateDecl(OMPThreadPrivateDecl *D) { |
| 2568 | VisitDecl(D); |
| 2569 | unsigned NumVars = D->varlist_size(); |
Alexey Bataev | 6f6f3b4 | 2013-05-13 04:18:18 +0000 | [diff] [blame] | 2570 | SmallVector<Expr *, 16> Vars; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2571 | Vars.reserve(NumVars); |
| 2572 | for (unsigned i = 0; i != NumVars; ++i) { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 2573 | Vars.push_back(Record.readExpr()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 2574 | } |
| 2575 | D->setVars(Vars); |
| 2576 | } |
| 2577 | |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 2578 | void ASTDeclReader::VisitOMPAllocateDecl(OMPAllocateDecl *D) { |
| 2579 | VisitDecl(D); |
| 2580 | unsigned NumVars = D->varlist_size(); |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 2581 | unsigned NumClauses = D->clauselist_size(); |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 2582 | SmallVector<Expr *, 16> Vars; |
| 2583 | Vars.reserve(NumVars); |
| 2584 | for (unsigned i = 0; i != NumVars; ++i) { |
| 2585 | Vars.push_back(Record.readExpr()); |
| 2586 | } |
| 2587 | D->setVars(Vars); |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 2588 | SmallVector<OMPClause *, 8> Clauses; |
| 2589 | Clauses.reserve(NumClauses); |
| 2590 | OMPClauseReader ClauseReader(Record); |
| 2591 | for (unsigned I = 0; I != NumClauses; ++I) |
| 2592 | Clauses.push_back(ClauseReader.readClause()); |
| 2593 | D->setClauses(Clauses); |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 2594 | } |
| 2595 | |
Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 2596 | void ASTDeclReader::VisitOMPRequiresDecl(OMPRequiresDecl * D) { |
| 2597 | VisitDecl(D); |
| 2598 | unsigned NumClauses = D->clauselist_size(); |
| 2599 | SmallVector<OMPClause *, 8> Clauses; |
| 2600 | Clauses.reserve(NumClauses); |
| 2601 | OMPClauseReader ClauseReader(Record); |
| 2602 | for (unsigned I = 0; I != NumClauses; ++I) |
| 2603 | Clauses.push_back(ClauseReader.readClause()); |
| 2604 | D->setClauses(Clauses); |
| 2605 | } |
| 2606 | |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 2607 | void ASTDeclReader::VisitOMPDeclareReductionDecl(OMPDeclareReductionDecl *D) { |
Alexey Bataev | c5b1d32 | 2016-03-04 09:22:22 +0000 | [diff] [blame] | 2608 | VisitValueDecl(D); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2609 | D->setLocation(ReadSourceLocation()); |
Alexey Bataev | e6aa469 | 2018-09-13 16:54:05 +0000 | [diff] [blame] | 2610 | Expr *In = Record.readExpr(); |
| 2611 | Expr *Out = Record.readExpr(); |
| 2612 | D->setCombinerData(In, Out); |
| 2613 | Expr *Combiner = Record.readExpr(); |
| 2614 | D->setCombiner(Combiner); |
| 2615 | Expr *Orig = Record.readExpr(); |
| 2616 | Expr *Priv = Record.readExpr(); |
| 2617 | D->setInitializerData(Orig, Priv); |
| 2618 | Expr *Init = Record.readExpr(); |
| 2619 | auto IK = static_cast<OMPDeclareReductionDecl::InitKind>(Record.readInt()); |
| 2620 | D->setInitializer(Init, IK); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 2621 | D->PrevDeclInScope = ReadDeclID(); |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 2622 | } |
| 2623 | |
Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 2624 | void ASTDeclReader::VisitOMPDeclareMapperDecl(OMPDeclareMapperDecl *D) { |
| 2625 | VisitValueDecl(D); |
| 2626 | D->setLocation(ReadSourceLocation()); |
| 2627 | Expr *MapperVarRefE = Record.readExpr(); |
| 2628 | D->setMapperVarRef(MapperVarRefE); |
| 2629 | D->VarName = Record.readDeclarationName(); |
| 2630 | D->PrevDeclInScope = ReadDeclID(); |
| 2631 | unsigned NumClauses = D->clauselist_size(); |
| 2632 | SmallVector<OMPClause *, 8> Clauses; |
| 2633 | Clauses.reserve(NumClauses); |
| 2634 | OMPClauseReader ClauseReader(Record); |
| 2635 | for (unsigned I = 0; I != NumClauses; ++I) |
| 2636 | Clauses.push_back(ClauseReader.readClause()); |
| 2637 | D->setClauses(Clauses); |
| 2638 | } |
| 2639 | |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 2640 | void ASTDeclReader::VisitOMPCapturedExprDecl(OMPCapturedExprDecl *D) { |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 2641 | VisitVarDecl(D); |
| 2642 | } |
| 2643 | |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 2644 | //===----------------------------------------------------------------------===// |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 2645 | // Attribute Reading |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 2646 | //===----------------------------------------------------------------------===// |
| 2647 | |
Richard Smith | e43e2b3 | 2018-08-20 21:47:29 +0000 | [diff] [blame] | 2648 | namespace { |
| 2649 | class AttrReader { |
| 2650 | ModuleFile *F; |
| 2651 | ASTReader *Reader; |
| 2652 | const ASTReader::RecordData &Record; |
| 2653 | unsigned &Idx; |
| 2654 | |
| 2655 | public: |
| 2656 | AttrReader(ModuleFile &F, ASTReader &Reader, |
| 2657 | const ASTReader::RecordData &Record, unsigned &Idx) |
| 2658 | : F(&F), Reader(&Reader), Record(Record), Idx(Idx) {} |
| 2659 | |
| 2660 | const uint64_t &readInt() { return Record[Idx++]; } |
| 2661 | |
| 2662 | SourceRange readSourceRange() { |
| 2663 | return Reader->ReadSourceRange(*F, Record, Idx); |
| 2664 | } |
| 2665 | |
Erich Keane | 6a24e80 | 2019-09-13 17:39:31 +0000 | [diff] [blame] | 2666 | SourceLocation readSourceLocation() { |
| 2667 | return Reader->ReadSourceLocation(*F, Record, Idx); |
| 2668 | } |
| 2669 | |
Richard Smith | e43e2b3 | 2018-08-20 21:47:29 +0000 | [diff] [blame] | 2670 | Expr *readExpr() { return Reader->ReadExpr(*F); } |
| 2671 | |
| 2672 | std::string readString() { |
| 2673 | return Reader->ReadString(Record, Idx); |
| 2674 | } |
| 2675 | |
| 2676 | TypeSourceInfo *getTypeSourceInfo() { |
| 2677 | return Reader->GetTypeSourceInfo(*F, Record, Idx); |
| 2678 | } |
| 2679 | |
| 2680 | IdentifierInfo *getIdentifierInfo() { |
| 2681 | return Reader->GetIdentifierInfo(*F, Record, Idx); |
| 2682 | } |
| 2683 | |
| 2684 | VersionTuple readVersionTuple() { |
| 2685 | return ASTReader::ReadVersionTuple(Record, Idx); |
| 2686 | } |
| 2687 | |
| 2688 | template <typename T> T *GetLocalDeclAs(uint32_t LocalID) { |
| 2689 | return cast_or_null<T>(Reader->GetLocalDecl(*F, LocalID)); |
| 2690 | } |
| 2691 | }; |
| 2692 | } |
| 2693 | |
| 2694 | Attr *ASTReader::ReadAttr(ModuleFile &M, const RecordData &Rec, |
| 2695 | unsigned &Idx) { |
| 2696 | AttrReader Record(M, *this, Rec, Idx); |
| 2697 | auto V = Record.readInt(); |
| 2698 | if (!V) |
| 2699 | return nullptr; |
| 2700 | |
| 2701 | Attr *New = nullptr; |
| 2702 | // Kind is stored as a 1-based integer because 0 is used to indicate a null |
| 2703 | // Attr pointer. |
| 2704 | auto Kind = static_cast<attr::Kind>(V - 1); |
Richard Smith | e43e2b3 | 2018-08-20 21:47:29 +0000 | [diff] [blame] | 2705 | ASTContext &Context = getContext(); |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 2706 | |
Erich Keane | 6a24e80 | 2019-09-13 17:39:31 +0000 | [diff] [blame] | 2707 | IdentifierInfo *AttrName = Record.getIdentifierInfo(); |
| 2708 | IdentifierInfo *ScopeName = Record.getIdentifierInfo(); |
| 2709 | SourceRange AttrRange = Record.readSourceRange(); |
| 2710 | SourceLocation ScopeLoc = Record.readSourceLocation(); |
| 2711 | unsigned ParsedKind = Record.readInt(); |
| 2712 | unsigned Syntax = Record.readInt(); |
| 2713 | unsigned SpellingIndex = Record.readInt(); |
| 2714 | |
| 2715 | AttributeCommonInfo Info(AttrName, ScopeName, AttrRange, ScopeLoc, |
| 2716 | AttributeCommonInfo::Kind(ParsedKind), |
| 2717 | AttributeCommonInfo::Syntax(Syntax), SpellingIndex); |
| 2718 | |
Alexis Hunt | dcfba7b | 2010-08-18 23:23:40 +0000 | [diff] [blame] | 2719 | #include "clang/Serialization/AttrPCHRead.inc" |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 2720 | |
Richard Smith | e43e2b3 | 2018-08-20 21:47:29 +0000 | [diff] [blame] | 2721 | assert(New && "Unable to decode attribute?"); |
| 2722 | return New; |
| 2723 | } |
| 2724 | |
| 2725 | /// Reads attributes from the current stream position. |
| 2726 | void ASTReader::ReadAttributes(ASTRecordReader &Record, AttrVec &Attrs) { |
| 2727 | for (unsigned I = 0, E = Record.readInt(); I != E; ++I) |
| 2728 | Attrs.push_back(Record.readAttr()); |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 2729 | } |
| 2730 | |
| 2731 | //===----------------------------------------------------------------------===// |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2732 | // ASTReader Implementation |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 2733 | //===----------------------------------------------------------------------===// |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 2734 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2735 | /// Note that we have loaded the declaration with the given |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 2736 | /// Index. |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 2737 | /// |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 2738 | /// This routine notes that this declaration has already been loaded, |
| 2739 | /// so that future GetDecl calls will return this declaration rather |
| 2740 | /// than trying to load a new declaration. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2741 | inline void ASTReader::LoadedDecl(unsigned Index, Decl *D) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 2742 | assert(!DeclsLoaded[Index] && "Decl loaded twice?"); |
| 2743 | DeclsLoaded[Index] = D; |
| 2744 | } |
| 2745 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2746 | /// Determine whether the consumer will be interested in seeing |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 2747 | /// this declaration (via HandleTopLevelDecl). |
| 2748 | /// |
| 2749 | /// This routine should return true for anything that might affect |
| 2750 | /// code generation, e.g., inline function definitions, Objective-C |
| 2751 | /// declarations with metadata, etc. |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 2752 | static bool isConsumerInterestedIn(ASTContext &Ctx, Decl *D, bool HasBody) { |
Argyrios Kyrtzidis | a98e861 | 2011-09-13 21:35:00 +0000 | [diff] [blame] | 2753 | // An ObjCMethodDecl is never considered as "interesting" because its |
| 2754 | // implementation container always is. |
| 2755 | |
Richard Smith | cd4a7a4 | 2017-09-07 00:55:55 +0000 | [diff] [blame] | 2756 | // An ImportDecl or VarDecl imported from a module map module will get |
| 2757 | // emitted when we import the relevant module. |
Richard Smith | 520a37f | 2019-02-05 23:37:13 +0000 | [diff] [blame] | 2758 | if (isPartOfPerModuleInitializer(D)) { |
Richard Smith | cd4a7a4 | 2017-09-07 00:55:55 +0000 | [diff] [blame] | 2759 | auto *M = D->getImportedOwningModule(); |
| 2760 | if (M && M->Kind == Module::ModuleMapModule && |
| 2761 | Ctx.DeclMustBeEmitted(D)) |
| 2762 | return false; |
| 2763 | } |
Richard Smith | dc1f042 | 2016-07-20 19:10:16 +0000 | [diff] [blame] | 2764 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 2765 | if (isa<FileScopeAsmDecl>(D) || |
| 2766 | isa<ObjCProtocolDecl>(D) || |
Ben Langmuir | 332aafe | 2014-01-31 01:06:56 +0000 | [diff] [blame] | 2767 | isa<ObjCImplDecl>(D) || |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 2768 | isa<ImportDecl>(D) || |
Nico Weber | 6622029 | 2016-03-02 17:28:48 +0000 | [diff] [blame] | 2769 | isa<PragmaCommentDecl>(D) || |
Alexey Bataev | c5b1d32 | 2016-03-04 09:22:22 +0000 | [diff] [blame] | 2770 | isa<PragmaDetectMismatchDecl>(D)) |
Daniel Dunbar | 865c2a7 | 2009-09-17 03:06:44 +0000 | [diff] [blame] | 2771 | return true; |
Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 2772 | if (isa<OMPThreadPrivateDecl>(D) || isa<OMPDeclareReductionDecl>(D) || |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 2773 | isa<OMPDeclareMapperDecl>(D) || isa<OMPAllocateDecl>(D)) |
Alexey Bataev | c5b1d32 | 2016-03-04 09:22:22 +0000 | [diff] [blame] | 2774 | return !D->getDeclContext()->isFunctionOrMethod(); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2775 | if (const auto *Var = dyn_cast<VarDecl>(D)) |
Argyrios Kyrtzidis | 4ba81b2 | 2010-08-05 09:47:59 +0000 | [diff] [blame] | 2776 | return Var->isFileVarDecl() && |
Alexey Bataev | d01b749 | 2018-08-15 19:45:12 +0000 | [diff] [blame] | 2777 | (Var->isThisDeclarationADefinition() == VarDecl::Definition || |
| 2778 | OMPDeclareTargetDeclAttr::isDeclareTargetDeclaration(Var)); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2779 | if (const auto *Func = dyn_cast<FunctionDecl>(D)) |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 2780 | return Func->doesThisDeclarationHaveABody() || HasBody; |
David Blaikie | 1ac9c98 | 2017-04-11 21:13:37 +0000 | [diff] [blame] | 2781 | |
| 2782 | if (auto *ES = D->getASTContext().getExternalSource()) |
| 2783 | if (ES->hasExternalDefinitions(D) == ExternalASTSource::EK_Never) |
| 2784 | return true; |
| 2785 | |
Douglas Gregor | 87d8124 | 2011-09-10 00:22:34 +0000 | [diff] [blame] | 2786 | return false; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 2787 | } |
| 2788 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2789 | /// Get the correct cursor and offset for loading a declaration. |
Sebastian Redl | 2c499f6 | 2010-08-18 23:56:43 +0000 | [diff] [blame] | 2790 | ASTReader::RecordLocation |
Richard Smith | cb34bd3 | 2016-03-27 07:28:06 +0000 | [diff] [blame] | 2791 | ASTReader::DeclCursorForID(DeclID ID, SourceLocation &Loc) { |
Douglas Gregor | 047d2ef | 2011-07-20 00:27:43 +0000 | [diff] [blame] | 2792 | GlobalDeclMapType::iterator I = GlobalDeclMap.find(ID); |
| 2793 | assert(I != GlobalDeclMap.end() && "Corrupted global declaration map"); |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2794 | ModuleFile *M = I->second; |
Richard Smith | 34da751 | 2016-03-27 05:52:25 +0000 | [diff] [blame] | 2795 | const DeclOffset &DOffs = |
| 2796 | M->DeclOffsets[ID - M->BaseDeclID - NUM_PREDEF_DECL_IDS]; |
Richard Smith | cb34bd3 | 2016-03-27 07:28:06 +0000 | [diff] [blame] | 2797 | Loc = TranslateSourceLocation(*M, DOffs.getLocation()); |
Argyrios Kyrtzidis | 81ddd18 | 2011-10-27 18:47:35 +0000 | [diff] [blame] | 2798 | return RecordLocation(M, DOffs.BitOffset); |
Sebastian Redl | 3462779 | 2010-07-20 22:46:15 +0000 | [diff] [blame] | 2799 | } |
| 2800 | |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 2801 | ASTReader::RecordLocation ASTReader::getLocalBitOffset(uint64_t GlobalOffset) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2802 | auto I = GlobalBitOffsetsMap.find(GlobalOffset); |
Douglas Gregor | d32f035 | 2011-07-22 06:10:01 +0000 | [diff] [blame] | 2803 | |
| 2804 | assert(I != GlobalBitOffsetsMap.end() && "Corrupted global bit offsets map"); |
| 2805 | return RecordLocation(I->second, GlobalOffset - I->second->GlobalBitOffset); |
| 2806 | } |
| 2807 | |
Douglas Gregor | de3ef50 | 2011-11-30 23:21:26 +0000 | [diff] [blame] | 2808 | uint64_t ASTReader::getGlobalBitOffset(ModuleFile &M, uint32_t LocalOffset) { |
Douglas Gregor | c27b287 | 2011-08-04 00:01:48 +0000 | [diff] [blame] | 2809 | return LocalOffset + M.GlobalBitOffset; |
| 2810 | } |
| 2811 | |
Richard Smith | bf78e64 | 2013-06-24 22:51:00 +0000 | [diff] [blame] | 2812 | static bool isSameTemplateParameterList(const TemplateParameterList *X, |
| 2813 | const TemplateParameterList *Y); |
| 2814 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2815 | /// Determine whether two template parameters are similar enough |
Richard Smith | bf78e64 | 2013-06-24 22:51:00 +0000 | [diff] [blame] | 2816 | /// that they may be used in declarations of the same template. |
| 2817 | static bool isSameTemplateParameter(const NamedDecl *X, |
| 2818 | const NamedDecl *Y) { |
| 2819 | if (X->getKind() != Y->getKind()) |
| 2820 | return false; |
| 2821 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2822 | if (const auto *TX = dyn_cast<TemplateTypeParmDecl>(X)) { |
| 2823 | const auto *TY = cast<TemplateTypeParmDecl>(Y); |
Richard Smith | bf78e64 | 2013-06-24 22:51:00 +0000 | [diff] [blame] | 2824 | return TX->isParameterPack() == TY->isParameterPack(); |
| 2825 | } |
| 2826 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2827 | if (const auto *TX = dyn_cast<NonTypeTemplateParmDecl>(X)) { |
| 2828 | const auto *TY = cast<NonTypeTemplateParmDecl>(Y); |
Richard Smith | bf78e64 | 2013-06-24 22:51:00 +0000 | [diff] [blame] | 2829 | return TX->isParameterPack() == TY->isParameterPack() && |
| 2830 | TX->getASTContext().hasSameType(TX->getType(), TY->getType()); |
| 2831 | } |
| 2832 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2833 | const auto *TX = cast<TemplateTemplateParmDecl>(X); |
| 2834 | const auto *TY = cast<TemplateTemplateParmDecl>(Y); |
Richard Smith | bf78e64 | 2013-06-24 22:51:00 +0000 | [diff] [blame] | 2835 | return TX->isParameterPack() == TY->isParameterPack() && |
| 2836 | isSameTemplateParameterList(TX->getTemplateParameters(), |
| 2837 | TY->getTemplateParameters()); |
| 2838 | } |
| 2839 | |
Richard Smith | 32952e1 | 2014-10-14 02:00:47 +0000 | [diff] [blame] | 2840 | static NamespaceDecl *getNamespace(const NestedNameSpecifier *X) { |
| 2841 | if (auto *NS = X->getAsNamespace()) |
| 2842 | return NS; |
| 2843 | if (auto *NAS = X->getAsNamespaceAlias()) |
| 2844 | return NAS->getNamespace(); |
| 2845 | return nullptr; |
| 2846 | } |
| 2847 | |
| 2848 | static bool isSameQualifier(const NestedNameSpecifier *X, |
| 2849 | const NestedNameSpecifier *Y) { |
| 2850 | if (auto *NSX = getNamespace(X)) { |
| 2851 | auto *NSY = getNamespace(Y); |
| 2852 | if (!NSY || NSX->getCanonicalDecl() != NSY->getCanonicalDecl()) |
| 2853 | return false; |
| 2854 | } else if (X->getKind() != Y->getKind()) |
| 2855 | return false; |
| 2856 | |
| 2857 | // FIXME: For namespaces and types, we're permitted to check that the entity |
| 2858 | // is named via the same tokens. We should probably do so. |
| 2859 | switch (X->getKind()) { |
| 2860 | case NestedNameSpecifier::Identifier: |
| 2861 | if (X->getAsIdentifier() != Y->getAsIdentifier()) |
| 2862 | return false; |
| 2863 | break; |
| 2864 | case NestedNameSpecifier::Namespace: |
| 2865 | case NestedNameSpecifier::NamespaceAlias: |
| 2866 | // We've already checked that we named the same namespace. |
| 2867 | break; |
| 2868 | case NestedNameSpecifier::TypeSpec: |
| 2869 | case NestedNameSpecifier::TypeSpecWithTemplate: |
| 2870 | if (X->getAsType()->getCanonicalTypeInternal() != |
| 2871 | Y->getAsType()->getCanonicalTypeInternal()) |
| 2872 | return false; |
| 2873 | break; |
| 2874 | case NestedNameSpecifier::Global: |
| 2875 | case NestedNameSpecifier::Super: |
| 2876 | return true; |
| 2877 | } |
| 2878 | |
| 2879 | // Recurse into earlier portion of NNS, if any. |
| 2880 | auto *PX = X->getPrefix(); |
| 2881 | auto *PY = Y->getPrefix(); |
| 2882 | if (PX && PY) |
| 2883 | return isSameQualifier(PX, PY); |
| 2884 | return !PX && !PY; |
| 2885 | } |
| 2886 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2887 | /// Determine whether two template parameter lists are similar enough |
Richard Smith | bf78e64 | 2013-06-24 22:51:00 +0000 | [diff] [blame] | 2888 | /// that they may be used in declarations of the same template. |
| 2889 | static bool isSameTemplateParameterList(const TemplateParameterList *X, |
| 2890 | const TemplateParameterList *Y) { |
| 2891 | if (X->size() != Y->size()) |
| 2892 | return false; |
| 2893 | |
| 2894 | for (unsigned I = 0, N = X->size(); I != N; ++I) |
| 2895 | if (!isSameTemplateParameter(X->getParam(I), Y->getParam(I))) |
| 2896 | return false; |
| 2897 | |
| 2898 | return true; |
| 2899 | } |
| 2900 | |
George Burgess IV | 9584508 | 2017-02-15 22:43:27 +0000 | [diff] [blame] | 2901 | /// 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] | 2902 | /// 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] | 2903 | static bool hasSameOverloadableAttrs(const FunctionDecl *A, |
| 2904 | const FunctionDecl *B) { |
George Burgess IV | b776021 | 2017-02-24 02:49:47 +0000 | [diff] [blame] | 2905 | // Note that pass_object_size attributes are represented in the function's |
| 2906 | // ExtParameterInfo, so we don't need to check them here. |
| 2907 | |
George Burgess IV | 9584508 | 2017-02-15 22:43:27 +0000 | [diff] [blame] | 2908 | llvm::FoldingSetNodeID Cand1ID, Cand2ID; |
Michael Kruse | dc5ce72 | 2018-08-03 01:21:16 +0000 | [diff] [blame] | 2909 | auto AEnableIfAttrs = A->specific_attrs<EnableIfAttr>(); |
| 2910 | auto BEnableIfAttrs = B->specific_attrs<EnableIfAttr>(); |
Michael Kruse | 157a355 | 2018-12-10 15:16:37 +0000 | [diff] [blame] | 2911 | |
| 2912 | for (auto Pair : zip_longest(AEnableIfAttrs, BEnableIfAttrs)) { |
| 2913 | Optional<EnableIfAttr *> Cand1A = std::get<0>(Pair); |
| 2914 | Optional<EnableIfAttr *> Cand2A = std::get<1>(Pair); |
| 2915 | |
| 2916 | // Return false if the number of enable_if attributes is different. |
| 2917 | if (!Cand1A || !Cand2A) |
| 2918 | return false; |
| 2919 | |
George Burgess IV | 9584508 | 2017-02-15 22:43:27 +0000 | [diff] [blame] | 2920 | Cand1ID.clear(); |
| 2921 | Cand2ID.clear(); |
| 2922 | |
Michael Kruse | 157a355 | 2018-12-10 15:16:37 +0000 | [diff] [blame] | 2923 | (*Cand1A)->getCond()->Profile(Cand1ID, A->getASTContext(), true); |
| 2924 | (*Cand2A)->getCond()->Profile(Cand2ID, B->getASTContext(), true); |
| 2925 | |
| 2926 | // Return false if any of the enable_if expressions of A and B are |
| 2927 | // different. |
George Burgess IV | 9584508 | 2017-02-15 22:43:27 +0000 | [diff] [blame] | 2928 | if (Cand1ID != Cand2ID) |
| 2929 | return false; |
| 2930 | } |
Michael Kruse | 157a355 | 2018-12-10 15:16:37 +0000 | [diff] [blame] | 2931 | return true; |
George Burgess IV | 9584508 | 2017-02-15 22:43:27 +0000 | [diff] [blame] | 2932 | } |
| 2933 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 2934 | /// Determine whether the two declarations refer to the same entity. |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 2935 | static bool isSameEntity(NamedDecl *X, NamedDecl *Y) { |
| 2936 | assert(X->getDeclName() == Y->getDeclName() && "Declaration name mismatch!"); |
Richard Smith | f463436 | 2014-09-03 23:11:22 +0000 | [diff] [blame] | 2937 | |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 2938 | if (X == Y) |
| 2939 | return true; |
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 | // Must be in the same context. |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 2942 | // |
| 2943 | // Note that we can't use DeclContext::Equals here, because the DeclContexts |
| 2944 | // could be two different declarations of the same function. (We will fix the |
| 2945 | // semantic DC to refer to the primary definition after merging.) |
| 2946 | if (!declaresSameEntity(cast<Decl>(X->getDeclContext()->getRedeclContext()), |
| 2947 | cast<Decl>(Y->getDeclContext()->getRedeclContext()))) |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 2948 | return false; |
Douglas Gregor | 9b7b391 | 2012-01-04 16:44:10 +0000 | [diff] [blame] | 2949 | |
| 2950 | // Two typedefs refer to the same entity if they have the same underlying |
| 2951 | // type. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2952 | if (const auto *TypedefX = dyn_cast<TypedefNameDecl>(X)) |
| 2953 | if (const auto *TypedefY = dyn_cast<TypedefNameDecl>(Y)) |
Douglas Gregor | 9b7b391 | 2012-01-04 16:44:10 +0000 | [diff] [blame] | 2954 | return X->getASTContext().hasSameType(TypedefX->getUnderlyingType(), |
| 2955 | TypedefY->getUnderlyingType()); |
Richard Smith | f463436 | 2014-09-03 23:11:22 +0000 | [diff] [blame] | 2956 | |
Douglas Gregor | 9b7b391 | 2012-01-04 16:44:10 +0000 | [diff] [blame] | 2957 | // Must have the same kind. |
| 2958 | if (X->getKind() != Y->getKind()) |
| 2959 | return false; |
Richard Smith | f463436 | 2014-09-03 23:11:22 +0000 | [diff] [blame] | 2960 | |
Douglas Gregor | da38930 | 2012-01-01 21:47:52 +0000 | [diff] [blame] | 2961 | // Objective-C classes and protocols with the same name always match. |
| 2962 | if (isa<ObjCInterfaceDecl>(X) || isa<ObjCProtocolDecl>(X)) |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 2963 | return true; |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 2964 | |
| 2965 | if (isa<ClassTemplateSpecializationDecl>(X)) { |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2966 | // No need to handle these here: we merge them when adding them to the |
| 2967 | // template. |
Richard Smith | 1d209d0 | 2013-05-23 01:49:11 +0000 | [diff] [blame] | 2968 | return false; |
| 2969 | } |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 2970 | |
Douglas Gregor | 2009cee | 2012-01-03 22:46:00 +0000 | [diff] [blame] | 2971 | // Compatible tags match. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2972 | if (const auto *TagX = dyn_cast<TagDecl>(X)) { |
| 2973 | const auto *TagY = cast<TagDecl>(Y); |
Joao Matos | e9a3ed4 | 2012-08-31 22:18:20 +0000 | [diff] [blame] | 2974 | return (TagX->getTagKind() == TagY->getTagKind()) || |
| 2975 | ((TagX->getTagKind() == TTK_Struct || TagX->getTagKind() == TTK_Class || |
| 2976 | TagX->getTagKind() == TTK_Interface) && |
| 2977 | (TagY->getTagKind() == TTK_Struct || TagY->getTagKind() == TTK_Class || |
| 2978 | TagY->getTagKind() == TTK_Interface)); |
| 2979 | } |
Richard Smith | 8f8f05c | 2013-06-24 04:45:28 +0000 | [diff] [blame] | 2980 | |
Joao Matos | e9a3ed4 | 2012-08-31 22:18:20 +0000 | [diff] [blame] | 2981 | // Functions with the same type and linkage match. |
Richard Smith | f463436 | 2014-09-03 23:11:22 +0000 | [diff] [blame] | 2982 | // FIXME: This needs to cope with merging of prototyped/non-prototyped |
| 2983 | // functions, etc. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 2984 | if (const auto *FuncX = dyn_cast<FunctionDecl>(X)) { |
| 2985 | const auto *FuncY = cast<FunctionDecl>(Y); |
| 2986 | if (const auto *CtorX = dyn_cast<CXXConstructorDecl>(X)) { |
| 2987 | const auto *CtorY = cast<CXXConstructorDecl>(Y); |
Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 2988 | if (CtorX->getInheritedConstructor() && |
| 2989 | !isSameEntity(CtorX->getInheritedConstructor().getConstructor(), |
| 2990 | CtorY->getInheritedConstructor().getConstructor())) |
| 2991 | return false; |
| 2992 | } |
Erich Keane | 281d20b | 2018-01-08 21:34:17 +0000 | [diff] [blame] | 2993 | |
| 2994 | if (FuncX->isMultiVersion() != FuncY->isMultiVersion()) |
| 2995 | return false; |
| 2996 | |
| 2997 | // Multiversioned functions with different feature strings are represented |
| 2998 | // as separate declarations. |
| 2999 | if (FuncX->isMultiVersion()) { |
| 3000 | const auto *TAX = FuncX->getAttr<TargetAttr>(); |
| 3001 | const auto *TAY = FuncY->getAttr<TargetAttr>(); |
| 3002 | assert(TAX && TAY && "Multiversion Function without target attribute"); |
| 3003 | |
| 3004 | if (TAX->getFeaturesStr() != TAY->getFeaturesStr()) |
| 3005 | return false; |
| 3006 | } |
| 3007 | |
Richard Smith | a54d324 | 2017-03-08 23:00:26 +0000 | [diff] [blame] | 3008 | ASTContext &C = FuncX->getASTContext(); |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 3009 | auto GetTypeAsWritten = [](const FunctionDecl *FD) { |
| 3010 | // Map to the first declaration that we've already merged into this one. |
| 3011 | // The TSI of redeclarations might not match (due to calling conventions |
| 3012 | // being inherited onto the type but not the TSI), but the TSI type of |
| 3013 | // the first declaration of the function should match across modules. |
| 3014 | FD = FD->getCanonicalDecl(); |
| 3015 | return FD->getTypeSourceInfo() ? FD->getTypeSourceInfo()->getType() |
| 3016 | : FD->getType(); |
| 3017 | }; |
| 3018 | QualType XT = GetTypeAsWritten(FuncX), YT = GetTypeAsWritten(FuncY); |
| 3019 | if (!C.hasSameType(XT, YT)) { |
Richard Smith | a54d324 | 2017-03-08 23:00:26 +0000 | [diff] [blame] | 3020 | // We can get functions with different types on the redecl chain in C++17 |
| 3021 | // if they have differing exception specifications and at least one of |
| 3022 | // the excpetion specs is unresolved. |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 3023 | auto *XFPT = XT->getAs<FunctionProtoType>(); |
| 3024 | auto *YFPT = YT->getAs<FunctionProtoType>(); |
Aaron Ballman | c351fba | 2017-12-04 20:27:34 +0000 | [diff] [blame] | 3025 | if (C.getLangOpts().CPlusPlus17 && XFPT && YFPT && |
Richard Smith | a54d324 | 2017-03-08 23:00:26 +0000 | [diff] [blame] | 3026 | (isUnresolvedExceptionSpec(XFPT->getExceptionSpecType()) || |
| 3027 | isUnresolvedExceptionSpec(YFPT->getExceptionSpecType())) && |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 3028 | C.hasSameFunctionTypeIgnoringExceptionSpec(XT, YT)) |
Richard Smith | a54d324 | 2017-03-08 23:00:26 +0000 | [diff] [blame] | 3029 | return true; |
| 3030 | return false; |
| 3031 | } |
George Burgess IV | 9584508 | 2017-02-15 22:43:27 +0000 | [diff] [blame] | 3032 | return FuncX->getLinkageInternal() == FuncY->getLinkageInternal() && |
George Burgess IV | 9584508 | 2017-02-15 22:43:27 +0000 | [diff] [blame] | 3033 | hasSameOverloadableAttrs(FuncX, FuncY); |
Douglas Gregor | b258569 | 2012-01-04 17:13:46 +0000 | [diff] [blame] | 3034 | } |
Axel Naumann | 866ba3e | 2012-10-01 09:18:00 +0000 | [diff] [blame] | 3035 | |
Douglas Gregor | b8c6f1e | 2012-01-04 17:21:36 +0000 | [diff] [blame] | 3036 | // Variables with the same type and linkage match. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3037 | if (const auto *VarX = dyn_cast<VarDecl>(X)) { |
| 3038 | const auto *VarY = cast<VarDecl>(Y); |
Yaron Keren | e94da64 | 2016-01-22 19:03:27 +0000 | [diff] [blame] | 3039 | if (VarX->getLinkageInternal() == VarY->getLinkageInternal()) { |
| 3040 | ASTContext &C = VarX->getASTContext(); |
| 3041 | if (C.hasSameType(VarX->getType(), VarY->getType())) |
| 3042 | return true; |
| 3043 | |
| 3044 | // We can get decls with different types on the redecl chain. Eg. |
| 3045 | // template <typename T> struct S { static T Var[]; }; // #1 |
| 3046 | // template <typename T> T S<T>::Var[sizeof(T)]; // #2 |
| 3047 | // Only? happens when completing an incomplete array type. In this case |
Vassil Vassilev | 4d75e8d | 2016-02-28 19:08:24 +0000 | [diff] [blame] | 3048 | // when comparing #1 and #2 we should go through their element type. |
Yaron Keren | e94da64 | 2016-01-22 19:03:27 +0000 | [diff] [blame] | 3049 | const ArrayType *VarXTy = C.getAsArrayType(VarX->getType()); |
| 3050 | const ArrayType *VarYTy = C.getAsArrayType(VarY->getType()); |
| 3051 | if (!VarXTy || !VarYTy) |
| 3052 | return false; |
| 3053 | if (VarXTy->isIncompleteArrayType() || VarYTy->isIncompleteArrayType()) |
| 3054 | return C.hasSameType(VarXTy->getElementType(), VarYTy->getElementType()); |
| 3055 | } |
| 3056 | return false; |
Douglas Gregor | b8c6f1e | 2012-01-04 17:21:36 +0000 | [diff] [blame] | 3057 | } |
Richard Smith | 8f8f05c | 2013-06-24 04:45:28 +0000 | [diff] [blame] | 3058 | |
Douglas Gregor | cfe7dc6 | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 3059 | // Namespaces with the same name and inlinedness match. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3060 | if (const auto *NamespaceX = dyn_cast<NamespaceDecl>(X)) { |
| 3061 | const auto *NamespaceY = cast<NamespaceDecl>(Y); |
Douglas Gregor | cfe7dc6 | 2012-01-09 17:30:44 +0000 | [diff] [blame] | 3062 | return NamespaceX->isInline() == NamespaceY->isInline(); |
| 3063 | } |
Axel Naumann | 866ba3e | 2012-10-01 09:18:00 +0000 | [diff] [blame] | 3064 | |
Richard Smith | 8f8f05c | 2013-06-24 04:45:28 +0000 | [diff] [blame] | 3065 | // Identical template names and kinds match if their template parameter lists |
| 3066 | // and patterns match. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3067 | if (const auto *TemplateX = dyn_cast<TemplateDecl>(X)) { |
| 3068 | const auto *TemplateY = cast<TemplateDecl>(Y); |
Richard Smith | 8f8f05c | 2013-06-24 04:45:28 +0000 | [diff] [blame] | 3069 | return isSameEntity(TemplateX->getTemplatedDecl(), |
Richard Smith | bf78e64 | 2013-06-24 22:51:00 +0000 | [diff] [blame] | 3070 | TemplateY->getTemplatedDecl()) && |
| 3071 | isSameTemplateParameterList(TemplateX->getTemplateParameters(), |
| 3072 | TemplateY->getTemplateParameters()); |
Richard Smith | 8f8f05c | 2013-06-24 04:45:28 +0000 | [diff] [blame] | 3073 | } |
Axel Naumann | 866ba3e | 2012-10-01 09:18:00 +0000 | [diff] [blame] | 3074 | |
Richard Smith | 0b87e07 | 2013-10-07 08:02:11 +0000 | [diff] [blame] | 3075 | // Fields with the same name and the same type match. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3076 | if (const auto *FDX = dyn_cast<FieldDecl>(X)) { |
| 3077 | const auto *FDY = cast<FieldDecl>(Y); |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame] | 3078 | // FIXME: Also check the bitwidth is odr-equivalent, if any. |
Richard Smith | 0b87e07 | 2013-10-07 08:02:11 +0000 | [diff] [blame] | 3079 | return X->getASTContext().hasSameType(FDX->getType(), FDY->getType()); |
| 3080 | } |
| 3081 | |
Richard Smith | 8cbd895 | 2015-08-04 02:05:09 +0000 | [diff] [blame] | 3082 | // Indirect fields with the same target field match. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3083 | if (const auto *IFDX = dyn_cast<IndirectFieldDecl>(X)) { |
| 3084 | const auto *IFDY = cast<IndirectFieldDecl>(Y); |
Richard Smith | 8cbd895 | 2015-08-04 02:05:09 +0000 | [diff] [blame] | 3085 | return IFDX->getAnonField()->getCanonicalDecl() == |
| 3086 | IFDY->getAnonField()->getCanonicalDecl(); |
| 3087 | } |
| 3088 | |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame] | 3089 | // Enumerators with the same name match. |
| 3090 | if (isa<EnumConstantDecl>(X)) |
| 3091 | // FIXME: Also check the value is odr-equivalent. |
| 3092 | return true; |
| 3093 | |
Richard Smith | fd8634a | 2013-10-23 02:17:46 +0000 | [diff] [blame] | 3094 | // Using shadow declarations with the same target match. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3095 | if (const auto *USX = dyn_cast<UsingShadowDecl>(X)) { |
| 3096 | const auto *USY = cast<UsingShadowDecl>(Y); |
Richard Smith | fd8634a | 2013-10-23 02:17:46 +0000 | [diff] [blame] | 3097 | return USX->getTargetDecl() == USY->getTargetDecl(); |
| 3098 | } |
| 3099 | |
Richard Smith | 32952e1 | 2014-10-14 02:00:47 +0000 | [diff] [blame] | 3100 | // Using declarations with the same qualifier match. (We already know that |
| 3101 | // the name matches.) |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3102 | if (const auto *UX = dyn_cast<UsingDecl>(X)) { |
| 3103 | const auto *UY = cast<UsingDecl>(Y); |
Richard Smith | 32952e1 | 2014-10-14 02:00:47 +0000 | [diff] [blame] | 3104 | return isSameQualifier(UX->getQualifier(), UY->getQualifier()) && |
| 3105 | UX->hasTypename() == UY->hasTypename() && |
| 3106 | UX->isAccessDeclaration() == UY->isAccessDeclaration(); |
| 3107 | } |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3108 | if (const auto *UX = dyn_cast<UnresolvedUsingValueDecl>(X)) { |
| 3109 | const auto *UY = cast<UnresolvedUsingValueDecl>(Y); |
Richard Smith | 32952e1 | 2014-10-14 02:00:47 +0000 | [diff] [blame] | 3110 | return isSameQualifier(UX->getQualifier(), UY->getQualifier()) && |
| 3111 | UX->isAccessDeclaration() == UY->isAccessDeclaration(); |
| 3112 | } |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3113 | if (const auto *UX = dyn_cast<UnresolvedUsingTypenameDecl>(X)) |
Richard Smith | 32952e1 | 2014-10-14 02:00:47 +0000 | [diff] [blame] | 3114 | return isSameQualifier( |
| 3115 | UX->getQualifier(), |
| 3116 | cast<UnresolvedUsingTypenameDecl>(Y)->getQualifier()); |
| 3117 | |
Richard Smith | f463436 | 2014-09-03 23:11:22 +0000 | [diff] [blame] | 3118 | // Namespace alias definitions with the same target match. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3119 | if (const auto *NAX = dyn_cast<NamespaceAliasDecl>(X)) { |
| 3120 | const auto *NAY = cast<NamespaceAliasDecl>(Y); |
Richard Smith | f463436 | 2014-09-03 23:11:22 +0000 | [diff] [blame] | 3121 | return NAX->getNamespace()->Equals(NAY->getNamespace()); |
| 3122 | } |
| 3123 | |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 3124 | return false; |
| 3125 | } |
| 3126 | |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 3127 | /// Find the context in which we should search for previous declarations when |
| 3128 | /// looking for declarations to merge. |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 3129 | DeclContext *ASTDeclReader::getPrimaryContextForMerging(ASTReader &Reader, |
| 3130 | DeclContext *DC) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3131 | if (auto *ND = dyn_cast<NamespaceDecl>(DC)) |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 3132 | return ND->getOriginalNamespace(); |
| 3133 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3134 | if (auto *RD = dyn_cast<CXXRecordDecl>(DC)) { |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 3135 | // Try to dig out the definition. |
Richard Smith | b648399 | 2016-05-17 22:44:15 +0000 | [diff] [blame] | 3136 | auto *DD = RD->DefinitionData; |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 3137 | if (!DD) |
Richard Smith | b648399 | 2016-05-17 22:44:15 +0000 | [diff] [blame] | 3138 | DD = RD->getCanonicalDecl()->DefinitionData; |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 3139 | |
| 3140 | // If there's no definition yet, then DC's definition is added by an update |
| 3141 | // record, but we've not yet loaded that update record. In this case, we |
| 3142 | // commit to DC being the canonical definition now, and will fix this when |
| 3143 | // we load the update record. |
| 3144 | if (!DD) { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 3145 | DD = new (Reader.getContext()) struct CXXRecordDecl::DefinitionData(RD); |
Erich Keane | f92f31c | 2018-08-01 20:48:16 +0000 | [diff] [blame] | 3146 | RD->setCompleteDefinition(true); |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 3147 | RD->DefinitionData = DD; |
| 3148 | RD->getCanonicalDecl()->DefinitionData = DD; |
| 3149 | |
| 3150 | // 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] | 3151 | Reader.PendingFakeDefinitionData.insert( |
| 3152 | std::make_pair(DD, ASTReader::PendingFakeDefinitionKind::Fake)); |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 3153 | } |
| 3154 | |
| 3155 | return DD->Definition; |
| 3156 | } |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 3157 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3158 | if (auto *ED = dyn_cast<EnumDecl>(DC)) |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 3159 | return ED->getASTContext().getLangOpts().CPlusPlus? ED->getDefinition() |
| 3160 | : nullptr; |
Richard Smith | 01a7337 | 2013-10-15 22:02:41 +0000 | [diff] [blame] | 3161 | |
Richard Smith | 4eca9b9 | 2015-02-04 23:37:59 +0000 | [diff] [blame] | 3162 | // We can see the TU here only if we have no Sema object. In that case, |
| 3163 | // there's no TU scope to look in, so using the DC alone is sufficient. |
| 3164 | if (auto *TU = dyn_cast<TranslationUnitDecl>(DC)) |
| 3165 | return TU; |
| 3166 | |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 3167 | return nullptr; |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 3168 | } |
| 3169 | |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 3170 | ASTDeclReader::FindExistingResult::~FindExistingResult() { |
Richard Smith | f1f4bc2 | 2015-01-22 02:21:23 +0000 | [diff] [blame] | 3171 | // Record that we had a typedef name for linkage whether or not we merge |
| 3172 | // with that declaration. |
| 3173 | if (TypedefNameForLinkage) { |
| 3174 | DeclContext *DC = New->getDeclContext()->getRedeclContext(); |
| 3175 | Reader.ImportedTypedefNamesForLinkage.insert( |
| 3176 | std::make_pair(std::make_pair(DC, TypedefNameForLinkage), New)); |
| 3177 | return; |
| 3178 | } |
| 3179 | |
Douglas Gregor | 9b47f94 | 2012-01-09 17:38:47 +0000 | [diff] [blame] | 3180 | if (!AddResult || Existing) |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 3181 | return; |
Richard Smith | 95d9930 | 2013-07-13 02:00:19 +0000 | [diff] [blame] | 3182 | |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 3183 | DeclarationName Name = New->getDeclName(); |
Richard Smith | 95d9930 | 2013-07-13 02:00:19 +0000 | [diff] [blame] | 3184 | DeclContext *DC = New->getDeclContext()->getRedeclContext(); |
Richard Smith | 2b56057 | 2015-02-07 03:11:11 +0000 | [diff] [blame] | 3185 | if (needsAnonymousDeclarationNumber(New)) { |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3186 | setAnonymousDeclForMerging(Reader, New->getLexicalDeclContext(), |
| 3187 | AnonymousDeclNumber, New); |
Richard Smith | 1037909 | 2016-05-06 23:14:07 +0000 | [diff] [blame] | 3188 | } else if (DC->isTranslationUnit() && |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 3189 | !Reader.getContext().getLangOpts().CPlusPlus) { |
Richard Smith | 1037909 | 2016-05-06 23:14:07 +0000 | [diff] [blame] | 3190 | if (Reader.getIdResolver().tryAddTopLevelDecl(New, Name)) |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 3191 | Reader.PendingFakeLookupResults[Name.getAsIdentifierInfo()] |
| 3192 | .push_back(New); |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 3193 | } else if (DeclContext *MergeDC = getPrimaryContextForMerging(Reader, DC)) { |
Richard Smith | 95d9930 | 2013-07-13 02:00:19 +0000 | [diff] [blame] | 3194 | // Add the declaration to its redeclaration context so later merging |
| 3195 | // lookups will find it. |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 3196 | MergeDC->makeDeclVisibleInContextImpl(New, /*Internal*/true); |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 3197 | } |
| 3198 | } |
| 3199 | |
Richard Smith | 88ebade | 2014-08-23 01:45:27 +0000 | [diff] [blame] | 3200 | /// Find the declaration that should be merged into, given the declaration found |
| 3201 | /// by name lookup. If we're merging an anonymous declaration within a typedef, |
| 3202 | /// we need a matching typedef, and we merge with the type inside it. |
| 3203 | static NamedDecl *getDeclForMerging(NamedDecl *Found, |
| 3204 | bool IsTypedefNameForLinkage) { |
| 3205 | if (!IsTypedefNameForLinkage) |
| 3206 | return Found; |
| 3207 | |
| 3208 | // If we found a typedef declaration that gives a name to some other |
| 3209 | // declaration, then we want that inner declaration. Declarations from |
| 3210 | // AST files are handled via ImportedTypedefNamesForLinkage. |
Richard Smith | a523022 | 2015-03-27 01:37:43 +0000 | [diff] [blame] | 3211 | if (Found->isFromASTFile()) |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 3212 | return nullptr; |
Richard Smith | a523022 | 2015-03-27 01:37:43 +0000 | [diff] [blame] | 3213 | |
| 3214 | if (auto *TND = dyn_cast<TypedefNameDecl>(Found)) |
Richard Smith | 3fb1a85 | 2016-08-30 19:13:18 +0000 | [diff] [blame] | 3215 | return TND->getAnonDeclWithTypedefName(/*AnyRedecl*/true); |
Richard Smith | 88ebade | 2014-08-23 01:45:27 +0000 | [diff] [blame] | 3216 | |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 3217 | return nullptr; |
Richard Smith | 88ebade | 2014-08-23 01:45:27 +0000 | [diff] [blame] | 3218 | } |
| 3219 | |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 3220 | /// Find the declaration to use to populate the anonymous declaration table |
| 3221 | /// for the given lexical DeclContext. We only care about finding local |
| 3222 | /// definitions of the context; we'll merge imported ones as we go. |
| 3223 | DeclContext * |
| 3224 | ASTDeclReader::getPrimaryDCForAnonymousDecl(DeclContext *LexicalDC) { |
| 3225 | // For classes, we track the definition as we merge. |
| 3226 | if (auto *RD = dyn_cast<CXXRecordDecl>(LexicalDC)) { |
| 3227 | auto *DD = RD->getCanonicalDecl()->DefinitionData; |
| 3228 | return DD ? DD->Definition : nullptr; |
| 3229 | } |
| 3230 | |
| 3231 | // For anything else, walk its merged redeclarations looking for a definition. |
| 3232 | // Note that we can't just call getDefinition here because the redeclaration |
| 3233 | // chain isn't wired up. |
| 3234 | for (auto *D : merged_redecls(cast<Decl>(LexicalDC))) { |
| 3235 | if (auto *FD = dyn_cast<FunctionDecl>(D)) |
| 3236 | if (FD->isThisDeclarationADefinition()) |
| 3237 | return FD; |
| 3238 | if (auto *MD = dyn_cast<ObjCMethodDecl>(D)) |
| 3239 | if (MD->isThisDeclarationADefinition()) |
| 3240 | return MD; |
| 3241 | } |
| 3242 | |
| 3243 | // No merged definition yet. |
| 3244 | return nullptr; |
| 3245 | } |
| 3246 | |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3247 | NamedDecl *ASTDeclReader::getAnonymousDeclForMerging(ASTReader &Reader, |
| 3248 | DeclContext *DC, |
| 3249 | unsigned Index) { |
| 3250 | // If the lexical context has been merged, look into the now-canonical |
| 3251 | // definition. |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 3252 | auto *CanonDC = cast<Decl>(DC)->getCanonicalDecl(); |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3253 | |
| 3254 | // If we've seen this before, return the canonical declaration. |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 3255 | auto &Previous = Reader.AnonymousDeclarationsForMerging[CanonDC]; |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3256 | if (Index < Previous.size() && Previous[Index]) |
| 3257 | return Previous[Index]; |
| 3258 | |
| 3259 | // If this is the first time, but we have parsed a declaration of the context, |
| 3260 | // build the anonymous declaration list from the parsed declaration. |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 3261 | auto *PrimaryDC = getPrimaryDCForAnonymousDecl(DC); |
| 3262 | if (PrimaryDC && !cast<Decl>(PrimaryDC)->isFromASTFile()) { |
| 3263 | numberAnonymousDeclsWithin(PrimaryDC, [&](NamedDecl *ND, unsigned Number) { |
Richard Smith | 2b56057 | 2015-02-07 03:11:11 +0000 | [diff] [blame] | 3264 | if (Previous.size() == Number) |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3265 | Previous.push_back(cast<NamedDecl>(ND->getCanonicalDecl())); |
| 3266 | else |
Richard Smith | 2b56057 | 2015-02-07 03:11:11 +0000 | [diff] [blame] | 3267 | Previous[Number] = cast<NamedDecl>(ND->getCanonicalDecl()); |
| 3268 | }); |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3269 | } |
| 3270 | |
| 3271 | return Index < Previous.size() ? Previous[Index] : nullptr; |
| 3272 | } |
| 3273 | |
| 3274 | void ASTDeclReader::setAnonymousDeclForMerging(ASTReader &Reader, |
| 3275 | DeclContext *DC, unsigned Index, |
| 3276 | NamedDecl *D) { |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 3277 | auto *CanonDC = cast<Decl>(DC)->getCanonicalDecl(); |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3278 | |
Richard Smith | 600adef | 2018-07-04 02:25:38 +0000 | [diff] [blame] | 3279 | auto &Previous = Reader.AnonymousDeclarationsForMerging[CanonDC]; |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3280 | if (Index >= Previous.size()) |
| 3281 | Previous.resize(Index + 1); |
| 3282 | if (!Previous[Index]) |
| 3283 | Previous[Index] = D; |
| 3284 | } |
| 3285 | |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 3286 | ASTDeclReader::FindExistingResult ASTDeclReader::findExisting(NamedDecl *D) { |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 3287 | DeclarationName Name = TypedefNameForLinkage ? TypedefNameForLinkage |
| 3288 | : D->getDeclName(); |
Richard Smith | 88ebade | 2014-08-23 01:45:27 +0000 | [diff] [blame] | 3289 | |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3290 | if (!Name && !needsAnonymousDeclarationNumber(D)) { |
| 3291 | // Don't bother trying to find unnamed declarations that are in |
| 3292 | // unmergeable contexts. |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 3293 | FindExistingResult Result(Reader, D, /*Existing=*/nullptr, |
| 3294 | AnonymousDeclNumber, TypedefNameForLinkage); |
Douglas Gregor | 2009cee | 2012-01-03 22:46:00 +0000 | [diff] [blame] | 3295 | Result.suppress(); |
| 3296 | return Result; |
| 3297 | } |
Richard Smith | 95d9930 | 2013-07-13 02:00:19 +0000 | [diff] [blame] | 3298 | |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 3299 | DeclContext *DC = D->getDeclContext()->getRedeclContext(); |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 3300 | if (TypedefNameForLinkage) { |
Richard Smith | 88ebade | 2014-08-23 01:45:27 +0000 | [diff] [blame] | 3301 | auto It = Reader.ImportedTypedefNamesForLinkage.find( |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 3302 | std::make_pair(DC, TypedefNameForLinkage)); |
Richard Smith | 88ebade | 2014-08-23 01:45:27 +0000 | [diff] [blame] | 3303 | if (It != Reader.ImportedTypedefNamesForLinkage.end()) |
| 3304 | if (isSameEntity(It->second, D)) |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 3305 | return FindExistingResult(Reader, D, It->second, AnonymousDeclNumber, |
| 3306 | TypedefNameForLinkage); |
Richard Smith | 88ebade | 2014-08-23 01:45:27 +0000 | [diff] [blame] | 3307 | // Go on to check in other places in case an existing typedef name |
| 3308 | // was not imported. |
| 3309 | } |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3310 | |
Richard Smith | 2b56057 | 2015-02-07 03:11:11 +0000 | [diff] [blame] | 3311 | if (needsAnonymousDeclarationNumber(D)) { |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3312 | // This is an anonymous declaration that we may need to merge. Look it up |
| 3313 | // in its context by number. |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3314 | if (auto *Existing = getAnonymousDeclForMerging( |
| 3315 | Reader, D->getLexicalDeclContext(), AnonymousDeclNumber)) |
| 3316 | if (isSameEntity(Existing, D)) |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 3317 | return FindExistingResult(Reader, D, Existing, AnonymousDeclNumber, |
| 3318 | TypedefNameForLinkage); |
Richard Smith | 1037909 | 2016-05-06 23:14:07 +0000 | [diff] [blame] | 3319 | } else if (DC->isTranslationUnit() && |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 3320 | !Reader.getContext().getLangOpts().CPlusPlus) { |
Richard Smith | 1037909 | 2016-05-06 23:14:07 +0000 | [diff] [blame] | 3321 | IdentifierResolver &IdResolver = Reader.getIdResolver(); |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 3322 | |
| 3323 | // Temporarily consider the identifier to be up-to-date. We don't want to |
| 3324 | // cause additional lookups here. |
| 3325 | class UpToDateIdentifierRAII { |
| 3326 | IdentifierInfo *II; |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3327 | bool WasOutToDate = false; |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 3328 | |
| 3329 | public: |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3330 | explicit UpToDateIdentifierRAII(IdentifierInfo *II) : II(II) { |
Douglas Gregor | 6168bd2 | 2013-02-18 15:53:43 +0000 | [diff] [blame] | 3331 | if (II) { |
| 3332 | WasOutToDate = II->isOutOfDate(); |
| 3333 | if (WasOutToDate) |
| 3334 | II->setOutOfDate(false); |
| 3335 | } |
| 3336 | } |
| 3337 | |
| 3338 | ~UpToDateIdentifierRAII() { |
| 3339 | if (WasOutToDate) |
| 3340 | II->setOutOfDate(true); |
| 3341 | } |
| 3342 | } UpToDate(Name.getAsIdentifierInfo()); |
| 3343 | |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3344 | for (IdentifierResolver::iterator I = IdResolver.begin(Name), |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 3345 | IEnd = IdResolver.end(); |
| 3346 | I != IEnd; ++I) { |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 3347 | if (NamedDecl *Existing = getDeclForMerging(*I, TypedefNameForLinkage)) |
Richard Smith | 87dacc7 | 2014-08-25 23:33:46 +0000 | [diff] [blame] | 3348 | if (isSameEntity(Existing, D)) |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 3349 | return FindExistingResult(Reader, D, Existing, AnonymousDeclNumber, |
| 3350 | TypedefNameForLinkage); |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 3351 | } |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 3352 | } else if (DeclContext *MergeDC = getPrimaryContextForMerging(Reader, DC)) { |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 3353 | DeclContext::lookup_result R = MergeDC->noload_lookup(Name); |
Richard Smith | 95d9930 | 2013-07-13 02:00:19 +0000 | [diff] [blame] | 3354 | 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] | 3355 | if (NamedDecl *Existing = getDeclForMerging(*I, TypedefNameForLinkage)) |
Richard Smith | 88ebade | 2014-08-23 01:45:27 +0000 | [diff] [blame] | 3356 | if (isSameEntity(Existing, D)) |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 3357 | return FindExistingResult(Reader, D, Existing, AnonymousDeclNumber, |
| 3358 | TypedefNameForLinkage); |
Douglas Gregor | 9b47f94 | 2012-01-09 17:38:47 +0000 | [diff] [blame] | 3359 | } |
Richard Smith | 2b9e3e3 | 2013-10-18 06:05:18 +0000 | [diff] [blame] | 3360 | } else { |
| 3361 | // Not in a mergeable context. |
| 3362 | return FindExistingResult(Reader); |
Douglas Gregor | 9b47f94 | 2012-01-09 17:38:47 +0000 | [diff] [blame] | 3363 | } |
Richard Smith | d55889a | 2013-09-09 16:55:27 +0000 | [diff] [blame] | 3364 | |
Richard Smith | 2b9e3e3 | 2013-10-18 06:05:18 +0000 | [diff] [blame] | 3365 | // If this declaration is from a merged context, make a note that we need to |
| 3366 | // check that the canonical definition of that context contains the decl. |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 3367 | // |
| 3368 | // FIXME: We should do something similar if we merge two definitions of the |
| 3369 | // same template specialization into the same CXXRecordDecl. |
Richard Smith | 88126a2 | 2014-08-25 02:10:01 +0000 | [diff] [blame] | 3370 | auto MergedDCIt = Reader.MergedDeclContexts.find(D->getLexicalDeclContext()); |
| 3371 | if (MergedDCIt != Reader.MergedDeclContexts.end() && |
| 3372 | MergedDCIt->second == D->getDeclContext()) |
Richard Smith | 2b9e3e3 | 2013-10-18 06:05:18 +0000 | [diff] [blame] | 3373 | Reader.PendingOdrMergeChecks.push_back(D); |
| 3374 | |
Richard Smith | d08aeb6 | 2014-08-28 01:33:39 +0000 | [diff] [blame] | 3375 | return FindExistingResult(Reader, D, /*Existing=*/nullptr, |
Richard Smith | 70d5850 | 2014-08-30 00:04:23 +0000 | [diff] [blame] | 3376 | AnonymousDeclNumber, TypedefNameForLinkage); |
Douglas Gregor | 022857e | 2011-12-22 01:48:48 +0000 | [diff] [blame] | 3377 | } |
| 3378 | |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 3379 | template<typename DeclT> |
Richard Smith | c3a5325 | 2015-02-28 05:57:02 +0000 | [diff] [blame] | 3380 | Decl *ASTDeclReader::getMostRecentDeclImpl(Redeclarable<DeclT> *D) { |
| 3381 | return D->RedeclLink.getLatestNotUpdated(); |
| 3382 | } |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3383 | |
Richard Smith | c3a5325 | 2015-02-28 05:57:02 +0000 | [diff] [blame] | 3384 | Decl *ASTDeclReader::getMostRecentDeclImpl(...) { |
| 3385 | llvm_unreachable("getMostRecentDecl on non-redeclarable declaration"); |
| 3386 | } |
| 3387 | |
| 3388 | Decl *ASTDeclReader::getMostRecentDecl(Decl *D) { |
| 3389 | assert(D); |
| 3390 | |
| 3391 | switch (D->getKind()) { |
| 3392 | #define ABSTRACT_DECL(TYPE) |
| 3393 | #define DECL(TYPE, BASE) \ |
| 3394 | case Decl::TYPE: \ |
| 3395 | return getMostRecentDeclImpl(cast<TYPE##Decl>(D)); |
| 3396 | #include "clang/AST/DeclNodes.inc" |
| 3397 | } |
| 3398 | llvm_unreachable("unknown decl kind"); |
| 3399 | } |
| 3400 | |
Richard Smith | 8ce5108 | 2015-03-11 01:44:51 +0000 | [diff] [blame] | 3401 | Decl *ASTReader::getMostRecentExistingDecl(Decl *D) { |
| 3402 | return ASTDeclReader::getMostRecentDecl(D->getCanonicalDecl()); |
| 3403 | } |
| 3404 | |
Richard Smith | c3a5325 | 2015-02-28 05:57:02 +0000 | [diff] [blame] | 3405 | template<typename DeclT> |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 3406 | void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader, |
| 3407 | Redeclarable<DeclT> *D, |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 3408 | Decl *Previous, Decl *Canon) { |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 3409 | D->RedeclLink.setPrevious(cast<DeclT>(Previous)); |
Manuel Klimek | 093b2d4 | 2015-03-25 23:18:30 +0000 | [diff] [blame] | 3410 | D->First = cast<DeclT>(Previous)->First; |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 3411 | } |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 3412 | |
Richard Smith | 24d166c | 2014-07-31 23:52:38 +0000 | [diff] [blame] | 3413 | namespace clang { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3414 | |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 3415 | template<> |
| 3416 | void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader, |
Richard Smith | edbc6e9 | 2016-10-14 21:41:24 +0000 | [diff] [blame] | 3417 | Redeclarable<VarDecl> *D, |
| 3418 | Decl *Previous, Decl *Canon) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3419 | auto *VD = static_cast<VarDecl *>(D); |
| 3420 | auto *PrevVD = cast<VarDecl>(Previous); |
Richard Smith | edbc6e9 | 2016-10-14 21:41:24 +0000 | [diff] [blame] | 3421 | D->RedeclLink.setPrevious(PrevVD); |
| 3422 | D->First = PrevVD->First; |
| 3423 | |
| 3424 | // We should keep at most one definition on the chain. |
| 3425 | // FIXME: Cache the definition once we've found it. Building a chain with |
| 3426 | // N definitions currently takes O(N^2) time here. |
| 3427 | if (VD->isThisDeclarationADefinition() == VarDecl::Definition) { |
| 3428 | for (VarDecl *CurD = PrevVD; CurD; CurD = CurD->getPreviousDecl()) { |
| 3429 | if (CurD->isThisDeclarationADefinition() == VarDecl::Definition) { |
| 3430 | Reader.mergeDefinitionVisibility(CurD, VD); |
| 3431 | VD->demoteThisDefinitionToDeclaration(); |
| 3432 | break; |
| 3433 | } |
| 3434 | } |
| 3435 | } |
| 3436 | } |
| 3437 | |
Richard Smith | a62d198 | 2018-08-03 01:00:01 +0000 | [diff] [blame] | 3438 | static bool isUndeducedReturnType(QualType T) { |
| 3439 | auto *DT = T->getContainedDeducedType(); |
| 3440 | return DT && !DT->isDeduced(); |
| 3441 | } |
| 3442 | |
Richard Smith | edbc6e9 | 2016-10-14 21:41:24 +0000 | [diff] [blame] | 3443 | template<> |
| 3444 | void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader, |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 3445 | Redeclarable<FunctionDecl> *D, |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 3446 | Decl *Previous, Decl *Canon) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3447 | auto *FD = static_cast<FunctionDecl *>(D); |
| 3448 | auto *PrevFD = cast<FunctionDecl>(Previous); |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 3449 | |
| 3450 | FD->RedeclLink.setPrevious(PrevFD); |
Manuel Klimek | 093b2d4 | 2015-03-25 23:18:30 +0000 | [diff] [blame] | 3451 | FD->First = PrevFD->First; |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 3452 | |
| 3453 | // If the previous declaration is an inline function declaration, then this |
| 3454 | // declaration is too. |
Erich Keane | 9c66506 | 2018-08-01 21:02:40 +0000 | [diff] [blame] | 3455 | if (PrevFD->isInlined() != FD->isInlined()) { |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 3456 | // FIXME: [dcl.fct.spec]p4: |
| 3457 | // If a function with external linkage is declared inline in one |
| 3458 | // translation unit, it shall be declared inline in all translation |
| 3459 | // units in which it appears. |
| 3460 | // |
| 3461 | // Be careful of this case: |
| 3462 | // |
| 3463 | // module A: |
| 3464 | // template<typename T> struct X { void f(); }; |
| 3465 | // template<typename T> inline void X<T>::f() {} |
| 3466 | // |
| 3467 | // module B instantiates the declaration of X<int>::f |
| 3468 | // module C instantiates the definition of X<int>::f |
| 3469 | // |
| 3470 | // 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] | 3471 | FD->setImplicitlyInline(true); |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 3472 | } |
| 3473 | |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 3474 | auto *FPT = FD->getType()->getAs<FunctionProtoType>(); |
| 3475 | auto *PrevFPT = PrevFD->getType()->getAs<FunctionProtoType>(); |
Richard Smith | 8096975 | 2015-03-10 02:00:53 +0000 | [diff] [blame] | 3476 | if (FPT && PrevFPT) { |
Richard Smith | a62d198 | 2018-08-03 01:00:01 +0000 | [diff] [blame] | 3477 | // If we need to propagate an exception specification along the redecl |
| 3478 | // 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] | 3479 | bool IsUnresolved = isUnresolvedExceptionSpec(FPT->getExceptionSpecType()); |
| 3480 | bool WasUnresolved = |
| 3481 | isUnresolvedExceptionSpec(PrevFPT->getExceptionSpecType()); |
| 3482 | if (IsUnresolved != WasUnresolved) |
| 3483 | Reader.PendingExceptionSpecUpdates.insert( |
Richard Smith | a62d198 | 2018-08-03 01:00:01 +0000 | [diff] [blame] | 3484 | {Canon, IsUnresolved ? PrevFD : FD}); |
| 3485 | |
| 3486 | // If we need to propagate a deduced return type along the redecl chain, |
| 3487 | // make a note of that so that we can do it later. |
| 3488 | bool IsUndeduced = isUndeducedReturnType(FPT->getReturnType()); |
| 3489 | bool WasUndeduced = isUndeducedReturnType(PrevFPT->getReturnType()); |
| 3490 | if (IsUndeduced != WasUndeduced) |
| 3491 | Reader.PendingDeducedTypeUpdates.insert( |
| 3492 | {cast<FunctionDecl>(Canon), |
| 3493 | (IsUndeduced ? PrevFPT : FPT)->getReturnType()}); |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 3494 | } |
| 3495 | } |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3496 | |
| 3497 | } // namespace clang |
Hans Wennborg | dcfba33 | 2015-10-06 23:40:43 +0000 | [diff] [blame] | 3498 | |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 3499 | void ASTDeclReader::attachPreviousDeclImpl(ASTReader &Reader, ...) { |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 3500 | llvm_unreachable("attachPreviousDecl on non-redeclarable declaration"); |
| 3501 | } |
| 3502 | |
Richard Smith | 8346e52 | 2015-06-10 01:47:58 +0000 | [diff] [blame] | 3503 | /// Inherit the default template argument from \p From to \p To. Returns |
| 3504 | /// \c false if there is no default template for \p From. |
| 3505 | template <typename ParmDecl> |
| 3506 | static bool inheritDefaultTemplateArgument(ASTContext &Context, ParmDecl *From, |
| 3507 | Decl *ToD) { |
| 3508 | auto *To = cast<ParmDecl>(ToD); |
| 3509 | if (!From->hasDefaultArgument()) |
| 3510 | return false; |
Richard Smith | e7bd6de | 2015-06-10 20:30:23 +0000 | [diff] [blame] | 3511 | To->setInheritedDefaultArgument(Context, From); |
Richard Smith | 8346e52 | 2015-06-10 01:47:58 +0000 | [diff] [blame] | 3512 | return true; |
| 3513 | } |
| 3514 | |
| 3515 | static void inheritDefaultTemplateArguments(ASTContext &Context, |
| 3516 | TemplateDecl *From, |
| 3517 | TemplateDecl *To) { |
| 3518 | auto *FromTP = From->getTemplateParameters(); |
| 3519 | auto *ToTP = To->getTemplateParameters(); |
| 3520 | assert(FromTP->size() == ToTP->size() && "merged mismatched templates?"); |
| 3521 | |
| 3522 | for (unsigned I = 0, N = FromTP->size(); I != N; ++I) { |
Richard Smith | 559cc69 | 2018-07-31 21:01:53 +0000 | [diff] [blame] | 3523 | NamedDecl *FromParam = FromTP->getParam(I); |
| 3524 | NamedDecl *ToParam = ToTP->getParam(I); |
Richard Smith | 8346e52 | 2015-06-10 01:47:58 +0000 | [diff] [blame] | 3525 | |
Richard Smith | 559cc69 | 2018-07-31 21:01:53 +0000 | [diff] [blame] | 3526 | if (auto *FTTP = dyn_cast<TemplateTypeParmDecl>(FromParam)) |
| 3527 | inheritDefaultTemplateArgument(Context, FTTP, ToParam); |
| 3528 | else if (auto *FNTTP = dyn_cast<NonTypeTemplateParmDecl>(FromParam)) |
| 3529 | inheritDefaultTemplateArgument(Context, FNTTP, ToParam); |
| 3530 | else |
| 3531 | inheritDefaultTemplateArgument( |
| 3532 | Context, cast<TemplateTemplateParmDecl>(FromParam), ToParam); |
Richard Smith | 8346e52 | 2015-06-10 01:47:58 +0000 | [diff] [blame] | 3533 | } |
| 3534 | } |
| 3535 | |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 3536 | void ASTDeclReader::attachPreviousDecl(ASTReader &Reader, Decl *D, |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 3537 | Decl *Previous, Decl *Canon) { |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 3538 | assert(D && Previous); |
| 3539 | |
| 3540 | switch (D->getKind()) { |
| 3541 | #define ABSTRACT_DECL(TYPE) |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 3542 | #define DECL(TYPE, BASE) \ |
| 3543 | case Decl::TYPE: \ |
| 3544 | attachPreviousDeclImpl(Reader, cast<TYPE##Decl>(D), Previous, Canon); \ |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 3545 | break; |
| 3546 | #include "clang/AST/DeclNodes.inc" |
Argyrios Kyrtzidis | 9fdd254 | 2011-02-12 07:50:47 +0000 | [diff] [blame] | 3547 | } |
Richard Smith | 7ecc31b | 2013-08-02 01:09:12 +0000 | [diff] [blame] | 3548 | |
| 3549 | // If the declaration was visible in one module, a redeclaration of it in |
| 3550 | // another module remains visible even if it wouldn't be visible by itself. |
| 3551 | // |
| 3552 | // FIXME: In this case, the declaration should only be visible if a module |
| 3553 | // that makes it visible has been imported. |
Richard Smith | 7ecc31b | 2013-08-02 01:09:12 +0000 | [diff] [blame] | 3554 | D->IdentifierNamespace |= |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 3555 | Previous->IdentifierNamespace & |
Richard Smith | 7ecc31b | 2013-08-02 01:09:12 +0000 | [diff] [blame] | 3556 | (Decl::IDNS_Ordinary | Decl::IDNS_Tag | Decl::IDNS_Type); |
Richard Smith | 195d8ef | 2014-05-29 03:15:31 +0000 | [diff] [blame] | 3557 | |
Richard Smith | 8346e52 | 2015-06-10 01:47:58 +0000 | [diff] [blame] | 3558 | // If the declaration declares a template, it may inherit default arguments |
| 3559 | // from the previous declaration. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3560 | if (auto *TD = dyn_cast<TemplateDecl>(D)) |
Richard Smith | 8346e52 | 2015-06-10 01:47:58 +0000 | [diff] [blame] | 3561 | inheritDefaultTemplateArguments(Reader.getContext(), |
| 3562 | cast<TemplateDecl>(Previous), TD); |
Argyrios Kyrtzidis | 9fdd254 | 2011-02-12 07:50:47 +0000 | [diff] [blame] | 3563 | } |
| 3564 | |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 3565 | template<typename DeclT> |
| 3566 | void ASTDeclReader::attachLatestDeclImpl(Redeclarable<DeclT> *D, Decl *Latest) { |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 3567 | D->RedeclLink.setLatest(cast<DeclT>(Latest)); |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 3568 | } |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3569 | |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 3570 | void ASTDeclReader::attachLatestDeclImpl(...) { |
| 3571 | llvm_unreachable("attachLatestDecl on non-redeclarable declaration"); |
| 3572 | } |
| 3573 | |
Douglas Gregor | 05f1035 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 3574 | void ASTDeclReader::attachLatestDecl(Decl *D, Decl *Latest) { |
| 3575 | assert(D && Latest); |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 3576 | |
| 3577 | switch (D->getKind()) { |
| 3578 | #define ABSTRACT_DECL(TYPE) |
Richard Smith | 053f6c6 | 2014-05-16 23:01:30 +0000 | [diff] [blame] | 3579 | #define DECL(TYPE, BASE) \ |
| 3580 | case Decl::TYPE: \ |
Richard Smith | b321ecb | 2014-05-13 01:15:00 +0000 | [diff] [blame] | 3581 | attachLatestDeclImpl(cast<TYPE##Decl>(D), Latest); \ |
| 3582 | break; |
| 3583 | #include "clang/AST/DeclNodes.inc" |
Douglas Gregor | 05f1035 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 3584 | } |
| 3585 | } |
| 3586 | |
Richard Smith | 851072e | 2014-05-19 20:59:20 +0000 | [diff] [blame] | 3587 | template<typename DeclT> |
| 3588 | void ASTDeclReader::markIncompleteDeclChainImpl(Redeclarable<DeclT> *D) { |
| 3589 | D->RedeclLink.markIncomplete(); |
| 3590 | } |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3591 | |
Richard Smith | 851072e | 2014-05-19 20:59:20 +0000 | [diff] [blame] | 3592 | void ASTDeclReader::markIncompleteDeclChainImpl(...) { |
| 3593 | llvm_unreachable("markIncompleteDeclChain on non-redeclarable declaration"); |
| 3594 | } |
| 3595 | |
| 3596 | void ASTReader::markIncompleteDeclChain(Decl *D) { |
| 3597 | switch (D->getKind()) { |
| 3598 | #define ABSTRACT_DECL(TYPE) |
| 3599 | #define DECL(TYPE, BASE) \ |
| 3600 | case Decl::TYPE: \ |
| 3601 | ASTDeclReader::markIncompleteDeclChainImpl(cast<TYPE##Decl>(D)); \ |
| 3602 | break; |
| 3603 | #include "clang/AST/DeclNodes.inc" |
| 3604 | } |
| 3605 | } |
| 3606 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 3607 | /// Read the declaration at the given offset from the AST file. |
Douglas Gregor | f718062 | 2011-08-03 15:48:04 +0000 | [diff] [blame] | 3608 | Decl *ASTReader::ReadDeclRecord(DeclID ID) { |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 3609 | unsigned Index = ID - NUM_PREDEF_DECL_IDS; |
Richard Smith | cb34bd3 | 2016-03-27 07:28:06 +0000 | [diff] [blame] | 3610 | SourceLocation DeclLoc; |
| 3611 | RecordLocation Loc = DeclCursorForID(ID, DeclLoc); |
Sebastian Redl | 2c373b9 | 2010-10-05 15:59:54 +0000 | [diff] [blame] | 3612 | llvm::BitstreamCursor &DeclsCursor = Loc.F->DeclsCursor; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3613 | // Keep track of where we are in the stream, then jump back there |
| 3614 | // after reading this declaration. |
Chris Lattner | 1de76db | 2009-04-27 05:58:23 +0000 | [diff] [blame] | 3615 | SavedStreamPosition SavedPosition(DeclsCursor); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3616 | |
Argyrios Kyrtzidis | d0795b2 | 2010-06-28 22:28:35 +0000 | [diff] [blame] | 3617 | ReadingKindTracker ReadingKind(Read_Decl, *this); |
| 3618 | |
Douglas Gregor | 1342e84 | 2009-07-06 18:54:52 +0000 | [diff] [blame] | 3619 | // Note that we are loading a declaration record. |
Argyrios Kyrtzidis | b24355a | 2010-07-30 10:03:16 +0000 | [diff] [blame] | 3620 | Deserializing ADecl(this); |
Mike Stump | 11289f4 | 2009-09-09 15:08:12 +0000 | [diff] [blame] | 3621 | |
JF Bastien | 0e82895 | 2019-06-26 19:50:12 +0000 | [diff] [blame] | 3622 | auto Fail = [](const char *what, llvm::Error &&Err) { |
| 3623 | llvm::report_fatal_error(Twine("ASTReader::ReadDeclRecord failed ") + what + |
| 3624 | ": " + toString(std::move(Err))); |
| 3625 | }; |
| 3626 | |
| 3627 | if (llvm::Error JumpFailed = DeclsCursor.JumpToBit(Loc.Offset)) |
| 3628 | Fail("jumping", std::move(JumpFailed)); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3629 | ASTRecordReader Record(*this, *Loc.F); |
| 3630 | ASTDeclReader Reader(*this, Record, Loc, ID, DeclLoc); |
JF Bastien | 0e82895 | 2019-06-26 19:50:12 +0000 | [diff] [blame] | 3631 | Expected<unsigned> MaybeCode = DeclsCursor.ReadCode(); |
| 3632 | if (!MaybeCode) |
| 3633 | Fail("reading code", MaybeCode.takeError()); |
| 3634 | unsigned Code = MaybeCode.get(); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3635 | |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 3636 | ASTContext &Context = getContext(); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 3637 | Decl *D = nullptr; |
JF Bastien | 0e82895 | 2019-06-26 19:50:12 +0000 | [diff] [blame] | 3638 | Expected<unsigned> MaybeDeclCode = Record.readRecord(DeclsCursor, Code); |
| 3639 | if (!MaybeDeclCode) |
| 3640 | llvm::report_fatal_error( |
| 3641 | "ASTReader::ReadDeclRecord failed reading decl code: " + |
| 3642 | toString(MaybeDeclCode.takeError())); |
| 3643 | switch ((DeclCode)MaybeDeclCode.get()) { |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3644 | case DECL_CONTEXT_LEXICAL: |
| 3645 | case DECL_CONTEXT_VISIBLE: |
David Blaikie | 83d382b | 2011-09-23 05:06:16 +0000 | [diff] [blame] | 3646 | llvm_unreachable("Record cannot be de-serialized with ReadDeclRecord"); |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3647 | case DECL_TYPEDEF: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3648 | D = TypedefDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3649 | break; |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 3650 | case DECL_TYPEALIAS: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3651 | D = TypeAliasDecl::CreateDeserialized(Context, ID); |
Richard Smith | dda56e4 | 2011-04-15 14:24:37 +0000 | [diff] [blame] | 3652 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3653 | case DECL_ENUM: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3654 | D = EnumDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3655 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3656 | case DECL_RECORD: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3657 | D = RecordDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3658 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3659 | case DECL_ENUM_CONSTANT: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3660 | D = EnumConstantDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3661 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3662 | case DECL_FUNCTION: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3663 | D = FunctionDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3664 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3665 | case DECL_LINKAGE_SPEC: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3666 | D = LinkageSpecDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3667 | break; |
Richard Smith | 8df390f | 2016-09-08 23:14:54 +0000 | [diff] [blame] | 3668 | case DECL_EXPORT: |
| 3669 | D = ExportDecl::CreateDeserialized(Context, ID); |
| 3670 | break; |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 3671 | case DECL_LABEL: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3672 | D = LabelDecl::CreateDeserialized(Context, ID); |
Chris Lattner | c8e630e | 2011-02-17 07:39:24 +0000 | [diff] [blame] | 3673 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3674 | case DECL_NAMESPACE: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3675 | D = NamespaceDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3676 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3677 | case DECL_NAMESPACE_ALIAS: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3678 | D = NamespaceAliasDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3679 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3680 | case DECL_USING: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3681 | D = UsingDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3682 | break; |
Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 3683 | case DECL_USING_PACK: |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3684 | D = UsingPackDecl::CreateDeserialized(Context, ID, Record.readInt()); |
Richard Smith | 151c456 | 2016-12-20 21:35:28 +0000 | [diff] [blame] | 3685 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3686 | case DECL_USING_SHADOW: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3687 | D = UsingShadowDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3688 | break; |
Richard Smith | 5179eb7 | 2016-06-28 19:03:57 +0000 | [diff] [blame] | 3689 | case DECL_CONSTRUCTOR_USING_SHADOW: |
| 3690 | D = ConstructorUsingShadowDecl::CreateDeserialized(Context, ID); |
| 3691 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3692 | case DECL_USING_DIRECTIVE: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3693 | D = UsingDirectiveDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3694 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3695 | case DECL_UNRESOLVED_USING_VALUE: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3696 | D = UnresolvedUsingValueDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3697 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3698 | case DECL_UNRESOLVED_USING_TYPENAME: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3699 | D = UnresolvedUsingTypenameDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3700 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3701 | case DECL_CXX_RECORD: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3702 | D = CXXRecordDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3703 | break; |
Richard Smith | bc49120 | 2017-02-17 20:05:37 +0000 | [diff] [blame] | 3704 | case DECL_CXX_DEDUCTION_GUIDE: |
| 3705 | D = CXXDeductionGuideDecl::CreateDeserialized(Context, ID); |
| 3706 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3707 | case DECL_CXX_METHOD: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3708 | D = CXXMethodDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3709 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3710 | case DECL_CXX_CONSTRUCTOR: |
Richard Smith | 76b9027 | 2019-05-09 03:59:21 +0000 | [diff] [blame] | 3711 | D = CXXConstructorDecl::CreateDeserialized(Context, ID, Record.readInt()); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3712 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3713 | case DECL_CXX_DESTRUCTOR: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3714 | D = CXXDestructorDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3715 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3716 | case DECL_CXX_CONVERSION: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3717 | D = CXXConversionDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3718 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3719 | case DECL_ACCESS_SPEC: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3720 | D = AccessSpecDecl::CreateDeserialized(Context, ID); |
Abramo Bagnara | d734058 | 2010-06-05 05:09:32 +0000 | [diff] [blame] | 3721 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3722 | case DECL_FRIEND: |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3723 | D = FriendDecl::CreateDeserialized(Context, ID, Record.readInt()); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3724 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3725 | case DECL_FRIEND_TEMPLATE: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3726 | D = FriendTemplateDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3727 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3728 | case DECL_CLASS_TEMPLATE: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3729 | D = ClassTemplateDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3730 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3731 | case DECL_CLASS_TEMPLATE_SPECIALIZATION: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3732 | D = ClassTemplateSpecializationDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3733 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3734 | case DECL_CLASS_TEMPLATE_PARTIAL_SPECIALIZATION: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3735 | D = ClassTemplatePartialSpecializationDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3736 | break; |
Larisse Voufo | 39a1e50 | 2013-08-06 01:03:05 +0000 | [diff] [blame] | 3737 | case DECL_VAR_TEMPLATE: |
| 3738 | D = VarTemplateDecl::CreateDeserialized(Context, ID); |
| 3739 | break; |
| 3740 | case DECL_VAR_TEMPLATE_SPECIALIZATION: |
| 3741 | D = VarTemplateSpecializationDecl::CreateDeserialized(Context, ID); |
| 3742 | break; |
| 3743 | case DECL_VAR_TEMPLATE_PARTIAL_SPECIALIZATION: |
| 3744 | D = VarTemplatePartialSpecializationDecl::CreateDeserialized(Context, ID); |
| 3745 | break; |
Francois Pichet | 00c7e6c | 2011-08-14 03:52:19 +0000 | [diff] [blame] | 3746 | case DECL_CLASS_SCOPE_FUNCTION_SPECIALIZATION: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3747 | D = ClassScopeFunctionSpecializationDecl::CreateDeserialized(Context, ID); |
Francois Pichet | 00c7e6c | 2011-08-14 03:52:19 +0000 | [diff] [blame] | 3748 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3749 | case DECL_FUNCTION_TEMPLATE: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3750 | D = FunctionTemplateDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3751 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3752 | case DECL_TEMPLATE_TYPE_PARM: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3753 | D = TemplateTypeParmDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3754 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3755 | case DECL_NON_TYPE_TEMPLATE_PARM: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3756 | D = NonTypeTemplateParmDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3757 | break; |
Douglas Gregor | 0231d8d | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 3758 | case DECL_EXPANDED_NON_TYPE_TEMPLATE_PARM_PACK: |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3759 | D = NonTypeTemplateParmDecl::CreateDeserialized(Context, ID, |
| 3760 | Record.readInt()); |
Douglas Gregor | 0231d8d | 2011-01-19 20:10:05 +0000 | [diff] [blame] | 3761 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3762 | case DECL_TEMPLATE_TEMPLATE_PARM: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3763 | D = TemplateTemplateParmDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3764 | break; |
Richard Smith | 1fde8ec | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 3765 | case DECL_EXPANDED_TEMPLATE_TEMPLATE_PARM_PACK: |
| 3766 | D = TemplateTemplateParmDecl::CreateDeserialized(Context, ID, |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3767 | Record.readInt()); |
Richard Smith | 1fde8ec | 2012-09-07 02:06:42 +0000 | [diff] [blame] | 3768 | break; |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 3769 | case DECL_TYPE_ALIAS_TEMPLATE: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3770 | D = TypeAliasTemplateDecl::CreateDeserialized(Context, ID); |
Richard Smith | 3f1b5d0 | 2011-05-05 21:57:07 +0000 | [diff] [blame] | 3771 | break; |
Saar Raz | d7aae33 | 2019-07-10 21:25:49 +0000 | [diff] [blame] | 3772 | case DECL_CONCEPT: |
| 3773 | D = ConceptDecl::CreateDeserialized(Context, ID); |
| 3774 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3775 | case DECL_STATIC_ASSERT: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3776 | D = StaticAssertDecl::CreateDeserialized(Context, ID); |
Chris Lattner | ca025db | 2010-05-07 21:43:38 +0000 | [diff] [blame] | 3777 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3778 | case DECL_OBJC_METHOD: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3779 | D = ObjCMethodDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3780 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3781 | case DECL_OBJC_INTERFACE: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3782 | D = ObjCInterfaceDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3783 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3784 | case DECL_OBJC_IVAR: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3785 | D = ObjCIvarDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3786 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3787 | case DECL_OBJC_PROTOCOL: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3788 | D = ObjCProtocolDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3789 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3790 | case DECL_OBJC_AT_DEFS_FIELD: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3791 | D = ObjCAtDefsFieldDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3792 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3793 | case DECL_OBJC_CATEGORY: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3794 | D = ObjCCategoryDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3795 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3796 | case DECL_OBJC_CATEGORY_IMPL: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3797 | D = ObjCCategoryImplDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3798 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3799 | case DECL_OBJC_IMPLEMENTATION: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3800 | D = ObjCImplementationDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3801 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3802 | case DECL_OBJC_COMPATIBLE_ALIAS: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3803 | D = ObjCCompatibleAliasDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3804 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3805 | case DECL_OBJC_PROPERTY: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3806 | D = ObjCPropertyDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3807 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3808 | case DECL_OBJC_PROPERTY_IMPL: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3809 | D = ObjCPropertyImplDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3810 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3811 | case DECL_FIELD: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3812 | D = FieldDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3813 | break; |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3814 | case DECL_INDIRECTFIELD: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3815 | D = IndirectFieldDecl::CreateDeserialized(Context, ID); |
Francois Pichet | 783dd6e | 2010-11-21 06:08:52 +0000 | [diff] [blame] | 3816 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3817 | case DECL_VAR: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3818 | D = VarDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3819 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3820 | case DECL_IMPLICIT_PARAM: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3821 | D = ImplicitParamDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3822 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3823 | case DECL_PARM_VAR: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3824 | D = ParmVarDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3825 | break; |
Richard Smith | 7b76d81 | 2016-08-12 02:21:25 +0000 | [diff] [blame] | 3826 | case DECL_DECOMPOSITION: |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3827 | D = DecompositionDecl::CreateDeserialized(Context, ID, Record.readInt()); |
Richard Smith | 7b76d81 | 2016-08-12 02:21:25 +0000 | [diff] [blame] | 3828 | break; |
| 3829 | case DECL_BINDING: |
| 3830 | D = BindingDecl::CreateDeserialized(Context, ID); |
| 3831 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3832 | case DECL_FILE_SCOPE_ASM: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3833 | D = FileScopeAsmDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3834 | break; |
Sebastian Redl | 539c506 | 2010-08-18 23:57:32 +0000 | [diff] [blame] | 3835 | case DECL_BLOCK: |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3836 | D = BlockDecl::CreateDeserialized(Context, ID); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3837 | break; |
John McCall | 5e77d76 | 2013-04-16 07:28:30 +0000 | [diff] [blame] | 3838 | case DECL_MS_PROPERTY: |
| 3839 | D = MSPropertyDecl::CreateDeserialized(Context, ID); |
| 3840 | break; |
Tareq A. Siraj | 6dfa25a | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 3841 | case DECL_CAPTURED: |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3842 | D = CapturedDecl::CreateDeserialized(Context, ID, Record.readInt()); |
Tareq A. Siraj | 6dfa25a | 2013-04-16 19:37:38 +0000 | [diff] [blame] | 3843 | break; |
Douglas Gregor | d4c5ed0 | 2010-10-29 22:39:52 +0000 | [diff] [blame] | 3844 | case DECL_CXX_BASE_SPECIFIERS: |
| 3845 | Error("attempt to read a C++ base-specifier record as a declaration"); |
Craig Topper | a13603a | 2014-05-22 05:54:18 +0000 | [diff] [blame] | 3846 | return nullptr; |
Richard Smith | c2bb818 | 2015-03-24 06:36:48 +0000 | [diff] [blame] | 3847 | case DECL_CXX_CTOR_INITIALIZERS: |
| 3848 | Error("attempt to read a C++ ctor initializer record as a declaration"); |
| 3849 | return nullptr; |
Douglas Gregor | ba34552 | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 3850 | case DECL_IMPORT: |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3851 | // 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] | 3852 | // locations. |
Douglas Gregor | 72172e9 | 2012-01-05 21:55:30 +0000 | [diff] [blame] | 3853 | D = ImportDecl::CreateDeserialized(Context, ID, Record.back()); |
Douglas Gregor | ba34552 | 2011-12-02 23:23:56 +0000 | [diff] [blame] | 3854 | break; |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 3855 | case DECL_OMP_THREADPRIVATE: |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3856 | D = OMPThreadPrivateDecl::CreateDeserialized(Context, ID, Record.readInt()); |
Alexey Bataev | a769e07 | 2013-03-22 06:34:35 +0000 | [diff] [blame] | 3857 | break; |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 3858 | case DECL_OMP_ALLOCATE: { |
| 3859 | unsigned NumVars = Record.readInt(); |
| 3860 | unsigned NumClauses = Record.readInt(); |
| 3861 | D = OMPAllocateDecl::CreateDeserialized(Context, ID, NumVars, NumClauses); |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 3862 | break; |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 3863 | } |
Kelvin Li | 1408f91 | 2018-09-26 04:28:39 +0000 | [diff] [blame] | 3864 | case DECL_OMP_REQUIRES: |
| 3865 | D = OMPRequiresDecl::CreateDeserialized(Context, ID, Record.readInt()); |
| 3866 | break; |
Alexey Bataev | 94a4f0c | 2016-03-03 05:21:39 +0000 | [diff] [blame] | 3867 | case DECL_OMP_DECLARE_REDUCTION: |
| 3868 | D = OMPDeclareReductionDecl::CreateDeserialized(Context, ID); |
| 3869 | break; |
Michael Kruse | 251e148 | 2019-02-01 20:25:04 +0000 | [diff] [blame] | 3870 | case DECL_OMP_DECLARE_MAPPER: |
| 3871 | D = OMPDeclareMapperDecl::CreateDeserialized(Context, ID, Record.readInt()); |
| 3872 | break; |
Alexey Bataev | 4244be2 | 2016-02-11 05:35:55 +0000 | [diff] [blame] | 3873 | case DECL_OMP_CAPTUREDEXPR: |
| 3874 | D = OMPCapturedExprDecl::CreateDeserialized(Context, ID); |
Alexey Bataev | 90c228f | 2016-02-08 09:29:13 +0000 | [diff] [blame] | 3875 | break; |
Nico Weber | 6622029 | 2016-03-02 17:28:48 +0000 | [diff] [blame] | 3876 | case DECL_PRAGMA_COMMENT: |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3877 | D = PragmaCommentDecl::CreateDeserialized(Context, ID, Record.readInt()); |
Nico Weber | 6622029 | 2016-03-02 17:28:48 +0000 | [diff] [blame] | 3878 | break; |
Nico Weber | cbbaeb1 | 2016-03-02 19:28:54 +0000 | [diff] [blame] | 3879 | case DECL_PRAGMA_DETECT_MISMATCH: |
| 3880 | D = PragmaDetectMismatchDecl::CreateDeserialized(Context, ID, |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3881 | Record.readInt()); |
Nico Weber | cbbaeb1 | 2016-03-02 19:28:54 +0000 | [diff] [blame] | 3882 | break; |
Michael Han | 8432435 | 2013-02-22 17:15:32 +0000 | [diff] [blame] | 3883 | case DECL_EMPTY: |
| 3884 | D = EmptyDecl::CreateDeserialized(Context, ID); |
| 3885 | break; |
Douglas Gregor | 85f3f95 | 2015-07-07 03:57:15 +0000 | [diff] [blame] | 3886 | case DECL_OBJC_TYPE_PARAM: |
| 3887 | D = ObjCTypeParamDecl::CreateDeserialized(Context, ID); |
| 3888 | break; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3889 | } |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3890 | |
Sebastian Redl | b3298c3 | 2010-08-18 23:56:48 +0000 | [diff] [blame] | 3891 | assert(D && "Unknown declaration reading AST file"); |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 3892 | LoadedDecl(Index, D); |
Argyrios Kyrtzidis | 6c07547 | 2012-02-09 06:02:44 +0000 | [diff] [blame] | 3893 | // Set the DeclContext before doing any deserialization, to make sure internal |
| 3894 | // calls to Decl::getASTContext() by Decl's methods will find the |
| 3895 | // TranslationUnitDecl without crashing. |
| 3896 | D->setDeclContext(Context.getTranslationUnitDecl()); |
Chris Lattner | 8f63ab5 | 2009-04-27 06:01:06 +0000 | [diff] [blame] | 3897 | Reader.Visit(D); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3898 | |
| 3899 | // If this declaration is also a declaration context, get the |
| 3900 | // offsets for its tables of lexical and visible declarations. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3901 | if (auto *DC = dyn_cast<DeclContext>(D)) { |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3902 | std::pair<uint64_t, uint64_t> Offsets = Reader.VisitDeclContext(DC); |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 3903 | if (Offsets.first && |
| 3904 | ReadLexicalDeclContextStorage(*Loc.F, DeclsCursor, Offsets.first, DC)) |
| 3905 | return nullptr; |
| 3906 | if (Offsets.second && |
| 3907 | ReadVisibleDeclContextStorage(*Loc.F, DeclsCursor, Offsets.second, ID)) |
| 3908 | return nullptr; |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3909 | } |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3910 | assert(Record.getIdx() == Record.size()); |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 3911 | |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 3912 | // Load any relevant update records. |
Vassil Vassilev | 74c3e8c | 2017-05-19 16:46:06 +0000 | [diff] [blame] | 3913 | PendingUpdateRecords.push_back( |
| 3914 | PendingUpdateRecord(ID, D, /*JustLoaded=*/true)); |
Argyrios Kyrtzidis | 7d268c3 | 2011-11-14 07:07:59 +0000 | [diff] [blame] | 3915 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3916 | // Load the categories after recursive loading is finished. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3917 | if (auto *Class = dyn_cast<ObjCInterfaceDecl>(D)) |
Manman Ren | ec315f1 | 2016-09-09 23:48:27 +0000 | [diff] [blame] | 3918 | // If we already have a definition when deserializing the ObjCInterfaceDecl, |
| 3919 | // we put the Decl in PendingDefinitions so we can pull the categories here. |
| 3920 | if (Class->isThisDeclarationADefinition() || |
| 3921 | PendingDefinitions.count(Class)) |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 3922 | loadObjCCategories(ID, Class); |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 3923 | |
Richard Smith | 13fb860 | 2016-07-15 21:33:46 +0000 | [diff] [blame] | 3924 | // If we have deserialized a declaration that has a definition the |
| 3925 | // AST consumer might need to know about, queue it. |
| 3926 | // We don't pass it to the consumer immediately because we may be in recursive |
| 3927 | // loading, and some declarations may still be initializing. |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 3928 | PotentiallyInterestingDecls.push_back( |
| 3929 | InterestingDecl(D, Reader.hasPendingBody())); |
Richard Smith | 13fb860 | 2016-07-15 21:33:46 +0000 | [diff] [blame] | 3930 | |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 3931 | return D; |
| 3932 | } |
| 3933 | |
Vassil Vassilev | 46afbbb | 2017-04-12 21:56:05 +0000 | [diff] [blame] | 3934 | void ASTReader::PassInterestingDeclsToConsumer() { |
| 3935 | assert(Consumer); |
| 3936 | |
| 3937 | if (PassingDeclsToConsumer) |
| 3938 | return; |
| 3939 | |
| 3940 | // Guard variable to avoid recursively redoing the process of passing |
| 3941 | // decls to consumer. |
| 3942 | SaveAndRestore<bool> GuardPassingDeclsToConsumer(PassingDeclsToConsumer, |
| 3943 | true); |
| 3944 | |
| 3945 | // Ensure that we've loaded all potentially-interesting declarations |
| 3946 | // that need to be eagerly loaded. |
| 3947 | for (auto ID : EagerlyDeserializedDecls) |
| 3948 | GetDecl(ID); |
| 3949 | EagerlyDeserializedDecls.clear(); |
| 3950 | |
| 3951 | while (!PotentiallyInterestingDecls.empty()) { |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 3952 | InterestingDecl D = PotentiallyInterestingDecls.front(); |
Vassil Vassilev | 46afbbb | 2017-04-12 21:56:05 +0000 | [diff] [blame] | 3953 | PotentiallyInterestingDecls.pop_front(); |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 3954 | if (isConsumerInterestedIn(getContext(), D.getDecl(), D.hasPendingBody())) |
| 3955 | PassInterestingDeclToConsumer(D.getDecl()); |
Vassil Vassilev | 46afbbb | 2017-04-12 21:56:05 +0000 | [diff] [blame] | 3956 | } |
| 3957 | } |
| 3958 | |
Vassil Vassilev | 74c3e8c | 2017-05-19 16:46:06 +0000 | [diff] [blame] | 3959 | void ASTReader::loadDeclUpdateRecords(PendingUpdateRecord &Record) { |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3960 | // The declaration may have been modified by files later in the chain. |
| 3961 | // If this is the case, read the record containing the updates from each file |
| 3962 | // and pass it to ASTDeclReader to make the modifications. |
Vassil Vassilev | 74c3e8c | 2017-05-19 16:46:06 +0000 | [diff] [blame] | 3963 | serialization::GlobalDeclID ID = Record.ID; |
| 3964 | Decl *D = Record.D; |
Vassil Vassilev | 19765fb | 2016-07-22 21:08:24 +0000 | [diff] [blame] | 3965 | ProcessingUpdatesRAIIObj ProcessingUpdates(*this); |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3966 | DeclUpdateOffsetsMap::iterator UpdI = DeclUpdateOffsets.find(ID); |
Vassil Vassilev | 7d26462 | 2017-06-30 22:40:17 +0000 | [diff] [blame] | 3967 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 3968 | SmallVector<serialization::DeclID, 8> PendingLazySpecializationIDs; |
Vassil Vassilev | 7d26462 | 2017-06-30 22:40:17 +0000 | [diff] [blame] | 3969 | |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3970 | if (UpdI != DeclUpdateOffsets.end()) { |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 3971 | auto UpdateOffsets = std::move(UpdI->second); |
| 3972 | DeclUpdateOffsets.erase(UpdI); |
| 3973 | |
Vassil Vassilev | 74c3e8c | 2017-05-19 16:46:06 +0000 | [diff] [blame] | 3974 | // Check if this decl was interesting to the consumer. If we just loaded |
| 3975 | // the declaration, then we know it was interesting and we skip the call |
| 3976 | // to isConsumerInterestedIn because it is unsafe to call in the |
| 3977 | // current ASTReader state. |
| 3978 | bool WasInteresting = |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 3979 | Record.JustLoaded || isConsumerInterestedIn(getContext(), D, false); |
Richard Smith | 0f4e2c4 | 2015-08-06 04:23:48 +0000 | [diff] [blame] | 3980 | for (auto &FileAndOffset : UpdateOffsets) { |
| 3981 | ModuleFile *F = FileAndOffset.first; |
| 3982 | uint64_t Offset = FileAndOffset.second; |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 3983 | llvm::BitstreamCursor &Cursor = F->DeclsCursor; |
| 3984 | SavedStreamPosition SavedPosition(Cursor); |
JF Bastien | 0e82895 | 2019-06-26 19:50:12 +0000 | [diff] [blame] | 3985 | if (llvm::Error JumpFailed = Cursor.JumpToBit(Offset)) |
| 3986 | // FIXME don't do a fatal error. |
| 3987 | llvm::report_fatal_error( |
| 3988 | "ASTReader::loadDeclUpdateRecords failed jumping: " + |
| 3989 | toString(std::move(JumpFailed))); |
| 3990 | Expected<unsigned> MaybeCode = Cursor.ReadCode(); |
| 3991 | if (!MaybeCode) |
| 3992 | llvm::report_fatal_error( |
| 3993 | "ASTReader::loadDeclUpdateRecords failed reading code: " + |
| 3994 | toString(MaybeCode.takeError())); |
| 3995 | unsigned Code = MaybeCode.get(); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 3996 | ASTRecordReader Record(*this, *F); |
JF Bastien | 0e82895 | 2019-06-26 19:50:12 +0000 | [diff] [blame] | 3997 | if (Expected<unsigned> MaybeRecCode = Record.readRecord(Cursor, Code)) |
| 3998 | assert(MaybeRecCode.get() == DECL_UPDATES && |
| 3999 | "Expected DECL_UPDATES record!"); |
| 4000 | else |
| 4001 | llvm::report_fatal_error( |
| 4002 | "ASTReader::loadDeclUpdateRecords failed reading rec code: " + |
| 4003 | toString(MaybeCode.takeError())); |
Richard Smith | 04d05b5 | 2014-03-23 00:27:18 +0000 | [diff] [blame] | 4004 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 4005 | ASTDeclReader Reader(*this, Record, RecordLocation(F, Offset), ID, |
| 4006 | SourceLocation()); |
Vassil Vassilev | 7d26462 | 2017-06-30 22:40:17 +0000 | [diff] [blame] | 4007 | Reader.UpdateDecl(D, PendingLazySpecializationIDs); |
Richard Smith | 04d05b5 | 2014-03-23 00:27:18 +0000 | [diff] [blame] | 4008 | |
| 4009 | // We might have made this declaration interesting. If so, remember that |
| 4010 | // we need to hand it off to the consumer. |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 4011 | if (!WasInteresting && |
| 4012 | isConsumerInterestedIn(getContext(), D, Reader.hasPendingBody())) { |
| 4013 | PotentiallyInterestingDecls.push_back( |
| 4014 | InterestingDecl(D, Reader.hasPendingBody())); |
Richard Smith | 04d05b5 | 2014-03-23 00:27:18 +0000 | [diff] [blame] | 4015 | WasInteresting = true; |
| 4016 | } |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4017 | } |
| 4018 | } |
Vassil Vassilev | 7d26462 | 2017-06-30 22:40:17 +0000 | [diff] [blame] | 4019 | // Add the lazy specializations to the template. |
| 4020 | assert((PendingLazySpecializationIDs.empty() || isa<ClassTemplateDecl>(D) || |
| 4021 | isa<FunctionTemplateDecl>(D) || isa<VarTemplateDecl>(D)) && |
| 4022 | "Must not have pending specializations"); |
| 4023 | if (auto *CTD = dyn_cast<ClassTemplateDecl>(D)) |
| 4024 | ASTDeclReader::AddLazySpecializations(CTD, PendingLazySpecializationIDs); |
| 4025 | else if (auto *FTD = dyn_cast<FunctionTemplateDecl>(D)) |
| 4026 | ASTDeclReader::AddLazySpecializations(FTD, PendingLazySpecializationIDs); |
| 4027 | else if (auto *VTD = dyn_cast<VarTemplateDecl>(D)) |
| 4028 | ASTDeclReader::AddLazySpecializations(VTD, PendingLazySpecializationIDs); |
| 4029 | PendingLazySpecializationIDs.clear(); |
Richard Smith | 1e8e91b | 2016-04-08 20:53:26 +0000 | [diff] [blame] | 4030 | |
| 4031 | // Load the pending visible updates for this decl context, if it has any. |
| 4032 | auto I = PendingVisibleUpdates.find(ID); |
| 4033 | if (I != PendingVisibleUpdates.end()) { |
| 4034 | auto VisibleUpdates = std::move(I->second); |
| 4035 | PendingVisibleUpdates.erase(I); |
| 4036 | |
| 4037 | auto *DC = cast<DeclContext>(D)->getPrimaryContext(); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4038 | for (const auto &Update : VisibleUpdates) |
Richard Smith | 1e8e91b | 2016-04-08 20:53:26 +0000 | [diff] [blame] | 4039 | Lookups[DC].Table.add( |
| 4040 | Update.Mod, Update.Data, |
| 4041 | reader::ASTDeclContextNameLookupTrait(*this, *Update.Mod)); |
| 4042 | DC->setHasExternalVisibleStorage(true); |
| 4043 | } |
Chris Lattner | 487412d | 2009-04-27 05:27:42 +0000 | [diff] [blame] | 4044 | } |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4045 | |
Richard Smith | d61d4ac | 2015-08-22 20:13:39 +0000 | [diff] [blame] | 4046 | void ASTReader::loadPendingDeclChain(Decl *FirstLocal, uint64_t LocalOffset) { |
| 4047 | // Attach FirstLocal to the end of the decl chain. |
Richard Smith | d8a8371 | 2015-08-22 01:47:18 +0000 | [diff] [blame] | 4048 | Decl *CanonDecl = FirstLocal->getCanonicalDecl(); |
Richard Smith | d61d4ac | 2015-08-22 20:13:39 +0000 | [diff] [blame] | 4049 | if (FirstLocal != CanonDecl) { |
| 4050 | Decl *PrevMostRecent = ASTDeclReader::getMostRecentDecl(CanonDecl); |
| 4051 | ASTDeclReader::attachPreviousDecl( |
| 4052 | *this, FirstLocal, PrevMostRecent ? PrevMostRecent : CanonDecl, |
| 4053 | CanonDecl); |
| 4054 | } |
| 4055 | |
| 4056 | if (!LocalOffset) { |
| 4057 | ASTDeclReader::attachLatestDecl(CanonDecl, FirstLocal); |
| 4058 | return; |
| 4059 | } |
| 4060 | |
| 4061 | // Load the list of other redeclarations from this module file. |
| 4062 | ModuleFile *M = getOwningModuleFile(FirstLocal); |
| 4063 | assert(M && "imported decl from no module file"); |
| 4064 | |
| 4065 | llvm::BitstreamCursor &Cursor = M->DeclsCursor; |
| 4066 | SavedStreamPosition SavedPosition(Cursor); |
JF Bastien | 0e82895 | 2019-06-26 19:50:12 +0000 | [diff] [blame] | 4067 | if (llvm::Error JumpFailed = Cursor.JumpToBit(LocalOffset)) |
| 4068 | llvm::report_fatal_error( |
| 4069 | "ASTReader::loadPendingDeclChain failed jumping: " + |
| 4070 | toString(std::move(JumpFailed))); |
Richard Smith | d61d4ac | 2015-08-22 20:13:39 +0000 | [diff] [blame] | 4071 | |
| 4072 | RecordData Record; |
JF Bastien | 0e82895 | 2019-06-26 19:50:12 +0000 | [diff] [blame] | 4073 | Expected<unsigned> MaybeCode = Cursor.ReadCode(); |
| 4074 | if (!MaybeCode) |
| 4075 | llvm::report_fatal_error( |
| 4076 | "ASTReader::loadPendingDeclChain failed reading code: " + |
| 4077 | toString(MaybeCode.takeError())); |
| 4078 | unsigned Code = MaybeCode.get(); |
| 4079 | if (Expected<unsigned> MaybeRecCode = Cursor.readRecord(Code, Record)) |
| 4080 | assert(MaybeRecCode.get() == LOCAL_REDECLARATIONS && |
| 4081 | "expected LOCAL_REDECLARATIONS record!"); |
| 4082 | else |
| 4083 | llvm::report_fatal_error( |
| 4084 | "ASTReader::loadPendingDeclChain failed reading rec code: " + |
| 4085 | toString(MaybeCode.takeError())); |
Richard Smith | d61d4ac | 2015-08-22 20:13:39 +0000 | [diff] [blame] | 4086 | |
| 4087 | // FIXME: We have several different dispatches on decl kind here; maybe |
| 4088 | // we should instead generate one loop per kind and dispatch up-front? |
| 4089 | Decl *MostRecent = FirstLocal; |
| 4090 | for (unsigned I = 0, N = Record.size(); I != N; ++I) { |
| 4091 | auto *D = GetLocalDecl(*M, Record[N - I - 1]); |
Richard Smith | e2f8ce9 | 2015-07-15 00:02:40 +0000 | [diff] [blame] | 4092 | ASTDeclReader::attachPreviousDecl(*this, D, MostRecent, CanonDecl); |
| 4093 | MostRecent = D; |
Douglas Gregor | 05f1035 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 4094 | } |
Richard Smith | c3a5325 | 2015-02-28 05:57:02 +0000 | [diff] [blame] | 4095 | ASTDeclReader::attachLatestDecl(CanonDecl, MostRecent); |
Douglas Gregor | 05f1035 | 2011-12-17 23:38:30 +0000 | [diff] [blame] | 4096 | } |
| 4097 | |
| 4098 | namespace { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4099 | |
Adrian Prantl | 9fc8faf | 2018-05-09 01:00:01 +0000 | [diff] [blame] | 4100 | /// Given an ObjC interface, goes through the modules and links to the |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4101 | /// interface all the categories for it. |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4102 | class ObjCCategoriesVisitor { |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4103 | ASTReader &Reader; |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4104 | ObjCInterfaceDecl *Interface; |
Craig Topper | 4dd9b43 | 2014-08-17 23:49:53 +0000 | [diff] [blame] | 4105 | llvm::SmallPtrSetImpl<ObjCCategoryDecl *> &Deserialized; |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4106 | ObjCCategoryDecl *Tail = nullptr; |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4107 | llvm::DenseMap<DeclarationName, ObjCCategoryDecl *> NameCategoryMap; |
Alexander Shaposhnikov | 96cbe7b | 2016-09-24 02:07:19 +0000 | [diff] [blame] | 4108 | serialization::GlobalDeclID InterfaceID; |
| 4109 | unsigned PreviousGeneration; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4110 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4111 | void add(ObjCCategoryDecl *Cat) { |
| 4112 | // Only process each category once. |
Benjamin Kramer | fc6eb7d | 2012-08-22 15:37:55 +0000 | [diff] [blame] | 4113 | if (!Deserialized.erase(Cat)) |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4114 | return; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4115 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4116 | // Check for duplicate categories. |
| 4117 | if (Cat->getDeclName()) { |
| 4118 | ObjCCategoryDecl *&Existing = NameCategoryMap[Cat->getDeclName()]; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4119 | if (Existing && |
| 4120 | Reader.getOwningModuleFile(Existing) |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4121 | != Reader.getOwningModuleFile(Cat)) { |
| 4122 | // FIXME: We should not warn for duplicates in diamond: |
| 4123 | // |
| 4124 | // MT // |
| 4125 | // / \ // |
| 4126 | // ML MR // |
| 4127 | // \ / // |
| 4128 | // MB // |
| 4129 | // |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4130 | // If there are duplicates in ML/MR, there will be warning when |
| 4131 | // creating MB *and* when importing MB. We should not warn when |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4132 | // importing. |
| 4133 | Reader.Diag(Cat->getLocation(), diag::warn_dup_category_def) |
| 4134 | << Interface->getDeclName() << Cat->getDeclName(); |
| 4135 | Reader.Diag(Existing->getLocation(), diag::note_previous_definition); |
| 4136 | } else if (!Existing) { |
| 4137 | // Record this category. |
| 4138 | Existing = Cat; |
| 4139 | } |
| 4140 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4141 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4142 | // Add this category to the end of the chain. |
| 4143 | if (Tail) |
| 4144 | ASTDeclReader::setNextObjCCategory(Tail, Cat); |
| 4145 | else |
Douglas Gregor | 048fbfa | 2013-01-16 23:00:23 +0000 | [diff] [blame] | 4146 | Interface->setCategoryListRaw(Cat); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4147 | Tail = Cat; |
| 4148 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4149 | |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4150 | public: |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4151 | ObjCCategoriesVisitor(ASTReader &Reader, |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4152 | ObjCInterfaceDecl *Interface, |
Alexander Shaposhnikov | 96cbe7b | 2016-09-24 02:07:19 +0000 | [diff] [blame] | 4153 | llvm::SmallPtrSetImpl<ObjCCategoryDecl *> &Deserialized, |
| 4154 | serialization::GlobalDeclID InterfaceID, |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4155 | unsigned PreviousGeneration) |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4156 | : Reader(Reader), Interface(Interface), Deserialized(Deserialized), |
| 4157 | InterfaceID(InterfaceID), PreviousGeneration(PreviousGeneration) { |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4158 | // Populate the name -> category map with the set of known categories. |
Aaron Ballman | 15063e1 | 2014-03-13 21:35:02 +0000 | [diff] [blame] | 4159 | for (auto *Cat : Interface->known_categories()) { |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4160 | if (Cat->getDeclName()) |
Aaron Ballman | 15063e1 | 2014-03-13 21:35:02 +0000 | [diff] [blame] | 4161 | NameCategoryMap[Cat->getDeclName()] = Cat; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4162 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4163 | // Keep track of the tail of the category list. |
Aaron Ballman | 15063e1 | 2014-03-13 21:35:02 +0000 | [diff] [blame] | 4164 | Tail = Cat; |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4165 | } |
| 4166 | } |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4167 | |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 4168 | bool operator()(ModuleFile &M) { |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4169 | // If we've loaded all of the category information we care about from |
| 4170 | // this module file, we're done. |
| 4171 | if (M.Generation <= PreviousGeneration) |
| 4172 | return true; |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4173 | |
| 4174 | // 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] | 4175 | // module file. If there is no such mapping, we'll find nothing here |
| 4176 | // (or in any module it imports). |
| 4177 | DeclID LocalID = Reader.mapGlobalIDToModuleFileGlobalID(M, InterfaceID); |
| 4178 | if (!LocalID) |
| 4179 | return true; |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4180 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4181 | // Perform a binary search to find the local redeclarations for this |
| 4182 | // declaration (if any). |
Benjamin Kramer | a6f3950 | 2014-03-15 14:21:58 +0000 | [diff] [blame] | 4183 | const ObjCCategoriesInfo Compare = { LocalID, 0 }; |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4184 | const ObjCCategoriesInfo *Result |
| 4185 | = std::lower_bound(M.ObjCCategoriesMap, |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4186 | M.ObjCCategoriesMap + M.LocalNumObjCCategoriesInMap, |
Benjamin Kramer | a6f3950 | 2014-03-15 14:21:58 +0000 | [diff] [blame] | 4187 | Compare); |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4188 | if (Result == M.ObjCCategoriesMap + M.LocalNumObjCCategoriesInMap || |
| 4189 | Result->DefinitionID != LocalID) { |
| 4190 | // We didn't find anything. If the class definition is in this module |
| 4191 | // file, then the module files it depends on cannot have any categories, |
| 4192 | // so suppress further lookup. |
| 4193 | return Reader.isDeclIDFromModule(InterfaceID, M); |
| 4194 | } |
Fangrui Song | 6907ce2 | 2018-07-30 19:24:48 +0000 | [diff] [blame] | 4195 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4196 | // We found something. Dig out all of the categories. |
| 4197 | unsigned Offset = Result->Offset; |
| 4198 | unsigned N = M.ObjCCategories[Offset]; |
| 4199 | M.ObjCCategories[Offset++] = 0; // Don't try to deserialize again |
| 4200 | for (unsigned I = 0; I != N; ++I) |
| 4201 | add(cast_or_null<ObjCCategoryDecl>( |
| 4202 | Reader.GetLocalDecl(M, M.ObjCCategories[Offset++]))); |
| 4203 | return true; |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4204 | } |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4205 | }; |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4206 | |
| 4207 | } // namespace |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4208 | |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4209 | void ASTReader::loadObjCCategories(serialization::GlobalDeclID ID, |
| 4210 | ObjCInterfaceDecl *D, |
| 4211 | unsigned PreviousGeneration) { |
Alexander Shaposhnikov | 96cbe7b | 2016-09-24 02:07:19 +0000 | [diff] [blame] | 4212 | ObjCCategoriesVisitor Visitor(*this, D, CategoriesDeserialized, ID, |
Douglas Gregor | 404cdde | 2012-01-27 01:47:08 +0000 | [diff] [blame] | 4213 | PreviousGeneration); |
Benjamin Kramer | 9a9efba | 2015-07-25 12:14:04 +0000 | [diff] [blame] | 4214 | ModuleMgr.visit(Visitor); |
Argyrios Kyrtzidis | 7d847c9 | 2011-09-01 00:58:55 +0000 | [diff] [blame] | 4215 | } |
Douglas Gregor | dab4243 | 2011-08-12 00:15:20 +0000 | [diff] [blame] | 4216 | |
Richard Smith | d6db68c | 2014-08-07 20:58:41 +0000 | [diff] [blame] | 4217 | template<typename DeclT, typename Fn> |
| 4218 | static void forAllLaterRedecls(DeclT *D, Fn F) { |
| 4219 | F(D); |
| 4220 | |
| 4221 | // Check whether we've already merged D into its redeclaration chain. |
| 4222 | // MostRecent may or may not be nullptr if D has not been merged. If |
| 4223 | // not, walk the merged redecl chain and see if it's there. |
| 4224 | auto *MostRecent = D->getMostRecentDecl(); |
| 4225 | bool Found = false; |
| 4226 | for (auto *Redecl = MostRecent; Redecl && !Found; |
| 4227 | Redecl = Redecl->getPreviousDecl()) |
| 4228 | Found = (Redecl == D); |
| 4229 | |
| 4230 | // If this declaration is merged, apply the functor to all later decls. |
| 4231 | if (Found) { |
| 4232 | for (auto *Redecl = MostRecent; Redecl != D; |
| 4233 | Redecl = Redecl->getPreviousDecl()) |
| 4234 | F(Redecl); |
| 4235 | } |
| 4236 | } |
| 4237 | |
Vassil Vassilev | 7d26462 | 2017-06-30 22:40:17 +0000 | [diff] [blame] | 4238 | void ASTDeclReader::UpdateDecl(Decl *D, |
| 4239 | llvm::SmallVectorImpl<serialization::DeclID> &PendingLazySpecializationIDs) { |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 4240 | while (Record.getIdx() < Record.size()) { |
| 4241 | switch ((DeclUpdateKind)Record.readInt()) { |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4242 | case UPD_CXX_ADDED_IMPLICIT_MEMBER: { |
Richard Smith | 1b65dbc | 2015-01-22 03:50:31 +0000 | [diff] [blame] | 4243 | auto *RD = cast<CXXRecordDecl>(D); |
Richard Smith | d6db68c | 2014-08-07 20:58:41 +0000 | [diff] [blame] | 4244 | // FIXME: If we also have an update record for instantiating the |
| 4245 | // 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] | 4246 | Decl *MD = Record.readDecl(); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4247 | assert(MD && "couldn't read decl from update record"); |
Richard Smith | 46bb581 | 2014-08-01 01:56:39 +0000 | [diff] [blame] | 4248 | // FIXME: We should call addHiddenDecl instead, to add the member |
| 4249 | // to its DeclContext. |
Richard Smith | 1b65dbc | 2015-01-22 03:50:31 +0000 | [diff] [blame] | 4250 | RD->addedMember(MD); |
Argyrios Kyrtzidis | e16a530 | 2010-10-24 17:26:54 +0000 | [diff] [blame] | 4251 | break; |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4252 | } |
Argyrios Kyrtzidis | 402dbbb | 2010-10-28 07:38:42 +0000 | [diff] [blame] | 4253 | |
| 4254 | case UPD_CXX_ADDED_TEMPLATE_SPECIALIZATION: |
Vassil Vassilev | 7d26462 | 2017-06-30 22:40:17 +0000 | [diff] [blame] | 4255 | // It will be added to the template's lazy specialization set. |
| 4256 | PendingLazySpecializationIDs.push_back(ReadDeclID()); |
Sebastian Redl | fa1f370 | 2011-04-24 16:28:13 +0000 | [diff] [blame] | 4257 | break; |
| 4258 | |
| 4259 | case UPD_CXX_ADDED_ANONYMOUS_NAMESPACE: { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4260 | auto *Anon = ReadDeclAs<NamespaceDecl>(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4261 | |
Douglas Gregor | 540fd81 | 2012-01-09 18:07:24 +0000 | [diff] [blame] | 4262 | // Each module has its own anonymous namespace, which is disjoint from |
| 4263 | // any other module's anonymous namespaces, so don't attach the anonymous |
| 4264 | // namespace at all. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4265 | if (!Record.isModule()) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4266 | if (auto *TU = dyn_cast<TranslationUnitDecl>(D)) |
Douglas Gregor | 540fd81 | 2012-01-09 18:07:24 +0000 | [diff] [blame] | 4267 | TU->setAnonymousNamespace(Anon); |
| 4268 | else |
| 4269 | cast<NamespaceDecl>(D)->setAnonymousNamespace(Anon); |
| 4270 | } |
Sebastian Redl | fa1f370 | 2011-04-24 16:28:13 +0000 | [diff] [blame] | 4271 | break; |
| 4272 | } |
Sebastian Redl | 2ac2c72 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 4273 | |
Richard Smith | 891fc7f | 2017-12-05 01:31:47 +0000 | [diff] [blame] | 4274 | case UPD_CXX_ADDED_VAR_DEFINITION: { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4275 | auto *VD = cast<VarDecl>(D); |
Richard Smith | f501759 | 2017-11-02 01:06:00 +0000 | [diff] [blame] | 4276 | VD->NonParmVarDeclBits.IsInline = Record.readInt(); |
| 4277 | VD->NonParmVarDeclBits.IsInlineSpecified = Record.readInt(); |
Richard Smith | 05a2135 | 2017-06-22 22:18:46 +0000 | [diff] [blame] | 4278 | uint64_t Val = Record.readInt(); |
| 4279 | if (Val && !VD->getInit()) { |
| 4280 | VD->setInit(Record.readExpr()); |
| 4281 | if (Val > 1) { // IsInitKnownICE = 1, IsInitNotICE = 2, IsInitICE = 3 |
| 4282 | EvaluatedStmt *Eval = VD->ensureEvaluatedStmt(); |
| 4283 | Eval->CheckedICE = true; |
| 4284 | Eval->IsICE = Val == 3; |
| 4285 | } |
| 4286 | } |
Sebastian Redl | 2ac2c72 | 2011-04-29 08:19:30 +0000 | [diff] [blame] | 4287 | break; |
Richard Smith | 05a2135 | 2017-06-22 22:18:46 +0000 | [diff] [blame] | 4288 | } |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 4289 | |
Richard Smith | 891fc7f | 2017-12-05 01:31:47 +0000 | [diff] [blame] | 4290 | case UPD_CXX_POINT_OF_INSTANTIATION: { |
| 4291 | SourceLocation POI = Record.readSourceLocation(); |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4292 | if (auto *VTSD = dyn_cast<VarTemplateSpecializationDecl>(D)) { |
Richard Smith | 891fc7f | 2017-12-05 01:31:47 +0000 | [diff] [blame] | 4293 | VTSD->setPointOfInstantiation(POI); |
| 4294 | } else if (auto *VD = dyn_cast<VarDecl>(D)) { |
| 4295 | VD->getMemberSpecializationInfo()->setPointOfInstantiation(POI); |
| 4296 | } else { |
| 4297 | auto *FD = cast<FunctionDecl>(D); |
| 4298 | if (auto *FTSInfo = FD->TemplateOrSpecialization |
| 4299 | .dyn_cast<FunctionTemplateSpecializationInfo *>()) |
| 4300 | FTSInfo->setPointOfInstantiation(POI); |
| 4301 | else |
| 4302 | FD->TemplateOrSpecialization.get<MemberSpecializationInfo *>() |
| 4303 | ->setPointOfInstantiation(POI); |
| 4304 | } |
| 4305 | break; |
| 4306 | } |
| 4307 | |
John McCall | 32791cc | 2016-01-06 22:34:54 +0000 | [diff] [blame] | 4308 | case UPD_CXX_INSTANTIATED_DEFAULT_ARGUMENT: { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4309 | auto *Param = cast<ParmVarDecl>(D); |
John McCall | 32791cc | 2016-01-06 22:34:54 +0000 | [diff] [blame] | 4310 | |
| 4311 | // We have to read the default argument regardless of whether we use it |
| 4312 | // so that hypothetical further update records aren't messed up. |
| 4313 | // TODO: Add a function to skip over the next expr record. |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4314 | auto *DefaultArg = Record.readExpr(); |
John McCall | 32791cc | 2016-01-06 22:34:54 +0000 | [diff] [blame] | 4315 | |
| 4316 | // Only apply the update if the parameter still has an uninstantiated |
| 4317 | // default argument. |
| 4318 | if (Param->hasUninstantiatedDefaultArg()) |
| 4319 | Param->setDefaultArg(DefaultArg); |
| 4320 | break; |
| 4321 | } |
| 4322 | |
Richard Smith | 4b054b2 | 2016-08-24 21:25:37 +0000 | [diff] [blame] | 4323 | case UPD_CXX_INSTANTIATED_DEFAULT_MEMBER_INITIALIZER: { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4324 | auto *FD = cast<FieldDecl>(D); |
| 4325 | auto *DefaultInit = Record.readExpr(); |
Richard Smith | 4b054b2 | 2016-08-24 21:25:37 +0000 | [diff] [blame] | 4326 | |
| 4327 | // Only apply the update if the field still has an uninstantiated |
| 4328 | // default member initializer. |
| 4329 | if (FD->hasInClassInitializer() && !FD->getInClassInitializer()) { |
| 4330 | if (DefaultInit) |
| 4331 | FD->setInClassInitializer(DefaultInit); |
| 4332 | else |
| 4333 | // Instantiation failed. We can get here if we serialized an AST for |
| 4334 | // an invalid program. |
| 4335 | FD->removeInClassInitializer(); |
| 4336 | } |
| 4337 | break; |
| 4338 | } |
| 4339 | |
Richard Smith | 4d23579 | 2014-08-07 18:53:08 +0000 | [diff] [blame] | 4340 | case UPD_CXX_ADDED_FUNCTION_DEFINITION: { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4341 | auto *FD = cast<FunctionDecl>(D); |
Daniel Jasper | 4a6d5b7 | 2017-10-11 07:47:54 +0000 | [diff] [blame] | 4342 | if (Reader.PendingBodies[FD]) { |
| 4343 | // FIXME: Maybe check for ODR violations. |
| 4344 | // It's safe to stop now because this update record is always last. |
| 4345 | return; |
| 4346 | } |
| 4347 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 4348 | if (Record.readInt()) { |
Richard Smith | 195d8ef | 2014-05-29 03:15:31 +0000 | [diff] [blame] | 4349 | // Maintain AST consistency: any later redeclarations of this function |
| 4350 | // are inline if this one is. (We might have merged another declaration |
| 4351 | // into this one.) |
Richard Smith | d6db68c | 2014-08-07 20:58:41 +0000 | [diff] [blame] | 4352 | forAllLaterRedecls(FD, [](FunctionDecl *FD) { |
| 4353 | FD->setImplicitlyInline(); |
| 4354 | }); |
Richard Smith | 195d8ef | 2014-05-29 03:15:31 +0000 | [diff] [blame] | 4355 | } |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4356 | FD->setInnerLocStart(ReadSourceLocation()); |
David Blaikie | ac4345c | 2017-02-12 18:45:31 +0000 | [diff] [blame] | 4357 | ReadFunctionDefinition(FD); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 4358 | assert(Record.getIdx() == Record.size() && "lazy body must be last"); |
Richard Smith | d28ac5b | 2014-03-22 23:33:22 +0000 | [diff] [blame] | 4359 | break; |
| 4360 | } |
| 4361 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4362 | case UPD_CXX_INSTANTIATED_CLASS_DEFINITION: { |
| 4363 | auto *RD = cast<CXXRecordDecl>(D); |
Richard Smith | b648399 | 2016-05-17 22:44:15 +0000 | [diff] [blame] | 4364 | auto *OldDD = RD->getCanonicalDecl()->DefinitionData; |
Richard Smith | 2a9e5c5 | 2015-02-03 03:32:14 +0000 | [diff] [blame] | 4365 | bool HadRealDefinition = |
Richard Smith | 7483d20 | 2015-02-04 01:23:46 +0000 | [diff] [blame] | 4366 | OldDD && (OldDD->Definition != RD || |
| 4367 | !Reader.PendingFakeDefinitionData.count(OldDD)); |
Akira Hatanaka | fcbe17c | 2018-03-28 21:13:14 +0000 | [diff] [blame] | 4368 | RD->setParamDestroyedInCallee(Record.readInt()); |
Akira Hatanaka | e6313ac | 2018-04-09 22:48:22 +0000 | [diff] [blame] | 4369 | RD->setArgPassingRestrictions( |
| 4370 | (RecordDecl::ArgPassingKind)Record.readInt()); |
Richard Smith | 2a9e5c5 | 2015-02-03 03:32:14 +0000 | [diff] [blame] | 4371 | ReadCXXRecordDefinition(RD, /*Update*/true); |
| 4372 | |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4373 | // Visible update is handled separately. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4374 | uint64_t LexicalOffset = ReadLocalOffset(); |
Richard Smith | 8a63989 | 2015-01-24 01:07:20 +0000 | [diff] [blame] | 4375 | if (!HadRealDefinition && LexicalOffset) { |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 4376 | Record.readLexicalDeclContextStorage(LexicalOffset, RD); |
Richard Smith | 2a9e5c5 | 2015-02-03 03:32:14 +0000 | [diff] [blame] | 4377 | Reader.PendingFakeDefinitionData.erase(OldDD); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4378 | } |
| 4379 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 4380 | auto TSK = (TemplateSpecializationKind)Record.readInt(); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4381 | SourceLocation POI = ReadSourceLocation(); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4382 | if (MemberSpecializationInfo *MSInfo = |
| 4383 | RD->getMemberSpecializationInfo()) { |
| 4384 | MSInfo->setTemplateSpecializationKind(TSK); |
| 4385 | MSInfo->setPointOfInstantiation(POI); |
| 4386 | } else { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4387 | auto *Spec = cast<ClassTemplateSpecializationDecl>(RD); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4388 | Spec->setTemplateSpecializationKind(TSK); |
| 4389 | Spec->setPointOfInstantiation(POI); |
Richard Smith | df35205 | 2014-05-22 20:59:29 +0000 | [diff] [blame] | 4390 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 4391 | if (Record.readInt()) { |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4392 | auto *PartialSpec = |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4393 | ReadDeclAs<ClassTemplatePartialSpecializationDecl>(); |
Richard Smith | df35205 | 2014-05-22 20:59:29 +0000 | [diff] [blame] | 4394 | SmallVector<TemplateArgument, 8> TemplArgs; |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 4395 | Record.readTemplateArgumentList(TemplArgs); |
Richard Smith | df35205 | 2014-05-22 20:59:29 +0000 | [diff] [blame] | 4396 | auto *TemplArgList = TemplateArgumentList::CreateCopy( |
David Majnemer | 8b62269 | 2016-07-03 21:17:51 +0000 | [diff] [blame] | 4397 | Reader.getContext(), TemplArgs); |
Richard Smith | 72544f8 | 2014-08-14 03:30:27 +0000 | [diff] [blame] | 4398 | |
| 4399 | // FIXME: If we already have a partial specialization set, |
| 4400 | // check that it matches. |
| 4401 | if (!Spec->getSpecializedTemplateOrPartial() |
| 4402 | .is<ClassTemplatePartialSpecializationDecl *>()) |
| 4403 | Spec->setInstantiationOf(PartialSpec, TemplArgList); |
Richard Smith | df35205 | 2014-05-22 20:59:29 +0000 | [diff] [blame] | 4404 | } |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4405 | } |
| 4406 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 4407 | RD->setTagKind((TagTypeKind)Record.readInt()); |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4408 | RD->setLocation(ReadSourceLocation()); |
| 4409 | RD->setLocStart(ReadSourceLocation()); |
| 4410 | RD->setBraceRange(ReadSourceRange()); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4411 | |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 4412 | if (Record.readInt()) { |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4413 | AttrVec Attrs; |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 4414 | Record.readAttributes(Attrs); |
Richard Smith | 842e46e | 2016-10-26 02:31:56 +0000 | [diff] [blame] | 4415 | // If the declaration already has attributes, we assume that some other |
| 4416 | // AST file already loaded them. |
| 4417 | if (!D->hasAttrs()) |
| 4418 | D->setAttrsImpl(Attrs, Reader.getContext()); |
Richard Smith | cd45dbc | 2014-04-19 03:48:30 +0000 | [diff] [blame] | 4419 | } |
| 4420 | break; |
| 4421 | } |
| 4422 | |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 4423 | case UPD_CXX_RESOLVED_DTOR_DELETE: { |
| 4424 | // Set the 'operator delete' directly to avoid emitting another update |
| 4425 | // record. |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4426 | auto *Del = ReadDeclAs<FunctionDecl>(); |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 4427 | auto *First = cast<CXXDestructorDecl>(D->getCanonicalDecl()); |
Richard Smith | 5b34958 | 2017-10-13 01:55:36 +0000 | [diff] [blame] | 4428 | auto *ThisArg = Record.readExpr(); |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 4429 | // FIXME: Check consistency if we have an old and new operator delete. |
Richard Smith | 5b34958 | 2017-10-13 01:55:36 +0000 | [diff] [blame] | 4430 | if (!First->OperatorDelete) { |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 4431 | First->OperatorDelete = Del; |
Richard Smith | 5b34958 | 2017-10-13 01:55:36 +0000 | [diff] [blame] | 4432 | First->OperatorDeleteThisArg = ThisArg; |
| 4433 | } |
Richard Smith | f813400 | 2015-03-10 01:41:22 +0000 | [diff] [blame] | 4434 | break; |
| 4435 | } |
| 4436 | |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 4437 | case UPD_CXX_RESOLVED_EXCEPTION_SPEC: { |
Richard Smith | 8acb428 | 2014-07-31 21:57:55 +0000 | [diff] [blame] | 4438 | FunctionProtoType::ExceptionSpecInfo ESI; |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 4439 | SmallVector<QualType, 8> ExceptionStorage; |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 4440 | Record.readExceptionSpec(ExceptionStorage, ESI); |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 4441 | |
| 4442 | // Update this declaration's exception specification, if needed. |
| 4443 | auto *FD = cast<FunctionDecl>(D); |
| 4444 | auto *FPT = FD->getType()->castAs<FunctionProtoType>(); |
| 4445 | // FIXME: If the exception specification is already present, check that it |
| 4446 | // matches. |
| 4447 | if (isUnresolvedExceptionSpec(FPT->getExceptionSpecType())) { |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 4448 | FD->setType(Reader.getContext().getFunctionType( |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 4449 | FPT->getReturnType(), FPT->getParamTypes(), |
| 4450 | FPT->getExtProtoInfo().withExceptionSpec(ESI))); |
Richard Smith | 9e2341d | 2015-03-23 03:25:59 +0000 | [diff] [blame] | 4451 | |
| 4452 | // When we get to the end of deserializing, see if there are other decls |
| 4453 | // that we need to propagate this exception specification onto. |
| 4454 | Reader.PendingExceptionSpecUpdates.insert( |
| 4455 | std::make_pair(FD->getCanonicalDecl(), FD)); |
Richard Smith | 6de7a24 | 2014-07-31 23:46:44 +0000 | [diff] [blame] | 4456 | } |
Richard Smith | 564417a | 2014-03-20 21:47:22 +0000 | [diff] [blame] | 4457 | break; |
| 4458 | } |
| 4459 | |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 4460 | case UPD_CXX_DEDUCED_RETURN_TYPE: { |
Richard Smith | a62d198 | 2018-08-03 01:00:01 +0000 | [diff] [blame] | 4461 | auto *FD = cast<FunctionDecl>(D); |
David L. Jones | be1557a | 2016-12-21 00:17:49 +0000 | [diff] [blame] | 4462 | QualType DeducedResultType = Record.readType(); |
Richard Smith | a62d198 | 2018-08-03 01:00:01 +0000 | [diff] [blame] | 4463 | Reader.PendingDeducedTypeUpdates.insert( |
| 4464 | {FD->getCanonicalDecl(), DeducedResultType}); |
Richard Smith | 1fa5d64 | 2013-05-11 05:45:24 +0000 | [diff] [blame] | 4465 | break; |
| 4466 | } |
Eli Friedman | 276dd18 | 2013-09-05 00:02:25 +0000 | [diff] [blame] | 4467 | |
Eugene Zelenko | e69b33f | 2018-04-11 20:57:28 +0000 | [diff] [blame] | 4468 | case UPD_DECL_MARKED_USED: |
Richard Smith | 675d279 | 2014-06-16 20:26:19 +0000 | [diff] [blame] | 4469 | // Maintain AST consistency: any later redeclarations are used too. |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 4470 | D->markUsed(Reader.getContext()); |
Eli Friedman | 276dd18 | 2013-09-05 00:02:25 +0000 | [diff] [blame] | 4471 | break; |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4472 | |
| 4473 | case UPD_MANGLING_NUMBER: |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 4474 | Reader.getContext().setManglingNumber(cast<NamedDecl>(D), |
| 4475 | Record.readInt()); |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4476 | break; |
| 4477 | |
| 4478 | case UPD_STATIC_LOCAL_NUMBER: |
Richard Smith | dbafb6c | 2017-06-29 23:23:46 +0000 | [diff] [blame] | 4479 | Reader.getContext().setStaticLocalNumber(cast<VarDecl>(D), |
| 4480 | Record.readInt()); |
Richard Smith | 5652c0f | 2014-03-21 01:48:23 +0000 | [diff] [blame] | 4481 | break; |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 4482 | |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 4483 | case UPD_DECL_MARKED_OPENMP_THREADPRIVATE: |
Erich Keane | 6a24e80 | 2019-09-13 17:39:31 +0000 | [diff] [blame] | 4484 | D->addAttr(OMPThreadPrivateDeclAttr::CreateImplicit( |
| 4485 | Reader.getContext(), ReadSourceRange(), |
| 4486 | AttributeCommonInfo::AS_Pragma)); |
Alexey Bataev | 9772000 | 2014-11-11 04:05:39 +0000 | [diff] [blame] | 4487 | break; |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 4488 | |
Alexey Bataev | 27ef951 | 2019-03-20 20:14:22 +0000 | [diff] [blame] | 4489 | case UPD_DECL_MARKED_OPENMP_ALLOCATE: { |
| 4490 | auto AllocatorKind = |
| 4491 | static_cast<OMPAllocateDeclAttr::AllocatorTypeTy>(Record.readInt()); |
| 4492 | Expr *Allocator = Record.readExpr(); |
| 4493 | SourceRange SR = ReadSourceRange(); |
Alexey Bataev | 9cc10fc | 2019-03-12 18:52:33 +0000 | [diff] [blame] | 4494 | D->addAttr(OMPAllocateDeclAttr::CreateImplicit( |
Erich Keane | 6a24e80 | 2019-09-13 17:39:31 +0000 | [diff] [blame] | 4495 | Reader.getContext(), AllocatorKind, Allocator, SR, |
| 4496 | AttributeCommonInfo::AS_Pragma)); |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 4497 | break; |
Alexey Bataev | 27ef951 | 2019-03-20 20:14:22 +0000 | [diff] [blame] | 4498 | } |
Alexey Bataev | 25ed0c0 | 2019-03-07 17:54:44 +0000 | [diff] [blame] | 4499 | |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 4500 | case UPD_DECL_EXPORTED: { |
David L. Jones | c4808b9e | 2016-12-15 20:53:26 +0000 | [diff] [blame] | 4501 | unsigned SubmoduleID = readSubmoduleID(); |
Richard Smith | beb4478 | 2015-06-20 01:05:19 +0000 | [diff] [blame] | 4502 | auto *Exported = cast<NamedDecl>(D); |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 4503 | Module *Owner = SubmoduleID ? Reader.getSubmodule(SubmoduleID) : nullptr; |
Richard Smith | 13897eb | 2018-09-12 23:37:00 +0000 | [diff] [blame] | 4504 | Reader.getContext().mergeDefinitionIntoModule(Exported, Owner); |
| 4505 | Reader.PendingMergedDefinitionsToDeduplicate.insert(Exported); |
Richard Smith | 65ebb4a | 2015-03-26 04:09:53 +0000 | [diff] [blame] | 4506 | break; |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 4507 | } |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 4508 | |
Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 4509 | case UPD_DECL_MARKED_OPENMP_DECLARETARGET: { |
| 4510 | OMPDeclareTargetDeclAttr::MapTypeTy MapType = |
| 4511 | static_cast<OMPDeclareTargetDeclAttr::MapTypeTy>(Record.readInt()); |
| 4512 | OMPDeclareTargetDeclAttr::DevTypeTy DevType = |
| 4513 | static_cast<OMPDeclareTargetDeclAttr::DevTypeTy>(Record.readInt()); |
Alexey Bataev | d01b749 | 2018-08-15 19:45:12 +0000 | [diff] [blame] | 4514 | D->addAttr(OMPDeclareTargetDeclAttr::CreateImplicit( |
Erich Keane | 6a24e80 | 2019-09-13 17:39:31 +0000 | [diff] [blame] | 4515 | Reader.getContext(), MapType, DevType, ReadSourceRange(), |
| 4516 | AttributeCommonInfo::AS_Pragma)); |
Alexey Bataev | d01b749 | 2018-08-15 19:45:12 +0000 | [diff] [blame] | 4517 | break; |
Alexey Bataev | 729e242 | 2019-08-23 16:11:14 +0000 | [diff] [blame] | 4518 | } |
Alexey Bataev | d01b749 | 2018-08-15 19:45:12 +0000 | [diff] [blame] | 4519 | |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 4520 | case UPD_ADDED_ATTR_TO_RECORD: |
| 4521 | AttrVec Attrs; |
David L. Jones | b6a8f02 | 2016-12-21 04:34:52 +0000 | [diff] [blame] | 4522 | Record.readAttributes(Attrs); |
Alex Denisov | fde6495 | 2015-06-26 05:28:36 +0000 | [diff] [blame] | 4523 | assert(Attrs.size() == 1); |
| 4524 | D->addAttr(Attrs[0]); |
| 4525 | break; |
| 4526 | } |
Argyrios Kyrtzidis | d170d84 | 2010-10-24 17:26:50 +0000 | [diff] [blame] | 4527 | } |
Argyrios Kyrtzidis | 65ad569 | 2010-10-24 17:26:36 +0000 | [diff] [blame] | 4528 | } |